includes/mcp/mcp_queue.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/mcp/mcp_queue.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,999 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package mcp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* mcp_queue
    1.24 +* Handling the moderation queue
    1.25 +* @package mcp
    1.26 +*/
    1.27 +class mcp_queue
    1.28 +{
    1.29 +	var $p_master;
    1.30 +	var $u_action;
    1.31 +
    1.32 +	function mcp_queue(&$p_master)
    1.33 +	{
    1.34 +		$this->p_master = &$p_master;
    1.35 +	}
    1.36 +
    1.37 +	function main($id, $mode)
    1.38 +	{
    1.39 +		global $auth, $db, $user, $template, $cache;
    1.40 +		global $config, $phpbb_root_path, $phpEx, $action;
    1.41 +
    1.42 +		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
    1.43 +
    1.44 +		$forum_id = request_var('f', 0);
    1.45 +		$start = request_var('start', 0);
    1.46 +
    1.47 +		$this->page_title = 'MCP_QUEUE';
    1.48 +
    1.49 +		switch ($action)
    1.50 +		{
    1.51 +			case 'approve':
    1.52 +			case 'disapprove':
    1.53 +				include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
    1.54 +
    1.55 +				$post_id_list = request_var('post_id_list', array(0));
    1.56 +
    1.57 +				if (!sizeof($post_id_list))
    1.58 +				{
    1.59 +					trigger_error('NO_POST_SELECTED');
    1.60 +				}
    1.61 +
    1.62 +				if ($action == 'approve')
    1.63 +				{
    1.64 +					approve_post($post_id_list, 'queue', $mode);
    1.65 +				}
    1.66 +				else
    1.67 +				{
    1.68 +					disapprove_post($post_id_list, 'queue', $mode);
    1.69 +				}
    1.70 +
    1.71 +			break;
    1.72 +		}
    1.73 +
    1.74 +		switch ($mode)
    1.75 +		{
    1.76 +			case 'approve_details':
    1.77 +
    1.78 +				$this->tpl_name = 'mcp_post';
    1.79 +
    1.80 +				$user->add_lang(array('posting', 'viewtopic'));
    1.81 +
    1.82 +				$post_id = request_var('p', 0);
    1.83 +				$topic_id = request_var('t', 0);
    1.84 +
    1.85 +				if ($topic_id)
    1.86 +				{
    1.87 +					$topic_info = get_topic_data(array($topic_id), 'm_approve');
    1.88 +					if (isset($topic_info[$topic_id]['topic_first_post_id']))
    1.89 +					{
    1.90 +						$post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
    1.91 +					}
    1.92 +					else
    1.93 +					{
    1.94 +						$topic_id = 0;
    1.95 +					}
    1.96 +				}
    1.97 +
    1.98 +				$post_info = get_post_data(array($post_id), 'm_approve', true);
    1.99 +
   1.100 +				if (!sizeof($post_info))
   1.101 +				{
   1.102 +					trigger_error('NO_POST_SELECTED');
   1.103 +				}
   1.104 +
   1.105 +				$post_info = $post_info[$post_id];
   1.106 +
   1.107 +				if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
   1.108 +				{
   1.109 +					$template->assign_vars(array(
   1.110 +						'S_TOPIC_REVIEW'	=> true,
   1.111 +						'S_BBCODE_ALLOWED'	=> $post_info['enable_bbcode'],
   1.112 +						'TOPIC_TITLE'		=> $post_info['topic_title'])
   1.113 +					);
   1.114 +				}
   1.115 +
   1.116 +				$extensions = $attachments = $topic_tracking_info = array();
   1.117 +
   1.118 +				// Get topic tracking info
   1.119 +				if ($config['load_db_lastread'])
   1.120 +				{
   1.121 +					$tmp_topic_data = array($post_info['topic_id'] => $post_info);
   1.122 +					$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']));
   1.123 +					unset($tmp_topic_data);
   1.124 +				}
   1.125 +				else
   1.126 +				{
   1.127 +					$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
   1.128 +				}
   1.129 +
   1.130 +				$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
   1.131 +
   1.132 +				// Process message, leave it uncensored
   1.133 +				$message = $post_info['post_text'];
   1.134 +
   1.135 +				if ($post_info['bbcode_bitfield'])
   1.136 +				{
   1.137 +					include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
   1.138 +					$bbcode = new bbcode($post_info['bbcode_bitfield']);
   1.139 +					$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
   1.140 +				}
   1.141 +
   1.142 +				$message = bbcode_nl2br($message);
   1.143 +				$message = smiley_text($message);
   1.144 +
   1.145 +				if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
   1.146 +				{
   1.147 +					$extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
   1.148 +
   1.149 +					$sql = 'SELECT *
   1.150 +						FROM ' . ATTACHMENTS_TABLE . '
   1.151 +						WHERE post_msg_id = ' . $post_id . '
   1.152 +							AND in_message = 0
   1.153 +						ORDER BY filetime DESC, post_msg_id ASC';
   1.154 +					$result = $db->sql_query($sql);
   1.155 +
   1.156 +					while ($row = $db->sql_fetchrow($result))
   1.157 +					{
   1.158 +						$attachments[] = $row;
   1.159 +					}
   1.160 +					$db->sql_freeresult($result);
   1.161 +
   1.162 +					if (sizeof($attachments))
   1.163 +					{
   1.164 +						$update_count = array();
   1.165 +						parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
   1.166 +					}
   1.167 +
   1.168 +					// Display not already displayed Attachments for this post, we already parsed them. ;)
   1.169 +					if (!empty($attachments))
   1.170 +					{
   1.171 +						$template->assign_var('S_HAS_ATTACHMENTS', true);
   1.172 +
   1.173 +						foreach ($attachments as $attachment)
   1.174 +						{
   1.175 +							$template->assign_block_vars('attachment', array(
   1.176 +								'DISPLAY_ATTACHMENT'	=> $attachment)
   1.177 +							);
   1.178 +						}
   1.179 +					}
   1.180 +				}
   1.181 +
   1.182 +				$post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']);
   1.183 +				$topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']);
   1.184 +
   1.185 +				$template->assign_vars(array(
   1.186 +					'S_MCP_QUEUE'			=> true,
   1.187 +					'U_APPROVE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&amp;p=$post_id&amp;f=$forum_id"),
   1.188 +					'S_CAN_VIEWIP'			=> $auth->acl_get('m_info', $post_info['forum_id']),
   1.189 +					'S_POST_REPORTED'		=> $post_info['post_reported'],
   1.190 +					'S_POST_UNAPPROVED'		=> !$post_info['post_approved'],
   1.191 +					'S_POST_LOCKED'			=> $post_info['post_edit_locked'],
   1.192 +					'S_USER_NOTES'			=> true,
   1.193 +
   1.194 +					'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']}") : '',
   1.195 +					'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),
   1.196 +					'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),
   1.197 +					'U_MCP_USER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
   1.198 +					'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']) : '',
   1.199 +					'U_VIEW_POST'			=> $post_url,
   1.200 +					'U_VIEW_TOPIC'			=> $topic_url,
   1.201 +
   1.202 +					'MINI_POST_IMG'			=> ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
   1.203 +
   1.204 +					'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>'),
   1.205 +					'RETURN_POST'			=> sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
   1.206 +					'RETURN_TOPIC_SIMPLE'	=> sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),
   1.207 +					'REPORTED_IMG'			=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
   1.208 +					'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
   1.209 +					'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
   1.210 +
   1.211 +					'POST_AUTHOR_FULL'		=> get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.212 +					'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.213 +					'POST_AUTHOR'			=> get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.214 +					'U_POST_AUTHOR'			=> get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
   1.215 +
   1.216 +					'POST_PREVIEW'			=> $message,
   1.217 +					'POST_SUBJECT'			=> $post_info['post_subject'],
   1.218 +					'POST_DATE'				=> $user->format_date($post_info['post_time']),
   1.219 +					'POST_IP'				=> $post_info['poster_ip'],
   1.220 +					'POST_IPADDR'			=> ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
   1.221 +					'POST_ID'				=> $post_info['post_id'],
   1.222 +					'S_FIRST_POST'			=> ($post_info['topic_first_post_id'] == $post_id),
   1.223 +
   1.224 +					'U_LOOKUP_IP'			=> ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id . '&amp;lookup=' . $post_info['poster_ip']) . '#ip' : '',
   1.225 +				));
   1.226 +
   1.227 +			break;
   1.228 +
   1.229 +			case 'unapproved_topics':
   1.230 +			case 'unapproved_posts':
   1.231 +				$user->add_lang(array('viewtopic', 'viewforum'));
   1.232 +
   1.233 +				$topic_id = request_var('t', 0);
   1.234 +				$forum_info = array();
   1.235 +
   1.236 +				if ($topic_id)
   1.237 +				{
   1.238 +					$topic_info = get_topic_data(array($topic_id));
   1.239 +
   1.240 +					if (!sizeof($topic_info))
   1.241 +					{
   1.242 +						trigger_error('TOPIC_NOT_EXIST');
   1.243 +					}
   1.244 +
   1.245 +					$topic_info = $topic_info[$topic_id];
   1.246 +					$forum_id = $topic_info['forum_id'];
   1.247 +				}
   1.248 +
   1.249 +				$forum_list_approve = get_forum_list('m_approve', false, true);
   1.250 +				$forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
   1.251 +
   1.252 +				// Remove forums we cannot read
   1.253 +				foreach ($forum_list_approve as $k => $forum_data)
   1.254 +				{
   1.255 +					if (!isset($forum_list_read[$forum_data['forum_id']]))
   1.256 +					{
   1.257 +						unset($forum_list_approve[$k]);
   1.258 +					}
   1.259 +				}
   1.260 +				unset($forum_list_read);
   1.261 +
   1.262 +				if (!$forum_id)
   1.263 +				{
   1.264 +					$forum_list = array();
   1.265 +					foreach ($forum_list_approve as $row)
   1.266 +					{
   1.267 +						$forum_list[] = $row['forum_id'];
   1.268 +					}
   1.269 +
   1.270 +					if (!sizeof($forum_list))
   1.271 +					{
   1.272 +						trigger_error('NOT_MODERATOR');
   1.273 +					}
   1.274 +
   1.275 +					$global_id = $forum_list[0];
   1.276 +
   1.277 +					$forum_list = implode(', ', $forum_list);
   1.278 +
   1.279 +					$sql = 'SELECT SUM(forum_topics) as sum_forum_topics
   1.280 +						FROM ' . FORUMS_TABLE . "
   1.281 +						WHERE forum_id IN (0, $forum_list)";
   1.282 +					$result = $db->sql_query($sql);
   1.283 +					$forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
   1.284 +					$db->sql_freeresult($result);
   1.285 +				}
   1.286 +				else
   1.287 +				{
   1.288 +					$forum_info = get_forum_data(array($forum_id), 'm_approve');
   1.289 +
   1.290 +					if (!sizeof($forum_info))
   1.291 +					{
   1.292 +						trigger_error('NOT_MODERATOR');
   1.293 +					}
   1.294 +
   1.295 +					$forum_info = $forum_info[$forum_id];
   1.296 +					$forum_list = $forum_id;
   1.297 +					$global_id = $forum_id;
   1.298 +				}
   1.299 +
   1.300 +				$forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
   1.301 +				foreach ($forum_list_approve as $row)
   1.302 +				{
   1.303 +					$forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp; &nbsp;', $row['padding']) . $row['forum_name'] . '</option>';
   1.304 +				}
   1.305 +
   1.306 +				$sort_days = $total = 0;
   1.307 +				$sort_key = $sort_dir = '';
   1.308 +				$sort_by_sql = $sort_order_sql = array();
   1.309 +				mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
   1.310 +
   1.311 +				$forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
   1.312 +				$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
   1.313 +
   1.314 +				$forum_names = array();
   1.315 +
   1.316 +				if ($mode == 'unapproved_posts')
   1.317 +				{
   1.318 +					$sql = 'SELECT p.post_id
   1.319 +						FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . "
   1.320 +						WHERE p.forum_id IN (0, $forum_list)
   1.321 +							AND p.post_approved = 0
   1.322 +							" . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
   1.323 +							' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
   1.324 +							AND t.topic_id = p.topic_id
   1.325 +							AND t.topic_first_post_id <> p.post_id
   1.326 +							$limit_time_sql
   1.327 +						ORDER BY $sort_order_sql";
   1.328 +					$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
   1.329 +
   1.330 +					$i = 0;
   1.331 +					$post_ids = array();
   1.332 +					while ($row = $db->sql_fetchrow($result))
   1.333 +					{
   1.334 +						$post_ids[] = $row['post_id'];
   1.335 +						$row_num[$row['post_id']] = $i++;
   1.336 +					}
   1.337 +					$db->sql_freeresult($result);
   1.338 +
   1.339 +					if (sizeof($post_ids))
   1.340 +					{
   1.341 +						$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, u.username_clean, u.user_colour
   1.342 +							FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
   1.343 +							WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
   1.344 +								AND t.topic_id = p.topic_id
   1.345 +								AND u.user_id = p.poster_id
   1.346 +							ORDER BY ' . $sort_order_sql;
   1.347 +						$result = $db->sql_query($sql);
   1.348 +
   1.349 +						$post_data = $rowset = array();
   1.350 +						while ($row = $db->sql_fetchrow($result))
   1.351 +						{
   1.352 +							if ($row['forum_id'])
   1.353 +							{
   1.354 +								$forum_names[] = $row['forum_id'];
   1.355 +							}
   1.356 +							$post_data[$row['post_id']] = $row;
   1.357 +						}
   1.358 +						$db->sql_freeresult($result);
   1.359 +
   1.360 +						foreach ($post_ids as $post_id)
   1.361 +						{
   1.362 +							$rowset[] = $post_data[$post_id];
   1.363 +						}
   1.364 +						unset($post_data, $post_ids);
   1.365 +					}
   1.366 +					else
   1.367 +					{
   1.368 +						$rowset = array();
   1.369 +					}
   1.370 +				}
   1.371 +				else
   1.372 +				{
   1.373 +					$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, t.topic_first_poster_colour AS user_colour
   1.374 +						FROM ' . TOPICS_TABLE . " t
   1.375 +						WHERE forum_id IN (0, $forum_list)
   1.376 +							AND topic_approved = 0
   1.377 +							$limit_time_sql
   1.378 +						ORDER BY $sort_order_sql";
   1.379 +					$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
   1.380 +
   1.381 +					$rowset = array();
   1.382 +					while ($row = $db->sql_fetchrow($result))
   1.383 +					{
   1.384 +						if ($row['forum_id'])
   1.385 +						{
   1.386 +							$forum_names[] = $row['forum_id'];
   1.387 +						}
   1.388 +						$rowset[] = $row;
   1.389 +					}
   1.390 +					$db->sql_freeresult($result);
   1.391 +				}
   1.392 +
   1.393 +				if (sizeof($forum_names))
   1.394 +				{
   1.395 +					// Select the names for the forum_ids
   1.396 +					$sql = 'SELECT forum_id, forum_name
   1.397 +						FROM ' . FORUMS_TABLE . '
   1.398 +						WHERE ' . $db->sql_in_set('forum_id', $forum_names);
   1.399 +					$result = $db->sql_query($sql, 3600);
   1.400 +
   1.401 +					$forum_names = array();
   1.402 +					while ($row = $db->sql_fetchrow($result))
   1.403 +					{
   1.404 +						$forum_names[$row['forum_id']] = $row['forum_name'];
   1.405 +					}
   1.406 +					$db->sql_freeresult($result);
   1.407 +				}
   1.408 +
   1.409 +				foreach ($rowset as $row)
   1.410 +				{
   1.411 +					$global_topic = ($row['forum_id']) ? false : true;
   1.412 +					if ($global_topic)
   1.413 +					{
   1.414 +						$row['forum_id'] = $global_id;
   1.415 +					}
   1.416 +
   1.417 +					if (empty($row['post_username']))
   1.418 +					{
   1.419 +						$row['post_username'] = $user->lang['GUEST'];
   1.420 +					}
   1.421 +
   1.422 +					$template->assign_block_vars('postrow', array(
   1.423 +						'U_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
   1.424 +						'U_VIEWFORUM'		=> (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
   1.425 +						'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'] : ''),
   1.426 +						'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']}" : '')),
   1.427 +
   1.428 +						'POST_AUTHOR_FULL'		=> get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
   1.429 +						'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
   1.430 +						'POST_AUTHOR'			=> get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
   1.431 +						'U_POST_AUTHOR'			=> get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
   1.432 +
   1.433 +						'POST_ID'		=> $row['post_id'],
   1.434 +						'FORUM_NAME'	=> (!$global_topic) ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'],
   1.435 +						'POST_SUBJECT'	=> ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
   1.436 +						'TOPIC_TITLE'	=> $row['topic_title'],
   1.437 +						'POST_TIME'		=> $user->format_date($row['post_time']))
   1.438 +					);
   1.439 +				}
   1.440 +				unset($rowset, $forum_names);
   1.441 +
   1.442 +				// Now display the page
   1.443 +				$template->assign_vars(array(
   1.444 +					'L_DISPLAY_ITEMS'		=> ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
   1.445 +					'L_EXPLAIN'				=> ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
   1.446 +					'L_TITLE'				=> ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
   1.447 +					'L_ONLY_TOPIC'			=> ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
   1.448 +
   1.449 +					'S_FORUM_OPTIONS'		=> $forum_options,
   1.450 +					'S_MCP_ACTION'			=> build_url(array('t', 'f', 'sd', 'st', 'sk')),
   1.451 +					'S_TOPICS'				=> ($mode == 'unapproved_posts') ? false : true,
   1.452 +
   1.453 +					'PAGINATION'			=> generate_pagination($this->u_action . "&amp;f=$forum_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $config['topics_per_page'], $start),
   1.454 +					'PAGE_NUMBER'			=> on_page($total, $config['topics_per_page'], $start),
   1.455 +					'TOPIC_ID'				=> $topic_id,
   1.456 +					'TOTAL'					=> ($total == 1) ? (($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POST'] : $user->lang['VIEW_FORUM_TOPIC']) : sprintf((($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POSTS'] : $user->lang['VIEW_FORUM_TOPICS']), $total),
   1.457 +				));
   1.458 +
   1.459 +				$this->tpl_name = 'mcp_queue';
   1.460 +			break;
   1.461 +		}
   1.462 +	}
   1.463 +}
   1.464 +
   1.465 +/**
   1.466 +* Approve Post/Topic
   1.467 +*/
   1.468 +function approve_post($post_id_list, $id, $mode)
   1.469 +{
   1.470 +	global $db, $template, $user, $config;
   1.471 +	global $phpEx, $phpbb_root_path;
   1.472 +
   1.473 +	if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
   1.474 +	{
   1.475 +		trigger_error('NOT_AUTHORISED');
   1.476 +	}
   1.477 +
   1.478 +	$redirect = request_var('redirect', build_url(array('quickmod')));
   1.479 +	$success_msg = '';
   1.480 +
   1.481 +	$s_hidden_fields = build_hidden_fields(array(
   1.482 +		'i'				=> $id,
   1.483 +		'mode'			=> $mode,
   1.484 +		'post_id_list'	=> $post_id_list,
   1.485 +		'action'		=> 'approve',
   1.486 +		'redirect'		=> $redirect)
   1.487 +	);
   1.488 +
   1.489 +	$post_info = get_post_data($post_id_list, 'm_approve');
   1.490 +
   1.491 +	if (confirm_box(true))
   1.492 +	{
   1.493 +		$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
   1.494 +
   1.495 +		// If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
   1.496 +		// If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
   1.497 +
   1.498 +		$total_topics = $total_posts = 0;
   1.499 +		$topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
   1.500 +		$user_posts_sql = $post_approved_list = array();
   1.501 +
   1.502 +		foreach ($post_info as $post_id => $post_data)
   1.503 +		{
   1.504 +			if ($post_data['post_approved'])
   1.505 +			{
   1.506 +				$post_approved_list[] = $post_id;
   1.507 +				continue;
   1.508 +			}
   1.509 +
   1.510 +			$topic_id_list[$post_data['topic_id']] = 1;
   1.511 +
   1.512 +			if ($post_data['forum_id'])
   1.513 +			{
   1.514 +				$forum_id_list[$post_data['forum_id']] = 1;
   1.515 +			}
   1.516 +
   1.517 +			// User post update (we do not care about topic or post, since user posts are strictly connected to posts)
   1.518 +			// But we care about forums where post counts get not increased. ;)
   1.519 +			if ($post_data['post_postcount'])
   1.520 +			{
   1.521 +				$user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
   1.522 +			}
   1.523 +
   1.524 +			// Topic or Post. ;)
   1.525 +			if ($post_data['topic_first_post_id'] == $post_id)
   1.526 +			{
   1.527 +				if ($post_data['forum_id'])
   1.528 +				{
   1.529 +					$total_topics++;
   1.530 +				}
   1.531 +				$topic_approve_sql[] = $post_data['topic_id'];
   1.532 +
   1.533 +				$approve_log[] = array(
   1.534 +					'type'			=> 'topic',
   1.535 +					'post_subject'	=> $post_data['post_subject'],
   1.536 +					'forum_id'		=> $post_data['forum_id'],
   1.537 +					'topic_id'		=> $post_data['topic_id'],
   1.538 +				);
   1.539 +			}
   1.540 +			else
   1.541 +			{
   1.542 +				$approve_log[] = array(
   1.543 +					'type'			=> 'post',
   1.544 +					'post_subject'	=> $post_data['post_subject'],
   1.545 +					'forum_id'		=> $post_data['forum_id'],
   1.546 +					'topic_id'		=> $post_data['topic_id'],
   1.547 +				);
   1.548 +			}
   1.549 +
   1.550 +			if ($post_data['forum_id'])
   1.551 +			{
   1.552 +				$total_posts++;
   1.553 +
   1.554 +				// Increment by topic_replies if we approve a topic...
   1.555 +				// This works because we do not adjust the topic_replies when re-approving a topic after an edit.
   1.556 +				if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
   1.557 +				{
   1.558 +					$total_posts += $post_data['topic_replies'];
   1.559 +				}
   1.560 +			}
   1.561 +
   1.562 +			$post_approve_sql[] = $post_id;
   1.563 +		}
   1.564 +
   1.565 +		$post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
   1.566 +		for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
   1.567 +		{
   1.568 +			unset($post_info[$post_approved_list[$i]]);
   1.569 +		}
   1.570 +
   1.571 +		if (sizeof($topic_approve_sql))
   1.572 +		{
   1.573 +			$sql = 'UPDATE ' . TOPICS_TABLE . '
   1.574 +				SET topic_approved = 1
   1.575 +				WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
   1.576 +			$db->sql_query($sql);
   1.577 +		}
   1.578 +
   1.579 +		if (sizeof($post_approve_sql))
   1.580 +		{
   1.581 +			$sql = 'UPDATE ' . POSTS_TABLE . '
   1.582 +				SET post_approved = 1
   1.583 +				WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
   1.584 +			$db->sql_query($sql);
   1.585 +		}
   1.586 +
   1.587 +		unset($topic_approve_sql, $post_approve_sql);
   1.588 +
   1.589 +		foreach ($approve_log as $log_data)
   1.590 +		{
   1.591 +			add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
   1.592 +		}
   1.593 +
   1.594 +		if (sizeof($user_posts_sql))
   1.595 +		{
   1.596 +			// Try to minimize the query count by merging users with the same post count additions
   1.597 +			$user_posts_update = array();
   1.598 +
   1.599 +			foreach ($user_posts_sql as $user_id => $user_posts)
   1.600 +			{
   1.601 +				$user_posts_update[$user_posts][] = $user_id;
   1.602 +			}
   1.603 +
   1.604 +			foreach ($user_posts_update as $user_posts => $user_id_ary)
   1.605 +			{
   1.606 +				$sql = 'UPDATE ' . USERS_TABLE . '
   1.607 +					SET user_posts = user_posts + ' . $user_posts . '
   1.608 +					WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
   1.609 +				$db->sql_query($sql);
   1.610 +			}
   1.611 +		}
   1.612 +
   1.613 +		if ($total_topics)
   1.614 +		{
   1.615 +			set_config_count('num_topics', $total_topics, true);
   1.616 +		}
   1.617 +
   1.618 +		if ($total_posts)
   1.619 +		{
   1.620 +			set_config_count('num_posts', $total_posts, true);
   1.621 +		}
   1.622 +
   1.623 +		sync('topic', 'topic_id', array_keys($topic_id_list), true);
   1.624 +		sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
   1.625 +		unset($topic_id_list, $forum_id_list);
   1.626 +
   1.627 +		$messenger = new messenger();
   1.628 +
   1.629 +		// Notify Poster?
   1.630 +		if ($notify_poster)
   1.631 +		{
   1.632 +			foreach ($post_info as $post_id => $post_data)
   1.633 +			{
   1.634 +				if ($post_data['poster_id'] == ANONYMOUS)
   1.635 +				{
   1.636 +					continue;
   1.637 +				}
   1.638 +
   1.639 +				$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';
   1.640 +
   1.641 +				$messenger->template($email_template, $post_data['user_lang']);
   1.642 +
   1.643 +				$messenger->to($post_data['user_email'], $post_data['username']);
   1.644 +				$messenger->im($post_data['user_jabber'], $post_data['username']);
   1.645 +
   1.646 +				$messenger->assign_vars(array(
   1.647 +					'USERNAME'		=> htmlspecialchars_decode($post_data['username']),
   1.648 +					'POST_SUBJECT'	=> htmlspecialchars_decode(censor_text($post_data['post_subject'])),
   1.649 +					'TOPIC_TITLE'	=> htmlspecialchars_decode(censor_text($post_data['topic_title'])),
   1.650 +
   1.651 +					'U_VIEW_TOPIC'	=> generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0",
   1.652 +					'U_VIEW_POST'	=> generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id")
   1.653 +				);
   1.654 +
   1.655 +				$messenger->send($post_data['user_notify_type']);
   1.656 +			}
   1.657 +		}
   1.658 +
   1.659 +		$messenger->save_queue();
   1.660 +
   1.661 +		// Send out normal user notifications
   1.662 +		$email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
   1.663 +
   1.664 +		foreach ($post_info as $post_id => $post_data)
   1.665 +		{
   1.666 +			if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
   1.667 +			{
   1.668 +				// Forum Notifications
   1.669 +				user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
   1.670 +			}
   1.671 +			else
   1.672 +			{
   1.673 +				// Topic Notifications
   1.674 +				user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
   1.675 +			}
   1.676 +		}
   1.677 +
   1.678 +		if (sizeof($post_id_list) == 1)
   1.679 +		{
   1.680 +			$post_data = $post_info[$post_id_list[0]];
   1.681 +			$post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&amp;t={$post_data['topic_id']}&amp;p={$post_data['post_id']}") . '#p' . $post_data['post_id'];
   1.682 +		}
   1.683 +		unset($post_info);
   1.684 +
   1.685 +		if ($total_topics)
   1.686 +		{
   1.687 +			$success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
   1.688 +		}
   1.689 +		else
   1.690 +		{
   1.691 +			$success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
   1.692 +		}
   1.693 +	}
   1.694 +	else
   1.695 +	{
   1.696 +		$show_notify = false;
   1.697 +
   1.698 +		if ($config['email_enable'] || $config['jab_enable'])
   1.699 +		{
   1.700 +			foreach ($post_info as $post_data)
   1.701 +			{
   1.702 +				if ($post_data['poster_id'] == ANONYMOUS)
   1.703 +				{
   1.704 +					continue;
   1.705 +				}
   1.706 +				else
   1.707 +				{
   1.708 +					$show_notify = true;
   1.709 +					break;
   1.710 +				}
   1.711 +			}
   1.712 +		}
   1.713 +
   1.714 +		$template->assign_vars(array(
   1.715 +			'S_NOTIFY_POSTER'	=> $show_notify,
   1.716 +			'S_APPROVE'			=> true)
   1.717 +		);
   1.718 +
   1.719 +		confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
   1.720 +	}
   1.721 +
   1.722 +	$redirect = request_var('redirect', "index.$phpEx");
   1.723 +	$redirect = reapply_sid($redirect);
   1.724 +
   1.725 +	if (!$success_msg)
   1.726 +	{
   1.727 +		redirect($redirect);
   1.728 +	}
   1.729 +	else
   1.730 +	{
   1.731 +		meta_refresh(3, $redirect);
   1.732 +
   1.733 +		// If approving one post, also give links back to post...
   1.734 +		$add_message = '';
   1.735 +		if (sizeof($post_id_list) == 1 && !empty($post_url))
   1.736 +		{
   1.737 +			$add_message = '<br /><br />' . sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>');
   1.738 +		}
   1.739 +
   1.740 +		trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>') . $add_message);
   1.741 +	}
   1.742 +}
   1.743 +
   1.744 +/**
   1.745 +* Disapprove Post/Topic
   1.746 +*/
   1.747 +function disapprove_post($post_id_list, $id, $mode)
   1.748 +{
   1.749 +	global $db, $template, $user, $config;
   1.750 +	global $phpEx, $phpbb_root_path;
   1.751 +
   1.752 +	if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
   1.753 +	{
   1.754 +		trigger_error('NOT_AUTHORISED');
   1.755 +	}
   1.756 +
   1.757 +	$redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&amp;mode=$mode");
   1.758 +	$reason = utf8_normalize_nfc(request_var('reason', '', true));
   1.759 +	$reason_id = request_var('reason_id', 0);
   1.760 +	$success_msg = $additional_msg = '';
   1.761 +
   1.762 +	$s_hidden_fields = build_hidden_fields(array(
   1.763 +		'i'				=> $id,
   1.764 +		'mode'			=> $mode,
   1.765 +		'post_id_list'	=> $post_id_list,
   1.766 +		'action'		=> 'disapprove',
   1.767 +		'redirect'		=> $redirect)
   1.768 +	);
   1.769 +
   1.770 +	$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
   1.771 +	$disapprove_reason = '';
   1.772 +
   1.773 +	if ($reason_id)
   1.774 +	{
   1.775 +		$sql = 'SELECT reason_title, reason_description
   1.776 +			FROM ' . REPORTS_REASONS_TABLE . "
   1.777 +			WHERE reason_id = $reason_id";
   1.778 +		$result = $db->sql_query($sql);
   1.779 +		$row = $db->sql_fetchrow($result);
   1.780 +		$db->sql_freeresult($result);
   1.781 +
   1.782 +		if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
   1.783 +		{
   1.784 +			$additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
   1.785 +			unset($_REQUEST['confirm_key']);
   1.786 +			unset($_POST['confirm_key']);
   1.787 +			unset($_POST['confirm']);
   1.788 +		}
   1.789 +		else
   1.790 +		{
   1.791 +			// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
   1.792 +			$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']) : '';
   1.793 +			$disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
   1.794 +
   1.795 +			if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
   1.796 +			{
   1.797 +				$disapprove_reason_lang = strtoupper($row['reason_title']);
   1.798 +			}
   1.799 +
   1.800 +			$email_disapprove_reason = $disapprove_reason;
   1.801 +		}
   1.802 +	}
   1.803 +
   1.804 +	$post_info = get_post_data($post_id_list, 'm_approve');
   1.805 +
   1.806 +	if (confirm_box(true))
   1.807 +	{
   1.808 +		$disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
   1.809 +		$topic_replies_real = $post_disapprove_list = array();
   1.810 +
   1.811 +		// Build a list of posts to be unapproved and get the related topics real replies count
   1.812 +		foreach ($post_info as $post_id => $post_data)
   1.813 +		{
   1.814 +			$post_disapprove_list[$post_id] = $post_data['topic_id'];
   1.815 +			if (!isset($topic_replies_real[$post_data['topic_id']]))
   1.816 +			{
   1.817 +				$topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
   1.818 +			}
   1.819 +		}
   1.820 +
   1.821 +		// Now we build the log array
   1.822 +		foreach ($post_disapprove_list as $post_id => $topic_id)
   1.823 +		{
   1.824 +			// If the count of disapproved posts for the topic is greater
   1.825 +			// than topic's real replies count, the whole topic is disapproved/deleted
   1.826 +			if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
   1.827 +			{
   1.828 +				// Don't write the log more than once for every topic
   1.829 +				if (!isset($disapprove_log_topics[$topic_id]))
   1.830 +				{
   1.831 +					// Build disapproved topics log
   1.832 +					$disapprove_log_topics[$topic_id] = array(
   1.833 +						'type'			=> 'topic',
   1.834 +						'post_subject'	=> $post_info[$post_id]['topic_title'],
   1.835 +						'forum_id'		=> $post_info[$post_id]['forum_id'],
   1.836 +						'topic_id'		=> 0, // useless to log a topic id, as it will be deleted
   1.837 +					);
   1.838 +				}
   1.839 +			}
   1.840 +			else
   1.841 +			{
   1.842 +				// Build disapproved posts log
   1.843 +				$disapprove_log_posts[] = array(
   1.844 +					'type'			=> 'post',
   1.845 +					'post_subject'	=> $post_info[$post_id]['post_subject'],
   1.846 +					'forum_id'		=> $post_info[$post_id]['forum_id'],
   1.847 +					'topic_id'		=> $post_info[$post_id]['topic_id'],
   1.848 +				);
   1.849 +
   1.850 +			}
   1.851 +		}
   1.852 +
   1.853 +		// Get disapproved posts/topics counts separately
   1.854 +		$num_disapproved_topics = sizeof($disapprove_log_topics);
   1.855 +		$num_disapproved_posts = sizeof($disapprove_log_posts);
   1.856 +
   1.857 +		// Build the whole log
   1.858 +		$disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
   1.859 +
   1.860 +		// Unset unneeded arrays
   1.861 +		unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
   1.862 +
   1.863 +		// Let's do the job - delete disapproved posts
   1.864 +		if (sizeof($post_disapprove_list))
   1.865 +		{
   1.866 +			if (!function_exists('delete_posts'))
   1.867 +			{
   1.868 +				include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
   1.869 +			}
   1.870 +
   1.871 +			// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
   1.872 +			// Note: function delete_posts triggers related forums/topics sync,
   1.873 +			// so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
   1.874 +			delete_posts('post_id', array_keys($post_disapprove_list));
   1.875 +
   1.876 +			foreach ($disapprove_log as $log_data)
   1.877 +			{
   1.878 +				add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
   1.879 +			}
   1.880 +		}
   1.881 +
   1.882 +		$messenger = new messenger();
   1.883 +
   1.884 +		// Notify Poster?
   1.885 +		if ($notify_poster)
   1.886 +		{
   1.887 +			$lang_reasons = array();
   1.888 +
   1.889 +			foreach ($post_info as $post_id => $post_data)
   1.890 +			{
   1.891 +				if ($post_data['poster_id'] == ANONYMOUS)
   1.892 +				{
   1.893 +					continue;
   1.894 +				}
   1.895 +
   1.896 +				if (isset($disapprove_reason_lang))
   1.897 +				{
   1.898 +					// Okay we need to get the reason from the posters language
   1.899 +					if (!isset($lang_reasons[$post_data['user_lang']]))
   1.900 +					{
   1.901 +						// Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
   1.902 +						$lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
   1.903 +
   1.904 +						// Only load up the language pack if the language is different to the current one
   1.905 +						if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
   1.906 +						{
   1.907 +							// Load up the language pack
   1.908 +							$lang = array();
   1.909 +							@include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
   1.910 +
   1.911 +							// If we find the reason in this language pack use it
   1.912 +							if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
   1.913 +							{
   1.914 +								$lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
   1.915 +							}
   1.916 +
   1.917 +							unset($lang); // Free memory
   1.918 +						}
   1.919 +					}
   1.920 +
   1.921 +					$email_disapprove_reason = $lang_reasons[$post_data['user_lang']];
   1.922 +					$email_disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
   1.923 +				}
   1.924 +
   1.925 +				$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';
   1.926 +
   1.927 +				$messenger->template($email_template, $post_data['user_lang']);
   1.928 +
   1.929 +				$messenger->to($post_data['user_email'], $post_data['username']);
   1.930 +				$messenger->im($post_data['user_jabber'], $post_data['username']);
   1.931 +
   1.932 +				$messenger->assign_vars(array(
   1.933 +					'USERNAME'		=> htmlspecialchars_decode($post_data['username']),
   1.934 +					'REASON'		=> htmlspecialchars_decode($email_disapprove_reason),
   1.935 +					'POST_SUBJECT'	=> htmlspecialchars_decode(censor_text($post_data['post_subject'])),
   1.936 +					'TOPIC_TITLE'	=> htmlspecialchars_decode(censor_text($post_data['topic_title'])))
   1.937 +				);
   1.938 +
   1.939 +				$messenger->send($post_data['user_notify_type']);
   1.940 +			}
   1.941 +
   1.942 +			unset($lang_reasons);
   1.943 +		}
   1.944 +		unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang);
   1.945 +
   1.946 +		$messenger->save_queue();
   1.947 +
   1.948 +		if ($num_disapproved_topics)
   1.949 +		{
   1.950 +			$success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
   1.951 +		}
   1.952 +		else
   1.953 +		{
   1.954 +			$success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
   1.955 +		}
   1.956 +	}
   1.957 +	else
   1.958 +	{
   1.959 +		include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   1.960 +
   1.961 +		display_reasons($reason_id);
   1.962 +
   1.963 +		$show_notify = false;
   1.964 +
   1.965 +		foreach ($post_info as $post_data)
   1.966 +		{
   1.967 +			if ($post_data['poster_id'] == ANONYMOUS)
   1.968 +			{
   1.969 +				continue;
   1.970 +			}
   1.971 +			else
   1.972 +			{
   1.973 +				$show_notify = true;
   1.974 +				break;
   1.975 +			}
   1.976 +		}
   1.977 +
   1.978 +		$template->assign_vars(array(
   1.979 +			'S_NOTIFY_POSTER'	=> $show_notify,
   1.980 +			'S_APPROVE'			=> false,
   1.981 +			'REASON'			=> $reason,
   1.982 +			'ADDITIONAL_MSG'	=> $additional_msg)
   1.983 +		);
   1.984 +
   1.985 +		confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
   1.986 +	}
   1.987 +
   1.988 +	$redirect = request_var('redirect', "index.$phpEx");
   1.989 +	$redirect = reapply_sid($redirect);
   1.990 +
   1.991 +	if (!$success_msg)
   1.992 +	{
   1.993 +		redirect($redirect);
   1.994 +	}
   1.995 +	else
   1.996 +	{
   1.997 +		meta_refresh(3, $redirect);
   1.998 +		trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
   1.999 +	}
  1.1000 +}
  1.1001 +
  1.1002 +?>
  1.1003 \ No newline at end of file