<?php
session_start();

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "summaryid")
    $summaryId = $paramValue;
  else if ($paramName == "field")
    $field = $paramValue;
}

$dal = new DAL();

if ($field == 'cxtfkyControlType') {

//  $_SESSION["controltype"] = $summaryId;

//  if ($summaryId > 0) {
    $sql = "SELECT CF.id, SPACE(0) AS 'select', field, CO.control  " .
           "FROM menuitem MI, controlfield CF, controlobject CO " .
           "WHERE MI.itemtype_id = $summaryId AND CF.menuitem_id = MI.id " .
           "AND CO.id = CF.controlobject_id " .
           "ORDER BY CO.control, CF.menuitem_id ";
    $result = $dal->query($sql);
//  }           
}

else if ($field == "cxtfkyMenuItem" || $field == "frmControlField" || $field == "updfrmControlField") {

  if ($field == "cxtfkyMenuItem")
    $_SESSION["menuitem"] = $summaryId;

 // if ($summaryId > 0) {
    $sql = "SELECT CF.id, SPACE(0) AS 'select', field, CO.control  " .
           "FROM controlfield CF, controlobject CO " .
           "WHERE CF.menuitem_id = $summaryId AND CF.controlobject_id = CO.id " .
           "ORDER BY CO.control, CF.menuitem_id ";
    $result = $dal->query($sql);
 // }           
}



echo json_encode($result);

?>

