<?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', " .
       "LU.descr AS 'Land Use', " .
       "(CASE WHEN UC.id IS NULL " .
         "THEN '' ELSE GC.descr END) AS 'Ground Cover', " .
       "(CASE WHEN AG.id IS NULL THEN '' " .
             "WHEN AG.modification <> '' THEN AG.modification " .
             "ELSE AP.descr END) AS 'Assessment Strategy' " . 
       "FROM (projectworkday PW, projectworkdayoperation PWO, " .
       "operationspatialunit OS, spatialunit SU, part P, landuse LU) " .
       "LEFT JOIN (unitcondition UC, groundcovertype GC) " .
       "ON (UC.operationspatialunit_id = OS.id " .
       "AND UC.groundcovertype_id = GC.id) " .
       "LEFT JOIN (assesstrategy AG, assesstype AP) " .
       "ON (AG.operationspatialunit_id = OS.id " .
       "AND AP.id = AG.assesstype_id) " . 
       "WHERE PW.parcel_id = $pa_id " .
       "AND PWO.projectworkday_id = PW.id " .
       "AND OS.operation_id = PWO.operation_id " .
       "AND SU.id = OS.spatialunit_id " .
       "AND P.spatialunit_id = SU.id AND P.landuse_id = LU.id ";
$result = $dal->query($sql);

echo json_encode($result);

?>

