  <?php include "head.php";
  include "dbconfig.php";
  ?>
  <?php

$driver_id=$_GET['driver_id'];

$query ="SELECT employees.*,vehicles.*,vehicle_make.make as make,vehicle_make.id as make_id FROM employees
JOIN vehicles on vehicles.driver_id=employees.id
JOIN vehicle_make on vehicles.make=vehicle_make.id

 WHERE employees.id=".$driver_id;
$res=$con->query($query);
//echo $query;
$driver_data= mysqli_fetch_assoc($res);
  
  ?>
  
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<!DOCTYPE html>
<html lang="en">
   <body>

  <div class="container-fluid">
  <div class="col-md-3"></div>
    <div class="panel col-md-6" style="background-color: #e9e9e9;box-shadow: 5px 5px 5px;">
                    
                     <div class="panel-body">
                    
                  
                     <form method="post" id="driver_form" action="" enctype="multipart/form-data">
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                           <h2>Driver Personal Details</h2>
                           <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6"> 
                           <div class="form-group">
                              <div class="col-md-6"> 
                              <label>Current Photo</label>
                              <input type="hidden" name="current_photo" id="current_photo" value="<?php echo $driver_data['driver_photo'];?>">
                              <?php 
							  $path=$driver_data['driver_photo'];
							  if($path==''){$path="images/dummy.jpg";}else{$path= "drivers/".$driver_data['driver_photo'];}?>
							  
                              
                              <img width="50" height="50" class="img img-circle" src="<?php echo $path;?>">
                              </div>
                              <div class="col-md-6">
                                 <label for="uplaod">Uplaod Photo</label>
                                 <input type="file" name="driver[]" id="post_code" placeholder="Post Code" class="form-control radius" />
                                 <div id="loader"><img src="images/image_loader.gif"/></div>
                              </div>
                            </div>
                             <div class="form-group">
                             <div class="clearfix"></div>
                                 <label for="first_name">Driver Name</label>
                                 <input type="text" id="first_name" name="first_name" value="<?php echo $driver_data['first_name'];?>"  placeholder="Driver Name" class="form-control radius" />
                              <!-- save driver id for sql query in post-->
                              <input type="hidden" name="driver_id" value="<?php echo $driver_id;?>">
                              </div>
                             
                              <div class="form-group">
                                 <label for="email">Email Address</label>
                                 <input type="text" id="email" name="email" value="<?php echo $driver_data['email'];?>"  placeholder="Email Address" class="form-control radius" />
                              </div>
							  
							  <div class="form-group">
                                 <label for="dob">Date of Birth</label>
                                 <input type="text" id="dob" name="dob" value="<?php echo date("d/m/Y",strtotime($driver_data['dob']));?>"  placeholder="Date of Birth" class="form-control radius" />
                              </div>
                           </div>
                           <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                              <div class="form-group">
                                 <label for="address">Address</label>
                                 <input type="text" id="address" name="address" value="<?php echo $driver_data['address'];?>"  placeholder="Address" class="form-control radius" />
                              </div>
                              <div class="form-group">
                                 <label for="post_code">Post Code</label>
                                 <input type="text" id="post_code" name="post_code" value="<?php echo $driver_data['post_code'];?>"  placeholder="Post Code" class="form-control radius" />
                              </div>
 								<div class="form-group">
                                 <label for="phone">Phone</label>
                                 <input type="text" id="phone" name="phone" value="<?php echo $driver_data['phone'];?>"  placeholder="Phone" class="form-control radius" />
                              </div>

                           </div>

                        </div>
                        <div id="error"></div>
                    
                           <h2>Driving Details</h2>
                           <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                              <div class="form-group">
                                 <label for="pco_number">PCO Badge Number</label>
                                 <input type="text" id="pco_number" name="pco_number" value="<?php echo $driver_data['pco_number'];?>"  placeholder="PCO Badge Number" class="form-control radius" />
                              </div>
							   <div class="form-group">
                                 <label for="post_code">PCO Plate Number</label>
                                 <input type="text" id="post_code" name="reg" value="<?php echo $driver_data['reg'];?>"  placeholder="JS89 XYZ" class="form-control radius" />
                              </div>
							   <div class="form-group">
                                 <label for="reg_plate">Reg Plate</label>
                                 <input type="text" id="reg_plate" name="reg_plate" placeholder="Reg Plate" value="<?php echo $driver_data['reg_plate'];?>" class="form-control radius required" />
                              </div>
							  </div>
							  <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                              <div class="form-group">
                                 <label for="d_l_number">PCO Expiry Date</label>
                                 *<input type="text" id="pco_expiry" name="pco_expiry" value="<?php echo date("d/m/Y",strtotime($driver_data['pco_expiry']));?>"  required placeholder="PCO Expiry" class="form-control radius" />
                              </div>
                               <div class="form-group">
                                 <label for="insurance_date">PCO Plate Expiry Date</label>
                                 <input type="text" id="tfl_expiry" name="tfl_expiry" value="<?php echo date("d/m/Y",strtotime($driver_data['tfl_expiry']));?>"  placeholder="PCO Plate Expiry Date" class="form-control radius required" />
                              </div>
							   <div class="form-group">
                                 <label for="n_i_number">N. I. Number</label>
                                 <input type="text" id="n_i_number" name="n_i_number" value="<?php echo $driver_data['n_i_number'];?>" placeholder="N. I. Number" class="form-control radius" />
                              </div>
                         
                              
                 </div>
               
            
        


                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                           <h2>Car Details</h2>
                           <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                          
                              <div class="form-group">
                                 <label for="phone">Car Make</label>
                                 <select name="make" style="width:70%;background-color:#053DD4; color:#ffffff;" id="make" class="form-control">
                               <?php
                 
                  $skip_sql="SELECT id,make from vehicle_make order by id ASC";
				  
                  $t_result=mysqli_query($con,$skip_sql);
                  while($vehicle=mysqli_fetch_assoc($t_result))
                  {
                  ?>
         
     <option value="<?php echo $vehicle['id'];?>" <?php if ($driver_data['make_id'] ==$vehicle['id']) { echo 'selected'; } ?>><?php echo $vehicle['make'];?></option>	
            <?php
            
            }
            ?>
                                </select>
                              </div>
                              <div class="form-group">
                                 <label for="mot_date">MOT Expiry Date</label>
                                 <input type="text" id="mot_date" name="mot_date" value="<?php echo date("d/m/Y",strtotime($driver_data['mot_date']));?>"  placeholder="MOT Expiry Date" class="form-control radius" />
                              </div>
                             
                          
                           </div>
                           <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                              <div class="form-group">
                                 <label for="address">Color</label>
                                 <input type="text" id="address" name="color" value="<?php echo $driver_data['color'];?>"  placeholder="Black" class="form-control radius req" />
                              </div>
                               <div class="form-group">
                                 <label for="insurance_date">Insurance Expiry Date</label>
                                 <input type="text" id="insurance_date" name="insurance_date" class="form-control radius" value="<?php echo date("d/m/Y",strtotime($driver_data['insurance_date']));?>"  />
                              </div>
                              
                              <!--div class="form-group">
                                 <label for="post_code">Passengers</label>
                                 <input type="text" id="passengers" name="passengers" value="<?php //echo $driver_data['passengers'];?>" class="form-control radius req" />
                              </div-->
 						</div>
                              
               <div class="form-group pull-right">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                  <input type="submit" class="btn btn-primary" value="Update Driver" />
               </div> 
               </div>
  </form>
           
     
    </div>
</div>
<script type="text/javascript">
$(document).ready(function () {
	$('#loader').hide();
});


// function to post data
$(document).ready(function (e) {
	 
	
	$("#driver_form").on('submit',(function(e) {
		//$('#driver_form').validate();
		e.preventDefault();
		$('#loader').show();
		var url11 = 'ajax/update_driver.php?'+new Date().getTime();
		$.ajax({
			
        	url: url11,
			type: "POST",
			data:  new FormData(this),
			contentType: false,
    	    cache: false,
			processData:false,
			success: function(data)
		    { 
			//alert(data);
			if(data=='success'){
		alert("Driver Details Were Updated Successfully");
		$('#loader').delay(500).fadeOut("slow");
		var url1 = 'list_drivers.php?'+new Date().getTime();
		window.location.href = url1;
		
			}else{
				alert("Driver Was not Update Error 576");
				$('#loader').delay(500).fadeOut("slow");
				
				}
					
				
			//$("#gallery").html(data);
			
				
				
		    },
		  	error: function() 
	    	{
	    	} 	        
	   });
		
	}));
});

 $(document).ready(
 
 
 
      function () {
	   $('#mot_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	   $('#insurance_date').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	   $('#pco_expiry').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
      $('#tfl_expiry').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	  $('#badge_expiry').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
	  
	  $('#dob').datepicker({
        changeMonth: true,//this option for allowing user to select month
        changeYear: true, //this option for allowing user to select from year range
        dateFormat: 'dd/mm/yy'
      });
      }
	  );			
</script>
   </body>
</html>
