[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

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

   1  <?php
   2  /** 
   3  *
   4  * @package mcp
   5  * @version $Id: mcp_queue.php,v 1.59 2006/11/03 21:04:09 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * mcp_queue
  13  * Handling the moderation queue
  14  * @package mcp
  15  */
  16  class mcp_queue
  17  {
  18      var $p_master;
  19      var $u_action;
  20  
  21  	function mcp_main(&$p_master)
  22      {
  23          $this->p_master = &$p_master;
  24      }
  25  
  26  	function main($id, $mode)
  27      {
  28          global $auth, $db, $user, $template;
  29          global $config, $phpbb_root_path, $phpEx, $action;
  30  
  31          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  32  
  33          $forum_id = request_var('f', 0);
  34          $start = request_var('start', 0);
  35  
  36          $this->page_title = 'MCP_QUEUE';
  37  
  38          switch ($action)
  39          {
  40              case 'approve':
  41              case 'disapprove':
  42                  include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  43  
  44                  $post_id_list = request_var('post_id_list', array(0));
  45  
  46                  if (!sizeof($post_id_list))
  47                  {
  48                      trigger_error('NO_POST_SELECTED');
  49                  }
  50  
  51                  if ($action == 'approve')
  52                  {
  53                      approve_post($post_id_list, $mode);
  54                  }
  55                  else
  56                  {
  57                      disapprove_post($post_id_list, $mode);
  58                  }
  59  
  60              break;
  61          }
  62  
  63          switch ($mode)
  64          {
  65              case 'approve_details':
  66  
  67                  $user->add_lang('posting');
  68  
  69                  $post_id = request_var('p', 0);
  70                  $topic_id = request_var('t', 0);
  71  
  72                  if ($topic_id)
  73                  {
  74                      $topic_info = get_topic_data(array($topic_id), 'm_approve');
  75                      if (isset($topic_info[$topic_id]['topic_first_post_id']))
  76                      {
  77                          $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
  78                      }
  79                      else
  80                      {
  81                          $topic_id = 0;
  82                      }
  83                  }
  84  
  85                  $post_info = get_post_data(array($post_id), 'm_approve');
  86  
  87                  if (!sizeof($post_info))
  88                  {
  89                      trigger_error('NO_POST_SELECTED');
  90                  }
  91  
  92                  $post_info = $post_info[$post_id];
  93  
  94                  if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
  95                  {
  96                      $template->assign_vars(array(
  97                          'S_TOPIC_REVIEW'    => true,
  98                          'TOPIC_TITLE'        => $post_info['topic_title'])
  99                      );
 100                  }
 101  
 102                  // Set some vars
 103                  if ($post_info['user_id'] == ANONYMOUS)
 104                  {
 105                      $poster = ($post_info['post_username']) ? $post_info['post_username'] : $user->lang['GUEST'];
 106                  }
 107  
 108                  $poster = ($post_info['user_colour']) ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username'];
 109  
 110                  // Process message, leave it uncensored
 111                  $message = $post_info['post_text'];
 112                  $message = str_replace("\n", '<br />', $message);
 113                  if ($post_info['bbcode_bitfield'])
 114                  {
 115                      include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 116                      $bbcode = new bbcode($post_info['bbcode_bitfield']);
 117                      $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
 118                  }
 119                  $message = smiley_text($message);
 120  
 121                  $template->assign_vars(array(
 122                      'S_MCP_QUEUE'            => true,
 123                      'S_APPROVE_ACTION'        => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"),
 124                      'S_CAN_VIEWIP'            => $auth->acl_get('m_info', $post_info['forum_id']),
 125                      'S_POST_REPORTED'        => $post_info['post_reported'],
 126                      'S_POST_UNAPPROVED'        => !$post_info['post_approved'],
 127                      'S_POST_LOCKED'            => $post_info['post_edit_locked'],
 128                      'S_USER_NOTES'            => true,
 129  
 130                      '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']}") : '',
 131                      '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),
 132                      '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),
 133                      'U_MCP_USER_NOTES'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
 134                      'U_MCP_WARN_USER'        => ($auth->acl_getf_global('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '',
 135                      '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']),
 136                      'U_VIEW_PROFILE'        => ($post_info['user_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $post_info['user_id']) : '',
 137                      'U_VIEW_TOPIC'            => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
 138  
 139                      'RETURN_QUEUE'            => sprintf($user->lang['RETURN_QUEUE'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue' . (($topic_id) ? '&amp;mode=unapproved_topics' : '&amp;mode=unapproved_posts')) . "&amp;start=$start\">", '</a>'),
 140                      'REPORTED_IMG'            => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
 141                      'UNAPPROVED_IMG'        => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
 142                      'EDIT_IMG'                => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
 143  
 144                      'POSTER_NAME'            => $poster,
 145                      'POST_PREVIEW'            => $message,
 146                      'POST_SUBJECT'            => $post_info['post_subject'],
 147                      'POST_DATE'                => $user->format_date($post_info['post_time']),
 148                      'POST_IP'                => $post_info['poster_ip'],
 149                      'POST_IPADDR'            => @gethostbyaddr($post_info['poster_ip']),
 150                      'POST_ID'                => $post_info['post_id'])
 151                  );
 152  
 153                  $this->tpl_name = 'mcp_post';
 154  
 155              break;
 156  
 157              case 'unapproved_topics':
 158              case 'unapproved_posts':
 159                  $topic_id = request_var('t', 0);
 160                  $forum_info = array();
 161  
 162                  if ($topic_id)
 163                  {
 164                      $topic_info = get_topic_data(array($topic_id));
 165  
 166                      if (!sizeof($topic_info))
 167                      {
 168                          trigger_error($user->lang['TOPIC_NOT_EXIST']);
 169                      }
 170  
 171                      $topic_info = $topic_info[$topic_id];
 172                      $forum_id = $topic_info['forum_id'];
 173                  }
 174  
 175                  $forum_list_approve = get_forum_list('m_approve', false, true);
 176  
 177                  if (!$forum_id)
 178                  {
 179                      $forum_list = array();
 180                      foreach ($forum_list_approve as $row)
 181                      {
 182                          $forum_list[] = $row['forum_id'];
 183                      }
 184  
 185                      if (!sizeof($forum_list))
 186                      {
 187                          trigger_error('NOT_MODERATOR');
 188                      }
 189  
 190                      $global_id = $forum_list[0];
 191  
 192                      $forum_list = implode(', ', $forum_list);
 193  
 194                      $sql = 'SELECT SUM(forum_topics) as sum_forum_topics
 195                          FROM ' . FORUMS_TABLE . "
 196                          WHERE forum_id IN (0, $forum_list)";
 197                      $result = $db->sql_query($sql);
 198                      $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
 199                      $db->sql_freeresult($result);
 200                  }
 201                  else
 202                  {
 203                      $forum_info = get_forum_data(array($forum_id), 'm_approve');
 204  
 205                      if (!sizeof($forum_info))
 206                      {
 207                          trigger_error('NOT_MODERATOR');
 208                      }
 209  
 210                      $forum_info = $forum_info[$forum_id];
 211                      $forum_list = $forum_id;
 212                      $global_id = $forum_id;
 213                  }
 214  
 215                  $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
 216                  foreach ($forum_list_approve as $row)
 217                  {
 218                      $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . $row['forum_name'] . '</option>';
 219                  }
 220  
 221                  $sort_days = $total = 0;
 222                  $sort_key = $sort_dir = '';
 223                  $sort_by_sql = $sort_order_sql = array();
 224                  mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 225  
 226                  $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
 227                  $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 228  
 229                  $forum_names = array();
 230  
 231                  if ($mode == 'unapproved_posts')
 232                  {
 233                      $sql = 'SELECT p.post_id
 234                          FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . "
 235                          WHERE p.forum_id IN (0, $forum_list)
 236                              AND p.post_approved = 0
 237                              " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
 238                              ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
 239                              AND t.topic_id = p.topic_id
 240                              AND t.topic_first_post_id <> p.post_id
 241                              $limit_time_sql
 242                          ORDER BY $sort_order_sql";
 243                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 244  
 245                      $i = 0;
 246                      $post_ids = array();
 247                      while ($row = $db->sql_fetchrow($result))
 248                      {
 249                          $post_ids[] = $row['post_id'];
 250                          $row_num[$row['post_id']] = $i++;
 251                      }
 252                      $db->sql_freeresult($result);
 253  
 254                      if (sizeof($post_ids))
 255                      {
 256                          $sql = 'SELECT t.topic_id, t.topic_title, t.forum_id, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, u.username
 257                              FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
 258                              WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
 259                                  AND t.topic_id = p.topic_id
 260                                  AND u.user_id = p.poster_id';
 261                          $result = $db->sql_query($sql);
 262  
 263                          $post_data = $rowset = array();
 264                          while ($row = $db->sql_fetchrow($result))
 265                          {
 266                              if ($row['forum_id'])
 267                              {
 268                                  $forum_names[] = $row['forum_id'];
 269                              }
 270                              $post_data[$row['post_id']] = $row;
 271                          }
 272                          $db->sql_freeresult($result);
 273  
 274                          foreach ($post_ids as $post_id)
 275                          {
 276                              $rowset[] = $post_data[$post_id];
 277                          }
 278                          unset($post_data, $post_ids);
 279                      }
 280                      else
 281                      {
 282                          $rowset = array();
 283                      }
 284                  }
 285                  else
 286                  {
 287                      $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_first_poster_name AS username
 288                          FROM ' . TOPICS_TABLE . " t
 289                          WHERE forum_id IN (0, $forum_list)
 290                              AND topic_approved = 0
 291                              $limit_time_sql
 292                          ORDER BY $sort_order_sql";
 293                      $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 294  
 295                      $rowset = array();
 296                      while ($row = $db->sql_fetchrow($result))
 297                      {
 298                          if ($row['forum_id'])
 299                          {
 300                              $forum_names[] = $row['forum_id'];
 301                          }
 302                          $rowset[] = $row;
 303                      }
 304                      $db->sql_freeresult($result);
 305                  }
 306  
 307                  if (sizeof($forum_names))
 308                  {
 309                      // Select the names for the forum_ids
 310                      $sql = 'SELECT forum_id, forum_name
 311                          FROM ' . FORUMS_TABLE . '
 312                          WHERE ' . $db->sql_in_set('forum_id', $forum_names);
 313                      $result = $db->sql_query($sql, 3600);
 314  
 315                      $forum_names = array();
 316                      while ($row = $db->sql_fetchrow($result))
 317                      {
 318                          $forum_names[$row['forum_id']] = $row['forum_name'];
 319                      }
 320                      $db->sql_freeresult($result);
 321                  }
 322  
 323                  foreach ($rowset as $row)
 324                  {
 325                      if ($row['poster_id'] == ANONYMOUS)
 326                      {
 327                          $poster = (!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST'];
 328                      }
 329                      else
 330                      {
 331                          $poster = $row['username'];
 332                      }
 333  
 334                      $global_topic = ($row['forum_id']) ? false : true;
 335                      if ($global_topic)
 336                      {
 337                          $row['forum_id'] = $global_id;
 338                      }
 339  
 340                      $template->assign_block_vars('postrow', array(
 341                          'U_VIEWFORUM'        => (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
 342                          'U_VIEWPOST'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''),
 343                          'U_VIEW_DETAILS'    => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;start=$start&amp;mode=approve_details&amp;f={$row['forum_id']}&amp;p={$row['post_id']}" . (($mode == 'unapproved_topics') ? "&amp;t={$row['topic_id']}" : '')),
 344                          'U_VIEWPROFILE'        => ($row['poster_id'] != ANONYMOUS) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['poster_id']) : '',
 345  
 346                          'POST_ID'        => $row['post_id'],
 347                          'FORUM_NAME'    => (!$global_topic) ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'],
 348                          'POST_SUBJECT'    => $row['post_subject'],
 349                          'POSTER'        => $poster,
 350                          'POST_TIME'        => $user->format_date($row['post_time']))
 351                      );
 352                  }
 353                  unset($rowset, $forum_names);
 354  
 355                  // Now display the page
 356                  $template->assign_vars(array(
 357                      'L_DISPLAY_ITEMS'        => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
 358                      'L_EXPLAIN'                => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
 359                      'L_TITLE'                => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
 360                      'L_ONLY_TOPIC'            => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
 361  
 362                      'S_FORUM_OPTIONS'        => $forum_options,
 363                      'S_MCP_ACTION'            => build_url(array('t', 'f', 'sd', 'st', 'sk')),
 364                      'S_TOPICS'                => ($mode == 'unapproved_posts') ? false : true,
 365  
 366                      'PAGINATION'            => generate_pagination($this->u_action . "&amp;f=$forum_id", $total, $config['topics_per_page'], $start),
 367                      'PAGE_NUMBER'            => on_page($total, $config['topics_per_page'], $start),
 368                      'TOPIC_ID'                => $topic_id,
 369                      'TOTAL'                    => $total)
 370                  );
 371  
 372                  $this->tpl_name = 'mcp_queue';
 373              break;
 374          }
 375      }
 376  }
 377  
 378  /**
 379  * Approve Post/Topic
 380  */
 381  function approve_post($post_id_list, $mode)
 382  {
 383      global $db, $template, $user, $config;
 384      global $phpEx, $phpbb_root_path;
 385  
 386      if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_approve')))
 387      {
 388          trigger_error('NOT_AUTHORIZED');
 389      }
 390  
 391      $redirect = request_var('redirect', $user->data['session_page']);
 392      $success_msg = '';
 393  
 394      $s_hidden_fields = build_hidden_fields(array(
 395          'i'                => 'queue',
 396          'mode'            => $mode,
 397          'post_id_list'    => $post_id_list,
 398          'f'                => $forum_id,
 399          'action'        => 'approve',
 400          'redirect'        => $redirect)
 401      );
 402  
 403      if (confirm_box(true))
 404      {
 405          $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
 406  
 407          $post_info = get_post_data($post_id_list, 'm_approve');
 408  
 409          // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
 410          // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
 411  
 412          $total_topics = $total_posts = $forum_topics = $forum_posts = 0;
 413          $topic_approve_sql = $topic_replies_sql = $post_approve_sql = $topic_id_list = array();
 414  
 415          $update_forum_information = false;
 416  
 417          foreach ($post_info as $post_id => $post_data)
 418          {
 419              $topic_id_list[$post_data['topic_id']] = 1;
 420  
 421              // Topic or Post. ;)
 422              if ($post_data['topic_first_post_id'] == $post_id)
 423              {
 424                  if ($post_data['forum_id'])
 425                  {
 426                      $total_topics++;
 427                      $forum_topics++;
 428                  }
 429  
 430                  $topic_approve_sql[] = $post_data['topic_id'];
 431              }
 432              else
 433              {
 434                  if (!isset($topic_replies_sql[$post_data['topic_id']]))
 435                  {
 436                      $topic_replies_sql[$post_data['topic_id']] = 1;
 437                  }
 438                  else
 439                  {
 440                      $topic_replies_sql[$post_data['topic_id']]++;
 441                  }
 442              }
 443  
 444              if ($post_data['forum_id'])
 445              {
 446                  $total_posts++;
 447                  $forum_posts++;
 448              }
 449  
 450              $post_approve_sql[] = $post_id;
 451  
 452              // If the post is newer than the last post information stored we need to update the forum information
 453              if ($post_data['post_time'] >= $post_data['forum_last_post_time'])
 454              {
 455                  $update_forum_information = true;
 456              }
 457          }
 458  
 459          if (sizeof($topic_approve_sql))
 460          {
 461              $sql = 'UPDATE ' . TOPICS_TABLE . '
 462                  SET topic_approved = 1
 463                  WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
 464              $db->sql_query($sql);
 465          }
 466  
 467          if (sizeof($post_approve_sql))
 468          {
 469              $sql = 'UPDATE ' . POSTS_TABLE . '
 470                  SET post_approved = 1
 471                  WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
 472              $db->sql_query($sql);
 473          }
 474  
 475          if (sizeof($topic_replies_sql))
 476          {
 477              foreach ($topic_replies_sql as $topic_id => $num_replies)
 478              {
 479                  $sql = 'UPDATE ' . TOPICS_TABLE . "
 480                      SET topic_replies = topic_replies + $num_replies
 481                      WHERE topic_id = $topic_id";
 482                  $db->sql_query($sql);
 483              }
 484          }
 485  
 486          if ($forum_topics || $forum_posts)
 487          {
 488              $sql = 'UPDATE ' . FORUMS_TABLE . '
 489                  SET ';
 490              $sql .= ($forum_topics) ? "forum_topics = forum_topics + $forum_topics" : '';
 491              $sql .= ($forum_topics && $forum_posts) ? ', ' : '';
 492              $sql .= ($forum_posts) ? "forum_posts = forum_posts + $forum_posts" : '';
 493              $sql .= " WHERE forum_id = $forum_id";
 494  
 495              $db->sql_query($sql);
 496          }
 497  
 498          if ($total_topics)
 499          {
 500              set_config('num_topics', $config['num_topics'] + $total_topics, true);
 501          }
 502  
 503          if ($total_posts)
 504          {
 505              set_config('num_posts', $config['num_posts'] + $total_posts, true);
 506          }
 507          unset($topic_approve_sql, $topic_replies_sql, $post_approve_sql);
 508  
 509          update_post_information('topic', array_keys($topic_id_list));
 510  
 511          if ($update_forum_information)
 512          {
 513              update_post_information('forum', $forum_id);
 514          }
 515          unset($topic_id_list);
 516  
 517          $messenger = new messenger();
 518  
 519          // Notify Poster?
 520          if ($notify_poster)
 521          {
 522              foreach ($post_info as $post_id => $post_data)
 523              {
 524                  if ($post_data['poster_id'] == ANONYMOUS)
 525                  {
 526                      continue;
 527                  }
 528  
 529                  $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved';
 530  
 531                  $messenger->template($email_template, $post_data['user_lang']);
 532  
 533                  $messenger->replyto($config['board_email']);
 534                  $messenger->to($post_data['user_email'], $post_data['username']);
 535                  $messenger->im($post_data['user_jabber'], $post_data['username']);
 536  
 537                  $messenger->assign_vars(array(
 538                      'USERNAME'        => htmlspecialchars_decode($post_data['username']),
 539                      'POST_SUBJECT'    => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
 540                      'TOPIC_TITLE'    => htmlspecialchars_decode(censor_text($post_data['topic_title'])),
 541  
 542                      'U_VIEW_TOPIC'    => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t={$post_data['topic_id']}&e=0",
 543                      'U_VIEW_POST'    => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t={$post_data['topic_id']}&p=$post_id&e=$post_id")
 544                  );
 545  
 546                  $messenger->send($post_data['user_notify_type']);
 547                  $messenger->reset();
 548              }
 549  
 550              $messenger->save_queue();
 551          }
 552  
 553          // Send out normal user notifications
 554          $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
 555  
 556          foreach ($post_info as $post_id => $post_data)
 557          {
 558              if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
 559              {
 560                  // Forum Notifications
 561                  user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $forum_id, $post_data['topic_id'], $post_id);
 562              }
 563              else
 564              {
 565                  // Topic Notifications
 566                  user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $forum_id, $post_data['topic_id'], $post_id);
 567              }
 568          }
 569          unset($post_info);
 570  
 571          if ($forum_topics)
 572          {
 573              $success_msg = ($forum_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
 574          }
 575          else
 576          {
 577              $success_msg = (sizeof($post_id_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
 578          }
 579      }
 580      else
 581      {
 582          $template->assign_vars(array(
 583              'S_NOTIFY_POSTER'    => true,
 584              'S_APPROVE'            => true)
 585          );
 586  
 587          confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
 588      }
 589  
 590      $redirect = request_var('redirect', "index.$phpEx");
 591      $redirect = reapply_sid($redirect);
 592  
 593      if (!$success_msg)
 594      {
 595          redirect($redirect);
 596      }
 597      else
 598      {
 599          meta_refresh(3, $redirect);
 600          trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
 601      }
 602  }
 603  
 604  /**
 605  * Disapprove Post/Topic
 606  */
 607  function disapprove_post($post_id_list, $mode)
 608  {
 609      global $db, $template, $user, $config;
 610      global $phpEx, $phpbb_root_path;
 611  
 612      if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_approve')))
 613      {
 614          trigger_error('NOT_AUTHORIZED');
 615      }
 616  
 617      $redirect = request_var('redirect', build_url(array('t', 'mode')) . '&amp;mode=unapproved_topics');
 618      $reason = request_var('reason', '', true);
 619      $reason_id = request_var('reason_id', 0);
 620      $success_msg = $additional_msg = '';
 621  
 622      $s_hidden_fields = build_hidden_fields(array(
 623          'i'                => 'queue',
 624          'mode'            => $mode,
 625          'post_id_list'    => $post_id_list,
 626          'f'                => $forum_id,
 627          'action'        => 'disapprove',
 628          'redirect'        => $redirect)
 629      );
 630  
 631      $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
 632      $disapprove_reason = '';
 633  
 634      if ($reason_id)
 635      {
 636          $sql = 'SELECT reason_title, reason_description
 637              FROM ' . REPORTS_REASONS_TABLE . "
 638              WHERE reason_id = $reason_id";
 639          $result = $db->sql_query($sql);
 640          $row = $db->sql_fetchrow($result);
 641          $db->sql_freeresult($result);
 642  
 643          if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
 644          {
 645              $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
 646              unset($_POST['confirm']);
 647          }
 648          else
 649          {
 650              // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
 651              $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : '';
 652              $disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
 653          }
 654      }
 655  
 656      if (confirm_box(true))
 657      {
 658          $post_info = get_post_data($post_id_list, 'm_approve');
 659  
 660          // If Topic -> forum_topics_real -= 1
 661          // If Post -> topic_replies_real -= 1
 662  
 663          $forum_topics_real = 0;
 664          $topic_replies_real_sql = $post_disapprove_sql = $topic_id_list = array();
 665  
 666          foreach ($post_info as $post_id => $post_data)
 667          {
 668              $topic_id_list[$post_data['topic_id']] = 1;
 669  
 670              // Topic or Post. ;)
 671              if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id)
 672              {
 673                  if ($post_data['forum_id'])
 674                  {
 675                      $forum_topics_real++;
 676                  }
 677              }
 678              else
 679              {
 680                  if (!isset($topic_replies_real_sql[$post_data['topic_id']]))
 681                  {
 682                      $topic_replies_real_sql[$post_data['topic_id']] = 1;
 683                  }
 684                  else
 685                  {
 686                      $topic_replies_real_sql[$post_data['topic_id']]++;
 687                  }
 688              }
 689  
 690              $post_disapprove_sql[] = $post_id;
 691          }
 692  
 693          if ($forum_topics_real)
 694          {
 695              $sql = 'UPDATE ' . FORUMS_TABLE . "
 696                  SET forum_topics_real = forum_topics_real - $forum_topics_real
 697                  WHERE forum_id = $forum_id";
 698              $db->sql_query($sql);
 699          }
 700  
 701          if (sizeof($topic_replies_real_sql))
 702          {
 703              foreach ($topic_replies_real_sql as $topic_id => $num_replies)
 704              {
 705                  $sql = 'UPDATE ' . TOPICS_TABLE . "
 706                      SET topic_replies_real = topic_replies_real - $num_replies
 707                      WHERE topic_id = $topic_id";
 708                  $db->sql_query($sql);
 709              }
 710          }
 711  
 712          if (sizeof($post_disapprove_sql))
 713          {
 714              if (!function_exists('delete_posts'))
 715              {
 716                  include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 717              }
 718  
 719              // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
 720              delete_posts('post_id', $post_disapprove_sql);
 721          }
 722          unset($post_disapprove_sql, $topic_replies_real_sql);
 723  
 724          update_post_information('topic', array_keys($topic_id_list));
 725          update_post_information('forum', $forum_id);
 726          unset($topic_id_list);
 727  
 728          $messenger = new messenger();
 729  
 730          // Notify Poster?
 731          if ($notify_poster)
 732          {
 733              foreach ($post_info as $post_id => $post_data)
 734              {
 735                  if ($post_data['poster_id'] == ANONYMOUS)
 736                  {
 737                      continue;
 738                  }
 739  
 740                  $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved';
 741  
 742                  $messenger->template($email_template, $post_data['user_lang']);
 743  
 744                  $messenger->replyto($config['board_email']);
 745                  $messenger->to($post_data['user_email'], $post_data['username']);
 746                  $messenger->im($post_data['user_jabber'], $post_data['username']);
 747  
 748                  $messenger->assign_vars(array(
 749                      'USERNAME'        => htmlspecialchars_decode($post_data['username']),
 750                      'REASON'        => htmlspecialchars_decode($disapprove_reason),
 751                      'POST_SUBJECT'    => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
 752                      'TOPIC_TITLE'    => htmlspecialchars_decode(censor_text($post_data['topic_title'])))
 753                  );
 754  
 755                  $messenger->send($post_data['user_notify_type']);
 756                  $messenger->reset();
 757              }
 758  
 759              $messenger->save_queue();
 760          }
 761          unset($post_info, $disapprove_reason);
 762  
 763          if ($forum_topics_real)
 764          {
 765              $success_msg = ($forum_topics_real == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
 766          }
 767          else
 768          {
 769              $success_msg = (sizeof($post_id_list) == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
 770          }
 771      }
 772      else
 773      {
 774          include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 775  
 776          display_reasons($reason_id);
 777  
 778          $template->assign_vars(array(
 779              'S_NOTIFY_POSTER'    => true,
 780              'S_APPROVE'            => false,
 781              'REASON'            => $reason,
 782              'ADDITIONAL_MSG'    => $additional_msg)
 783          );
 784  
 785          confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
 786      }
 787  
 788      $redirect = request_var('redirect', "index.$phpEx");
 789      $redirect = reapply_sid($redirect);
 790  
 791      if (!$success_msg)
 792      {
 793          redirect($redirect);
 794      }
 795      else
 796      {
 797          meta_refresh(3, $redirect);
 798          trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
 799      }
 800  }
 801  
 802  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6