Blame Extras/phpBB/3.0.4/includes/mcp/mcp_queue.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package mcp
4c79b5
* @version $Id: mcp_queue.php 9133 2008-11-30 12:03:43Z acydburn $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* mcp_queue
4c79b5
* Handling the moderation queue
4c79b5
* @package mcp
4c79b5
*/
4c79b5
class mcp_queue
4c79b5
{
4c79b5
	var $p_master;
4c79b5
	var $u_action;
4c79b5
4c79b5
	function mcp_queue(&$p_master)
4c79b5
	{
4c79b5
		$this->p_master = &$p_master;
4c79b5
	}
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $auth, $db, $user, $template, $cache;
4c79b5
		global $config, $phpbb_root_path, $phpEx, $action;
4c79b5
4c79b5
		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
4c79b5
4c79b5
		$forum_id = request_var('f', 0);
4c79b5
		$start = request_var('start', 0);
4c79b5
4c79b5
		$this->page_title = 'MCP_QUEUE';
4c79b5
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'approve':
4c79b5
			case 'disapprove':
4c79b5
				include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
4c79b5
4c79b5
				$post_id_list = request_var('post_id_list', array(0));
4c79b5
4c79b5
				if (!sizeof($post_id_list))
4c79b5
				{
4c79b5
					trigger_error('NO_POST_SELECTED');
4c79b5
				}
4c79b5
4c79b5
				if ($action == 'approve')
4c79b5
				{
4c79b5
					approve_post($post_id_list, 'queue', $mode);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					disapprove_post($post_id_list, 'queue', $mode);
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		switch ($mode)
4c79b5
		{
4c79b5
			case 'approve_details':
4c79b5
4c79b5
				$this->tpl_name = 'mcp_post';
4c79b5
4c79b5
				$user->add_lang(array('posting', 'viewtopic'));
4c79b5
4c79b5
				$post_id = request_var('p', 0);
4c79b5
				$topic_id = request_var('t', 0);
4c79b5
4c79b5
				if ($topic_id)
4c79b5
				{
4c79b5
					$topic_info = get_topic_data(array($topic_id), 'm_approve');
4c79b5
					if (isset($topic_info[$topic_id]['topic_first_post_id']))
4c79b5
					{
4c79b5
						$post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$topic_id = 0;
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$post_info = get_post_data(array($post_id), 'm_approve', true);
4c79b5
4c79b5
				if (!sizeof($post_info))
4c79b5
				{
4c79b5
					trigger_error('NO_POST_SELECTED');
4c79b5
				}
4c79b5
4c79b5
				$post_info = $post_info[$post_id];
4c79b5
4c79b5
				if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
4c79b5
				{
4c79b5
					$template->assign_vars(array(
4c79b5
						'S_TOPIC_REVIEW'	=> true,
4c79b5
						'TOPIC_TITLE'		=> $post_info['topic_title'])
4c79b5
					);
4c79b5
				}
4c79b5
4c79b5
				$extensions = $attachments = $topic_tracking_info = array();
4c79b5
4c79b5
				// Get topic tracking info
4c79b5
				if ($config['load_db_lastread'])
4c79b5
				{
4c79b5
					$tmp_topic_data = array($post_info['topic_id'] => $post_info);
4c79b5
					$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']));
4c79b5
					unset($tmp_topic_data);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
4c79b5
				}
4c79b5
4c79b5
				$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
4c79b5
4c79b5
				// Process message, leave it uncensored
4c79b5
				$message = $post_info['post_text'];
4c79b5
4c79b5
				if ($post_info['bbcode_bitfield'])
4c79b5
				{
4c79b5
					include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
4c79b5
					$bbcode = new bbcode($post_info['bbcode_bitfield']);
4c79b5
					$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
4c79b5
				}
4c79b5
4c79b5
				$message = bbcode_nl2br($message);
4c79b5
				$message = smiley_text($message);
4c79b5
4c79b5
				if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
4c79b5
				{
4c79b5
					$extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
4c79b5
4c79b5
					$sql = 'SELECT *
4c79b5
						FROM ' . ATTACHMENTS_TABLE . '
4c79b5
						WHERE post_msg_id = ' . $post_id . '
4c79b5
							AND in_message = 0
4c79b5
						ORDER BY filetime DESC, post_msg_id ASC';
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$attachments[] = $row;
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					if (sizeof($attachments))
4c79b5
					{
4c79b5
						$update_count = array();
4c79b5
						parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
4c79b5
					}
4c79b5
4c79b5
					// Display not already displayed Attachments for this post, we already parsed them. ;)
4c79b5
					if (!empty($attachments))
4c79b5
					{
4c79b5
						$template->assign_var('S_HAS_ATTACHMENTS', true);
4c79b5
4c79b5
						foreach ($attachments as $attachment)
4c79b5
						{
4c79b5
							$template->assign_block_vars('attachment', array(
4c79b5
								'DISPLAY_ATTACHMENT'	=> $attachment)
4c79b5
							);
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']);
4c79b5
				$topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_MCP_QUEUE'			=> true,
4c79b5
					'U_APPROVE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"),
4c79b5
					'S_CAN_VIEWIP'			=> $auth->acl_get('m_info', $post_info['forum_id']),
4c79b5
					'S_POST_REPORTED'		=> $post_info['post_reported'],
4c79b5
					'S_POST_UNAPPROVED'		=> !$post_info['post_approved'],
4c79b5
					'S_POST_LOCKED'			=> $post_info['post_edit_locked'],
4c79b5
					'S_USER_NOTES'			=> true,
4c79b5
4c79b5
					'U_EDIT'				=> ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '',
4c79b5
					'U_MCP_APPROVE'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
4c79b5
					'U_MCP_REPORT'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
4c79b5
					'U_MCP_USER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
4c79b5
					'U_MCP_WARN_USER'		=> ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $post_info['user_id']) : '',
4c79b5
					'U_VIEW_POST'			=> $post_url,
4c79b5
					'U_VIEW_TOPIC'			=> $topic_url,
4c79b5
4c79b5
					'MINI_POST_IMG'			=> ($post_unread) ? $user->img('icon_post_target_unread', 'NEW_POST') : $user->img('icon_post_target', 'POST'),
4c79b5
4c79b5
					'RETURN_QUEUE'			=> sprintf($user->lang['RETURN_QUEUE'], '", ''),
4c79b5
					'RETURN_POST'			=> sprintf($user->lang['RETURN_POST'], '', ''),
4c79b5
					'RETURN_TOPIC_SIMPLE'	=> sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '', ''),
4c79b5
					'REPORTED_IMG'			=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
4c79b5
					'UNAPPROVED_IMG'		=> $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
4c79b5
					'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
4c79b5
4c79b5
					'POST_AUTHOR_FULL'		=> get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
					'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
					'POST_AUTHOR'			=> get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
					'U_POST_AUTHOR'			=> get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
4c79b5
4c79b5
					'POST_PREVIEW'			=> $message,
4c79b5
					'POST_SUBJECT'			=> $post_info['post_subject'],
4c79b5
					'POST_DATE'				=> $user->format_date($post_info['post_time']),
4c79b5
					'POST_IP'				=> $post_info['poster_ip'],
4c79b5
					'POST_IPADDR'			=> ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
4c79b5
					'POST_ID'				=> $post_info['post_id'],
4c79b5
4c79b5
					'U_LOOKUP_IP'			=> ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id . '&lookup=' . $post_info['poster_ip']) . '#ip' : '',
4c79b5
				));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'unapproved_topics':
4c79b5
			case 'unapproved_posts':
4c79b5
				$user->add_lang(array('viewtopic', 'viewforum'));
4c79b5
4c79b5
				$topic_id = request_var('t', 0);
4c79b5
				$forum_info = array();
4c79b5
4c79b5
				if ($topic_id)
4c79b5
				{
4c79b5
					$topic_info = get_topic_data(array($topic_id));
4c79b5
4c79b5
					if (!sizeof($topic_info))
4c79b5
					{
4c79b5
						trigger_error('TOPIC_NOT_EXIST');
4c79b5
					}
4c79b5
4c79b5
					$topic_info = $topic_info[$topic_id];
4c79b5
					$forum_id = $topic_info['forum_id'];
4c79b5
				}
4c79b5
4c79b5
				$forum_list_approve = get_forum_list('m_approve', false, true);
4c79b5
				$forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
4c79b5
4c79b5
				// Remove forums we cannot read
4c79b5
				foreach ($forum_list_approve as $k => $forum_data)
4c79b5
				{
4c79b5
					if (!isset($forum_list_read[$forum_data['forum_id']]))
4c79b5
					{
4c79b5
						unset($forum_list_approve[$k]);
4c79b5
					}
4c79b5
				}
4c79b5
				unset($forum_list_read);
4c79b5
4c79b5
				if (!$forum_id)
4c79b5
				{
4c79b5
					$forum_list = array();
4c79b5
					foreach ($forum_list_approve as $row)
4c79b5
					{
4c79b5
						$forum_list[] = $row['forum_id'];
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($forum_list))
4c79b5
					{
4c79b5
						trigger_error('NOT_MODERATOR');
4c79b5
					}
4c79b5
4c79b5
					$global_id = $forum_list[0];
4c79b5
4c79b5
					$forum_list = implode(', ', $forum_list);
4c79b5
4c79b5
					$sql = 'SELECT SUM(forum_topics) as sum_forum_topics
4c79b5
						FROM ' . FORUMS_TABLE . "
4c79b5
						WHERE forum_id IN (0, $forum_list)";
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$forum_info = get_forum_data(array($forum_id), 'm_approve');
4c79b5
4c79b5
					if (!sizeof($forum_info))
4c79b5
					{
4c79b5
						trigger_error('NOT_MODERATOR');
4c79b5
					}
4c79b5
4c79b5
					$forum_info = $forum_info[$forum_id];
4c79b5
					$forum_list = $forum_id;
4c79b5
					$global_id = $forum_id;
4c79b5
				}
4c79b5
4c79b5
				$forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
4c79b5
				foreach ($forum_list_approve as $row)
4c79b5
				{
4c79b5
					$forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat('   ', $row['padding']) . $row['forum_name'] . '</option>';
4c79b5
				}
4c79b5
4c79b5
				$sort_days = $total = 0;
4c79b5
				$sort_key = $sort_dir = '';
4c79b5
				$sort_by_sql = $sort_order_sql = array();
4c79b5
				mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
4c79b5
4c79b5
				$forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
4c79b5
				$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
4c79b5
4c79b5
				$forum_names = array();
4c79b5
4c79b5
				if ($mode == 'unapproved_posts')
4c79b5
				{
4c79b5
					$sql = 'SELECT p.post_id
4c79b5
						FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . "
4c79b5
						WHERE p.forum_id IN (0, $forum_list)
4c79b5
							AND p.post_approved = 0
4c79b5
							" . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
4c79b5
							' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
4c79b5
							AND t.topic_id = p.topic_id
4c79b5
							AND t.topic_first_post_id <> p.post_id
4c79b5
							$limit_time_sql
4c79b5
						ORDER BY $sort_order_sql";
4c79b5
					$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
4c79b5
4c79b5
					$i = 0;
4c79b5
					$post_ids = array();
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$post_ids[] = $row['post_id'];
4c79b5
						$row_num[$row['post_id']] = $i++;
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					if (sizeof($post_ids))
4c79b5
					{
4c79b5
						$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
4c79b5
							FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
4c79b5
							WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
4c79b5
								AND t.topic_id = p.topic_id
4c79b5
								AND u.user_id = p.poster_id
4c79b5
							ORDER BY ' . $sort_order_sql;
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						$post_data = $rowset = array();
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							if ($row['forum_id'])
4c79b5
							{
4c79b5
								$forum_names[] = $row['forum_id'];
4c79b5
							}
4c79b5
							$post_data[$row['post_id']] = $row;
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						foreach ($post_ids as $post_id)
4c79b5
						{
4c79b5
							$rowset[] = $post_data[$post_id];
4c79b5
						}
4c79b5
						unset($post_data, $post_ids);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$rowset = array();
4c79b5
					}
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$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
4c79b5
						FROM ' . TOPICS_TABLE . " t
4c79b5
						WHERE forum_id IN (0, $forum_list)
4c79b5
							AND topic_approved = 0
4c79b5
							$limit_time_sql
4c79b5
						ORDER BY $sort_order_sql";
4c79b5
					$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
4c79b5
4c79b5
					$rowset = array();
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						if ($row['forum_id'])
4c79b5
						{
4c79b5
							$forum_names[] = $row['forum_id'];
4c79b5
						}
4c79b5
						$rowset[] = $row;
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
4c79b5
				if (sizeof($forum_names))
4c79b5
				{
4c79b5
					// Select the names for the forum_ids
4c79b5
					$sql = 'SELECT forum_id, forum_name
4c79b5
						FROM ' . FORUMS_TABLE . '
4c79b5
						WHERE ' . $db->sql_in_set('forum_id', $forum_names);
4c79b5
					$result = $db->sql_query($sql, 3600);
4c79b5
4c79b5
					$forum_names = array();
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$forum_names[$row['forum_id']] = $row['forum_name'];
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
4c79b5
				foreach ($rowset as $row)
4c79b5
				{
4c79b5
					$global_topic = ($row['forum_id']) ? false : true;
4c79b5
					if ($global_topic)
4c79b5
					{
4c79b5
						$row['forum_id'] = $global_id;
4c79b5
					}
4c79b5
4c79b5
					if (empty($row['post_username']))
4c79b5
					{
4c79b5
						$row['post_username'] = $user->lang['GUEST'];
4c79b5
					}
4c79b5
4c79b5
					$template->assign_block_vars('postrow', array(
4c79b5
						'U_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
4c79b5
						'U_VIEWFORUM'		=> (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
4c79b5
						'U_VIEWPOST'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''),
4c79b5
						'U_VIEW_DETAILS'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&start=$start&mode=approve_details&f={$row['forum_id']}&p={$row['post_id']}" . (($mode == 'unapproved_topics') ? "&t={$row['topic_id']}" : '')),
4c79b5
4c79b5
						'POST_AUTHOR_FULL'		=> get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
						'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
						'POST_AUTHOR'			=> get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
						'U_POST_AUTHOR'			=> get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
4c79b5
4c79b5
						'POST_ID'		=> $row['post_id'],
4c79b5
						'FORUM_NAME'	=> (!$global_topic) ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'],
4c79b5
						'POST_SUBJECT'	=> $row['post_subject'],
4c79b5
						'TOPIC_TITLE'	=> $row['topic_title'],
4c79b5
						'POST_TIME'		=> $user->format_date($row['post_time']))
4c79b5
					);
4c79b5
				}
4c79b5
				unset($rowset, $forum_names);
4c79b5
4c79b5
				// Now display the page
4c79b5
				$template->assign_vars(array(
4c79b5
					'L_DISPLAY_ITEMS'		=> ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
4c79b5
					'L_EXPLAIN'				=> ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
4c79b5
					'L_TITLE'				=> ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
4c79b5
					'L_ONLY_TOPIC'			=> ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
4c79b5
4c79b5
					'S_FORUM_OPTIONS'		=> $forum_options,
4c79b5
					'S_MCP_ACTION'			=> build_url(array('t', 'f', 'sd', 'st', 'sk')),
4c79b5
					'S_TOPICS'				=> ($mode == 'unapproved_posts') ? false : true,
4c79b5
4c79b5
					'PAGINATION'			=> generate_pagination($this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $total, $config['topics_per_page'], $start),
4c79b5
					'PAGE_NUMBER'			=> on_page($total, $config['topics_per_page'], $start),
4c79b5
					'TOPIC_ID'				=> $topic_id,
4c79b5
					'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),
4c79b5
				));
4c79b5
4c79b5
				$this->tpl_name = 'mcp_queue';
4c79b5
			break;
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Approve Post/Topic
4c79b5
*/
4c79b5
function approve_post($post_id_list, $id, $mode)
4c79b5
{
4c79b5
	global $db, $template, $user, $config;
4c79b5
	global $phpEx, $phpbb_root_path;
4c79b5
4c79b5
	if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
4c79b5
	{
4c79b5
		trigger_error('NOT_AUTHORISED');
4c79b5
	}
4c79b5
4c79b5
	$redirect = request_var('redirect', build_url(array('quickmod')));
4c79b5
	$success_msg = '';
4c79b5
4c79b5
	$s_hidden_fields = build_hidden_fields(array(
4c79b5
		'i'				=> $id,
4c79b5
		'mode'			=> $mode,
4c79b5
		'post_id_list'	=> $post_id_list,
4c79b5
		'action'		=> 'approve',
4c79b5
		'redirect'		=> $redirect)
4c79b5
	);
4c79b5
4c79b5
	$post_info = get_post_data($post_id_list, 'm_approve');
4c79b5
4c79b5
	if (confirm_box(true))
4c79b5
	{
4c79b5
		$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
4c79b5
4c79b5
		// If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
4c79b5
		// If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
4c79b5
4c79b5
		$total_topics = $total_posts = 0;
4c79b5
		$forum_topics_posts = $topic_approve_sql = $topic_replies_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
4c79b5
		$user_posts_sql = array();
4c79b5
4c79b5
		$update_forum_information = false;
4c79b5
4c79b5
		foreach ($post_info as $post_id => $post_data)
4c79b5
		{
4c79b5
			$topic_id_list[$post_data['topic_id']] = 1;
4c79b5
4c79b5
			if ($post_data['forum_id'])
4c79b5
			{
4c79b5
				$forum_id_list[$post_data['forum_id']] = 1;
4c79b5
			}
4c79b5
4c79b5
			// User post update (we do not care about topic or post, since user posts are strictly connected to posts)
4c79b5
			// But we care about forums where post counts get not increased. ;)
4c79b5
			if ($post_data['post_postcount'])
4c79b5
			{
4c79b5
				$user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
4c79b5
			}
4c79b5
4c79b5
			// Topic or Post. ;)
4c79b5
			if ($post_data['topic_first_post_id'] == $post_id)
4c79b5
			{
4c79b5
				if ($post_data['forum_id'])
4c79b5
				{
4c79b5
					if (!isset($forum_topics_posts[$post_data['forum_id']]))
4c79b5
					{
4c79b5
						$forum_topics_posts[$post_data['forum_id']] = array(
4c79b5
							'forum_posts'	=> 0,
4c79b5
							'forum_topics'	=> 0
4c79b5
						);
4c79b5
					}
4c79b5
4c79b5
					$total_topics++;
4c79b5
					$forum_topics_posts[$post_data['forum_id']]['forum_topics']++;
4c79b5
				}
4c79b5
				$topic_approve_sql[] = $post_data['topic_id'];
4c79b5
4c79b5
				$approve_log[] = array(
4c79b5
					'type'			=> 'topic',
4c79b5
					'post_subject'	=> $post_data['post_subject'],
4c79b5
					'forum_id'		=> $post_data['forum_id'],
4c79b5
					'topic_id'		=> $post_data['topic_id'],
4c79b5
				);
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				if (!isset($topic_replies_sql[$post_data['topic_id']]))
4c79b5
				{
4c79b5
					$topic_replies_sql[$post_data['topic_id']] = 0;
4c79b5
				}
4c79b5
				$topic_replies_sql[$post_data['topic_id']]++;
4c79b5
4c79b5
				$approve_log[] = array(
4c79b5
					'type'			=> 'post',
4c79b5
					'post_subject'	=> $post_data['post_subject'],
4c79b5
					'forum_id'		=> $post_data['forum_id'],
4c79b5
					'topic_id'		=> $post_data['topic_id'],
4c79b5
				);
4c79b5
			}
4c79b5
4c79b5
			if ($post_data['forum_id'])
4c79b5
			{
4c79b5
				if (!isset($forum_topics_posts[$post_data['forum_id']]))
4c79b5
				{
4c79b5
					$forum_topics_posts[$post_data['forum_id']] = array(
4c79b5
						'forum_posts'	=> 0,
4c79b5
						'forum_topics'	=> 0
4c79b5
					);
4c79b5
				}
4c79b5
4c79b5
				$total_posts++;
4c79b5
				$forum_topics_posts[$post_data['forum_id']]['forum_posts']++;
4c79b5
4c79b5
				// Increment by topic_replies if we approve a topic...
4c79b5
				// This works because we do not adjust the topic_replies when re-approving a topic after an edit.
4c79b5
				if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
4c79b5
				{
4c79b5
					$total_posts += $post_data['topic_replies'];
4c79b5
					$forum_topics_posts[$post_data['forum_id']]['forum_posts'] += $post_data['topic_replies'];
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			$post_approve_sql[] = $post_id;
4c79b5
4c79b5
			// If the post is newer than the last post information stored we need to update the forum information
4c79b5
			if ($post_data['post_time'] >= $post_data['forum_last_post_time'])
4c79b5
			{
4c79b5
				$update_forum_information = true;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($topic_approve_sql))
4c79b5
		{
4c79b5
			$sql = 'UPDATE ' . TOPICS_TABLE . '
4c79b5
				SET topic_approved = 1
4c79b5
				WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
4c79b5
			$db->sql_query($sql);
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($post_approve_sql))
4c79b5
		{
4c79b5
			$sql = 'UPDATE ' . POSTS_TABLE . '
4c79b5
				SET post_approved = 1
4c79b5
				WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
4c79b5
			$db->sql_query($sql);
4c79b5
		}
4c79b5
4c79b5
		foreach ($approve_log as $log_data)
4c79b5
		{
4c79b5
			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']);
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($topic_replies_sql))
4c79b5
		{
4c79b5
			foreach ($topic_replies_sql as $topic_id => $num_replies)
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . TOPICS_TABLE . "
4c79b5
					SET topic_replies = topic_replies + $num_replies
4c79b5
					WHERE topic_id = $topic_id";
4c79b5
				$db->sql_query($sql);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($forum_topics_posts))
4c79b5
		{
4c79b5
			foreach ($forum_topics_posts as $forum_id => $row)
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . FORUMS_TABLE . '
4c79b5
					SET ';
4c79b5
				$sql .= ($row['forum_topics']) ? "forum_topics = forum_topics + {$row['forum_topics']}" : '';
4c79b5
				$sql .= ($row['forum_topics'] && $row['forum_posts']) ? ', ' : '';
4c79b5
				$sql .= ($row['forum_posts']) ? "forum_posts = forum_posts + {$row['forum_posts']}" : '';
4c79b5
				$sql .= " WHERE forum_id = $forum_id";
4c79b5
4c79b5
				$db->sql_query($sql);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($user_posts_sql))
4c79b5
		{
4c79b5
			// Try to minimize the query count by merging users with the same post count additions
4c79b5
			$user_posts_update = array();
4c79b5
4c79b5
			foreach ($user_posts_sql as $user_id => $user_posts)
4c79b5
			{
4c79b5
				$user_posts_update[$user_posts][] = $user_id;
4c79b5
			}
4c79b5
4c79b5
			foreach ($user_posts_update as $user_posts => $user_id_ary)
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
					SET user_posts = user_posts + ' . $user_posts . '
4c79b5
					WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
4c79b5
				$db->sql_query($sql);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ($total_topics)
4c79b5
		{
4c79b5
			set_config('num_topics', $config['num_topics'] + $total_topics, true);
4c79b5
		}
4c79b5
4c79b5
		if ($total_posts)
4c79b5
		{
4c79b5
			set_config('num_posts', $config['num_posts'] + $total_posts, true);
4c79b5
		}
4c79b5
		unset($topic_approve_sql, $topic_replies_sql, $post_approve_sql);
4c79b5
4c79b5
		update_post_information('topic', array_keys($topic_id_list));
4c79b5
4c79b5
		if ($update_forum_information)
4c79b5
		{
4c79b5
			update_post_information('forum', array_keys($forum_id_list));
4c79b5
		}
4c79b5
		unset($topic_id_list, $forum_id_list);
4c79b5
4c79b5
		$messenger = new messenger();
4c79b5
4c79b5
		// Notify Poster?
4c79b5
		if ($notify_poster)
4c79b5
		{
4c79b5
			foreach ($post_info as $post_id => $post_data)
4c79b5
			{
4c79b5
				if ($post_data['poster_id'] == ANONYMOUS)
4c79b5
				{
4c79b5
					continue;
4c79b5
				}
4c79b5
4c79b5
				$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';
4c79b5
4c79b5
				$messenger->template($email_template, $post_data['user_lang']);
4c79b5
4c79b5
				$messenger->to($post_data['user_email'], $post_data['username']);
4c79b5
				$messenger->im($post_data['user_jabber'], $post_data['username']);
4c79b5
4c79b5
				$messenger->assign_vars(array(
4c79b5
					'USERNAME'		=> htmlspecialchars_decode($post_data['username']),
4c79b5
					'POST_SUBJECT'	=> htmlspecialchars_decode(censor_text($post_data['post_subject'])),
4c79b5
					'TOPIC_TITLE'	=> htmlspecialchars_decode(censor_text($post_data['topic_title'])),
4c79b5
4c79b5
					'U_VIEW_TOPIC'	=> generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0",
4c79b5
					'U_VIEW_POST'	=> generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id")
4c79b5
				);
4c79b5
4c79b5
				$messenger->send($post_data['user_notify_type']);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$messenger->save_queue();
4c79b5
4c79b5
		// Send out normal user notifications
4c79b5
		$email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']);
4c79b5
4c79b5
		foreach ($post_info as $post_id => $post_data)
4c79b5
		{
4c79b5
			if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
4c79b5
			{
4c79b5
				// Forum Notifications
4c79b5
				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);
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				// Topic Notifications
4c79b5
				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);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($post_id_list) == 1)
4c79b5
		{
4c79b5
			$post_data = $post_info[$post_id_list[0]];
4c79b5
			$post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id'];
4c79b5
		}
4c79b5
		unset($post_info);
4c79b5
4c79b5
		if ($total_topics)
4c79b5
		{
4c79b5
			$success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$success_msg = (sizeof($post_id_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
4c79b5
		}
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$show_notify = false;
4c79b5
4c79b5
		foreach ($post_info as $post_data)
4c79b5
		{
4c79b5
			if ($post_data['poster_id'] == ANONYMOUS)
4c79b5
			{
4c79b5
				continue;
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$show_notify = true;
4c79b5
				break;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'S_NOTIFY_POSTER'	=> $show_notify,
4c79b5
			'S_APPROVE'			=> true)
4c79b5
		);
4c79b5
4c79b5
		confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
4c79b5
	}
4c79b5
4c79b5
	$redirect = request_var('redirect', "index.$phpEx");
4c79b5
	$redirect = reapply_sid($redirect);
4c79b5
4c79b5
	if (!$success_msg)
4c79b5
	{
4c79b5
		redirect($redirect);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		meta_refresh(3, $redirect);
4c79b5
4c79b5
		// If approving one post, also give links back to post...
4c79b5
		$add_message = '';
4c79b5
		if (sizeof($post_id_list) == 1 && !empty($post_url))
4c79b5
		{
4c79b5
			$add_message = '

' . sprintf($user->lang['RETURN_POST'], '', '');
4c79b5
		}
4c79b5
4c79b5
		trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message);
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* Disapprove Post/Topic
4c79b5
*/
4c79b5
function disapprove_post($post_id_list, $id, $mode)
4c79b5
{
4c79b5
	global $db, $template, $user, $config;
4c79b5
	global $phpEx, $phpbb_root_path;
4c79b5
4c79b5
	if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
4c79b5
	{
4c79b5
		trigger_error('NOT_AUTHORISED');
4c79b5
	}
4c79b5
4c79b5
	$redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode");
4c79b5
	$reason = utf8_normalize_nfc(request_var('reason', '', true));
4c79b5
	$reason_id = request_var('reason_id', 0);
4c79b5
	$success_msg = $additional_msg = '';
4c79b5
4c79b5
	$s_hidden_fields = build_hidden_fields(array(
4c79b5
		'i'				=> $id,
4c79b5
		'mode'			=> $mode,
4c79b5
		'post_id_list'	=> $post_id_list,
4c79b5
		'action'		=> 'disapprove',
4c79b5
		'redirect'		=> $redirect)
4c79b5
	);
4c79b5
4c79b5
	$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
4c79b5
	$disapprove_reason = '';
4c79b5
4c79b5
	if ($reason_id)
4c79b5
	{
4c79b5
		$sql = 'SELECT reason_title, reason_description
4c79b5
			FROM ' . REPORTS_REASONS_TABLE . "
4c79b5
			WHERE reason_id = $reason_id";
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
4c79b5
		{
4c79b5
			$additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
4c79b5
			unset($_POST['confirm']);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
4c79b5
			$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']) : '';
4c79b5
			$disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
4c79b5
4c79b5
			if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
4c79b5
			{
4c79b5
				$disapprove_reason_lang = strtoupper($row['reason_title']);
4c79b5
			}
4c79b5
4c79b5
			$email_disapprove_reason = $disapprove_reason;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	$post_info = get_post_data($post_id_list, 'm_approve');
4c79b5
4c79b5
	if (confirm_box(true))
4c79b5
	{
4c79b5
4c79b5
		// If Topic -> forum_topics_real -= 1
4c79b5
		// If Post -> topic_replies_real -= 1
4c79b5
4c79b5
		$num_disapproved = 0;
4c79b5
		$forum_topics_real = $topic_id_list = $forum_id_list = $topic_replies_real_sql = $post_disapprove_sql = $disapprove_log = array();
4c79b5
4c79b5
		foreach ($post_info as $post_id => $post_data)
4c79b5
		{
4c79b5
			$topic_id_list[$post_data['topic_id']] = 1;
4c79b5
4c79b5
			if ($post_data['forum_id'])
4c79b5
			{
4c79b5
				$forum_id_list[$post_data['forum_id']] = 1;
4c79b5
			}
4c79b5
4c79b5
			// Topic or Post. ;)
4c79b5
			/**
4c79b5
			* @todo this probably is a different method than the one used by delete_posts, does this cause counter inconsistency?
4c79b5
			*/
4c79b5
			if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id)
4c79b5
			{
4c79b5
				if ($post_data['forum_id'])
4c79b5
				{
4c79b5
					if (!isset($forum_topics_real[$post_data['forum_id']]))
4c79b5
					{
4c79b5
						$forum_topics_real[$post_data['forum_id']] = 0;
4c79b5
					}
4c79b5
					$forum_topics_real[$post_data['forum_id']]++;
4c79b5
					$num_disapproved++;
4c79b5
				}
4c79b5
4c79b5
				$disapprove_log[] = array(
4c79b5
					'type'			=> 'topic',
4c79b5
					'post_subject'	=> $post_data['post_subject'],
4c79b5
					'forum_id'		=> $post_data['forum_id'],
4c79b5
					'topic_id'		=> 0, // useless to log a topic id, as it will be deleted
4c79b5
				);
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				if (!isset($topic_replies_real_sql[$post_data['topic_id']]))
4c79b5
				{
4c79b5
					$topic_replies_real_sql[$post_data['topic_id']] = 0;
4c79b5
				}
4c79b5
				$topic_replies_real_sql[$post_data['topic_id']]++;
4c79b5
4c79b5
				$disapprove_log[] = array(
4c79b5
					'type'			=> 'post',
4c79b5
					'post_subject'	=> $post_data['post_subject'],
4c79b5
					'forum_id'		=> $post_data['forum_id'],
4c79b5
					'topic_id'		=> $post_data['topic_id'],
4c79b5
				);
4c79b5
			}
4c79b5
4c79b5
			$post_disapprove_sql[] = $post_id;
4c79b5
		}
4c79b5
4c79b5
		unset($post_data);
4c79b5
4c79b5
		if (sizeof($forum_topics_real))
4c79b5
		{
4c79b5
			foreach ($forum_topics_real as $forum_id => $topics_real)
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . FORUMS_TABLE . "
4c79b5
					SET forum_topics_real = forum_topics_real - $topics_real
4c79b5
					WHERE forum_id = $forum_id";
4c79b5
				$db->sql_query($sql);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($topic_replies_real_sql))
4c79b5
		{
4c79b5
			foreach ($topic_replies_real_sql as $topic_id => $num_replies)
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . TOPICS_TABLE . "
4c79b5
					SET topic_replies_real = topic_replies_real - $num_replies
4c79b5
					WHERE topic_id = $topic_id";
4c79b5
				$db->sql_query($sql);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if (sizeof($post_disapprove_sql))
4c79b5
		{
4c79b5
			if (!function_exists('delete_posts'))
4c79b5
			{
4c79b5
				include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
4c79b5
			}
4c79b5
4c79b5
			// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
4c79b5
			delete_posts('post_id', $post_disapprove_sql);
4c79b5
4c79b5
			foreach ($disapprove_log as $log_data)
4c79b5
			{
4c79b5
				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);
4c79b5
			}
4c79b5
		}
4c79b5
		unset($post_disapprove_sql, $topic_replies_real_sql);
4c79b5
4c79b5
		update_post_information('topic', array_keys($topic_id_list));
4c79b5
4c79b5
		if (sizeof($forum_id_list))
4c79b5
		{
4c79b5
			update_post_information('forum', array_keys($forum_id_list));
4c79b5
		}
4c79b5
		unset($topic_id_list, $forum_id_list);
4c79b5
4c79b5
		$messenger = new messenger();
4c79b5
4c79b5
		// Notify Poster?
4c79b5
		if ($notify_poster)
4c79b5
		{
4c79b5
			$lang_reasons = array();
4c79b5
4c79b5
			foreach ($post_info as $post_id => $post_data)
4c79b5
			{
4c79b5
				if ($post_data['poster_id'] == ANONYMOUS)
4c79b5
				{
4c79b5
					continue;
4c79b5
				}
4c79b5
4c79b5
				if (isset($disapprove_reason_lang))
4c79b5
				{
4c79b5
					// Okay we need to get the reason from the posters language
4c79b5
					if (!isset($lang_reasons[$post_data['user_lang']]))
4c79b5
					{
4c79b5
						// Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
4c79b5
						$lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
4c79b5
4c79b5
						// Only load up the language pack if the language is different to the current one
4c79b5
						if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
4c79b5
						{
4c79b5
							// Load up the language pack
4c79b5
							$lang = array();
4c79b5
							@include($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx);
4c79b5
4c79b5
							// If we find the reason in this language pack use it
4c79b5
							if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
4c79b5
							{
4c79b5
								$lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
4c79b5
							}
4c79b5
4c79b5
							unset($lang); // Free memory
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					$email_disapprove_reason = $lang_reasons[$post_data['user_lang']];
4c79b5
					$email_disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
4c79b5
				}
4c79b5
4c79b5
				$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';
4c79b5
4c79b5
				$messenger->template($email_template, $post_data['user_lang']);
4c79b5
4c79b5
				$messenger->to($post_data['user_email'], $post_data['username']);
4c79b5
				$messenger->im($post_data['user_jabber'], $post_data['username']);
4c79b5
4c79b5
				$messenger->assign_vars(array(
4c79b5
					'USERNAME'		=> htmlspecialchars_decode($post_data['username']),
4c79b5
					'REASON'		=> htmlspecialchars_decode($email_disapprove_reason),
4c79b5
					'POST_SUBJECT'	=> htmlspecialchars_decode(censor_text($post_data['post_subject'])),
4c79b5
					'TOPIC_TITLE'	=> htmlspecialchars_decode(censor_text($post_data['topic_title'])))
4c79b5
				);
4c79b5
4c79b5
				$messenger->send($post_data['user_notify_type']);
4c79b5
			}
4c79b5
4c79b5
			unset($lang_reasons);
4c79b5
		}
4c79b5
		unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang);
4c79b5
4c79b5
		$messenger->save_queue();
4c79b5
4c79b5
		if (sizeof($forum_topics_real))
4c79b5
		{
4c79b5
			$success_msg = ($num_disapproved == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$success_msg = (sizeof($post_id_list) == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
4c79b5
		}
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
		display_reasons($reason_id);
4c79b5
4c79b5
		$show_notify = false;
4c79b5
4c79b5
		foreach ($post_info as $post_data)
4c79b5
		{
4c79b5
			if ($post_data['poster_id'] == ANONYMOUS)
4c79b5
			{
4c79b5
				continue;
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$show_notify = true;
4c79b5
				break;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'S_NOTIFY_POSTER'	=> $show_notify,
4c79b5
			'S_APPROVE'			=> false,
4c79b5
			'REASON'			=> $reason,
4c79b5
			'ADDITIONAL_MSG'	=> $additional_msg)
4c79b5
		);
4c79b5
4c79b5
		confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
4c79b5
	}
4c79b5
4c79b5
	$redirect = request_var('redirect', "index.$phpEx");
4c79b5
	$redirect = reapply_sid($redirect);
4c79b5
4c79b5
	if (!$success_msg)
4c79b5
	{
4c79b5
		redirect($redirect);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		meta_refresh(3, $redirect);
4c79b5
		trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", ''));
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>