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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "string")
    $name = $paramValue;
  else if ($paramName == "sequenceid")
    $pa_id = $paramValue;
}

$dal = new DAL();

$sql = "SELECT OS.id " .
       "FROM projectworkday PW, projectworkdayoperation PWO, " .
       "operation OP, operationspatialunit OS, spatialunit SU " .
       "WHERE PW.parcel_id = $pa_id AND PWO.projectworkday_id = PW.id " .
       "AND PWO.operation_id = OS.operation_id = OP.id " .
       "AND OS.spatialunit_id = SU.id AND SU.name = '$string' " .  
       "AND SU.spatialunittype_id = 1 " ;
$result = $dal->query($sql);

if (null == $result)
  $next_name = $name;
else
  $next_name = "";

echo json_encode($next_name);

?>

