<?php


ini_set('session.gc_maxlifetime', 30*60);

session_start();

include '../../../includes/config.php';





$Trip_ID = $_GET['Trip_ID'];
	$Max_Limit_Riders = $_GET['Max_Limit_Riders'];	
	$Gender = $_GET['Gender'];
	$Total_KM_Distance = $_GET['Total_KM_Distance'];	

	$Date = $_GET['Date'];
	$D_ID = $_GET['D_ID'];	


	$lng1 = $_GET['lng1'];	
	$lat1 = $_GET['lat1'];	
	$lng2 = $_GET['lng2'];	
	$lat2 = $_GET['lat2'];	
	$From_Location = $_GET['From_Location'];	
	$To_Location = $_GET['To_Location'];
	
	
	$sql11 = mysqli_query($dbConn,"select * from trips where ID='$Trip_ID'");
	$row11 = mysqli_fetch_array($sql11);
	$From_Time = $row11['From_Time'];
	$Current_Total_Riders = $row11['Current_Total_Riders'];
	
	

$sql2 = mysqli_query($dbConn,"select * from drivers_trips_cancelation where Driver_ID='$D_ID' AND Date='$Date'");
if (mysqli_num_rows($sql2)>0){
	
	$PA = $Current_Total_Riders*0.50;
	
	
	echo "<script language='JavaScript'>
			  alert ('Sorry ... penalty amount with ($PA JOD) has been added to your penalty balance !');
      </script>";
	  
	  
	  
	  $sql3 = mysqli_query($dbConn,"insert into drivers_trips_cancelation (Trip_ID,Driver_ID,Date) values ('$Trip_ID','$D_ID','$Date')");
	
	$sql4 = mysqli_query($dbConn,"update trips_users set Total_Price_All_Riders='0', Notes='Trip canceled by driver' where Status!='Dropoff' AND Trip_ID='$Trip_ID'");

	$sql5 = mysqli_query($dbConn,"update trips set Status='Canceled' where ID='$Trip_ID'");
	
		$sql6 = mysqli_query($dbConn,"select * from drivers where ID='$D_ID'");
		$row6 = mysqli_fetch_array($sql6);
		
		$Penalty_Balance = $row6['Penalty_Balance'];
		
		$New_Penalty_Balance = $Penalty_Balance + $PA;
		
		
		
	$sql7 = mysqli_query($dbConn,"update drivers set Penalty_Balance='$New_Penalty_Balance' where ID='$D_ID'");

	
	
	
	
	
	

	
	echo '<script language="JavaScript">
 document.location="../index.php";
</script>';


	
}else{
	
	$sql3 = mysqli_query($dbConn,"insert into drivers_trips_cancelation (Trip_ID,Driver_ID,Date) values ('$Trip_ID','$D_ID','$Date')");
	
	$sql4 = mysqli_query($dbConn,"update trips_users set Total_Price_All_Riders='0', Notes='Trip canceled by driver' where Status!='Dropoff' AND Trip_ID='$Trip_ID'");

	$sql5 = mysqli_query($dbConn,"update trips set Status='Canceled' where ID='$Trip_ID'");
	
	
	
	
	echo '<script language="JavaScript">
 document.location="../index.php";
</script>';






	
}
	
	


?>
