[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/includes/mcp/ -> mcp_reports.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  /**
  15  * @ignore
  16  */
  17  if (!defined('IN_PHPBB'))
  18  {
  19      exit;
  20  }
  21  
  22  /**
  23  * mcp_reports
  24  * Handling the reports queue
  25  */
  26  class mcp_reports
  27  {
  28      var $p_master;
  29      var $u_action;
  30  
  31  	function mcp_reports(&$p_master)
  32      {
  33          $this->p_master = &$p_master;
  34      }
  35  
  36  	function main($id, $mode)
  37      {
  38          global $auth, $db, $user, $template, $cache;
  39          global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container, $phpbb_dispatcher;
  40  
  41          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  42  
  43          $forum_id = request_var('f', 0);
  44          $start = request_var('start', 0);
  45  
  46          $this->page_title = 'MCP_REPORTS';
  47  
  48          switch ($action)
  49          {
  50              case 'close':
  51              case 'delete':
  52                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  53  
  54                  $report_id_list = request_var('report_id_list', array(0));
  55  
  56                  if (!sizeof($report_id_list))
  57                  {
  58                      trigger_error('NO_REPORT_SELECTED');
  59                  }
  60  
  61                  close_report($report_id_list, $mode, $action);
  62  
  63              break;
  64          }
  65  
  66          switch ($mode)
  67          {
  68              case 'report_details':
  69  
  70                  $user->add_lang(array('posting', 'viewforum', 'viewtopic'));
  71  
  72                  $post_id = request_var('p', 0);
  73  
  74                  // closed reports are accessed by report id
  75                  $report_id = request_var('r', 0);
  76                  $sql_ary = array(
  77                      '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',
  78  
  79                      'FROM'        => array(
  80                          REPORTS_TABLE            => 'r',
  81                          REPORTS_REASONS_TABLE    => 'rr',
  82                          USERS_TABLE                => 'u',
  83                      ),
  84  
  85                      'WHERE'        => (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . '
  86                          AND rr.reason_id = r.reason_id
  87                          AND r.user_id = u.user_id
  88                          AND r.pm_id = 0',
  89  
  90                      'ORDER_BY'    => 'report_closed ASC',
  91                  );
  92  
  93                  /**
  94                  * Allow changing the query to obtain the user-submitted report.
  95                  *
  96                  * @event core.mcp_reports_report_details_query_before
  97                  * @var    array    sql_ary            The array in the format of the query builder with the query
  98                  * @var    int        forum_id        The forum_id, the number in the f GET parameter
  99                  * @var    int        post_id            The post_id of the report being viewed (if 0, it is meaningless)
 100                  * @var    int        report_id        The report_id of the report being viewed
 101                  * @since 3.1.5-RC1
 102                  */
 103                  $vars = array(
 104                      'sql_ary',
 105                      'forum_id',
 106                      'post_id',
 107                      'report_id',
 108                  );
 109                  extract($phpbb_dispatcher->trigger_event('core.mcp_reports_report_details_query_before', compact($vars)));
 110  
 111                  $sql = $db->sql_build_query('SELECT', $sql_ary);
 112                  $result = $db->sql_query_limit($sql, 1);
 113                  $report = $db->sql_fetchrow($result);
 114                  $db->sql_freeresult($result);
 115  
 116                  /**
 117                  * Allow changing the data obtained from the user-submitted report.
 118                  *
 119                  * @event core.mcp_reports_report_details_query_after
 120                  * @var    array    sql_ary        The array in the format of the query builder with the query that had been executted
 121                  * @var    int        forum_id    The forum_id, the number in the f GET parameter
 122                  * @var    int        post_id        The post_id of the report being viewed (if 0, it is meaningless)
 123                  * @var    int        report_id    The report_id of the report being viewed
 124                  * @var    array    report        The query's resulting row.
 125                  * @since 3.1.5-RC1
 126                  */
 127                  $vars = array(
 128                      'sql_ary',
 129                      'forum_id',
 130                      'post_id',
 131                      'report_id',
 132                      'report',
 133                  );
 134                  extract($phpbb_dispatcher->trigger_event('core.mcp_reports_report_details_query_after', compact($vars)));
 135  
 136                  if (!$report)
 137                  {
 138                      trigger_error('NO_REPORT');
 139                  }
 140  
 141                  $phpbb_notifications = $phpbb_container->get('notification_manager');
 142  
 143                  $phpbb_notifications->mark_notifications_read('notification.type.report_post', $post_id, $user->data['user_id']);
 144  
 145                  if (!$report_id && $report['report_closed'])
 146                  {
 147                      trigger_error('REPORT_CLOSED');
 148                  }
 149  
 150                  $post_id = $report['post_id'];
 151                  $report_id = $report['report_id'];
 152  
 153                  $parse_post_flags = $report['reported_post_enable_bbcode'] ? OPTION_FLAG_BBCODE : 0;
 154                  $parse_post_flags += $report['reported_post_enable_smilies'] ? OPTION_FLAG_SMILIES : 0;
 155                  $parse_post_flags += $report['reported_post_enable_magic_url'] ? OPTION_FLAG_LINKS : 0;
 156  
 157                  $post_info = phpbb_get_post_data(array($post_id), 'm_report', true);
 158  
 159                  if (!sizeof($post_info))
 160                  {
 161                      trigger_error('NO_REPORT_SELECTED');
 162                  }
 163  
 164                  $post_info = $post_info[$post_id];
 165  
 166                  $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
 167                  if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
 168                  {
 169                      $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
 170                      $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
 171                  }
 172  
 173                  if (topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
 174                  {
 175                      $template->assign_vars(array(
 176                          'S_TOPIC_REVIEW'    => true,
 177                          'S_BBCODE_ALLOWED'    => $post_info['enable_bbcode'],
 178                          'TOPIC_TITLE'        => $post_info['topic_title'],
 179                          'REPORTED_POST_ID'    => $post_id,
 180                      ));
 181                  }
 182  
 183                  $topic_tracking_info = $extensions = $attachments = array();
 184                  // Get topic tracking info
 185                  if ($config['load_db_lastread'])
 186                  {
 187                      $tmp_topic_data = array($post_info['topic_id'] => $post_info);
 188                      $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']));
 189                      unset($tmp_topic_data);
 190                  }
 191                  else
 192                  {
 193                      $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
 194                  }
 195  
 196                  $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
 197                  $message = generate_text_for_display(
 198                      $report['reported_post_text'],
 199                      $report['reported_post_uid'],
 200                      $report['reported_post_bitfield'],
 201                      $parse_post_flags,
 202                      false
 203                  );
 204  
 205                  $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text']));
 206  
 207                  if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
 208                  {
 209                      $sql = 'SELECT *
 210                          FROM ' . ATTACHMENTS_TABLE . '
 211                          WHERE post_msg_id = ' . $post_id . '
 212                              AND in_message = 0
 213                              AND filetime <= ' . (int) $report['report_time'] . '
 214                          ORDER BY filetime DESC';
 215                      $result = $db->sql_query($sql);
 216  
 217                      while ($row = $db->sql_fetchrow($result))
 218                      {
 219                          $attachments[] = $row;
 220                      }
 221                      $db->sql_freeresult($result);
 222  
 223                      if (sizeof($attachments))
 224                      {
 225                          $update_count = array();
 226                          parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
 227                      }
 228  
 229                      // Display not already displayed Attachments for this post, we already parsed them. ;)
 230                      if (!empty($attachments))
 231                      {
 232                          $template->assign_var('S_HAS_ATTACHMENTS', true);
 233  
 234                          foreach ($attachments as $attachment)
 235                          {
 236                              $template->assign_block_vars('attachment', array(
 237                                  'DISPLAY_ATTACHMENT'    => $attachment)
 238                              );
 239                          }
 240                      }
 241                  }
 242  
 243                  $template->assign_vars(array(
 244                      'S_MCP_REPORT'            => true,
 245                      '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),
 246                      'S_CAN_VIEWIP'            => $auth->acl_get('m_info', $post_info['forum_id']),
 247                      'S_POST_REPORTED'        => $post_info['post_reported'],
 248                      'S_POST_UNAPPROVED'        => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE,
 249                      'S_POST_LOCKED'            => $post_info['post_edit_locked'],
 250                      'S_REPORT_CLOSED'        => $report['report_closed'],
 251                      'S_USER_NOTES'            => true,
 252  
 253                      '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']}") : '',
 254                      '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),
 255                      '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),
 256                      'U_MCP_REPORTER_NOTES'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $report['user_id']),
 257                      'U_MCP_USER_NOTES'            => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
 258                      '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']) : '',
 259                      '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']) : '',
 260                      'U_VIEW_FORUM'                => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $post_info['forum_id']),
 261                      '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']),
 262                      'U_VIEW_TOPIC'                => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
 263  
 264                      'EDIT_IMG'                => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
 265                      'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
 266                      'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
 267  
 268                      '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>'),
 269                      'REPORTED_IMG'                => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
 270                      'REPORT_DATE'                => $user->format_date($report['report_time']),
 271                      'REPORT_ID'                    => $report_id,
 272                      'REPORT_REASON_TITLE'        => $reason['title'],
 273                      'REPORT_REASON_DESCRIPTION'    => $reason['description'],
 274                      'REPORT_TEXT'                => $report['report_text'],
 275  
 276                      'POST_AUTHOR_FULL'        => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 277                      'POST_AUTHOR_COLOUR'    => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 278                      'POST_AUTHOR'            => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 279                      'U_POST_AUTHOR'            => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
 280  
 281                      'REPORTER_FULL'                => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
 282                      'REPORTER_COLOUR'            => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
 283                      'REPORTER_NAME'                => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
 284                      'U_VIEW_REPORTER_PROFILE'    => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
 285  
 286                      'POST_PREVIEW'            => $message,
 287                      'POST_SUBJECT'            => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'],
 288                      'POST_DATE'                => $user->format_date($post_info['post_time']),
 289                      'POST_IP'                => $post_info['poster_ip'],
 290                      'POST_IPADDR'            => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
 291                      'POST_ID'                => $post_info['post_id'],
 292  
 293                      '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' : '',
 294                  ));
 295  
 296                  $this->tpl_name = 'mcp_post';
 297  
 298              break;
 299  
 300              case 'reports':
 301              case 'reports_closed':
 302                  $topic_id = request_var('t', 0);
 303  
 304                  $forum_info = array();
 305                  $forum_list_reports = get_forum_list('m_report', false, true);
 306                  $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
 307  
 308                  // Remove forums we cannot read
 309                  foreach ($forum_list_reports as $k => $forum_data)
 310                  {
 311                      if (!isset($forum_list_read[$forum_data['forum_id']]))
 312                      {
 313                          unset($forum_list_reports[$k]);
 314                      }
 315                  }
 316                  unset($forum_list_read);
 317  
 318                  if ($topic_id)
 319                  {
 320                      $topic_info = phpbb_get_topic_data(array($topic_id));
 321  
 322                      if (!sizeof($topic_info))
 323                      {
 324                          trigger_error('TOPIC_NOT_EXIST');
 325                      }
 326  
 327                      if ($forum_id != $topic_info[$topic_id]['forum_id'])
 328                      {
 329                          $topic_id = 0;
 330                      }
 331                      else
 332                      {
 333                          $topic_info = $topic_info[$topic_id];
 334                          $forum_id = (int) $topic_info['forum_id'];
 335                      }
 336                  }
 337  
 338                  $forum_list = array();
 339  
 340                  if (!$forum_id)
 341                  {
 342                      foreach ($forum_list_reports as $row)
 343                      {
 344                          $forum_list[] = $row['forum_id'];
 345                      }
 346  
 347                      if (!sizeof($forum_list))
 348                      {
 349                          trigger_error('NOT_MODERATOR');
 350                      }
 351  
 352                      $global_id = $forum_list[0];
 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_info = $forum_info[$forum_id];
 371                      $forum_list = array($forum_id);
 372                  }
 373  
 374                  $forum_list[] = 0;
 375                  $forum_data = array();
 376                  $pagination = $phpbb_container->get('pagination');
 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                  $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total;
 392                  $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
 393  
 394                  if ($mode == 'reports')
 395                  {
 396                      $report_state = 'AND p.post_reported = 1 AND r.report_closed = 0';
 397                  }
 398                  else
 399                  {
 400                      $report_state = 'AND r.report_closed = 1';
 401                  }
 402  
 403                  $sql = 'SELECT r.report_id
 404                      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' : '') . '
 405                      WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . "
 406                          $report_state
 407                          AND r.post_id = p.post_id
 408                          " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
 409                          ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . '
 410                          ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
 411                          AND t.topic_id = p.topic_id
 412                          AND r.pm_id = 0
 413                          $limit_time_sql
 414                      ORDER BY $sort_order_sql";
 415  
 416                  /**
 417                  * Alter sql query to get report id of all reports for requested forum and topic or just forum
 418                  *
 419                  * @event core.mcp_reports_get_reports_query_before
 420                  * @var    string    sql                        String with the query to be executed
 421                  * @var    array    forum_list                List of forums that contain the posts
 422                  * @var    int        topic_id                topic_id in the page request
 423                  * @var    string    limit_time_sql            String with the SQL code to limit the time interval of the post (Note: May be empty string)
 424                  * @var    string    sort_order_sql            String with the ORDER BY SQL code used in this query
 425                  * @since 3.1.0-RC4
 426                  */
 427                  $vars = array(
 428                      'sql',
 429                      'forum_list',
 430                      'topic_id',
 431                      'limit_time_sql',
 432                      'sort_order_sql',
 433                  );
 434                  extract($phpbb_dispatcher->trigger_event('core.mcp_reports_get_reports_query_before', compact($vars)));
 435  
 436                  $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 437  
 438                  $i = 0;
 439                  $report_ids = array();
 440                  while ($row = $db->sql_fetchrow($result))
 441                  {
 442                      $report_ids[] = $row['report_id'];
 443                      $row_num[$row['report_id']] = $i++;
 444                  }
 445                  $db->sql_freeresult($result);
 446  
 447                  if (sizeof($report_ids))
 448                  {
 449                      $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
 450                          FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
 451                          WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . '
 452                              AND t.topic_id = p.topic_id
 453                              AND r.post_id = p.post_id
 454                              AND u.user_id = p.poster_id
 455                              AND ru.user_id = r.user_id
 456                              AND r.pm_id = 0
 457                          ORDER BY ' . $sort_order_sql;
 458                      $result = $db->sql_query($sql);
 459  
 460                      $report_data = $rowset = array();
 461                      while ($row = $db->sql_fetchrow($result))
 462                      {
 463                          $template->assign_block_vars('postrow', array(
 464                              'U_VIEWFORUM'                => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
 465                              'U_VIEWPOST'                => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']) . '#p' . $row['post_id'],
 466                              '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']}"),
 467  
 468                              'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 469                              'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 470                              'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 471                              'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
 472  
 473                              'REPORTER_FULL'            => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
 474                              'REPORTER_COLOUR'        => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
 475                              'REPORTER'                => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
 476                              'U_REPORTER'            => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
 477  
 478                              'FORUM_NAME'    => $forum_data[$row['forum_id']]['forum_name'],
 479                              'POST_ID'        => $row['post_id'],
 480                              'POST_SUBJECT'    => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
 481                              'POST_TIME'        => $user->format_date($row['post_time']),
 482                              'REPORT_ID'        => $row['report_id'],
 483                              'REPORT_TIME'    => $user->format_date($row['report_time']),
 484                              'TOPIC_TITLE'    => $row['topic_title'],
 485                              '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']) : '',
 486                          ));
 487                      }
 488                      $db->sql_freeresult($result);
 489                      unset($report_ids, $row);
 490                  }
 491  
 492                  $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";
 493                  $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
 494  
 495                  // Now display the page
 496                  $template->assign_vars(array(
 497                      'L_EXPLAIN'                => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'],
 498                      'L_TITLE'                => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN'] : $user->lang['MCP_REPORTS_CLOSED'],
 499                      'L_ONLY_TOPIC'            => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
 500  
 501                      'S_MCP_ACTION'            => $this->u_action,
 502                      'S_FORUM_OPTIONS'        => $forum_options,
 503                      'S_CLOSED'                => ($mode == 'reports_closed') ? true : false,
 504  
 505                      'TOPIC_ID'                => $topic_id,
 506                      'TOTAL'                    => $total,
 507                      'TOTAL_REPORTS'            => $user->lang('LIST_REPORTS', (int) $total),
 508                      )
 509                  );
 510  
 511                  $this->tpl_name = 'mcp_reports';
 512              break;
 513          }
 514      }
 515  }
 516  
 517  /**
 518  * Closes a report
 519  */
 520  function close_report($report_id_list, $mode, $action, $pm = false)
 521  {
 522      global $db, $template, $user, $config, $auth;
 523      global $phpEx, $phpbb_root_path, $phpbb_container;
 524  
 525      $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 ';
 526      $id_column = ($pm) ? 'pm_id' : 'post_id';
 527      $module = ($pm) ? 'pm_reports' : 'reports';
 528      $pm_prefix = ($pm) ? 'PM_' : '';
 529  
 530      $sql = "SELECT r.$id_column
 531          FROM " . REPORTS_TABLE . ' r
 532          WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . $pm_where;
 533      $result = $db->sql_query($sql);
 534  
 535      $post_id_list = array();
 536      while ($row = $db->sql_fetchrow($result))
 537      {
 538          $post_id_list[] = $row[$id_column];
 539      }
 540      $db->sql_freeresult($result);
 541      $post_id_list = array_unique($post_id_list);
 542  
 543      if ($pm)
 544      {
 545          if (!$auth->acl_getf_global('m_report'))
 546          {
 547              trigger_error('NOT_AUTHORISED');
 548          }
 549      }
 550      else
 551      {
 552          if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
 553          {
 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_var('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_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&amp;mode=pm_reports');
 565      }
 566      else if ($action == 'close' && !request_var('r', 0))
 567      {
 568          $redirect = request_var('redirect', build_url(array('mode', 'p', 'quickmod')) . '&amp;mode=' . $module);
 569      }
 570      else
 571      {
 572          $redirect = request_var('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          $phpbb_notifications = $phpbb_container->get('notification_manager');
 698  
 699          foreach ($reports as $report)
 700          {
 701              if ($pm)
 702              {
 703                  add_log('mod', 0, 0, 'LOG_PM_REPORT_' .  strtoupper($action) . 'D', $post_info[$report['pm_id']]['message_subject']);
 704                  $phpbb_notifications->delete_notifications('notification.type.report_pm', $report['pm_id']);
 705              }
 706              else
 707              {
 708                  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']);
 709                  $phpbb_notifications->delete_notifications('notification.type.report_post', $report['post_id']);
 710              }
 711          }
 712  
 713          // Notify reporters
 714          if (sizeof($notify_reporters))
 715          {
 716              foreach ($notify_reporters as $report_id => $reporter)
 717              {
 718                  if ($reporter['user_id'] == ANONYMOUS)
 719                  {
 720                      continue;
 721                  }
 722  
 723                  $post_id = $reporter[$id_column];
 724  
 725                  if ($pm)
 726                  {
 727                      $phpbb_notifications->add_notifications('notification.type.report_pm_closed', array_merge($post_info[$post_id], array(
 728                          'reporter'            => $reporter['user_id'],
 729                          'closer_id'            => $user->data['user_id'],
 730                          'from_user_id'        => $post_info[$post_id]['author_id'],
 731                      )));
 732                  }
 733                  else
 734                  {
 735                      $phpbb_notifications->add_notifications('notification.type.report_post_closed', array_merge($post_info[$post_id], array(
 736                          'reporter'            => $reporter['user_id'],
 737                          'closer_id'            => $user->data['user_id'],
 738                      )));
 739                  }
 740              }
 741          }
 742  
 743          if (!$pm)
 744          {
 745              foreach ($post_info as $post)
 746              {
 747                  $forum_ids[$post['forum_id']] = $post['forum_id'];
 748                  $topic_ids[$post['topic_id']] = $post['topic_id'];
 749              }
 750          }
 751  
 752          unset($notify_reporters, $post_info, $reports);
 753  
 754          $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS';
 755      }
 756      else
 757      {
 758          confirm_box(false, $user->lang[strtoupper($action) . "_{$pm_prefix}REPORT" . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
 759      }
 760  
 761      $redirect = request_var('redirect', "index.$phpEx");
 762      $redirect = reapply_sid($redirect);
 763  
 764      if (!$success_msg)
 765      {
 766          redirect($redirect);
 767      }
 768      else
 769      {
 770          meta_refresh(3, $redirect);
 771  
 772          $return_forum = '';
 773          $return_topic = '';
 774  
 775          if (!$pm)
 776          {
 777              if (sizeof($forum_ids) === 1)
 778              {
 779                  $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
 780              }
 781  
 782              if (sizeof($topic_ids) === 1)
 783              {
 784                  $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 />';
 785              }
 786          }
 787  
 788          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
 789      }
 790  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1