<?php
require_once '../../Server/connection.php';

## Read value
$draw = $_POST['draw'];
$row = $_POST['start'];
$rowperpage = $_POST['length']; // Rows display per page
$columnIndex = $_POST['order'][0]['column']; // Column index
$columnName = $_POST['columns'][$columnIndex]['data']; // Column name
$columnSortOrder = $_POST['order'][0]['dir']; // asc or desc
$searchValue = $_POST['search']['value']; // Search value

## Custom Field value
//$searchByPermName = $_POST['searchByPermName'];
//$searchByroleName = $_POST['searchByroleName'];
$staffId = $_POST['staffId'];
## Search 



## Total number of records without filtering
$sel = mysqli_query($conn,"select count(*) as allcount from staffdocs where staff_id='$staffId'");
$records = mysqli_fetch_assoc($sel);
$totalRecords = $records['allcount'];



## Fetch records
$empQuery = "select * from staffdocs where staff_id='$staffId'";
$empRecords = mysqli_query($conn, $empQuery);
$data = array();
$x = 1;
while ($row = mysqli_fetch_assoc($empRecords)){
	
	$productId = $row['staff_docId'];
	$fileName = $row['fileName'];
	
	$fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
	
	//if($fileExtension=='pdf' or $fileExtension=='doc' or $fileExtension=='docx' or $fileExtension=='xlsx' or $fileExtension=='txt' or $fileExtension=='csv'){
   $button = '<!-- Single button -->
	<div class="btn-group">
	    <a class="btn btn-primary" href="files/'.$fileName.'"  id="editOrderModalBtn"> <i class="glyphicon glyphicon-download"></i></a>
	</div>';
       //}
	   
	   
	   //else{
	
     //$imageUrl = substr($row['fileName'], 3);	
	 //$button = "<img class='img-round' src='".$imageUrl."' style='height:100px; width:100px;'  />";
		   
     //$button ='No File Uploaded';
       //}
	
	$button1 = '<!-- Single button -->
	<div class="btn-group">
	<a type="button" class="btn btn-primary" data-toggle="modal" data-target="#removeProductModal" id="removeProductModalBtn" onclick="removeProduct('.$productId.')"> <i class="glyphicon glyphicon-trash"></i></a>
	
	</div>';
	
	
    $data[] = array(
    		"doc_id"=>$x,
			"FileExt"=>$fileExtension,
			"Files"=>$button,
    		//"delete"=>$button1
    	);
		$x++;
		
		
}

## Response
$response = array(
    "draw" => intval($draw),
    "iTotalRecords" => $totalRecords,
    "iTotalDisplayRecords" => $totalRecordwithFilter,
    "aaData" => $data
);

echo json_encode($response);
