<?php 
error_reporting(E_ALL);
include "dbconfig.php";
include 'phpmailer/PHPMailerAutoload.php';		
date_default_timezone_set ("Europe/London");
	
 $reminder_date=date('Y-m-d',strtotime("+8 hours")); 
 $reminder_hours=date("H",strtotime("+8 hours"));
 $reminder_mins=date("i",strtotime("+0 minutes"));
 
 $sql="SELECT employees.pco_number,employees.pco_expiry,employees.address,employees.post_code,employees.phone,
employees.first_name,employees.email as driver_email,employees.phone as driver_phone,
vehicles.reg,vehicles.color,vehicle_make.make,
company_contact.name as passenger,company_contact.email as passenger_email,company_contact.mobile as passenger_phone,
bookings.pickup_date,bookings.pickup_address,bookings.pickup_post_code,bookings.drop_address,
bookings.drop_post_code,bookings.hours,bookings.mins,bookings.id as booking_id
FROM bookings
LEFT JOIN vehicles on vehicles.driver_id=bookings.driver_id
LEFT JOIN vehicle_make on vehicle_make.make=vehicles.make
LEFT JOIN company_contact on bookings.passenger_id=company_contact.id
LEFT JOIN employees on bookings.driver_id=employees.id
WHERE bookings.reminder_status=0 AND bookings.pickup_date='".$reminder_date."' AND bookings.hours='$reminder_hours' AND bookings.mins='$reminder_mins'"; 
 		//echo $sql;
		$result=mysqli_query($con,$sql);
	    $db=mysqli_fetch_assoc($result);
		
$db_date=$db['pickup_date'];
$db_hours=$db['hours'];
$db_mins=$db['mins'];

 function send_driver_email($to,$message,$driver_name)
		 {
		   $driver_email=$to;
		   $driver_message=$message;
		  $driver_name='';
		$mail2 = new PHPMailer;
		$mail2->setFrom('info@limochauffeurs.com', 'Limo Chauffeurs Ltd.');
		$mail2->IsHTML(true);
		$mail2->addAddress($driver_email, $driver_name);
		$mail->AddCC('rajtakkar@yahoo.co.uk', 'Rajesh');
		
		$mail2->Subject  = 'Your Booking Reminder';
		$mail2->Body     = $driver_message;
		if(!$mail2->send()){
			//echo '<h3>Email was not sent</h3>';
			}else{
				//echo 'Mail was sent';
		    }
		 }
		    $res=mysqli_query($con,$sql);
			$passenger_message='';
			$driver_message='';
			
			$rowcount=mysqli_num_rows($res);
			
		if($rowcount>0){
				
			while($driver=mysqli_fetch_assoc($res))
			{
			
			$booking_id=$driver['booking_id'];
			echo $booking_id;
			//Driver
			$driver_email=$driver['driver_email'];
			$driver_phone=$driver['driver_phone'];
			$driver_name=$driver['first_name'];
			$pco_number=$driver['pco_number'];
			$pco_expiry=$driver['pco_expiry'];
			$driver_address=$driver['address'];
			$driver_post_code=$driver['post_code'];
			
			
			//Passenger
			$passenger=$driver['passenger'];
			$passenger_email=$driver['passenger_email'];
			$passenger_phone=$driver['passenger_phone'];
			//Pickup Details
			$pickup_date=$driver['pickup_date'];
			$pickup_address=$driver['pickup_address'];
			$pickup_post_code=$driver['pickup_post_code'];
			$drop_address=$driver['drop_address'];
			$drop_post_code=$driver['drop_post_code'];
			
			$hours=$driver['hours'];
			$mins=$driver['mins'];
			$pickup_time=$hours.":".$mins;
			
			//Car
			$make=$driver['make'];
			$color=$driver['color'];
			$reg=$driver['reg'];
	
		
		// Driver Message
		$driver_message .= '    
		 <p> Dear '.$driver_name.' </p><h3  style="color:#E3060A"> This is your 8 Hour Booking Reminder</h3>
		 <h4>
		 <p><b>Booking Ref: </b>'.$booking_id.'</p>
		 <p><strong>Date: </strong>'.date("d/m/Y",strtotime($pickup_date)).'</p>
		 <p>Time: '.$pickup_time.'</p>
		 <p>Passenger: </b>'.$passenger.'</p>
		 <p>Passenger Phone: '.$passenger_phone.'</p>
		 <p><strong>Pickup From: </strong>'.$pickup_address.','.$pickup_post_code.'</p>
         <p><strong>Drop To: </strong>'.$drop_address.','.$drop_post_code.'</p>
		 <hr>
		 <p>LIMO CHAUFEURS LTD. Contact Number - 0208 230 4594 M:- 07808939220</p>
		
		 ';
		if($reminder_date==$db_date && $reminder_hours==$reminder_hours && $reminder_mins==$reminder_mins)
			 {
				 $send_mail=send_driver_email('jaspinder32@gmail.com',$driver_message,$driver_name);
				 
			 }
		
		    }//while lopp
		} // if(rowcount>0
		

