<?php 	
session_start();
require_once '../../Server/connection.php';
$user_id = $_SESSION['user_id'];
$sql = "select client_files.file_id,client_files.file_no,client_files.fileStatus,client_files.client_id,assignstatus.remarks,assignstatus.assigned_by from client_files,assignstatus WHERE client_files.file_id=assignstatus.file_id and assignstatus.status=0 order by assignstatus.id desc";

$result = $conn->query($sql);

$output = array('data' => array());

if($result->num_rows > 0) { 

 // $row = $result->fetch_array();
 $active = ""; 
 $x = 1;

 while($row = $result->fetch_array()){
 	
	$categoriesId = $row['file_id'];
	$clientId = $row['client_id'];
	$fileStatus = $row['fileStatus'];
	$remarks = $row['remarks'];
	$assigned_by = $row['assigned_by'];
	$fileNo = $row['file_no'];
	$space = " ";
	
	$sql812 = "SELECT * FROM clients where client_id='$clientId'";
			$result812 = $conn->query($sql812);
				while($data812 = mysqli_fetch_array($result812))
							{
							$clientfName = $data812['client_fname'].$space.$data812['client_lname'];
                            $clientTin = $data812['client_tin']; 							
							}
							
							
	$sql81215 = "SELECT * FROM staff,users,designation where users.user_id='$assigned_by' and staff.staff_id=users.staff_id and staff.des_id=designation.des_id";
			$result81215 = $conn->query($sql81215);
				while($data81215 = mysqli_fetch_array($result81215))
							{
							$role = $data81215['firstname']." ".$data81215['lastname']." ".$data81215['des_short_name']; 
							}
	
	if($fileStatus==0){
		$st = "<span class='badge badge-info'>File Pending</span>";
	}else{
		$st = "<span class='badge badge-success'>File Closed</span>";
	 }
	 
	 $button = '<!-- Single button -->
	<div class="btn-group">
	    <a type="button" class="btn btn-primary" href="updateCustFile.php?i='.$categoriesId.'&assignId='.$searchByAssignId.'" id="editOrderModalBtn"> <center><i class="glyphicon glyphicon-edit"></i></center></a>
	</div>';
	
	
	$button1 = '<!-- Single button -->
	<div class="btn-group">
	    <a type="button" class="btn btn-primary" href="uploadedFls.php?i='.$categoriesId.'" id="editOrderModalBtn"><center><i class="glyphicon glyphicon-eye-open"></i></center></a>
	</div>';
	
	$button2 = '<!-- Single button -->
	<div class="btn-group">
	    <a type="button" class="btn btn-primary" href="pdf_file.php?i='.$categoriesId.'" id="editOrderModalBtn"> <center><i class="glyphicon glyphicon-eye-open"></i></center></a>
	</div>';
	
	$button3 = '<!-- Single button -->
	<div class="btn-group">
	    <a type="button" class="btn btn-primary" href="viewClientFiles.php?i='.$categoriesId.'" id="editOrderModalBtn"><center><i class="glyphicon glyphicon-eye-open"></i></center></a>
	</div>';
	
	
	$button4 = '<!-- Single button -->
	<div class="btn-group">
	<a type="button" class="btn btn-primary" data-toggle="modal" data-target="#removeCategoriesModal" id="removeCategoriesModalBtn" onclick="removeCategories('.$categoriesId.')"> <i class="glyphicon glyphicon-trash"></i></a>
	
	</div>';
	
	
	

 	$output['data'][] = array( 

	    $x,
 		$clientfName, 
 		$fileNo,
        $st,
		$role,
        $remarks, 
        $button1,
        $button 		
 		); 
        
		$x++;
		
 } // /while 

}// if num_rows

$conn->close();

echo json_encode($output);