<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "action") 
    $action = $paramValue;  
  else if ($paramName == "rowid") 
    $row_id = $paramValue;  
  else if ($paramName == "currid")
    $su_id = $paramValue;   
}
$sf_id = 0;
$dal = new DAL();

if ($action == 'insert') {
         
  $sf_id = hexdec(uniqid());

  $sql = "INSERT INTO spatialunitfop " .
         "(id, spatialunit_id, parcelfop_id) " .
         "VALUES ($sf_id, $su_id, $row_id) ";
  $result = $dal->query($sql);
}
else {
  $sql = "DELETE FROM spatialunitfop WHERE id = $row_id  " ;
  $result = $dal->query($sql);
}  
    
echo json_encode($sf_id);

?>

