<?php

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

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

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

    $poo_id = hexdec(uniqid());
  
    if ($from == "leftmulOpObservers" && $to == "rightmulOpObservers") {
      $sql = "INSERT INTO projectworkdayoperationobserver " .
             "(id, projectworkdayoperation_id, projectworkdayobserver_id) " .
             "VALUES ($poo_id, $pwo_id, $pob_ids[$i]) " ;
      $result = $dal->query($sql);
    }       

    else if ($from == "rightmulOpObservers" && $to == "leftmulOpOpobservers") {
      $sql = "DELETE FROM projectworkdayoperationobserver " .
             "WHERE projectworkdayobserver_id = $pob_ids[$i] " .
             "AND projectworkdayoperation_id = $pwo_id ";

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

echo json_encode($result);

?>

