<?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']))
{
	$DID=mysqli_real_escape_string($dbConn,$_POST['DID']);
$user_ID=mysqli_real_escape_string($dbConn,$_POST['user_ID']);


	
$Name=$_POST['Name'];
$Phone_Number=$_POST['Phone_Number'];
$Password=$_POST['Password'];
$Gender=$_POST['Gender'];
$Car_Plat_Number=$_POST['Car_Plat_Number'];
$Car_Type=$_POST['Car_Type'];
$Car_Color=$_POST['Car_Color'];
$Special_Code=$_POST['Special_Code'];


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





$query1 = mysqli_query($dbConn,"SELECT * FROM drivers WHERE Phone_Number='$Phone_Number'"); 	
if (mysqli_num_rows($query1)>2){
	$Error = 'Error ... phone number is already used with another two accounts !';
	
}
else 
{





$Verification_Code = rand(1000,9999);

	
	
	
		$Now = date('Y-m-d', time());

	
	
	
		
$file;
$file=$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], "../../../Administrator/Administrator/Drivers_Info/" . $_FILES["file"]["name"]);
$Car_Licence_ID = 'Drivers_Info/'.$file;


$file2;
$file2=$_FILES["file2"]["name"];
move_uploaded_file($_FILES["file2"]["tmp_name"], "../../../Administrator/Administrator/Drivers_Info/" . $_FILES["file2"]["name"]);
$Driver_Licence_ID = 'Drivers_Info/'.$file2;


$file3;
$file3=$_FILES["file3"]["name"];
move_uploaded_file($_FILES["file2"]["tmp_name"], "../../../Administrator/Administrator/Drivers_Info/" . $_FILES["file3"]["name"]);
$Lack_Of_Judgment_File = 'Drivers_Info/'.$file3;








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





$insert = mysqli_query($dbConn,"insert into drivers (Special_Code,Driver_Licence_ID,Car_Licence_ID,Lack_Of_Judgment_File,Total_Rates,Car_Type,Car_Color,Total_Rates,Penalty_Balance,Credit_Balance,Total_Rates,Gender,Phone_Type,Photo,Name,Phone_Number,Password,Latitude,Longitude,Status,Login_Status,Device_ID,U_ID,Verification_Code,Add_Date_Time) values 
('$Special_Code','$Driver_Licence_ID','$Car_Licence_ID','$Lack_Of_Judgment_File','$Car_Plat_Number','$Car_Type','$Car_Color','0','0','0','5','$Gender','IOS','Profile_Pictures/avatar.svg','$Name','$Phone_Number','$Password','$lat','$long','Active','True','$DID','$user_ID','$Verification_Code','$Now')");


	
	}else{
		
$insert = mysqli_query($dbConn,"insert into drivers (Special_Code,Car_Licence_ID,Car_Licence_ID,Lack_Of_Judgment_File,Penalty_Balance,Credit_Balance,Total_Rates,Gender,Phone_Type,Photo,Name,Phone_Number,Password,Latitude,Longitude,Status,Login_Status,Device_ID,U_ID,Verification_Code,Add_Date_Time) values 
('$Special_Code','$Driver_Licence_ID','$Car_Licence_ID','$Lack_Of_Judgment_File','0','0','5','$Gender','Android','Profile_Pictures/avatar.svg','$Name','$Phone_Number','$Password','$lat','$long','Active','True','$DID','$user_ID','$Verification_Code','$Now')");

	}
	
	
	
	




	


$query1234 = mysqli_query($dbConn,"SELECT * FROM drivers WHERE Device_ID='$DID'");
$row1234 = mysqli_fetch_array($query1234);
$U_ID_2=$row1234['U_ID'];
$Phone_Type=$row1234['Phone_Type'];
$Login_Status=$row1234['Login_Status'];







$query123458 = mysqli_query($dbConn,"SELECT * FROM drivers WHERE Phone_Number='$Phone_Number'");
$row123458 = mysqli_fetch_array($query123458);
$D_ID=$row123458['ID'];





$_SESSION['D_Log'] = $D_ID;







if ($Phone_Type=='Android'){


    function sendMessage($U_ID_2){
        
        
        
        
        
        $content = array(
            "en" => 'Welcome to SHEELD - Drivers app'
            );
        
        $fields = array(
            'app_id' => "XXXXXXXXXXXXXX",
            'include_player_ids' => array($U_ID_2),
            'data' => array("foo" => "bar"),
            'contents' => $content
        );
        
        $fields = json_encode($fields);
       // print("\nJSON sent:\n");
       // print($fields);
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        
        return $response;
    }
    
    $response = sendMessage($U_ID_2);
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    
   // print("\n\nJSON received:\n");
   //    print($return);
   // print("\n");
   
}else{
	
	
	
	
	
	 function sendMessage($U_ID_2){
        
        
        
        
        
        $content = array(
            "en" => 'Welcome to SHEELD - Drivers app'
            );
        
        $fields = array(
            'app_id' => "XXXXXXXXXXXXXX",
            'include_player_ids' => array($U_ID_2),
            'data' => array("foo" => "bar"),
            'contents' => $content
        );
        
        $fields = json_encode($fields);
       // print("\nJSON sent:\n");
       // print($fields);
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        
        return $response;
    }
    
    $response = sendMessage($U_ID_2);
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    
   // print("\n\nJSON received:\n");
   //    print($return);
   // print("\n");
	
	
	
	
	
	
	
	
	
	
}
   












	  
echo '<script language="JavaScript">
            document.location="Drivers-Sign-Up-2.php?Phone_Number='.$Phone_Number.'&D_ID='.$D_ID.'&Verification_Code='.$Verification_Code.'";
        </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"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0"/>


    <title>تسجيل حساب جديد</title>
	
	

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



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


</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="sign-up.html">
                <span class="float-left">
                    <img src="icons/back.svg" alt="Back Icon">
                </span>
            </a>-->
            <span><br>تسجيل حساب جديد</span>
        </div>
        <!--Page Title & Icons End-->

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

            <!--Sign Up Container Start-->
            <div class="sign-up-form-container text-center">
                <form class="width-100" method="post" action="Drivers-Sign-Up-1.php?DID=<?php echo $DID; ?>&user_ID=<?php echo $user_ID; ?>" enctype="multipart/form-data">




 <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="">
	 
	
					<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" placeholder="الاسم" required >
                            <div class="input-group-append password-visibility">
                               
                            </div>
                        </div>
                    </div>
					
					
					
						
					  <!--Sign Up Input Field Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span><img src="../icons/gender.svg" width="12px" height="17px" alt="Gender"></span>
                            </div>
                            <select dir="rtl" class="custom-select font-weight-light" style="border-radius: 50px;" name="Gender"  required>
														<option disabled selected value>&nbsp;&nbsp;اختر الجنس</option>
								<option value="Male">ذكر</option>
								<option value="Female">انثى</option>
								

							</select>

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

                    <!--Sign Up Input 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 dir="rtl" class="form-control" type="tel"  name="Phone_Number" placeholder="رقم الهاتف" required> 
                            <div class="input-group-append password-visibility">
                               
                            </div>
                        </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
				
						 <!--Sign Up Input Field Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span ><img src="../icons/license.svg" alt="Special Code"  ></span>
                            </div>
                            <input class="form-control" type="text" autocomplete="off" name="Special_Code" placeholder="ادخل الرمز الخاص">
<div class="input-group-append password-visibility">
                                
                            </div>                        
					   </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
					
					
					
					 <!--Sign Up Input Field Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span ><img src="../icons/car-registration.svg" alt="Phone Icon"  ></span>
                            </div>
                            <input class="form-control" type="text" autocomplete="off" name="Car_Plat_Number" placeholder="رقم لوحة المركبة" required>
<div class="input-group-append password-visibility">
                                
                            </div>                        
					   </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
					
						 <!--Sign Up Input Field Start-->
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span ><img src="../icons/car-registration.svg"   ></span>
                            </div>
                            <input class="form-control" type="text" autocomplete="off" name="Car_Type" placeholder="نوع المركبة" required>
<div class="input-group-append password-visibility">
                                
                            </div>                       
					  </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
					
					
						 <!--Sign Up Input Field Start-->
                    <div class="form-group" style="color:#011F39">
                  رخصة المركبة
					  <div class="input-group">
                            <div class="input-group-prepend">
                                <span ><img src="../icons/license.svg"   ></span>
                            </div>
                            <input class="form-control" type="file" name="file" placeholder="رخصة المركبة" required>
<div class="input-group-append password-visibility">
                                
                            </div>                        
					   </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
					
                    <div class="form-group" style="color:#011F39">
					  رخصة القيادة للسائق
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span ><img src="../icons/license.svg"   ></span>
                            </div>
                            <input class="form-control" type="file" name="file2" placeholder="رخصة القيادة للسائق" required>
<div class="input-group-append password-visibility">
                                
                            </div>                       
					   </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
					
					
					
					
					
					
					  <div class="form-group" style="color:#011F39">
					  شهادة عدم المحكومية
                        <div class="input-group">
                            <div class="input-group-prepend">
                                <span ><img src="../icons/license.svg"   ></span>
                            </div>
                            <input class="form-control" type="file" name="file3" placeholder="Lack of judgment fi" required>
<div class="input-group-append password-visibility">
                                
                            </div>                       
					   </div>
                    </div>
                    <!--Sign Up Input Field End-->
					
					
					
					
					
					
					

                    <!--Sign Up Input 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="كلمة المرور" required>
                            <div class="input-group-append password-visibility">
                                <span>
                                    <img src="../icons/eye.svg" alt="Password Visibility Icon">
                                </span>
                            </div>
                        </div>
                    </div>
                    <!--Sign Up Input Field End-->

                    

                    <div class="form-submit-button">
                        <button type="submit" name="Submit" style="height:50px; font-size: 14px; width:250px !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>
                    </div>
                </form>
            </div>
            <!--Sign Up Container Start-->

        </div>
    </div>

 <!--Terms And Conditions Agreement Container Start-->
      <div class="col-xs-12 col-sm-12 text-center sms-rate-text font-roboto flex-end margin-bottom-30">
        <div class="container-sms-rate-text width-100 font-11">
            <span class="light-gray font-weight-light" style="color:#011F39">بالتسجيل فإنك قد وافقت على </span>
            <br/>
            <a style="color:#011F39" href="Terms_Policy.php?DID=<?php echo $DID; ?>&user_ID=<?php echo $user_ID; ?>" class="dark-link">
                <span class="font-weight-light" style="011F39">شروط الاستخدام وسياسة الخصوصية</span>
            </a>
        </div>
    </div>
    <!--Terms And Conditions Agreement Container End-->
<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>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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>