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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "scopeid")
    $pwo_id = $paramValue;
  else if ($paramName == "baseid")
    $pa_id = $paramValue;
}

$dal = new DAL();

$sql = "SELECT LO.id, LO.name AS text, " .
       "CASE WHEN LC.culturalunit_id IS NULL THEN '' ELSE 'disabled' END AS attribute " . 
       "FROM (projectworkday PW, projectworkdayoperation PWO, " .
       "operationspatialunit OS, spatialunitlot SL, lot LO) " .
       "LEFT JOIN lotculturalunit LC ON LC.spatialunitlot_id = SL.id " .
       "WHERE PW.parcel_id = $pa_id AND PWO.projectworkday_id = PW.id " .
       "AND OS.projectworkdayoperation_id = PWO.id AND SL.operationspatialunit_id = OS.id " .
       "AND LO.id = SL.lot_id " ;
$result = $dal->query($sql);

echo json_encode($result);

?>

