<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');
 
foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id") 
    $poc_id = $paramValue; 
  else if ($paramName == "project_fk") 
    $pr_id = $paramValue; 
  else if ($paramName == "organizationcontact_fk") 
    $oc_id = $paramValue; 
  else if ($paramName == "descr") 
    $descr = $paramValue; 
  else if ($paramName == "contactype_id") 
    $ct_id = $paramValue; 
  else if ($paramName == "refno") 
    $refno = $paramValue; 
  else if ($paramName == "stage_id") 
    $stage_id = $paramValue; 
  else if ($paramName == "development_refno") 
    $development_refno = $paramValue; 
  else if ($paramName == "department_id") 
    $department_id = $paramValue; 
  else if ($paramName == "approver_id") 
    $approver_id = $paramValue; 
  else if ($paramName == "licence_no") 
    $licence_no = $paramValue; 
  else if ($paramName == "note") 
    $note = $paramValue; 
}

$dal = new DAL();

if ($poc_id == 0) {
  $poc_id = hexdec(uniqid());

  $sql = "INSERT INTO projectorganizationcontact " .
         "(id, project_id, organizationcontact_id, contactype_id) " .
         "VALUES ($poc_id, $pr_id, $oc_id, $ct_id) ";
  $result = $dal->query($sql);
}

else {
  $sql = "UPDATE projectorganizationcontact " .
         "SET contactype_id=$ct_id " .
         "WHERE id = $poc_id ";
  $result = $dal->query($sql);

  $sql = "UPDATE project " .
         "SET descr='$descr', " .
         "stage_id=$stage_id, " .
         "development_refno='$development_refno', approver_id=$approver_id, " .
         "department_id=$department_id, licence_no='$licence_no', note='$note' " . 
         "WHERE id = $pr_id ";
  $result = $dal->query($sql);

}  


echo json_encode($poc_id);

?>

