forked from eKing-one/phpBB-WAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guestbook.php
260 lines (208 loc) · 6.48 KB
/
guestbook.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
<?php
/**
* @package phpBB-WAP
* @简体中文:中文phpBB-WAP团队
* @license http://opensource.org/licenses/gpl-license.php
**/
/**
* 这是一款自由软件, 您可以在 Free Software Foundation 发布的
* GNU General Public License 的条款下重新发布或修改; 您可以
* 选择目前 version 2 这个版本(亦可以选择任何更新的版本,由
* 你喜欢)作为新的牌照.
**/
define('IN_PHPBB', true);
define('ROOT_PATH', './');
require(ROOT_PATH . 'common.php');
//session
$userdata = $session->start($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$mode = get_var('m', '');
if ($mode == 'new')
{
$gb_title = get_var('title', '');
$gb_password = get_var('password', '');
$gb_text = get_var('message', '');
$gb_username = get_var('username', '');
$gb_code = get_var('code', '');
$error = false;
$error_message = '';
if ($gb_code !== $board_config['server_name'])
{
trigger_error('请输入正确的留言问题');
}
if (empty($gb_title) || strlen($gb_username) > 255)
{
$error = true;
$error_message .= '<p>留言标题不合法</p>';
}
if (empty($gb_text))
{
$error = true;
$error_message .= '<p>留言内容不能留空</p>';
}
if (empty($gb_username) || strlen($gb_username) > 12)
{
$error = true;
$error_message .= '<p>姓名不合法</p>';
}
if (!$error)
{
$gb_username = magic_quotes($gb_username);
$gb_password = ($gb_password == '') ? '' : md5($gb_password);
$gb_title = magic_quotes($gb_title);
$gb_text = magic_quotes($gb_text);
$sql = 'INSERT INTO ' . GUESTBOOK_TABLE . " (gb_time, gb_ip, gb_username, gb_password, gb_title, gb_text, gb_reply)
VALUES (" . time() .", '" . $user_ip . "', '$gb_username', '$gb_password', '$gb_title', '$gb_text', '')";
if (!$db->sql_query($sql))
{
trigger_error('无法插入新留言', E_USER_WARNING);
}
trigger_error('留言成功' . back_link(append_sid('guestbook.php')), E_USER_ERROR);
}
error_box('ERROR_BOX', $error_message);
}
else if ($mode == 'view')
{
$gb_id = get_var('i', '');
if (empty($gb_id))
{
trigger_error('您没有指定留言' . back_link(append_sid('guestbook.php')), E_USER_ERROR);
}
$sql = 'SELECT gb_time, gb_ip, gb_username, gb_password, gb_title, gb_text, gb_reply
FROM ' . GUESTBOOK_TABLE . '
WHERE gb_id = ' . (int) $gb_id;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询留言信息', E_USER_WARNING);
}
if (!$row = $db->sql_fetchrow($result))
{
trigger_error('您指定的留言不存在' . back_link(append_sid('guestbook.php')), E_USER_ERROR);
}
if ($row['gb_password'] !== '')
{
if ($userdata['user_level'] != ADMIN)
{
if (isset($_POST['password']))
{
if (md5($_POST['password']) !== $row['gb_password'])
{
trigger_error('您输入的密码错误' . back_link(append_sid('guestbook.php?m=view&i=' . $gb_id)), E_USER_ERROR);
}
}
else
{
page_header('请输入查看密码');
$template->set_filenames(array('enter_password' => 'guestbook_enter_password.tpl'));
$template->assign_vars(array(
'S_ACTION' => append_sid('guestbook.php?m=view&i=' . $gb_id),
'U_BACK' => append_sid('guestbook.php'))
);
$template->pparse('enter_password');
page_footer();
}
}
}
if ($userdata['user_level'] == ADMIN && isset($_POST['reply']))
{
$gb_reply = get_var('reply', '');
$gb_reply = magic_quotes($gb_reply);
$sql = 'UPDATE ' . GUESTBOOK_TABLE . "
SET gb_reply = '$gb_reply'
WHERE gb_id = " . (int)$gb_id;
if (!$db->sql_query($sql))
{
trigger_error('无法回复留言', E_USER_WARNING);
}
trigger_error('留言成功' . back_link(append_sid('guestbook.php?m=view&i=' . $gb_id)), E_USER_ERROR);
}
page_header($row['gb_title']);
if ($userdata['user_level'] == ADMIN)
{
$template->assign_block_vars('delete', array());
if ($row['gb_reply'] == '')
{
$template->assign_block_vars('reply', array());
}
}
$template->set_filenames(array('body' => 'guestbook_view.tpl'));
$template->assign_vars(array(
'GB_TITLE' => decode_char($row['gb_title']),
'GB_TEXT' => decode_char($row['gb_text']),
'GB_TIME' => create_date('Y年m月d日 H:i', $row['gb_time'], $board_config['board_timezone']),
'GB_IP' => decode_ip($row['gb_ip']),
'GB_USERNAME' => decode_char($row['gb_username']),
'GB_REPLY' => (decode_char($row['gb_reply']) == '') ? '管理员没有回复' : decode_char($row['gb_reply']),
'U_BACK' => append_sid('guestbook.php'),
'U_GB_DELETE' => append_sid('guestbook.php?m=delete&i=' . $gb_id))
);
$template->pparse('body');
page_footer();
}
elseif ($mode == 'delete')
{
$gb_id = get_var('i', '');
if ($gb_id == '')
{
trigger_error('请指定要删除的留言' . back_link(append_sid('guestbook.php')), E_USER_ERROR);
}
$sql = 'DELETE FROM ' . GUESTBOOK_TABLE . '
WHERE gb_id = ' . (int)$gb_id;
if (!$db->sql_query($sql))
{
trigger_error('无法删除留言', E_USER_WARNING);
}
trigger_error('留言删除成功' . back_link(append_sid('guestbook.php')), E_USER_ERROR);
}
page_header('留言板');
$per = 15;
$start = get_pagination_start($per);
$sql = 'SELECT gb_id, gb_time, gb_title, gb_reply
FROM ' . GUESTBOOK_TABLE . "
ORDER BY gb_time DESC
LIMIT $start , $per";
if (!$result = $db->sql_query($sql))
{
trigger_error('无法查询留言板信息', E_USER_WARNING);
}
$i = 0;
while ($row = $db->sql_fetchrow($result))
{
$row_class = ( !($i % 2) ) ? 'row1' : 'row2';
$gb_reply = ($row['gb_reply'] == '') ? '未回复' : '<font color="red">已回复</font>';
$template->assign_block_vars('guestbook_row', array(
'ROW_CLASS' => $row_class,
'GB_NUMBER' => $start + $i + 1,
'GB_REPLY' => $gb_reply,
'GB_TIME' => create_date('m月d日 H:i', $row['gb_time'], $board_config['board_timezone']),
'GB_TITLE' => decode_char($row['gb_title']),
'U_GB' => append_sid(ROOT_PATH . 'guestbook.php?m=view&i=' . $row['gb_id']))
);
$i++;
}
if (!$db->sql_numrows($result))
{
$template->assign_block_vars('not_guestbook', array());
}
else
{
$sql = 'SELECT COUNT(gb_id) AS total_gb
FROM ' . GUESTBOOK_TABLE;
if (!$result = $db->sql_query($sql))
{
trigger_error('无法统计留言板记录', E_USER_WARNING);
}
$row = $db->sql_fetchrow($result);
}
$pagination = generate_pagination('guestbook.php?', $row['total_gb'], $per, $start);
$template->set_filenames(array(
'body' => 'guestbook_body.tpl')
);
$template->assign_vars(array(
'L_SERVER_NAME' => $board_config['server_name'],
'PAGINATION' => $pagination,
'S_ACTION' => append_sid('guestbook.php?m=new'))
);
$template->pparse('body');
page_footer();
?>