<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "scopeid") 
    $pwo_id = $paramValue;  
  else if ($paramName == "id") 
    $cu_id = $paramValue;  
  else if ($paramName == "selectsite_name") 
    $site_name_id = $paramValue;  
  else if ($paramName == "site_descr") 
    $site_descr = $paramValue;  
  else if ($paramName == "interpret_id") 
    $interpret_id = $paramValue;  
  else if ($paramName == "site_location") 
    $site_location = $paramValue;  
  else if ($paramName == "planshape_id") 
    $planshape_id = $paramValue;  
  else if ($paramName == "rationale_note") 
    $rationale_note = $paramValue;  
  else if ($paramName == "topography_id") 
    $topography_id = $paramValue;  
  else if ($paramName == "long_axis") 
    $long_axis = $paramValue;  
  else if ($paramName == "mapareaid") 
    $mapareaid = $paramValue;  
  else if ($paramName == "short_axis") 
    $short_axis = $paramValue;  
  else if ($paramName == "orientation_id") 
    $orientation_id = $paramValue;  
  else if ($paramName == "stg2_recommendation") 
    $stg2_recommendation = $paramValue;  
  else if ($paramName == "recommendrationale_id") 
    $recommendrationale_id = $paramValue;  
  else if ($paramName == "bordenizable") 
    $bordenizable = $paramValue;  
  else if ($paramName == "bordenrationale_id") 
    $bordenrationale_id = $paramValue;  
  else if ($paramName == "cultunitnote") 
    $cultunitnote = $paramValue;  
}

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

$dal = new DAL();
  
$sql = "SELECT name FROM culturalunit WHERE id = $cu_id LIMIT 1";
$site_name = $dal->query($sql)->name; 
 
$sql = "UPDATE culturalunit ". 
       "SET name='$site_name', descr='$site_descr', mapareaid='$mapareaid', " .
       "location='$site_location', longaxis='$long_axis', shortaxis='$short_axis', " .
       "orientation_id=$orientation_id, planshape_id=$planshape_id, " .
       "interpret_id=$interpret_id, rationale='$rationale_note', note='$cultunitnote' " .
       "WHERE id = $cu_id ";
$result = $dal->query($sql);

$sql = "UPDATE site " .
       "SET topography_id=$topography_id, bordenizable=$bordenizable, " .
       "bordenrationale_id=$bordenrationale_id, stg2recommendation='$stg2recommendation', " .
       "recommendrationale_id=$recommendrationale_id " .
       "WHERE culturalunit_id = $cu_id ";
$result = $dal->query($sql);
    
echo json_encode($result);

?>

