Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
mcp_reports.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 /**
015 * @ignore
016 */
017 if (!defined('IN_PHPBB'))
018 {
019 exit;
020 }
021
022 /**
023 * mcp_reports
024 * Handling the reports queue
025 */
026 class mcp_reports
027 {
028 var $p_master;
029 var $u_action;
030
031 function mcp_reports(&$p_master)
032 {
033 $this->p_master = &$p_master;
034 }
035
036 function main($id, $mode)
037 {
038 global $auth, $db, $user, $template, $cache;
039 global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container, $phpbb_dispatcher;
040
041 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
042
043 $forum_id = request_var('f', 0);
044 $start = request_var('start', 0);
045
046 $this->page_title = 'MCP_REPORTS';
047
048 switch ($action)
049 {
050 case 'close':
051 case 'delete':
052 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
053
054 $report_id_list = request_var('report_id_list', array(0));
055
056 if (!sizeof($report_id_list))
057 {
058 trigger_error('NO_REPORT_SELECTED');
059 }
060
061 close_report($report_id_list, $mode, $action);
062
063 break;
064 }
065
066 switch ($mode)
067 {
068 case 'report_details':
069
070 $user->add_lang(array('posting', 'viewforum', 'viewtopic'));
071
072 $post_id = request_var('p', 0);
073
074 // closed reports are accessed by report id
075 $report_id = request_var('r', 0);
076
077 $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, r.reported_post_enable_magic_url, r.reported_post_enable_smilies, r.reported_post_enable_bbcode, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
078 FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
079 WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . '
080 AND rr.reason_id = r.reason_id
081 AND r.user_id = u.user_id
082 AND r.pm_id = 0
083 ORDER BY report_closed ASC';
084 $result = $db->sql_query_limit($sql, 1);
085 $report = $db->sql_fetchrow($result);
086 $db->sql_freeresult($result);
087
088 if (!$report)
089 {
090 trigger_error('NO_REPORT');
091 }
092
093 $phpbb_notifications = $phpbb_container->get('notification_manager');
094
095 $phpbb_notifications->mark_notifications_read('notification.type.report_post', $post_id, $user->data['user_id']);
096
097 if (!$report_id && $report['report_closed'])
098 {
099 trigger_error('REPORT_CLOSED');
100 }
101
102 $post_id = $report['post_id'];
103 $report_id = $report['report_id'];
104
105 $parse_post_flags = $report['reported_post_enable_bbcode'] ? OPTION_FLAG_BBCODE : 0;
106 $parse_post_flags += $report['reported_post_enable_smilies'] ? OPTION_FLAG_SMILIES : 0;
107 $parse_post_flags += $report['reported_post_enable_magic_url'] ? OPTION_FLAG_LINKS : 0;
108
109 $post_info = phpbb_get_post_data(array($post_id), 'm_report', true);
110
111 if (!sizeof($post_info))
112 {
113 trigger_error('NO_REPORT_SELECTED');
114 }
115
116 $post_info = $post_info[$post_id];
117
118 $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
119 if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
120 {
121 $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
122 $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
123 }
124
125 if (topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
126 {
127 $template->assign_vars(array(
128 'S_TOPIC_REVIEW' => true,
129 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'],
130 'TOPIC_TITLE' => $post_info['topic_title'],
131 'REPORTED_POST_ID' => $post_id,
132 ));
133 }
134
135 $topic_tracking_info = $extensions = $attachments = array();
136 // Get topic tracking info
137 if ($config['load_db_lastread'])
138 {
139 $tmp_topic_data = array($post_info['topic_id'] => $post_info);
140 $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']));
141 unset($tmp_topic_data);
142 }
143 else
144 {
145 $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
146 }
147
148 $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
149 $message = generate_text_for_display(
150 $report['reported_post_text'],
151 $report['reported_post_uid'],
152 $report['reported_post_bitfield'],
153 $parse_post_flags,
154 false
155 );
156
157 $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text']));
158
159 if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
160 {
161 $sql = 'SELECT *
162 FROM ' . ATTACHMENTS_TABLE . '
163 WHERE post_msg_id = ' . $post_id . '
164 AND in_message = 0
165 AND filetime <= ' . (int) $report['report_time'] . '
166 ORDER BY filetime DESC';
167 $result = $db->sql_query($sql);
168
169 while ($row = $db->sql_fetchrow($result))
170 {
171 $attachments[] = $row;
172 }
173 $db->sql_freeresult($result);
174
175 if (sizeof($attachments))
176 {
177 $update_count = array();
178 parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
179 }
180
181 // Display not already displayed Attachments for this post, we already parsed them. ;)
182 if (!empty($attachments))
183 {
184 $template->assign_var('S_HAS_ATTACHMENTS', true);
185
186 foreach ($attachments as $attachment)
187 {
188 $template->assign_block_vars('attachment', array(
189 'DISPLAY_ATTACHMENT' => $attachment)
190 );
191 }
192 }
193 }
194
195 $template->assign_vars(array(
196 'S_MCP_REPORT' => true,
197 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
198 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
199 'S_POST_REPORTED' => $post_info['post_reported'],
200 'S_POST_UNAPPROVED' => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE,
201 'S_POST_LOCKED' => $post_info['post_edit_locked'],
202 'S_REPORT_CLOSED' => $report['report_closed'],
203 'S_USER_NOTES' => true,
204
205 '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']}") : '',
206 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
207 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
208 'U_MCP_REPORTER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $report['user_id']),
209 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
210 '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']) : '',
211 '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']) : '',
212 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $post_info['forum_id']),
213 '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']),
214 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']),
215
216 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
217 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
218 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
219
220 '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>'),
221 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
222 'REPORT_DATE' => $user->format_date($report['report_time']),
223 'REPORT_ID' => $report_id,
224 'REPORT_REASON_TITLE' => $reason['title'],
225 'REPORT_REASON_DESCRIPTION' => $reason['description'],
226 'REPORT_TEXT' => $report['report_text'],
227
228 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
229 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
230 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
231 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
232
233 'REPORTER_FULL' => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
234 'REPORTER_COLOUR' => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
235 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
236 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
237
238 'POST_PREVIEW' => $message,
239 'POST_SUBJECT' => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'],
240 'POST_DATE' => $user->format_date($post_info['post_time']),
241 'POST_IP' => $post_info['poster_ip'],
242 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
243 'POST_ID' => $post_info['post_id'],
244
245 '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' : '',
246 ));
247
248 $this->tpl_name = 'mcp_post';
249
250 break;
251
252 case 'reports':
253 case 'reports_closed':
254 $topic_id = request_var('t', 0);
255
256 $forum_info = array();
257 $forum_list_reports = get_forum_list('m_report', false, true);
258 $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
259
260 // Remove forums we cannot read
261 foreach ($forum_list_reports as $k => $forum_data)
262 {
263 if (!isset($forum_list_read[$forum_data['forum_id']]))
264 {
265 unset($forum_list_reports[$k]);
266 }
267 }
268 unset($forum_list_read);
269
270 if ($topic_id)
271 {
272 $topic_info = phpbb_get_topic_data(array($topic_id));
273
274 if (!sizeof($topic_info))
275 {
276 trigger_error('TOPIC_NOT_EXIST');
277 }
278
279 if ($forum_id != $topic_info[$topic_id]['forum_id'])
280 {
281 $topic_id = 0;
282 }
283 else
284 {
285 $topic_info = $topic_info[$topic_id];
286 $forum_id = (int) $topic_info['forum_id'];
287 }
288 }
289
290 $forum_list = array();
291
292 if (!$forum_id)
293 {
294 foreach ($forum_list_reports as $row)
295 {
296 $forum_list[] = $row['forum_id'];
297 }
298
299 if (!sizeof($forum_list))
300 {
301 trigger_error('NOT_MODERATOR');
302 }
303
304 $global_id = $forum_list[0];
305
306 $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics
307 FROM ' . FORUMS_TABLE . '
308 WHERE ' . $db->sql_in_set('forum_id', $forum_list);
309 $result = $db->sql_query($sql);
310 $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics');
311 $db->sql_freeresult($result);
312 }
313 else
314 {
315 $forum_info = phpbb_get_forum_data(array($forum_id), 'm_report');
316
317 if (!sizeof($forum_info))
318 {
319 trigger_error('NOT_MODERATOR');
320 }
321
322 $forum_info = $forum_info[$forum_id];
323 $forum_list = array($forum_id);
324 }
325
326 $forum_list[] = 0;
327 $forum_data = array();
328 $pagination = $phpbb_container->get('pagination');
329
330 $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
331 foreach ($forum_list_reports as $row)
332 {
333 $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $row['padding']) . $row['forum_name'] . '</option>';
334 $forum_data[$row['forum_id']] = $row;
335 }
336 unset($forum_list_reports);
337
338 $sort_days = $total = 0;
339 $sort_key = $sort_dir = '';
340 $sort_by_sql = $sort_order_sql = array();
341 phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
342
343 $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total;
344 $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
345
346 if ($mode == 'reports')
347 {
348 $report_state = 'AND p.post_reported = 1 AND r.report_closed = 0';
349 }
350 else
351 {
352 $report_state = 'AND r.report_closed = 1';
353 }
354
355 $sql = 'SELECT r.report_id
356 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' : '') . '
357 WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . "
358 $report_state
359 AND r.post_id = p.post_id
360 " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
361 ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . '
362 ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
363 AND t.topic_id = p.topic_id
364 AND r.pm_id = 0
365 $limit_time_sql
366 ORDER BY $sort_order_sql";
367
368 /**
369 * Alter sql query to get report id of all reports for requested forum and topic or just forum
370 *
371 * @event core.mcp_reports_get_reports_query_before
372 * @var string sql String with the query to be executed
373 * @var array forum_list List of forums that contain the posts
374 * @var int topic_id topic_id in the page request
375 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string)
376 * @var string sort_order_sql String with the ORDER BY SQL code used in this query
377 * @since 3.1.0-RC4
378 */
379 $vars = array(
380 'sql',
381 'forum_list',
382 'topic_id',
383 'limit_time_sql',
384 'sort_order_sql',
385 );
386 extract($phpbb_dispatcher->trigger_event('core.mcp_reports_get_reports_query_before', compact($vars)));
387
388 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
389
390 $i = 0;
391 $report_ids = array();
392 while ($row = $db->sql_fetchrow($result))
393 {
394 $report_ids[] = $row['report_id'];
395 $row_num[$row['report_id']] = $i++;
396 }
397 $db->sql_freeresult($result);
398
399 if (sizeof($report_ids))
400 {
401 $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, p.post_attachment, 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
402 FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
403 WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . '
404 AND t.topic_id = p.topic_id
405 AND r.post_id = p.post_id
406 AND u.user_id = p.poster_id
407 AND ru.user_id = r.user_id
408 AND r.pm_id = 0
409 ORDER BY ' . $sort_order_sql;
410 $result = $db->sql_query($sql);
411
412 $report_data = $rowset = array();
413 while ($row = $db->sql_fetchrow($result))
414 {
415 $template->assign_block_vars('postrow', array(
416 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
417 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . '#p' . $row['post_id'],
418 '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']}"),
419
420 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
421 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
422 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
423 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
424
425 'REPORTER_FULL' => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
426 'REPORTER_COLOUR' => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
427 'REPORTER' => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
428 'U_REPORTER' => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
429
430 'FORUM_NAME' => $forum_data[$row['forum_id']]['forum_name'],
431 'POST_ID' => $row['post_id'],
432 'POST_SUBJECT' => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
433 'POST_TIME' => $user->format_date($row['post_time']),
434 'REPORT_ID' => $row['report_id'],
435 'REPORT_TIME' => $user->format_date($row['report_time']),
436 'TOPIC_TITLE' => $row['topic_title'],
437 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
438 ));
439 }
440 $db->sql_freeresult($result);
441 unset($report_ids, $row);
442 }
443
444 $base_url = $this->u_action . "&f=$forum_id&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir";
445 $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
446
447 // Now display the page
448 $template->assign_vars(array(
449 'L_EXPLAIN' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'],
450 'L_TITLE' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN'] : $user->lang['MCP_REPORTS_CLOSED'],
451 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
452
453 'S_MCP_ACTION' => $this->u_action,
454 'S_FORUM_OPTIONS' => $forum_options,
455 'S_CLOSED' => ($mode == 'reports_closed') ? true : false,
456
457 'TOPIC_ID' => $topic_id,
458 'TOTAL' => $total,
459 'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $total),
460 )
461 );
462
463 $this->tpl_name = 'mcp_reports';
464 break;
465 }
466 }
467 }
468
469 /**
470 * Closes a report
471 */
472 function close_report($report_id_list, $mode, $action, $pm = false)
473 {
474 global $db, $template, $user, $config, $auth;
475 global $phpEx, $phpbb_root_path, $phpbb_container;
476
477 $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 ';
478 $id_column = ($pm) ? 'pm_id' : 'post_id';
479 $module = ($pm) ? 'pm_reports' : 'reports';
480 $pm_prefix = ($pm) ? 'PM_' : '';
481
482 $sql = "SELECT r.$id_column
483 FROM " . REPORTS_TABLE . ' r
484 WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . $pm_where;
485 $result = $db->sql_query($sql);
486
487 $post_id_list = array();
488 while ($row = $db->sql_fetchrow($result))
489 {
490 $post_id_list[] = $row[$id_column];
491 }
492 $post_id_list = array_unique($post_id_list);
493
494 if ($pm)
495 {
496 if (!$auth->acl_getf_global('m_report'))
497 {
498 trigger_error('NOT_AUTHORISED');
499 }
500 }
501 else
502 {
503 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
504 {
505 trigger_error('NOT_AUTHORISED');
506 }
507 }
508
509 if ($action == 'delete' && strpos($user->data['session_page'], 'mode=report_details') !== false)
510 {
511 $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&mode=reports');
512 }
513 else if ($action == 'delete' && strpos($user->data['session_page'], 'mode=pm_report_details') !== false)
514 {
515 $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&mode=pm_reports');
516 }
517 else if ($action == 'close' && !request_var('r', 0))
518 {
519 $redirect = request_var('redirect', build_url(array('mode', 'p', 'quickmod')) . '&mode=' . $module);
520 }
521 else
522 {
523 $redirect = request_var('redirect', build_url(array('quickmod')));
524 }
525 $success_msg = '';
526 $forum_ids = array();
527 $topic_ids = array();
528
529 $s_hidden_fields = build_hidden_fields(array(
530 'i' => $module,
531 'mode' => $mode,
532 'report_id_list' => $report_id_list,
533 'action' => $action,
534 'redirect' => $redirect)
535 );
536
537 if (confirm_box(true))
538 {
539 $post_info = ($pm) ? phpbb_get_pm_data($post_id_list) : phpbb_get_post_data($post_id_list, 'm_report');
540
541 $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
542 FROM " . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u
543 WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . '
544 ' . (($action == 'close') ? 'AND r.report_closed = 0' : '') . '
545 AND r.user_id = u.user_id' . $pm_where;
546 $result = $db->sql_query($sql);
547
548 $reports = $close_report_posts = $close_report_topics = $notify_reporters = $report_id_list = array();
549 while ($report = $db->sql_fetchrow($result))
550 {
551 $reports[$report['report_id']] = $report;
552 $report_id_list[] = $report['report_id'];
553
554 if (!$report['report_closed'])
555 {
556 $close_report_posts[] = $report[$id_column];
557
558 if (!$pm)
559 {
560 $close_report_topics[] = $post_info[$report['post_id']]['topic_id'];
561 }
562 }
563
564 if ($report['user_notify'] && !$report['report_closed'])
565 {
566 $notify_reporters[$report['report_id']] = &$reports[$report['report_id']];
567 }
568 }
569 $db->sql_freeresult($result);
570
571 if (sizeof($reports))
572 {
573 $close_report_posts = array_unique($close_report_posts);
574 $close_report_topics = array_unique($close_report_topics);
575
576 if (!$pm && sizeof($close_report_posts))
577 {
578 // Get a list of topics that still contain reported posts
579 $sql = 'SELECT DISTINCT topic_id
580 FROM ' . POSTS_TABLE . '
581 WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
582 AND post_reported = 1
583 AND ' . $db->sql_in_set('post_id', $close_report_posts, true);
584 $result = $db->sql_query($sql);
585
586 $keep_report_topics = array();
587 while ($row = $db->sql_fetchrow($result))
588 {
589 $keep_report_topics[] = $row['topic_id'];
590 }
591 $db->sql_freeresult($result);
592
593 $close_report_topics = array_diff($close_report_topics, $keep_report_topics);
594 unset($keep_report_topics);
595 }
596
597 $db->sql_transaction('begin');
598
599 if ($action == 'close')
600 {
601 $sql = 'UPDATE ' . REPORTS_TABLE . '
602 SET report_closed = 1
603 WHERE ' . $db->sql_in_set('report_id', $report_id_list);
604 }
605 else
606 {
607 $sql = 'DELETE FROM ' . REPORTS_TABLE . '
608 WHERE ' . $db->sql_in_set('report_id', $report_id_list);
609 }
610 $db->sql_query($sql);
611
612 if (sizeof($close_report_posts))
613 {
614 if ($pm)
615 {
616 $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
617 SET message_reported = 0
618 WHERE ' . $db->sql_in_set('msg_id', $close_report_posts);
619 $db->sql_query($sql);
620
621 if ($action == 'delete')
622 {
623 delete_pm(ANONYMOUS, $close_report_posts, PRIVMSGS_INBOX);
624 }
625 }
626 else
627 {
628 $sql = 'UPDATE ' . POSTS_TABLE . '
629 SET post_reported = 0
630 WHERE ' . $db->sql_in_set('post_id', $close_report_posts);
631 $db->sql_query($sql);
632
633 if (sizeof($close_report_topics))
634 {
635 $sql = 'UPDATE ' . TOPICS_TABLE . '
636 SET topic_reported = 0
637 WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
638 OR ' . $db->sql_in_set('topic_moved_id', $close_report_topics);
639 $db->sql_query($sql);
640 }
641 }
642 }
643
644 $db->sql_transaction('commit');
645 }
646 unset($close_report_posts, $close_report_topics);
647
648 $phpbb_notifications = $phpbb_container->get('notification_manager');
649
650 foreach ($reports as $report)
651 {
652 if ($pm)
653 {
654 add_log('mod', 0, 0, 'LOG_PM_REPORT_' . strtoupper($action) . 'D', $post_info[$report['pm_id']]['message_subject']);
655 $phpbb_notifications->delete_notifications('notification.type.report_pm', $report['pm_id']);
656 }
657 else
658 {
659 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']);
660 $phpbb_notifications->delete_notifications('notification.type.report_post', $report['post_id']);
661 }
662 }
663
664 // Notify reporters
665 if (sizeof($notify_reporters))
666 {
667 foreach ($notify_reporters as $report_id => $reporter)
668 {
669 if ($reporter['user_id'] == ANONYMOUS)
670 {
671 continue;
672 }
673
674 $post_id = $reporter[$id_column];
675
676 if ($pm)
677 {
678 $phpbb_notifications->add_notifications('notification.type.report_pm_closed', array_merge($post_info[$post_id], array(
679 'reporter' => $reporter['user_id'],
680 'closer_id' => $user->data['user_id'],
681 'from_user_id' => $post_info[$post_id]['author_id'],
682 )));
683 }
684 else
685 {
686 $phpbb_notifications->add_notifications('notification.type.report_post_closed', array_merge($post_info[$post_id], array(
687 'reporter' => $reporter['user_id'],
688 'closer_id' => $user->data['user_id'],
689 )));
690 }
691 }
692 }
693
694 if (!$pm)
695 {
696 foreach ($post_info as $post)
697 {
698 $forum_ids[$post['forum_id']] = $post['forum_id'];
699 $topic_ids[$post['topic_id']] = $post['topic_id'];
700 }
701 }
702
703 unset($notify_reporters, $post_info, $reports);
704
705 $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS';
706 }
707 else
708 {
709 confirm_box(false, $user->lang[strtoupper($action) . "_{$pm_prefix}REPORT" . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
710 }
711
712 $redirect = request_var('redirect', "index.$phpEx");
713 $redirect = reapply_sid($redirect);
714
715 if (!$success_msg)
716 {
717 redirect($redirect);
718 }
719 else
720 {
721 meta_refresh(3, $redirect);
722
723 $return_forum = '';
724 $return_topic = '';
725
726 if (!$pm)
727 {
728 if (sizeof($forum_ids) === 1)
729 {
730 $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
731 }
732
733 if (sizeof($topic_ids) === 1)
734 {
735 $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 />';
736 }
737 }
738
739 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
740 }
741 }
742