<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "scopeid") 
    $pwo_id = $paramValue;  
  else if ($paramName == "id") 
    $su_id = $paramValue;  
  else if ($paramName == "selectpart_name") 
    $part_name_id = $paramValue;  
  else if ($paramName == "loc_descr") 
    $loc_descr = $paramValue;  
  else if ($paramName == "longaxis") 
    $longaxis = $paramValue;  
  else if ($paramName == "shortaxis") 
    $shortaxis = $paramValue;  
  else if ($paramName == "longdirection_id") 
    $longdirection_id = $paramValue;  
  else if ($paramName == "mapareaid") 
    $mapareaid = $paramValue;  
  else if ($paramName == "topography_id") 
    $topography_id = $paramValue;  
  else if ($paramName == "landuse_id") 
    $landuse_id = $paramValue;  
  else if ($paramName == "add_descr") 
    $add_descr = $paramValue;  
}

if ("null" == $part_name_id)
  $part_name_id = $su_id;

$dal = new DAL();
  
$sql = "SELECT name FROM spatialunit WHERE id = $part_name_id LIMIT 1";
$part_name = $dal->query($sql)->name;
  
$sql = "UPDATE spatialunit ". 
       "SET name='$part_name', longaxis='$longaxis', shortaxis='$shortaxis', " .
       "mapareaid='$mapareaid', longdirection_id=$longdirection_id " .
       "WHERE id = $su_id ";
$result = $dal->query($sql);

$sql = "UPDATE part ". 
       "SET location='$loc_descr', topography_id=$topography_id, landuse_id=$landuse_id, descr='$add_descr' " .
       "WHERE spatialunit_id = $su_id ";
$result = $dal->query($sql);
    
echo json_encode($su_id);

?>

