-
Notifications
You must be signed in to change notification settings - Fork 0
/
customers.server.php
412 lines (350 loc) · 14 KB
/
customers.server.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?php
/*******************************************************************************
* customers.server.php
* 账户管理系统后台文件
* customers background management script
* Function Desc
provide customers management script
* 功能描述
提供帐户管理脚本
* Function Desc
init 初始化页面元素
showGrid 显示grid
createGrid 生成grid的HTML代码
add 显示添加clid的表单
save 保存clid信息
update 更新clid信息
edit 显示修改clid的表单
delete 删除clid信息
当前返回空值
searchFormSubmit 根据提交的搜索信息重构显示页面
* Desc: page created
********************************************************************************/
require_once ("db_connect.php");
require_once ('customers.grid.inc.php');
require_once ('include/xajaxGrid.inc.php');
require_once ('include/astercrm.class.php');
require_once ('include/asterevent.class.php');
require_once ('include/asterisk.class.php');
require_once ('include/common.class.php');
require_once ("customers.common.php");
/**
* initialize page elements
*
*/
function init(){
global $locate;
$objResponse = new xajaxResponse();
$objResponse->addAssign("divNav","innerHTML",common::generateManageNav($skin));
$objResponse->addAssign("divCopyright","innerHTML",common::generateCopyright($skin));
$objResponse->addScript("xajax_showGrid(0,".ROWSXPAGE.",'','','')");
return $objResponse;
}
/**
* show grid HTML code
* @param start int record start
* @param limit int how many records need
* @param filter string the field need to search
* @param content string the contect want to match
* @param divName string which div grid want to be put
* @param order string data order
* @return objResponse object xajax response object
*/
function showGrid($start = 0, $limit = 1,$filter = null, $content = null, $order = null, $divName = "grid", $ordering = ""){
$html .= createGrid($start, $limit,$filter, $content, $order, $divName, $ordering);
$objResponse = new xajaxResponse();
$objResponse->addClear("msgZone", "innerHTML");
$objResponse->addAssign($divName, "innerHTML", $html);
return $objResponse;
}
/**
* generate grid HTML code
* @param start int record start
* @param limit int how many records need
* @param filter string the field need to search
* @param content string the contect want to match
* @param divName string which div grid want to be put
* @param order string data order
* @return html string grid HTML code
*/
function createGrid($start = 0, $limit = 1, $filter = null, $content = null, $order = null, $divName = "grid", $ordering = "",$stype=array()){
global $locate,$config;
$_SESSION['ordering'] = $ordering;
if($filter == null or $content == null || (!is_array($content) && $content == 'Array') || (!is_array(filter) && $filter == 'Array')){
$content = null;
$filter = null;
$numRows =& Customer::getNumRows();
$arreglo =& Customer::getAllRecords($start,$limit,$order);
}else{
foreach($content as $value){
if(trim($value) != ""){ //搜索内容有值
$flag = "1";
break;
}
}
foreach($filter as $value){
if(trim($value) != ""){ //搜索条件有值
$flag2 = "1";
break;
}
}
foreach($stype as $value){
if(trim($value) != ""){ //搜索方式有值
$flag3 = "1";
break;
}
}
if($flag != "1" || $flag2 != "1"){ //无值
$order = null;
$numRows =& Customer::getNumRows();
$arreglo =& Customer::getAllRecords($start,$limit,$order);
}elseif($flag3 != 1 ){
$order = "id";
$numRows =& Customer::getNumRowsMore($filter, $content,$config['customers']['customertable']);
$arreglo =& Customer::getRecordsFilteredMore($start, $limit, $filter, $content, $order,$config['customers']['customertable']);
}else{
$order = "id";
$numRows =& Customer::getNumRowsMorewithstype($filter, $content,$stype,$config['customers']['customertable']);
$arreglo =& Customer::getRecordsFilteredMorewithstype($start, $limit, $filter, $content, $stype,$order,$config['customers']['customertable']);
}
}
// Select Box: type table.
$typeFromSearch = array();
$typeFromSearch[] = 'like';
$typeFromSearch[] = 'equal';
$typeFromSearch[] = 'more';
$typeFromSearch[] = 'less';
// Selecct Box: Labels showed on searchtype select box.
$typeFromSearchShowAs = array();
$typeFromSearchShowAs[] = $locate->Translate("like");
$typeFromSearchShowAs[] = '=';
$typeFromSearchShowAs[] = '>';
$typeFromSearchShowAs[] = '<';
// Editable zone
// Databse Table: fields
$fields = array();
$fields[] = 'pin';
$fields[] = 'first_name';
$fields[] = 'last_name';
$fields[] = 'amount';
$fields[] = 'discount';
$fields[] = 'cretime';
// HTML table: Headers showed
$headers = array();
$headers[] = $locate->Translate("Pin");
$headers[] = $locate->Translate("First name");
$headers[] = $locate->Translate("Last name");
$headers[] = $locate->Translate("Amount");
$headers[] = $locate->Translate("Discount");
$headers[] = $locate->Translate("Create time");
// HTML table: hearders attributes
$attribsHeader = array();
$attribsHeader[] = 'width=""';
$attribsHeader[] = 'width=""';
$attribsHeader[] = 'width=""';
$attribsHeader[] = 'width=""';
$attribsHeader[] = 'width=""';
$attribsHeader[] = 'width=""';
// HTML Table: columns attributes
$attribsCols = array();
$attribsCols[] = 'style="text-align: left"';
$attribsCols[] = 'style="text-align: left"';
$attribsCols[] = 'style="text-align: left"';
$attribsCols[] = 'style="text-align: left"';
$attribsCols[] = 'style="text-align: left"';
$attribsCols[] = 'style="text-align: left"';
// HTML Table: If you want ascendent and descendent ordering, set the Header Events.
$eventHeader = array();
$eventHeader[]= 'onClick=\'xajax_showGrid(0,'.$limit.',"'.$filter.'","'.$content.'","pin","'.$divName.'","ORDERING");return false;\'';
$eventHeader[]= 'onClick=\'xajax_showGrid(0,'.$limit.',"'.$filter.'","'.$content.'","first_name","'.$divName.'","ORDERING");return false;\'';
$eventHeader[]= 'onClick=\'xajax_showGrid(0,'.$limit.',"'.$filter.'","'.$content.'","last_name","'.$divName.'","ORDERING");return false;\'';
$eventHeader[]= 'onClick=\'xajax_showGrid(0,'.$limit.',"'.$filter.'","'.$content.'","amount","'.$divName.'","ORDERING");return false;\'';
$eventHeader[]= 'onClick=\'xajax_showGrid(0,'.$limit.',"'.$filter.'","'.$content.'","discount","'.$divName.'","ORDERING");return false;\'';
$eventHeader[]= 'onClick=\'xajax_showGrid(0,'.$limit.',"'.$filter.'","'.$content.'","cretime","'.$divName.'","ORDERING");return false;\'';
// Select Box: fields table.
$fieldsFromSearch = array();
$fieldsFromSearch[] = 'pin';
$fieldsFromSearch[] = 'first_name';
$fieldsFromSearch[] = 'last_name';
$fieldsFromSearch[] = 'amount';
$fieldsFromSearch[] = 'discount';
$fieldsFromSearch[] = 'cretime';
// Selecct Box: Labels showed on search select box.
$fieldsFromSearchShowAs = array();
$fieldsFromSearchShowAs[] = $locate->Translate("Pin");
$fieldsFromSearchShowAs[] = $locate->Translate("First name");
$fieldsFromSearchShowAs[] = $locate->Translate("Last name");
$fieldsFromSearchShowAs[] = $locate->Translate("Amount");
$fieldsFromSearchShowAs[] = $locate->Translate("Discount");
$fieldsFromSearchShowAs[] = $locate->Translate("Create time");
// Create object whit 5 cols and all data arrays set before.
$table = new ScrollTable(6,$start,$limit,$filter,$numRows,$content,$order);
$table->setAttribsCols($attribsCols);
if ($_SESSION['curuser']['usertype'] == 'admin' ){
$table->setHeader('title',$headers,$attribsHeader,$eventHeader,1,1,'customer');
//$table->deleteFlag = '1';//对删除标记进行赋值
//$table->exportFlag = '1';//对导出标记进行赋值
$table->addRowSearchMore($config['customers']['customertable'],$fieldsFromSearch,$fieldsFromSearchShowAs,$filter,$content,$start,$limit,1,$typeFromSearch,$typeFromSearchShowAs,$stype);
}else{
$table->setHeader('title',$headers,$attribsHeader,$eventHeader,0,0,'customer');
//if($_SESSION['curuser']['usertype'] == 'groupadmin') $table->exportFlag = '1';//对导出标记进行赋值
$table->addRowSearchMore($config['customers']['customertable'],$fieldsFromSearch,$fieldsFromSearchShowAs,$filter,$content,$start,$limit,0,$typeFromSearch,$typeFromSearchShowAs,$stype);
}
while ($arreglo->fetchInto($row)) {
// Change here by the name of fields of its database table
$rowc = array();
$rowc[] = $row['id'];
$rowc[] = $row['pin'];
$rowc[] = $row['first_name'];
$rowc[] = $row['last_name'];
$rowc[] = $row['amount'];
if($row['discount'] == -1 )
$rowc[] = $locate->Translate("dynamic");
else
$rowc[] = $row['discount'];
$rowc[] = $row['cretime'];
if ($_SESSION['curuser']['usertype'] == 'admin'){
$table->addRow($config['customers']['customertable'],$rowc,1,1,'customer',$divName,$fields);
}else{
$table->addRow($config['customers']['customertable'],$rowc,0,0,'customer',$divName,$fields);
}
}
// End Editable Zone
$html = $table->render();
return $html;
}
/**
* generate account add form HTML code
* @return html string account add HTML code
*/
function add(){
// Edit zone
global $locate;
$objResponse = new xajaxResponse();
$html = Table::Top($locate->Translate("add_customer"),"formDiv"); // <-- Set the title for your form.
$html .= Customer::formAdd(); // <-- Change by your method
// End edit zone
$html .= Table::Footer();
$objResponse->addAssign("formDiv", "style.visibility", "visible");
$objResponse->addAssign("formDiv", "innerHTML", $html);
return $objResponse->getXML();
}
/**
* save account record
* @param f array account record
* @return objResponse object xajax response object
*/
function save($f){
global $locate,$db;
$objResponse = new xajaxResponse();
if ( trim($f['pin']) == '' ){
$objResponse->addAlert($locate->Translate("pin field cant be null"));
return $objResponse;
}
if($f['discount_type'] == 0){
$f['discount'] = -1;
}elseif ( !is_numeric(trim($f['discount'])) || $f['discount'] <0 || $f['discount'] >1 ){
$objResponse->addAlert($locate->Translate("discount must be GE 0 and LE 1"));
return $objResponse;
}
// check if pin duplicate
$res = Customer::checkValues($f['pin']);
if ($res != ''){
$objResponse->addAlert($locate->Translate("pin duplicate"));
return $objResponse->getXML();
}
$respOk = Customer::insertNewCustomer($f); // add a new account
if ($respOk){
$html = createGrid(0,ROWSXPAGE);
$objResponse->addAssign("grid", "innerHTML", $html);
$objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("add_customer"));
$objResponse->addAssign("formDiv", "style.visibility", "hidden");
$objResponse->addClear("formDiv", "innerHTML");
}else{
$objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("rec_cannot_insert"));
}
return $objResponse->getXML();
}
/**
* update account record
* @param f array account record
* @return objResponse object xajax response object
*/
function update($f){
global $locate;
$objResponse = new xajaxResponse();
if ( trim($f['pin']) == '' ){
$objResponse->addAlert($locate->Translate("pin field cant be null"));
return $objResponse;
}
if($f['discount_type'] == 0){
$f['discount'] = -1;
}elseif ( !is_numeric(trim($f['discount'])) || $f['discount'] <0 || $f['discount'] >1 ){
$objResponse->addAlert($locate->Translate("discount must be GE 0 and LE 1"));
return $objResponse;
}
$respOk = Customer::updateCustomer($f);
if($respOk){
$html = createGrid(0,ROWSXPAGE);
$objResponse->addAssign("grid", "innerHTML", $html);
$objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("update_rec"));
$objResponse->addAssign("formDiv", "style.visibility", "hidden");
}else{
$objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("rec_cannot_update"));
}
return $objResponse->getXML();
}
/**
* show account edit form
* @param id int account id
* @return objResponse object xajax response object
*/
function edit($id){
global $locate;
$html = Table::Top( $locate->Translate("edit_customer"),"formDiv");
$html .= Customer::formEdit($id);
$html .= Table::Footer();
// End edit zone
$objResponse = new xajaxResponse();
$objResponse->addAssign("formDiv", "style.visibility", "visible");
$objResponse->addAssign("formDiv", "innerHTML", $html);
return $objResponse->getXML();
}
function searchFormSubmit($searchFormValue,$numRows,$limit,$id,$type){
global $locate,$db;
$objResponse = new xajaxResponse();
$searchField = array();
$searchContent = array();
$optionFlag = $searchFormValue['optionFlag'];
$searchContent = $searchFormValue['searchContent']; //搜索内容 数组
$searchField = $searchFormValue['searchField']; //搜索条件 数组
$searchType = $searchFormValue['searchType']; //搜索方式 数组
$divName = "grid";
if($optionFlag == "export"){
$sql = astercrm::getSql($searchContent,$searchField,$searchType,'clid'); //得到要导出的sql语句
$_SESSION['export_sql'] = $sql;
$objResponse->addAssign("hidSql", "value", $sql); //赋值隐含域
$objResponse->addScript("document.getElementById('exportForm').submit();");
}elseif($optionFlag == "delete"){
astercrm::deletefromsearch($searchContent,$searchField,$searchType,'clid');
$html = createGrid($numRows, $limit,'','','',$divName,"",$searchType);
$objResponse->addClear("msgZone", "innerHTML");
$objResponse->addAssign($divName, "innerHTML", $html);
}elseif($type == "delete"){
$res = Customer::deleteCustomer($id);
if ($res){
$html = createGrid($searchFormValue['numRows'], $searchFormValue['limit'],$searchField, $searchContent, $searchField, $divName, "",$searchType);
$objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("record deleted"));
$objResponse->addAssign($divName, "innerHTML", $html);
}else{
$objResponse->addAssign("msgZone", "innerHTML", $locate->Translate("record cannot be deleted"));
}
}else{
$html = createGrid($numRows, $limit,$searchField, $searchContent, $searchField, $divName, "",$searchType);
$objResponse->addClear("msgZone", "innerHTML");
$objResponse->addAssign($divName, "innerHTML", $html);
}
return $objResponse->getXML();
}
$xajax->processRequests();
?>