<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "id") 
    $pf_id = $paramValue; 
  else if ($paramName == "foptype_id") 
    $foptype_id = $paramValue;  
  else if ($paramName == "mapareaid") 
    $mapareaid = $paramValue;  
  else if ($paramName == "note") 
    $note = $paramValue;  
  else if ($paramName == "field_descr") 
    $field_descr = $paramValue;  
  else if ($paramName == "office_descr") 
    $office_descr = $paramValue;  
  else if ($paramName == "fieldefined") 
    $fieldefined = $paramValue;  
}

$dal = new DAL();
         
$sql = "SELECT fop_id FROM parcelfop WHERE id = $pf_id LIMIT 1";
$fo_id = $dal->query($sql)->fop_id;

$sql = "UPDATE fop SET foptype_id = $foptype_id, mapareaid='$mapareaid' " .
       "WHERE id = $fo_id ";
$result = $dal->query($sql);

$sql = "UPDATE parcelfop SET office_descr='$office_descr', note='$note', " .
       "field_descr='$field_descr', fieldefined=$fieldefined " .
       "WHERE id = $pf_id " ;
$result = $dal->query($sql);
    
echo json_encode($pf_id);

?>

