<?php
include('../include/session.php');

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time()); 

$vehicle_id = $_GET['vehicle_id_text'];


$admin_date = $_GET['admin_date'];
$admin_type = $_GET['type_group'];
if ($admin_type=='Other') {
	  $admin_type = $_GET['type_other_text'];
}

$mileage = $_GET['km_reading_text'];
$admin_cost = $_GET['admin_cost_text'];
$provider = $_GET['provider_select'];
$expiry_date = $_GET['expiry_date'];
$document_no = $_GET['document_no_text'];
$notes = $_GET['notes_text'];


$table_name = $_SESSION['db_prefix']."_vehicle_admin";
$fuel_query = "INSERT INTO $table_name (admin_date, vehicle_id, admin_type, mileage, admin_cost,  provider, expiry_date, document_no, notes) VALUES ('".$admin_date."', '".$vehicle_id."', '".$admin_type."', '".$mileage."', '".$admin_cost."', '".$provider."', '".$expiry_date."', '".$document_no."', '".$notes."' ) ";
execsql($fuel_query);

if ($admin_type=='Road license') {
	$table_name = $_SESSION['db_prefix']."_vehicle";
	$date_query = "UPDATE $table_name SET road_license_date = '".$expiry_date."' WHERE vehicle_id = '".$vehicle_id."' ";
	execsql($date_query);
}

if ($admin_type=='BA license') {
	$table_name = $_SESSION['db_prefix']."_vehicle";
	$date_query = "UPDATE $table_name SET ba_license_date = '".$expiry_date."' WHERE vehicle_id = '".$vehicle_id."' ";
	execsql($date_query);
}

if ($admin_type=='Insurance') {
	$table_name = $_SESSION['db_prefix']."_vehicle";
	$date_query = "UPDATE $table_name SET insurance = '".$provider."', renewal_date = '".$expiry_date."' WHERE vehicle_id = '".$vehicle_id."' ";
	execsql($date_query);
}


$table_name = $_SESSION['db_prefix']."_tracking_transport";
   $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '44', '".$vehicle_id."' ,'".$admin_type."','','".$mileage."' )";
   $trackingResult = mySQL_query($trackingQuery);



if (isset($_GET['save_close_button']) )
	   { ?>
       <script>
	 		 window.location="../transport/transport_main.php?date=0";
		</script>
        <?php		 
	   }
	   
	if (isset($_GET['save_button']) )
	   {  ?>
       <script>
	        window.location="admin_rec.php?vehicle_id="
	   </script>
        <?php		 
	   }
	   ?>
