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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "checkval")
    $part_name = $paramValue;
  else if ($paramName == "scopeId")
    $pa_id = $paramValue;
}

$dal = new DAL();

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

if (null == $result)
  $next_part_name = $part_name;
else
  $next_part_name = "";

echo json_encode($next_part_name);

?>

