1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/mcp/mcp_reports.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,728 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package mcp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* mcp_reports
1.24 +* Handling the reports queue
1.25 +* @package mcp
1.26 +*/
1.27 +class mcp_reports
1.28 +{
1.29 + var $p_master;
1.30 + var $u_action;
1.31 +
1.32 + function mcp_reports(&$p_master)
1.33 + {
1.34 + $this->p_master = &$p_master;
1.35 + }
1.36 +
1.37 + function main($id, $mode)
1.38 + {
1.39 + global $auth, $db, $user, $template, $cache;
1.40 + global $config, $phpbb_root_path, $phpEx, $action;
1.41 +
1.42 + include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1.43 +
1.44 + $forum_id = request_var('f', 0);
1.45 + $start = request_var('start', 0);
1.46 +
1.47 + $this->page_title = 'MCP_REPORTS';
1.48 +
1.49 + switch ($action)
1.50 + {
1.51 + case 'close':
1.52 + case 'delete':
1.53 + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
1.54 +
1.55 + $report_id_list = request_var('report_id_list', array(0));
1.56 +
1.57 + if (!sizeof($report_id_list))
1.58 + {
1.59 + trigger_error('NO_REPORT_SELECTED');
1.60 + }
1.61 +
1.62 + close_report($report_id_list, $mode, $action);
1.63 +
1.64 + break;
1.65 + }
1.66 +
1.67 + switch ($mode)
1.68 + {
1.69 + case 'report_details':
1.70 +
1.71 + $user->add_lang(array('posting', 'viewforum', 'viewtopic'));
1.72 +
1.73 + $post_id = request_var('p', 0);
1.74 +
1.75 + // closed reports are accessed by report id
1.76 + $report_id = request_var('r', 0);
1.77 +
1.78 + $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
1.79 + FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
1.80 + WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . '
1.81 + AND rr.reason_id = r.reason_id
1.82 + AND r.user_id = u.user_id
1.83 + AND r.pm_id = 0
1.84 + ORDER BY report_closed ASC';
1.85 + $result = $db->sql_query_limit($sql, 1);
1.86 + $report = $db->sql_fetchrow($result);
1.87 + $db->sql_freeresult($result);
1.88 +
1.89 + if (!$report)
1.90 + {
1.91 + trigger_error('NO_REPORT');
1.92 + }
1.93 +
1.94 + if (!$report_id && $report['report_closed'])
1.95 + {
1.96 + trigger_error('REPORT_CLOSED');
1.97 + }
1.98 +
1.99 + $post_id = $report['post_id'];
1.100 + $report_id = $report['report_id'];
1.101 +
1.102 + $post_info = get_post_data(array($post_id), 'm_report', true);
1.103 +
1.104 + if (!sizeof($post_info))
1.105 + {
1.106 + trigger_error('NO_REPORT_SELECTED');
1.107 + }
1.108 +
1.109 + $post_info = $post_info[$post_id];
1.110 +
1.111 + $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
1.112 + if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
1.113 + {
1.114 + $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
1.115 + $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
1.116 + }
1.117 +
1.118 + if (topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
1.119 + {
1.120 + $template->assign_vars(array(
1.121 + 'S_TOPIC_REVIEW' => true,
1.122 + 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'],
1.123 + 'TOPIC_TITLE' => $post_info['topic_title'])
1.124 + );
1.125 + }
1.126 +
1.127 + $topic_tracking_info = $extensions = $attachments = array();
1.128 + // Get topic tracking info
1.129 + if ($config['load_db_lastread'])
1.130 + {
1.131 + $tmp_topic_data = array($post_info['topic_id'] => $post_info);
1.132 + $topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
1.133 + unset($tmp_topic_data);
1.134 + }
1.135 + else
1.136 + {
1.137 + $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
1.138 + }
1.139 +
1.140 + $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
1.141 +
1.142 + // Process message, leave it uncensored
1.143 + $message = $post_info['post_text'];
1.144 +
1.145 + if ($post_info['bbcode_bitfield'])
1.146 + {
1.147 + include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
1.148 + $bbcode = new bbcode($post_info['bbcode_bitfield']);
1.149 + $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
1.150 + }
1.151 +
1.152 + $message = bbcode_nl2br($message);
1.153 + $message = smiley_text($message);
1.154 + $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text']));
1.155 +
1.156 + if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
1.157 + {
1.158 + $sql = 'SELECT *
1.159 + FROM ' . ATTACHMENTS_TABLE . '
1.160 + WHERE post_msg_id = ' . $post_id . '
1.161 + AND in_message = 0
1.162 + ORDER BY filetime DESC';
1.163 + $result = $db->sql_query($sql);
1.164 +
1.165 + while ($row = $db->sql_fetchrow($result))
1.166 + {
1.167 + $attachments[] = $row;
1.168 + }
1.169 + $db->sql_freeresult($result);
1.170 +
1.171 + if (sizeof($attachments))
1.172 + {
1.173 + $update_count = array();
1.174 + parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
1.175 + }
1.176 +
1.177 + // Display not already displayed Attachments for this post, we already parsed them. ;)
1.178 + if (!empty($attachments))
1.179 + {
1.180 + $template->assign_var('S_HAS_ATTACHMENTS', true);
1.181 +
1.182 + foreach ($attachments as $attachment)
1.183 + {
1.184 + $template->assign_block_vars('attachment', array(
1.185 + 'DISPLAY_ATTACHMENT' => $attachment)
1.186 + );
1.187 + }
1.188 + }
1.189 + }
1.190 +
1.191 + $template->assign_vars(array(
1.192 + 'S_MCP_REPORT' => true,
1.193 + 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
1.194 + 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
1.195 + 'S_POST_REPORTED' => $post_info['post_reported'],
1.196 + 'S_POST_UNAPPROVED' => !$post_info['post_approved'],
1.197 + 'S_POST_LOCKED' => $post_info['post_edit_locked'],
1.198 + 'S_USER_NOTES' => true,
1.199 +
1.200 + 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '',
1.201 + 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
1.202 + 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
1.203 + 'U_MCP_REPORTER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $report['user_id']),
1.204 + 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
1.205 + 'U_MCP_WARN_REPORTER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $report['user_id']) : '',
1.206 + 'U_MCP_WARN_USER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $post_info['user_id']) : '',
1.207 + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $post_info['forum_id']),
1.208 + 'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']),
1.209 + 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']),
1.210 +
1.211 + 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
1.212 + 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
1.213 + 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
1.214 +
1.215 + 'RETURN_REPORTS' => sprintf($user->lang['RETURN_REPORTS'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports' . (($post_info['post_reported']) ? '&mode=reports' : '&mode=reports_closed') . '&start=' . $start . '&f=' . $post_info['forum_id']) . '">', '</a>'),
1.216 + 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
1.217 + 'REPORT_DATE' => $user->format_date($report['report_time']),
1.218 + 'REPORT_ID' => $report_id,
1.219 + 'REPORT_REASON_TITLE' => $reason['title'],
1.220 + 'REPORT_REASON_DESCRIPTION' => $reason['description'],
1.221 + 'REPORT_TEXT' => $report['report_text'],
1.222 +
1.223 + 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
1.224 + 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
1.225 + 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
1.226 + 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
1.227 +
1.228 + 'REPORTER_FULL' => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
1.229 + 'REPORTER_COLOUR' => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
1.230 + 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
1.231 + 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
1.232 +
1.233 + 'POST_PREVIEW' => $message,
1.234 + 'POST_SUBJECT' => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'],
1.235 + 'POST_DATE' => $user->format_date($post_info['post_time']),
1.236 + 'POST_IP' => $post_info['poster_ip'],
1.237 + 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
1.238 + 'POST_ID' => $post_info['post_id'],
1.239 +
1.240 + 'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? $this->u_action . '&r=' . $report_id . '&p=' . $post_id . '&f=' . $forum_id . '&lookup=' . $post_info['poster_ip'] . '#ip' : '',
1.241 + ));
1.242 +
1.243 + $this->tpl_name = 'mcp_post';
1.244 +
1.245 + break;
1.246 +
1.247 + case 'reports':
1.248 + case 'reports_closed':
1.249 + $topic_id = request_var('t', 0);
1.250 +
1.251 + $forum_info = array();
1.252 + $forum_list_reports = get_forum_list('m_report', false, true);
1.253 + $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
1.254 +
1.255 + // Remove forums we cannot read
1.256 + foreach ($forum_list_reports as $k => $forum_data)
1.257 + {
1.258 + if (!isset($forum_list_read[$forum_data['forum_id']]))
1.259 + {
1.260 + unset($forum_list_reports[$k]);
1.261 + }
1.262 + }
1.263 + unset($forum_list_read);
1.264 +
1.265 + if ($topic_id)
1.266 + {
1.267 + $topic_info = get_topic_data(array($topic_id));
1.268 +
1.269 + if (!sizeof($topic_info))
1.270 + {
1.271 + trigger_error('TOPIC_NOT_EXIST');
1.272 + }
1.273 +
1.274 + if ($forum_id != $topic_info[$topic_id]['forum_id'])
1.275 + {
1.276 + $topic_id = 0;
1.277 + }
1.278 + else
1.279 + {
1.280 + $topic_info = $topic_info[$topic_id];
1.281 + $forum_id = (int) $topic_info['forum_id'];
1.282 + }
1.283 + }
1.284 +
1.285 + $forum_list = array();
1.286 +
1.287 + if (!$forum_id)
1.288 + {
1.289 + foreach ($forum_list_reports as $row)
1.290 + {
1.291 + $forum_list[] = $row['forum_id'];
1.292 + }
1.293 +
1.294 + if (!sizeof($forum_list))
1.295 + {
1.296 + trigger_error('NOT_MODERATOR');
1.297 + }
1.298 +
1.299 + $global_id = $forum_list[0];
1.300 +
1.301 + $sql = 'SELECT SUM(forum_topics) as sum_forum_topics
1.302 + FROM ' . FORUMS_TABLE . '
1.303 + WHERE ' . $db->sql_in_set('forum_id', $forum_list);
1.304 + $result = $db->sql_query($sql);
1.305 + $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
1.306 + $db->sql_freeresult($result);
1.307 + }
1.308 + else
1.309 + {
1.310 + $forum_info = get_forum_data(array($forum_id), 'm_report');
1.311 +
1.312 + if (!sizeof($forum_info))
1.313 + {
1.314 + trigger_error('NOT_MODERATOR');
1.315 + }
1.316 +
1.317 + $forum_info = $forum_info[$forum_id];
1.318 + $forum_list = array($forum_id);
1.319 + $global_id = $forum_id;
1.320 + }
1.321 +
1.322 + $forum_list[] = 0;
1.323 + $forum_data = array();
1.324 +
1.325 + $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
1.326 + foreach ($forum_list_reports as $row)
1.327 + {
1.328 + $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $row['padding']) . $row['forum_name'] . '</option>';
1.329 + $forum_data[$row['forum_id']] = $row;
1.330 + }
1.331 + unset($forum_list_reports);
1.332 +
1.333 + $sort_days = $total = 0;
1.334 + $sort_key = $sort_dir = '';
1.335 + $sort_by_sql = $sort_order_sql = array();
1.336 + mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
1.337 +
1.338 + $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
1.339 + $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
1.340 +
1.341 + if ($mode == 'reports')
1.342 + {
1.343 + $report_state = 'AND p.post_reported = 1 AND r.report_closed = 0';
1.344 + }
1.345 + else
1.346 + {
1.347 + $report_state = 'AND r.report_closed = 1';
1.348 + }
1.349 +
1.350 + $sql = 'SELECT r.report_id
1.351 + FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . REPORTS_TABLE . ' r ' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . (($sort_order_sql[0] == 'r') ? ', ' . USERS_TABLE . ' ru' : '') . '
1.352 + WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . "
1.353 + $report_state
1.354 + AND r.post_id = p.post_id
1.355 + " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
1.356 + ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . '
1.357 + ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
1.358 + AND t.topic_id = p.topic_id
1.359 + AND r.pm_id = 0
1.360 + $limit_time_sql
1.361 + ORDER BY $sort_order_sql";
1.362 + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1.363 +
1.364 + $i = 0;
1.365 + $report_ids = array();
1.366 + while ($row = $db->sql_fetchrow($result))
1.367 + {
1.368 + $report_ids[] = $row['report_id'];
1.369 + $row_num[$row['report_id']] = $i++;
1.370 + }
1.371 + $db->sql_freeresult($result);
1.372 +
1.373 + if (sizeof($report_ids))
1.374 + {
1.375 + $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, u.username, u.username_clean, u.user_colour, r.user_id as reporter_id, ru.username as reporter_name, ru.user_colour as reporter_colour, r.report_time, r.report_id
1.376 + FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
1.377 + WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . '
1.378 + AND t.topic_id = p.topic_id
1.379 + AND r.post_id = p.post_id
1.380 + AND u.user_id = p.poster_id
1.381 + AND ru.user_id = r.user_id
1.382 + AND r.pm_id = 0
1.383 + ORDER BY ' . $sort_order_sql;
1.384 + $result = $db->sql_query($sql);
1.385 +
1.386 + $report_data = $rowset = array();
1.387 + while ($row = $db->sql_fetchrow($result))
1.388 + {
1.389 + $global_topic = ($row['forum_id']) ? false : true;
1.390 + if ($global_topic)
1.391 + {
1.392 + $row['forum_id'] = $global_id;
1.393 + }
1.394 +
1.395 + $template->assign_block_vars('postrow', array(
1.396 + 'U_VIEWFORUM' => (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
1.397 + 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . '#p' . $row['post_id'],
1.398 + 'U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=reports&start=$start&mode=report_details&f={$row['forum_id']}&r={$row['report_id']}"),
1.399 +
1.400 + 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
1.401 + 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
1.402 + 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
1.403 + 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
1.404 +
1.405 + 'REPORTER_FULL' => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
1.406 + 'REPORTER_COLOUR' => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
1.407 + 'REPORTER' => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
1.408 + 'U_REPORTER' => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
1.409 +
1.410 + 'FORUM_NAME' => (!$global_topic) ? $forum_data[$row['forum_id']]['forum_name'] : $user->lang['GLOBAL_ANNOUNCEMENT'],
1.411 + 'POST_ID' => $row['post_id'],
1.412 + 'POST_SUBJECT' => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
1.413 + 'POST_TIME' => $user->format_date($row['post_time']),
1.414 + 'REPORT_ID' => $row['report_id'],
1.415 + 'REPORT_TIME' => $user->format_date($row['report_time']),
1.416 + 'TOPIC_TITLE' => $row['topic_title'])
1.417 + );
1.418 + }
1.419 + $db->sql_freeresult($result);
1.420 + unset($report_ids, $row);
1.421 + }
1.422 +
1.423 + // Now display the page
1.424 + $template->assign_vars(array(
1.425 + 'L_EXPLAIN' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'],
1.426 + 'L_TITLE' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN'] : $user->lang['MCP_REPORTS_CLOSED'],
1.427 + 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
1.428 +
1.429 + 'S_MCP_ACTION' => $this->u_action,
1.430 + 'S_FORUM_OPTIONS' => $forum_options,
1.431 + 'S_CLOSED' => ($mode == 'reports_closed') ? true : false,
1.432 +
1.433 + 'PAGINATION' => generate_pagination($this->u_action . "&f=$forum_id&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $total, $config['topics_per_page'], $start),
1.434 + 'PAGE_NUMBER' => on_page($total, $config['topics_per_page'], $start),
1.435 + 'TOPIC_ID' => $topic_id,
1.436 + 'TOTAL' => $total,
1.437 + 'TOTAL_REPORTS' => ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),
1.438 + )
1.439 + );
1.440 +
1.441 + $this->tpl_name = 'mcp_reports';
1.442 + break;
1.443 + }
1.444 + }
1.445 +}
1.446 +
1.447 +/**
1.448 +* Closes a report
1.449 +*/
1.450 +function close_report($report_id_list, $mode, $action, $pm = false)
1.451 +{
1.452 + global $db, $template, $user, $config, $auth;
1.453 + global $phpEx, $phpbb_root_path;
1.454 +
1.455 + $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 ';
1.456 + $id_column = ($pm) ? 'pm_id' : 'post_id';
1.457 + $module = ($pm) ? 'pm_reports' : 'reports';
1.458 + $pm_prefix = ($pm) ? 'PM_' : '';
1.459 +
1.460 + $sql = "SELECT r.$id_column
1.461 + FROM " . REPORTS_TABLE . ' r
1.462 + WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . $pm_where;
1.463 + $result = $db->sql_query($sql);
1.464 +
1.465 + $post_id_list = array();
1.466 + while ($row = $db->sql_fetchrow($result))
1.467 + {
1.468 + $post_id_list[] = $row[$id_column];
1.469 + }
1.470 + $post_id_list = array_unique($post_id_list);
1.471 +
1.472 + if ($pm)
1.473 + {
1.474 + if (!$auth->acl_getf_global('m_report'))
1.475 + {
1.476 + trigger_error('NOT_AUTHORISED');
1.477 + }
1.478 + }
1.479 + else
1.480 + {
1.481 + if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
1.482 + {
1.483 + trigger_error('NOT_AUTHORISED');
1.484 + }
1.485 + }
1.486 +
1.487 + if ($action == 'delete' && strpos($user->data['session_page'], 'mode=report_details') !== false)
1.488 + {
1.489 + $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&mode=reports');
1.490 + }
1.491 + elseif ($action == 'delete' && strpos($user->data['session_page'], 'mode=pm_report_details') !== false)
1.492 + {
1.493 + $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&mode=pm_reports');
1.494 + }
1.495 + else if ($action == 'close' && !request_var('r', 0))
1.496 + {
1.497 + $redirect = request_var('redirect', build_url(array('mode', 'p', 'quickmod')) . '&mode=' . $module);
1.498 + }
1.499 + else
1.500 + {
1.501 + $redirect = request_var('redirect', build_url(array('quickmod')));
1.502 + }
1.503 + $success_msg = '';
1.504 + $forum_ids = array();
1.505 + $topic_ids = array();
1.506 +
1.507 + $s_hidden_fields = build_hidden_fields(array(
1.508 + 'i' => $module,
1.509 + 'mode' => $mode,
1.510 + 'report_id_list' => $report_id_list,
1.511 + 'action' => $action,
1.512 + 'redirect' => $redirect)
1.513 + );
1.514 +
1.515 + if (confirm_box(true))
1.516 + {
1.517 + $post_info = ($pm) ? get_pm_data($post_id_list) : get_post_data($post_id_list, 'm_report');
1.518 +
1.519 + $sql = "SELECT r.report_id, r.$id_column, r.report_closed, r.user_id, r.user_notify, u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type
1.520 + FROM " . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u
1.521 + WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . '
1.522 + ' . (($action == 'close') ? 'AND r.report_closed = 0' : '') . '
1.523 + AND r.user_id = u.user_id' . $pm_where;
1.524 + $result = $db->sql_query($sql);
1.525 +
1.526 + $reports = $close_report_posts = $close_report_topics = $notify_reporters = $report_id_list = array();
1.527 + while ($report = $db->sql_fetchrow($result))
1.528 + {
1.529 + $reports[$report['report_id']] = $report;
1.530 + $report_id_list[] = $report['report_id'];
1.531 +
1.532 + if (!$report['report_closed'])
1.533 + {
1.534 + $close_report_posts[] = $report[$id_column];
1.535 +
1.536 + if (!$pm)
1.537 + {
1.538 + $close_report_topics[] = $post_info[$report['post_id']]['topic_id'];
1.539 + }
1.540 + }
1.541 +
1.542 + if ($report['user_notify'] && !$report['report_closed'])
1.543 + {
1.544 + $notify_reporters[$report['report_id']] = &$reports[$report['report_id']];
1.545 + }
1.546 + }
1.547 + $db->sql_freeresult($result);
1.548 +
1.549 + if (sizeof($reports))
1.550 + {
1.551 + $close_report_posts = array_unique($close_report_posts);
1.552 + $close_report_topics = array_unique($close_report_topics);
1.553 +
1.554 + if (!$pm && sizeof($close_report_posts))
1.555 + {
1.556 + // Get a list of topics that still contain reported posts
1.557 + $sql = 'SELECT DISTINCT topic_id
1.558 + FROM ' . POSTS_TABLE . '
1.559 + WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
1.560 + AND post_reported = 1
1.561 + AND ' . $db->sql_in_set('post_id', $close_report_posts, true);
1.562 + $result = $db->sql_query($sql);
1.563 +
1.564 + $keep_report_topics = array();
1.565 + while ($row = $db->sql_fetchrow($result))
1.566 + {
1.567 + $keep_report_topics[] = $row['topic_id'];
1.568 + }
1.569 + $db->sql_freeresult($result);
1.570 +
1.571 + $close_report_topics = array_diff($close_report_topics, $keep_report_topics);
1.572 + unset($keep_report_topics);
1.573 + }
1.574 +
1.575 + $db->sql_transaction('begin');
1.576 +
1.577 + if ($action == 'close')
1.578 + {
1.579 + $sql = 'UPDATE ' . REPORTS_TABLE . '
1.580 + SET report_closed = 1
1.581 + WHERE ' . $db->sql_in_set('report_id', $report_id_list);
1.582 + }
1.583 + else
1.584 + {
1.585 + $sql = 'DELETE FROM ' . REPORTS_TABLE . '
1.586 + WHERE ' . $db->sql_in_set('report_id', $report_id_list);
1.587 + }
1.588 + $db->sql_query($sql);
1.589 +
1.590 +
1.591 + if (sizeof($close_report_posts))
1.592 + {
1.593 + if ($pm)
1.594 + {
1.595 + $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
1.596 + SET message_reported = 0
1.597 + WHERE ' . $db->sql_in_set('msg_id', $close_report_posts);
1.598 + $db->sql_query($sql);
1.599 +
1.600 + if ($action == 'delete')
1.601 + {
1.602 + delete_pm(ANONYMOUS, $close_report_posts, PRIVMSGS_INBOX);
1.603 + }
1.604 + }
1.605 + else
1.606 + {
1.607 + $sql = 'UPDATE ' . POSTS_TABLE . '
1.608 + SET post_reported = 0
1.609 + WHERE ' . $db->sql_in_set('post_id', $close_report_posts);
1.610 + $db->sql_query($sql);
1.611 +
1.612 + if (sizeof($close_report_topics))
1.613 + {
1.614 + $sql = 'UPDATE ' . TOPICS_TABLE . '
1.615 + SET topic_reported = 0
1.616 + WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
1.617 + OR ' . $db->sql_in_set('topic_moved_id', $close_report_topics);
1.618 + $db->sql_query($sql);
1.619 + }
1.620 + }
1.621 + }
1.622 +
1.623 + $db->sql_transaction('commit');
1.624 + }
1.625 + unset($close_report_posts, $close_report_topics);
1.626 +
1.627 + foreach ($reports as $report)
1.628 + {
1.629 + if ($pm)
1.630 + {
1.631 + add_log('mod', 0, 0, 'LOG_PM_REPORT_' . strtoupper($action) . 'D', $post_info[$report['pm_id']]['message_subject']);
1.632 + }
1.633 + else
1.634 + {
1.635 + add_log('mod', $post_info[$report['post_id']]['forum_id'], $post_info[$report['post_id']]['topic_id'], 'LOG_REPORT_' . strtoupper($action) . 'D', $post_info[$report['post_id']]['post_subject']);
1.636 + }
1.637 + }
1.638 +
1.639 + $messenger = new messenger();
1.640 +
1.641 + // Notify reporters
1.642 + if (sizeof($notify_reporters))
1.643 + {
1.644 + foreach ($notify_reporters as $report_id => $reporter)
1.645 + {
1.646 + if ($reporter['user_id'] == ANONYMOUS)
1.647 + {
1.648 + continue;
1.649 + }
1.650 +
1.651 + $post_id = $reporter[$id_column];
1.652 +
1.653 + $messenger->template((($pm) ? 'pm_report_' : 'report_') . $action . 'd', $reporter['user_lang']);
1.654 +
1.655 + $messenger->to($reporter['user_email'], $reporter['username']);
1.656 + $messenger->im($reporter['user_jabber'], $reporter['username']);
1.657 +
1.658 + if ($pm)
1.659 + {
1.660 + $messenger->assign_vars(array(
1.661 + 'USERNAME' => htmlspecialchars_decode($reporter['username']),
1.662 + 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']),
1.663 + 'PM_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['message_subject'])),
1.664 + ));
1.665 + }
1.666 + else
1.667 + {
1.668 + $messenger->assign_vars(array(
1.669 + 'USERNAME' => htmlspecialchars_decode($reporter['username']),
1.670 + 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']),
1.671 + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])),
1.672 + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title'])))
1.673 + );
1.674 + }
1.675 +
1.676 + $messenger->send($reporter['user_notify_type']);
1.677 + }
1.678 + }
1.679 +
1.680 + if (!$pm)
1.681 + {
1.682 + foreach ($post_info as $post)
1.683 + {
1.684 + $forum_ids[$post['forum_id']] = $post['forum_id'];
1.685 + $topic_ids[$post['topic_id']] = $post['topic_id'];
1.686 + }
1.687 + }
1.688 +
1.689 + unset($notify_reporters, $post_info, $reports);
1.690 +
1.691 + $messenger->save_queue();
1.692 +
1.693 + $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS';
1.694 + }
1.695 + else
1.696 + {
1.697 + confirm_box(false, $user->lang[strtoupper($action) . "_{$pm_prefix}REPORT" . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
1.698 + }
1.699 +
1.700 + $redirect = request_var('redirect', "index.$phpEx");
1.701 + $redirect = reapply_sid($redirect);
1.702 +
1.703 + if (!$success_msg)
1.704 + {
1.705 + redirect($redirect);
1.706 + }
1.707 + else
1.708 + {
1.709 + meta_refresh(3, $redirect);
1.710 +
1.711 + $return_forum = '';
1.712 + $return_topic = '';
1.713 +
1.714 + if (!$pm)
1.715 + {
1.716 + if (sizeof($forum_ids) === 1)
1.717 + {
1.718 + $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
1.719 + }
1.720 +
1.721 + if (sizeof($topic_ids) === 1)
1.722 + {
1.723 + $return_topic = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . current($topic_ids) . '&f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
1.724 + }
1.725 + }
1.726 +
1.727 + trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
1.728 + }
1.729 +}
1.730 +
1.731 +?>
1.732 \ No newline at end of file