<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "rowid")
    $ve_id = $paramValue;
  elseif ($paramName == "selid") 
    $pw_id = $paramValue;  
}

$dal = new DAL();
   
$tr_id = hexdec(uniqid());
  
$sql = "INSERT INTO travel (id, destination, vehicle_id) VALUES ($tr_id, 'to', $ve_id) " ;
$result = $dal->query($sql);

$sql = "SELECT TR.id, CONCAT (VE.name, ' (', VE.seating, ') ', VE.descr) text, 0 added " .
       "FROM (travel TR, vehicle VE, projectworkdaypersonnel PP) " .
       "LEFT JOIN personneltravel PT ON PT.travel_id = TR.id " .
       "WHERE PT.projectworkdaypersonnel_id = PP.id " .
       "AND PP.projectworkday_id = $pw_id AND TR.destination = 'from' " .
       "AND VE.id = TR.vehicle_id " .
       "GROUP BY TR.id " .
       "UNION " .
       "SELECT TR.id, CONCAT (VE.name, ' (', VE.seating, ') ', VE.descr) text, 2 added " .
       "FROM vehicle VE, travel TR WHERE VE.id = TR.vehicle_id AND TR.id = $tr_id ";         
$result = $dal->query($sql);

echo json_encode($result);

?>

