<?php

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

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

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

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

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

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

echo json_encode($result);

?>

