<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "selectid")
    $os_id = $paramValue;
}

$dal = new DAL();
$sql = "SELECT OS.id,              PW.parcel_id AS fkid, " .
       "SU.name,                   '' AS name_text, " .
       "SU.mapareaid,              '' AS mapareaid_text, " .
       "LA.descr AS landuse,       '' AS landuse_id_text, " .
       "P.location,                '' AS location_text, " .
       "(CASE WHEN UC.id IS NULL THEN 0 " .
          "ELSE UC.groundcovertype_id END) AS groundcovertype_id, " . 
       "'' AS groundcovertype_id_text, " .
       "(CASE WHEN UC.id IS NULL THEN 0 " .
          "ELSE UC.groundconditiontype_id END) AS groundconditiontype_id, " . 
       "'' AS groundconditiontype_id_text, " .
       "(CASE WHEN UC.id IS NULL THEN 0 " .
          "ELSE UC.groundvisibility_id END) AS groundvisibility_id, " . 
       "'' AS groundvisibility_id_text, " .
       "(CASE WHEN AG.id IS NULL THEN 0 " .
          "ELSE AG.assesstype_id END) AS assesstype_id, " . 
       "'' AS assesstype_id_text, " . 
       "AG.modification,           '' AS modification_text, " . 
       "AG.rationale,              '' AS rationale_text, " .
       "AP.mapcode,                '' AS mapcode_text, " . 
       "OS.note,                   '' AS note_text " .
       "FROM operationspatialunit OS, spatialunit SU, part P, " .
       "projectworkdayoperation PWO, projectworkday PW, landuse LA " .
       "LEFT JOIN unitcondition UC ON UC.operationspatialunit_id = $os_id " .
       "LEFT JOIN (assesstrategy AG, assesstype AP) " .
       "ON AG.operationspatialunit_id = $os_id AND AG.assesstype_id = AP.id " .
       "WHERE OS.id = $os_id  AND PWO.operation_id = OS.operation_id " .
       "AND PW.id = PWO.projectworkday_id AND SU.id = OS.spatialunit_id " .
       "AND P.spatialunit_id = SU.id AND LA.id = P.landuse_id " . 
       "LIMIT 1 " ;
$result = $dal->query($sql);

echo json_encode($result);

?>

