<?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, 'from', $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 PWP) " .
       "LEFT JOIN personneltravel PT ON PT.travel_id = TR.id " .
       "WHERE PT.projectworkdaypersonnel_id = PWP.id " .
       "AND PWP.projectworkevent_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);

?>

