Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

mcp_reports.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 29.41 KiB


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