<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "currid")
    $su_id = $paramValue;
  else if ($paramName == "filterid")
    $pa_id = $paramValue;
}
  
$dal = new DAL();

$sql = "SELECT PF.id, FO.name AS 'text', SF.Location AS input, " .  
       "(CASE WHEN SF.id IS NULL " .
       "THEN '' ELSE 'SF' END) AS part " .
       "FROM (parcelfop PF, fop FO)  " .
       "LEFT JOIN (spatialunitfop SF, spatialunit SU, part P) " .
       "ON SF.parcelfop_id = PF.id AND SU.id = SF.spatialunit_id " .
       "AND P.spatialunit_id = SU.id " .
       "WHERE PF.parcel_id = $pa_id AND FO.id = PF.fop_id " .
       "ORDER BY FO.name " ; 
$result = $dal->query($sql);

echo json_encode($result);
?>


