<?php
session_start();

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id") 
    $pwo_id = $paramValue;  
  else if ($paramName == "projectworkevent_id") 
    $pw_id = $paramValue;  
  else if ($paramName == "operation_id") 
    $op_id = $paramValue;  
  else if ($paramName == "duration") 
    $duration = $paramValue;  
}


$dal = new DAL();

if ($pwo_id == 0) {

  $pwo_id = hexdec(uniqid());

  $sql = "INSERT INTO projectworkdayoperation " .
         "(id, operation_id, projectworkevent_id, duration) " .
         "VALUES ($pwo_id, $op_id, $pw_id, '$duration') ";
  $result = $dal->query($sql);
}

else {
  $sql = "UPDATE projectworkdayoperation ". 
         "SET duration='$duration' " .
         "WHERE id = $pwo_id ";
  $result = $dal->query($sql);
}  
    
echo json_encode($pwo_id);

?>

