<?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 == "sumControlInstances") {


  if ($summaryId == 0) {
//print_r ("sum:$summaryId sel: $selectId");
    $_SESSION['panelfolder'] = $selectId;
    $_SESSION['controlinstance'] = 0;
  }
  
  else {
    $sql = "SELECT id, path AS text " .
           "FROM mainmenu " .
           "WHERE 1 ORDER BY text ";
    $result = $dal->query($sql);
  }    
} 

//else if ($field == "sumControlInstances") {

//  $_SESSION['panelfolder'] = $selectId;
//  $_SESSION['controlinstance'] = 0;

//  $sql = "SELECT id, path AS text " .
//         "FROM mainmenu " .
//         "WHERE 1 ORDER BY text ";
//  $result = $dal->query($sql);
//} 

echo json_encode ($result);

?>

