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

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

$dal = new DAL();
$sql = "SELECT OS.id, SU.name AS 'Part Name', SU.mapareaid AS 'Map Id', " . 
       "CASE WHEN LA.descr IS NULL " .
         "THEN '' ELSE LA.descr END AS 'Land Use', " .
       "P.location AS Location " .
       "FROM (projectworkday PW, projectworkdayoperation PWO, " .
       "operationspatialunit OS, spatialunit SU, part P) " .
       "LEFT JOIN landuse LA ON LA.id = P.landuse_id " .
       "WHERE PW.parcel_id = $pa_id " .
       "AND PWO.projectworkday_id = PW.id " .
       "AND PWO.operation_id = OS.operation_id " .
       "AND OS.spatialunit_id = SU.id AND SU.spatialunittype_id = 1 " .
       "AND P.spatialunit_id = SU.id " .
       "ORDER BY SU.name ";
$result = $dal->query($sql);

echo json_encode($result);

?>

