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

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

$dal = new DAL();

$sql = "SELECT SL.id, LO.name AS text " .
       "FROM (projectworkday PW, projectworkdayoperation PWO, " .
       "operationspatialunit OS, spatialunitlot SL, lot LO) " .
       "LEFT JOIN (spatialunitlot SL1) " .
       "ON SL.operationspatialunit_id = $os_id AND SL.lot_id = LO.id " .
       "WHERE SL1.id IS NULL AND PW.parcel_id = $pa_id " .
       "AND PWO.projectworkday_id = PW.id " .
       "AND PWO.operation_id = OS.operation_id " .
       "AND SL.operationspatialunit_id = OS.id " .
       "AND LO.id = SL.lot_id " ;
$result = $dal->query($sql);

echo json_encode($result);

?>

