 <form action="" method="post">
<input type="hidden" name="filter_search" value="yes">
  <div class="col-md-12 well" style="text-align:left;">
	<label style="font-size:16px;">Appy Jobs Filter to Search Jobs</label>
        <center>
       <div class="col-md-3" id="jobs_data">
	</div>
          
        <div class="col-md-2">
         <div class="form-group">
          <input type="text" name="from" class="from form-control" placeholder="Date From" id="from">
           </div>
          </div>
       <div class="col-md-2">
         <div class="form-group">
           <input type="text"  name="to" class="to form-control" placeholder="Date To" id="to">
           </div>
        </div>
        
        <div class="col-md-1">
         <div class="form-group">
          <input type="submit" name="filter_search" id="filter_search" class="btn btn-warning btn-sm" placeholder="Type N or P">
         </div>
      </div>
      </center>
        </div>
<div class="col-md-12 well" style="margin-bottom:10pz;">
            <div class="col-md-3">
			<?php
            $rowcount=mysqli_num_rows($res);

if($rowcount==0)
{
	echo '<label>No Driver Record Found</label>';
}
				
$today = date("d/m/y", strtotime($today));
echo '<label>Total '.$rowcount.' Record Found</label>';

?>
</div>
            
             
				<!--div class="col-md-3">
                	<a href="reports/drivers_data_print.php" class="btn btn-warning btn-sm>">Print TFL Data</a>
                </div>
                <div class="col-md-3">
                <a href="new_driver.php" class="btn btn-info btn-sm>">Add New Driver</a>
                </div> 
                <div class="col-md-3">
   
    <input name="delete_driver" type="submit" class="btn btn-sm btn-danger" value="Delete"/>
  
	</div-->
                </div>
<table style="font-size:16px; color:#000000;" id="drivers" class="table table list_jobs table-hover table-bordered table-striped table-info" cellspacing="0" border="1">

        
			
            
           <thead>    
            <tr class="btn-primary" style="padding:10px;">

                           <th>Sr No.</th>
                           <th>Name</th>
						    <th>Balance</th>
                           <!--th>Phone</th>
						   <th>email</th>
                           <th>Address</th-->
                           <th>View</th>
                           <!--th><input type="checkbox" id="select_all" /></th-->
                           
          </tr>

        </thead>

        <tfoot>

            <tr class="btn-primary">
                          <th>Sr No.</th>
                           <th>Name</th>
						   <th>Balance</th>
                           <!--th>Phone</th>
						   <th>email</th>
                           <th>Address</th-->
                            <th>View</th>
                            <!--th></th-->
                            
                          
            </tr>

        </tfoot>

        <tbody>
        
        <?php
				$i=1;
                while($job=mysqli_fetch_assoc($res))
   					{
					$d_sql="SELECT id,name,SUM(balance) as total from debtors WHERE source_id=".$job['id'];
$d_res=mysqli_query($con,$d_sql);
$passbook=mysqli_fetch_assoc($d_res);
$debtor_balance=$passbook['total'];
					?>      
                  <tr class="update_job" row-id="<?php echo $job['id'];?>">
                   
                     <input type="hidden" name="id[]" value=<?php echo $job['id'];?>>
					       <td><?php echo $i;?></td>
                           <td><?php echo strtoupper($job['first_name']);?></td>
						   <td><?php if($debtor_balance<0){ echo '&pound;'.number_format(-$debtor_balance,2);}
else{ echo '&pound;'.number_format($debtor_balance,2);}?></td>
                           <!--td><?php //echo $job['phone'];?></td>
						   <td><?php //echo $job['email'];?></td>
                           <td><?php //echo $job['address']."<br>".$job['post_code'];?></td-->
                          
                           <td><a href="data_debtor.php?id=<?php echo $job['id'];?>">View</a></td>
                           <!--td style="text-align:right;"><input name="selected_driver[]" type="checkbox" class="checkbox selected_driver" value=<?php echo $job['id'];?>></td-->
                        </tr>
             
   <?php 
   $i++;
   } ?>
   		 </tbody>
			   </table>
               </form>

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Success</h4>
      </div>
      <div class="modal-body">
        <p>Records Updated Succesfully.</p>
      </div>
      <div class="modal-footer">
        <button id="close_me" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
<?php /////////// if Delete is Pressed //

 if(isset($_POST['delete_driver']))
			{
		
		/*	
			echo "<pre>";
  				 print_r($_POST);
			echo "</pre>";
		exit;
		*/	
		$bookingIds = $_POST;
		$count=count($_POST['selected_driver']);
		for ($i=0;$i<$count;$i++){
			$counter=1+$i;
			$index = array_search($_POST['selected_driver'][$i] ,$bookingIds['id']);
			//echo "index=".$index;
		$driver_id=$con->real_escape_string($_POST['selected_driver'][$i]);
		
		
		$DELETE_booking="DELETE FROM employees,vehicles USING employees
JOIN vehicles on vehicles.driver_id=employees.id
WHERE employees.id=$driver_id";
					  //echo $DELETE_booking;
					  if (!mysqli_query($con,$DELETE_booking)) {
							echo $update_booking;
							die('DELETE 3 INTO Bookings -Error: ' . mysqli_error($con));
							exit;
						 }
					  
		  }
		  echo '<script>alert("Record Deleted"); window.location.replace("list_drivers.php")</script>';
		}
?>

	<script type="text/javascript">
$(document).ready(function(){
    $('#select_all').on('click',function(){
        if(this.checked){
            $('.checkbox').each(function(){
                this.checked = true;
            });
        }else{
             $('.checkbox').each(function(){
                this.checked = false;
            });
        }
    });
    
    $('.checkbox').on('click',function(){
        if($('.checkbox:checked').length == $('.checkbox').length){
            $('#select_all').prop('checked',true);
        }else{
            $('#select_all').prop('checked',false);
        }
    });
});
</script>