<?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` = 'call_evaluation' ");
		$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>Week</th>
											
									 
                     <?php 
                        $datac= get_all_column($conn,'call_evaluation');
                        
                         
							//	 $datac = explode(',',$table_fieldsData['column_names']);
                                 
						$questionsArray = array('Greetings, Self Introduction, Brand Introduction/Lender name done?',
					'Did agent check the Reason for Delinquency (RFD) and probed?','Did agent Call recording status informed?',
					'Did agent follow the negotiation hierarchy for BKT 30-90 (Norm/RB/Stab)? This applies for Bucket X EMI negotiation also.',
					'Did agent handled objection effectively and displayed ownership on call?',
					'Did agent offer appropriate programmed as per given guidelines. (LPF/Knock off/settlement)?',
					'Did agent use effective articulation of Whats in it for me? - CIBIL Impact and Zest relationship',
					'Appropriate codes marked (RFD/NCD/ Disposition Code) Crisp and articulate documentation (Post call notes)',
					'Active listening (Fail to listen actively or Making the customer repeat the information)',
					'Appropriate Acknowledgement/Responses/Tone/Energy/Enthusiasm(Rate of speech and tone modulation) used on call?');



					
								 
						$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;
						 
						if (strpos($column_name, 'question')  !== false) {      $question_no = str_replace('question_','',$column_name); $column_name = $questionsArray[$question_no - 2];  } 
						
						
						if($column_name == 'score')
						{
							$column_name = 'Actual QS';
						}
										
							
                        ?>
                     <th ><?php echo ucfirst(str_replace('_',' ',$column_name)); ?></th>
                     <?php }   } ?>
					 <th>Actual QS</th>
										
										</tr>
                                        </thead>
                                      <tbody>
											
											<?php
											
											 
										   $eQ=mysqli_query($conn,"select *from call_evaluation  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>
									  
									  
									  <td>
									  <?php  
									  $evaluation_date = $row['evaluation_date'];
									  $year_month = date('Y-m',strtotime($evaluation_date));
									  $day = date('d',strtotime($evaluation_date));
									  
									  $start_date = $year_month.'-11';
									  if($day <= 10)
									  {
										  $start_date = date('Y-m-d',strtotime($start_date.' -1 month'));
									  }
									  
									  
										$startTimeStamp = strtotime($start_date);
										$endTimeStamp = strtotime($evaluation_date);

										$timeDiff = abs($endTimeStamp - $startTimeStamp);

										$numberDays = $timeDiff/86400;  // 86400 seconds in one day

										// and you might want to convert to integer
										   $numberDays = intval($numberDays);
										  
										  echo "WEEK ".ceil($numberDays/7);

									   
									  
									  
									  

									  ?>
									  </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 } } ?>
					 <td><?php echo $row['score']; ?></td>
					 
				 			</tr>
																		<?php }  ?>

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