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

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

$dal = new DAL();
      
$sql = "SELECT CU.id, CU.name AS 'Site Name', SU.name AS 'Property Part', " .
       "(CASE " .
       "  WHEN LC.id IS NOT NULL THEN 'Shovel-testing survey' " .
       "  WHEN SI.id IS NOT NULL THEN 'Pedestrian survey' " .
       "  ELSE 'Not Defined' END) AS Method, " .
       "CU.descr AS Description, IP.descr AS Interpretation " .
       "FROM operationspatialunit OS, spatialunit SU, " .
       "sitespatialunit SS, culturalunit CU " .
       "LEFT JOIN interpret IP ON IP.id = CU.interpret_id " .
       "LEFT JOIN lotculturalunit LC ON LC.culturalunit_id = CU.id " .
       "LEFT JOIN siteintensification SI ON SI.culturalunit_id = CU.id " .
       "WHERE OS.id = $os_id " .
       "AND SU.id = OS.spatialunit_id " .
       "AND SU.spatialunittype_id = 1 " .
       "AND SS.operationspatialunit_id = OS.id " .
       "AND CU.id = SS.culturalunit_id " .
       "ORDER BY SU.name, CU.name ";
$result = $dal->query($sql);

echo json_encode($result);

?>

