-
Notifications
You must be signed in to change notification settings - Fork 0
/
customers.grid.inc.php
377 lines (317 loc) · 13.1 KB
/
customers.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
/*******************************************************************************
* clid.grid.inc.php
* clid操作类
* Customer class
* @author Solo Fu <[email protected]>
* @classVersion 1.0
* @date 18 Oct 2007
* Functions List
getAllRecords 获取所有记录
getRecordsFiltered 获取记录集
getNumRows 获取记录集条数
formAdd 生成添加clid表单的HTML
formEdit 生成编辑clid表单的HTML
新增getRecordsFilteredMore 用于获得多条件搜索记录集
新增getNumRowsMore 用于获得多条件搜索记录条数
* Revision 0.0456 2007/10/30 13:15:00 last modified by solo
* Desc: add channel field
* Revision 0.045 2007/10/18 13:15:00 last modified by solo
* Desc: page created
********************************************************************************/
require_once 'customers.common.php';
require_once 'include/astercrm.class.php';
//ini_set('include_path',dirname($_SERVER["SCRIPT_FILENAME"])."/include");
// define database connection string
define('SQLCC', $config['customers']['dbtype']."://".$config['customers']['username'].":".$config['customers']['password']."@tcp+".$config['customers']['dbhost'].":".$config['customers']['dbport']."/".$config['customers']['dbname']."");
// set a global variable to save customers database connection
$GLOBALS['customers_db'] = DB::connect(SQLCC);
//print_R($GLOBALS['customers_db']);exit;
// need to check if db connected
if (DB::iserror($GLOBALS['customers_db'])){
die("customer database:".$GLOBALS['customers_db']->getmessage());
}
// change database fetch mode
$GLOBALS['customers_db']->setFetchMode(DB_FETCHMODE_ASSOC);
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 $customers_db,$config;
$sql = "SELECT * FROM ".$config['customers']['customertable']." ";
if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " ";
}//elseif ($_SESSION['curuser']['usertype'] == 'reseller'){
// $sql .= " WHERE clid.resellerid = ".$_SESSION['curuser']['resellerid']." ";
//}else{
// $sql .= " WHERE clid.groupid = ".$_SESSION['curuser']['groupid']." ";
//}
if($order == null){
$sql .= " LIMIT $start, $limit";//.$_SESSION['ordering'];
}else{
$sql .= " ORDER BY $order ".$_SESSION['ordering']." LIMIT $start, $limit";
}
//echo $sql;exit;
Customer::events($sql);
$res =& $customers_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 $customers_db,$config;
$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++;
}
$sql = "SELECT * FROM ".$config['customers']['customertable']." WHERE ";
//if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " 1 ";
//}
if ($joinstr!=''){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= " AND ".$joinstr." "
." ORDER BY ".$order
." ".$_SESSION['ordering']
." LIMIT $start, $limit $ordering";
}
Customer::events($sql);
$res =& $customers_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 $customers_db,$config;
//if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql = " SELECT COUNT(*) FROM ".$config['customers']['customertable']." ";
//}//elseif ($_SESSION['curuser']['usertype'] == 'reseller'){
// $sql = " SELECT COUNT(*) FROM clid LEFT JOIN accountgroup ON accountgroup.id = clid.groupid LEFT JOIN resellergroup ON resellergroup.id = clid.resellerid WHERE clid.resellerid = ".$_SESSION['curuser']['resellerid']." ";
//}else{
// $sql = " SELECT COUNT(*) FROM clid LEFT JOIN accountgroup ON accountgroup.id = clid.groupid LEFT JOIN resellergroup ON resellergroup.id = clid.resellerid WHERE clid.groupid = ".$_SESSION['curuser']['groupid']." ";
//}
Customer::events($sql);
$res =& $customers_db->getOne($sql);
return $res;
}
function &getNumRowsMore($filter = null, $content = null,$table){
global $customers_db,$config;
$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++;
}
$sql = "SELECT COUNT(*) FROM ".$config['customers']['customertable']." WHERE ";
//if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " 1 ";
//}
if ($joinstr!=''){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= " AND ".$joinstr;
}
Customer::events($sql);
$res =& $customers_db->getOne($sql);
return $res;
}
function &getRecordsFilteredMorewithstype($start, $limit, $filter, $content, $stype,$order,$table){
global $customers_db,$config;
$joinstr = astercrm::createSqlWithStype($filter,$content,$stype);
$sql = "SELECT * FROM ".$config['customers']['customertable']." WHERE ";
//if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " 1 ";
//}
if ($joinstr!=''){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= " AND ".$joinstr." "
." ORDER BY ".$order
." ".$_SESSION['ordering']
." LIMIT $start, $limit $ordering";
}
Customer::events($sql);
$res =& $customers_db->query($sql);
return $res;
}
function &getNumRowsMorewithstype($filter, $content,$stype,$table){
global $customers_db,$config;
$joinstr = astercrm::createSqlWithStype($filter,$content,$stype);
$sql = "SELECT COUNT(*) FROM ".$config['customers']['customertable']." WHERE ";
//if ($_SESSION['curuser']['usertype'] == 'admin'){
$sql .= " 1 ";
//}
if ($joinstr!=''){
$joinstr=ltrim($joinstr,'AND'); //去掉最左边的AND
$sql .= " AND ".$joinstr;
}
Customer::events($sql);
$res =& $customers_db->getOne($sql);
return $res;
}
/**
* Imprime la forma para agregar un nuevo registro sobre el DIV identificado por "formDiv".
*
* @param ninguno
* @return $html (string) Devuelve una cadena de caracteres que contiene la forma para insertar
* un nuevo registro.
*/
function formAdd(){
global $locate,$config;
$pin = astercrm::generateUniquePin(intval($config['system']['pin_len']));
$html = '
<!-- No edit the next line -->
<form method="post" name="f" id="f">
<table border="1" width="100%" class="adminlist">
<tr>
<td nowrap align="left">'.$locate->Translate("Pin").'*</td>
<td align="left"><input type="text" id="pin" name="pin" size="25" maxlength="30" value="'.$pin.'" readonly><input type="hidden" id="pin" name="pin" value="'.$pin.'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("First name").'</td>
<td align="left"><input type="text" id="first_name" name="first_name" size="25" maxlength="50"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Last name").'</td>
<td align="left"><input type="text" id="last_name" name="last_name" size="25" maxlength="50"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Discount").'</td>
<td align="left"><input type="radio" id="discount_type" name="discount_type" value="0" onclick="selectDiscountType(this.value);" checked>'.$locate->Translate("Dynamic").'<input type="radio" id="discount_type" name="discount_type" value="1" onclick="selectDiscountType(this.value);">'.$locate->Translate("Static").' <input type="text" id="discount" name="discount" size="15" maxlength="10" disabled></td>
</tr>
<tr>
<td colspan="2" align="center"><button id="submitButton" onClick=\'xajax_save(xajax.getFormValues("f"));return false;\'>'.$locate->Translate("continue").'</button></td>
</tr>
</table>
';
$html .='
</form>
*'.$locate->Translate("obligatory_fields").'
';
return $html;
}
/**
* Imprime la forma para editar un nuevo registro sobre el DIV identificado por "formDiv".
*
* @param $id (int) Identificador del registro a ser editado.
* @return $html (string) Devuelve una cadena de caracteres que contiene la forma con los datos
* a extraidos de la base de datos para ser editados
*/
function formEdit($id){
global $customers_db,$config,$locate;
$sql = "SELECT * FROM ".$config['customers']['customertable']." WHERE id = $id";
//echo $sql;exit;
$customer = $customers_db->getRow($sql);
if($customer['discount'] == -1){
$dynamic = 'checked';
$static = '';
$discount_abled = 'disabled';
$discount_value = '';
}else{
$dynamic = '';
$static = 'checked';
$discount_abled = '';
$discount_value = $customer['discount'];
}
//print_r($customer);exit;
$html = '
<!-- No edit the next line -->
<form method="post" name="f" id="f">
<table border="1" width="100%" class="adminlist">
<tr>
<td nowrap align="left">'.$locate->Translate("Pin").'*</td>
<td align="left"><input type="text" id="pin" name="pin" size="25" maxlength="30" value="'.$customer['pin'].'" readonly><input type="hidden" id="pin" name="pin" value="'.$customer['pin'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("First name").'</td>
<td align="left"><input type="text" id="first_name" name="first_name" size="25" maxlength="50" value="'.$customer['first_name'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Last name").'</td>
<td align="left"><input type="text" id="last_name" name="last_name" size="25" maxlength="50" value="'.$customer['last_name'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Discount").'</td>
<td align="left"><input type="radio" id="discount_type" name="discount_type" value="0" onclick="selectDiscountType(this.value);" '.$dynamic.'>'.$locate->Translate("Dynamic").'<input type="radio" id="discount_type" name="discount_type" value="1" onclick="selectDiscountType(this.value);" '.$static.'>'.$locate->Translate("Static").' <input type="text" id="discount" name="discount" size="15" maxlength="10" value="'.$discount_value.'" '.$discount_abled.'></td>
</tr>
<tr>
<td colspan="2" align="center"><button id="submitButton" onClick=\'xajax_update(xajax.getFormValues("f"));return false;\'>'.$locate->Translate("Continue").'</button></td>
</tr>
</table>
';
$html .= '
</form>
*'.$locate->Translate("Obligatory Fields").'
';
return $html;
}
function checkValues($pin){
global $customers_db,$config;
$sql = "SELECT id FROM ".$config['customers']['customertable']." WHERE pin=$pin";
astercrm::events($sql);
$id =& $customers_db->getOne($sql);
return $id;
}
function insertNewCustomer($f){
global $customers_db,$config;
$f = astercrm::variableFiler($f);
$sql= "INSERT INTO ".$config['customers']['customertable']." SET "
."pin='".$f['pin']."', "
."first_name='".$f['first_name']."', "
."last_name = '".$f['last_name']."', "
."discount = '".$f['discount']."', "
."cretime = now() ";
//echo $sql;exit;
astercrm::events($sql);
$res =& $customers_db->query($sql);
return $res;
}
function updateCustomer($f){
global $customers_db,$config;
//print_r($f);exit;
$f = astercrm::variableFiler($f);
$sql= "UPDATE ".$config['customers']['customertable']." SET "
."first_name='".$f['first_name']."', "
."last_name = '".$f['last_name']."', "
."discount = '".$f['discount']." 'WHERE pin = '".$f['pin']."'";
astercrm::events($sql);
$res =& $customers_db->query($sql);
return $res;
}
function deleteCustomer($id){
global $customers_db,$config;
$query = "DELETE FROM ".$config['customers']['customertable']." WHERE id = $id";
astercrm::events($query);
$res =& $customers_db->query($query);
return $res;
}
}
?>