5
* @version $Id: mcp_warn.php,v 1.54 2007/10/19 13:10:01 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
21
* Handling warning the users
29
function mcp_warn(&$p_master)
31
$this->p_master = &$p_master;
34
function main($id, $mode)
36
global $auth, $db, $user, $template;
37
global $config, $phpbb_root_path, $phpEx;
39
$action = request_var('action', array('' => ''));
41
if (is_array($action))
43
list($action, ) = each($action);
46
$this->page_title = 'MCP_WARN';
48
add_form_key('mcp_warn');
53
$this->mcp_warn_front_view();
54
$this->tpl_name = 'mcp_warn_front';
58
$this->mcp_warn_list_view($action);
59
$this->tpl_name = 'mcp_warn_list';
63
$this->mcp_warn_post_view($action);
64
$this->tpl_name = 'mcp_warn_post';
68
$this->mcp_warn_user_view($action);
69
$this->tpl_name = 'mcp_warn_user';
75
* Generates the summary on the main page of the warning module
77
function mcp_warn_front_view()
79
global $phpEx, $phpbb_root_path, $config;
80
global $template, $db, $user, $auth;
82
$template->assign_vars(array(
83
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp&field=username&select_single=true'),
84
'U_POST_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user'),
87
// Obtain a list of the 5 naughtiest users....
88
// These are the 5 users with the highest warning count
92
view_warned_users($highest, $count, 5);
94
foreach ($highest as $row)
96
$template->assign_block_vars('highest', array(
97
'U_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $row['user_id']),
99
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
100
'USERNAME' => $row['username'],
101
'USERNAME_COLOUR' => ($row['user_colour']) ? '#' . $row['user_colour'] : '',
102
'U_USER' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['user_id']),
104
'WARNING_TIME' => $user->format_date($row['user_last_warning']),
105
'WARNINGS' => $row['user_warnings'],
109
// And now the 5 most recent users to get in trouble
110
$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_warnings, w.warning_time
111
FROM ' . USERS_TABLE . ' u, ' . WARNINGS_TABLE . ' w
112
WHERE u.user_id = w.user_id
113
ORDER BY w.warning_time DESC';
114
$result = $db->sql_query_limit($sql, 5);
116
while ($row = $db->sql_fetchrow($result))
118
$template->assign_block_vars('latest', array(
119
'U_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $row['user_id']),
121
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
122
'USERNAME' => $row['username'],
123
'USERNAME_COLOUR' => ($row['user_colour']) ? '#' . $row['user_colour'] : '',
124
'U_USER' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['user_id']),
126
'WARNING_TIME' => $user->format_date($row['warning_time']),
127
'WARNINGS' => $row['user_warnings'],
130
$db->sql_freeresult($result);
134
* Lists all users with warnings
136
function mcp_warn_list_view($action)
138
global $phpEx, $phpbb_root_path, $config;
139
global $template, $db, $user, $auth;
141
$user->add_lang('memberlist');
143
$start = request_var('start', 0);
144
$st = request_var('st', 0);
145
$sk = request_var('sk', 'b');
146
$sd = request_var('sd', 'd');
148
$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
149
$sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_WARNINGS']);
150
$sort_by_sql = array('a' => 'username_clean', 'b' => 'user_last_warning', 'c' => 'user_warnings');
152
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
153
gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
155
// Define where and sort sql for use in displaying logs
156
$sql_where = ($st) ? (time() - ($st * 86400)) : 0;
157
$sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
162
view_warned_users($users, $user_count, $config['topics_per_page'], $start, $sql_where, $sql_sort);
164
foreach ($users as $row)
166
$template->assign_block_vars('user', array(
167
'U_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $row['user_id']),
169
'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
170
'USERNAME' => $row['username'],
171
'USERNAME_COLOUR' => ($row['user_colour']) ? '#' . $row['user_colour'] : '',
172
'U_USER' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $row['user_id']),
174
'WARNING_TIME' => $user->format_date($row['user_last_warning']),
175
'WARNINGS' => $row['user_warnings'],
179
$template->assign_vars(array(
180
'U_POST_ACTION' => $this->u_action,
181
'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false,
182
'S_SELECT_SORT_DIR' => $s_sort_dir,
183
'S_SELECT_SORT_KEY' => $s_sort_key,
184
'S_SELECT_SORT_DAYS' => $s_limit_days,
186
'PAGE_NUMBER' => on_page($user_count, $config['topics_per_page'], $start),
187
'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}mcp.$phpEx", "i=warn&mode=list&st=$st&sk=$sk&sd=$sd"), $user_count, $config['topics_per_page'], $start),
188
'TOTAL_USERS' => ($user_count == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $user_count),
193
* Handles warning the user when the warning is for a specific post
195
function mcp_warn_post_view($action)
197
global $phpEx, $phpbb_root_path, $config;
198
global $template, $db, $user, $auth;
200
$post_id = request_var('p', 0);
201
$forum_id = request_var('f', 0);
202
$notify = (isset($_REQUEST['notify_user'])) ? true : false;
203
$warning = utf8_normalize_nfc(request_var('warning', '', true));
205
$sql = 'SELECT u.*, p.*
206
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
207
WHERE post_id = $post_id
208
AND u.user_id = p.poster_id";
209
$result = $db->sql_query($sql);
210
$user_row = $db->sql_fetchrow($result);
211
$db->sql_freeresult($result);
215
trigger_error('NO_POST');
218
// There is no point issuing a warning to ignored users (ie anonymous and bots)
219
if ($user_row['user_type'] == USER_IGNORE)
221
trigger_error('CANNOT_WARN_ANONYMOUS');
224
// Prevent someone from warning themselves
225
if ($user_row['user_id'] == $user->data['user_id'])
227
trigger_error('CANNOT_WARN_SELF');
230
// Check if there is already a warning for this post to prevent multiple
231
// warnings for the same offence
232
$sql = 'SELECT post_id
233
FROM ' . WARNINGS_TABLE . "
234
WHERE post_id = $post_id";
235
$result = $db->sql_query($sql);
236
$row = $db->sql_fetchrow($result);
237
$db->sql_freeresult($result);
241
trigger_error('ALREADY_WARNED');
244
$user_id = $user_row['user_id'];
246
if (strpos($this->u_action, "&f=$forum_id&p=$post_id") === false)
248
$this->p_master->adjust_url("&f=$forum_id&p=$post_id");
249
$this->u_action .= "&f=$forum_id&p=$post_id";
252
if ($warning && $action == 'add_warning')
254
if (check_form_key('mcp_warn'))
256
add_warning($user_row, $warning, $notify, $post_id);
257
$msg = $user->lang['USER_WARNING_ADDED'];
261
$msg = $user->lang['FORM_INVALID'];
263
$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&mode=user_notes&u=$user_id");
264
meta_refresh(2, $redirect);
265
trigger_error($user->lang['USER_WARNING_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
268
// OK, they didn't submit a warning so lets build the page for them to do so
270
// We want to make the message available here as a reminder
271
// Parse the message and subject
272
$message = censor_text($user_row['post_text']);
274
// Second parse bbcode here
275
if ($user_row['bbcode_bitfield'])
277
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
279
$bbcode = new bbcode($user_row['bbcode_bitfield']);
280
$bbcode->bbcode_second_pass($message, $user_row['bbcode_uid'], $user_row['bbcode_bitfield']);
283
$message = bbcode_nl2br($message);
284
$message = smiley_text($message);
286
// Generate the appropriate user information for the user we are looking at
287
if (!function_exists('get_user_avatar'))
289
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
292
$rank_title = $rank_img = '';
293
$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
295
$template->assign_vars(array(
296
'U_POST_ACTION' => $this->u_action,
299
'USERNAME' => $user_row['username'],
300
'USER_COLOR' => (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '',
301
'RANK_TITLE' => $rank_title,
302
'JOINED' => $user->format_date($user_row['user_regdate']),
303
'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
304
'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
306
'AVATAR_IMG' => $avatar_img,
307
'RANK_IMG' => $rank_img,
309
'L_WARNING_POST_DEFAULT' => sprintf($user->lang['WARNING_POST_DEFAULT'], generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&p=$post_id#p$post_id"),
314
* Handles warning the user
316
function mcp_warn_user_view($action)
318
global $phpEx, $phpbb_root_path, $config, $module;
319
global $template, $db, $user, $auth;
321
$user_id = request_var('u', 0);
322
$username = request_var('username', '', true);
323
$notify = (isset($_REQUEST['notify_user'])) ? true : false;
324
$warning = utf8_normalize_nfc(request_var('warning', '', true));
326
$sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
329
FROM ' . USERS_TABLE . '
330
WHERE ' . $sql_where;
331
$result = $db->sql_query($sql);
332
$user_row = $db->sql_fetchrow($result);
333
$db->sql_freeresult($result);
337
trigger_error('NO_USER');
340
// Prevent someone from warning themselves
341
if ($user_row['user_id'] == $user->data['user_id'])
343
trigger_error('CANNOT_WARN_SELF');
346
$user_id = $user_row['user_id'];
348
if (strpos($this->u_action, "&u=$user_id") === false)
350
$this->p_master->adjust_url('&u=' . $user_id);
351
$this->u_action .= "&u=$user_id";
354
if ($warning && $action == 'add_warning')
356
if (check_form_key('mcp_warn'))
358
add_warning($user_row, $warning, $notify);
359
$msg = $user->lang['USER_WARNING_ADDED'];
363
$msg = $user->lang['FORM_INVALID'];
365
$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&mode=user_notes&u=$user_id");
366
meta_refresh(2, $redirect);
367
trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
370
// Generate the appropriate user information for the user we are looking at
371
if (!function_exists('get_user_avatar'))
373
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
376
$rank_title = $rank_img = '';
377
$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
379
// OK, they didn't submit a warning so lets build the page for them to do so
380
$template->assign_vars(array(
381
'U_POST_ACTION' => $this->u_action,
383
'USERNAME' => $user_row['username'],
384
'USER_COLOR' => (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '',
385
'RANK_TITLE' => $rank_title,
386
'JOINED' => $user->format_date($user_row['user_regdate']),
387
'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
388
'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
390
'AVATAR_IMG' => $avatar_img,
391
'RANK_IMG' => $rank_img,
399
* Insert the warning into the database
401
function add_warning($user_row, $warning, $send_pm = true, $post_id = 0)
403
global $phpEx, $phpbb_root_path, $config;
404
global $template, $db, $user, $auth;
408
include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
409
include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
411
$user_row['user_lang'] = (file_exists($phpbb_root_path . 'language/' . $user_row['user_lang'] . "/mcp.$phpEx")) ? $user_row['user_lang'] : $config['default_lang'];
412
include($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");
414
$message_parser = new parse_message();
416
$message_parser->message = sprintf($lang['WARNING_PM_BODY'], $warning);
417
$message_parser->parse(true, true, true, false, false, true, true);
420
'from_user_id' => $user->data['user_id'],
421
'from_user_ip' => $user->ip,
422
'from_username' => $user->data['username'],
423
'enable_sig' => false,
424
'enable_bbcode' => true,
425
'enable_smilies' => true,
426
'enable_urls' => false,
428
'bbcode_bitfield' => $message_parser->bbcode_bitfield,
429
'bbcode_uid' => $message_parser->bbcode_uid,
430
'message' => $message_parser->message,
431
'address_list' => array('u' => array($user_row['user_id'] => 'to')),
434
submit_pm('post', $lang['WARNING_PM_SUBJECT'], $pm_data, false);
437
add_log('admin', 'LOG_USER_WARNING', $user_row['username']);
438
$log_id = add_log('user', $user_row['user_id'], 'LOG_USER_WARNING_BODY', $warning);
441
'user_id' => $user_row['user_id'],
442
'post_id' => $post_id,
444
'warning_time' => time(),
447
$db->sql_query('INSERT INTO ' . WARNINGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
449
$sql = 'UPDATE ' . USERS_TABLE . '
450
SET user_warnings = user_warnings + 1,
451
user_last_warning = ' . time() . '
452
WHERE user_id = ' . $user_row['user_id'];
453
$db->sql_query($sql);
455
// We add this to the mod log too for moderators to see that a specific user got warned.
456
$sql = 'SELECT forum_id, topic_id
457
FROM ' . POSTS_TABLE . '
458
WHERE post_id = ' . $post_id;
459
$result = $db->sql_query($sql);
460
$row = $db->sql_fetchrow($result);
461
$db->sql_freeresult($result);
463
add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_USER_WARNING', $user_row['username']);
b'\\ No newline at end of file'