<?php

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

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

if (isset($_REQUEST["move"])) {
  $move = explode (",", $_REQUEST["move"]);
  
  $lc_id  = array_pop ($move);
  $to     = array_pop ($move);
  $from   = array_pop ($move);
  $in_ids = $move;

  $dal = new DAL();
  
  for ($i=0; $i<count($in_ids); $i++) {
      
    if ($from == "leftmulCompInclusions" && $to == "rightmulCompInclusions") {

      $lci_id = hexdec(uniqid());
  
      $sql = "INSERT INTO lotcompositioninclusion " .
             "(id, inclusion_id, lotcomposition_id) " .
             "VALUES ($lci_id, $in_ids[$i], $lc_id) " ;
      $result = $dal->query($sql);
    }       

    else if ($from == "rightmulCompInclusions" && $to == "leftmulCompInclusions") {
      $sql = "DELETE FROM lotcompositioninclusion " .
             "WHERE inclusion_id = $in_ids[$i] AND lotcomposition_id = $lc_id ";

      $result = $dal->query($sql);
    }
  }
}

echo json_encode($result);

?>

