<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "move") 
    $move = explode (",",  $paramValue);  
}

$su_id  = array_pop ($move);
$to     = array_pop ($move);
$from   = array_pop ($move);

$dal = new DAL();
  
for ($i=0; $i<count($move); $i++) {

//print_r ("sf:$su_id $to $from $pf_ids[$i]");  

  if ($from == "leftmulFeatureLocation" && $to == "rightmulFeatureLocation") {
    $sf_id = hexdec(uniqid());
    $sql = "INSERT INTO spatialunitfop " .
           "(id, spatialunit_id, parcelfop_id) " .
           "VALUES ($sf_id, $su_id, $move[$i]) " ;
    $result = $dal->query($sql);
  }
    
  else if ($from == "rightmulFeatureLocation"
      && $to == "leftmulFeatureLocation") {
    $sql = "DELETE FROM spatialunitfop  " .
           "WHERE parcelfop_id = $move[$i] AND spatialunit_id = $su_id ";
    $result = $dal->query($sql);
  }
}

echo json_encode($result);

?>

