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

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

$dal = new DAL();

if ($field == "fkyControlType") {

//  $_SESSION['controltype'] = 0;
  $_SESSION['menuitem'] = 0;

  $sql = "SELECT 0 AS id, 'Select' AS text " .
         "UNION ALL " .
         "SELECT id, descr AS text " .
         "FROM itemtype " .
         "WHERE id > $summaryId ORDER BY id ";
  $result = $dal->query($sql);
} 

else if ($field == "fkyMenuItem") {

  $_SESSION['controltype'] = $summaryId;
//  $_SESSION['menuitem'] = 0;

  $sql = "SELECT 0 AS id, 'Select' AS text " .
         "UNION ALL " .
         "SELECT id, CONCAT (name, ': ', path) AS text " .
         "FROM menuitem " .
         "WHERE menuitem.itemtype_id = $summaryId ORDER BY id ";
  $result = $dal->query($sql);
} 

echo json_encode ($result);

?>

