escape(trim($_GET['search']));
} else {
$search = "";
}
if(isset($_GET['offset'])){
$offset = $db -> escape(trim($_GET['offset']));
} else {
$offset = "";
}
if(isset($_GET['limit'])){
$limit = $db -> escape(trim($_GET['limit']));
$offset_limit = " LIMIT ". $offset.",".$limit;
} else {
$offset_limit = "";
}
$json_arr['rows'] = array();
$count = " count(ed.id) ";
$fields = " ed.id, ed.department_code, ed.department_name, e.first_name, e.last_name, ed.status ";
$department_query = "SELECT %s FROM `employee_department` ed
INNER JOIN `employee` e ON ed.add_by=e.id
WHERE ed.department_code LIKE '%%%s%%' AND ed.id != 0 ORDER BY department_name ASC ";
//echo sprintf($department_query,$fields,$search)." $offset_limit";return;
$department_list_query = $db -> sql_query(sprintf($department_query, $fields, $search)." $offset_limit");
$department_list_query_count = $db -> select(sprintf($department_query,$count,$search));
//$menu_arr = array();
//$sub_menu_arr = array();
while($row = $department_list_query->fetch_assoc()) {
$json_arr['rows'] = array_merge($json_arr['rows'],array(array('code'=>$row['department_code'] ,
'id'=>$row['id'],
'name'=>$row['department_name'],
'add_by'=>$row['first_name']. " " .$row['last_name'],
'status'=>$row['status']//,
//'customer_name_id'=>(($row['name']) <> "" ? $row['name'] : "(Not provided)")
// 'customer_name_id'=>(($row['customer_id']) <> "" ? $row['customer_id'] : "") . " / " .
// (($row['name']) <> "" ? $row['name'] : "(Not provided)")
)));
}
$json_arr['total'] = $department_list_query_count; //total number of result
echo json_encode($json_arr);
?>