commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 提交用户咨询 |
|
5 |
*/ |
|
6 |
|
|
7 |
define('IN_ECS', true); |
|
8 |
|
|
9 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
10 |
require(ROOT_PATH . 'includes/cls_json.php'); |
|
11 |
|
|
12 |
if (!isset($_REQUEST['cmt']) && !isset($_REQUEST['act'])) |
|
13 |
{ |
|
14 |
/* 只有在没有提交咨询内容以及没有act的情况下才跳转 */ |
|
15 |
ecs_header("Location: ./\n"); |
|
16 |
exit; |
|
17 |
} |
|
18 |
$_REQUEST['cmt'] = isset($_REQUEST['cmt']) ? json_str_iconv($_REQUEST['cmt']) : ''; |
|
19 |
|
|
20 |
$json = new JSON; |
|
21 |
$result = array('error' => 0, 'message' => '', 'content' => ''); |
|
22 |
|
|
23 |
if (empty($_REQUEST['act'])) |
|
24 |
{ |
|
25 |
/* |
|
26 |
* act 参数为空 |
|
27 |
* 默认为添加咨询内容 |
|
28 |
*/ |
|
29 |
$cmt = $json->decode($_REQUEST['cmt']); |
|
30 |
$cmt->page = 1; |
|
31 |
$cmt->id = !empty($cmt->id) ? intval($cmt->id) : 0; |
|
32 |
|
|
33 |
if (empty($cmt) || !isset($cmt->id)) |
|
34 |
{ |
|
35 |
$result['error'] = 1; |
|
36 |
$result['message'] = '此咨询无效!'; |
|
37 |
} |
|
38 |
elseif (!is_email($cmt->email)) |
|
39 |
{ |
|
40 |
$result['error'] = 1; |
|
41 |
$result['message'] = $_LANG['error_email']; |
|
42 |
} |
|
43 |
else |
|
44 |
{ |
|
45 |
if ((intval($_CFG['captcha']) & CAPTCHA_QUESTION) && gd_version() > 0) |
|
46 |
{ |
|
47 |
/* 检查验证码 */ |
|
48 |
include_once('includes/cls_captcha.php'); |
|
49 |
|
|
50 |
$validator = new captcha(); |
|
51 |
$validator->session_word = 'captcha_zixun'; |
|
52 |
if (!$validator->check_word($cmt->captcha)) |
|
53 |
{ |
|
54 |
$result['error'] = 1; |
|
55 |
$result['message'] = $_LANG['invalid_captcha']; |
|
56 |
} |
|
57 |
else |
|
58 |
{ |
|
59 |
|
|
60 |
/* 无错误就保存留言 */ |
|
61 |
if (empty($result['error'])) |
|
62 |
{ |
|
63 |
add_question($cmt); |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
else |
|
68 |
{ |
|
69 |
/* 没有验证码时,用时间来限制机器人发帖或恶意发评论 */ |
|
70 |
if (!isset($_SESSION['send_time'])) |
|
71 |
{ |
|
72 |
$_SESSION['send_time'] = 0; |
|
73 |
} |
|
74 |
|
|
75 |
$cur_time = gmtime(); |
|
76 |
if (($cur_time - $_SESSION['send_time']) < 30) // 小于30秒禁止发评论 |
|
77 |
{ |
|
78 |
$result['error'] = 1; |
|
79 |
$result['message'] = $_LANG['cmt_spam_warning']; |
|
80 |
} |
|
81 |
else |
|
82 |
{ |
|
83 |
|
|
84 |
|
|
85 |
/* 无错误就保存留言 */ |
|
86 |
if (empty($result['error'])) |
|
87 |
{ |
|
88 |
add_question($cmt); |
|
89 |
$_SESSION['send_time'] = $cur_time; |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
else |
|
96 |
{ |
|
97 |
/* |
|
98 |
* act 参数不为空 |
|
99 |
* 默认为咨询内容列表 |
|
100 |
* 根据 _GET 创建一个静态对象 |
|
101 |
*/ |
|
102 |
$cmt = new stdClass(); |
|
103 |
$cmt->id = !empty($_GET['id']) ? intval($_GET['id']) : 0; |
|
104 |
$cmt->type = !empty($_GET['type']) ? intval($_GET['type']) : 0; |
|
105 |
$cmt->page = !empty($_GET['page']) ? intval($_GET['page']) : 1; |
|
106 |
$cmt->question_type = !empty($_GET['question_type']) ? intval($_GET['question_type']) : 0; |
|
107 |
} |
|
108 |
|
|
109 |
if ($result['error'] == 0) |
|
110 |
{ |
|
111 |
$comments = assign_question($cmt->id, $cmt->page, $cmt->question_type); |
|
112 |
|
|
113 |
$smarty->assign('id', $cmt->id); |
|
114 |
$smarty->assign('username', $_SESSION['user_name']); |
|
115 |
$smarty->assign('email', $_SESSION['email']); |
|
116 |
$smarty->assign('question_list', $comments['comments']); |
|
117 |
$smarty->assign('pager', $comments['pager']); |
|
118 |
|
|
119 |
/* 验证码相关设置 */ |
|
120 |
if ((intval($_CFG['captcha']) & CAPTCHA_QUESTION) && gd_version() > 0) |
|
121 |
{ |
|
122 |
$smarty->assign('enabled_captcha_question', 1); |
|
123 |
$smarty->assign('rand', mt_rand()); |
|
124 |
} |
|
125 |
|
|
126 |
$result['message'] = $_CFG['comment_check'] ? '您的咨询已成功提交, 请等待管理员的审核!' : '您的咨询已成功提交, 感谢您的参与!'; |
|
127 |
$result['content'] = $smarty->fetch("library/question_list.lbi"); |
|
128 |
$result['question_type'] = $cmt->question_type; |
|
129 |
$result['goods_id'] = $cmt->id; |
|
130 |
} |
|
131 |
|
|
132 |
echo $json->encode($result); |
|
133 |
|
|
134 |
/*------------------------------------------------------ */ |
|
135 |
//-- PRIVATE FUNCTION |
|
136 |
/*------------------------------------------------------ */ |
|
137 |
|
|
138 |
/** |
|
139 |
* 添加咨询内容 |
|
140 |
* |
|
141 |
* @access public |
|
142 |
* @param object $cmt |
|
143 |
* @return void |
|
144 |
*/ |
|
145 |
function add_question($cmt) |
|
146 |
{ |
|
147 |
/* 咨询是否需要审核 */ |
|
148 |
$status = 1 - $GLOBALS['_CFG']['comment_check']; |
|
149 |
|
|
150 |
$user_id = empty($_SESSION['user_id']) ? 0 : $_SESSION['user_id']; |
|
151 |
$email = empty($cmt->email) ? $_SESSION['email'] : trim($cmt->email); |
|
152 |
$user_name = empty($cmt->username) ? $_SESSION['user_name'] : trim($cmt->username); |
|
153 |
$email = htmlspecialchars($email); |
|
154 |
$question_type = empty($cmt->question_type) ? 0 : intval($cmt->question_type); |
|
155 |
$user_name = htmlspecialchars($user_name); |
|
156 |
|
|
157 |
/* 保存咨询内容 */ |
|
158 |
$sql = "INSERT INTO " .$GLOBALS['ecs']->table('question') . |
|
159 |
"( id_value, question_type, email, user_name, content, add_time, ip_address, status, parent_id, user_id) VALUES " . |
|
160 |
"('" .$cmt->id. "', '$question_type', '$email', '$user_name', '" .$cmt->content."', ".gmtime().", '".real_ip()."', '$status', '0', '$user_id')"; |
|
161 |
|
|
162 |
$result = $GLOBALS['db']->query($sql); |
|
163 |
clear_cache_files('question_list.lbi'); |
|
164 |
return $result; |
|
165 |
} |
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
?> |