-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.php
398 lines (345 loc) · 12.5 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
<?php
/**
* ECSHOP 用户中心
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: user.php 16643 2009-09-08 07:02:13Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/* 载入语言文件 */
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
$act = isset($_GET['act']) ? $_GET['act'] : '';
if ($act == 'order_list')
{
if (empty($_SESSION['user_id']))
{
ecs_header("Location: user.php\n");
exit();
}
$record_count = $db->getOne("SELECT COUNT(*) FROM " .$ecs->table('order_info'). " WHERE user_id = {$_SESSION['user_id']}");
if ($record_count > 0)
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$page_num = '10';
$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
$pages = ceil($record_count / $page_num);
if ($page <= 0)
{
$page = 1;
}
if ($pages == 0)
{
$pages = 1;
}
if ($page > $pages)
{
$page = $pages;
}
$pagebar = get_wap_pager($record_count, $page_num, $page, 'user.php?act=order_list', 'page');
$smarty->assign('pagebar' , $pagebar);
$orders = get_user_orders($_SESSION['user_id'], $page_num, $page_num * ($page - 1));
if (!empty($orders))
{
foreach ($orders as $key => $val)
{
$orders[$key]['total_fee'] = encode_output($val['total_fee']);
}
}
//$merge = get_user_merge($_SESSION['user_id']);
$smarty->assign('orders', $orders);
}
$smarty->assign('footer', get_footer());
$smarty->display('order_list.html');
exit;
}
/* 取消订单 */
elseif ($act == '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, $_SESSION['user_id']))
{
ecs_header("Location: user.php?act=order_list\n");
exit;
}
}
/* 查看订单详情 */
elseif ($act == '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, $_SESSION['user_id']);
if ($order === false)
{
ecs_header("Location: user.php?act=order_list\n");
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('order_detail.html');
}
/* 确认收货 */
elseif ($act == 'affirm_received')
{
include_once(ROOT_PATH . 'includes/lib_transaction.php');
$order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0;
$_LANG['buyer'] = '买家';
if (affirm_received($order_id, $_SESSION['user_id']))
{
ecs_header("Location: user.php?act=order_list\n");
exit;
}
}
/* 退出会员中心 */
elseif ($act == 'logout')
{
if (!isset($back_act) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
{
$back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
}
$user->logout();
$Loaction = 'index.php';
ecs_header("Location: $Loaction\n");
}
/* 用户登陆 */
elseif ($act == 'ajax_login')
{
$user_name = !empty($_POST['username']) ? $_POST['username'] : '';
$pwd = !empty($_POST['pwd']) ? $_POST['pwd'] : '';
if (empty($user_name) || empty($pwd))
{
$login_faild = 1;
}
else
{
if ($user->check_user($user_name, $pwd) > 0)
{
$user->set_session($user_name);
$user->set_cookie($user_name);
update_user_info();
//show_user_center();
ajax_show_message('', 'index.php');
}
else
{
$login_faild = 1;
}
}
if ($login_faild)
{
//ecs_header("Location: user.php\n");
ajax_show_message($_mLANG['login_error']);
}
}
/* 注册会员的处理 */
elseif ($act == 'ajax_register')
{
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']) : '';
$err_msg = m_register($username, $password, $email);
if (!$err_msg)
{
/*把新注册用户的扩展信息插入数据库*/
$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);
}
$ucdata = empty($user->ucdata)? "" : $user->ucdata;
//$Loaction = 'index.php';
//ecs_header("Location: $Loaction\n");
ajax_show_message('', 'index.php');
}
else {
$Loaction = 'user.php?act=register';
//ecs_header("Location: $Loaction\n");
ajax_show_message($err_msg);
}
}
/* 显示会员注册界面 */
elseif ($act == 'register')
{
$smarty->display('user_register.html');
}
/* 用户中心 */
else
{
if ($_SESSION['user_id'] > 0)
{
//show_user_center();
ecs_header("Location: index.php");
}
else
{
$smarty->display('user_login.html');
}
}
/**
* 用户中心显示
*/
function show_user_center()
{
$best_goods = get_recommend_goods('best');
if (count($best_goods) > 0)
{
foreach ($best_goods as $key => $best_data)
{
$best_goods[$key]['shop_price'] = encode_output($best_data['shop_price']);
$best_goods[$key]['name'] = encode_output($best_data['name']);
}
}
$GLOBALS['smarty']->assign('best_goods' , $best_goods);
//$GLOBALS['smarty']->assign('footer', get_footer());
$GLOBALS['smarty']->display('user.html');
}
/**
* 手机注册
*/
function m_register($username, $password, $email, $other = array())
{
/* 检查username */
if (empty($username))
{
return '用户名不能为空';
}
if (preg_match('/\'\/^\\s*$|^c:\\\\con\\\\con$|[%,\\*\\"\\s\\t\\<\\>\\&\'\\\\]/', $username))
{
return '用户名错误';
}
/* 检查email */
if (empty($email))
{
return 'email不能为空';
}
if(!is_email($email))
{
return 'email错误';
}
/* 检查是否和管理员重名 */
if (admin_registered($username))
{
return '此用户已存在!';
}
if (!$GLOBALS['user']->add_user($username, $password, $email))
{
return '注册失败!';
//注册失败
}
else
{
//注册成功
/* 设置成登录状态 */
$GLOBALS['user']->set_session($username);
$GLOBALS['user']->set_cookie($username);
}
//定义other合法的变量数组
$other_key_array = array('msn', 'qq', 'office_phone', 'home_phone', 'mobile_phone');
$update_data['reg_time'] = local_strtotime(local_date('Y-m-d H:i:s'));
if ($other)
{
foreach ($other as $key=>$val)
{
//删除非法key值
if (!in_array($key, $other_key_array))
{
unset($other[$key]);
}
else
{
$other[$key] = htmlspecialchars(trim($val)); //防止用户输入javascript代码
}
}
$update_data = array_merge($update_data, $other);
}
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('users'), $update_data, 'UPDATE', 'user_id = ' . $_SESSION['user_id']);
update_user_info(); // 更新用户信息
}
?>