<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id") 
    $op_id = $paramValue;  
  else if ($paramName == "projectparcel_id") 
    $pp_id = $paramValue;  
  else if ($paramName == "name") 
    $name = $paramValue;  
  else if ($paramName == "operationtype_id") 
    $operationtype_id = $paramValue;  
  else if ($paramName == "note") 
    $note = $paramValue;  
}

$dal = new DAL();

if ($op_id == 0) {

  $op_id = hexdec(uniqid());
  $sql = "INSERT INTO operation " .
         "(id, name, operationtype_id, projectparcel_id) " .
         "VALUES ($op_id, '$name', $operationtype_id,  $pp_id) ";
  $result = $dal->query($sql);
}

else {

  $sql = "UPDATE operation ". 
         "SET name='$name', operationtype_id=$operationtype_id " .
         "WHERE id = $op_id ";
  $result = $dal->query($sql);
}  
    
echo json_encode($op_id);

?>

