Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

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:51 - Dateigröße: 23.80 KiB


001  <?php
002  /**
003  *
004  * @package mcp
005  * @version $Id$
006  * @copyright (c) 2005 phpBB Group
007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
008  *
009  */
010   
011  /**
012  * @ignore
013  */
014  if (!defined('IN_PHPBB'))
015  {
016      exit;
017  }
018   
019  /**
020  * mcp_reports
021  * Handling the reports queue
022  * @package mcp
023  */
024  class mcp_reports
025  {
026      var $p_master;
027      var $u_action;
028   
029      function mcp_reports(&$p_master)
030      {
031          $this->p_master = &$p_master;
032      }
033   
034      function main($id, $mode)
035      {
036          global $auth, $db, $user, $template, $cache;
037          global $config, $phpbb_root_path, $phpEx, $action;
038   
039          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
040   
041          $forum_id = request_var('f', 0);
042          $start = request_var('start', 0);
043   
044          $this->page_title = 'MCP_REPORTS';
045   
046          switch ($action)
047          {
048              case 'close':
049              case 'delete':
050                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
051   
052                  $report_id_list = request_var('report_id_list', array(0));
053   
054                  if (!sizeof($report_id_list))
055                  {
056                      trigger_error('NO_REPORT_SELECTED');
057                  }
058   
059                  close_report($report_id_list, $mode, $action);
060   
061              break;
062          }
063   
064          switch ($mode)
065          {
066              case 'report_details':
067   
068                  $user->add_lang('posting');
069   
070                  $post_id = request_var('p', 0);
071   
072                  // closed reports are accessed by report id
073                  $report_id = request_var('r', 0);
074   
075                  $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
076                      FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
077                      WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . '
078                          AND rr.reason_id = r.reason_id
079                          AND r.user_id = u.user_id
080                      ORDER BY report_closed ASC';
081                  $result = $db->sql_query_limit($sql, 1);
082                  $report = $db->sql_fetchrow($result);
083                  $db->sql_freeresult($result);
084   
085                  if (!$report)
086                  {
087                      trigger_error('NO_REPORT');
088                  }
089   
090                  if (!$report_id && $report['report_closed'])
091                  {
092                      trigger_error('REPORT_CLOSED');
093                  }
094   
095                  $post_id = $report['post_id'];
096                  $report_id = $report['report_id'];
097   
098                  $post_info = get_post_data(array($post_id), 'm_report', true);
099   
100                  if (!sizeof($post_info))
101                  {
102                      trigger_error('NO_REPORT_SELECTED');
103                  }
104   
105                  $post_info = $post_info[$post_id];
106   
107                  $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
108                  if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
109                  {
110                      $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
111                      $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
112                  }
113   
114                  if (topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
115                  {
116                      $template->assign_vars(array(
117                          'S_TOPIC_REVIEW'    => true,
118                          'TOPIC_TITLE'        => $post_info['topic_title'])
119                      );
120                  }
121   
122                  $topic_tracking_info = $extensions = $attachments = array();
123                  // Get topic tracking info
124                  if ($config['load_db_lastread'])
125                  {
126                      $tmp_topic_data = array($post_info['topic_id'] => $post_info);
127                      $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']));
128                      unset($tmp_topic_data);
129                  }
130                  else
131                  {
132                      $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
133                  }
134   
135                  $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
136   
137                  // Process message, leave it uncensored
138                  $message = $post_info['post_text'];
139   
140                  if ($post_info['bbcode_bitfield'])
141                  {
142                      include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
143                      $bbcode = new bbcode($post_info['bbcode_bitfield']);
144                      $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
145                  }
146   
147                  $message = bbcode_nl2br($message);
148                  $message = smiley_text($message);
149   
150                  if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
151                  {
152                      $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
153   
154                      $sql = 'SELECT *
155                          FROM ' . ATTACHMENTS_TABLE . '
156                          WHERE post_msg_id = ' . $post_id . '
157                              AND in_message = 0
158                          ORDER BY filetime DESC, post_msg_id ASC';
159                      $result = $db->sql_query($sql);
160   
161                      while ($row = $db->sql_fetchrow($result))
162                      {
163                          $attachments[] = $row;
164                      }
165                      $db->sql_freeresult($result);
166   
167                      if (sizeof($attachments))
168                      {
169                          $update_count = array();
170                          parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
171                      }
172   
173                      // Display not already displayed Attachments for this post, we already parsed them. ;)
174                      if (!empty($attachments))
175                      {
176                          $template->assign_var('S_HAS_ATTACHMENTS', true);
177   
178                          foreach ($attachments as $attachment)
179                          {
180                              $template->assign_block_vars('attachment', array(
181                                  'DISPLAY_ATTACHMENT'    => $attachment)
182                              );
183                          }
184                      }
185                  }
186   
187                  $template->assign_vars(array(
188                      'S_MCP_REPORT'            => true,
189                      'S_CLOSE_ACTION'        => $this->u_action . '&amp;p=' . $post_id . '&amp;f=' . $forum_id,
190                      'S_CAN_VIEWIP'            => $auth->acl_get('m_info', $post_info['forum_id']),
191                      'S_POST_REPORTED'        => $post_info['post_reported'],
192                      'S_POST_UNAPPROVED'        => !$post_info['post_approved'],
193                      'S_POST_LOCKED'            => $post_info['post_edit_locked'],
194                      'S_USER_NOTES'            => true,
195   
196                      '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']}") : '',
197                      '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),
198                      '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),
199                      'U_MCP_REPORTER_NOTES'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $report['user_id']),
200                      'U_MCP_USER_NOTES'            => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
201                      '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']) : '',
202                      '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']) : '',
203                      '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']),
204                      'U_VIEW_TOPIC'                => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
205   
206                      'EDIT_IMG'                => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
207                      'MINI_POST_IMG'            => ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
208                      'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
209   
210                      '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>'),
211                      'REPORTED_IMG'                => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
212                      'REPORT_DATE'                => $user->format_date($report['report_time']),
213                      'REPORT_ID'                    => $report_id,
214                      'REPORT_REASON_TITLE'        => $reason['title'],
215                      'REPORT_REASON_DESCRIPTION'    => $reason['description'],
216                      'REPORT_TEXT'                => $report['report_text'],
217   
218                      'POST_AUTHOR_FULL'        => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
219                      'POST_AUTHOR_COLOUR'    => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
220                      'POST_AUTHOR'            => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
221                      'U_POST_AUTHOR'            => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
222   
223                      'REPORTER_FULL'                => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
224                      'REPORTER_COLOUR'            => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
225                      'REPORTER_NAME'                => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
226                      'U_VIEW_REPORTER_PROFILE'    => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
227   
228                      'POST_PREVIEW'            => $message,
229                      'POST_SUBJECT'            => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'],
230                      'POST_DATE'                => $user->format_date($post_info['post_time']),
231                      'POST_IP'                => $post_info['poster_ip'],
232                      'POST_IPADDR'            => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
233                      'POST_ID'                => $post_info['post_id'],
234   
235                      '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' : '',
236                  ));
237   
238                  $this->tpl_name = 'mcp_post';
239   
240              break;
241   
242              case 'reports':
243              case 'reports_closed':
244                  $topic_id = request_var('t', 0);
245   
246                  $forum_info = array();
247                  $forum_list_reports = get_forum_list('m_report', false, true);
248   
249                  if ($topic_id && $forum_id)
250                  {
251                      $topic_info = get_topic_data(array($topic_id));
252   
253                      if (!sizeof($topic_info))
254                      {
255                          trigger_error('TOPIC_NOT_EXIST');
256                      }
257   
258                      $topic_info = $topic_info[$topic_id];
259                      $forum_id = $topic_info['forum_id'];
260                  }
261                  else if ($topic_id && !$forum_id)
262                  {
263                      $topic_id = 0;
264                  }
265   
266                  $forum_list = array();
267   
268                  if (!$forum_id)
269                  {
270                      foreach ($forum_list_reports as $row)
271                      {
272                          $forum_list[] = $row['forum_id'];
273                      }
274   
275                      if (!sizeof($forum_list))
276                      {
277                          trigger_error('NOT_MODERATOR');
278                      }
279   
280                      $global_id = $forum_list[0];
281   
282                      $sql = 'SELECT SUM(forum_topics) as sum_forum_topics
283                          FROM ' . FORUMS_TABLE . '
284                          WHERE ' . $db->sql_in_set('forum_id', $forum_list);
285                      $result = $db->sql_query($sql);
286                      $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
287                      $db->sql_freeresult($result);
288                  }
289                  else
290                  {
291                      $forum_info = get_forum_data(array($forum_id), 'm_report');
292   
293                      if (!sizeof($forum_info))
294                      {
295                          trigger_error('NOT_MODERATOR');
296                      }
297   
298                      $forum_info = $forum_info[$forum_id];
299                      $forum_list = array($forum_id);
300                      $global_id = $forum_id;
301                  }
302   
303                  $forum_list[] = 0;
304                  $forum_data = array();
305   
306                  $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
307                  foreach ($forum_list_reports as $row)
308                  {
309                      $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp; &nbsp;', $row['padding']) . $row['forum_name'] . '</option>';
310                      $forum_data[$row['forum_id']] = $row;
311                  }
312                  unset($forum_list_reports);
313   
314                  $sort_days = $total = 0;
315                  $sort_key = $sort_dir = '';
316                  $sort_by_sql = $sort_order_sql = array();
317                  mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
318   
319                  $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
320                  $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
321   
322                  if ($mode == 'reports')
323                  {
324                      $report_state = 'AND p.post_reported = 1 AND r.report_closed = 0';
325                  }
326                  else
327                  {
328                      $report_state = 'AND r.report_closed = 1';
329                  }
330   
331                  $sql = 'SELECT r.report_id
332                      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' : '') . '
333                      WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . "
334                          $report_state
335                          AND r.post_id = p.post_id
336                          " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
337                          ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = p.poster_id' : '') . '
338                          ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
339                          AND t.topic_id = p.topic_id
340                          $limit_time_sql
341                      ORDER BY $sort_order_sql";
342                  $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
343   
344                  $i = 0;
345                  $report_ids = array();
346                  while ($row = $db->sql_fetchrow($result))
347                  {
348                      $report_ids[] = $row['report_id'];
349                      $row_num[$row['report_id']] = $i++;
350                  }
351                  $db->sql_freeresult($result);
352   
353                  if (sizeof($report_ids))
354                  {
355                      $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, u.username, u.username_clean, u.user_colour, r.user_id as reporter_id, ru.username as reporter_name, ru.user_colour as reporter_colour, r.report_time, r.report_id
356                          FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
357                          WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . '
358                              AND t.topic_id = p.topic_id
359                              AND r.post_id = p.post_id
360                              AND u.user_id = p.poster_id
361                              AND ru.user_id = r.user_id
362                          ORDER BY ' . $sort_order_sql;
363                      $result = $db->sql_query($sql);
364   
365                      $report_data = $rowset = array();
366                      while ($row = $db->sql_fetchrow($result))
367                      {
368                          $global_topic = ($row['forum_id']) ? false : true;
369                          if ($global_topic)
370                          {
371                              $row['forum_id'] = $global_id;
372                          }
373   
374                          $template->assign_block_vars('postrow', array(
375                              'U_VIEWFORUM'                => (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
376                              'U_VIEWPOST'                => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']) . '#p' . $row['post_id'],
377                              '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']}"),
378   
379                              'POST_AUTHOR_FULL'        => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
380                              'POST_AUTHOR_COLOUR'    => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
381                              'POST_AUTHOR'            => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
382                              'U_POST_AUTHOR'            => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
383   
384                              'REPORTER_FULL'            => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
385                              'REPORTER_COLOUR'        => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
386                              'REPORTER'                => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
387                              'U_REPORTER'            => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
388   
389                              'FORUM_NAME'    => (!$global_topic) ? $forum_data[$row['forum_id']]['forum_name'] : $user->lang['GLOBAL_ANNOUNCEMENT'],
390                              'POST_ID'        => $row['post_id'],
391                              'POST_SUBJECT'    => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
392                              'POST_TIME'        => $user->format_date($row['post_time']),
393                              'REPORT_ID'        => $row['report_id'],
394                              'REPORT_TIME'    => $user->format_date($row['report_time']),
395                              'TOPIC_TITLE'    => $row['topic_title'])
396                          );
397                      }
398                      $db->sql_freeresult($result);
399                      unset($report_ids, $row);
400                  }
401   
402                  // Now display the page
403                  $template->assign_vars(array(
404                      'L_EXPLAIN'                => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'],
405                      'L_TITLE'                => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN'] : $user->lang['MCP_REPORTS_CLOSED'],
406                      'L_ONLY_TOPIC'            => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
407   
408                      'S_MCP_ACTION'            => $this->u_action,
409                      'S_FORUM_OPTIONS'        => $forum_options,
410                      'S_CLOSED'                => ($mode == 'reports_closed') ? true : false,
411   
412                      'PAGINATION'            => generate_pagination($this->u_action . "&amp;f=$forum_id&amp;t=$topic_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $config['topics_per_page'], $start),
413                      'PAGE_NUMBER'            => on_page($total, $config['topics_per_page'], $start),
414                      'TOPIC_ID'                => $topic_id,
415                      'TOTAL'                    => $total,
416                      'TOTAL_REPORTS'            => ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),                    
417                      )
418                  );
419   
420                  $this->tpl_name = 'mcp_reports';
421              break;
422          }
423      }
424  }
425   
426  /**
427  * Closes a report
428  */
429  function close_report($report_id_list, $mode, $action)
430  {
431      global $db, $template, $user, $config;
432      global $phpEx, $phpbb_root_path;
433   
434      $sql = 'SELECT r.post_id
435          FROM ' . REPORTS_TABLE . ' r
436          WHERE ' . $db->sql_in_set('r.report_id', $report_id_list);
437      $result = $db->sql_query($sql);
438   
439      $post_id_list = array();
440      while ($row = $db->sql_fetchrow($result))
441      {
442          $post_id_list[] = $row['post_id'];
443      }
444      $post_id_list = array_unique($post_id_list);
445   
446      if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
447      {
448          trigger_error('NOT_AUTHORISED');
449      }
450   
451      if ($action == 'delete' && strpos($user->data['session_page'], 'mode=report_details') !== false)
452      {
453          $redirect = request_var('redirect', build_url(array('mode', '_f_', 'r', 'quickmod')) . '&amp;mode=reports');
454      }
455      else if ($action == 'close' && !request_var('r', 0))
456      {
457          $redirect = request_var('redirect', build_url(array('mode', '_f_', 'p', 'quickmod')) . '&amp;mode=reports');
458      }
459      else
460      {
461          $redirect = request_var('redirect', build_url(array('_f_', 'quickmod')));
462      }
463      $success_msg = '';
464      $forum_ids = array();
465      $topic_ids = array();
466   
467      $s_hidden_fields = build_hidden_fields(array(
468          'i'                    => 'reports',
469          'mode'                => $mode,
470          'report_id_list'    => $report_id_list,
471          'action'            => $action,
472          'redirect'            => $redirect)
473      );
474   
475      if (confirm_box(true))
476      {
477          $post_info = get_post_data($post_id_list, 'm_report');
478   
479          $sql = 'SELECT r.report_id, r.post_id, 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
480              FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u
481              WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . '
482                  ' . (($action == 'close') ? 'AND r.report_closed = 0' : '') . '
483                  AND r.user_id = u.user_id';
484          $result = $db->sql_query($sql);
485   
486          $reports = $close_report_posts = $close_report_topics = $notify_reporters = $report_id_list = array();
487          while ($report = $db->sql_fetchrow($result))
488          {
489              $reports[$report['report_id']] = $report;
490              $report_id_list[] = $report['report_id'];
491   
492              if (!$report['report_closed'])
493              {
494                  $close_report_posts[] = $report['post_id'];
495                  $close_report_topics[] = $post_info[$report['post_id']]['topic_id'];
496              }
497   
498              if ($report['user_notify'] && !$report['report_closed'])
499              {
500                  $notify_reporters[$report['report_id']] = &$reports[$report['report_id']];
501              }
502          }
503          $db->sql_freeresult($result);
504   
505          if (sizeof($reports))
506          {
507              $close_report_posts = array_unique($close_report_posts);
508              $close_report_topics = array_unique($close_report_topics);
509   
510              if (sizeof($close_report_posts))
511              {
512                  // Get a list of topics that still contain reported posts
513                  $sql = 'SELECT DISTINCT topic_id
514                      FROM ' . POSTS_TABLE . '
515                      WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
516                          AND post_reported = 1
517                          AND ' . $db->sql_in_set('post_id', $close_report_posts, true);
518                  $result = $db->sql_query($sql);
519   
520                  $keep_report_topics = array();
521                  while ($row = $db->sql_fetchrow($result))
522                  {
523                      $keep_report_topics[] = $row['topic_id'];
524                  }
525                  $db->sql_freeresult($result);
526   
527                  $close_report_topics = array_diff($close_report_topics, $keep_report_topics);
528                  unset($keep_report_topics);
529              }
530   
531              $db->sql_transaction('begin');
532   
533              if ($action == 'close')
534              {
535                  $sql = 'UPDATE ' . REPORTS_TABLE . '
536                      SET report_closed = 1
537                      WHERE ' . $db->sql_in_set('report_id', $report_id_list);
538              }
539              else
540              {
541                  $sql = 'DELETE FROM ' . REPORTS_TABLE . '
542                      WHERE ' . $db->sql_in_set('report_id', $report_id_list);
543              }
544              $db->sql_query($sql);
545   
546   
547              if (sizeof($close_report_posts))
548              {
549                  $sql = 'UPDATE ' . POSTS_TABLE . '
550                      SET post_reported = 0
551                      WHERE ' . $db->sql_in_set('post_id', $close_report_posts);
552                  $db->sql_query($sql);
553   
554                  if (sizeof($close_report_topics))
555                  {
556                      $sql = 'UPDATE ' . TOPICS_TABLE . '
557                          SET topic_reported = 0
558                          WHERE ' . $db->sql_in_set('topic_id', $close_report_topics);
559                      $db->sql_query($sql);
560                  }
561              }
562   
563              $db->sql_transaction('commit');
564          }
565          unset($close_report_posts, $close_report_topics);
566   
567          foreach ($reports as $report)
568          {
569              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']);
570          }
571   
572          $messenger = new messenger();
573   
574          // Notify reporters
575          if (sizeof($notify_reporters))
576          {
577              foreach ($notify_reporters as $report_id => $reporter)
578              {
579                  if ($reporter['user_id'] == ANONYMOUS)
580                  {
581                      continue;
582                  }
583   
584                  $post_id = $reporter['post_id'];
585   
586                  $messenger->template('report_' . $action . 'd', $reporter['user_lang']);
587   
588                  $messenger->to($reporter['user_email'], $reporter['username']);
589                  $messenger->im($reporter['user_jabber'], $reporter['username']);
590   
591                  $messenger->assign_vars(array(
592                      'USERNAME'        => htmlspecialchars_decode($reporter['username']),
593                      'CLOSER_NAME'    => htmlspecialchars_decode($user->data['username']),
594                      'POST_SUBJECT'    => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])),
595                      'TOPIC_TITLE'    => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title'])))
596                  );
597   
598                  $messenger->send($reporter['user_notify_type']);
599              }
600          }
601          
602          foreach ($post_info as $post)
603          {
604              $forum_ids[$post['forum_id']] = $post['forum_id'];
605              $topic_ids[$post['topic_id']] = $post['topic_id'];
606          }
607          
608          unset($notify_reporters, $post_info, $reports);
609   
610          $messenger->save_queue();
611   
612          $success_msg = (sizeof($report_id_list) == 1) ? 'REPORT_' . strtoupper($action) . 'D_SUCCESS' : 'REPORTS_' . strtoupper($action) . 'D_SUCCESS';
613      }
614      else
615      {
616          confirm_box(false, $user->lang[strtoupper($action) . '_REPORT' . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
617      }
618   
619      $redirect = request_var('redirect', "index.$phpEx");
620      $redirect = reapply_sid($redirect);
621   
622      if (!$success_msg)
623      {
624          redirect($redirect);
625      }
626      else
627      {
628          meta_refresh(3, $redirect);
629          $return_forum = '';
630          if (sizeof($forum_ids == 1))
631          {
632              $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
633          }
634          $return_topic = '';
635          if (sizeof($topic_ids == 1))
636          {
637              $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 />';
638          }
639          
640          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
641      }
642  }
643   
644  ?>