-
Notifications
You must be signed in to change notification settings - Fork 36
/
data.php
123 lines (102 loc) · 3.2 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
define('CLIENT_PATH',dirname(__FILE__));
include ("include.common.php");
$modulePath = getSessionObject("modulePath");
if(!defined('MODULE_PATH')){
define('MODULE_PATH',$modulePath);
}
include("server.includes.inc.php");
if(empty($user)){
$ret['status'] = "ERROR";
echo json_encode($ret);
exit();
}
$_REQUEST['sm'] = fixJSON($_REQUEST['sm']);
$_REQUEST['cl'] = fixJSON($_REQUEST['cl']);
$_REQUEST['ft'] = fixJSON($_REQUEST['ft']);
$columns = json_decode($_REQUEST['cl'],true);
$columns[]="id";
$table = $_REQUEST['t'];
$obj = new $table();
$sLimit = "";
if ( isset( $_REQUEST['iDisplayStart'] ) && $_REQUEST['iDisplayLength'] != '-1' ){
$sLimit = " LIMIT ".intval( $_REQUEST['iDisplayStart'] ).", ".intval( $_REQUEST['iDisplayLength'] );
}
$isSubOrdinates = false;
if(isset($_REQUEST['type']) && $_REQUEST['type']="sub"){
$isSubOrdinates = true;
}
$skipEmployeeRestriction = false;
if(isset($_REQUEST['skip']) && $_REQUEST['type']="1"){
$skipEmployeeRestriction = true;
}
$data = $baseService->getData($_REQUEST['t'],$_REQUEST['sm'],$_REQUEST['ft'],$_REQUEST['ob'],$sLimit, $_REQUEST['cl'], $_REQUEST['sSearch'],$isSubOrdinates,$skipEmployeeRestriction);
//Get Total row count
$totalRows = 0;
$countFilterQuery = "";
$countFilterQueryData = array();
if(!empty($_REQUEST['ft'])){
$filter = json_decode($_REQUEST['ft']);
if(!empty($filter)){
foreach($filter as $k=>$v){
$countFilterQuery.=" and ".$k."=?";
$countFilterQueryData[] = $v;
}
}
}
if(in_array($table, $baseService->userTables) && !$skipEmployeeRestriction && !$isSubOrdinates){
$cemp = $baseService->getCurrentEmployeeId();
$sql = "Select count(id) as count from ".$obj->_table." where employee = ? ".$countFilterQuery;
array_unshift($countFilterQueryData,$cemp);
$rowCount = $obj->DB()->Execute($sql, $countFilterQueryData);
}else{
if($isSubOrdinates){
$cemp = $baseService->getCurrentEmployeeId();
$subordinate = new Employee();
$subordinates = $subordinate->Find("supervisor = ?",array($cemp));
$subordinatesIds = "";
foreach($subordinates as $sub){
if($subordinatesIds != ""){
$subordinatesIds.=",";
}
$subordinatesIds.=$sub->id;
}
$subordinatesIds.="";
$sql = "Select count(id) as count from ".$obj->_table." where employee in (".$subordinatesIds.") ".$countFilterQuery;
$rowCount = $obj->DB()->Execute($sql,$countFilterQueryData);
}else{
$sql = "Select count(id) as count from ".$obj->_table;
if(!empty($countFilterQuery)){
$sql.=" where 1=1 ".$countFilterQuery;
}
$rowCount = $obj->DB()->Execute($sql,$countFilterQueryData);
}
}
foreach ($rowCount as $cnt) {
$totalRows = $cnt['count'];
}
/*
* Output
*/
$output = array(
"sEcho" => intval($_REQUEST['sEcho']),
"iTotalRecords" => $totalRows,
"iTotalDisplayRecords" => $totalRows,
"aaData" => array()
);
/*
$output['debug_data'] = print_r($data,true);
$output['debug_col'] = print_r($columns,true);
$output['debug_col_plain'] = $_REQUEST['cl'];
$output['get_magic_quotes_gpc'] = get_magic_quotes_gpc();
*/
foreach($data as $item){
$row = array();
$colCount = count($columns);
for ($i=0 ; $i<$colCount;$i++){
$row[] = $item->$columns[$i];
}
$row["_org"] = $baseService->cleanUpAdoDB($item);
$output['aaData'][] = $row;
}
echo json_encode($output);