<?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` = 'leads' ");
		$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>

										<th>Account Holder Id</th>
										 
                     <?php 
                       // $datac= get_all_column($conn,$page_name);
                        
                         
								 $datac = explode(',',$table_fieldsData['column_names']);
                                 
								 
								 

                        // print_r($data);
                        foreach($datac as $field)
                        {    
                        if($field!='status' && $field!='id'  && $field!='date_time'    )
                        {
                        ?>
                     <th ><?php echo ucfirst(str_replace('_',' ',$field)); ?></th>
                     <?php }   } ?>
										
										</tr>
                                        </thead>
                                      <tbody>
											
											<?php
											
											
											
											
											  
												 	 $eQ=mysqli_query($conn,"select *from leads  where lead_no like '%$keyword%' or account_holder_name like '%$keyword%' or lead_data like '%$keyword%'  order by id desc limit $page,10");
												 
										  
										
											 
											$i=$page;

											while($row=mysqli_fetch_assoc($eQ))
											 {  
										 
											$lead_data = $row['lead_data'];
											$leadDataArray = json_decode(stripslashes($lead_data),TRUE); 
                      
											 
											 $i++; ?>
   											
											<tr class="text-nowrap">
													
								      <td>  <input type="checkbox" name="delete_checkbox" value="<?php echo $row['id']; ?>" /> </td>
										
							
							<td><a href="#" onclick="getAccountHolderView('<?php echo $leadDataArray['accountholderid']; ?>')" data-bs-toggle="modal" data-bs-target="#accountHolderView" style="text-decoration:underline" ><?php echo $leadDataArray['accountholderid']; ?></a></td>
							 
                     <?php 
                        foreach($datac as $field)
                        		 {  
                        		  if($field!='status' && $field!='id'  && $field!='date_time'  )
                        		 {
                        ?>
                     <td><?php  if($field=='image') { ?>
					 <a href="images/<?php  echo $leadDataArray[$field];  ?>" target="_BLANK" ><img src="images/<?php  echo $leadDataArray[$field];  ?>" height="30" width="30" /></a>

					 <?php  } 
					 else if($field == 'accountholderid')
					 {
						 ?>
						 
						<a href="#" onclick="getAccountHolderView('<?php echo $leadDataArray['accountholderid']; ?>')" data-bs-toggle="modal" data-bs-target="#accountHolderView" style="text-decoration:underline" ><?php echo $leadDataArray['accountholderid']; ?></a>
						 
						 <?php
					 }
					 
					 
					 else { echo $leadDataArray[$field]; } ?></td>
					 
					 
					 
					 
					 
                     <?php } } ?>
					 
					 
				 			</tr>
																		<?php }  ?>

												</tbody>
									
									
									</table>
									
									</div>
									
									<?php if($_SESSION['login_as'] == 'admin') {  ?>
									<a style="color:red; cursor:pointer"  onclick="deleteSelected('leads');" style="    margin: 10px;"  >Delete</a>
									<?php } ?>
								
                                
                            </div>
				  
				  
                </div>
               
			   
			   
			   
			   
			   							
									
									
					
	<?php    
	
	
										 
												 
												 
																					
	     $eNoQ=mysqli_query($conn,"select *from leads  where lead_no like '%$keyword%' or account_holder_name like '%$keyword%' or lead_data like '%$keyword%' ");
													 
												 
											 
											
		
		 
			 
		 $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>
	
	