-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_clients.php
executable file
·430 lines (415 loc) · 14.9 KB
/
view_clients.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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<?php
session_start();
if(!$_SESSION['islogin'])
{
include "template.php";
$template= new template('html');
$template->set_filenames(array(
'login' => 'login.html')
);
$template->assign_block_vars('switch_login_fails', array());
$template->pparse('login');
$template->set_filenames(array(
'footer' => 'footer.html')
);
$template->pparse('footer');
exit();
}
if($_GET['zid']){
unset($_SESSION['zone']);
$_SESSION['zone']=$_GET['zid'];
}
if(!$_SESSION['zone']){
if($_SESSION['access']>1){
include_once "view_all_clients.php";
}
else{
$template->set_filenames(array(
'body' => 'zone_error.html')
);
$template->pparse('body');
}
}
else{
include'classes/my_customers.php';
$List=new client();
if($_GET['pageload']==7){
$template->set_filenames(array(
'body' => 'view_client.html')
);
if($_GET['cid']||$_POST['cid']||$_POST['scid']){
include"classes/deposit.php";
$test= new deposit();
$cid=$_GET['cid']+$_POST['cid'];
if($_POST['scid']){
$cid= $test->is_cust($_POST['scid'],$_POST['szone']);
if($cid==0){
$template->assign_vars(array(
'ERROR' => "Votre donnee n'est pas valide",
));
$template->assign_block_vars('switch_cust_search', array());
if($_SESSION['access']>1){
$template->assign_block_vars('switch_cust_search.switch_zone', array());
}
$template->pparse('body');
$template->set_filenames(array(
'footer' => 'footer.html')
);
$template->pparse('footer');
exit();
}
}
$template->assign_block_vars('switch_cust_display', array());
$List->query("CREATE TEMPORARY TABLE recent_date_zone
SELECT MAX( DATE ) AS max_date, CUST_ID
FROM cust_location
WHERE CUST_ID= $cid
GROUP BY CUST_ID;");
$List->query("CREATE TEMPORARY TABLE current_zone
SELECT cust_location.CUST_ID, cust_location.ZONE
FROM recent_date_zone, cust_location
WHERE cust_location.DATE = recent_date_zone.max_date
AND cust_location.CUST_ID = recent_date_zone.CUST_ID
AND ZONE = {$_SESSION['zone']};");
$List->query("CREATE TEMPORARY TABLE recent_date_goal
SELECT MAX( cust_goal.DATE ) AS max_date, cust_goal.CUST_ID
FROM cust_goal, current_zone
WHERE cust_goal.CUST_ID=current_zone.CUST_ID
GROUP BY CUST_ID;");
$List->query("CREATE TEMPORARY TABLE current_goal
SELECT cust_goal.CUST_ID, cust_goal.GOAL
FROM cust_goal, recent_date_goal, account
WHERE cust_goal.DATE=recent_date_goal.max_date
AND cust_goal.CUST_ID=recent_date_goal.CUST_ID
AND account.CUST_ID=recent_date_goal.CUST_ID;");
$List->query("SELECT account.CUST_ID, account.CL_ACCT, account.DESCR, account.SIGNING_EMP,
account.SIGNING_DATE, account.STATUS, current_goal.GOAL
FROM account, current_goal
WHERE account.CUST_ID = current_goal.CUST_ID;");
$List->dumpTable();
$template->assign_vars(array(
'CUST_ID' => $List->display[CUST_ID],
'EMP_ID' => $_SESSION['emp'],
'CL_ACCT' => $List->display[CL_ACCT],
'DESCR' => $List->display[DESCR],
'STATUS' => $List->display[STATUS],
'SIGNING_AGENT' => $List->display[SIGNING_EMP],
'SIGNING_DATE' => $List->display[SIGNING_DATE],
'CURRENT_GOAL' => $List->display[GOAL],));
//================== Finds signatories and displays them
$List->query("SELECT cust_info.CUST_ID, cust_info.FIRST_NAME, cust_info.LAST_NAME, cust_info.D_O_B, cust_info.OCCUPATION, cust_info.SEX, cust_info.UNIQUEID,
current_goal.GOAL, current_goal.CUST_ID
FROM cust_info, current_goal
WHERE cust_info.CUST_ID = current_goal.CUST_ID
;");
while($resultie = mysql_fetch_array($List->result)){
if (mysql_errno ( )){
die (sprintf ("Cannot connect to server: %s (%d)\n", htmlspecialchars (mysql_error ( )), mysql_errno ( )));
}
$template->assign_block_vars('switch_cust_display.person', array(
'UNIQUE' => $resultie[UNIQUEID],
'FIRST_NAME' => $resultie[FIRST_NAME],
'LAST_NAME' => $resultie[LAST_NAME],
'D_O_B' => $resultie[D_O_B],
'OCCUPATION' => $resultie[OCCUPATION],
'SEX' => $resultie[SEX],)
);
}
if(!$resultie){$template->assign_block_vars('switch_cust_display.addperson', array());}
if($_SESSION['access']>3 and $_SESSION['access']<7){
$template->assign_block_vars('switch_cust_display.goal_edit', array());
}
else{
$template->assign_block_vars('switch_cust_display.goal', array());
}
//================== Building the data for a month of deposits
$template->assign_block_vars('switch_cust_display.a', array());
if($_POST['date']){
$template->assign_vars(array(
'DATE'=>date("M-Y", $_POST['date']),
'NoDATE'=>$_POST['date'],));
$List->display[DATE]=date("M-Y", $_POST['date']);
$List->date($cid,$caller_file,$_POST['date']);
$m=date(n,$_POST['date']);
$y=date(Y,$_POST['date']);
if($_SESSION['access']>1 and $_SESSION['access']<9){
$template->assign_block_vars('switch_cust_display.a.pull', array());
}
}
else{
$template->assign_vars(array(
'DATE'=> date("M-Y"),));
$List->display[DATE]=date("M-Y");
$List->date($cid,$caller_file,date(U));
$m='MONTH(CURDATE( ))';
$y='YEAR(CURDATE( ))';
}
if($_POST['date']){
$List->query("CREATE TEMPORARY TABLE goal_hist
SELECT DATE , CUST_ID, GOAL
FROM cust_goal
WHERE CUST_ID= $cid
AND DATE <= '$y-$m-31';");
$List->query("CREATE TEMPORARY TABLE goal_for_date
SELECT MAX(DATE) AS max_date, CUST_ID
FROM goal_hist
GROUP BY CUST_ID;");
$List->query("SELECT cust_goal.GOAL, cust_goal.CUST_ID
FROM cust_goal,goal_for_date
WHERE cust_goal.CUST_ID=goal_for_date.CUST_ID
AND cust_goal.DATE=goal_for_date.max_date
GROUP BY CUST_ID;");
while($resultie = mysql_fetch_array($List->result)){$List->display[GOAL]=$resultie[GOAL];}
$List->query("SELECT AMOUNT, VERIFY, STATUS
FROM deposit
WHERE MONTH(DATE) = $m
AND YEAR(DATE) =$y
AND CUST_ID ='{$List->display[CUST_ID]}';");
$List->dumpDeposits();
$List->dumpBooklet($List->display[GOAL]);
}
else{
$List->query("SELECT AMOUNT, VERIFY, STATUS
FROM deposit
WHERE MONTH(DATE) = $m
AND YEAR(DATE) =$y
AND CUST_ID ='{$List->display[CUST_ID]}'");
$List->dumpDeposits();
$List->dumpBooklet($List->display[GOAL]);
}
$template->assign_vars(array(
'UNVERIFIED'=> $List->funds_unverified,
'WITHDRAWN'=>$List->funds_withdrawn,
'GROSS'=>$List->funds_available,
'SHOWING_DATE'=>$List->display[DATE],
'SHOWING_GOAL'=>$List->display[GOAL],
'NET'=>$List->funds_available+$List->funds_withdrawn-$List->display[GOAL],
));
/*****************************Generates 35 entries for the booklet table with a default empty option**************************/
for($b=1;$b<=31;$b++){
if($List->entries_available>0){
$template->assign_vars(array(
$b => 'a',)
);
$List->entries_available--;
}
else{
if($List->entries_unverified>0){
$template->assign_vars(array(
$b => 'b',)
);
$List->entries_unverified--;
}
else{
if($List->entries_withdrawn>0){
$template->assign_vars(array(
$b => 'c',)
);
$List->entries_withdrawn--;
}
else{
$template->assign_vars(array(
$b => 'd',)
);
}
}
}
}
/*****************************************************************************************************************/
For($J=0; $J<=sizeof($List->worddate); $J++){
$template->assign_block_vars('switch_cust_display.a.drop', array(
'DATE_NAME' => $List->worddate[$J],
'DATE_VALUE' => $List->newdate[$J],)
);
}
}
else{
$template->assign_block_vars('switch_cust_search', array());
if($_SESSION['access']>1){
$template->assign_block_vars('switch_cust_search.switch_zone', array());
}
}
}
/******************************GENERATES CLIENT LIST FOR CURRENT ZONE***********************************************************************************/
else if($_GET['pageload']==17){
$template->set_filenames(array(
'body' => 'dump_all_clients.html')
);
$List->query("CREATE TEMPORARY TABLE recent_date_zone
SELECT MAX( DATE ) AS max_date, CUST_ID
FROM cust_location
GROUP BY CUST_ID;");
$List->query("CREATE TEMPORARY TABLE current_zone
SELECT cust_location.CUST_ID, cust_location.ZONE
FROM recent_date_zone, cust_location
WHERE cust_location.DATE = recent_date_zone.max_date
AND cust_location.CUST_ID=recent_date_zone.CUST_ID
AND ZONE = {$_SESSION['zone']};");
$List->query("CREATE TEMPORARY TABLE recent_date_goal
SELECT MAX( cust_goal.DATE ) AS max_date, cust_goal.CUST_ID, cust_goal.GOAL
FROM cust_goal, current_zone
WHERE cust_goal.CUST_ID=current_zone.CUST_ID
GROUP BY CUST_ID;");
$List->query("CREATE TEMPORARY TABLE cust_lst(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id))
SELECT recent_date_goal.CUST_ID, recent_date_goal.GOAL, account.DESCR
FROM recent_date_goal, account
WHERE account.CUST_ID=recent_date_goal.CUST_ID
ORDER BY account.CUST_ID asc;");
$List->query("SELECT id, CUST_ID,DESCR, GOAL
FROM cust_lst
ORDER BY CUST_ID ASC;");
while($resultie = mysql_fetch_array($List->result)){
if (mysql_errno ( )){
die (sprintf ("Cannot connect to server: %s (%d)\n", htmlspecialchars (mysql_error ( )), mysql_errno ( )));
}
$contenttest=sizeof($resultie);
$template->assign_vars(array(
'ZONE' => $_SESSION['zone'],));
$template->assign_block_vars('line', array(
'SWITCH' => $switch,
'ID'=> $resultie[id],
'CUST_ID' => $resultie[CUST_ID],
'NAME' => $resultie[DESCR],
'GOAL' => $resultie[GOAL],)
);
if(isset($switch)){
unset($switch);
}
else{
$switch='line';
}
if(!$contenttest){
$template->assign_block_vars('line', array(
'NO_RESULT' => 'No Result')
);
}
}
}
else{
//================== Initial set of queries generates a client list with current goals to match the location of the user
$template->set_filenames(array(
'body' => 'list_client.html')
);
$List->query("CREATE TEMPORARY TABLE recent_date_zone
SELECT MAX( DATE ) AS max_date, CUST_ID
FROM cust_location
GROUP BY CUST_ID;");
$List->query("CREATE TEMPORARY TABLE current_zone
SELECT cust_location.CUST_ID, cust_location.ZONE
FROM recent_date_zone, cust_location
WHERE cust_location.DATE = recent_date_zone.max_date
AND cust_location.CUST_ID=recent_date_zone.CUST_ID
AND ZONE = {$_SESSION['zone']};");
$List->query("CREATE TEMPORARY TABLE recent_date_goal
SELECT MAX( cust_goal.DATE ) AS max_date, cust_goal.CUST_ID, cust_goal.GOAL
FROM cust_goal, current_zone
WHERE cust_goal.CUST_ID=current_zone.CUST_ID
GROUP BY CUST_ID;");
$List->query("CREATE TEMPORARY TABLE cust_lst(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id))
SELECT recent_date_goal.CUST_ID, recent_date_goal.GOAL, account.DESCR
FROM recent_date_goal, account
WHERE account.CUST_ID=recent_date_goal.CUST_ID
ORDER BY account.CUST_ID asc;");
//================== Final query handles a basic sort by for the initial customer list
/*
**This is more complete now.
**This could usesome testing to make sure that it continues to work
**I would like to see some filters added e.g. "select only female clients"
*/
//==========Set some data to make a next/prev page navigation
$List->query("SELECT COUNT(id)
FROM cust_lst;");
$nav= array(
'START'=> (!$_GET['page']? 0 : ($_GET['page']*20)-20),
'FINISH'=> (!$_GET['page']? 20 : ($_GET['page']*20)),
'TOTAL_PAGES'=>(!is_int(mysql_result($List->result, 0)/20)? intval(mysql_result($List->result, 0)/20)+1:mysql_result($List->result, 0)/20),
'CURRENT_PAGE'=> (!$_GET['page']? 1 : $_GET['page']),
);
//===========Set final queries for Ordering collums
switch($_GET['orderby']){
case "id":
$orderby = "ORDER BY id";
if($_GET['dir']){$orderby.=" ASC";}
else{$orderby.=" DESC";}
echo $orderby;
break;
case "name":
$orderby = "ORDER BY DESCR";
if($_GET['dir']){$orderby.=" ASC";}
else{$orderby.=" DESC";}
break;
case "goal":
$orderby = "ORDER BY GOAL";
if($_GET['dir']){$orderby.=" ASC";}
else{$orderby.=" DESC";}
break;
default:
unset($orderby);
break;
}
$List->query("SELECT id, CUST_ID,DESCR, GOAL
FROM cust_lst
$orderby
LIMIT {$nav['START']},20;");
//===============================================================================
while($resultie = mysql_fetch_array($List->result)){
if (mysql_errno ( )){
die (sprintf ("Cannot connect to server: %s (%d)\n", htmlspecialchars (mysql_error ( )), mysql_errno ( )));
}
$contenttest=sizeof($resultie);
$template->assign_vars(array(
'ZONE' => $_SESSION['zone'],));
$template->assign_block_vars('line', array(
'SWITCH' => $switch,
'ID'=> $resultie[id],
'CUST_ID' => $resultie[CUST_ID],
'NAME' => $resultie[DESCR],
'GOAL' => $resultie[GOAL],)
);
if(isset($switch)){
unset($switch);
}
else{
$switch='line';
}
if(!$contenttest){
$template->assign_block_vars('line', array(
'NO_RESULT' => 'No Result')
);
}
}
//===============================Assign all of the formatting for list links
if($nav['CURRENT_PAGE']>1){
$template->assign_block_vars('prev', array(
'ORDERBY' => $_GET['orderby'],
'DIRECTION' => $_GET['dir'],
'NEW_PAGE' => $nav['CURRENT_PAGE']-1,)
);
}
for($j=($nav['CURRENT_PAGE']-3<=0? 1:$nav['CURRENT_PAGE']-3);
$j<=(($nav['CURRENT_PAGE']+3)>=$nav['TOTAL_PAGES']?$nav['TOTAL_PAGES']:$nav['CURRENT_PAGE']+3);
$j++){
$bold= j==$nav['CURRENT_PAGE']? "":"bold";
$template->assign_block_vars('page', array(
'ORDERBY' => $_GET['orderby'],
'DIRECTION' => $_GET['dir'],
'BOLD' => $bold,
'NEW_PAGE' => $j,)
);
unset($bold);
}
if($nav['CURRENT_PAGE']<$nav['TOTAL_PAGES']){
$template->assign_block_vars('next', array(
'ORDERBY' => $_GET['orderby'],
'DIRECTION' => $_GET['dir'],
'NEW_PAGE' => $nav['CURRENT_PAGE']+1,)
);
}
}
$template->pparse('body');
}
?>