<?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'
);
$c_9 = $_POST['c_9'];
$c_10 = $_POST['c_10'];
$c_11 = $_POST['c_11'];
$c_12 = $_POST['c_12'];
$c_13 = $_POST['c_13'];
$ss = $_POST['s'];

if($c_9 == "0")
{
	$s9 = "none";
}else{
	$s9 = "";
}
if($c_10 == "0")
{
	$s10 = "none";
}else{
	$s10 = "";
}

if($c_11 == "0")
{
	$s11 = "none";
}else{
	$s11 = "";
}


if($c_12 == "0")
{
	$s12 = "none";
}else{
	$s12 = "";
}

if($c_13 == "0")
{
	$s13 = "none";
}else{
	$s13 = "";
}
if($ss == 0)
{
	$sql = "SELECT `id_cus`, `name_cus`, `phone_cus`, `born_cus`, `type_play`, `id_scanner`, `date_cus`, `type_stop`, `cus_active`, `active_play`, `id_member`, `count_s`, `member_date`, `memeber_end`, `mony_cus`, `com_cus`, `nato_cus`, `massage_cus`, `date_fraze`, `day_stay_fraze`, `id_emp_fraze` ";
	$sql.="  from `cus` where `cus_active` = '0'";
}else{
	$sql = "SELECT `id_cus`, `name_cus`, `phone_cus`, `born_cus`, `type_play`, `id_scanner`, `date_cus`, `type_stop`, `cus_active`, `active_play`, `id_member`, `count_s`, `member_date`, `memeber_end`, `mony_cus`, `com_cus`, `nato_cus`, `massage_cus`, `date_fraze`, `day_stay_fraze`, `id_emp_fraze`  ";
	$sql.="  from `cus` where `cus_active` = '0' and `id_member` = '".$ss."'";
}

$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
if($ss == 0)
{
	$sql = "SELECT `id_cus`, `name_cus`, `phone_cus`, `born_cus`, `type_play`, `id_scanner`, `date_cus`, `type_stop`, `cus_active`, `active_play`, `id_member`, `count_s`, `member_date`, `memeber_end`, `mony_cus`, `com_cus`, `nato_cus`, `massage_cus`, `date_fraze`, `day_stay_fraze`, `id_emp_fraze` ";
	$sql.="  from `cus` where `cus_active` = '0'";	
}else{
	$sql = "SELECT `id_cus`, `name_cus`, `phone_cus`, `born_cus`, `type_play`, `id_scanner`, `date_cus`, `type_stop`, `cus_active`, `active_play`, `id_member`, `count_s`, `member_date`, `memeber_end`, `mony_cus`, `com_cus`, `nato_cus`, `massage_cus`, `date_fraze`, `day_stay_fraze`, `id_emp_fraze` ";
	$sql.="  from `cus` where `cus_active` = '0' and `id_member` = '".$ss."'";
}
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();
$i = 0;
while( $row=mysqli_fetch_array($query)) {
	$nestedData=array(); 
	$i++;
	
	if($row['type_play'] == 0)
	 {
		$a =  "عادى"; 
	 }	 
	 if($row['type_play'] == 1)
	 {
		 $a = "عادى او كارت	";
	 }


	$nestedData[] = $i;
	$nestedData[] = $row["name_cus"];
	$nestedData[] = $row["phone_cus"];
	$nestedData[] = $row['id_scanner'];
	$nestedData[] = 
	"
	                   <button  style='display:".$s10."' onclick='del_cus(".$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'><i class='fa fa-trash' aria-hidden='true'></i></button>
                       <button style='display:".$s9."' class='btn btn-success ' href='javascript:void(0)' data-role='update' data-id='".  $row['id_cus'] ."' data-toggle='modal' onclick='get_cus(".  $row['id_cus'] .")' rel='tooltip'  data-placement='auto' data-original-title='تعديل بيانات العميل'><i class='fa fa-pencil' aria-hidden='true'></i></button>
                      
                       <button class='btn btn-warning ' style='display:".$s11."'  onclick='open_mony(".  $row['id_cus'] .")'ل من العميل'> <i class='fa fa-credit-card'></i></button>
                       <button   class='btn btn-success ' href='javascript:void(0)' data-role='member' data-id='".  $row['id_cus'] ."' data-toggle='modal' onclick='photo(".$row['id_cus'].")' rel='tooltip'  data-placement='auto' data-original-title=''><i class='fa fa-camera'  aria-hidden='true'></i></button>
                       <button  style='display:".$s11."' class='btn btn-warning ' style='' href='javascript:void(0)' data-role='' data-id='".  $row['id_cus'] ."' data-toggle='modal' onclick='ser_cus(".$row['id_cus'].")' rel='tooltip'  data-placement='auto' data-original-title=''> <i class='fa fa-th-list' aria-hidden='true'></i>
					   </button>
    <button class='btn btn-success ' style='display:".$s9."' onclick='return_memeber(".  $row['id_cus'] .")' rel='tooltip'  data-placement='auto' data-original-title=' '> <i class='fa fa-undo' aria-hidden='true'></i>	</button>
	<button  style='display:".$s12."' class='btn btn-warning ' style='' href='javascript:void(0)' data-role='' data-id='".  $row['id_cus'] ."' data-toggle='modal' onclick='discount_cus(".$row['id_cus'].")' rel='tooltip'  data-placement='auto' data-original-title=''><i class='fa fa-percent' aria-hidden='true'></i>	</button>
    <button class='btn btn-success ' onclick='massage_cus(".  $row['id_cus'] .")' rel='tooltip'  data-placement='auto' data-original-title=' '><i class='fa fa-bell' aria-hidden='true'></i>	</button>
	<button   class='btn btn-warning ' style='' href='javascript:void(0)' data-role='' data-id='".  $row['id_cus'] ."' data-toggle='modal' onclick='login_cus(".$row['id_cus'].")' rel='tooltip'  data-placement='auto' data-original-title=''> <i class='fa fa-id-card' aria-hidden='true'></i>	</button>
   
	<button class='btn btn-defulet '  style='display:".$s13."'  onclick='change_cus(".  $row['id_cus'] .")' rel='tooltip'  data-placement='auto' data-original-title=' '> <i class='fa fa-database' aria-hidden='true'></i></button>
   
	<button  style='display:".$s13."' class='btn btn-success ' href='javascript:void(0)' data-role='member' data-id='".  $row['id_cus'] ."' data-toggle='modal' onclick='change_mem(".$row['id_cus'].")' rel='tooltip'  data-placement='auto' data-original-title=''>	<i class= 'fa fa-cog'  aria-hidden='true'></i></button>
	
	";	
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



