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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "baseid")
    $pa_id = $paramValue;
}

$dal = new DAL();

$sql = "SELECT LO.name_seq " .
       "FROM projectworkday PW, projectworkdayoperation PWO, " .
       "operationspatialunit OS, spatialunitlot SL, lot LO " .
       "WHERE PW.parcel_id = $pa_id AND PWO.projectworkday_id = PW.id " .
       "AND OS.projectworkdayoperation_id = PWO.id AND SL.operationspatialunit_id = OS.id " .
       "AND LO.id = SL.lot_id ORDER BY name_seq DESC LIMIT 1 " ;
$result = $dal->query($sql);       

if (null == $result)
  $next_seq = 1; 
else
  $next_seq = $result->name_seq + 1;

$next_site_name = $next_seq;

echo json_encode($next_site_name);

?>

