-
Notifications
You must be signed in to change notification settings - Fork 0
/
credithistory.grid.inc.php
260 lines (221 loc) · 9.34 KB
/
credithistory.grid.inc.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
/*******************************************************************************
* credithistory.grid.inc.php
* credithistory操作类
* Customer class
* @author Solo Fu <[email protected]>
* @classVersion 1.0
* @date 18 Oct 2007
* Functions List
getAllRecords 获取所有记录
getRecordsFiltered 获取记录集
getNumRows 获取记录集条数
新增getRecordsFilteredMore 用于获得多条件搜索记录集
新增getNumRowsMore 用于获得多条件搜索记录条数
新增getRecordsFilteredMorewithstype 用于获得指定匹配方式(like,=,<,>)的多条件记录集
新增getNumRowsMorewithstype 用于获得指定匹配方式(like,=,<,>)的多条件记录条数
********************************************************************************/
require_once 'db_connect.php';
require_once 'credithistory.common.php';
require_once 'include/astercrm.class.php';
class Customer extends astercrm
{
/**
* Obtiene todos los registros de la tabla paginados.
*
* @param $start (int) Inicio del rango de la página de datos en la consulta SQL.
* @param $limit (int) Límite del rango de la página de datos en la consultal SQL.
* @param $order (string) Campo por el cual se aplicará el orden en la consulta SQL.
* @return $res (object) Objeto que contiene el arreglo del resultado de la consulta SQL.
*/
function &getAllRecords($start, $limit, $order = null, $creby = null){
global $db;
if($_SESSION['curuser']['usertype'] == 'admin'){
$sql = "SELECT * FROM credithistory ";
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$sql = "SELECT * FROM credithistory WHERE credithistory.groupid = '".$_SESSION['curuser']['groupid']."'" ;
}elseif($_SESSION['curuser']['usertype'] == 'reseller'){
$sql = "SELECT * FROM credithistory WHERE resellerid = '".$_SESSION['curuser']['resellerid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'clid'){
$sql = "SELECT * FROM credithistory WHERE clidid = '".$_SESSION['curuser']['clidid']."'";
}
if($order == null || is_array($order)){
$sql .= " ORDER by modifytime DESC LIMIT $start, $limit";//.$_SESSION['ordering'];
}else{
$sql .= " ORDER BY ".$order." ".$_SESSION['ordering']." LIMIT $start, $limit";
}
Customer::events($sql);
$res =& $db->query($sql);
return $res;
}
/**
* Obtiene todos registros de la tabla paginados y aplicando un filtro
*
* @param $start (int) Es el inicio de la página de datos en la consulta SQL
* @param $limit (int) Es el limite de los datos páginados en la consultal SQL.
* @param $filter (string) Nombre del campo para aplicar el filtro en la consulta SQL
* @param $content (string) Contenido a filtrar en la conslta SQL.
* @param $order (string) Campo por el cual se aplicará el orden en la consulta SQL.
* @return $res (object) Objeto que contiene el arreglo del resultado de la consulta SQL.
*/
function &getRecordsFilteredMore($start, $limit, $filter, $content, $order,$table, $ordering = ""){
global $db;
$i=0;
$joinstr='';
foreach ($content as $value){
$value = preg_replace("/'/","\\'",$value);
$value=trim($value);
if (strlen($value)!=0 && strlen($filter[$i]) != 0){
$joinstr.="AND $filter[$i] like '%".$value."%' ";
}
$i++;
}
if($_SESSION['curuser']['usertype'] == 'admin'){
$sql = "SELECT * FROM credithistory WHERE ";
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$sql = "SELECT * FROM credithistory WHERE groupid = '".$_SESSION['curuser']['groupid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'reseller'){
$sql = "SELECT * FROM credithistory WHERE resellerid = '".$_SESSION['curuser']['resellerid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'clid'){
$sql = "SELECT * FROM credithistory WHERE clidid = '".$_SESSION['curuser']['clidid']."'";
}
if ($joinstr!=''){
if ( $_SESSION['curuser']['usertype'] == 'admin' ){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= $joinstr." ";
}else{
$sql .= $joinstr." ";
}
}
$sql .= " ORDER BY ".$order
." ".$_SESSION['ordering']
." LIMIT $start, $limit $ordering";
Customer::events($sql);
$res =& $db->query($sql);
return $res;
}
/**
* Devuelte el numero de registros de acuerdo a los parámetros del filtro
*
* @param $filter (string) Nombre del campo para aplicar el filtro en la consulta SQL
* @param $order (string) Campo por el cual se aplicará el orden en la consulta SQL.
* @return $row['numrows'] (int) Número de registros (líneas)
*/
function &getNumRows($filter = null, $content = null){
global $db;
if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " SELECT COUNT(*) FROM credithistory ";
}elseif ($_SESSION['curuser']['usertype'] == 'groupadmin'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE groupid = '".$_SESSION['curuser']['groupid']."'";
}elseif ($_SESSION['curuser']['usertype'] == 'reseller'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE resellerid = '".$_SESSION['curuser']['resellerid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'clid'){
$sql = "SELECT COUNT(*) FROM credithistory WHERE clidid = '".$_SESSION['curuser']['clidid']."'";
}
Customer::events($sql);
$res =& $db->getOne($sql);
return $res;
}
function &getNumRowsMore($filter = null, $content = null,$table){
global $db;
$i=0;
$joinstr='';
foreach ($content as $value){
$value = preg_replace("/'/","\\'",$value);
$value=trim($value);
if (strlen($value)!=0 && strlen($filter[$i]) != 0){
$joinstr.="AND $filter[$i] like '%".$value."%' ";
}
$i++;
}
if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE ";
}elseif ($_SESSION['curuser']['usertype'] == 'groupadmin'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE groupid = '".$_SESSION['curuser']['groupid']."'";
}elseif ($_SESSION['curuser']['usertype'] == 'reseller'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE resellerid = '".$_SESSION['curuser']['resellerid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'clid'){
$sql = "SELECT COUNT(*) FROM credithistory WHERE clidid = '".$_SESSION['curuser']['clidid']."'";
}
if ($joinstr!='' ){
if ( $_SESSION['curuser']['usertype'] == 'admin' ){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= $joinstr." ";
}else{
$sql .= $joinstr." ";
}
}
Customer::events($sql);
$res =& $db->getOne($sql);
return $res;
}
function &getNumRowsMorewithstype($filter = null, $content = null,$stype = null,$table){
global $db;
$joinstr = astercrm::createSqlWithStype($filter,$content,$stype);
if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE ";
}elseif ($_SESSION['curuser']['usertype'] == 'groupadmin'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE groupid = '".$_SESSION['curuser']['groupid']."'";
}elseif ($_SESSION['curuser']['usertype'] == 'reseller'){
$sql .= " SELECT COUNT(*) FROM credithistory WHERE resellerid = '".$_SESSION['curuser']['resellerid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'clid'){
$sql = "SELECT COUNT(*) FROM credithistory WHERE clidid = '".$_SESSION['curuser']['clidid']."'";
}
if ($joinstr!='' ){
if ( $_SESSION['curuser']['usertype'] == 'admin' ){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= $joinstr." ";
}else{
$sql .= $joinstr." ";
}
}
Customer::events($sql);
$res =& $db->getOne($sql);
return $res;
}
function &getRecordsFilteredMorewithstype($start, $limit, $filter, $content, $stype = null, $order,$table, $ordering = ""){
global $db;
$joinstr = astercrm::createSqlWithStype($filter,$content,$stype);
if($_SESSION['curuser']['usertype'] == 'admin'){
$sql = "SELECT * FROM credithistory WHERE ";
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$sql = "SELECT * FROM credithistory WHERE groupid = '".$_SESSION['curuser']['groupid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'reseller'){
$sql = "SELECT * FROM credithistory WHERE resellerid = '".$_SESSION['curuser']['resellerid']."'";
}elseif($_SESSION['curuser']['usertype'] == 'clid'){
$sql = "SELECT * FROM credithistory WHERE clidid = '".$_SESSION['curuser']['clidid']."'";
}
if ($joinstr!='' ){
if ( $_SESSION['curuser']['usertype'] == 'admin' ){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= $joinstr." ";
}else{
$sql .= $joinstr." ";
}
}
$sql .= " ORDER BY ".$order
." ".$_SESSION['ordering']
." LIMIT $start, $limit $ordering";
Customer::events($sql);
$res =& $db->query($sql);
return $res;
}
function &getNames($userid, $resellerid, $groupid, $clidid){
global $db;
$username =& $db->getone("SELECT username FROM account WHERE id = '".$userid."' LIMIT 1");
$resellername =& $db->getone("SELECT resellername FROM resellergroup WHERE id = '".$resellerid."'");
if ( $groupid != '0' ){
$groupname =& $db->getone("SELECT groupname FROM accountgroup WHERE id = '".$groupid."'");
}else{
$groupname = '';
}
if( $clidid != '0' ){
$clidname =& $db->getone("SELECT clid FROM clid WHERE id = '".$clidid."'");
}else{
$clidname = '';
}
$names = array('username' => $username, 'resellername' => $resellername, 'groupname' => $groupname, 'clidname' => $clidname);
return $names;
}
}
?>