
<?php

//order_fetch.php

 include("../../../dbconnection/dbconnection.php");
// include('function.php');

$query = '';

$output = array();

$query .= "
	SELECT * FROM staff 
";
/*
if($_SESSION['type'] == 'admin')
{
	$query .= 'user_id = "'.$_SESSION["user_id"].'" AND ';
}
*/

$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row)
{
	
	$status = '';
	if($row['status'] == '1')
	{
		$status = '<span class="label label-success">Active</span>';
	}
	else
	{
		$status = '<span class="label label-danger">Disabled</span>';
	}
	$sub_array = array();
	$sub_array[] = $row['emp_no'];
	$sub_array[] = $row['fname'];
	$sub_array[] = $row['email'];
	$sub_array[] = $status;
	$sub_array[] = $row['account'];
	/*
	if($_SESSION['type'] == 'master')
	{
		$sub_array[] = get_user_name($connect, $row['user_id']);
	}
	*/
	$sub_array[] = '<a href="view_order.php?pdf=1&order_id='.$row["emp_no"].'" class="btn btn-info btn-xs">View PDF</a>';
	$sub_array[] = '<button type="button" name="update" id="'.$row["emp_no"].'" class="btn btn-warning btn-xs update">Update</button>';
	$data[] = $sub_array;
}

function get_total_all_records($connect)
{
	$statement = $connect->prepare("SELECT * FROM staff");
	$statement->execute();
	return $statement->rowCount();
}

$output = array(
	"draw"    			=> 	intval($_POST["draw"]),
	"recordsTotal"  	=>  $filtered_rows,
	"recordsFiltered" 	=> 	get_total_all_records($connect),
	"data"    			=> 	$data
);	

echo json_encode($output);

?>