<?php
include("../db.php");
$requestData= $_REQUEST;
$columns = array( 
	0 =>  'id_cus',
	1 => 'name_cus',
	2 => 'phone_cus',
	3 => 'type_play',
	4 => 'id_scanner',
	5 => 'img'
);


	$sql = "SELECT * ";
	$sql.="  from `cus` where `cus_active` = '5'";


$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;

	$sql = "SELECT * ";
	$sql.="  from `cus` where `cus_active` = '5'";	

if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( id_cus LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_cus LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR phone_cus LIKE '".$requestData['search']['value']."%' ";
	$sql.=" OR id_scanner 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['type_play'] == 0)
	 {
		$a =  "عادى"; 
	 }	 
	 if($row['type_play'] == 1)
	 {
		 $a = "عادى او كارت	";
	 }

	 $le_img = strlen($row['img']);
	 if($le_img == 0)
	 {
		 $img = "images/a.png";
	 }else{
		 $img = $row['img'];
	 }		
	$nestedData[] = "<img onclick=open_img('.$img.') src='".$img."' style='width:15%' />";
	$nestedData[] = $row["name_cus"];
	$nestedData[] = $row["phone_cus"];
	$nestedData[] = $row['id_scanner'];
	$nestedData[] = 
	"
	                   <button  style='' onclick='return_active(".$row['id_cus'].")'  href='javascript:void(0)' data-role='del' data-id='".$row['id_cus']."' rel='tooltip'  data-placement='auto' data-original-title='حذف العميل' class='btn btn-danger'>اعادة</button>

   ";	
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



