<?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'];
$Email_Address=$row3['Email_Address'];
$Password=$row3['Password'];
$Photo=$row3['Photo'];
$Total_Rates=$row3['Total_Rates'];
$Penalty_Balance=$row3['Penalty_Balance'];
$Credit_Balance=$row3['Credit_Balance'];






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



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

if (mysqli_num_rows($query)>0)
{

$Error = 'نعتذر ! رقم الهاتف هذا موجود بالفعل !';




	
}
else
{









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


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


echo "<script language='JavaScript'>
			  alert ('نعتذر ! حجم الصورة يجب ان يكون اقل من 1 ميغابايت !');
      </script>";


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

		
		
		
	}


}








$insert = mysqli_query($dbConn,"update users set Name='$Name', Phone_Number='$Phone_Number', Email_Address='$Email_Address', Password='$Password' where ID='$U_ID'");



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









</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?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 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>حسابي</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-->

         
	

        <div class="rest-container" >
                <form class="width-100" action="My_Profile.php" method="post" enctype="multipart/form-data">
				<input type="hidden" name="U_ID" value="<?php echo $U_ID; ?>"/>
  
            <!--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="الاسم">
<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="رقم الهاتف">
<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="البريد الإلكتروني">
<div class="input-group-append password-visibility">
                               
                            </div>                       
					   </div>
                    </div>
                    <!--Profile Field Container End-->

                   
                  
				  
				   <!--Profile Field Container Start-->
                    <div class="form-group">
					<label>رصيد الغرامات</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; ?> دينار اردني" >
<div class="input-group-append password-visibility">
                               
                            </div>                       
					   </div>
                    </div>
                    <!--Profile Field Container End-->
					
					
					
					 <!--Profile Field Container Start-->
                    <div class="form-group">
												<label>رصيد بالحساب</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; ?> دينار اردني" >
<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/lock.svg" alt="Lock Icon">
                                </span>
                            </div>
                            <input class="form-control" type="password" name="Password" value="<?php echo $Password; ?>" placeholder="كلمة المرور">
                            <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">حفظ</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">حذف الحساب</a>

                  

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

        </div>
    </div>









        
    </div>

  
    <!--Main Menu Start-->
    <div class="main-menu hidden-soft">
        <div class="mini-profile-info">
            <div class="menu-close">
                <span class="float-right">
                    <img src="../../icons/cross-light.svg" alt="Close Icon">
                </span>
            </div>
            <div class="profile-picture text-center">
                <img src="<?php echo $Photo; ?>" style="border-radius: 50%" width="30%" alt="Profile Picture">
            </div>
            <div class="profile-info">
                <div class="profile-name text-center"><?php echo $Name; ?></div>
                <div class="profile-phone text-center"><?php echo $Phone_Number; ?></div>
				<div class="profile-phone text-center"><?php echo $Total_Rates; ?> / 5<br>
				<?php
				  $NTotal_Rates = round(5 - $Total_Rates);
				  
				  for ($i=1; $i<=$Total_Rates; $i++){
					  
					  
					  echo '<span style="color:#B3E207" class="fa fa-star checked"></span>';
					  
					  
					  
				  }
				  
				  ?>
				  <?php
				  
				  for ($j=1; $j<=$NTotal_Rates; $j++){
					  
					  
					  echo '<span  class="fa fa-star "></span>';
					  
					  
					  
				  }
				  
				  ?>
				
				</div>
            </div>
        </div>
        <div class="menu-items" style="margin-top:-100px" style="margin-top:-100px">
            <div class="all-menu-items">
                <a class="menu-item" href="index.php">
                    <div>
                        <span class="menu-item-icon menu-dark">
                            <img src="../../icons/home-light.svg" alt="Home Icon">
                        </span>
                        
                        <span class="menu-item-title">الرئيسية</span>
                        <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                    </div>
                </a>
                <a class="menu-item" href="My_Profile.php">
                    <span class="menu-item-icon menu-dark profile">
                        <img src="../../icons/avatar-light-2.svg" alt="Avatar Darker Icon">
                    </span>
                    
                    <span class="menu-item-title profile">حسابي</span>
                    <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                </a>
				
				
				
				
               
                <a class="menu-item" href="My_Trips.php">
                    <span class="menu-item-icon menu-dark">
                        <img src="../../icons/my-addresses.svg" alt="My Addresses Icon">
                    </span>
                    
                    <span class="menu-item-title">رحلاتي</span>
                    <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                </a>
               
  
                <a class="menu-item" href="Terms_Conditions.php">
                    <span class="menu-item-icon menu-dark support">
                        <img src="../../icons/support-light.svg" alt="Support Icon">
                    </span>
                    
                    <span class="menu-item-title">الشروط والاحكام</span>
                    <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                </a>
				
				
				
				<a class="menu-item" href="Contact.php">
                    <span class="menu-item-icon menu-dark support">
                        <img src="../../icons/phone2.svg" alt="Support Icon">
                    </span>
                    
                    <span class="menu-item-title">اتصل بنا</span>
                    <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                </a>
				
				
				
				
				
				<a class="menu-item" href="../../EN/Users/index.php" style="font-family: myFirstFont;">
                    <span class="menu-item-icon menu-dark support">
                        <img src="../../icons/arabic.svg" width="18.76px" height="20.46px" alt="Support Icon">
                    </span>
                    
                    <span class="menu-item-title" style="font-family: myFirstFont2 !important;">English</span>
                    <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                </a>
				

                <a href="Logout.php" class="menu-item margin-top-auto">
                    <span class="menu-item-icon menu-dark logout">
                        <img src="../../icons/logout-light.svg" alt="Logout Icon">
                    </span>
                   
                    <span class="menu-item-title logout">خروج</span>
                    <span class="menu-item-click fas fa-arrow-right" style="color:#B3E207"></span>
                </a>
            </div>
        </div>
    </div>
    <!--Main Menu End-->

    

</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="../../js/jquery-3.4.1.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/main.js"></script>

</body>
</html>