<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "scopeid") 
    $pwo_id = $paramValue;  
  else if ($paramName == "rowval") 
    $part_name = $paramValue;  
}

$dal = new DAL();
         
$su_id = hexdec(uniqid());

$sql = "INSERT INTO spatialunit " .
       "(id, spatialunittype_id, name) " .
       "VALUES ($su_id, 1, '$part_name') ";
$result = $dal->query($sql);

$pa_id = hexdec(uniqid());

$sql = "INSERT INTO part (id, spatialunit_id) VALUES ($pa_id, $su_id) ";
$result = $dal->query($sql);

$os_id = hexdec(uniqid());

$sql = "INSERT INTO operationspatialunit " .
       "(id, spatialunit_id, projectworkdayoperation_id) " .
       "VALUES ($os_id, $su_id, $pwo_id) ";
$result = $dal->query($sql);
    
echo json_encode($su_id);

?>

