<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');
 
foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id")
    $ce_id = $paramValue;
  else if ($paramName == "property")
    $property = $paramValue;
  else if ($paramName == "value")
    $value = $paramValue;
  elseif ($paramName == "controlinstance_id") 
    $ci_id = $paramValue;  
}

$dal = new DAL(); 
 
if ($ce_id == 0) {
  $sql = "INSERT INTO controlentry " .
         "(controlinstance_id, property, value) " .
         "VALUES ($ci_id, '$property', '$value') ";
  $ce_id = $dal->query($sql);
}

else {
  $sql = "UPDATE controlentry " .
         "SET property='$property', value='$value' " .
         "WHERE id = $ce_id ";
  $result = $dal->query($sql);
}

echo json_encode($ce_id);

?>

