<?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;
}    

if ($field == 'sumLocationDefinitions') {
  $where = "PS.projectparcel_id = $id AND SU.id = PS.spatialunit_id";
  $table = "projectparcelspatialunit PS,";
}

$dal = new DAL();
$sql = "SELECT SU.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 ($table spatialunit SU, part P) " .
       "LEFT JOIN landuse LA ON LA.id = P.landuse_id " .
       "WHERE $where " .
       "AND SU.spatialunitype_id = 1 AND P.spatialunit_id = SU.id " .
       "ORDER BY SU.name ";
$result = $dal->query($sql);

echo json_encode($result);

?>

