<?php
	session_start();

    require('connect.php');
    require('functions.php');

    
	
if(isset($_POST['driver_submit_btn'])){
       echo '<script> alert("hello"); </script>';
	$name=$_POST['driver_name'];
       $name = test_input($name);
	$email=$_POST['driver_email'];
	$email=test_input($email);
	$password=$_POST['driver_password'];
	$password=test_input($password);
	$passwordConfirm=$_POST['driver_confirmpawword'];
	$passwordConfirm=test_input($passwordConfirm);
	$mobile=$_POST['driver_mobile'];
	//echo '<script> alert("hello"); </script>';
	$mobile=test_input($mobile);
	
	//$carname=$_FILES['carimage']['tmp_name'];
	//$carname=file_get_contents($carname);
       //echo '<script type=\'text/javascript\'>'; 
       //              echo 'alert("hiiii'.$carname.'");'; 
       //              echo '</script>'; 
	$carnumber=$_POST['driver_car_number'];
	$carnumber=test_input($carnumber);
	$licence=$_POST['driver_licence'];
	$licence=test_input($licence);

	//$cname = $_FILES['carimage']['name'];
       $image = $_FILES['carimage']['tmp_name'];
       $images = $_FILES['carimage'];
       $imgContent = addslashes(file_get_contents($image));
       //$file_array = reArrayFiles($images);
       //$extensions = array("jpg","jpeg","png","gif");
       // $file_c = explode('.',$images['name']);
       // $fname = $file_c[0];
       // $file_c = end($file_c);

       /*if(move_uploaded_file($images['tmp_name'],
              'driver_images/'.$images['name']))
       {       echo "<script> alert('upload');</script>";}*/


       // $destination_path = getcwd().DIRECTORY_SEPARATOR;
       // $target_path = $destination_path . 'driver_images/'. basename( $_FILES["carimage"]["name"]);
       // @move_uploaded_file($_FILES['carimage']['tmp_name'], $target_path);
       //$target_dir = "upload/";
       //$target_file = $target_dir . basename($cname);

       // Select file type
       //$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

       // Valid file extensions
       //$extensions_arr = array("jpg","jpeg","png","gif");

       // Check extension
       //if( in_array($imageFileType,$extensions_arr) ){

       // Insert record


	if($email=="" || substr($email, -10)!="@gmail.com" || $password=="" || $passwordConfirm=="" || $password!=$passwordConfirm || $name=="")
       {
    echo '<script>alert("Enter Email id assigned by gmail");</script>';
	}
	else
       {

		$checkDriverQuery="SELECT demail FROM driver WHERE demail='$email'";
		$checkDriverQuery=mysqli_query($con,$checkDriverQuery);
		if(mysqli_num_rows($checkDriverQuery) > 0)
              {// driver user exists
		     echo '<script>alert("User with this mail already exist");</script>';
		}
		else
              {//driver does not exist
                   

       $insertDriver="INSERT INTO driver (DNAME, DMOBILE, DEMAIL, DCATNUM, CARIMAGE, DLIC, DPASS) VALUES ('$name', '$mobile','$email','$carnumber', '$imgContent', '$licence', '$password')";
                     echo '<script> alert("hello"); </script>';

                     if(mysqli_query($con,$insertDriver))
                     {
                            //user added
                            move_uploaded_file($_FILES['carimage']['tmp_name'],$target_dir.$cname);
                            echo '<script> alert("Registration successful "+ $mobile); </script>';
                            $get_DID = "SELECT DID FROM driver WHERE demail='$email'";
                            $run = mysqli_query($con,$get_DID);
                            if($run)
                            {
                                   $row = mysqli_fetch_array($run);
                                   $_SESSION['id']=$email;
                                   $_SESSION['type']="student";
                                   $_SESSION['DID'] = $row['DID'];

                                   header('Refresh:0 url=driver.php');
                            }
                     }
                     else
                     {
                            echo '<script> alert("Cannot add user"); </script>';
                     }
              }
       }
}
?>








<!DOCTYPE html>
<html>
       <head>
              <script> alert("try try till u cry"); </script>
              <title>Sign Up</title>
              <meta charset="utf-8" />
              <meta name="viewport" content="width=device-width, initial-scale=1">
              <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  
              <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
              <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
	
	
	      <script>
                     function driver_submit_btn_onclick()
                     {
                            localStorage.setItem("user_type", "driver");
                            //alert("Enter all fields");
              		var enteredEmail=document.getElementById("demail").value;
              		var enteredPassword=document.getElementById("dpassword").value;
              		var enteredConfirmPassword=document.getElementById("dpasswordconfirm").value;
              		var enteredName=document.getElementById("dname").value;
              		var enteredmobile=document.getElementById("dmobile").value;
              		var enteredlicence=document.getElementById("dlicence").value;
              		var enteredcarname=document.getElementById("dcarname").value;
              		var enteredcarnumber=document.getElementById("dcarnumber").value;
		
                            alert(enteredmobile);
                            if(enteredPassword=="" || enteredEmail=="" || enteredConfirmPassword=="" || enteredName=="")
                            {
                                   //alert("Enter all fields");
                            }
                            else
                            {
                                   //check for @gmail.com
              			if(enteredEmail.substr(enteredEmail.length - 10)=="@gmail.com")
                                   {
              				if(enteredPassword==enteredConfirmPassword)
                                          {

              				}
              				else
                                          {
              					alert("Passwords do not match");
              				}
              			}
              			else
                                   {
              				alert("Please use proper email id");
              			}
                            }
                            alert("hiiii");
                     }

              </script>
       <style>
              form 
              {
                     border: 3px solid #f1f1f1;
                     margin-bottom: 3%;
                     margin-top: 10%;
                     
              }
              input[type=text], input[type=password], input[type=number] 
              {
                     width: 100%;
                     padding: 12px 20px;
                     margin: 8px 0;
                     display: inline-block;
                     border: 1px solid #ccc;
                     box-sizing: border-box;
              }

              button 
              {
                     background-color: #4CAF50;
                     color: white;
                     padding: 14px 20px;
                     margin-top: 1%;
                     border: none;
                     cursor: pointer;
                     width: 100%;
                     margin-bottom: 10%;
                     margin-top:  0%;
              }

              button:hover 
              {
                     opacity: 5.0;
              }

              .cancelbtn 
              {
                     width:100%;
                     margin-top:  0%;
                     background-color: #f44336;
                     
              }

              .imgcontainer 
              {
                     text-align: center;
                     margin: 24px 0 12px 0;
              }

              img.avatar 
              {
                     width: 40%;
                     border-radius: 50%;
              }

              .container 
              {
              	width:100%;
                     padding: 16px;
              }

              span.psw 
              {
                     float: right;
                     padding-top: 16px;
              }
              
              .footer 
              {
                     color: white;
                     background-color: black;
                     margin-left: 0px;
                     text-align: center;
                     position:fixed;
                     bottom: 0;
                     height: 5%;
                     width: 100%;
              }
              /* Change styles for span and cancel button on extra small screens */
              @media screen and (max-width: 300px) 
              {
                     span.psw 
                     {
                            display: block;
                            float: none;
                     }
                     .cancelbtn 
                     {
                            width: 70%;
                     }
              }
       </style>
</head>


<body style="overflow-x:hidden;background-size:100% 100%;background-repeat: no-repeat;bottom: 0;background-attachment: fixed;" background="images/blogin.jpg">

       <div>
              <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="padding: 0px margin:0px">
                     <div class="main" >
                            <div class="col-sm-6" >
                                   <h1 align="left" style="margin-left:10px;" ><a href="index.php"><font color="white" size="15">   ABHI CAB  </font></a>
                                          <img src="images/logo.png" alt="google.com" width="100" height="50" align="left" style="margin-left:10px;">
                                   </h1>
                            </div>
                            <div class="col-sm-6" style="margin-top:40px;">
                                   <ul class="nav navbar-nav navbar-right" style="margin-right:10px;">
                                          <li >
                                                 <a href="index.php"> Home   <span class="glyphicon glyphicon-home"></span></a>
                                          </li>
                                          <li class="active" >
                                                 <a class="dropdown-toggle" data-toggle="dropdown" href="#">Login <span class="caret"></span></a>
                                                 <ul class="dropdown-menu" >
                                                        <li align="right"><a href="index.php">Customer  <span class="glyphicon glyphicon-user"></span></a></li>
                                                        <li align="right"><a href="index.php">Admin  <span class="glyphicon glyphicon-user"></span></a></li>
                                                        <li align="right"><a href="index.php">Driver  <span class="glyphicon glyphicon-user"></span></a></li>
                                                 </ul>
                                          </li>

                                          <li><a href="main.php">Book Now  <span class="glyphicon glyphicon-shopping-cart"></span></a></li>
                                          <li><a href="about_us.php">About Us</a></li>
                                          <li><a href="contact.php">Contact Us <span class="glyphicon glyphicon-earphone"></span></a></li>
                                   </ul>
                            </div>
                     </div>
              </nav>
       </div>

       <div class="col-sm-2"></div>
       <div class="col-sm-8">
              <form  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  method="post" enctype="multipart/form-data"> 
                     <div class="imgcontainer">
                            <img src="images/login.png" alt="Avatar" class="avatar">
                     </div>

                     <div class="container">

                            <h2 align="center"><font color="yellow"><b>DRIVER SIGN UP</b></font></h2>

                            <label><b><font color="yellow" size="4">Name</font></b></label>
                            <input type="text" placeholder="Enter Name" name="driver_name" id="dname" required>
                            <hr>

                            <label><b><font color="yellow" size="4">Mobile Number</font></b></label>
                            <input type="number" min="7000000000" max="9999999999" placeholder="Enter Mobile Number" name="driver_mobile" text-type="number" id="dmobile" required>
                            <hr>

                            <label><b><font color="yellow" size="4">Gender</font></b></label>
                            <br></br>
                            <input type="radio" name="gender" > <font color="white" size="4">Male</font><br>
                            <input type="radio" name="gender" > <font color="white" size="4">Female</font><br>
                            <input type="radio" name="gender" > <font color="white" size="4">Other</font>
                            <hr>

                            <label><b><font color="yellow" size="4">Email</font></b></label>
                            <input type="text" placeholder="Enter Email" name="driver_email" id="demail"required>
                            <hr>

                            <label><b><font color="red" size="4">Licence Number</font></b></label>
                            <input type="number" pattern="[0-9]{10}" placeholder="Enter Licence NUmber" name="driver_licence" text-type="number" id="dlicence"required>
                            <hr>

                            <label><b><font color="red" size="4">Car Number</font></b></label>
                            <input type="text" placeholder="Enter Car NUmber" name="driver_car_number" text-type="text" id="dcarnumber" required>
                            <hr>

                            
                            <!--<label><b><font color="red" size="4">Car Name</font></b></label>
                            <input type="text" placeholder="Eg: Swift,Innova,etc." name="driver_car_name" text-type="text" id="dcarname" required>
                            <hr>-->

                            <div class="col-sm-12">
                                   <label><b><font color="red" size="4">Car Image</font></b></label>
                                   <!--<form action="upload.php" enctype="multipart/form-data" method="post">-->
                                          <font color="white">
                                          <input name="carimage" type="file" >
                                          <!--<input type="submit" value="Upload Image" name="submit">-->
                                          <!--<input name="Upload Now" type="submit" value="Upload Image">-->
                                          </font>
                                          <hr>
                                   <!--</form>-->
                                   
                            </div>
                            <!--
                            <div class="col-sm-6">
                                   <label><b><font color="red" size="4">Car Name</font></b></label>
                                   <input type="text" placeholder="Eg: Swift,Innova,etc." name="driver_car_name" text-type="text" id="dcarname" required>
                                   
                            </div>-->
                            
                                   

                            <label><b><font color="yellow" size="4">New Password</font></b></label>
                            <input type="password" placeholder="Enter Password" name="driver_password" text-type="password" id="dpassword"required>
                            <hr>

                            <label><b><font color="yellow" size="4">Confirm Password</font></b></label>
                            <input type="password" placeholder="Enter same Password" name="driver_confirmpawword" text-type="password" id="dpasswordconfirm"required>


                            <label>
                                   <input type="checkbox" checked="checked"> <font color="white" size="4">Remember me</font>
                            </label>
                     </div>

                     <div class="col-sm-6">
                            <button name="driver_submit_btn" type="submit" onclick="driver_submit_btn_onclick()">Submit</button>
                     </div>

                     <div class="col-sm-6">
                            <a  href="index.php"><button type="button" class="cancelbtn">Cancel</button></a>
                     </div>
              </form>
	<!--<div class="copy-right" style="padding:0px; bottom:true;">
  <p align="center">&copy; 2019 AbhiCab.com</p>-->
       </div>
  
       <div class="col-sm-2" ></div>

<!-- Footer -->
       <footer class="footer">
              <h5>Copyright &copy; 2019 AbhiCab.com</h5>
       </footer>



</body>

</html>





