<form action="" method="post">


			
            
            <div class="pull-right col-md-12">
                 <div class="col-md-6 pull-left">
			<?php
            $rowcount=mysqli_num_rows($res);

if($rowcount==0)
{
	echo '<label>Total '.$rowcount.' jobs found. Add some bookings.</label>';
}
				
echo '<label>Total '.$rowcount.' jobs found. You can see other jobs by applying filter</label>';

?>
</div>
<div class="col-md-6">
<input name="delete_booking" style="margin-bottom:10px;" type="submit" class="btn btn-sm btn-danger pull-right" value="Update All Jobs"/>

</div>
</div>

<table id="jobs" 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>Job ID</th>
                           <th>Pickup Date</th>
                           <th>Pickup Time</th>
                           <th>Company</th>
                           <th>Passenger</th>
                           <th>Pickup From</th>
                           
                           <th>Drop To</th>
                            <th>Driver Allocated</th>
                           <th>Waiting Time</th>
                           <th>Waiting Charges</th>
                           <th>Parking</th>
                           <th>Fare</th>
                           <th>Other</th>
                           <th>Total Fare</th>
                           <th>Comments</th>
                           <th>Update</th>
                           <th><input type="checkbox" id="select_all" /></th>
                           
            </tr>

        </thead>

        <tfoot>

            <tr class="btn-primary">
                          <th>Job ID</th>
                           <th>Pickup Date</th>
                           <th>Pickup Time</th>
                           <th>Company</th>
                           <th>Passenger</th>
                           <th>Pickup From</th>
                           
                           <th>Drop To</th>
                            <th>Driver Allocated</th>
                           <th>Waiting Time</th>
                           <th>Waiting Charges</th>
                           <th>Parking</th>
                           <th>Fare</th>
                           <th>Other</th>
                           <th>Total Fare</th>
                           <th>Comments</th>
                           <th>Update</th>
                           <th></th>
                          
            </tr>

        </tfoot>

        <tbody>
        
        <?php

                while($job=mysqli_fetch_assoc($res))

                  {?>      
                  <tr class="update_job" row-id="<?php echo $job['booking_id'];?>">
                 
						   <?php
						   if ($job['job_status']=='2'){?>
                           
							 <td style="background-color:#46E804; color:#0F0F0F;">
                             
                                
						    <?php echo $job['booking_id']; 
						   }else{
								
								echo '<td style="background-color:#F1070B; color:#FFF8F8;">'.$job['booking_id'];
								}
							?>
                           
                            
                            </td>
                          
                           <td>
						   <?php $start = date("d/m/y", strtotime($job['pickup_date'])); 
						   
						   echo $start  ;?></td>
                           
                            <td><label><?php echo $job['hours'];?>:<?php echo $job['mins'];?></label></td>
                            <td><?php echo $job['customer_name'];?></td>
                            <td><?php echo $job['company_contact'];?></td>
                            <td><?php echo $job['pickup_address']."<br><b>".$job['pickup_post_code']."</b>";?></td>
                            <td><?php echo $job['drop_address']."<br><b>".$job['drop_post_code']."</b>";?></td>
                            <td style="width:10%;">
                             <?php echo $job['driver'];?>
                          </td>
                          <input name="id[]" type="hidden" id="id" value=<?php echo $job['booking_id']; ?>>
                        <?php $id=$job['booking_id'];?>
                        
                        <td><input name="waiting_time[]" type="text" data-id=<?php echo $id;?> id="waiting_time<?php echo $id;?>" class="form-control waiting_time" value=
							<?php if($job['waiting_time']=='')
								{
									echo "mins";
									} 
								  else {
									  echo $job['waiting_time'];
									  } ?>></td>
               			
                        <td><input required name="waiting[]" type="text" data-id=<?php echo $id;?> id="waiting<?php echo $id;?>" class="form-control waiting" value=<?php echo $job['waiting_charges']; ?>  onkeypress="javascript:return isNumber(event)"></td>
                        <td><input required name="parking[]" type="text" data-id=<?php echo $id;?> id="parking<?php echo $id;?>" class="form-control parking" value=<?php echo $job['parking']; ?>  onkeypress="javascript:return isNumber(event)"></td>
                        <td><input required name="fare[]" type="text" data-id=<?php echo $id;?> id="fare<?php echo $id;?>" class="form-control fare" value=<?php echo $job['fare']; ?>  onkeypress="javascript:return isNumber(event)"></td>
                        <td><input required name="other[]" type="text" data-id=<?php echo $id;?> id="other<?php echo $id;?>" class="form-control other" value=<?php echo $job['other']; ?>  onkeypress="javascript:return isNumber(event)"></td>
                        
                        <td><input readonly name="total_fare[]" type="text" data-id=<?php echo $id;?> id="total_fare<?php echo $id;?>" class="form-control total_fare" value=<?php echo $job['total_fare']; ?>></td>
                        
                        <td><input type="hidden" name="comments[]" value="<?php echo $job['comments'];?>"><?php echo $job['comments'];?></td>
						
                         <td col-id="16"  data-id="<?php echo $job['booking_id'];?>"><button id="update" class="btn btn-success btn-sm update"><div id="loader<?php echo $job['booking_id'];?>" style="display:none;"><img src="images/ajax-loader.gif"/></div>Update</td>
                 <td style="text-align:right; font-size:20px;"><input name="selected_booking[]" type="checkbox" class="checkbox selected_booking" value=<?php echo $job['booking_id'];?>></td>
              </tr>
              
   <?php } ?>
   		 </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(isset($_POST['selected_booking'])){
/*	
echo "<pre>";
   print_r($_POST);
echo "</pre>";
 */
        $bookingIds = $_POST;
		$count=count($_POST['selected_booking']);
			
		for ($i=0;$i<$count;$i++){
          //$index = array_search($_POST['selected_booking'][$i] ,$bookingIds['id']);
			//echo "index=".$index;
			
		  $waiting_time=$con->real_escape_string($_POST['waiting_time'][$i]);
		  $waiting_charges=$con->real_escape_string($_POST['waiting'][$i]);
		  $parking=$con->real_escape_string($_POST['parking'][$i]);
		  $fare=$con->real_escape_string($_POST['fare'][$i]);
		   $other=$con->real_escape_string($_POST['other'][$i]);
		  $total_fare=$con->real_escape_string($_POST['total_fare'][$i]);
		  
		  $booking_id=$con->real_escape_string($_POST['id'][$i]);
		  
		  $comments=$con->real_escape_string($_POST['comments'][$i]);
$sql1="UPDATE driver_bookings SET
waiting_time='$waiting_time', 
waiting_charges='$waiting_charges', 
parking='$parking', 
fare='$fare', 
total_fare='$total_fare', 

other='$other',
comments='$comments'

WHERE id='$booking_id'";
//echo $sql1;

if (!mysqli_query($con,$sql1))
  {
  echo("Error description: " . mysqli_error($con));
  exit;
  }
  
 else
 {?>
 <script>
 
 
         $(window).load(function(){
             $('#myModal').modal('show');
			 
         });
		 $('#close_me').click(function(){
		 window.location = "list_job.php";
		 });
    </script>

	 
	 
	<?php 
	       }
         }
       }
    ?>