ucp.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ucp.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,361 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package ucp
     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 +define('IN_PHPBB', true);
    1.18 +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
    1.19 +$phpEx = substr(strrchr(__FILE__, '.'), 1);
    1.20 +require($phpbb_root_path . 'common.' . $phpEx);
    1.21 +require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    1.22 +require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
    1.23 +
    1.24 +// Basic parameter data
    1.25 +$id 	= request_var('i', '');
    1.26 +$mode	= request_var('mode', '');
    1.27 +
    1.28 +if (in_array($mode, array('login', 'logout', 'confirm', 'sendpassword', 'activate')))
    1.29 +{
    1.30 +	define('IN_LOGIN', true);
    1.31 +}
    1.32 +
    1.33 +// Start session management
    1.34 +$user->session_begin();
    1.35 +$auth->acl($user->data);
    1.36 +$user->setup('ucp');
    1.37 +
    1.38 +// Setting a variable to let the style designer know where he is...
    1.39 +$template->assign_var('S_IN_UCP', true);
    1.40 +
    1.41 +$module = new p_master();
    1.42 +$default = false;
    1.43 +
    1.44 +// Basic "global" modes
    1.45 +switch ($mode)
    1.46 +{
    1.47 +	case 'activate':
    1.48 +		$module->load('ucp', 'activate');
    1.49 +		$module->display($user->lang['UCP_ACTIVATE']);
    1.50 +
    1.51 +		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
    1.52 +	break;
    1.53 +
    1.54 +	case 'resend_act':
    1.55 +		$module->load('ucp', 'resend');
    1.56 +		$module->display($user->lang['UCP_RESEND']);
    1.57 +	break;
    1.58 +
    1.59 +	case 'sendpassword':
    1.60 +		$module->load('ucp', 'remind');
    1.61 +		$module->display($user->lang['UCP_REMIND']);
    1.62 +	break;
    1.63 +
    1.64 +	case 'register':
    1.65 +		if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
    1.66 +		{
    1.67 +			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
    1.68 +		}
    1.69 +
    1.70 +		$module->load('ucp', 'register');
    1.71 +		$module->display($user->lang['REGISTER']);
    1.72 +	break;
    1.73 +
    1.74 +	case 'confirm':
    1.75 +		$module->load('ucp', 'confirm');
    1.76 +	break;
    1.77 +
    1.78 +	case 'login':
    1.79 +		if ($user->data['is_registered'])
    1.80 +		{
    1.81 +			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
    1.82 +		}
    1.83 +
    1.84 +		login_box(request_var('redirect', "index.$phpEx"));
    1.85 +	break;
    1.86 +
    1.87 +	case 'logout':
    1.88 +		if ($user->data['user_id'] != ANONYMOUS && isset($_GET['sid']) && !is_array($_GET['sid']) && $_GET['sid'] === $user->session_id)
    1.89 +		{
    1.90 +			$user->session_kill();
    1.91 +			$user->session_begin();
    1.92 +			$message = $user->lang['LOGOUT_REDIRECT'];
    1.93 +		}
    1.94 +		else
    1.95 +		{
    1.96 +			$message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
    1.97 +		}
    1.98 +		meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
    1.99 +
   1.100 +		$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
   1.101 +		trigger_error($message);
   1.102 +
   1.103 +	break;
   1.104 +
   1.105 +	case 'terms':
   1.106 +	case 'privacy':
   1.107 +
   1.108 +		$message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
   1.109 +		$title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
   1.110 +
   1.111 +		if (empty($user->lang[$message]))
   1.112 +		{
   1.113 +			if ($user->data['is_registered'])
   1.114 +			{
   1.115 +				redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
   1.116 +			}
   1.117 +
   1.118 +			login_box();
   1.119 +		}
   1.120 +
   1.121 +		$template->set_filenames(array(
   1.122 +			'body'		=> 'ucp_agreement.html')
   1.123 +		);
   1.124 +
   1.125 +		// Disable online list
   1.126 +		page_header($user->lang[$title], false);
   1.127 +
   1.128 +		$template->assign_vars(array(
   1.129 +			'S_AGREEMENT'			=> true,
   1.130 +			'AGREEMENT_TITLE'		=> $user->lang[$title],
   1.131 +			'AGREEMENT_TEXT'		=> sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
   1.132 +			'U_BACK'				=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
   1.133 +			'L_BACK'				=> $user->lang['BACK_TO_LOGIN'],
   1.134 +		));
   1.135 +
   1.136 +		page_footer();
   1.137 +
   1.138 +	break;
   1.139 +
   1.140 +	case 'delete_cookies':
   1.141 +
   1.142 +		// Delete Cookies with dynamic names (do NOT delete poll cookies)
   1.143 +		if (confirm_box(true))
   1.144 +		{
   1.145 +			$set_time = time() - 31536000;
   1.146 +
   1.147 +			foreach ($_COOKIE as $cookie_name => $cookie_data)
   1.148 +			{
   1.149 +				// Only delete board cookies, no other ones...
   1.150 +				if (strpos($cookie_name, $config['cookie_name'] . '_') !== 0)
   1.151 +				{
   1.152 +					continue;
   1.153 +				}
   1.154 +
   1.155 +				$cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
   1.156 +
   1.157 +				// Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_
   1.158 +				if (strpos($cookie_name, 'poll_') !== 0)
   1.159 +				{
   1.160 +					$user->set_cookie($cookie_name, '', $set_time);
   1.161 +				}
   1.162 +			}
   1.163 +
   1.164 +			$user->set_cookie('track', '', $set_time);
   1.165 +			$user->set_cookie('u', '', $set_time);
   1.166 +			$user->set_cookie('k', '', $set_time);
   1.167 +			$user->set_cookie('sid', '', $set_time);
   1.168 +
   1.169 +			// We destroy the session here, the user will be logged out nevertheless
   1.170 +			$user->session_kill();
   1.171 +			$user->session_begin();
   1.172 +
   1.173 +			meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
   1.174 +
   1.175 +			$message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
   1.176 +			trigger_error($message);
   1.177 +		}
   1.178 +		else
   1.179 +		{
   1.180 +			confirm_box(false, 'DELETE_COOKIES', '');
   1.181 +		}
   1.182 +
   1.183 +		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
   1.184 +
   1.185 +	break;
   1.186 +
   1.187 +	case 'switch_perm':
   1.188 +
   1.189 +		$user_id = request_var('u', 0);
   1.190 +
   1.191 +		$sql = 'SELECT *
   1.192 +			FROM ' . USERS_TABLE . '
   1.193 +			WHERE user_id = ' . (int) $user_id;
   1.194 +		$result = $db->sql_query($sql);
   1.195 +		$user_row = $db->sql_fetchrow($result);
   1.196 +		$db->sql_freeresult($result);
   1.197 +
   1.198 +		if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'] || !check_link_hash(request_var('hash', ''), 'switchperm'))
   1.199 +		{
   1.200 +			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
   1.201 +		}
   1.202 +
   1.203 +		include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
   1.204 +
   1.205 +		$auth_admin = new auth_admin();
   1.206 +		if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
   1.207 +		{
   1.208 +			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
   1.209 +		}
   1.210 +
   1.211 +		add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
   1.212 +
   1.213 +		$message = sprintf($user->lang['PERMISSIONS_TRANSFERRED'], $user_row['username']) . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
   1.214 +		trigger_error($message);
   1.215 +
   1.216 +	break;
   1.217 +
   1.218 +	case 'restore_perm':
   1.219 +
   1.220 +		if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
   1.221 +		{
   1.222 +			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
   1.223 +		}
   1.224 +
   1.225 +		$auth->acl_cache($user->data);
   1.226 +
   1.227 +		$sql = 'SELECT username
   1.228 +			FROM ' . USERS_TABLE . '
   1.229 +			WHERE user_id = ' . $user->data['user_perm_from'];
   1.230 +		$result = $db->sql_query($sql);
   1.231 +		$username = $db->sql_fetchfield('username');
   1.232 +		$db->sql_freeresult($result);
   1.233 +
   1.234 +		add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
   1.235 +
   1.236 +		$message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
   1.237 +		trigger_error($message);
   1.238 +
   1.239 +	break;
   1.240 +
   1.241 +	default:
   1.242 +		$default = true;
   1.243 +	break;
   1.244 +}
   1.245 +
   1.246 +// We use this approach because it does not impose large code changes
   1.247 +if (!$default)
   1.248 +{
   1.249 +	return true;
   1.250 +}
   1.251 +
   1.252 +// Only registered users can go beyond this point
   1.253 +if (!$user->data['is_registered'])
   1.254 +{
   1.255 +	if ($user->data['is_bot'])
   1.256 +	{
   1.257 +		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
   1.258 +	}
   1.259 +
   1.260 +	if ($id == 'pm' && $mode == 'view' && isset($_GET['p']))
   1.261 +	{
   1.262 +		$redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx?i=pm&p=" . request_var('p', 0));
   1.263 +		login_box($redirect_url, $user->lang['LOGIN_EXPLAIN_UCP']);
   1.264 +	}
   1.265 +
   1.266 +	login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
   1.267 +}
   1.268 +
   1.269 +// Instantiate module system and generate list of available modules
   1.270 +$module->list_modules('ucp');
   1.271 +
   1.272 +// Check if the zebra module is set
   1.273 +if ($module->is_active('zebra', 'friends'))
   1.274 +{
   1.275 +	// Output listing of friends online
   1.276 +	$update_time = $config['load_online_time'] * 60;
   1.277 +
   1.278 +	$sql = $db->sql_build_query('SELECT_DISTINCT', array(
   1.279 +		'SELECT'	=> 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
   1.280 +
   1.281 +		'FROM'		=> array(
   1.282 +			USERS_TABLE		=> 'u',
   1.283 +			ZEBRA_TABLE		=> 'z'
   1.284 +		),
   1.285 +
   1.286 +		'LEFT_JOIN'	=> array(
   1.287 +			array(
   1.288 +				'FROM'	=> array(SESSIONS_TABLE => 's'),
   1.289 +				'ON'	=> 's.session_user_id = z.zebra_id'
   1.290 +			)
   1.291 +		),
   1.292 +
   1.293 +		'WHERE'		=> 'z.user_id = ' . $user->data['user_id'] . '
   1.294 +			AND z.friend = 1
   1.295 +			AND u.user_id = z.zebra_id',
   1.296 +
   1.297 +		'GROUP_BY'	=> 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',
   1.298 +
   1.299 +		'ORDER_BY'	=> 'u.username_clean ASC',
   1.300 +	));
   1.301 +
   1.302 +	$result = $db->sql_query($sql);
   1.303 +
   1.304 +	while ($row = $db->sql_fetchrow($result))
   1.305 +	{
   1.306 +		$which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';
   1.307 +
   1.308 +		$template->assign_block_vars("friends_{$which}", array(
   1.309 +			'USER_ID'		=> $row['user_id'],
   1.310 +
   1.311 +			'U_PROFILE'		=> get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
   1.312 +			'USER_COLOUR'	=> get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
   1.313 +			'USERNAME'		=> get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
   1.314 +			'USERNAME_FULL'	=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
   1.315 +		);
   1.316 +	}
   1.317 +	$db->sql_freeresult($result);
   1.318 +}
   1.319 +
   1.320 +// Do not display subscribed topics/forums if not allowed
   1.321 +if (!$config['allow_topic_notify'] && !$config['allow_forum_notify'])
   1.322 +{
   1.323 +	$module->set_display('main', 'subscribed', false);
   1.324 +}
   1.325 +
   1.326 +// Do not display signature panel if not authed to do so
   1.327 +if (!$auth->acl_get('u_sig'))
   1.328 +{
   1.329 +	$module->set_display('profile', 'signature', false);
   1.330 +}
   1.331 +
   1.332 +// Select the active module
   1.333 +$module->set_active($id, $mode);
   1.334 +
   1.335 +// Load and execute the relevant module
   1.336 +$module->load_active();
   1.337 +
   1.338 +// Assign data to the template engine for the list of modules
   1.339 +$module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
   1.340 +
   1.341 +// Generate the page, do not display/query online list
   1.342 +$module->display($module->get_page_title(), false);
   1.343 +
   1.344 +/**
   1.345 +* Function for assigning a template var if the zebra module got included
   1.346 +*/
   1.347 +function _module_zebra($mode, &$module_row)
   1.348 +{
   1.349 +	global $template;
   1.350 +
   1.351 +	$template->assign_var('S_ZEBRA_ENABLED', true);
   1.352 +
   1.353 +	if ($mode == 'friends')
   1.354 +	{
   1.355 +		$template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
   1.356 +	}
   1.357 +
   1.358 +	if ($mode == 'foes')
   1.359 +	{
   1.360 +		$template->assign_var('S_ZEBRA_FOES_ENABLED', true);
   1.361 +	}
   1.362 +}
   1.363 +
   1.364 +?>
   1.365 \ No newline at end of file