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

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

$dal = new DAL();

if ($field == 'sumLotDefinitions') {
    
  $where = "LO.projectparcel_id = $id";

  $sql = "SELECT LO.id, LO.name AS 'Lot', " .
         "(CASE WHEN LT.id IS NULL THEN 'None' ELSE LT.descr END) AS Type, " .
         "(CASE WHEN LI.id IS NULL THEN 'None' ELSE LI.descr END) " .
         "AS Interpretation " .
         "FROM lot LO " . 
         "LEFT JOIN lotinterpret LI ON LI.id = LO.lotinterpret_id " .
         "LEFT JOIN lottype LT ON LT.id = LO.lottype_id " .
         "WHERE $where " . 
         "ORDER BY LO.name_seq " ;

  $result = $dal->query($sql);
}


echo json_encode($result);

?>

