<?php
// this file is called by list_driver_jobs when user selecte dates to find out which driver worked during these dates
include "../dbconfig.php";

$from=$con->real_escape_string($_POST['from']);
	  $from = str_replace("/","-",$from);
	  $from = date("Y-m-d", strtotime($from));
	
	  $to=$con->real_escape_string($_POST['to']);
	  $to = str_replace("/","-",$to);
	  $to = date("Y-m-d", strtotime($to));
?>
 <select name="driver_id" id="driver_id" class="form-control">
			       	   	 <option style="padding:10px; background-color:#E7D91E; color:#F9F0F1; cursor:pointer;" value="">Select a Driver </option>
                               <?php
							   $c=0;
							   $aname=array();
							    $aid=array();
							        $customers_sql1="SELECT employees.first_name,employees.id,bookings.substitute from driver_bookings
left join employees on driver_bookings.driver_id=employees.id
left join bookings on driver_bookings.booking_id=bookings.id
where bookings.start_date BETWEEN '$from' AND '$to' AND driver_bookings.status=2 GROUP BY employees.id order by first_name ASC";
//echo $customers_sql;
					$t_result1=mysqli_query($con,$customers_sql1);
									while($customer1=mysqli_fetch_assoc($t_result1))
									{
									$aname[]=$customer1['first_name'];
									$aid[]=$customer1['id'];
									?>
	<!--option style="padding:20px; background-color:#2977C9; color:#F9F0F1; cursor:pointer;" value="<?php echo $customer1['id']; ?>">
	   <?php echo $customer1['first_name']; ?>
    </option-->
						<?php
									}								
								
							        $customers_sql=/*"SELECT employees.first_name,employees.id from employees,bookings
where bookings.driver_id=employees.id AND bookings.job_status=2 AND bookings.pickup_date BETWEEN '$from' AND '$to' GROUP BY employees.id order by first_name ASC";
"SELECT employees.first_name,employees.id from employees,bookings
LEFT JOIN driver_substitute on driver_substitute.booking_id=bookings.id
where bookings.start_date BETWEEN '$from' AND '$to' GROUP BY employees.id order by first_name ASC";	*/
"SELECT * from driver_substitute 
where start_date BETWEEN '$from' AND '$to' AND status=2";	
echo $customers_sql;
									$t_result=mysqli_query($con,$customers_sql);
									while($customer=mysqli_fetch_assoc($t_result))
									{
									$substitute_id=$customer['substitute_id'];
									$sqln= "SELECT * from employees where id='$substitute_id'";
									$t_resultn=mysqli_query($con,$sqln);
									$customern=mysqli_fetch_assoc($t_resultn);
									$aname[]=$customern['first_name'];
									$aid[]=$customern['id'];
									
									?>
	<!--option style="padding:20px; background-color:#2977C9; color:#F9F0F1; cursor:pointer;" value="<?php echo $aid[$c]; ?>">
	   <?php echo $aname[$c]; ?>
    </option-->
						<?php
						$c++;
						}
						
						
 $new_array = array();
foreach ($aid as $key => $value) {
    if(isset($new_array[$value]))
        $new_array[$value] += 1;
    else
        $new_array[$value] = 1;
}
//$new_array=array_unique($aid);
foreach ($new_array as $fruit => $n) {
    //echo $fruit;
	 $sqln1= "SELECT * from employees where id='$fruit'";
									$t_resultn1=mysqli_query($con,$sqln1);
									$customern1=mysqli_fetch_assoc($t_resultn1);
	?>
	<option style="padding:20px; background-color:#2977C9; color:#F9F0F1; cursor:pointer;" value="<?php echo $fruit; ?>">
	   <?php echo $customern1['first_name']; ?>
    </option>
						<?php
   
}

						
						?>
			       	  </select>
               <script type="text/javascript">
 $('#driver_id').select2({width: '100%'});
 </script>