<?php


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

session_start();

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



$U_ID = $_SESSION['U_Log'];




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





$sql3 = mysqli_query($dbConn,"select * from users where ID='$U_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'];


$U_ID = $_GET['U_ID'];	
$Trip_ID = $_GET['Trip_ID'];	
$Driver_ID = $_GET['Driver_ID'];
$TU_ID = $_GET['TU_ID'];
$Spot_Number = $_GET['Spot_Number'];


$sql1 = mysqli_query($dbConn,"select * from trips_users where ID='$TU_ID'");
$row1 = mysqli_fetch_array($sql1);
$From_Longitude=$row1['From_Longitude'];
$From_Latitude=$row1['From_Latitude'];
$Total_Riders=$row1['Total_Riders'];

	
	
	

?>

<!doctype html>
<html lang="ar" dir="rtl">
<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">
    <title>موقع سائقك المباشر</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/GE-SS-Two-Bold.otf);
   font-size:8px;
}

body {
   font-family: myFirstFont !important;
}


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



</style>



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load').load('check-confirm-pickup-2.php?Spot_Number=<?php echo $Spot_Number; ?>&Trip_ID=<?php echo $Trip_ID; ?>&U_ID=<?php echo $U_ID; ?>&Driver_ID=<?php echo $Driver_ID; ?>').fadeIn("slow");
}, 60000);


var auto_refresh2 = setInterval(
function ()
{
$('#load2').load('check-more-trips-same-road.php?Driver_ID=<?php echo $Driver_ID; ?>&Spot_Number=<?php echo $Spot_Number; ?>&From_Page=66&Payment_Type=<?php echo $Payment_Type; ?>&Total_Price_All_Riders=<?php echo $Total_Price_All_Riders; ?>&Total_Price=<?php echo $Total_Price; ?>&Total_KM_Distance=<?php echo $Total_KM_Distance; ?>&To_Location=<?php echo $To_Location; ?>&From_Location=<?php echo $From_Location; ?>&To_Latitude=<?php echo $To_Latitude; ?>&To_Longitude=<?php echo $To_Longitude; ?>&From_Latitude=<?php echo $T_From_Latitude; ?>&From_Longitude=<?php echo $T_From_Longitude; ?>&Total_Riders=<?php echo $T_Total_Riders; ?>&Gender=<?php echo $T_Gender; ?>&Spot_Number=<?php echo $Spot_Number; ?>&Trip_ID=<?php echo $Trip_ID; ?>&U_ID=<?php echo $U_ID; ?>&Driver_ID=<?php echo $Driver_ID; ?>').fadeIn("slow");
}, 5000);



</script>


 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDemEmJPVUC9PoCzTLZLZdhwJLt5fu5XUc&libraries=places"></script>
    <script>
        function initializeMap() {
			
			
			
            var mapOptions = {
                center: new google.maps.LatLng(<?php echo $From_Latitude; ?>, <?php echo $From_Longitude; ?>),
                zoom: 15,

                mapTypeId: google.maps.MapTypeId.roadmap  
            };
			
  
            var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
			const trafficLayer = new google.maps.TrafficLayer();
			trafficLayer.setMap(map);
			
				
				var marker = new google.maps.Marker({
				position: { lat: <?php echo $From_Latitude; ?>, lng: <?php echo $From_Longitude; ?> },
        map: map,
		icon: "../user-icon.png", // Path to your car icon

        title: 'موقع التحميل' // Set the title for the marker
    });


var infoWindow = new google.maps.InfoWindow({
        content: 'موقع التحميل'
    });
	
	
	marker.addListener('click', function() {
        infoWindow.open(map, marker);
    });



            function updateLocations() {

				
				
				
                fetch("get-driver-location-2-2.php?Driver_ID=<?php echo $Driver_ID; ?>")
                .then(response => response.json())
                .then(data => {
					
						
                    

                        var driver = data[0];
						
						
                        var marker2 = new google.maps.Marker({
                            position: new google.maps.LatLng(driver.Latitude, driver.Longitude),
                            map: map,
                            icon: "../car-icon.png",
                            title: driver.Name
                        });
						
						
						



						

                        var infoWindow = new google.maps.InfoWindow({
                            content: 
							
							
							
							"<div><center><img src='../../../../Drivers_App/EN/Drivers/" + driver.Photo + "'/><br><br>"+
							"<div><strong>اسم السائق: " + driver.Name + "</strong>"+
							"<div><strong>جنس السائق: " + driver.Gender + "</strong>"+
							"<div><strong>رقم اللوحة: " + driver.Car_Plat_Number + "</strong>"+
							"<div><strong>نوع السيارة: " + driver.Car_Type + "</strong>"+
							"<div><strong>لون السيارة: " + driver.Car_Color + "</strong>"+
							"<div><strong>رقم الهاتف: " + driver.Phone_Number + "</strong></div>"+
							
							
							
							
							"<br><br>"+
							"<center><a style='border-style: dashed; border-radius: 50px; color:#011F39; border-color:#B3E207; background-color:#ebebeb'class='btn btn-sm btn-center ' href='confirm-pickup-2.php?Spot_Number=<?php echo $Spot_Number; ?>&Total_Riders=<?php echo $Total_Riders; ?>&U_ID=<?php echo $U_ID; ?>&Driver_ID=<?php echo $Driver_ID; ?>&Trip_ID=<?php echo $Trip_ID; ?>&TU_ID=<?php echo $TU_ID; ?>'>تأكيد التحميل</a>"+
							" | <a style='border-style: dashed; border-radius: 50px; color:#011F39; border-color:#B3E207; background-color:#ebebeb'class='btn btn-sm btn-center ' href='tel:" + driver.Phone_Number + "'>اتصل بالسائق</a>"+
							" <br><br> <a style='border-style: dashed; border-radius: 50px; color:red; border-color:#B3E207; background-color:#ebebeb'class='btn btn-sm btn-center ' href='cancel-request-2.php?Total_Riders=<?php echo $Total_Riders; ?>&U_ID=<?php echo $U_ID; ?>&Driver_ID=<?php echo $Driver_ID; ?>&Trip_ID=<?php echo $Trip_ID; ?>&TU_ID=<?php echo $TU_ID; ?>'>الغاء الطلب</a>"+
							" | <a style='border-style: dashed; border-radius: 50px; color:#011F39; border-color:#B3E207; background-color:#ebebeb'class='btn btn-sm btn-center ' href='driver-complain-2.php?Spot_Number=<?php echo $Spot_Number; ?>&U_ID=<?php echo $U_ID; ?>&Driver_ID=<?php echo $Driver_ID; ?>&Trip_ID=<?php echo $Trip_ID; ?>&TU_ID=<?php echo $TU_ID; ?>'>ارسال شكوى بالسائق</a>"+

							"</div>"
                        });
						
																


                        marker2.addListener("click", function() {
							
                            infoWindow.open(map, marker2);
							
                        });
						
						setTimeout(function() {
						marker2.setMap(null);
						}, 5000);
						
						
						
					
                    
                });
				
			

				

				
				
            }

            updateLocations();
			
            setInterval(updateLocations, 5000); // Update every 5 seconds
        }
    </script>

</head>
<body onload="initializeMap()">
<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;

                    // ارسال 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?U_ID=<?php echo $U_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 position-relative text-center">
            <span class="float-left menu-open closed">
                    <img src="../../../icons/menu.svg" alt="Menu Hamburger Icon">
            </span>
            <span class="title"><br>موقع سائقك المباشر</span>
            
                <span class="float-right" style="margin-top:-27px !important">
                    <img src="../../../images/icon.png" alt="Logo" width="14px" height="20px">
                </span>
				
        </div>
        <!--Page Title & Icons End-->

<br>
    <div id="map_canvas" style="width: 100%; height: 100%;"></div>


      


        
    </div>


<div id="load" > </div>
<div id="load2" > </div>



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

</body>
</html>