-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.php
55 lines (45 loc) · 1.41 KB
/
data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
include ("include.common.php");
include("server.includes.inc.php");
$columns = json_decode($_REQUEST['cl']);
$columns[]="id";
$table = $_REQUEST['t'];
$obj = new $table();
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ){
$sLimit = " LIMIT ".intval( $_GET['iDisplayStart'] ).", ".intval( $_GET['iDisplayLength'] );
}
//error_log("Mapping:".$_REQUEST['sm']);
$data = $baseService->getData($_REQUEST['t'],$_REQUEST['sm'],$_REQUEST['ft'],$_REQUEST['ob'],$sLimit, $_REQUEST['cl'], $_REQUEST['sSearch']);
//Get Total row count
$totalRows = 0;
if(in_array($table, $baseService->userTables)){
$cemp = $baseService->getCurrentEmployeeId();
$sql = "Select count(id) as count from ".$obj->_table." where employee = ?";
$rowCount = $obj->DB()->Execute($sql, array($cemp));
}else{
$sql = "Select count(id) as count from ".$obj->_table;
$rowCount = $obj->DB()->Execute($sql);
}
foreach ($rowCount as $cnt) {
$totalRows = $cnt['count'];
}
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $totalRows,
"iTotalDisplayRecords" => $totalRows,
"aaData" => array()
);
foreach($data as $item){
$row = array();
$colCount = count($columns);
for ($i=0 ; $i<$colCount;$i++){
$row[] = $item->$columns[$i];
}
$output['aaData'][] = $row;
}
//error_log(print_r($output,true));
echo json_encode($output);