<?php

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

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

$dal = new DAL();
$sql = "SELECT CU.id, CU.name AS hint " .
       "FROM operationspatialunit OS, spatialunit SU, " .
       "sitespatialunit SS, culturalunit CU " .
       "WHERE OS.id = $os_id " .
       "AND SU.id = OS.spatialunit_id " .
       "AND SU.spatialunitype_id = 1 " .
       "AND SS.operationspatialunit_id = OS.id " .
       "AND CU.id = SS.culturalunit_id " .
       "AND CU.name LIKE '%$pattern%' " .
       "ORDER BY CU.name ";
$result = $dal->query($sql);

echo json_encode ($result);


