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




	if(isset($_POST['Submit']))
{
	
	
$D_ID=$_POST['D_ID'];
$Name=$_POST['Name'];
$Phone_Number=$_POST['Phone_Number'];
$Email_Address=$_POST['Email_Address'];
$Password=$_POST['Password'];
$Accept_Private_Trips_Gender_Status=$_POST['Accept_Private_Trips_Gender_Status'];
$Accept_Private_Trips_Status=$_POST['Accept_Private_Trips_Status'];



$query = mysqli_query($dbConn,"SELECT * FROM drivers WHERE Phone_Number='$Phone_Number' AND ID!='$D_ID'"); 
		

if (mysqli_num_rows($query)>2)
{

	$Error = 'Error ... phone number is already used with another two accounts !';




	
}
else
{









$file;
$file=$_FILES["file"]["name"];
	
	
	
	if ($file!=''){


if($_FILES['file']['size'] > 1000000 ){


echo "<script language='JavaScript'>
			  alert ('Sorry ! Photo size should be less than 1 mb !');
      </script>";


	}else{
		
		
		
		move_uploaded_file($_FILES["file"]["tmp_name"], "Profile_Pictures/" . $_FILES["file"]["name"]);
     	$Profile_Picture = 'Profile_Pictures/'.$file;
 
$sql1 = mysqli_query($dbConn,"update drivers set Photo='$Profile_Picture' where ID='$D_ID'");

		
		
		
	}


}








$insert = mysqli_query($dbConn,"update drivers set Accept_Private_Trips_Status='$Accept_Private_Trips_Status', Accept_Private_Trips_Gender_Status='$Accept_Private_Trips_Gender_Status', Name='$Name', Phone_Number='$Phone_Number', Email_Address='$Email_Address', Password='$Password' where ID='$D_ID'");



echo '<script language="JavaScript">
 document.location="My_Profile.php";
</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>My profile</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;
}



</style>








</head>
<body >
<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 emaining-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>My profile</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>

        <div class="rest-container" style="margin-top:-50px">
                <form class="width-100" action="My_Profile.php" method="post" enctype="multipart/form-data">
				<input type="hidden" name="D_ID" value="<?php echo $D_ID; ?>"/>
<br>  
            <!--Profile Information Container Start-->
            <div class="text-center header-icon-logo-margin">
                <div class="profile-picture-container">
                    <img id="output" src="<?php echo $Photo; ?>" style="border-radius: 50%" width="150px" height="150px" alt="Profile Picture">
                    <span class="fas fa-camera">
<input class="file-prompt" onchange="loadFile(event)" type="file" name="file" accept="image/*">
</span>
					
					
					
<script>
  var loadFile = function(event) {
    var output = document.getElementById('output');
    output.src = URL.createObjectURL(event.target.files[0]);
    output.onload = function() {
      URL.revokeObjectURL(output.src) // free memory
    }
  };
</script>



                </div>
                
            </div>
            <!--Profile Information Container End-->

            <!--Profile Information Fields Container Start-->
            <div class="sign-up-form-container text-center">

                   

                    <!--Profile Field Container Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span>
                                    <img src="../../icons/avatar-light.svg" alt="Avatar Icon">
                                </span>
                            </div>
                            <input class="form-control" type="text" autocomplete="off" name="Name" value="<?php echo $Name; ?>" placeholder="Name">
<div class="input-group-append password-visibility">
                               
                            </div>                        
					   </div>
                    </div>
                    <!--Profile Field Container End-->
					
					
					 <!--Profile Field Container Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span><img src="../../icons/phone.svg" alt="Phone Number"></span>
                            </div>
                            <input class="form-control" type="tel" name="Phone_Number" value="<?php echo $Phone_Number; ?>" placeholder="Phone number">
                        <div class="input-group-append password-visibility">
                               
                            </div> 
						</div>
                    </div>
                    <!--Profile Field Container End-->
					
					

                    <!--Profile Field Container Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span>
                                    <img src="../../icons/envelope.svg" alt="Envelope Icon">
                                </span>
                            </div>
                            <input class="form-control" type="email" name="Email_Address" value="<?php echo $Email_Address; ?>" placeholder="Email address">
                        <div class="input-group-append password-visibility">
                               
                            </div> 
						</div>
                    </div>
                    <!--Profile Field Container End-->

                   
                  
				  
				   <!--Profile Field Container Start-->
                    <div class="form-group">
										<label>Penalty balance</label>

                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span>
                                    <img src="../../icons/money.svg" alt="Avatar Icon">
                                </span>
                            </div>
                            <input class="form-control" type="text" readonly  value="<?php echo $Penalty_Balance; ?> JOD" >
<div class="input-group-append password-visibility">
                               
                            </div>                         
					   </div>
                    </div>
                    <!--Profile Field Container End-->
					
					
					
					 <!--Profile Field Container Start-->
                    <div class="form-group">
																	<label>Credit balance</label>

                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span>
                                    <img src="../../icons/money.svg" alt="Avatar Icon">
                                </span>
                            </div>
                            <input class="form-control" type="text" readonly  value="<?php echo $Credit_Balance; ?> JOD" >
<div class="input-group-append password-visibility">
                               
                            </div>                         
					   </div>
                    </div>
                    <!--Profile Field Container End-->
				  
				  
				  
				  
				  
				   <!--Profile Field Container Start-->
                    <div class="form-group">
																						<label>Total need balance</label>

                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span>
                                    <img src="../../icons/money.svg" alt="Avatar Icon">
                                </span>
                            </div>
                            <input class="form-control" type="text" readonly  value="<?php echo $Total_Need_Balance; ?> JOD" >
<div class="input-group-append password-visibility">
                               
                            </div>                         
					   </div>
                    </div>
                    <!--Profile Field Container End-->
				  
				  
				  
				  
				  
				  
				   <!--Sign Up Input Field Start-->
                    <div class="form-group">
					<label>Accept private trips gender status</label>

                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span><img src="../../icons/support-white.svg" width="12px" height="17px" alt="PRIVATE TRIPS GENDER STATUS"></span>
                            </div>
                            <select style="border-radius: 50px;" class="custom-select font-weight-light" name="Accept_Private_Trips_Gender_Status"  required>
								<option value="<?php echo $Accept_Private_Trips_Gender_Status; ?>"><?php echo $Accept_Private_Trips_Gender_Status; ?></option>
								<option value="Same gender">Same gender</option>
								<option value="Mix gender">Mix gender</option>
								

							</select>

                        </div>
                    </div>
                    <!--Sign Up Input Field End-->
				  
				  
				  
				  
				   <!--Sign Up Input Field Start-->
                    <div class="form-group">
										<label>Accept private trips status</label>

                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span><img src="../../icons/support-white.svg" width="12px" height="17px" alt="PRIVATE TRIPS STATUS"></span>
                            </div>
                            <select style="border-radius: 50px;" class="custom-select font-weight-light" name="Accept_Private_Trips_Status"  required>
								<option value="<?php echo $Accept_Private_Trips_Status; ?>"><?php echo $Accept_Private_Trips_Status; ?></option>
								<option value="True">True</option>
								<option value="False">False</option>
								

							</select>

                        </div>
                    </div>
                    <!--Sign Up Input Field End-->
				  
				  
				  
				  
				  
				  

                 

                    <!--Profile Field Container Start-->
					
					
				
					

                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span>
                                    <img src="../../icons/lock.svg" alt="Lock Icon">
                                </span>
                            </div>
                            <input class="form-control" type="password" name="Password" value="<?php echo $Password; ?>" placeholder="PASSWORD">
                            <div class="input-group-append password-visibility">
                                <span>
                                    <img src="../../icons/eye.svg" alt="Password Visibility Icon">
                                </span>
                            </div>
                        </div>
                    </div>
                    <!--Profile Field Container End-->

                  
                    <div class="form-submit-button">
                        <button name="Submit" type="submit" style="height:50px; font-size: 16px; width:150px !important; border-radius: 12px; color:#fff; border:none; background-image: linear-gradient(to right, #B3E207 0%, #3ADBDB 100%);" class="btn  w-100 mb-3">Save</button>
					
					
					<br>

                        <a href="Delete_Account.php" style="height:50px; font-size: 16px; width:150px !important; border-radius: 12px; color:#fff; border:none; background-image: linear-gradient(to right, #B3E207 0%, #3ADBDB 100%);" class="btn  w-100 mb-3">Delete Account</a>



                 
				 </div>  

                   
					
                   
					
					
                </form>
            </div>
            <!--Profile Information Fields Container End-->

        </div>
    </div>









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