<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');
 
foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id")
    $pa_id = $paramValue;
  else if ($paramName == "name")
    $name = $paramValue;
  else if ($paramName == "location")
    $location = $paramValue;
  else if ($paramName == "natural_context")
    $natural_context = $paramValue;
  else if ($paramName == "directions")
    $directions = $paramValue;
  elseif ($paramName == "fkid") 
    $project_id = $paramValue;  
}

$dal = new DAL(); 
 
if ($pa_id == 0) {
  $sql = "INSERT INTO parcel " .
         "(project_id, name, location, natural_context, directions) " .
         "VALUES ($project_id, '$location', '$natural_context', '$directions') ";
  $pa_id = $dal->query($sql);
}

else {
  $sql = "UPDATE parcel " .
         "SET name='$name', location='$location', " .
         "natural_context='$natural_context', directions='$directions' " .
         "WHERE id = $pa_id ";
  $result = $dal->query($sql);
}

echo json_encode($pa_id);

?>

