<?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'];




	$lng1 = $_GET['lng1'];
	$lat1 = $_GET['lat1'];
	
	
	
	$lng2 = $_GET['lng2'];
	$lat2 = $_GET['lat2'];	
	
	
	
	$From_Location = $_GET['From_Location'];
	$To_Location = $_GET['To_Location'];

	$Date = date("Y-m-d");
	$Time =date("Y-m-d");

	

	
  $unit = 'K';											
  $theta = $lng1 - $lng2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));

  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);										
  $Distance = round(($miles * 1.609344),1);	
  
  
if ($Distance==0){

$Distance = 1;

}	
 

    /* This sets the $time variable to the current hour in the 24 hour clock format */
    $time = date("H");
    /* Set the $timezone variable to become the current timezone */
    $timezone = date("e");
    /* If the time is less than 1200 hours, show good morning */
    if ($time < "12") {
       
	$Open_Price= 0.35;

    $KM_Price = 0.25;


    } else
    /* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */
    if ($time >= "12" && $time < "17") {
       



	$Open_Price= 0.35;

    $KM_Price = 0.25;






    } else
    /* Should the time be between or equal to 1700 and 1900 hours, show good evening */
    if ($time >= "17" && $time < "19") {
        
	$Open_Price= 0.36;

    $KM_Price = 0.30;


    } else
    /* Finally, show good night if the time is greater than or equal to 1900 hours */
    if ($time >= "19") {
        

	$Open_Price= 0.36;

    $KM_Price = 0.30;





    }



	$Total_Price = $Open_Price + $Distance * $KM_Price;





if(isset($_POST['Submit']))
{
	
	
	$U_ID = $_POST['U_ID'];
	$lng1 = $_POST['lng1'];
	$lat1 = $_POST['lat2'];
	
	
	
	$lng2 = $_POST['lng2'];
	$lat2 = $_POST['lat2'];	
	
	
	
	$From_Location = $_POST['From_Location'];
	$To_Location = $_POST['To_Location'];
	
	
	$Date = $_POST['Date'];
	$Time = $_POST['Time'];
	$Total_KM_Distance = $_POST['Total_KM_Distance'];
	$Total_Price = $_POST['Total_Price'];
	$Total_Riders = $_POST['Total_Riders'];
	$Total_Price_All_Riders = $Total_Price * $Total_Riders;
	$Payment_Type = $_POST['Payment_Type'];
	$Gender=$_POST['Gender'];



echo '<script language="JavaScript">
 document.location="private-same-gender-3.php?Gender='.$Gender.'&Total_Riders='.$Total_Riders.'&Payment_Type='.$Payment_Type.'&Total_Price_All_Riders='.$Total_Price_All_Riders.'&Total_Price='.$Total_Price.'&Total_KM_Distance='.$Total_KM_Distance.'&Date='.$Date.'&From_Location='.$From_Location.'&To_Location='.$To_Location.'&lng1='.$lng1.'&lat1='.$lat1.'&lng2='.$lng2.'&lat2='.$lat2.'&U_ID='.$U_ID.'";
</script>';


}


?>

<!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">
		    <link rel="shortcut icon" href="../../../images/icon.ico"/>

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


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

                    // ارسال 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 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-->

       
  			<br><br>

     
				
		<form  method="post" action="private-same-gender-2.php" enctype="multipart/form-data" >
		<input type="hidden" name="lng1" value="<?php echo $lng1; ?>"/>
		<input type="hidden" name="lat1" value="<?php echo $lat1; ?>"/>
		<input type="hidden" name="lng2" value="<?php echo $lng2; ?>"/>
		<input type="hidden" name="lat2" value="<?php echo $lat2; ?>"/>
		<input type="hidden" name="From_Location" value="<?php echo $From_Location; ?>"/>
		<input type="hidden" name="To_Location" value="<?php echo $To_Location; ?>"/>
		<input type="hidden" name="Date" value="<?php echo $Date; ?>"/>
		<input type="hidden" name="Total_KM_Distance" value="<?php echo $Distance; ?>"/>
		<input type="hidden" name="Total_Price" value="<?php echo $Total_Price; ?>"/>
		<input type="hidden" name="Gender" value="<?php echo $Gender; ?>"/>



 <div class="rest-container" style="margin-top:-50px">
            <div class="all-history-items remaining-height">
                <div class="history-items-container trip-history">
                    <div class="history-item">
                        <!--Google Map Start-->
  <div id="map" style="height: 140px;"></div>
                        <!--Google Map End-->

                        <!--Date & Time Container Start-->
                        <div class="border-bottom-primary thin">
                            <div class="status-container">
                                <div class="date float-left" style="color:#011F39">
                                    <img src="../../../icons/calendar.svg" alt="Calendar Icon" class="calendar-icon"> <?php echo $Date; ?>
                                </div>
                                
                                <div class="clearfix"></div>
                            </div>
                        </div>
                        <!--Date & Time Container 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" style="background-color:#00000000 "></span>
                                    <div class="map-input 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>
                                
                                    <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 display-flex border-0 controls flex-1 font-weight-light align-items-center">
                                            <?php echo $To_Location; ?>
                                        </div>
                                        <span class="dotted-line"></span>
                                    </div>
                              
                            </div>
                        </div>
						<br>
                        <!--Address Container End-->

                        <!--Trip Costs Container Start-->
                        <div class="border-bottom-primary thin width-48 border-bottom-light-grey">
                            <div class=" trip-fare" style="color:#011F39">معلومات الرحلة</div>
                        </div>

                        <div class="trip-fare-container font-weight-light" style="color:#011F39">
						
						
							
							<div class="trip-fare-item">
                                <span class="float-left">مجموع الكيلومترات</span>
                                <span class="float-right blue-price"><?php echo $Distance; ?> كيلو متر</span>
                                <span class="clearfix"></span>
                            </div>
							
							
							<div class="trip-fare-item">
                                <span class="float-left">السعر (لكل راكب)</span>
                                <span class="float-right blue-price"><?php echo $Total_Price; ?> دينار اردني</span>
                                <span class="clearfix"></span>
                            </div>
							
							
							
							<div class="trip-fare-item">
                                                              <span class="float-left">عدد الركاب</span>

							  <input class="form-control" type="number" min="1" autocomplete="off" value="1" required name="Total_Riders" placeholder="عدد الركاب">

                            </div>
							
							
							
							<div class="trip-fare-item">
                                                              <span class="float-left">نوع الدفعة</span>
                                <select class="custom-select font-weight-light" name="Payment_Type" required>
														<option disabled selected value>اختر نوع الدفعة</option>
								<option value="Cash">نقداً</option>
								<option value="رصيد SHEELD">رصيد SHEELD</option>
								

							</select>
                            </div>
							  
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							
					
							
							
                        </div>
                        <!--Trip Costs Container End-->

                        

                    
                </div>
            </div>
        </div>
		
		
		
<!--Choose a Car Container Start-->
            <div class="ride-options-bottom" style="position: fixed;">
                
               
                
                <div class="">
								<center>

               <button type="submit" name="Submit" class="btn btn-primary" 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" />تأكيد</button>
                    <a href="../index.php" class="btn btn-primary" style="line-height: 24px; 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"/>عودة</a>
	
	
	</center>
	
	
                </div>
            </div>
            <!--Choose a Car Container End-->








					
						
				
				
				
		 
    		









</form>































        
    </div>

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

  <script>
    function initMap() {
      const map = new google.maps.Map(document.getElementById('map'), {
        center: { lat: <?php echo $lat1; ?>, lng: <?php echo $lng1; ?> }, // Default center (San Francisco)
        zoom: 10,
      });
	  const trafficLayer = new google.maps.TrafficLayer();
			trafficLayer.setMap(map);

      const startPoint = { lat: <?php echo $lat1; ?>, lng: <?php echo $lng1; ?> }; // Replace with your start coordinates
      const endPoint = { lat: <?php echo $lat2; ?>, lng: <?php echo $lng2; ?> };       // Replace with your end coordinates

      const directionsService = new google.maps.DirectionsService();
      const directionsRenderer = new google.maps.DirectionsRenderer({ map: map });

      const request = {
        origin: startPoint,
        destination: endPoint,
        travelMode: google.maps.TravelMode.DRIVING,
      };

      directionsService.route(request, function (result, status) {
        if (status === google.maps.DirectionsStatus.OK) {
          directionsRenderer.setDirections(result);
        }
      });
    }
  </script>


    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDemEmJPVUC9PoCzTLZLZdhwJLt5fu5XUc&callback=initMap" async defer></script>





</body>
</html>