<?php

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

  if ($summaryId == 0) {
    $_SESSION['projectparcel'] = $selectId;
    $_SESSION['operationdefinition'] = 0;
  }
  
  else {
    $sql = "SELECT PP.id, CONCAT (PR.name, ': ',  PA.name) AS text " .
           "FROM projectparcel PP, parcel PA, project PR " .
           "WHERE PP.id = $summaryId AND PA.id = PP.parcel_id " .
           "AND PR.id = PP.project_id ORDER BY text ";
    $result = $dal->query($sql);
  }           
}         

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

  if ($summaryId == 0) {
    $_SESSION['workevent'] = $selectId;
    $_SESSION['operationdefinition'] = 0;
  }
  
  else {
    $sql = "SELECT PW.id, CONCAT (WD.textdate, ' - ', PW.workdayvisit) AS text " .
           "FROM projectworkevent PW, workday WD " .
           "WHERE PW.id = $summaryId AND WD.id = PW.workday_id ";
    $result = $dal->query($sql);
  }    
}         


echo json_encode ($result);

?>

