forked from zybmore/mingyou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
2756 lines (2380 loc) · 98.2 KB
/
user.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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* ECSHOP 会员中心
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: user.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/* 载入语言文件 */
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
$user_id = $_SESSION['user_id'];
$action = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
$affiliate = unserialize($GLOBALS['_CFG']['affiliate']);
$smarty->assign('affiliate', $affiliate);
$back_act='';
// 不需要登录的操作或自己验证是否登录(如ajax处理)的act
$not_login_arr =
array('login','act_login','register','act_register','act_edit_password','get_password','send_pwd_email','password', 'signin', 'add_tag', 'collect', 'return_to_cart', 'logout', 'email_list', 'validate_email', 'send_hash_mail', 'order_query', 'is_registered', 'check_email','clear_history','qpassword_name', 'get_passwd_question', 'check_answer');
/* 显示页面的action列表 */
$ui_arr = array('register', 'login', 'profile', 'order_list', 'order_detail', 'address_list', 'collection_list',
'message_list', 'tag_list', 'get_password', 'reset_password', 'booking_list', 'add_booking', 'account_raply',
'account_deposit', 'account_log', 'account_detail', 'act_account', 'pay', 'default', 'bonus', 'group_buy', 'group_buy_detail', 'affiliate', 'comment_list','validate_email','track_packages', 'transform_points','qpassword_name', 'get_passwd_question', 'check_answer');
/* 未登录处理 */
if (empty($_SESSION['user_id']))
{
if (!in_array($action, $not_login_arr))
{
if (in_array($action, $ui_arr))
{
/* 如果需要登录,并是显示页面的操作,记录当前操作,用于登录后跳转到相应操作
if ($action == 'login')
{
if (isset($_REQUEST['back_act']))
{
$back_act = trim($_REQUEST['back_act']);
}
}
else
{}*/
if (!empty($_SERVER['QUERY_STRING']))
{
$back_act = 'user.php?' . strip_tags($_SERVER['QUERY_STRING']);
}
$action = 'login';
}
else
{
//未登录提交数据。非正常途径提交数据!
die($_LANG['require_login']);
}
}
}
/* 如果是显示页面,对页面进行相应赋值 */
if (in_array($action, $ui_arr))
{
assign_template();
$position = assign_ur_here(0, $_LANG['user_center']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']);
$sql = "SELECT value FROM " . $ecs->table('shop_config') . " WHERE id = 419";
$row = $db->getRow($sql);
$car_off = $row['value'];
$smarty->assign('car_off', $car_off);
/* 是否显示积分兑换 */
if (!empty($_CFG['points_rule']) && unserialize($_CFG['points_rule']))
{
$smarty->assign('show_transform_points', 1);
}
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('data_dir', DATA_DIR); // 数据目录
$smarty->assign('action', $action);
$smarty->assign('lang', $_LANG);
}
//用户中心欢迎页
if ($action == 'default')
{
include_once(ROOT_PATH .'includes/lib_clips.php');
if ($rank = get_rank_info())
{
$smarty->assign('rank_name', sprintf($_LANG['your_level'], $rank['rank_name']));
if (!empty($rank['next_rank_name']))
{
$smarty->assign('next_rank_name', sprintf($_LANG['next_level'], $rank['next_rank'] ,$rank['next_rank_name']));
}
}
$smarty->assign('info', get_user_default($user_id));
$smarty->assign('user_notice', $_CFG['user_notice']);
$smarty->assign('prompt', get_user_prompt($user_id));
$smarty->display('user_clips.dwt');
}
/* 显示会员注册界面 */
if ($action == 'register')
{
if ((!isset($back_act)||empty($back_act)) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
/* 取出注册扩展字段 */
$sql = 'SELECT * FROM ' . $ecs->table('reg_fields') . ' WHERE type < 2 AND display = 1 ORDER BY dis_order, id';
$extend_info_list = $db->getAll($sql);
$smarty->assign('extend_info_list', $extend_info_list);
/* 验证码相关设置 */
if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
$smarty->assign('enabled_captcha', 1);
$smarty->assign('rand', mt_rand());
}
/* 密码提示问题 */
$smarty->assign('passwd_questions', $_LANG['passwd_questions']);
/* 增加是否关闭注册 */
$smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
// $smarty->assign('back_act', $back_act);
$smarty->display('user_passport.dwt');
}
/* 注册会员的处理 */
elseif ($action == 'act_register')
{
/* 增加是否关闭注册 */
if ($_CFG['shop_reg_closed'])
{
$smarty->assign('action', 'register');
$smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
$smarty->display('user_passport.dwt');
}
else
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$other['msn'] = isset($_POST['extend_field1']) ? $_POST['extend_field1'] : '';
$other['qq'] = isset($_POST['extend_field2']) ? $_POST['extend_field2'] : '';
$other['office_phone'] = isset($_POST['extend_field3']) ? $_POST['extend_field3'] : '';
$other['home_phone'] = isset($_POST['extend_field4']) ? $_POST['extend_field4'] : '';
$other['mobile_phone'] = isset($_POST['extend_field5']) ? $_POST['extend_field5'] : '';
$sel_question = empty($_POST['sel_question']) ? '' : compile_str($_POST['sel_question']);
$passwd_answer = isset($_POST['passwd_answer']) ? compile_str(trim($_POST['passwd_answer'])) : '';
$back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';
if(empty($_POST['agreement']))
{
show_message($_LANG['passport_js']['agreement']);
}
if (strlen($username) < 3)
{
show_message($_LANG['passport_js']['username_shorter']);
}
if (strlen($password) < 6)
{
show_message($_LANG['passport_js']['password_shorter']);
}
if (strpos($password, ' ') > 0)
{
show_message($_LANG['passwd_balnk']);
}
/* 验证码检查 */
if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['sign_up'], 'user.php?act=register', 'error');
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['sign_up'], 'user.php?act=register', 'error');
}
}
if (register($username, $password, $email, $other) !== false)
{
/*把新注册用户的扩展信息插入数据库*/
$sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id'; //读出所有自定义扩展字段的id
$fields_arr = $db->getAll($sql);
$extend_field_str = ''; //生成扩展字段的内容字符串
foreach ($fields_arr AS $val)
{
$extend_field_index = 'extend_field' . $val['id'];
if(!empty($_POST[$extend_field_index]))
{
$temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? mb_substr($_POST[$extend_field_index], 0, 99) : $_POST[$extend_field_index];
$extend_field_str .= " ('" . $_SESSION['user_id'] . "', '" . $val['id'] . "', '" . compile_str($temp_field_content) . "'),";
}
}
$extend_field_str = substr($extend_field_str, 0, -1);
if ($extend_field_str) //插入注册扩展数据
{
$sql = 'INSERT INTO '. $ecs->table('reg_extend_info') . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str;
$db->query($sql);
}
/* 写入密码提示问题和答案 */
if (!empty($passwd_answer) && !empty($sel_question))
{
$sql = 'UPDATE ' . $ecs->table('users') . " SET `passwd_question`='$sel_question', `passwd_answer`='$passwd_answer' WHERE `user_id`='" . $_SESSION['user_id'] . "'";
$db->query($sql);
}
/* 判断是否需要自动发送注册邮件 */
if ($GLOBALS['_CFG']['member_email_validate'] && $GLOBALS['_CFG']['send_verify_email'])
{
send_regiter_hash($_SESSION['user_id']);
}
$ucdata = empty($user->ucdata)? "" : $user->ucdata;
show_message(sprintf($_LANG['register_success'], $username . $ucdata), array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act, 'user.php'), 'info');
}
else
{
$err->show($_LANG['sign_up'], 'user.php?act=register');
}
}
}
/* 验证用户注册邮件 */
elseif ($action == 'validate_email')
{
$hash = empty($_GET['hash']) ? '' : trim($_GET['hash']);
if ($hash)
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$id = register_hash('decode', $hash);
if ($id > 0)
{
$sql = "UPDATE " . $ecs->table('users') . " SET is_validated = 1 WHERE user_id='$id'";
$db->query($sql);
$sql = 'SELECT user_name, email FROM ' . $ecs->table('users') . " WHERE user_id = '$id'";
$row = $db->getRow($sql);
show_message(sprintf($_LANG['validate_ok'], $row['user_name'], $row['email']),$_LANG['profile_lnk'], 'user.php');
}
}
show_message($_LANG['validate_fail']);
}
/* 验证用户注册用户名是否可以注册 */
elseif ($action == 'is_registered')
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$username = trim($_GET['username']);
$username = json_str_iconv($username);
if ($user->check_user($username) || admin_registered($username))
{
echo 'false';
}
else
{
echo 'true';
}
}
/* 验证用户邮箱地址是否被注册 */
elseif($action == 'check_email')
{
$email = trim($_GET['email']);
if ($user->check_email($email))
{
echo 'false';
}
else
{
echo 'ok';
}
}
/* 用户登录界面 */
elseif ($action == 'login')
{
if (empty($back_act))
{
if (empty($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
else
{
$back_act = 'user.php';
}
}
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
$GLOBALS['smarty']->assign('enabled_captcha', 1);
$GLOBALS['smarty']->assign('rand', mt_rand());
}
$smarty->assign('back_act', $back_act);
$smarty->display('user_passport.dwt');
}
/* 处理会员的登录 */
elseif ($action == 'act_login')
{
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
$password = isset($_POST['password']) ? trim($_POST['password']) : '';
$back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
$validator->session_word = 'captcha_login';
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
}
}
if ($user->login($username, $password,isset($_POST['remember'])))
{
update_user_info();
recalculate_price();
$ucdata = isset($user->ucdata)? $user->ucdata : '';
show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
}
else
{
$_SESSION['login_fail'] ++ ;
show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
}
}
/* 处理 ajax 的登录请求 */
elseif ($action == 'signin')
{
include_once('includes/cls_json.php');
$json = new JSON;
$username = !empty($_POST['username']) ? json_str_iconv(trim($_POST['username'])) : '';
$password = !empty($_POST['password']) ? trim($_POST['password']) : '';
$captcha = !empty($_POST['captcha']) ? json_str_iconv(trim($_POST['captcha'])) : '';
$result = array('error' => 0, 'content' => '');
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
if (empty($captcha))
{
$result['error'] = 1;
$result['content'] = $_LANG['invalid_captcha'];
die($json->encode($result));
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
$validator->session_word = 'captcha_login';
if (!$validator->check_word($_POST['captcha']))
{
$result['error'] = 1;
$result['content'] = $_LANG['invalid_captcha'];
die($json->encode($result));
}
}
if ($user->login($username, $password))
{
update_user_info(); //更新用户信息
recalculate_price(); // 重新计算购物车中的商品价格
$smarty->assign('user_info', get_user_info());
$ucdata = empty($user->ucdata)? "" : $user->ucdata;
$result['ucdata'] = $ucdata;
$result['content'] = $smarty->fetch('library/member_info.lbi');
}
else
{
$_SESSION['login_fail']++;
if ($_SESSION['login_fail'] > 2)
{
$smarty->assign('enabled_captcha', 1);
$result['html'] = $smarty->fetch('library/member_info.lbi');
}
$result['error'] = 1;
$result['content'] = $_LANG['login_failure'];
}
die($json->encode($result));
}
/* 退出会员中心 */
elseif ($action == 'logout')
{
if ((!isset($back_act)|| empty($back_act)) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
$user->logout();
$ucdata = empty($user->ucdata)? "" : $user->ucdata;
show_message($_LANG['logout'] . $ucdata, array($_LANG['back_up_page'], $_LANG['back_home_lnk']), array($back_act, 'index.php'), 'info');
}
/* 个人资料页面 */
elseif ($action == 'profile')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$user_info = get_profile($user_id);
/* 取出注册扩展字段 */
$sql = 'SELECT * FROM ' . $ecs->table('reg_fields') . ' WHERE type < 2 AND display = 1 ORDER BY dis_order, id';
$extend_info_list = $db->getAll($sql);
$sql = 'SELECT reg_field_id, content ' .
'FROM ' . $ecs->table('reg_extend_info') .
" WHERE user_id = $user_id";
$extend_info_arr = $db->getAll($sql);
$temp_arr = array();
foreach ($extend_info_arr AS $val)
{
$temp_arr[$val['reg_field_id']] = $val['content'];
}
foreach ($extend_info_list AS $key => $val)
{
switch ($val['id'])
{
case 1: $extend_info_list[$key]['content'] = $user_info['msn']; break;
case 2: $extend_info_list[$key]['content'] = $user_info['qq']; break;
case 3: $extend_info_list[$key]['content'] = $user_info['office_phone']; break;
case 4: $extend_info_list[$key]['content'] = $user_info['home_phone']; break;
case 5: $extend_info_list[$key]['content'] = $user_info['mobile_phone']; break;
default: $extend_info_list[$key]['content'] = empty($temp_arr[$val['id']]) ? '' : $temp_arr[$val['id']] ;
}
}
$smarty->assign('extend_info_list', $extend_info_list);
/* 密码提示问题 */
$smarty->assign('passwd_questions', $_LANG['passwd_questions']);
$smarty->assign('profile', $user_info);
$smarty->display('user_transaction.dwt');
}
/* 修改个人资料的处理 */
elseif ($action == 'act_edit_profile')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$birthday = trim($_POST['birthdayYear']) .'-'. trim($_POST['birthdayMonth']) .'-'.
trim($_POST['birthdayDay']);
$email = trim($_POST['email']);
$other['msn'] = $msn = isset($_POST['extend_field1']) ? trim($_POST['extend_field1']) : '';
$other['qq'] = $qq = isset($_POST['extend_field2']) ? trim($_POST['extend_field2']) : '';
$other['office_phone'] = $office_phone = isset($_POST['extend_field3']) ? trim($_POST['extend_field3']) : '';
$other['home_phone'] = $home_phone = isset($_POST['extend_field4']) ? trim($_POST['extend_field4']) : '';
$other['mobile_phone'] = $mobile_phone = isset($_POST['extend_field5']) ? trim($_POST['extend_field5']) : '';
$sel_question = empty($_POST['sel_question']) ? '' : compile_str($_POST['sel_question']);
$passwd_answer = isset($_POST['passwd_answer']) ? compile_str(trim($_POST['passwd_answer'])) : '';
/* 更新用户扩展字段的数据 */
$sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id'; //读出所有扩展字段的id
$fields_arr = $db->getAll($sql);
foreach ($fields_arr AS $val) //循环更新扩展用户信息
{
$extend_field_index = 'extend_field' . $val['id'];
if(isset($_POST[$extend_field_index]))
{
$temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? mb_substr(htmlspecialchars($_POST[$extend_field_index]), 0, 99) : htmlspecialchars($_POST[$extend_field_index]);
$sql = 'SELECT * FROM ' . $ecs->table('reg_extend_info') . " WHERE reg_field_id = '$val[id]' AND user_id = '$user_id'";
if ($db->getOne($sql)) //如果之前没有记录,则插入
{
$sql = 'UPDATE ' . $ecs->table('reg_extend_info') . " SET content = '$temp_field_content' WHERE reg_field_id = '$val[id]' AND user_id = '$user_id'";
}
else
{
$sql = 'INSERT INTO '. $ecs->table('reg_extend_info') . " (`user_id`, `reg_field_id`, `content`) VALUES ('$user_id', '$val[id]', '$temp_field_content')";
}
$db->query($sql);
}
}
/* 写入密码提示问题和答案 */
if (!empty($passwd_answer) && !empty($sel_question))
{
$sql = 'UPDATE ' . $ecs->table('users') . " SET `passwd_question`='$sel_question', `passwd_answer`='$passwd_answer' WHERE `user_id`='" . $_SESSION['user_id'] . "'";
$db->query($sql);
}
if (!empty($office_phone) && !preg_match( '/^[\d|\_|\-|\s]+$/', $office_phone ) )
{
show_message($_LANG['passport_js']['office_phone_invalid']);
}
if (!empty($home_phone) && !preg_match( '/^[\d|\_|\-|\s]+$/', $home_phone) )
{
show_message($_LANG['passport_js']['home_phone_invalid']);
}
if (!is_email($email))
{
show_message($_LANG['msg_email_format']);
}
if (!empty($msn) && !is_email($msn))
{
show_message($_LANG['passport_js']['msn_invalid']);
}
if (!empty($qq) && !preg_match('/^\d+$/', $qq))
{
show_message($_LANG['passport_js']['qq_invalid']);
}
if (!empty($mobile_phone) && !preg_match('/^[\d-\s]+$/', $mobile_phone))
{
show_message($_LANG['passport_js']['mobile_phone_invalid']);
}
$profile = array(
'user_id' => $user_id,
'email' => isset($_POST['email']) ? trim($_POST['email']) : '',
'sex' => isset($_POST['sex']) ? intval($_POST['sex']) : 0,
'birthday' => $birthday,
'other' => isset($other) ? $other : array()
);
if (edit_profile($profile))
{
show_message($_LANG['edit_profile_success'], $_LANG['profile_lnk'], 'user.php?act=profile', 'info');
}
else
{
if ($user->error == ERR_EMAIL_EXISTS)
{
$msg = sprintf($_LANG['email_exist'], $profile['email']);
}
else
{
$msg = $_LANG['edit_profile_failed'];
}
show_message($msg, '', '', 'info');
}
}
/* 密码找回-->修改密码界面 */
elseif ($action == 'get_password')
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
if (isset($_GET['code']) && isset($_GET['uid'])) //从邮件处获得的act
{
$code = trim($_GET['code']);
$uid = intval($_GET['uid']);
/* 判断链接的合法性 */
$user_info = $user->get_profile_by_id($uid);
if (empty($user_info) || ($user_info && md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']) != $code))
{
show_message($_LANG['parm_error'], $_LANG['back_home_lnk'], './', 'info');
}
$smarty->assign('uid', $uid);
$smarty->assign('code', $code);
$smarty->assign('action', 'reset_password');
$smarty->display('user_passport.dwt');
}
else
{
//显示用户名和email表单
$smarty->display('user_passport.dwt');
}
}
/* 密码找回-->输入用户名界面 */
elseif ($action == 'qpassword_name')
{
//显示输入要找回密码的账号表单
$smarty->display('user_passport.dwt');
}
/* 密码找回-->根据注册用户名取得密码提示问题界面 */
elseif ($action == 'get_passwd_question')
{
if (empty($_POST['user_name']))
{
show_message($_LANG['no_passwd_question'], $_LANG['back_home_lnk'], './', 'info');
}
else
{
$user_name = trim($_POST['user_name']);
}
//取出会员密码问题和答案
$sql = 'SELECT user_id, user_name, passwd_question, passwd_answer FROM ' . $ecs->table('users') . " WHERE user_name = '" . $user_name . "'";
$user_question_arr = $db->getRow($sql);
//如果没有设置密码问题,给出错误提示
if (empty($user_question_arr['passwd_answer']))
{
show_message($_LANG['no_passwd_question'], $_LANG['back_home_lnk'], './', 'info');
}
$_SESSION['temp_user'] = $user_question_arr['user_id']; //设置临时用户,不具有有效身份
$_SESSION['temp_user_name'] = $user_question_arr['user_name']; //设置临时用户,不具有有效身份
$_SESSION['passwd_answer'] = $user_question_arr['passwd_answer']; //存储密码问题答案,减少一次数据库访问
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
$GLOBALS['smarty']->assign('enabled_captcha', 1);
$GLOBALS['smarty']->assign('rand', mt_rand());
}
$smarty->assign('passwd_question', $_LANG['passwd_questions'][$user_question_arr['passwd_question']]);
$smarty->display('user_passport.dwt');
}
/* 密码找回-->根据提交的密码答案进行相应处理 */
elseif ($action == 'check_answer')
{
$captcha = intval($_CFG['captcha']);
if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
{
if (empty($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['back_retry_answer'], 'user.php?act=qpassword_name', 'error');
}
/* 检查验证码 */
include_once('includes/cls_captcha.php');
$validator = new captcha();
$validator->session_word = 'captcha_login';
if (!$validator->check_word($_POST['captcha']))
{
show_message($_LANG['invalid_captcha'], $_LANG['back_retry_answer'], 'user.php?act=qpassword_name', 'error');
}
}
if (empty($_POST['passwd_answer']) || $_POST['passwd_answer'] != $_SESSION['passwd_answer'])
{
show_message($_LANG['wrong_passwd_answer'], $_LANG['back_retry_answer'], 'user.php?act=qpassword_name', 'info');
}
else
{
$_SESSION['user_id'] = $_SESSION['temp_user'];
$_SESSION['user_name'] = $_SESSION['temp_user_name'];
unset($_SESSION['temp_user']);
unset($_SESSION['temp_user_name']);
$smarty->assign('uid', $_SESSION['user_id']);
$smarty->assign('action', 'reset_password');
$smarty->display('user_passport.dwt');
}
}
/* 发送密码修改确认邮件 */
elseif ($action == 'send_pwd_email')
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
/* 初始化会员用户名和邮件地址 */
$user_name = !empty($_POST['user_name']) ? trim($_POST['user_name']) : '';
$email = !empty($_POST['email']) ? trim($_POST['email']) : '';
//用户名和邮件地址是否匹配
$user_info = $user->get_user_info($user_name);
if ($user_info && $user_info['email'] == $email)
{
//生成code
//$code = md5($user_info[0] . $user_info[1]);
$code = md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']);
//发送邮件的函数
if (send_pwd_email($user_info['user_id'], $user_name, $email, $code))
{
show_message($_LANG['send_success'] . $email, $_LANG['back_home_lnk'], './', 'info');
}
else
{
//发送邮件出错
show_message($_LANG['fail_send_password'], $_LANG['back_page_up'], './', 'info');
}
}
else
{
//用户名与邮件地址不匹配
show_message($_LANG['username_no_email'], $_LANG['back_page_up'], '', 'info');
}
}
/* 重置新密码 */
elseif ($action == 'reset_password')
{
//显示重置密码的表单
$smarty->display('user_passport.dwt');
}
/* 修改会员密码 */
elseif ($action == 'act_edit_password')
{
include_once(ROOT_PATH . 'includes/lib_passport.php');
$old_password = isset($_POST['old_password']) ? trim($_POST['old_password']) : null;
$new_password = isset($_POST['new_password']) ? trim($_POST['new_password']) : '';
$user_id = isset($_POST['uid']) ? intval($_POST['uid']) : $user_id;
$code = isset($_POST['code']) ? trim($_POST['code']) : '';
if (strlen($new_password) < 6)
{
show_message($_LANG['passport_js']['password_shorter']);
}
$user_info = $user->get_profile_by_id($user_id); //论坛记录
if (($user_info && (!empty($code) && md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']) == $code)) || ($_SESSION['user_id']>0 && $_SESSION['user_id'] == $user_id && $user->check_user($_SESSION['user_name'], $old_password)))
{
if ($user->edit_user(array('username'=> (empty($code) ? $_SESSION['user_name'] : $user_info['user_name']), 'old_password'=>$old_password, 'password'=>$new_password), empty($code) ? 0 : 1))
{
$sql="UPDATE ".$ecs->table('users'). "SET `ec_salt`='0' WHERE user_id= '".$user_id."'";
$db->query($sql);
$user->logout();
show_message($_LANG['edit_password_success'], $_LANG['relogin_lnk'], 'user.php?act=login', 'info');
}
else
{
show_message($_LANG['edit_password_failure'], $_LANG['back_page_up'], '', 'info');
}
}
else
{
show_message($_LANG['edit_password_failure'], $_LANG['back_page_up'], '', 'info');
}
}
/* 添加一个红包 */
elseif ($action == 'act_add_bonus')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$bouns_sn = isset($_POST['bonus_sn']) ? intval($_POST['bonus_sn']) : '';
if (add_bonus($user_id, $bouns_sn))
{
show_message($_LANG['add_bonus_sucess'], $_LANG['back_up_page'], 'user.php?act=bonus', 'info');
}
else
{
$err->show($_LANG['back_up_page'], 'user.php?act=bonus');
}
}
/* 查看订单列表 */
elseif ($action == 'order_list')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
$record_count = $db->getOne("SELECT COUNT(*) FROM " .$ecs->table('order_info'). " WHERE user_id = '$user_id'");
$pager = get_pager('user.php', array('act' => $action), $record_count, $page);
$orders = get_user_orders($user_id, $pager['size'], $pager['start']);
$merge = get_user_merge($user_id);
$smarty->assign('merge', $merge);
$smarty->assign('pager', $pager);
$smarty->assign('orders', $orders);
$smarty->display('user_transaction.dwt');
}
/* 查看订单详情 */
elseif ($action == 'order_detail')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
include_once(ROOT_PATH . 'includes/lib_payment.php');
include_once(ROOT_PATH . 'includes/lib_order.php');
include_once(ROOT_PATH . 'includes/lib_clips.php');
$order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0;
/* 订单详情 */
$order = get_order_detail($order_id, $user_id);
if ($order === false)
{
$err->show($_LANG['back_home_lnk'], './');
exit;
}
/* 是否显示添加到购物车 */
if ($order['extension_code'] != 'group_buy' && $order['extension_code'] != 'exchange_goods')
{
$smarty->assign('allow_to_cart', 1);
}
/* 订单商品 */
$goods_list = order_goods($order_id);
foreach ($goods_list AS $key => $value)
{
$goods_list[$key]['market_price'] = price_format($value['market_price'], false);
$goods_list[$key]['goods_price'] = price_format($value['goods_price'], false);
$goods_list[$key]['subtotal'] = price_format($value['subtotal'], false);
}
/* 设置能否修改使用余额数 */
if ($order['order_amount'] > 0)
{
if ($order['order_status'] == OS_UNCONFIRMED || $order['order_status'] == OS_CONFIRMED)
{
$user = user_info($order['user_id']);
if ($user['user_money'] + $user['credit_line'] > 0)
{
$smarty->assign('allow_edit_surplus', 1);
$smarty->assign('max_surplus', sprintf($_LANG['max_surplus'], $user['user_money']));
}
}
}
/* 未发货,未付款时允许更换支付方式 */
if ($order['order_amount'] > 0 && $order['pay_status'] == PS_UNPAYED && $order['shipping_status'] == SS_UNSHIPPED)
{
$payment_list = available_payment_list(false, 0, true);
/* 过滤掉当前支付方式和余额支付方式 */
if(is_array($payment_list))
{
foreach ($payment_list as $key => $payment)
{
if ($payment['pay_id'] == $order['pay_id'] || $payment['pay_code'] == 'balance')
{
unset($payment_list[$key]);
}
}
}
$smarty->assign('payment_list', $payment_list);
}
/* 订单 支付 配送 状态语言项 */
$order['order_status'] = $_LANG['os'][$order['order_status']];
$order['pay_status'] = $_LANG['ps'][$order['pay_status']];
$order['shipping_status'] = $_LANG['ss'][$order['shipping_status']];
$smarty->assign('order', $order);
$smarty->assign('goods_list', $goods_list);
$smarty->display('user_transaction.dwt');
}
/* 取消订单 */
elseif ($action == 'cancel_order')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
include_once(ROOT_PATH . 'includes/lib_order.php');
$order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0;
if (cancel_order($order_id, $user_id))
{
ecs_header("Location: user.php?act=order_list\n");
exit;
}
else
{
$err->show($_LANG['order_list_lnk'], 'user.php?act=order_list');
}
}
/* 收货地址列表界面*/
elseif ($action == 'address_list')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
include_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php');
$smarty->assign('lang', $_LANG);
/* 取得国家列表、商店所在国家、商店所在国家的省列表 */
$smarty->assign('country_list', get_regions());
$smarty->assign('shop_province_list', get_regions(1, $_CFG['shop_country']));
/* 获得用户所有的收货人信息 */
$consignee_list = get_consignee_list($_SESSION['user_id']);
if (count($consignee_list) < 5 && $_SESSION['user_id'] > 0)
{
/* 如果用户收货人信息的总数小于5 则增加一个新的收货人信息 */
$consignee_list[] = array('country' => $_CFG['shop_country'], 'email' => isset($_SESSION['email']) ? $_SESSION['email'] : '');
}
$smarty->assign('consignee_list', $consignee_list);
//取得国家列表,如果有收货人列表,取得省市区列表
foreach ($consignee_list AS $region_id => $consignee)
{
$consignee['country'] = isset($consignee['country']) ? intval($consignee['country']) : 0;
$consignee['province'] = isset($consignee['province']) ? intval($consignee['province']) : 0;
$consignee['city'] = isset($consignee['city']) ? intval($consignee['city']) : 0;
$province_list[$region_id] = get_regions(1, $consignee['country']);
$city_list[$region_id] = get_regions(2, $consignee['province']);
$district_list[$region_id] = get_regions(3, $consignee['city']);
}
/* 获取默认收货ID */
$address_id = $db->getOne("SELECT address_id FROM " .$ecs->table('users'). " WHERE user_id='$user_id'");
//赋值于模板
$smarty->assign('real_goods_count', 1);
$smarty->assign('shop_country', $_CFG['shop_country']);
$smarty->assign('shop_province', get_regions(1, $_CFG['shop_country']));
$smarty->assign('province_list', $province_list);
$smarty->assign('address', $address_id);
$smarty->assign('city_list', $city_list);
$smarty->assign('district_list', $district_list);
$smarty->assign('currency_format', $_CFG['currency_format']);
$smarty->assign('integral_scale', $_CFG['integral_scale']);
$smarty->assign('name_of_region', array($_CFG['name_of_region_1'], $_CFG['name_of_region_2'], $_CFG['name_of_region_3'], $_CFG['name_of_region_4']));
$smarty->display('user_transaction.dwt');
}
/* 添加/编辑收货地址的处理 */
elseif ($action == 'act_edit_address')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
include_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php');
$smarty->assign('lang', $_LANG);
$address = array(
'user_id' => $user_id,
'address_id' => intval($_POST['address_id']),
'country' => isset($_POST['country']) ? intval($_POST['country']) : 0,
'province' => isset($_POST['province']) ? intval($_POST['province']) : 0,
'city' => isset($_POST['city']) ? intval($_POST['city']) : 0,
'district' => isset($_POST['district']) ? intval($_POST['district']) : 0,
'address' => isset($_POST['address']) ? compile_str(trim($_POST['address'])) : '',
'consignee' => isset($_POST['consignee']) ? compile_str(trim($_POST['consignee'])) : '',
'email' => isset($_POST['email']) ? compile_str(trim($_POST['email'])) : '',
'tel' => isset($_POST['tel']) ? compile_str(make_semiangle(trim($_POST['tel']))) : '',
'mobile' => isset($_POST['mobile']) ? compile_str(make_semiangle(trim($_POST['mobile']))) : '',
'best_time' => isset($_POST['best_time']) ? compile_str(trim($_POST['best_time'])) : '',
'sign_building' => isset($_POST['sign_building']) ? compile_str(trim($_POST['sign_building'])) : '',
'zipcode' => isset($_POST['zipcode']) ? compile_str(make_semiangle(trim($_POST['zipcode']))) : '',
);
if (update_address($address))
{
show_message($_LANG['edit_address_success'], $_LANG['address_list_lnk'], 'user.php?act=address_list');
}
}
/* 删除收货地址 */
elseif ($action == 'drop_consignee')
{
include_once('includes/lib_transaction.php');
$consignee_id = intval($_GET['id']);