<?php

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

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

  $dal = new DAL();
//print_r ("in ajax: $pwo_id $from $to $pwp_ids[0]");    
  for ($i=0; $i<count($pwp_ids); $i++) {

    $pop_id = hexdec(uniqid());

    if ($from == "leftmovoperationcrew" && $to == "rightmovoperationcrew") {
      
      $sql = "INSERT INTO projectworkdayoperationpersonnel " .
             "(id, projectworkdayoperation_id, projectworkdaypersonnel_id) " .
             "VALUES ($pop_id, $pwo_id, $pwp_ids[$i]) " ;
      $result = $dal->query($sql);
    }       

    else if ($from == "rightmovoperationcrew" && $to == "leftmovoperationcrew") {
      $sql = "DELETE FROM projectworkdayoperationpersonnel " .
             "WHERE projectworkdaypersonnel_id = $pwp_ids[$i] " .
             "AND projectworkdayoperation_id = $pwo_id ";

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

echo json_encode($result);

?>

