<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');
 
foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id")
    $cf_id = $paramValue;
  else if ($paramName == "field")
    $field = $paramValue;
  else if ($paramName == "panelfolder_id")
    $mm_id = $paramValue;
  elseif ($paramName == "controlobject_id") 
    $controlobject_id = $paramValue;  
  elseif ($paramName == "formhandler_id") 
    $formhandler_id = $paramValue;  
}

$dal = new DAL(); 
 
if ($cf_id == 0) {
  $sql = "INSERT INTO controlfield " .
         "(controlobject_id, field, mainmenu_id, formhandler_id) " .
         "VALUES ($controlobject_id, '$field', $mm_id, $formhandler_id) ";
  $cf_id = $dal->query($sql);
}

else {
  $sql = "UPDATE controlfield " .
         "SET controlobject_id=$controlobject_id, field='$field', " . 
         "formhandler_id=$formhandler_id " .
         "WHERE id = $cf_id ";
  $result = $dal->query($sql);
}

echo json_encode($cf_id);

?>

