<?php
require_once("../dbconfig.php");
include "../dbfunction.php";
/*
echo '<pre>';
print_r($_POST);
echo '</pre>';
*/
$end_date="";
$start_date="";
if (isset($_POST['booking_id'])) {
   

   // get values 
   if(isset($_POST['booking_id']))
   {
   $booking_id = $_POST['booking_id'];
   }
   else
   {
   $booking_id="";
   }
    if(isset($_POST['driver_id']))
   {
   $driver_id = $_POST['driver_id'];
   }
   else
   {
   $driver_id="";
   }
   if(isset($_POST['old_customer_id']))
   {
   $customer_id = $_POST['old_customer_id'];
   }
   else
   {
   $customer_id="";
   }
   // if passenger is changed ///////////////////
    if(isset($_POST['old_contact_id']))
	{
	$passenger_id = $_POST['old_contact_id'];
	}
	else
	{
    $passenger_id="";
	}
	if(isset($_POST['passenger_name']))
	{
	$passenger_name = $_POST['passenger_name']; 
	}
	else
	{
	$passenger_name="";
	}
	if(isset($_POST['contact_mobile']))
	{
	$phone = $_POST['contact_mobile'];
   }
   else
   {
   $phone="";
   }
   if(isset($_POST['contact_email']))
   {
   $email = $_POST['contact_email'];
   }
   else
   {
   $email="";
   }
  
   if(isset($_POST['bags']))
   {
   $bags = $_POST['bags'];
   }
   else
   {
   $bags="";
   }
   if(isset($_POST['client_reference']))
   {
   $client_reference=$_POST['client_reference'];
   }
   else
   {
   $client_reference="";
   }
   if($passenger_id==''){
	   // now also create a new record of this passenger
	   $condition=array("customer_id"=>$customer_id,"name"=>$passenger_name,"mobile"=>$phone,"email"=>$email,);
	   $passenger_id=insert($con,"company_contact",$condition,true);	
   }else{
	  //////// update comanpy_contact data anwyay
	      $sql="UPDATE `company_contact` SET
		  name='$passenger_name',
		  mobile='$phone',
		  email='$email'
		  WHERE id=$passenger_id";
		  $result=$con->query($sql);
		  //echo "passenger ssql".$sql."<br>";
   }
   
   ///////////////////////////////////////////
   if(isset($_POST['job_type']))
   {
   $job_type=$_POST['job_type'];
   }
   else
   {
   $job_type="";
   }
   if(isset($_POST['start_date']))
   {
  // $start_date=$_POST['start_date'];
 //  $start_date = date("Y-m-d", strtotime(str_replace('/', '-', $_POST['start_date'])));
  $start_date=$con->real_escape_string($_POST['start_date']);
		  $start_date = str_replace('/', '-', $start_date);
		 $b = explode('-',$start_date);
		 $start_date = $b[2].'-'.$b[1].'-'.$b[0];
   }
   else
   {
   $start_date="";
   }
   if(isset($_POST['end_date']))
   {
  // $end_date=$_POST['end_date'];
  // $end_date = date("Y-m-d", strtotime(str_replace('/', '-', $_POST['end_date'])));
  $end_date=$con->real_escape_string($_POST['end_date']);
		 $end_date = str_replace('/', '-', $end_date);
		 $a = explode('-',$end_date);
		 $end_date = $a[2].'-'.$a[1].'-'.$a[0];
   }
   else
   {
   $end_date="";
   }
   if(isset($_POST['rate']))
   {
   $rate=$_POST['rate'];
   }
   else
   {
   $rate="";
   }
    if(isset($_POST['supp_cost']))
   {
   $supp_cost=$_POST['supp_cost'];
   }
   else
   {
   $supp_cost="";
   }
   if(isset($_POST['pickup_date']))
   {
   $pickup_date=$con->real_escape_string($_POST['pickup_date']);
		 $pickup_date = str_replace('/', '-', $pickup_date);
		 $pickup_date = date("Y-m-d", strtotime($pickup_date));
	}
	else
	{
	$pickup_date="";
	}	 
	if(isset($_POST['hours']))
	{
   $hours = $_POST['hours'];
   }
   else
   {
   $hours="";
   }
   if(isset($_POST['mins']))
   {
   $mins = $_POST['mins'];
   }
   else
   {
   $mins="";
   }
   if(isset($_POST['pickup_address']))
   {
   $pickup_address = $_POST['pickup_address'];
   }
   else
   {
   $pickup_address="";
   }
   if(isset($_POST['pickup_post_code']))
   {
   $pickup_post_code = $_POST['pickup_post_code'];
   }
   else
   {
   $pickup_post_code="";
   }
   if(isset($_POST['drop_address']))
   {
   $drop_address = $_POST['drop_address'];
   }
   else
   {
   $drop_address="";
   }
   if(isset($_POST['drop_post_code']))
   {
   $drop_post_code = $_POST['drop_post_code'];
   }
   else
   {
   $drop_post_code="";
   }
   if(isset($_POST['passengers']))
   {
   $passengers = $_POST['passengers'];
   }
   else
   {
   $passengers="";
   }
   if(isset($_POST['vehicle']))
   {
   $vehicle_id = $_POST['vehicle'];
   }
   else
   {
   $vehicle_id="";
   }
   if(isset($_POST['job_status']))
   {
   $job_status = $_POST['job_status'];
   }
   else
   {
   $job_status="";
   }
   if(isset($_POST['comments']))
   {
   $comments = $_POST['comments'];
   }
   else
   {
   $comments="";
   }
    if(isset($_POST['days']))
   {
   $days = $_POST['days'];
   }
   else
   {
   $days="";
   }
    if(isset($_POST['flight_no']))
   {
   $flight_no = $_POST['flight_no'];
   }
   else
   {
   $flight_no="";
   }
}
$total_fare=$rate*$days;



$sql1 = "  UPDATE driver_bookings SET
		  
		 
		  days='$days',
		  start_date='$start_date',
		  end_date='$end_date'
		  WHERE booking_id='$booking_id' AND driver_id='$driver_id'
		  
";
$result1=$con->query($sql1);

if($result1){//echo 'success'; 
}


$sql = "  UPDATE`bookings` SET
		  customer_id='$customer_id',
		  passenger_id='$passenger_id',
		  vehicle_id='$vehicle_id',
		  flight_no='$flight_no',
		  
		  pickup_address='$pickup_address',
		  pickup_post_code='$pickup_post_code',
		  pickup_date='$pickup_date',
		  
		  hours='$hours',
		  mins='$mins',
		  passengers='$passengers',
		  drop_address='$drop_address',
		  drop_post_code='$drop_post_code',
		  days='$days',
		  rate='$rate',
		  supp_cost='$supp_cost',
		  total_fare='$total_fare',
		  job_type='$job_type',
		  start_date='$start_date',
		  end_date='$end_date',
		  comments='$comments',
		  bags='$bags',
		  client_reference='$client_reference'
		  WHERE id=$booking_id 
";
//echo "UPDATE sql ".$sql."<br>";
$result=$con->query($sql);

if($result){echo 'success';}



exit;
?>