<?php  

  session_start();
    error_reporting(0);
		include("../db.php");
		include("../all_query.php");
		
		$pg=$page=$_GET['page'];
        $keyword=$_GET['keyword'];
        $key_for=$_GET['key_for'];
		
		$cur_page=$pg + 1;

 $page=$page*10;
 
 
	
		$table_fieldsQ= mysqli_query($conn,"select *from `table_fields` where `table_name` = 'settlement' ");
		$table_fieldsData = mysqli_fetch_assoc($table_fieldsQ);
		
		
		
		
 
								 $where_str="";
		
		?>
			
                               <div class="card-datatable table-responsive text-nowrap">
   
									
									
									
									<table id="add-row" class=" table border-top" cellspacing="0" width="100%" role="grid" aria-describedby="example23_info" style="width: 100%;">
                                        <thead  >
                                            
									  <th style="width:100px;cursor:pointer;"><a onclick="selectAll();">Select</a></th>
									   
                     <?php 
                        $datac= get_all_column($conn,'settlement');
                        
                        
						$where_condition = '';
                        // print_r($data);
                        foreach($datac as $field)
                        {    
                        if($field!='status' && $field!='id'  && $field!='date_time'    )
                        {
							
						 $where_condition .= "`$field` LIKE '%$keyword%' or ";
						 
						 $column_name = $field;
					 
						 
							
                        ?>
                     <th ><?php echo ucfirst(str_replace('_',' ',$column_name)); ?></th>
                     <?php }   } ?>
					 					
										</tr>
                                        </thead>
                                      <tbody>
											
											<?php
											
											 
										   $eQ=mysqli_query($conn,"select *from settlement  where  ( $where_condition  `status` like '%$keyword%')    order by id desc limit $page,10");
												 
										   
											$i=$page;

											while($row=mysqli_fetch_assoc($eQ))
											 {  
										  
											 $i++; ?>
   											
											<tr class="text-nowrap">
													
								      <td>  <input type="checkbox" name="delete_checkbox" value="<?php echo $row['id']; ?>" /> </td>
									  
									   
                     <?php 
                        foreach($datac as $field)
                        		 {  
                        		  if($field!='status' && $field!='id'  && $field!='date_time'  )
                        		 {
                        ?>
                     <td><?php  if($field=='image') { ?>
					 <a href="images/<?php  echo $row[$field];  ?>" target="_BLANK" ><img src="images/<?php  echo $row[$field];  ?>" height="30" width="30" /></a>

					 <?php  } else { echo $row[$field]; } ?></td>
					 
					 
					 
					 
					 
                     <?php } } ?>
					  
				 			</tr>
																		<?php }  ?>

												</tbody>
									
									
									</table>
									
									</div>
									
									<?php if($_SESSION['login_as'] == 'admin') {  ?>
									<a style="color:red; cursor:pointer"  onclick="deleteSelected('settlement');" style="    margin: 10px;"  >Delete</a>
									<?php } ?>
								
                                
                            </div>
				  
				  
                </div>
               
			   
			   
			   
			   
			   							
									
									
					
	<?php    
	
	
										 
												 
												 
																					
	     $eNoQ=mysqli_query($conn,"select *from settlement    ");
													 
												 
											 
											
		
		 
			 
		 $total_party = mysqli_num_rows($eNoQ);
		?>
	Total Records: <?php  echo $total_party; ?>
		<nav style="float: right" aria-label="...">
  <ul class="pagination pagination-sm">
  
  <li class="page-link"> <span <?php if($cur_page>1) { ?> onclick="fetchAllParty('<?php echo $pg - 1; ?>','<?php echo $keyword; ?>','')"   <?php } ?> class="paginate_button">Prev</span><li>
  <?php		

        
			
        for($i=$pg;$i<$total_party/10;$i++)
		{
 
	// $limit = $cur_page + 3;
	if($i <  ($pg + 10) )
	{	
	?>
	
	
   <li class="page-item"><a onclick="fetchAllParty('<?php echo $i; ?>','<?php echo $keyword; ?>','')" class="page-link" href="#"  <?php if($i == $pg) { ?> style="background:#2962ff  !important; border-color:#2962ff  !important; color: #fff; text-decoration: none; border: none !important; padding: .56rem .95rem;" <?php } ?> style="padding: .5rem .75rem; "><?php echo $i+1; ?></a></li>
   
   <?php }   } ?>
		 <li class="page-link"> <span  <?php if($total_party/5  > $cur_page ) { ?> onclick="fetchAllParty('<?php echo $pg + 1; ?>','<?php echo $keyword; ?>','')"  <?php }  ?>  class="paginate_button">Next</span><li>
		 </ul>
</nav>
        
	
	</div>
	
	