<?php

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

$dal = new DAL(); 
 
if ($ci_id == 0) {
  $sql = "INSERT INTO controlinstance " .
         "(controlobject_id, instance, mainmenu_id) " .
         "VALUES ($controlobject_id, '$instance', '$mm_id') ";
  $ci_id = $dal->query($sql);
}

else {
  $sql = "UPDATE controlinstance " .
         "SET controlobject_id=$controlobject_id, instance='$instance' " .
         "WHERE id = $ci_id ";
  $result = $dal->query($sql);
}

echo json_encode($ci_id);

?>

