<?php
require('auth-validate.php');
require('../../db.php');


$id_user = $_SESSION['id_user'];
$id_file_row = isset($_REQUEST['id_file_row']) ? $_REQUEST['id_file_row'] : null;

//example: 06-09-2016 2:32 AM
$time_pickup = isset($_REQUEST['time_pickup']) ? $_REQUEST['time_pickup'] : null;
$time_depart = isset($_REQUEST['time_depart']) ? $_REQUEST['time_depart'] : null;
$bol_delivered = isset($_REQUEST['bol_delivered']) ? $_REQUEST['bol_delivered'] : null;


$stmt = $dbh->prepare(
	"INSERT INTO file_row_update
		(id_user, id_file_row, time_pickup, time_depart, bol_delivered)
	VALUES
		(:id_user, :id_file_row,
			STR_TO_DATE(:time_pickup, '%m/%d/%Y %h:%i %p'),
			STR_TO_DATE(:time_depart, '%m/%d/%Y %h:%i %p'),
			STR_TO_DATE(:bol_delivered, '%m/%d/%Y %h:%i %p')
		)");

try
{
	$ret = $stmt->execute(array(
		':id_user' => $id_user,
		':id_file_row' => $id_file_row,
		':time_pickup' => $time_pickup,
		':time_depart' => $time_depart,
		':bol_delivered' => $bol_delivered
	));
}
catch(Exception $e)
{
	http_response_code(500);
	
	//TODO: probably shouldn't report this internal exception message to the user
	echo $e->getMessage();
	
	return;
}

echo 'OK';


?>