    <?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "fkid")
    $cu_id = $paramValue;
  if ($paramName == "id")
    $si_id = $paramValue;
  elseif ($paramName == "intensificationtype_id") 
    $intenificationtype_id = $paramValue;  
  elseif ($paramName == "modification") 
    $modification = $paramValue;  
  elseif ($paramName == "rationale") 
    $rationale = $paramValue;  
}

$dal = new DAL();

//$sql = "SELECT id FROM siteintensification WHERE id = $cu_id " ;

if ($si_id == 0) {

  $si_id = hexdec(uniqid());

  $sql = "INSERT INTO siteintensification " .
         "(id, culturalunit_id, intensificationtype_id, modification, " .
         "rationale) VALUES ($si_id, $cu_id, $intensificationtype_id, " .
         "'$modification', '$rationale') " ;
  $result = $dal->query($sql);
}

else {        

  $sql = "UPDATE siteintensification SET " .
         "intensificationtype_id=$intensificationtype_id, " .
         "modification='$modification', rationale='$rationale'" .
         "WHERE id = $si_id " ;
  $result = $dal->query($sql);
}

echo json_encode($result);

?>

