<?php
include("../db.php");
$requestData= $_REQUEST;
$type = $_POST['type'];
$columns = array( 
	0 =>  'id_pro',
	1 =>  'name_pro',
    2 =>  'name_type',
    3 =>  'price_buy',
    4 =>  'scanner_pro'
);

$sql = "
SELECT * FROM `pro`
left join `type_1` on `type_1`.`id_type` = `pro`.`id_type`
where `pro`.`active_pro` = '0'
";
$query=mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "
SELECT * FROM `pro`
left join `type_1` on `type_1`.`id_type` = `pro`.`id_type`
where `pro`.`active_pro` = '0'
";
if( !empty($requestData['search']['value']) ) {  
	$sql.=" AND ( id_pro LIKE '".$requestData['search']['value']."%'  ";
	$sql.=" OR name_pro LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR name_type LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR price_buy LIKE '".$requestData['search']['value']."%' ";    
	$sql.=" OR scanner_pro 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(); 
	$nestedData[] = $row["id_pro"];
	$nestedData[] = $row["name_pro"];
	$nestedData[] = $row["name_type"];
	$nestedData[] = $row["price_buy"];
	$nestedData[] = $row["scanner_pro"];
	$nestedData[] = "<button type='button' class='btn btn-danger' onclick=del_branch('".$row['id_cus']."')>حذف</button>
	<button type='button' class='btn btn-success'  onclick='get_type_3(".$row['id_pro'].")'>تعديل</button>
	";
	
	$data[] = $nestedData;
}



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

echo json_encode($json_data);

?>



