<?php






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

session_start();

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



$D_ID = $_SESSION['D_Log'];




if (!$_SESSION['D_Log'])
echo '<script language="JavaScript">
 document.location="../../Drivers-Sign-In.php";
</script>';







$sql3 = mysqli_query($dbConn,"select * from drivers where ID='$D_ID'");
					$row3 = mysqli_fetch_array($sql3);
$Name=$row3['Name'];
$Phone_Number=$row3['Phone_Number'];
$Gender=$row3['Gender'];
$Photo=$row3['Photo'];
$lon=$row3['Longitude'];
$lat=$row3['Latitude'];
$Total_Rates=$row3['Total_Rates'];
$Car_Type=$row3['Car_Type'];
$Car_Color=$row3['Car_Color'];
$Penalty_Balance=$row3['Penalty_Balance'];
$Credit_Balance=$row3['Credit_Balance'];
$Total_Need_Balance=$row3['Total_Need_Balance'];
$Avalability_Status=$row3['Avalability_Status'];





	$TP_ID = $_GET['TP_ID'];
	$User_ID = $_GET['User_ID'];
	$Driver_ID = $_GET['Driver_ID'];
	
	
	
	
	
	

$sql = mysqli_query($dbConn,"select * from trips_privates where ID='$TP_ID'");
$row = mysqli_fetch_array($sql);


$Gender = $row['Gender'];
$Total_KM_Distance = $row['Total_KM_Distance'];
$Date = $row['Date'];
$From_Location = $row['From_Location'];
$To_Location = $row['To_Location'];
$lng1 = $row['From_Longitude'];
$lat1 = $row['From_Latitude'];
$lng2 = $row['To_Longitude'];
$lat2 = $row['To_Latitude'];
$Driver_ID = $row['Driver_ID'];
$Payment_Type = $row['Payment_Type'];
$Total_Riders = $row['Total_Riders'];
$Total_Price = $row['Total_Price'];



$sql3 = mysqli_query($dbConn,"select * from users where ID='$User_ID'");
$row3 = mysqli_fetch_array($sql3);
$U_Name = $row3['Name'];
$U_Photo = $row3['Photo'];
$U_Phone_Number = $row3['Phone_Number'];



if(isset($_POST['Submit']))
{
	
	
	
	$TP_ID = $_POST['TP_ID'];
	$User_ID = $_POST['User_ID'];
	$Driver_ID = $_POST['Driver_ID'];
	
	
	$sql112233 = mysqli_query($dbConn,"select * from trips_privates where ID='$TP_ID'");
	$row112233 = mysqli_fetch_array($sql112233);
	$Trip_Driver_ID = $row112233['Driver_ID'];
	
	if ($Trip_Driver_ID!='0'){
		
		
	echo "<script language='JavaScript'>
			  alert ('Sorry ... your late ... another driver take the trip !');
      </script>";	
		
		

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

	
	
	
	$From_Time = date("H:i");
	
	
	$sql1 = mysqli_query($dbConn,"update trips_privates set From_Time='$From_Time', Driver_ID='$Driver_ID', Status='Accepted' where ID='$TP_ID'");
	

	
$sqlcheck2 = mysqli_query($dbConn,"select * from users where ID='$User_ID'");
$rowcheck2 = mysqli_fetch_array($sqlcheck2);
		
$UU_ID = $rowcheck2['U_ID'];
$User_Phone_Type = $rowcheck2['Phone_Type'];
	

if ($User_Phone_Type=='Android'){
	
	
	
	  function sendMessage($UU_ID){
        
        
        
        
        
        $content = array(
            "en" => 'Your trip has been accepted by the driver !'
            );
        
        $fields = array(
            'app_id' => "XXXXXXXXXXXXXXXXXXXXXX",
            'include_player_ids' => array($UU_ID),
            'data' => array("foo" => "bar"),
            'contents' => $content
        );
        
        $fields = json_encode($fields);
       // print("\nJSON sent:\n");
       // print($fields);
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        
        return $response;
    }
    
    $response = sendMessage($UU_ID);
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    
   // print("\n\nJSON received:\n");
   //    print($return);
   // print("\n");


}else{
	
	
	
   
	 function sendMessage($UU_ID){
        
        
        
        
        
        $content = array(
            "en" => 'Your trip has been accepted by the driver !'
            );
        
        $fields = array(
            'app_id' => "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            'include_player_ids' => array($UU_ID),
            'data' => array("foo" => "bar"),
            'contents' => $content
        );
        
        $fields = json_encode($fields);
       // print("\nJSON sent:\n");
       // print($fields);
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        
        return $response;
    }
    
    $response = sendMessage($UU_ID);
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    
   // print("\n\nJSON received:\n");
   //    print($return);
   // print("\n");	
	
	
	
	
}




	echo '<script language="JavaScript">
 document.location="private-mix-gender-2.php?Driver_ID='.$Driver_ID.'&User_ID='.$User_ID.'&TP_ID='.$TP_ID.'";
</script>';



	}
		
	


}






if(isset($_POST['Submit2']))
{

	$TP_ID = $_POST['TP_ID'];
	$User_ID = $_POST['User_ID'];
	$Driver_ID = $_POST['Driver_ID'];
	
	
	
	
echo '<script language="JavaScript">
 document.location="reject-trip.php?Driver_ID='.$Driver_ID.'&User_ID='.$User_ID.'&TP_ID='.$TP_ID.'";
</script>';	
	
	
	
}


?>

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../../../css/bootstrap.min.css">
    <!-- FontAwesome -->
    <link rel="stylesheet" href="../../../css/fontawesome.css">
    <!-- Main Style -->
    <link rel="stylesheet" href="../../../css/styles.css">
		    <link rel="shortcut icon" href="../../../images/icon.ico"/>

    <title>Confirm private mix gender</title>
	
	    <link rel="shortcut icon" href="../../../images/icon.ico"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0"/>


    

		<style>
@font-face {
   font-family: myFirstFont;
   src: url(../../../fonts/Arial-Rounded-MT-Bold-Regular.ttf);
   font-size:8px;
}

body {
   font-family: myFirstFont !important;
}


@font-face {
   font-family: myFirstFont2;
   src: url(../../../fonts/GE-SS-Two-Bold.otf);
   font-size:8px;
}





::-webkit-input-placeholder { /* Edge */
  color: white !important;
}

:-ms-input-placeholder { /* Internet Explorer 10-11 */
  color: white !important;
}

::placeholder {
  color: white !important;
}


</style>



</head>
<body style="height:auto !important">

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script type="text/javascript">
        function getLocation() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function(position) {
                    var latitude = position.coords.latitude;
                    var longitude = position.coords.longitude;

                    // Send this to your PHP script via AJAX or other means
                    sendDataToServer(latitude, longitude);
                });
            } else {
                alert("Geolocation is not supported by this browser.");
            }
        }

        function sendDataToServer(latitude, longitude) {
            // Using fetch API to send data to PHP
            fetch('update-my-location-1.php?D_ID=<?php echo $D_ID; ?>	', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    latitude: latitude,
                    longitude: longitude
                })
            })
            .then(response => response.json())
            .then(data => {
                console.log('Success:', data);
            })
            .catch((error) => {
                console.error('Error:', error);
            });
        }

        // Keep updating every 5 seconds
        setInterval(getLocation, 5000);
    </script>


<!--Loading Container Start-->
<div id="load" class="loading-overlay display-flex flex-column justify-content-center align-items-center">
    <div class="primary-color font-28 fas fa-spinner fa-spin"></div>
</div>
<!--Loading Container End-->


<div class="row h-100">
    <div class="col-xs-12 col-sm-12 remaining-height">

 <!--Page Title & Icons Start-->
        <div class="header-icons-container text-center">
           
                <span class="float-left menu-open closed">
                    <img src="../../../icons/menu.svg" alt="Menu Hamburger Icon">
            </span>
            <span class="title"><br>Confirm private mix gender</span>
            <a href="#">
<span class="float-right" style="margin-top:-27px !important">
                    <img src="../../../images/icon.png" alt="Logo" width="14px" height="20px">
                </span>
            </a>
        </div>
        <!--Page Title & Icons End-->

       
  			<br><br><br>

     
				
		
		<form action="private-mix-gender.php?TP_ID=<?php echo $TP_ID ;?>" method="post"/>
	 <input type="hidden" name="TP_ID" value="<?php echo $TP_ID; ?>"/>
	 <input type="hidden" name="Driver_ID" value="<?php echo $D_ID; ?>"/>
	 <input type="hidden" name="User_ID" value="<?php echo $User_ID; ?>"/>
				
		
      <div class="rest-container new-request" style="margin-top:-150px">
            <div class="all-history-items all-history-items-driver remaining-height">

                <!--Request Item Container Start-->
                <div class="request-item-container">
                    <div class="profile-picture text-center">
                        <img src="../../../../Users_App/EN/Users/<?php echo $U_Photo; ?>" style="border-radius: 50%;" width="120px" alt="Profile Picture">
                    </div>
                    <div class="history-items-container">
                        <div class="history-item">

                            <!--Profile Information Container Start-->
                            <div class="profile-information text-center">
                                <div class="profile-information">
                                    <div class="profile-name font-18"><?php echo $U_Name; ?></div>
                                    <div class="profile-name font-18"><?php echo $U_Phone_Number; ?></div>
                                </div>
                            </div>
                            <!--Profile Information Container End-->

                            
								
								
                            <!--Wishes Container End-->
							
							
							<br>
							
							 <!--Google Maps Start-->
                        <div id="map1"></div>
                        <!--Google Maps End-->
						
						
						

                            <!--Address Container Start-->
                            <div class="addresses-container position-relative">
                                <div class="height-auto">
                                    <div class="w-100 map-input-container map-input-container-top">
                                        <span class="fas fa-location-arrow location-icon-rotate map-input-icon"></span>
                                        <div class="map-input mr-0 display-flex">
                                            <input class="controls flex-1 font-weight-light" type="text"
                                                   placeholder="Enter an origin location" value="<?php echo $From_Location; ?>" disabled>
                                        </div>
                                    </div>
                                    <a href="" class="href-decoration-none">
                                        <div class="w-100 map-input-container map-input-container-bottom">
                                            <span class="map-input-icon">
                                                <img src="../../../icons/circle.svg"  alt="Current Location Icon">
                                            </span>
                                            <div class="map-input mr-0 display-flex border-0 controls flex-1 font-weight-normal align-items-center">
                                                <?php echo $To_Location; ?>
                                            </div>
                                            <span class="dotted-line"></span>
                                        </div>
                                    </a>
                                </div>
                            </div>
                            <!--Address Container End-->

                            <!--All Trip Fares Container Start-->
                            <div class="all-trip-fares trip-fare-request">
                                <div class="border-bottom-primary border-bottom-light-grey">
                                    <div class=" trip-fare">	Trip information</div>
                                </div>
                                <div class="trip-fare-container trip-fare-driver font-weight-light">
								
								
								
									
								

								 <!--Trip Fares Item Container Start-->
                                    <div class="trip-fare-item">
                                        <span class="float-left">Total riders</span>
                                        <span class="float-right blue-price"><?php echo $Total_Riders; ?></span>
                                        <span class="clearfix"></span>
                                    </div>
                                    <!--Trip Fares Item Container End-->


									
									
									
									
									
								
									
									
									
									<div class="trip-fare-item">
                                <span class="float-left">Trip price</span>
                                <span class="float-right blue-price"><?php echo $Total_Price; ?> JOD</span>
                                <span class="clearfix"></span>
                            </div>
							
							
							<div class="trip-fare-item">
                                <span class="float-left">Total riders</span>
                                <span class="float-right blue-price"><?php echo $Total_Riders; ?></span>
                                <span class="clearfix"></span>
                            </div>
							
                            <div class="trip-fare-item">
                                <span class="float-left">Total km distance</span>
                                <span class="float-right blue-price"><?php echo $Total_KM_Distance; ?> KM</span>
                                <span class="clearfix"></span>
                            </div>								



									<!--Trip Fares Item Container Start-->
                                    <div class="trip-fare-item">
                                        <span class="float-left">Payment type</span>
                                        <span class="float-right blue-price"><?php echo $Payment_Type; ?></span>
                                        <span class="clearfix"></span>
                                    </div>
                                    <!--Trip Fares Item Container End-->	



									
                                </div>
                            </div>
                            <!--All Trip Fares Container End-->

                            <!--Accept or Decline Container Start-->
                            <div class="request-btn-container display-flex justify-content-between">
                                 <div class="request-btn">
								                                    <button style="height:50px; font-size: 16px; border-style: dashed; width:150px !important; border-style: dashed; border-radius: 50px; color:#011F39; border-color:#B3E207; background-color:#ebebeb" type="submit" name="Submit"  class="btn btn-primary w-100 font-weight-light ">Accept</button>

                                                          </div>
														  
								
								<div class="request-btn">
								                                    <button style="height:50px; font-size: 16px; border-style: dashed; width:150px !important; border-style: dashed; border-radius: 50px; color:red; border-color:#B3E207; background-color:#ebebeb" type="submit" name="Submit2"  class="btn btn-primary w-100 font-weight-light ">Decline</button>
                                </div>
                               
                            </div>
                            <!--Accept or Decline Container End-->

                        </div>
                    </div>
                </div>
                <!--Request Item Container End-->

               


            </div>
        </div>
						
				
		
		
				
						









        
    </div>

    <?php
   include 'menu.php';
   ?>

 
<script>
$(document).ready(function(){
    "use strict";
});
var map1;
var markerArray = [];
function initMap1() {
    var myOptions = {
        zoom: 14,
        disableDefaultUI: true
    };
    var oneMoreMapExists = true;
    var i =1;
    var originDestinationObj = [
        {
            origin: "<?php echo $From_Location; ?>",
            destination: "<?php echo $To_Location; ?>"
        },
       
    ];
    while(oneMoreMapExists){
        if($('#map'+i).length>0){
            var directionsDisplay1 = new google.maps.DirectionsRenderer;
            var directionsService1 = new google.maps.DirectionsService;
            var map1 = new google.maps.Map(document.getElementById('map'+i), myOptions);
            directionsDisplay1.setMap(map1);
            calculateAndDisplayRoute(originDestinationObj[i-1].origin,
                originDestinationObj[i-1].destination,
                directionsService1,
                directionsDisplay1,
                markerArray);
            i++;
        }
        else{
            oneMoreMapExists = false;
        }
    }
}

function calculateAndDisplayRoute(origin,destination, directionsService, directionsDisplay, markerArray) {
    for (var i = 0; i < markerArray.length; i++) {
         markerArray[i].setMap(null);
    }
    var icons = {
        start: new google.maps.MarkerImage(
            // URL
            '../icons/circle.svg',
            // (width,height)
            new google.maps.Size( 16, 16 ),
            // The origin point (x,y)
            new google.maps.Point( 0, 0 ),
            // The anchor point (x,y)
            new google.maps.Point( 0, 8 )
        ),
        end: new google.maps.MarkerImage(
            // URL
            '../images/end.png',
            // (width,height)
            new google.maps.Size( 58, 53 ),
            // The origin point (x,y)
            new google.maps.Point( 0, 0 ),
            // The anchor point (x,y)
            new google.maps.Point( 22, 32 )
        )
    };
    directionsService.route({
        origin: origin,
        destination: destination,
        travelMode: google.maps.TravelMode['DRIVING'],
        provideRouteAlternatives: true
    }, function (response, status) {
        if (status == 'OK') {
            directionsDisplay.setDirections(response);
            var leg = response.routes[0].legs[0];
            console.log(response);
            makeMarker1(leg.start_location, icons.start, "Route Start");
            makeMarker1(leg.end_location, icons.end, 'Route End');
        } else {
            window.alert('Directions request failed due to ' + status);
        }
    });
	
	
	
	
  
  
  
}
// }
function makeMarker1( position, icon, title, listener=true) {
    console.log(position);
    console.log(icon);
    var marker = new google.maps.Marker({
        position: position,
        map: map1,
        icon: icon,
        title: title,
        animation: google.maps.Animation.DROP,
    });
    markerArray.push(marker);
}






  
  
</script>


<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDemEmJPVUC9PoCzTLZLZdhwJLt5fu5XUc&libraries=places&callback=initMap1"></script>




</body>
</html>