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

session_start();




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

	$Error ='';
	
	
	
$DID = $_GET['DID'];
$user_ID = $_GET['user_ID'];




 
  


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

$long=$_POST['long'];
$lat=$_POST['lat'];


	

$DID=mysqli_real_escape_string($dbConn,$_POST['DID']);
$user_ID=mysqli_real_escape_string($dbConn,$_POST['user_ID']);







$query = mysqli_query($dbConn,"SELECT * FROM users WHERE Phone_Number='$Phone_Number' AND (Status='Active' AND Password='$Password')"); 
		

if (mysqli_num_rows($query)>0)
{

$row=mysqli_fetch_array($query);
$U_ID=$row['ID'];
$_SESSION['U_Log'] = $U_ID;


$query = mysqli_query($dbConn,"update users set Device_ID='$DID', U_ID='$user_ID', Login_Status='True', Longitude='$long', Latitude='$lat' where ID='$U_ID'"); 


	
	
	
	
	if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) 
	{
		
		


$query = mysqli_query($dbConn,"update users set Phone_Type='IOS' where ID='$U_ID'"); 



	}else{ 



$query = mysqli_query($dbConn,"update users set Phone_Type='Android' where ID='$U_ID'");


	
	}






	
	echo '<script language="JavaScript">
            document.location="Users/";
        </script>';
	
	
	
}
else
{

$Error = 'Sorry ! check your access information or your status with administrator !';


}
}

?>

<!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">
	
	<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"/>



    <title>Sign in</title>
	
	
	
	
	
	<style>
@font-face {
   font-family: myFirstFont;
   src: url(../fonts/Arial-Rounded-MT-Bold-Regular.ttf);
   font-size:8px;
}



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

}


</style>







</head>
<body onload="getLocation()">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></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">

  <!--Page Title & Icons Start-->
        <div class="header-icons-container text-center">
          <a href="Users-Sign-In.php?DID=<?php echo $DID; ?>&user_ID=<?php echo $user_ID; ?>">
                <span class="float-left">
                    <img src="../icons/back.svg" alt="Back Icon">
                </span>
            </a>
			            <span><br>Sign In</span>

        </div>

        <div class="rest-container" style="margin-top:-10px">
            <div class="text-center header-icon-logo-margin header-icon-logo-margin-extra">
                <img src="../images/icon.png" style="border-radius: 10%;" width="20%" alt="Main Logo">

				<center><p style="font-size:14px; color:#535353">HI welcome back to <span>SHEELD</span>, <br>if you have an account <br>please
enter your phone number and password,
<br>let the <span>adventure</span> roll</p>
            </div>

            <!--Sign Up Container Start-->
            <div class="sign-up-form-container text-center">
                <form class="width-100" method="post" action="Users-Sign-In.php?DID=<?php echo $DID; ?>&user_ID=<?php echo $user_ID; ?>">
				
	   <INPUT TYPE="hidden" NAME="DID"  VALUE="<?php echo $DID; ?>">
	 	   <INPUT TYPE="hidden" NAME="user_ID"  VALUE="<?php echo $user_ID; ?>">
		   
		   
				
 

 <INPUT TYPE="hidden" NAME="long" id="long" VALUE="">
     <INPUT TYPE="hidden" NAME="lat" id="lat" VALUE="">
	 






	 

                    <!--Sign Up Form Field Start-->
                   
					
					
					<div class="form-group" >
                        <div class="input-group" >
                            <div class="input-group-prepend" >
                                <span>
                                    <img src="../icons/phone.svg" alt="Lock Icon">
                                </span>
                            </div>
                            <input class="form-control" type="tel"  name="Phone_Number" placeholder="Phone number" required>
                            <div class="input-group-append password-visibility">
                               
                            </div>
                        </div>
                    </div>
					
					
					
                    <!--Sign Up Form Field End-->

                    <!--Sign Up Form Field 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" placeholder="Password" required>
                            <div class="input-group-append password-visibility">
                                <span>
                                    <img src="../icons/eye.svg" alt="Password Visibility Icon">
                                </span>
                            </div>
                        </div>
                    </div>
                    <!--Sign Up Form Field End-->
					<font style="color:#000"><a href="Users-Forget-Password.php?user_ID=<?php echo $user_ID; ?>&DID=<?php echo $DID; ?>" style="border-radius: 50px; color:#011F39">Forget your password?</a></font>

<br><br>											<center><span style="color:red"><?php echo $Error; ?></span></center>
<br>
<center>
<p style="font-size:14px; color:#535353">If you dont have account<br>
you can now <a href="Users-Sign-Up-1.php?user_ID=<?php echo $user_ID; ?>&DID=<?php echo $DID; ?>" style="text-decoration:underline; border-radius: 50px; color:#011F39">Signup</a></font>

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

						<br><br>

                    </div>

                </form>
				
				
					

				
				<br>
				
				
            </div>
            <!--Sign Up Container Start-->

        </div>
    </div>

   

	
<div class="footer" style="margin-top:-200px">
</div>

</div>


<style>
  .footer {
    background-image: url('../images/footer.png');
    background-size: cover;
    background-repeat: no-repeat;
    height: 280px; 
    bottom: 0;
    width: 120%;
	
  }
</style>





<script src="../js/jquery-3.4.1.js"></script>
<script src="../js/popper.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/main.js"></script>



<p id="demo"></p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
 

<script>
var x = document.getElementById("demo");

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.watchPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
    
function showPosition(position) {
   
	
	 document.getElementById('long').value = position.coords.longitude;
         document.getElementById('lat').value = position.coords.latitude
		 
		
	
	
	
	
	
	jQuery.ajax({
                    type:'POST',
                    url:'geocoordinates.php',
                    data:'lat='+position.coords.latitude+'&lng='+position.coords.longitude,
                    success:function(address){
                        if(address){
                            var encodedUrl = encodeURIComponent(address);
                          	jQuery("#location").html(address);
                          		jQuery("#mapurl").html('<a href="http://maps.google.com/maps?z=12&t=m&q=loc:'+encodedUrl+'">Map Url</a>');
                        }else{
                            	jQuery("#location").html('Not Available');
                        }
                    }
                });
	
}
</script>


</body>
</html>