<?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'];
$Longitude=$row3['Longitude'];
$Latitude=$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'];
$Accept_Private_Trips_Gender_Status= $row3['Accept_Private_Trips_Gender_Status'];
$Accept_Private_Trips_Status= $row3['Accept_Private_Trips_Status'];




if ($Credit_Balance<'1'){
	
	
	
	
	echo "<script language='JavaScript'>
			  alert ('Sorry ! Your credit balance less than 1 دينار اردني, you need to recharge your credit balance !');
      </script>";
	
	

$query12345 = mysqli_query($dbConn,"SELECT * FROM drivers WHERE ID='$D_ID'");
$row12345 = mysqli_fetch_array($query12345);
$UU_ID=$row12345['U_ID'];
$Device_ID=$row12345['Device_ID'];


$query = mysqli_query($dbConn,"update drivers set Login_Status='False' where ID='$D_ID'"); 








$_SESSION['D_Log']=0;

	
	
	
	  
echo '<script language="JavaScript">
            document.location="../../index.php?DID='.$Device_ID.'&onesignal_push_id='.$UU_ID.'";
        </script>';

	
	
	
	
	
	
	
}
	



















$sql11 = mysqli_query($dbConn,"select * from trips where Driver_ID='$D_ID' AND Status='In process'");
$sql111 = mysqli_query($dbConn,"select * from trips_users where Driver_ID='$D_ID' AND User_Rate_Status='' AND Status='Dropoff'");





if (mysqli_num_rows($sql11)>0){
$row11 = mysqli_fetch_array($sql11);
$Gender_Type = $row11['Gender_Type'];
$Trip_ID = $row11['ID'];
$Max_Limit_Riders = $row11['Max_Limit_Riders'];
$Time = $row11['Start_Time'];
$Gender_Type = $row11['Gender_Type'];
$Total_KM_Distance = $row11['Total_KM_Distance'];
$Date = $row11['Date'];
$From_Location = $row11['From_Location'];
$To_Location = $row11['To_Location'];
$lng1 = $row11['From_Longitude'];
$lat1 = $row11['From_Latitude'];
$lng2 = $row11['To_Longitude'];
$lat2 = $row11['To_Latitude'];

       

if ($Gender_Type=='Mix'){

echo '<script language="JavaScript">
 document.location="shared-mix-gender/shared-mix-gender-4.php?Trip_ID='.$Trip_ID.'&Max_Limit_Riders='.$Max_Limit_Riders.'&Time='.$Time.'&Gender='.$Gender_Type.'&Total_KM_Distance='.$Total_KM_Distance.'&Date='.$Date.'&From_Location='.$From_Location.'&To_Location='.$To_Location.'&lng1='.$lng1.'&lat1='.$lat1.'&lng2='.$lng2.'&lat2='.$lat2.'&D_ID='.$D_ID.'";
</script>';	



}else{

echo '<script language="JavaScript">
 document.location="shared-same-gender/shared-same-gender-4.php?Trip_ID='.$Trip_ID.'&Max_Limit_Riders='.$Max_Limit_Riders.'&Time='.$Time.'&Gender='.$Gender_Type.'&Total_KM_Distance='.$Total_KM_Distance.'&Date='.$Date.'&From_Location='.$From_Location.'&To_Location='.$To_Location.'&lng1='.$lng1.'&lat1='.$lat1.'&lng2='.$lng2.'&lat2='.$lat2.'&D_ID='.$D_ID.'";
</script>';	



}	
	
	
}











if (mysqli_num_rows($sql111)>0){
$row111 = mysqli_fetch_array($sql111);
$TU_ID = $row111['ID'];
$Trip_ID = $row111['Trip_ID'];
$User_ID = $row111['User_ID'];

$sql1111 = mysqli_query($dbConn,"select * from trips where ID='$Trip_ID'");
$row1111 = mysqli_fetch_array($sql1111);



$Gender_Type = $row1111['Gender_Type'];
$Trip_ID = $row1111['ID'];
$Max_Limit_Riders = $row1111['Max_Limit_Riders'];
$Time = $row1111['Start_Time'];
$Gender_Type = $row1111['Gender_Type'];
$Total_KM_Distance = $row1111['Total_KM_Distance'];
$Date = $row1111['Date'];
$From_Location = $row1111['From_Location'];
$To_Location = $row1111['To_Location'];
$lng1 = $row1111['From_Longitude'];
$lat1 = $row1111['From_Latitude'];
$lng2 = $row1111['To_Longitude'];
$lat2 = $row1111['To_Latitude'];

       

if ($Gender_Type=='Mix'){

echo '<script language="JavaScript">
 document.location="shared-mix-gender/shared-mix-gender-5.php?Trip_ID='.$Trip_ID.'&User_ID='.$User_ID.'&Driver_ID='.$Driver_ID.'&TU_ID='.$TU_ID.'";
</script>';	



}else{

echo '<script language="JavaScript">
 document.location="shared-same-gender/shared-same-gender-5.php?Trip_ID='.$Trip_ID.'&User_ID='.$User_ID.'&Driver_ID='.$Driver_ID.'&TU_ID='.$TU_ID.'";
</script>';	



}	
	
	
}




///////////////////////////////////////////////////////////////////////////////





$sql11 = mysqli_query($dbConn,"select * from trips_privates where Driver_ID='$D_ID' AND Status='Accepted'");
$sql111 = mysqli_query($dbConn,"select * from trips_privates where Driver_ID='$D_ID' AND Status='Pickedup'");
$sql1111 = mysqli_query($dbConn,"select * from trips_privates where Driver_ID='$D_ID' AND Status='Dropoff' AND User_Rate_Status=''");


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



if (mysqli_num_rows($sql11)>0){
$row11 = mysqli_fetch_array($sql11);
$Driver_ID = $row11['Driver_ID'];
$TP_ID = $row11['ID'];
$User_ID = $row11['User_ID'];
$Gender = $row11['Gender'];



if ($Gender=='Mix'){

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



}else{

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



}	
	
	
}







if (mysqli_num_rows($sql111)>0){
$row111 = mysqli_fetch_array($sql111);
$Driver_ID = $row111['Driver_ID'];
$TP_ID = $row111['ID'];
$User_ID = $row111['User_ID'];
$Gender = $row111['Gender'];



if ($Gender=='Mix'){

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



}else{

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



}	
	
	
}













if (mysqli_num_rows($sql1111)>0){
$row1111 = mysqli_fetch_array($sql1111);
$Driver_ID = $row1111['Driver_ID'];
$TP_ID = $row1111['ID'];
$User_ID = $row1111['User_ID'];
$Gender = $row1111['Gender'];



if ($Gender=='Mix'){

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



}else{

echo '<script language="JavaScript">
 document.location="private-same-gender/private-same-gender-4.php?User_ID='.$User_ID.'&TP_ID='.$TP_ID.'&Driver_ID='.$Driver_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">
    <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"/>


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




			<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <!-- Include jQuery -->

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

body {
   font-family: myFirstFont !important;
          overflow: hidden; 

}


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



</style>



<?PHP

if ($Avalability_Status=='Online' && $Accept_Private_Trips_Status=='True' && $Accept_Private_Trips_Gender_Status=='Same gender'){

?>

<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('private-same-gender/check-private-trips.php?D_ID=<?php echo $D_ID; ?>').fadeIn("slow");
}, 2000);


</script>

<?php	
	
}else{

?>	
	
<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('private-mix-gender/check-private-trips.php?D_ID=<?php echo $D_ID; ?>').fadeIn("slow");
}, 2000);


</script>	

<?php	
	
}

?>







 <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 $Latitude; ?>, <?php echo $Longitude; ?>),
                zoom: 13,

                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);
			
			




            function updateLocations() {
                // Fetch driver locations from the PHP backend
                fetch("get-driver-location.php?D_ID=<?php echo $D_ID; ?>")
                .then(response => response.json())
                .then(data => {
                    for (var i = 0; i < data.length; i++) {
                        var driver = data[i];
                        var marker = new google.maps.Marker({
                            position: new google.maps.LatLng(driver.Latitude, driver.Longitude),
                            map: map,
                            icon: "car-icon.png", // Path to your car icon
                            title: driver.Name
                        });
						
						
						
						
						
						
						
						
						
						
						

                       

                        marker.addListener("click", function() {
                            infoWindow.open(map, marker);
                        });
                    }
                });
            }

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


<?PHP
if ($Avalability_Status=='Online'){
?>
<style>	

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 60px;
    height: 30px;
    background: linear-gradient(to right, #B3E207, #B3E207) no-repeat;
    background-size: 100% 100%;
    border: none;
    outline: none;
    border-radius: 15px;
    cursor: pointer;
    transition: background 0.4s;
}
</style>	

<?php	
	
	
}else{
	
?>
<style>	
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 60px;
    height: 30px;
    background: linear-gradient(to right, red, red) no-repeat;
    background-size: 100% 100%;
    border: none;
    outline: none;
    border-radius: 15px;
    cursor: pointer;
    transition: background 0.4s;
}
</style>	

<?php	
	
}?>

<style>



input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 30px;
    height: 30px;
    background: #011F39;
    border: 1px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.4s;
}

input[type="range"]::-moz-range-thumb {
    width: 30px;
    height: 30px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.4s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #fff;
}

input[type="range"]::-moz-range-thumb:hover {
    background: #fff;
}

</style>



</head>
<body  style="height:auto !important" 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;

                    // 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>اخرت نوع الرحلة</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-->

	   
	<?php
if ($Avalability_Status == 'Online') {
    $Switch_Value = 1;
    $visibility = "visible";
} else {
    $Switch_Value = 0;
    $visibility = "hidden";
}
?>

<center>
    <input style="margin-top:70px" input type="range" min="0" max="1" step="1" id="statusSlider" value="<?php echo $Switch_Value; ?>">
</center>

<script>
    const statusInput = document.getElementById("statusSlider");

    statusInput.addEventListener("input", function() {
        const value = this.value;
        if (value == 1) {
            this.style.background = "linear-gradient(to right, #B3E207, #B3E207)";
            this.style.border = "1px solid #B3E207";
        } else if (value == 0) {
            this.style.background = "linear-gradient(to right, red, red)";
            this.style.border = "1px solid red";
        }
    });

    // Function to update href elements visibility
    function updateVisibility(status) {
        const visibility = status === 'Online' ? 'visible' : 'hidden';
        document.querySelectorAll('.sign-up-btn-container').forEach(function(element) {
            element.style.visibility = visibility;
        });
    }

    // Initial update based on availability status
    updateVisibility("<?php echo $Avalability_Status; ?>");

    // Update visibility when slider changes
    statusInput.addEventListener("input", function() {
        const status = this.value == 1 ? "Online" : "Offline";
        updateVisibility(status);
        
        // Send an AJAX request to update the visibility on the server
        $.ajax({
            type: "POST",
            url: "Update_Visibility.php",
            data: { Status: status },
            success: function(response) {
                console.log("Visibility updated: " + status);
            }
        });
    });
</script>

<center>
    <br><h6 style="color:#011F39">الحالة الحالية (<span id="status"><?php echo $Avalability_Status; ?></span>)</h6><br>
</center>

<script>
    $(document).ready(function() {
        // Set the initial user status
        var userStatus = "<?php echo $Avalability_Status; ?>";

        // Update the user status based on the slider value
        $("#statusSlider").on("input", function() {
            userStatus = $(this).val() == 1 ? "Online" : "Offline";
            $("#status").text(userStatus);

            // Send an AJAX request to update the user status
            $.ajax({
                type: "POST",
                url: "Update_Status.php",
                data: { Status: userStatus },
                success: function(response) {
                    console.log("User status updated: " + userStatus);
                }
            });
        });
    });
</script>

<br>
<div class="col-xs-12 col-sm-12 margin-bottom-up">

    <center>
        <!--Sign Up Buttons Container Start-->
        <div class="sign-up-btn-container">
            <!--<a class="btn btn-center width-100 display-block btn-secondary text-uppercase btn-padding-1">Sign Up With Facebook</a>-->
            <a href="shared-same-gender/shared-same-gender.php?DID=<?php echo $DID; ?>&user_ID=<?php echo $user_ID; ?>" style="height:50px; font-size: 16px; border-style: dashed; width:100% !important; border-radius: 12px; color:#fff; border:none; background-image: linear-gradient(to right, #B3E207 0%, #3ADBDB 100%);" class="btn  w-100 mb-3">مشترك / نفس الجنس</a>
        </div>

        <div class="sign-up-btn-container">
            <!--<a class="btn btn-center width-100 display-block btn-secondary text-uppercase btn-padding-1">Sign Up With Facebook</a>-->
            <a href="shared-mix-gender/shared-mix-gender.php?DID=<?php echo $DID; ?>&user_ID=<?php echo $user_ID; ?>" style="height:50px; font-size: 16px; border-style: dashed; width:100% !important; border-radius: 12px; color:#fff; border:none; background-image: linear-gradient(to right, #B3E207 0%, #3ADBDB 100%);" class="btn  w-100 mb-3">مشترك / مختلط بين الجنسين</a>
        </div>
    </center>
</div>

  




<br>

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


    

        
    </div>
	  </div>


    <?php
	include 'menu.php'
	?>
</body>
</html>