<?php

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

$dal = new DAL(); 
 
if ($ca_id == 0) {
  $sql = "INSERT INTO controlattr " .
         "(controlfield_id, attribute, value) " .
         "VALUES ($cf_id, '$attribute', '$value') ";
  $ce_id = $dal->query($sql);
}

else {
  $sql = "UPDATE controlattr " .
         "SET attribute='$attribute', value='$value' " .
         "WHERE id = $ca_id ";
  $result = $dal->query($sql);
}

echo json_encode($ca_id);

?>

