<?php

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

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

  $dal = new DAL();
  
  for ($i=0; $i<count($ppIds); $i++) {
      
    if ($from == "righttravel_to" && $to == "lefttravel_to") {

      $pt_id = hexdec(uniqid());
  
      $sql = "INSERT INTO personneltravel " .
             "(id, projectworkdaypersonnel_id, travel_id, travelrole_id) " .
             "VALUES ($pt_id, $ppIds[$i], $travelId, 3) " ;
      $result = $dal->query($sql);
    }       

    else if ($from == "lefttravel_to" && $to == "righttravel_to") {
      $sql = "DELETE FROM personneltravel  " .
             "WHERE projectworkdaypersonnel_id = $ppIds[$i] AND travel_id = $travelId ";

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

echo json_encode($result);

?>

