includes/mcp/mcp_front.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/mcp/mcp_front.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,380 @@
     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 Front Panel
    1.24 +*/
    1.25 +function mcp_front_view($id, $mode, $action)
    1.26 +{
    1.27 +	global $phpEx, $phpbb_root_path, $config;
    1.28 +	global $template, $db, $user, $auth, $module;
    1.29 +
    1.30 +	// Latest 5 unapproved
    1.31 +	if ($module->loaded('queue'))
    1.32 +	{
    1.33 +		$forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_approve')));
    1.34 +		$post_list = array();
    1.35 +		$forum_names = array();
    1.36 +
    1.37 +		$forum_id = request_var('f', 0);
    1.38 +
    1.39 +		$template->assign_var('S_SHOW_UNAPPROVED', (!empty($forum_list)) ? true : false);
    1.40 +
    1.41 +		if (!empty($forum_list))
    1.42 +		{
    1.43 +			$sql = 'SELECT COUNT(post_id) AS total
    1.44 +				FROM ' . POSTS_TABLE . '
    1.45 +				WHERE forum_id IN (0, ' . implode(', ', $forum_list) . ')
    1.46 +					AND post_approved = 0';
    1.47 +			$result = $db->sql_query($sql);
    1.48 +			$total = (int) $db->sql_fetchfield('total');
    1.49 +			$db->sql_freeresult($result);
    1.50 +
    1.51 +			if ($total)
    1.52 +			{
    1.53 +				$global_id = $forum_list[0];
    1.54 +
    1.55 +				$sql = 'SELECT forum_id, forum_name
    1.56 +					FROM ' . FORUMS_TABLE . '
    1.57 +					WHERE ' . $db->sql_in_set('forum_id', $forum_list);
    1.58 +				$result = $db->sql_query($sql);
    1.59 +
    1.60 +				while ($row = $db->sql_fetchrow($result))
    1.61 +				{
    1.62 +					$forum_names[$row['forum_id']] = $row['forum_name'];
    1.63 +				}
    1.64 +				$db->sql_freeresult($result);
    1.65 +
    1.66 +				$sql = 'SELECT post_id
    1.67 +					FROM ' . POSTS_TABLE . '
    1.68 +					WHERE forum_id IN (0, ' . implode(', ', $forum_list) . ')
    1.69 +						AND post_approved = 0
    1.70 +					ORDER BY post_time DESC';
    1.71 +				$result = $db->sql_query_limit($sql, 5);
    1.72 +
    1.73 +				while ($row = $db->sql_fetchrow($result))
    1.74 +				{
    1.75 +					$post_list[] = $row['post_id'];
    1.76 +				}
    1.77 +				$db->sql_freeresult($result);
    1.78 +
    1.79 +				if (empty($post_list))
    1.80 +				{
    1.81 +					$total = 0;
    1.82 +				}
    1.83 +			}
    1.84 +
    1.85 +			if ($total)
    1.86 +			{
    1.87 +				$sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.username, u.username_clean, u.user_colour, t.topic_id, t.topic_title, t.topic_first_post_id, p.forum_id
    1.88 +					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
    1.89 +					WHERE ' . $db->sql_in_set('p.post_id', $post_list) . '
    1.90 +						AND t.topic_id = p.topic_id
    1.91 +						AND p.poster_id = u.user_id
    1.92 +					ORDER BY p.post_time DESC';
    1.93 +				$result = $db->sql_query($sql);
    1.94 +
    1.95 +				while ($row = $db->sql_fetchrow($result))
    1.96 +				{
    1.97 +					$global_topic = ($row['forum_id']) ? false : true;
    1.98 +					if ($global_topic)
    1.99 +					{
   1.100 +						$row['forum_id'] = $global_id;
   1.101 +					}
   1.102 +
   1.103 +					$template->assign_block_vars('unapproved', array(
   1.104 +						'U_POST_DETAILS'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']),
   1.105 +						'U_MCP_FORUM'		=> (!$global_topic) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=forum_view&amp;f=' . $row['forum_id']) : '',
   1.106 +						'U_MCP_TOPIC'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=topic_view&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
   1.107 +						'U_FORUM'			=> (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
   1.108 +						'U_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
   1.109 +
   1.110 +						'AUTHOR_FULL'		=> get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']),
   1.111 +						'AUTHOR'			=> get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour']),
   1.112 +						'AUTHOR_COLOUR'		=> get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour']),
   1.113 +						'U_AUTHOR'			=> get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour']),
   1.114 +
   1.115 +						'FORUM_NAME'	=> (!$global_topic) ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'],
   1.116 +						'POST_ID'		=> $row['post_id'],
   1.117 +						'TOPIC_TITLE'	=> $row['topic_title'],
   1.118 +						'SUBJECT'		=> ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
   1.119 +						'POST_TIME'		=> $user->format_date($row['post_time']))
   1.120 +					);
   1.121 +				}
   1.122 +				$db->sql_freeresult($result);
   1.123 +			}
   1.124 +
   1.125 +			$s_hidden_fields = build_hidden_fields(array(
   1.126 +				'redirect'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main' . (($forum_id) ? '&amp;f=' . $forum_id : ''))
   1.127 +			));
   1.128 +
   1.129 +			$template->assign_vars(array(
   1.130 +				'S_HIDDEN_FIELDS'		=> $s_hidden_fields,
   1.131 +				'S_MCP_QUEUE_ACTION'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue"),
   1.132 +			));
   1.133 +
   1.134 +			if ($total == 0)
   1.135 +			{
   1.136 +				$template->assign_vars(array(
   1.137 +					'L_UNAPPROVED_TOTAL'		=> $user->lang['UNAPPROVED_POSTS_ZERO_TOTAL'],
   1.138 +					'S_HAS_UNAPPROVED_POSTS'	=> false)
   1.139 +				);
   1.140 +			}
   1.141 +			else
   1.142 +			{
   1.143 +				$template->assign_vars(array(
   1.144 +					'L_UNAPPROVED_TOTAL'		=> ($total == 1) ? $user->lang['UNAPPROVED_POST_TOTAL'] : sprintf($user->lang['UNAPPROVED_POSTS_TOTAL'], $total),
   1.145 +					'S_HAS_UNAPPROVED_POSTS'	=> true)
   1.146 +				);
   1.147 +			}
   1.148 +		}
   1.149 +	}
   1.150 +
   1.151 +	// Latest 5 reported
   1.152 +	if ($module->loaded('reports'))
   1.153 +	{
   1.154 +		$forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_report')));
   1.155 +
   1.156 +		$template->assign_var('S_SHOW_REPORTS', (!empty($forum_list)) ? true : false);
   1.157 +
   1.158 +		if (!empty($forum_list))
   1.159 +		{
   1.160 +			$sql = 'SELECT COUNT(r.report_id) AS total
   1.161 +				FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
   1.162 +				WHERE r.post_id = p.post_id
   1.163 +					AND r.pm_id = 0
   1.164 +					AND r.report_closed = 0
   1.165 +					AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')';
   1.166 +			$result = $db->sql_query($sql);
   1.167 +			$total = (int) $db->sql_fetchfield('total');
   1.168 +			$db->sql_freeresult($result);
   1.169 +
   1.170 +			if ($total)
   1.171 +			{
   1.172 +				$global_id = $forum_list[0];
   1.173 +
   1.174 +				$sql = $db->sql_build_query('SELECT', array(
   1.175 +					'SELECT'	=> 'r.report_time, p.post_id, p.post_subject, p.post_time, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id, t.topic_id, t.topic_title, f.forum_id, f.forum_name',
   1.176 +
   1.177 +					'FROM'		=> array(
   1.178 +						REPORTS_TABLE			=> 'r',
   1.179 +						REPORTS_REASONS_TABLE	=> 'rr',
   1.180 +						TOPICS_TABLE			=> 't',
   1.181 +						USERS_TABLE				=> array('u', 'u2'),
   1.182 +						POSTS_TABLE				=> 'p'
   1.183 +					),
   1.184 +
   1.185 +					'LEFT_JOIN'	=> array(
   1.186 +						array(
   1.187 +							'FROM'	=> array(FORUMS_TABLE => 'f'),
   1.188 +							'ON'	=> 'f.forum_id = p.forum_id'
   1.189 +						)
   1.190 +					),
   1.191 +
   1.192 +					'WHERE'		=> 'r.post_id = p.post_id
   1.193 +						AND r.pm_id = 0
   1.194 +						AND r.report_closed = 0
   1.195 +						AND r.reason_id = rr.reason_id
   1.196 +						AND p.topic_id = t.topic_id
   1.197 +						AND r.user_id = u.user_id
   1.198 +						AND p.poster_id = u2.user_id
   1.199 +						AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')',
   1.200 +
   1.201 +					'ORDER_BY'	=> 'p.post_time DESC'
   1.202 +				));
   1.203 +				$result = $db->sql_query_limit($sql, 5);
   1.204 +
   1.205 +				while ($row = $db->sql_fetchrow($result))
   1.206 +				{
   1.207 +					$global_topic = ($row['forum_id']) ? false : true;
   1.208 +					if ($global_topic)
   1.209 +					{
   1.210 +						$row['forum_id'] = $global_id;
   1.211 +					}
   1.212 +
   1.213 +					$template->assign_block_vars('report', array(
   1.214 +						'U_POST_DETAILS'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id'] . "&amp;i=reports&amp;mode=report_details"),
   1.215 +						'U_MCP_FORUM'		=> (!$global_topic) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . "&amp;i=$id&amp;mode=forum_view") : '',
   1.216 +						'U_MCP_TOPIC'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . "&amp;i=$id&amp;mode=topic_view"),
   1.217 +						'U_FORUM'			=> (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
   1.218 +						'U_TOPIC'			=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
   1.219 +
   1.220 +						'REPORTER_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
   1.221 +						'REPORTER'			=> get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
   1.222 +						'REPORTER_COLOUR'	=> get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
   1.223 +						'U_REPORTER'		=> get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
   1.224 +
   1.225 +						'AUTHOR_FULL'		=> get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.226 +						'AUTHOR'			=> get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.227 +						'AUTHOR_COLOUR'		=> get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.228 +						'U_AUTHOR'			=> get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.229 +
   1.230 +						'FORUM_NAME'	=> (!$global_topic) ? $row['forum_name'] : $user->lang['GLOBAL_ANNOUNCEMENT'],
   1.231 +						'TOPIC_TITLE'	=> $row['topic_title'],
   1.232 +						'SUBJECT'		=> ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
   1.233 +						'REPORT_TIME'	=> $user->format_date($row['report_time']),
   1.234 +						'POST_TIME'		=> $user->format_date($row['post_time']),
   1.235 +					));
   1.236 +				}
   1.237 +			}
   1.238 +
   1.239 +			if ($total == 0)
   1.240 +			{
   1.241 +				$template->assign_vars(array(
   1.242 +					'L_REPORTS_TOTAL'	=>	$user->lang['REPORTS_ZERO_TOTAL'],
   1.243 +					'S_HAS_REPORTS'		=>	false)
   1.244 +				);
   1.245 +			}
   1.246 +			else
   1.247 +			{
   1.248 +				$template->assign_vars(array(
   1.249 +					'L_REPORTS_TOTAL'	=> ($total == 1) ? $user->lang['REPORT_TOTAL'] : sprintf($user->lang['REPORTS_TOTAL'], $total),
   1.250 +					'S_HAS_REPORTS'		=> true)
   1.251 +				);
   1.252 +			}
   1.253 +		}
   1.254 +	}
   1.255 +
   1.256 +	// Latest 5 reported PMs
   1.257 +	if ($module->loaded('pm_reports') && $auth->acl_getf_global('m_report'))
   1.258 +	{
   1.259 +		$template->assign_var('S_SHOW_PM_REPORTS', true);
   1.260 +		$user->add_lang(array('ucp'));
   1.261 +
   1.262 +		$sql = 'SELECT COUNT(r.report_id) AS total
   1.263 +			FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p
   1.264 +			WHERE r.post_id = 0
   1.265 +				AND r.pm_id = p.msg_id
   1.266 +				AND r.report_closed = 0';
   1.267 +		$result = $db->sql_query($sql);
   1.268 +		$total = (int) $db->sql_fetchfield('total');
   1.269 +		$db->sql_freeresult($result);
   1.270 +
   1.271 +		if ($total)
   1.272 +		{
   1.273 +			include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
   1.274 +
   1.275 +			$sql = $db->sql_build_query('SELECT', array(
   1.276 +				'SELECT'	=> 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id',
   1.277 +
   1.278 +				'FROM'		=> array(
   1.279 +					REPORTS_TABLE			=> 'r',
   1.280 +					REPORTS_REASONS_TABLE	=> 'rr',
   1.281 +					USERS_TABLE				=> array('u', 'u2'),
   1.282 +					PRIVMSGS_TABLE				=> 'p'
   1.283 +				),
   1.284 +
   1.285 +				'WHERE'		=> 'r.pm_id = p.msg_id
   1.286 +					AND r.post_id = 0
   1.287 +					AND r.report_closed = 0
   1.288 +					AND r.reason_id = rr.reason_id
   1.289 +					AND r.user_id = u.user_id
   1.290 +					AND p.author_id = u2.user_id',
   1.291 +
   1.292 +				'ORDER_BY'	=> 'p.message_time DESC'
   1.293 +			));
   1.294 +			$result = $db->sql_query_limit($sql, 5);
   1.295 +
   1.296 +			$pm_by_id = $pm_list = array();
   1.297 +			while ($row = $db->sql_fetchrow($result))
   1.298 +			{
   1.299 +				$pm_by_id[(int) $row['msg_id']] = $row;
   1.300 +				$pm_list[] = (int) $row['msg_id'];
   1.301 +			}
   1.302 +
   1.303 +			$address_list = get_recipient_strings($pm_by_id);
   1.304 +
   1.305 +			foreach ($pm_list as $message_id)
   1.306 +			{
   1.307 +				$row = $pm_by_id[$message_id];
   1.308 +
   1.309 +				$template->assign_block_vars('pm_report', array(
   1.310 +					'U_PM_DETAILS'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'r=' . $row['report_id'] . "&amp;i=pm_reports&amp;mode=pm_report_details"),
   1.311 +
   1.312 +					'REPORTER_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
   1.313 +					'REPORTER'			=> get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
   1.314 +					'REPORTER_COLOUR'	=> get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
   1.315 +					'U_REPORTER'		=> get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
   1.316 +
   1.317 +					'PM_AUTHOR_FULL'		=> get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.318 +					'PM_AUTHOR'			=> get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.319 +					'PM_AUTHOR_COLOUR'		=> get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.320 +					'U_PM_AUTHOR'			=> get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']),
   1.321 +
   1.322 +					'PM_SUBJECT'		=> $row['message_subject'],
   1.323 +					'REPORT_TIME'		=> $user->format_date($row['report_time']),
   1.324 +					'PM_TIME'			=> $user->format_date($row['message_time']),
   1.325 +					'RECIPIENTS'		=> implode(', ', $address_list[$row['msg_id']]),
   1.326 +				));
   1.327 +			}
   1.328 +		}
   1.329 +
   1.330 +		if ($total == 0)
   1.331 +		{
   1.332 +			$template->assign_vars(array(
   1.333 +				'L_PM_REPORTS_TOTAL'	=>	$user->lang['PM_REPORTS_ZERO_TOTAL'],
   1.334 +				'S_HAS_PM_REPORTS'		=>	false)
   1.335 +			);
   1.336 +		}
   1.337 +		else
   1.338 +		{
   1.339 +			$template->assign_vars(array(
   1.340 +				'L_PM_REPORTS_TOTAL'	=> ($total == 1) ? $user->lang['PM_REPORT_TOTAL'] : sprintf($user->lang['PM_REPORTS_TOTAL'], $total),
   1.341 +				'S_HAS_PM_REPORTS'		=> true)
   1.342 +			);
   1.343 +		}
   1.344 +	}
   1.345 +
   1.346 +	// Latest 5 logs
   1.347 +	if ($module->loaded('logs'))
   1.348 +	{
   1.349 +		$forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
   1.350 +
   1.351 +		if (!empty($forum_list))
   1.352 +		{
   1.353 +			// Add forum_id 0 for global announcements
   1.354 +			$forum_list[] = 0;
   1.355 +
   1.356 +			$log_count = false;
   1.357 +			$log = array();
   1.358 +			view_log('mod', $log, $log_count, 5, 0, $forum_list);
   1.359 +
   1.360 +			foreach ($log as $row)
   1.361 +			{
   1.362 +				$template->assign_block_vars('log', array(
   1.363 +					'USERNAME'		=> $row['username_full'],
   1.364 +					'IP'			=> $row['ip'],
   1.365 +					'TIME'			=> $user->format_date($row['time']),
   1.366 +					'ACTION'		=> $row['action'],
   1.367 +					'U_VIEW_TOPIC'	=> (!empty($row['viewtopic'])) ? $row['viewtopic'] : '',
   1.368 +					'U_VIEWLOGS'	=> (!empty($row['viewlogs'])) ? $row['viewlogs'] : '')
   1.369 +				);
   1.370 +			}
   1.371 +		}
   1.372 +
   1.373 +		$template->assign_vars(array(
   1.374 +			'S_SHOW_LOGS'	=> (!empty($forum_list)) ? true : false,
   1.375 +			'S_HAS_LOGS'	=> (!empty($log)) ? true : false)
   1.376 +		);
   1.377 +	}
   1.378 +
   1.379 +	$template->assign_var('S_MCP_ACTION', append_sid("{$phpbb_root_path}mcp.$phpEx"));
   1.380 +	make_jumpbox(append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=forum_view'), 0, false, 'm_', true);
   1.381 +}
   1.382 +
   1.383 +?>
   1.384 \ No newline at end of file