<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
	0 =>  'name_emp',
	1 =>  'name_job',
	2 =>  'name_branch'
);

$sql = "
SELECT * FROM emp 
left join `jobs` on`emp`.`id_job` = `jobs`.`id_job`
left join  `branch` on`branch`.`id_branch` = `emp`.`id_branch`
where `emp`.`active_emp` = '0'
";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "
SELECT * FROM emp 
left join `jobs` on`emp`.`id_job` = `jobs`.`id_job`
left join  `branch` on`branch`.`id_branch` = `emp`.`id_branch`
where `emp`.`active_emp` = '0'
";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( name_emp LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_job LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR name_branch LIKE '".$requestData['search']['value']."%' )";
}
$query=mysqli_query($db, $sql);
$totalFiltered = mysqli_num_rows($query); 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
$query=mysqli_query($db, $sql);
$data = array();
while( $row=mysqli_fetch_array($query)) {
	$nestedData=array(); 
    
	if($row['login_emp'] == 1)
	{
		$a = 
		"
			<button type='button' class='btn btn-warning' onclick='acc_custem(3,3,".$row['id_emp'].")'>الصلاحيات</button>
		";
	}else{
		$a = "";
	}
	
	$nestedData[] = $row["name_emp"];
	$nestedData[] = $row["name_branch"];
	$nestedData[] = $row["name_job"];
	$nestedData[] = "<button type='button' class='btn btn-danger' onclick=acc_custem(2,1,'".$row['id_emp']."')>حذف</button>
	<button type='button' class='btn btn-success'  onclick='acc_custem(2,0,".$row['id_emp'].")'>تعديل</button>
	".$a;
	
	$data[] = $nestedData;
}



$json_data = array(
			"draw"            => intval( $requestData['draw']),   
			"recordsTotal"    => intval( $totalData ),  
			"recordsFiltered" => intval( $totalFiltered ),
			"data"            => $data
			);

echo json_encode($json_data);

?>



