Blame Extras/phpBB/3.0.4/includes/acp/acp_users.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package acp
4c79b5
* @version $Id: acp_users.php 8831 2008-09-05 19:02:36Z toonarmy $
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
* @package acp
4c79b5
*/
4c79b5
class acp_users
4c79b5
{
4c79b5
	var $u_action;
4c79b5
	var $p_master;
4c79b5
4c79b5
	function acp_users(&$p_master)
4c79b5
	{
4c79b5
		$this->p_master = &$p_master;
4c79b5
	}
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $config, $db, $user, $auth, $template, $cache;
4c79b5
		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
4c79b5
4c79b5
		$user->add_lang(array('posting', 'ucp', 'acp/users'));
4c79b5
		$this->tpl_name = 'acp_users';
4c79b5
		$this->page_title = 'ACP_USER_' . strtoupper($mode);
4c79b5
4c79b5
		$error		= array();
4c79b5
		$username	= utf8_normalize_nfc(request_var('username', '', true));
4c79b5
		$user_id	= request_var('u', 0);
4c79b5
		$action		= request_var('action', '');
4c79b5
4c79b5
		$submit		= (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false;
4c79b5
4c79b5
		$form_name = 'acp_users';
4c79b5
		add_form_key($form_name);
4c79b5
4c79b5
		// Whois (special case)
4c79b5
		if ($action == 'whois')
4c79b5
		{
4c79b5
			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
			$this->page_title = 'WHOIS';
4c79b5
			$this->tpl_name = 'simple_body';
4c79b5
4c79b5
			$user_ip = request_var('user_ip', '');
4c79b5
			$domain = gethostbyaddr($user_ip);
4c79b5
			$ipwhois = user_ipwhois($user_ip);
4c79b5
4c79b5
			$template->assign_vars(array(
4c79b5
				'MESSAGE_TITLE'		=> sprintf($user->lang['IP_WHOIS_FOR'], $domain),
4c79b5
				'MESSAGE_TEXT'		=> nl2br($ipwhois))
4c79b5
			);
4c79b5
4c79b5
			return;
4c79b5
		}
4c79b5
4c79b5
		// Show user selection mask
4c79b5
		if (!$username && !$user_id)
4c79b5
		{
4c79b5
			$this->page_title = 'SELECT_USER';
4c79b5
4c79b5
			$template->assign_vars(array(
4c79b5
				'U_ACTION'			=> $this->u_action,
4c79b5
				'ANONYMOUS_USER_ID'	=> ANONYMOUS,
4c79b5
4c79b5
				'S_SELECT_USER'		=> true,
4c79b5
				'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=select_user&field=username&select_single=true'),
4c79b5
			));
4c79b5
4c79b5
			return;
4c79b5
		}
4c79b5
4c79b5
		if (!$user_id)
4c79b5
		{
4c79b5
			$sql = 'SELECT user_id
4c79b5
				FROM ' . USERS_TABLE . "
4c79b5
				WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$user_id = (int) $db->sql_fetchfield('user_id');
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (!$user_id)
4c79b5
			{
4c79b5
				trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Generate content for all modes
4c79b5
		$sql = 'SELECT u.*, s.*
4c79b5
			FROM ' . USERS_TABLE . ' u
4c79b5
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
4c79b5
			WHERE u.user_id = ' . $user_id . '
4c79b5
			ORDER BY s.session_time DESC';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$user_row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (!$user_row)
4c79b5
		{
4c79b5
			trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
		}
4c79b5
4c79b5
		// Generate overall "header" for user admin
4c79b5
		$s_form_options = '';
4c79b5
4c79b5
		// Build modes dropdown list
4c79b5
		$sql = 'SELECT module_mode, module_auth
4c79b5
			FROM ' . MODULES_TABLE . "
4c79b5
			WHERE module_basename = 'users'
4c79b5
				AND module_enabled = 1
4c79b5
				AND module_class = 'acp'
4c79b5
			ORDER BY left_id, module_mode";
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$dropdown_modes = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			if (!$this->p_master->module_auth($row['module_auth']))
4c79b5
			{
4c79b5
				continue;
4c79b5
			}
4c79b5
4c79b5
			$dropdown_modes[$row['module_mode']] = true;
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		foreach ($dropdown_modes as $module_mode => $null)
4c79b5
		{
4c79b5
			$selected = ($mode == $module_mode) ? ' selected="selected"' : '';
4c79b5
			$s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'U_BACK'			=> $this->u_action,
4c79b5
			'U_MODE_SELECT'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&u=$user_id"),
4c79b5
			'U_ACTION'			=> $this->u_action . '&u=' . $user_id,
4c79b5
			'S_FORM_OPTIONS'	=> $s_form_options,
4c79b5
			'MANAGED_USERNAME'	=> $user_row['username'])
4c79b5
		);
4c79b5
4c79b5
		// Prevent normal users/admins change/view founders if they are not a founder by themselves
4c79b5
		if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER)
4c79b5
		{
4c79b5
			trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
		}
4c79b5
4c79b5
		switch ($mode)
4c79b5
		{
4c79b5
			case 'overview':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
				$user->add_lang('acp/ban');
4c79b5
4c79b5
				$delete			= request_var('delete', 0);
4c79b5
				$delete_type	= request_var('delete_type', '');
4c79b5
				$ip				= request_var('ip', 'ip');
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					// You can't delete the founder
4c79b5
					if ($delete && $user_row['user_type'] != USER_FOUNDER)
4c79b5
					{
4c79b5
						if (!$auth->acl_get('a_userdel'))
4c79b5
						{
4c79b5
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
						}
4c79b5
4c79b5
						// Check if the user wants to remove himself or the guest user account
4c79b5
						if ($user_id == ANONYMOUS)
4c79b5
						{
4c79b5
							trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
						}
4c79b5
4c79b5
						if ($user_id == $user->data['user_id'])
4c79b5
						{
4c79b5
							trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
						}
4c79b5
4c79b5
						if (confirm_box(true))
4c79b5
						{
4c79b5
							user_delete($delete_type, $user_id, $user_row['username']);
4c79b5
4c79b5
							add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
4c79b5
							trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
								'u'				=> $user_id,
4c79b5
								'i'				=> $id,
4c79b5
								'mode'			=> $mode,
4c79b5
								'action'		=> $action,
4c79b5
								'update'		=> true,
4c79b5
								'delete'		=> 1,
4c79b5
								'delete_type'	=> $delete_type))
4c79b5
							);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					// Handle quicktool actions
4c79b5
					switch ($action)
4c79b5
					{
4c79b5
						case 'banuser':
4c79b5
						case 'banemail':
4c79b5
						case 'banip':
4c79b5
4c79b5
							if ($user_id == $user->data['user_id'])
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($user_row['user_type'] == USER_FOUNDER)
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if (!check_form_key($form_name))
4c79b5
							{
4c79b5
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							$ban = array();
4c79b5
4c79b5
							switch ($action)
4c79b5
							{
4c79b5
								case 'banuser':
4c79b5
									$ban[] = $user_row['username'];
4c79b5
									$reason = 'USER_ADMIN_BAN_NAME_REASON';
4c79b5
									$log = 'LOG_USER_BAN_USER';
4c79b5
								break;
4c79b5
4c79b5
								case 'banemail':
4c79b5
									$ban[] = $user_row['user_email'];
4c79b5
									$reason = 'USER_ADMIN_BAN_EMAIL_REASON';
4c79b5
									$log = 'LOG_USER_BAN_EMAIL';
4c79b5
								break;
4c79b5
4c79b5
								case 'banip':
4c79b5
									$ban[] = $user_row['user_ip'];
4c79b5
4c79b5
									$sql = 'SELECT DISTINCT poster_ip
4c79b5
										FROM ' . POSTS_TABLE . "
4c79b5
										WHERE poster_id = $user_id";
4c79b5
									$result = $db->sql_query($sql);
4c79b5
4c79b5
									while ($row = $db->sql_fetchrow($result))
4c79b5
									{
4c79b5
										$ban[] = $row['poster_ip'];
4c79b5
									}
4c79b5
									$db->sql_freeresult($result);
4c79b5
4c79b5
									$reason = 'USER_ADMIN_BAN_IP_REASON';
4c79b5
									$log = 'LOG_USER_BAN_IP';
4c79b5
								break;
4c79b5
							}
4c79b5
4c79b5
							$ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
4c79b5
							$ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));
4c79b5
4c79b5
							// Log not used at the moment, we simply utilize the ban function.
4c79b5
							$result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
4c79b5
4c79b5
							trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
4c79b5
						break;
4c79b5
4c79b5
						case 'reactivate':
4c79b5
4c79b5
							if ($user_id == $user->data['user_id'])
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if (!check_form_key($form_name))
4c79b5
							{
4c79b5
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($user_row['user_type'] == USER_FOUNDER)
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($user_row['user_type'] == USER_IGNORE)
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($config['email_enable'])
4c79b5
							{
4c79b5
								include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
4c79b5
4c79b5
								$server_url = generate_board_url();
4c79b5
4c79b5
								$user_actkey = gen_rand_string(10);
4c79b5
								$key_len = 54 - (strlen($server_url));
4c79b5
								$key_len = ($key_len > 6) ? $key_len : 6;
4c79b5
								$user_actkey = substr($user_actkey, 0, $key_len);
4c79b5
								$email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive';
4c79b5
4c79b5
								if ($user_row['user_type'] == USER_NORMAL)
4c79b5
								{
4c79b5
									user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
4c79b5
4c79b5
									$sql = 'UPDATE ' . USERS_TABLE . "
4c79b5
										SET user_actkey = '" . $db->sql_escape($user_actkey) . "'
4c79b5
										WHERE user_id = $user_id";
4c79b5
									$db->sql_query($sql);
4c79b5
								}
4c79b5
								else
4c79b5
								{
4c79b5
									// Grabbing the last confirm key - we only send a reminder
4c79b5
									$sql = 'SELECT user_actkey
4c79b5
										FROM ' . USERS_TABLE . '
4c79b5
										WHERE user_id = ' . $user_id;
4c79b5
									$result = $db->sql_query($sql);
4c79b5
									$user_actkey = (string) $db->sql_fetchfield('user_actkey');
4c79b5
									$db->sql_freeresult($result);
4c79b5
								}
4c79b5
4c79b5
								$messenger = new messenger(false);
4c79b5
4c79b5
								$messenger->template($email_template, $user_row['user_lang']);
4c79b5
4c79b5
								$messenger->to($user_row['user_email'], $user_row['username']);
4c79b5
4c79b5
								$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
4c79b5
								$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
4c79b5
								$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
4c79b5
								$messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
4c79b5
4c79b5
								$messenger->assign_vars(array(
4c79b5
									'WELCOME_MSG'	=> htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
4c79b5
									'USERNAME'		=> htmlspecialchars_decode($user_row['username']),
4c79b5
									'U_ACTIVATE'	=> "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
4c79b5
								);
4c79b5
4c79b5
								$messenger->send(NOTIFY_EMAIL);
4c79b5
4c79b5
								add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
4c79b5
								add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
4c79b5
4c79b5
								trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
							}
4c79b5
4c79b5
						break;
4c79b5
4c79b5
						case 'active':
4c79b5
4c79b5
							if ($user_id == $user->data['user_id'])
4c79b5
							{
4c79b5
								// It is only deactivation since the user is already activated (else he would not have reached this page)
4c79b5
								trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if (!check_form_key($form_name))
4c79b5
							{
4c79b5
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($user_row['user_type'] == USER_FOUNDER)
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($user_row['user_type'] == USER_IGNORE)
4c79b5
							{
4c79b5
								trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							user_active_flip('flip', $user_id);
4c79b5
4c79b5
							$message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
4c79b5
							$log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
4c79b5
4c79b5
							add_log('admin', $log, $user_row['username']);
4c79b5
							add_log('user', $user_id, $log . '_USER');
4c79b5
4c79b5
							trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
4c79b5
						break;
4c79b5
4c79b5
						case 'delsig':
4c79b5
4c79b5
							if (!check_form_key($form_name))
4c79b5
							{
4c79b5
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							$sql_ary = array(
4c79b5
								'user_sig'					=> '',
4c79b5
								'user_sig_bbcode_uid'		=> '',
4c79b5
								'user_sig_bbcode_bitfield'	=> ''
4c79b5
							);
4c79b5
4c79b5
							$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
4c79b5
								WHERE user_id = $user_id";
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
4c79b5
							add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
4c79b5
4c79b5
							trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
4c79b5
						break;
4c79b5
4c79b5
						case 'delavatar':
4c79b5
4c79b5
							if (!check_form_key($form_name))
4c79b5
							{
4c79b5
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							$sql_ary = array(
4c79b5
								'user_avatar'			=> '',
4c79b5
								'user_avatar_type'		=> 0,
4c79b5
								'user_avatar_width'		=> 0,
4c79b5
								'user_avatar_height'	=> 0,
4c79b5
							);
4c79b5
4c79b5
							$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
4c79b5
								WHERE user_id = $user_id";
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							// Delete old avatar if present
4c79b5
							if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY)
4c79b5
							{
4c79b5
								avatar_delete('user', $user_row);
4c79b5
							}
4c79b5
4c79b5
							add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
4c79b5
							add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
4c79b5
4c79b5
							trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
						break;
4c79b5
4c79b5
						case 'delposts':
4c79b5
4c79b5
							if (confirm_box(true))
4c79b5
							{
4c79b5
								// Delete posts, attachments, etc.
4c79b5
								delete_posts('poster_id', $user_id);
4c79b5
4c79b5
								add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
4c79b5
								trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
									'u'				=> $user_id,
4c79b5
									'i'				=> $id,
4c79b5
									'mode'			=> $mode,
4c79b5
									'action'		=> $action,
4c79b5
									'update'		=> true))
4c79b5
								);
4c79b5
							}
4c79b5
4c79b5
						break;
4c79b5
4c79b5
						case 'delattach':
4c79b5
4c79b5
							if (confirm_box(true))
4c79b5
							{
4c79b5
								delete_attachments('user', $user_id);
4c79b5
4c79b5
								add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
4c79b5
								trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
									'u'				=> $user_id,
4c79b5
									'i'				=> $id,
4c79b5
									'mode'			=> $mode,
4c79b5
									'action'		=> $action,
4c79b5
									'update'		=> true))
4c79b5
								);
4c79b5
							}
4c79b5
4c79b5
						break;
4c79b5
4c79b5
						case 'moveposts':
4c79b5
4c79b5
							if (!check_form_key($form_name))
4c79b5
							{
4c79b5
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							$user->add_lang('acp/forums');
4c79b5
4c79b5
							$new_forum_id = request_var('new_f', 0);
4c79b5
4c79b5
							if (!$new_forum_id)
4c79b5
							{
4c79b5
								$this->page_title = 'USER_ADMIN_MOVE_POSTS';
4c79b5
4c79b5
								$template->assign_vars(array(
4c79b5
									'S_SELECT_FORUM'		=> true,
4c79b5
									'U_ACTION'				=> $this->u_action . "&action=$action&u=$user_id",
4c79b5
									'U_BACK'				=> $this->u_action . "&u=$user_id",
4c79b5
									'S_FORUM_OPTIONS'		=> make_forum_select(false, false, false, true))
4c79b5
								);
4c79b5
4c79b5
								return;
4c79b5
							}
4c79b5
4c79b5
							// Is the new forum postable to?
4c79b5
							$sql = 'SELECT forum_name, forum_type
4c79b5
								FROM ' . FORUMS_TABLE . "
4c79b5
								WHERE forum_id = $new_forum_id";
4c79b5
							$result = $db->sql_query($sql);
4c79b5
							$forum_info = $db->sql_fetchrow($result);
4c79b5
							$db->sql_freeresult($result);
4c79b5
4c79b5
							if (!$forum_info)
4c79b5
							{
4c79b5
								trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($forum_info['forum_type'] != FORUM_POST)
4c79b5
							{
4c79b5
								trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							// Two stage?
4c79b5
							// Move topics comprising only posts from this user
4c79b5
							$topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
4c79b5
							$forum_id_ary = array($new_forum_id);
4c79b5
4c79b5
							$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
4c79b5
								FROM ' . POSTS_TABLE . "
4c79b5
								WHERE poster_id = $user_id
4c79b5
									AND forum_id <> $new_forum_id
4c79b5
								GROUP BY topic_id";
4c79b5
							$result = $db->sql_query($sql);
4c79b5
4c79b5
							while ($row = $db->sql_fetchrow($result))
4c79b5
							{
4c79b5
								$topic_id_ary[$row['topic_id']] = $row['total_posts'];
4c79b5
							}
4c79b5
							$db->sql_freeresult($result);
4c79b5
4c79b5
							if (sizeof($topic_id_ary))
4c79b5
							{
4c79b5
								$sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment
4c79b5
									FROM ' . TOPICS_TABLE . '
4c79b5
									WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
4c79b5
								$result = $db->sql_query($sql);
4c79b5
4c79b5
								while ($row = $db->sql_fetchrow($result))
4c79b5
								{
4c79b5
									if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
4c79b5
									{
4c79b5
										$move_topic_ary[] = $row['topic_id'];
4c79b5
									}
4c79b5
									else
4c79b5
									{
4c79b5
										$move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
4c79b5
										$move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0;
4c79b5
									}
4c79b5
4c79b5
									$forum_id_ary[] = $row['forum_id'];
4c79b5
								}
4c79b5
								$db->sql_freeresult($result);
4c79b5
							}
4c79b5
4c79b5
							// Entire topic comprises posts by this user, move these topics
4c79b5
							if (sizeof($move_topic_ary))
4c79b5
							{
4c79b5
								move_topics($move_topic_ary, $new_forum_id, false);
4c79b5
							}
4c79b5
4c79b5
							if (sizeof($move_post_ary))
4c79b5
							{
4c79b5
								// Create new topic
4c79b5
								// Update post_ids, report_ids, attachment_ids
4c79b5
								foreach ($move_post_ary as $topic_id => $post_ary)
4c79b5
								{
4c79b5
									// Create new topic
4c79b5
									$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
4c79b5
										'topic_poster'				=> $user_id,
4c79b5
										'topic_time'				=> time(),
4c79b5
										'forum_id' 					=> $new_forum_id,
4c79b5
										'icon_id'					=> 0,
4c79b5
										'topic_approved'			=> 1,
4c79b5
										'topic_title' 				=> $post_ary['title'],
4c79b5
										'topic_first_poster_name'	=> $user_row['username'],
4c79b5
										'topic_type'				=> POST_NORMAL,
4c79b5
										'topic_time_limit'			=> 0,
4c79b5
										'topic_attachment'			=> $post_ary['attach'])
4c79b5
									);
4c79b5
									$db->sql_query($sql);
4c79b5
4c79b5
									$new_topic_id = $db->sql_nextid();
4c79b5
4c79b5
									// Move posts
4c79b5
									$sql = 'UPDATE ' . POSTS_TABLE . "
4c79b5
										SET forum_id = $new_forum_id, topic_id = $new_topic_id
4c79b5
										WHERE topic_id = $topic_id
4c79b5
											AND poster_id = $user_id";
4c79b5
									$db->sql_query($sql);
4c79b5
4c79b5
									if ($post_ary['attach'])
4c79b5
									{
4c79b5
										$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
4c79b5
											SET topic_id = $new_topic_id
4c79b5
											WHERE topic_id = $topic_id
4c79b5
												AND poster_id = $user_id";
4c79b5
										$db->sql_query($sql);
4c79b5
									}
4c79b5
4c79b5
									$new_topic_id_ary[] = $new_topic_id;
4c79b5
								}
4c79b5
							}
4c79b5
4c79b5
							$forum_id_ary = array_unique($forum_id_ary);
4c79b5
							$topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
4c79b5
4c79b5
							if (sizeof($topic_id_ary))
4c79b5
							{
4c79b5
								sync('topic_reported', 'topic_id', $topic_id_ary);
4c79b5
								sync('topic', 'topic_id', $topic_id_ary);
4c79b5
							}
4c79b5
4c79b5
							if (sizeof($forum_id_ary))
4c79b5
							{
4c79b5
								sync('forum', 'forum_id', $forum_id_ary, false, true);
4c79b5
							}
4c79b5
4c79b5
4c79b5
							add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
4c79b5
							add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
4c79b5
4c79b5
							trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
4c79b5
						break;
4c79b5
					}
4c79b5
4c79b5
					// Handle registration info updates
4c79b5
					$data = array(
4c79b5
						'username'			=> utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
4c79b5
						'user_founder'		=> request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
4c79b5
						'email'				=> strtolower(request_var('user_email', $user_row['user_email'])),
4c79b5
						'email_confirm'		=> strtolower(request_var('email_confirm', '')),
4c79b5
						'new_password'		=> request_var('new_password', '', true),
4c79b5
						'password_confirm'	=> request_var('password_confirm', '', true),
4c79b5
					);
4c79b5
4c79b5
					// Validation data - we do not check the password complexity setting here
4c79b5
					$check_ary = array(
4c79b5
						'new_password'		=> array(
4c79b5
							array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
4c79b5
							array('password')),
4c79b5
						'password_confirm'	=> array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
4c79b5
					);
4c79b5
4c79b5
					// Check username if altered
4c79b5
					if ($data['username'] != $user_row['username'])
4c79b5
					{
4c79b5
						$check_ary += array(
4c79b5
							'username'			=> array(
4c79b5
								array('string', false, $config['min_name_chars'], $config['max_name_chars']),
4c79b5
								array('username', $user_row['username'])
4c79b5
							),
4c79b5
						);
4c79b5
					}
4c79b5
4c79b5
					// Check email if altered
4c79b5
					if ($data['email'] != $user_row['user_email'])
4c79b5
					{
4c79b5
						$check_ary += array(
4c79b5
							'email'				=> array(
4c79b5
								array('string', false, 6, 60),
4c79b5
								array('email', $user_row['user_email'])
4c79b5
							),
4c79b5
							'email_confirm'		=> array('string', true, 6, 60)
4c79b5
						);
4c79b5
					}
4c79b5
4c79b5
					$error = validate_data($data, $check_ary);
4c79b5
4c79b5
					if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
4c79b5
					{
4c79b5
						$error[] = 'NEW_PASSWORD_ERROR';
4c79b5
					}
4c79b5
4c79b5
					if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email'])
4c79b5
					{
4c79b5
						$error[] = 'NEW_EMAIL_ERROR';
4c79b5
					}
4c79b5
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						$error[] = 'FORM_INVALID';
4c79b5
					}
4c79b5
4c79b5
					// Which updates do we need to do?
4c79b5
					$update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
4c79b5
					$update_password = ($data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password'])) ? true : false;
4c79b5
					$update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						$sql_ary = array();
4c79b5
4c79b5
						if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
4c79b5
						{
4c79b5
							// Only allow founders updating the founder status...
4c79b5
							if ($user->data['user_type'] == USER_FOUNDER)
4c79b5
							{
4c79b5
								// Setting a normal member to be a founder
4c79b5
								if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
4c79b5
								{
4c79b5
									// Make sure the user is not setting an Inactive or ignored user to be a founder
4c79b5
									if ($user_row['user_type'] == USER_IGNORE)
4c79b5
									{
4c79b5
										trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
									}
4c79b5
4c79b5
									if ($user_row['user_type'] == USER_INACTIVE)
4c79b5
									{
4c79b5
										trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
									}
4c79b5
4c79b5
									$sql_ary['user_type'] = USER_FOUNDER;
4c79b5
								}
4c79b5
								else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
4c79b5
								{
4c79b5
									// Check if at least one founder is present
4c79b5
									$sql = 'SELECT user_id
4c79b5
										FROM ' . USERS_TABLE . '
4c79b5
										WHERE user_type = ' . USER_FOUNDER . '
4c79b5
											AND user_id <> ' . $user_id;
4c79b5
									$result = $db->sql_query_limit($sql, 1);
4c79b5
									$row = $db->sql_fetchrow($result);
4c79b5
									$db->sql_freeresult($result);
4c79b5
4c79b5
									if ($row)
4c79b5
									{
4c79b5
										$sql_ary['user_type'] = USER_NORMAL;
4c79b5
									}
4c79b5
									else
4c79b5
									{
4c79b5
										trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
									}
4c79b5
								}
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						if ($update_username !== false)
4c79b5
						{
4c79b5
							$sql_ary['username'] = $update_username;
4c79b5
							$sql_ary['username_clean'] = utf8_clean_string($update_username);
4c79b5
4c79b5
							add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
4c79b5
						}
4c79b5
4c79b5
						if ($update_email !== false)
4c79b5
						{
4c79b5
							$sql_ary += array(
4c79b5
								'user_email'		=> $update_email,
4c79b5
								'user_email_hash'	=> crc32($update_email) . strlen($update_email)
4c79b5
							);
4c79b5
4c79b5
							add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
4c79b5
						}
4c79b5
4c79b5
						if ($update_password)
4c79b5
						{
4c79b5
							$sql_ary += array(
4c79b5
								'user_password'		=> phpbb_hash($data['new_password']),
4c79b5
								'user_passchg'		=> time(),
4c79b5
								'user_pass_convert'	=> 0,
4c79b5
							);
4c79b5
4c79b5
							$user->reset_login_keys($user_id);
4c79b5
							add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
4c79b5
						}
4c79b5
4c79b5
						if (sizeof($sql_ary))
4c79b5
						{
4c79b5
							$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
4c79b5
								WHERE user_id = ' . $user_id;
4c79b5
							$db->sql_query($sql);
4c79b5
						}
4c79b5
4c79b5
						if ($update_username)
4c79b5
						{
4c79b5
							user_update_name($user_row['username'], $update_username);
4c79b5
						}
4c79b5
4c79b5
						// Let the users permissions being updated
4c79b5
						$auth->acl_clear_prefetch($user_id);
4c79b5
4c79b5
						add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
4c79b5
4c79b5
						trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
					}
4c79b5
4c79b5
					// Replace "error" strings with their real, localised form
4c79b5
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
4c79b5
				}
4c79b5
4c79b5
				if ($user_id == $user->data['user_id'])
4c79b5
				{
4c79b5
					$quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$quick_tool_ary = array();
4c79b5
4c79b5
					if ($user_row['user_type'] != USER_FOUNDER)
4c79b5
					{
4c79b5
						$quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
4c79b5
					}
4c79b5
4c79b5
					if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
4c79b5
					{
4c79b5
						$quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
4c79b5
					}
4c79b5
4c79b5
					$quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
4c79b5
4c79b5
					if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
4c79b5
					{
4c79b5
						$quick_tool_ary['reactivate'] = 'FORCE';
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
4c79b5
				foreach ($quick_tool_ary as $value => $lang)
4c79b5
				{
4c79b5
					$s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
4c79b5
				}
4c79b5
4c79b5
				if ($config['load_onlinetrack'])
4c79b5
				{
4c79b5
					$sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
4c79b5
						FROM ' . SESSIONS_TABLE . "
4c79b5
						WHERE session_user_id = $user_id";
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$row = $db->sql_fetchrow($result);
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					$user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
4c79b5
					$user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
4c79b5
					unset($row);
4c79b5
				}
4c79b5
4c79b5
				$last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];
4c79b5
4c79b5
				$inactive_reason = '';
4c79b5
				if ($user_row['user_type'] == USER_INACTIVE)
4c79b5
				{
4c79b5
					$inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
4c79b5
4c79b5
					switch ($user_row['user_inactive_reason'])
4c79b5
					{
4c79b5
						case INACTIVE_REGISTER:
4c79b5
							$inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
4c79b5
						break;
4c79b5
4c79b5
						case INACTIVE_PROFILE:
4c79b5
							$inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
4c79b5
						break;
4c79b5
4c79b5
						case INACTIVE_MANUAL:
4c79b5
							$inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
4c79b5
						break;
4c79b5
4c79b5
						case INACTIVE_REMIND:
4c79b5
							$inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
4c79b5
						break;
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				// Posts in Queue
4c79b5
				$sql = 'SELECT COUNT(post_id) as posts_in_queue
4c79b5
					FROM ' . POSTS_TABLE . '
4c79b5
					WHERE poster_id = ' . $user_id . '
4c79b5
						AND post_approved = 0';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'L_NAME_CHARS_EXPLAIN'		=> sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
4c79b5
					'L_CHANGE_PASSWORD_EXPLAIN'	=> sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']),
4c79b5
					'L_POSTS_IN_QUEUE'			=> $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']),
4c79b5
					'S_FOUNDER'					=> ($user->data['user_type'] == USER_FOUNDER) ? true : false,
4c79b5
4c79b5
					'S_OVERVIEW'		=> true,
4c79b5
					'S_USER_IP'			=> ($user_row['user_ip']) ? true : false,
4c79b5
					'S_USER_FOUNDER'	=> ($user_row['user_type'] == USER_FOUNDER) ? true : false,
4c79b5
					'S_ACTION_OPTIONS'	=> $s_action_options,
4c79b5
					'S_OWN_ACCOUNT'		=> ($user_id == $user->data['user_id']) ? true : false,
4c79b5
					'S_USER_INACTIVE'	=> ($user_row['user_type'] == USER_INACTIVE) ? true : false,
4c79b5
4c79b5
					'U_SHOW_IP'		=> $this->u_action . "&u=$user_id&ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
4c79b5
					'U_WHOIS'		=> $this->u_action . "&action=whois&user_ip={$user_row['user_ip']}",
4c79b5
					'U_MCP_QUEUE'	=> ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
4c79b5
4c79b5
					'U_SWITCH_PERMISSIONS'	=> ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&u={$user_row['user_id']}") : '',
4c79b5
4c79b5
					'POSTS_IN_QUEUE'	=> $user_row['posts_in_queue'],
4c79b5
					'USER'				=> $user_row['username'],
4c79b5
					'USER_REGISTERED'	=> $user->format_date($user_row['user_regdate']),
4c79b5
					'REGISTERED_IP'		=> ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
4c79b5
					'USER_LASTACTIVE'	=> ($last_visit) ? $user->format_date($last_visit) : ' - ',
4c79b5
					'USER_EMAIL'		=> $user_row['user_email'],
4c79b5
					'USER_WARNINGS'		=> $user_row['user_warnings'],
4c79b5
					'USER_POSTS'		=> $user_row['user_posts'],
4c79b5
					'USER_INACTIVE_REASON'	=> $inactive_reason,
4c79b5
				));
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'feedback':
4c79b5
4c79b5
				$user->add_lang('mcp');
4c79b5
4c79b5
				// Set up general vars
4c79b5
				$start		= request_var('start', 0);
4c79b5
				$deletemark = (isset($_POST['delmarked'])) ? true : false;
4c79b5
				$deleteall	= (isset($_POST['delall'])) ? true : false;
4c79b5
				$marked		= request_var('mark', array(0));
4c79b5
				$message	= utf8_normalize_nfc(request_var('message', '', true));
4c79b5
4c79b5
				// Sort keys
4c79b5
				$sort_days	= request_var('st', 0);
4c79b5
				$sort_key	= request_var('sk', 't');
4c79b5
				$sort_dir	= request_var('sd', 'd');
4c79b5
4c79b5
				// Delete entries if requested and able
4c79b5
				if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
4c79b5
				{
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$where_sql = '';
4c79b5
					if ($deletemark && $marked)
4c79b5
					{
4c79b5
						$sql_in = array();
4c79b5
						foreach ($marked as $mark)
4c79b5
						{
4c79b5
							$sql_in[] = $mark;
4c79b5
						}
4c79b5
						$where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
4c79b5
						unset($sql_in);
4c79b5
					}
4c79b5
4c79b5
					if ($where_sql || $deleteall)
4c79b5
					{
4c79b5
						$sql = 'DELETE FROM ' . LOG_TABLE . '
4c79b5
							WHERE log_type = ' . LOG_USERS . "
4c79b5
							$where_sql";
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				if ($submit && $message)
4c79b5
				{
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
4c79b5
					add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
4c79b5
					add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
4c79b5
4c79b5
					trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
				}
4c79b5
4c79b5
				// Sorting
4c79b5
				$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
4c79b5
				$sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
4c79b5
				$sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
4c79b5
4c79b5
				$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
4c79b5
				gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
4c79b5
4c79b5
				// Define where and sort sql for use in displaying logs
4c79b5
				$sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
4c79b5
				$sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
4c79b5
4c79b5
				// Grab log data
4c79b5
				$log_data = array();
4c79b5
				$log_count = 0;
4c79b5
				view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_FEEDBACK'	=> true,
4c79b5
					'S_ON_PAGE'		=> on_page($log_count, $config['topics_per_page'], $start),
4c79b5
					'PAGINATION'	=> generate_pagination($this->u_action . "&u=$user_id&$u_sort_param", $log_count, $config['topics_per_page'], $start, true),
4c79b5
4c79b5
					'S_LIMIT_DAYS'	=> $s_limit_days,
4c79b5
					'S_SORT_KEY'	=> $s_sort_key,
4c79b5
					'S_SORT_DIR'	=> $s_sort_dir,
4c79b5
					'S_CLEARLOGS'	=> $auth->acl_get('a_clearlogs'))
4c79b5
				);
4c79b5
4c79b5
				foreach ($log_data as $row)
4c79b5
				{
4c79b5
					$template->assign_block_vars('log', array(
4c79b5
						'USERNAME'		=> $row['username_full'],
4c79b5
						'IP'			=> $row['ip'],
4c79b5
						'DATE'			=> $user->format_date($row['time']),
4c79b5
						'ACTION'		=> nl2br($row['action']),
4c79b5
						'ID'			=> $row['id'])
4c79b5
					);
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'profile':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
				include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
4c79b5
4c79b5
				$cp = new custom_profile();
4c79b5
4c79b5
				$cp_data = $cp_error = array();
4c79b5
4c79b5
				$sql = 'SELECT lang_id
4c79b5
					FROM ' . LANG_TABLE . "
4c79b5
					WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$row = $db->sql_fetchrow($result);
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$user_row['iso_lang_id'] = $row['lang_id'];
4c79b5
4c79b5
				$data = array(
4c79b5
					'icq'			=> request_var('icq', $user_row['user_icq']),
4c79b5
					'aim'			=> request_var('aim', $user_row['user_aim']),
4c79b5
					'msn'			=> request_var('msn', $user_row['user_msnm']),
4c79b5
					'yim'			=> request_var('yim', $user_row['user_yim']),
4c79b5
					'jabber'		=> utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
4c79b5
					'website'		=> request_var('website', $user_row['user_website']),
4c79b5
					'location'		=> utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)),
4c79b5
					'occupation'	=> utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)),
4c79b5
					'interests'		=> utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)),
4c79b5
					'bday_day'		=> 0,
4c79b5
					'bday_month'	=> 0,
4c79b5
					'bday_year'		=> 0,
4c79b5
				);
4c79b5
4c79b5
				if ($user_row['user_birthday'])
4c79b5
				{
4c79b5
					list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
4c79b5
				}
4c79b5
4c79b5
				$data['bday_day']		= request_var('bday_day', $data['bday_day']);
4c79b5
				$data['bday_month']		= request_var('bday_month', $data['bday_month']);
4c79b5
				$data['bday_year']		= request_var('bday_year', $data['bday_year']);
4c79b5
				$data['user_birthday']	= sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
4c79b5
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					$error = validate_data($data, array(
4c79b5
						'icq'			=> array(
4c79b5
							array('string', true, 3, 15),
4c79b5
							array('match', true, '#^[0-9]+$#i')),
4c79b5
						'aim'			=> array('string', true, 3, 255),
4c79b5
						'msn'			=> array('string', true, 5, 255),
4c79b5
						'jabber'		=> array(
4c79b5
							array('string', true, 5, 255),
4c79b5
							array('jabber')),
4c79b5
						'yim'			=> array('string', true, 5, 255),
4c79b5
						'website'		=> array(
4c79b5
							array('string', true, 12, 255),
4c79b5
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
4c79b5
						'location'		=> array('string', true, 2, 100),
4c79b5
						'occupation'	=> array('string', true, 2, 500),
4c79b5
						'interests'		=> array('string', true, 2, 500),
4c79b5
						'bday_day'		=> array('num', true, 1, 31),
4c79b5
						'bday_month'	=> array('num', true, 1, 12),
4c79b5
						'bday_year'		=> array('num', true, 1901, gmdate('Y', time())),
4c79b5
						'user_birthday'	=> array('date', true),
4c79b5
					));
4c79b5
4c79b5
					// validate custom profile fields
4c79b5
					$cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
4c79b5
4c79b5
					if (sizeof($cp_error))
4c79b5
					{
4c79b5
						$error = array_merge($error, $cp_error);
4c79b5
					}
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						$error[] = 'FORM_INVALID';
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						$sql_ary = array(
4c79b5
							'user_icq'		=> $data['icq'],
4c79b5
							'user_aim'		=> $data['aim'],
4c79b5
							'user_msnm'		=> $data['msn'],
4c79b5
							'user_yim'		=> $data['yim'],
4c79b5
							'user_jabber'	=> $data['jabber'],
4c79b5
							'user_website'	=> $data['website'],
4c79b5
							'user_from'		=> $data['location'],
4c79b5
							'user_occ'		=> $data['occupation'],
4c79b5
							'user_interests'=> $data['interests'],
4c79b5
							'user_birthday'	=> $data['user_birthday'],
4c79b5
						);
4c79b5
4c79b5
						$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
4c79b5
							WHERE user_id = $user_id";
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						// Update Custom Fields
4c79b5
						if (sizeof($cp_data))
4c79b5
						{
4c79b5
							switch ($db->sql_layer)
4c79b5
							{
4c79b5
								case 'oracle':
4c79b5
								case 'firebird':
4c79b5
								case 'postgres':
4c79b5
									$right_delim = $left_delim = '"';
4c79b5
								break;
4c79b5
4c79b5
								case 'sqlite':
4c79b5
								case 'mssql':
4c79b5
								case 'mssql_odbc':
4c79b5
									$right_delim = ']';
4c79b5
									$left_delim = '[';
4c79b5
								break;
4c79b5
4c79b5
								case 'mysql':
4c79b5
								case 'mysql4':
4c79b5
								case 'mysqli':
4c79b5
									$right_delim = $left_delim = '`';
4c79b5
								break;
4c79b5
							}
4c79b5
4c79b5
							foreach ($cp_data as $key => $value)
4c79b5
							{
4c79b5
								$cp_data[$left_delim . $key . $right_delim] = $value;
4c79b5
								unset($cp_data[$key]);
4c79b5
							}
4c79b5
4c79b5
							$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
4c79b5
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . "
4c79b5
								WHERE user_id = $user_id";
4c79b5
							$db->sql_query($sql);
4c79b5
4c79b5
							if (!$db->sql_affectedrows())
4c79b5
							{
4c79b5
								$cp_data['user_id'] = (int) $user_id;
4c79b5
4c79b5
								$db->sql_return_on_error(true);
4c79b5
4c79b5
								$sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
4c79b5
								$db->sql_query($sql);
4c79b5
4c79b5
								$db->sql_return_on_error(false);
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
					}
4c79b5
4c79b5
					// Replace "error" strings with their real, localised form
4c79b5
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
4c79b5
				}
4c79b5
4c79b5
				$s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
4c79b5
				for ($i = 1; $i < 32; $i++)
4c79b5
				{
4c79b5
					$selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
4c79b5
					$s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
4c79b5
				}
4c79b5
4c79b5
				$s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
4c79b5
				for ($i = 1; $i < 13; $i++)
4c79b5
				{
4c79b5
					$selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
4c79b5
					$s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
4c79b5
				}
4c79b5
				$s_birthday_year_options = '';
4c79b5
4c79b5
				$now = getdate();
4c79b5
				$s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
4c79b5
				for ($i = $now['year'] - 100; $i < $now['year']; $i++)
4c79b5
				{
4c79b5
					$selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
4c79b5
					$s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
4c79b5
				}
4c79b5
				unset($now);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'ICQ'			=> $data['icq'],
4c79b5
					'YIM'			=> $data['yim'],
4c79b5
					'AIM'			=> $data['aim'],
4c79b5
					'MSN'			=> $data['msn'],
4c79b5
					'JABBER'		=> $data['jabber'],
4c79b5
					'WEBSITE'		=> $data['website'],
4c79b5
					'LOCATION'		=> $data['location'],
4c79b5
					'OCCUPATION'	=> $data['occupation'],
4c79b5
					'INTERESTS'		=> $data['interests'],
4c79b5
4c79b5
					'S_BIRTHDAY_DAY_OPTIONS'	=> $s_birthday_day_options,
4c79b5
					'S_BIRTHDAY_MONTH_OPTIONS'	=> $s_birthday_month_options,
4c79b5
					'S_BIRTHDAY_YEAR_OPTIONS'	=> $s_birthday_year_options,
4c79b5
4c79b5
					'S_PROFILE'		=> true)
4c79b5
				);
4c79b5
4c79b5
				// Get additional profile fields and assign them to the template block var 'profile_fields'
4c79b5
				$user->get_profile_fields($user_id);
4c79b5
4c79b5
				$cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'prefs':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
				$data = array(
4c79b5
					'dateformat'		=> utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
4c79b5
					'lang'				=> basename(request_var('lang', $user_row['user_lang'])),
4c79b5
					'tz'				=> request_var('tz', (float) $user_row['user_timezone']),
4c79b5
					'style'				=> request_var('style', $user_row['user_style']),
4c79b5
					'dst'				=> request_var('dst', $user_row['user_dst']),
4c79b5
					'viewemail'			=> request_var('viewemail', $user_row['user_allow_viewemail']),
4c79b5
					'massemail'			=> request_var('massemail', $user_row['user_allow_massemail']),
4c79b5
					'hideonline'		=> request_var('hideonline', !$user_row['user_allow_viewonline']),
4c79b5
					'notifymethod'		=> request_var('notifymethod', $user_row['user_notify_type']),
4c79b5
					'notifypm'			=> request_var('notifypm', $user_row['user_notify_pm']),
4c79b5
					'popuppm'			=> request_var('popuppm', $this->optionget($user_row, 'popuppm')),
4c79b5
					'allowpm'			=> request_var('allowpm', $user_row['user_allow_pm']),
4c79b5
4c79b5
					'topic_sk'			=> request_var('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
4c79b5
					'topic_sd'			=> request_var('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
4c79b5
					'topic_st'			=> request_var('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),
4c79b5
4c79b5
					'post_sk'			=> request_var('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
4c79b5
					'post_sd'			=> request_var('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
4c79b5
					'post_st'			=> request_var('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),
4c79b5
4c79b5
					'view_images'		=> request_var('view_images', $this->optionget($user_row, 'viewimg')),
4c79b5
					'view_flash'		=> request_var('view_flash', $this->optionget($user_row, 'viewflash')),
4c79b5
					'view_smilies'		=> request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')),
4c79b5
					'view_sigs'			=> request_var('view_sigs', $this->optionget($user_row, 'viewsigs')),
4c79b5
					'view_avatars'		=> request_var('view_avatars', $this->optionget($user_row, 'viewavatars')),
4c79b5
					'view_wordcensor'	=> request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')),
4c79b5
4c79b5
					'bbcode'	=> request_var('bbcode', $this->optionget($user_row, 'bbcode')),
4c79b5
					'smilies'	=> request_var('smilies', $this->optionget($user_row, 'smilies')),
4c79b5
					'sig'		=> request_var('sig', $this->optionget($user_row, 'attachsig')),
4c79b5
					'notify'	=> request_var('notify', $user_row['user_notify']),
4c79b5
				);
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					$error = validate_data($data, array(
4c79b5
						'dateformat'	=> array('string', false, 1, 30),
4c79b5
						'lang'			=> array('match', false, '#^[a-z_\-]{2,}$#i'),
4c79b5
						'tz'			=> array('num', false, -14, 14),
4c79b5
4c79b5
						'topic_sk'		=> array('string', false, 1, 1),
4c79b5
						'topic_sd'		=> array('string', false, 1, 1),
4c79b5
						'post_sk'		=> array('string', false, 1, 1),
4c79b5
						'post_sd'		=> array('string', false, 1, 1),
4c79b5
					));
4c79b5
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						$error[] = 'FORM_INVALID';
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						$this->optionset($user_row, 'popuppm', $data['popuppm']);
4c79b5
						$this->optionset($user_row, 'viewimg', $data['view_images']);
4c79b5
						$this->optionset($user_row, 'viewflash', $data['view_flash']);
4c79b5
						$this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
4c79b5
						$this->optionset($user_row, 'viewsigs', $data['view_sigs']);
4c79b5
						$this->optionset($user_row, 'viewavatars', $data['view_avatars']);
4c79b5
						$this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
4c79b5
						$this->optionset($user_row, 'bbcode', $data['bbcode']);
4c79b5
						$this->optionset($user_row, 'smilies', $data['smilies']);
4c79b5
						$this->optionset($user_row, 'attachsig', $data['sig']);
4c79b5
4c79b5
						$sql_ary = array(
4c79b5
							'user_options'			=> $user_row['user_options'],
4c79b5
4c79b5
							'user_allow_pm'			=> $data['allowpm'],
4c79b5
							'user_allow_viewemail'	=> $data['viewemail'],
4c79b5
							'user_allow_massemail'	=> $data['massemail'],
4c79b5
							'user_allow_viewonline'	=> !$data['hideonline'],
4c79b5
							'user_notify_type'		=> $data['notifymethod'],
4c79b5
							'user_notify_pm'		=> $data['notifypm'],
4c79b5
4c79b5
							'user_dst'				=> $data['dst'],
4c79b5
							'user_dateformat'		=> $data['dateformat'],
4c79b5
							'user_lang'				=> $data['lang'],
4c79b5
							'user_timezone'			=> $data['tz'],
4c79b5
							'user_style'			=> $data['style'],
4c79b5
4c79b5
							'user_topic_sortby_type'	=> $data['topic_sk'],
4c79b5
							'user_post_sortby_type'		=> $data['post_sk'],
4c79b5
							'user_topic_sortby_dir'		=> $data['topic_sd'],
4c79b5
							'user_post_sortby_dir'		=> $data['post_sd'],
4c79b5
4c79b5
							'user_topic_show_days'	=> $data['topic_st'],
4c79b5
							'user_post_show_days'	=> $data['post_st'],
4c79b5
4c79b5
							'user_notify'	=> $data['notify'],
4c79b5
						);
4c79b5
4c79b5
						$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
4c79b5
							WHERE user_id = $user_id";
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
					}
4c79b5
4c79b5
					// Replace "error" strings with their real, localised form
4c79b5
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
4c79b5
				}
4c79b5
4c79b5
				$dateformat_options = '';
4c79b5
				foreach ($user->lang['dateformats'] as $format => $null)
4c79b5
				{
4c79b5
					$dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
4c79b5
					$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
4c79b5
					$dateformat_options .= '</option>';
4c79b5
				}
4c79b5
4c79b5
				$s_custom = false;
4c79b5
4c79b5
				$dateformat_options .= '
4c79b5
				if (!isset($user->lang['dateformats'][$data['dateformat']]))
4c79b5
				{
4c79b5
					$dateformat_options .= ' selected="selected"';
4c79b5
					$s_custom = true;
4c79b5
				}
4c79b5
				$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
4c79b5
4c79b5
				$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
4c79b5
4c79b5
				// Topic ordering options
4c79b5
				$limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
4c79b5
				$sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
4c79b5
4c79b5
				// Post ordering options
4c79b5
				$limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
4c79b5
				$sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
4c79b5
4c79b5
				$_options = array('topic', 'post');
4c79b5
				foreach ($_options as $sort_option)
4c79b5
				{
4c79b5
					${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
4c79b5
					foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
4c79b5
					{
4c79b5
						$selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
4c79b5
						${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
4c79b5
					}
4c79b5
					${'s_limit_' . $sort_option . '_days'} .= '</select>';
4c79b5
4c79b5
					${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
4c79b5
					foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
4c79b5
					{
4c79b5
						$selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
4c79b5
						${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
4c79b5
					}
4c79b5
					${'s_sort_' . $sort_option . '_key'} .= '</select>';
4c79b5
4c79b5
					${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
4c79b5
					foreach ($sort_dir_text as $key => $value)
4c79b5
					{
4c79b5
						$selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
4c79b5
						${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
					}
4c79b5
					${'s_sort_' . $sort_option . '_dir'} .= '</select>';
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_PREFS'			=> true,
4c79b5
					'S_JABBER_DISABLED'	=> ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
4c79b5
4c79b5
					'VIEW_EMAIL'		=> $data['viewemail'],
4c79b5
					'MASS_EMAIL'		=> $data['massemail'],
4c79b5
					'ALLOW_PM'			=> $data['allowpm'],
4c79b5
					'HIDE_ONLINE'		=> $data['hideonline'],
4c79b5
					'NOTIFY_EMAIL'		=> ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
4c79b5
					'NOTIFY_IM'			=> ($data['notifymethod'] == NOTIFY_IM) ? true : false,
4c79b5
					'NOTIFY_BOTH'		=> ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
4c79b5
					'NOTIFY_PM'			=> $data['notifypm'],
4c79b5
					'POPUP_PM'			=> $data['popuppm'],
4c79b5
					'DST'				=> $data['dst'],
4c79b5
					'BBCODE'			=> $data['bbcode'],
4c79b5
					'SMILIES'			=> $data['smilies'],
4c79b5
					'ATTACH_SIG'		=> $data['sig'],
4c79b5
					'NOTIFY'			=> $data['notify'],
4c79b5
					'VIEW_IMAGES'		=> $data['view_images'],
4c79b5
					'VIEW_FLASH'		=> $data['view_flash'],
4c79b5
					'VIEW_SMILIES'		=> $data['view_smilies'],
4c79b5
					'VIEW_SIGS'			=> $data['view_sigs'],
4c79b5
					'VIEW_AVATARS'		=> $data['view_avatars'],
4c79b5
					'VIEW_WORDCENSOR'	=> $data['view_wordcensor'],
4c79b5
4c79b5
					'S_TOPIC_SORT_DAYS'		=> $s_limit_topic_days,
4c79b5
					'S_TOPIC_SORT_KEY'		=> $s_sort_topic_key,
4c79b5
					'S_TOPIC_SORT_DIR'		=> $s_sort_topic_dir,
4c79b5
					'S_POST_SORT_DAYS'		=> $s_limit_post_days,
4c79b5
					'S_POST_SORT_KEY'		=> $s_sort_post_key,
4c79b5
					'S_POST_SORT_DIR'		=> $s_sort_post_dir,
4c79b5
4c79b5
					'DATE_FORMAT'			=> $data['dateformat'],
4c79b5
					'S_DATEFORMAT_OPTIONS'	=> $dateformat_options,
4c79b5
					'S_CUSTOM_DATEFORMAT'	=> $s_custom,
4c79b5
					'DEFAULT_DATEFORMAT'	=> $config['default_dateformat'],
4c79b5
					'A_DEFAULT_DATEFORMAT'	=> addslashes($config['default_dateformat']),
4c79b5
4c79b5
					'S_LANG_OPTIONS'	=> language_select($data['lang']),
4c79b5
					'S_STYLE_OPTIONS'	=> style_select($data['style']),
4c79b5
					'S_TZ_OPTIONS'		=> tz_select($data['tz'], true),
4c79b5
					)
4c79b5
				);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'avatar':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
				$can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					if (avatar_process_user($error, $user_row))
4c79b5
					{
4c79b5
						trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_row['user_id']));
4c79b5
					}
4c79b5
4c79b5
					// Replace "error" strings with their real, localised form
4c79b5
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
4c79b5
				}
4c79b5
4c79b5
				// Generate users avatar
4c79b5
				$avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '';
4c79b5
4c79b5
				$display_gallery = (isset($_POST['display_gallery'])) ? true : false;
4c79b5
				$avatar_select = basename(request_var('avatar_select', ''));
4c79b5
				$category = basename(request_var('category', ''));
4c79b5
4c79b5
				if ($config['allow_avatar_local'] && $display_gallery)
4c79b5
				{
4c79b5
					avatar_gallery($category, $avatar_select, 4);
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_AVATAR'			=> true,
4c79b5
					'S_CAN_UPLOAD'		=> ($can_upload && $config['allow_avatar_upload']) ? true : false,
4c79b5
					'S_ALLOW_REMOTE'	=> ($config['allow_avatar_remote']) ? true : false,
4c79b5
					'S_DISPLAY_GALLERY'	=> ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
4c79b5
					'S_IN_GALLERY'		=> ($config['allow_avatar_local'] && $display_gallery) ? true : false,
4c79b5
4c79b5
					'AVATAR_IMAGE'			=> $avatar_img,
4c79b5
					'AVATAR_MAX_FILESIZE'	=> $config['avatar_filesize'],
4c79b5
					'USER_AVATAR_WIDTH'		=> $user_row['user_avatar_width'],
4c79b5
					'USER_AVATAR_HEIGHT'	=> $user_row['user_avatar_height'],
4c79b5
4c79b5
					'L_AVATAR_EXPLAIN'	=> sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))
4c79b5
				);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'rank':
4c79b5
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$rank_id = request_var('user_rank', 0);
4c79b5
4c79b5
					$sql = 'UPDATE ' . USERS_TABLE . "
4c79b5
						SET user_rank = $rank_id
4c79b5
						WHERE user_id = $user_id";
4c79b5
					$db->sql_query($sql);
4c79b5
4c79b5
					trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . RANKS_TABLE . '
4c79b5
					WHERE rank_special = 1
4c79b5
					ORDER BY rank_title';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : '';
4c79b5
					$s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_RANK'			=> true,
4c79b5
					'S_RANK_OPTIONS'	=> $s_rank_options)
4c79b5
				);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'sig':
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
4c79b5
				include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
				$enable_bbcode	= ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', !$user->optionget('bbcode'))) ? false : true) : false;
4c79b5
				$enable_smilies	= ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', !$user->optionget('smilies'))) ? false : true) : false;
4c79b5
				$enable_urls	= ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
4c79b5
				$signature		= utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));
4c79b5
4c79b5
				$preview		= (isset($_POST['preview'])) ? true : false;
4c79b5
4c79b5
				if ($submit || $preview)
4c79b5
				{
4c79b5
					include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
4c79b5
4c79b5
					$message_parser = new parse_message($signature);
4c79b5
4c79b5
					// Allowing Quote BBCode
4c79b5
					$message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
4c79b5
4c79b5
					if (sizeof($message_parser->warn_msg))
4c79b5
					{
4c79b5
						$error[] = implode('
', $message_parser->warn_msg);
4c79b5
					}
4c79b5
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						$error = 'FORM_INVALID';
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($error) && $submit)
4c79b5
					{
4c79b5
						$sql_ary = array(
4c79b5
							'user_sig'					=> (string) $message_parser->message,
4c79b5
							'user_sig_bbcode_uid'		=> (string) $message_parser->bbcode_uid,
4c79b5
							'user_sig_bbcode_bitfield'	=> (string) $message_parser->bbcode_bitfield
4c79b5
						);
4c79b5
4c79b5
						$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
4c79b5
							WHERE user_id = ' . $user_id;
4c79b5
						$db->sql_query($sql);
4c79b5
4c79b5
						trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
					}
4c79b5
4c79b5
					// Replace "error" strings with their real, localised form
4c79b5
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
4c79b5
				}
4c79b5
4c79b5
				$signature_preview = '';
4c79b5
4c79b5
				if ($preview)
4c79b5
				{
4c79b5
					// Now parse it for displaying
4c79b5
					$signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
4c79b5
					unset($message_parser);
4c79b5
				}
4c79b5
4c79b5
				decode_message($signature, $user_row['user_sig_bbcode_uid']);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_SIGNATURE'		=> true,
4c79b5
4c79b5
					'SIGNATURE'			=> $signature,
4c79b5
					'SIGNATURE_PREVIEW'	=> $signature_preview,
4c79b5
4c79b5
					'S_BBCODE_CHECKED'		=> (!$enable_bbcode) ? ' checked="checked"' : '',
4c79b5
					'S_SMILIES_CHECKED'		=> (!$enable_smilies) ? ' checked="checked"' : '',
4c79b5
					'S_MAGIC_URL_CHECKED'	=> (!$enable_urls) ? ' checked="checked"' : '',
4c79b5
4c79b5
					'BBCODE_STATUS'			=> ($config['allow_sig_bbcode']) ? sprintf($user->lang['BBCODE_IS_ON'], '', '') : sprintf($user->lang['BBCODE_IS_OFF'], '', ''),
4c79b5
					'SMILIES_STATUS'		=> ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
4c79b5
					'IMG_STATUS'			=> ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
4c79b5
					'FLASH_STATUS'			=> ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
4c79b5
					'URL_STATUS'			=> ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
4c79b5
4c79b5
					'L_SIGNATURE_EXPLAIN'	=> sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']),
4c79b5
4c79b5
					'S_BBCODE_ALLOWED'		=> $config['allow_sig_bbcode'],
4c79b5
					'S_SMILIES_ALLOWED'		=> $config['allow_sig_smilies'],
4c79b5
					'S_BBCODE_IMG'			=> ($config['allow_sig_img']) ? true : false,
4c79b5
					'S_BBCODE_FLASH'		=> ($config['allow_sig_flash']) ? true : false,
4c79b5
					'S_LINKS_ALLOWED'		=> ($config['allow_sig_links']) ? true : false)
4c79b5
				);
4c79b5
4c79b5
				// Assigning custom bbcodes
4c79b5
				display_custom_bbcodes();
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'attach':
4c79b5
4c79b5
				$start		= request_var('start', 0);
4c79b5
				$deletemark = (isset($_POST['delmarked'])) ? true : false;
4c79b5
				$marked		= request_var('mark', array(0));
4c79b5
4c79b5
				// Sort keys
4c79b5
				$sort_key	= request_var('sk', 'a');
4c79b5
				$sort_dir	= request_var('sd', 'd');
4c79b5
4c79b5
				if ($deletemark && sizeof($marked))
4c79b5
				{
4c79b5
					$sql = 'SELECT attach_id
4c79b5
						FROM ' . ATTACHMENTS_TABLE . '
4c79b5
						WHERE poster_id = ' . $user_id . '
4c79b5
							AND is_orphan = 0
4c79b5
							AND ' . $db->sql_in_set('attach_id', $marked);
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					$marked = array();
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$marked[] = $row['attach_id'];
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
4c79b5
				if ($deletemark && sizeof($marked))
4c79b5
				{
4c79b5
					if (confirm_box(true))
4c79b5
					{
4c79b5
						$sql = 'SELECT real_filename
4c79b5
							FROM ' . ATTACHMENTS_TABLE . '
4c79b5
							WHERE ' . $db->sql_in_set('attach_id', $marked);
4c79b5
						$result = $db->sql_query($sql);
4c79b5
4c79b5
						$log_attachments = array();
4c79b5
						while ($row = $db->sql_fetchrow($result))
4c79b5
						{
4c79b5
							$log_attachments[] = $row['real_filename'];
4c79b5
						}
4c79b5
						$db->sql_freeresult($result);
4c79b5
4c79b5
						delete_attachments('attach', $marked);
4c79b5
4c79b5
						$message = (sizeof($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
4c79b5
4c79b5
						add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments));
4c79b5
						trigger_error($message . adm_back_link($this->u_action . '&u=' . $user_id));
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
							'u'				=> $user_id,
4c79b5
							'i'				=> $id,
4c79b5
							'mode'			=> $mode,
4c79b5
							'action'		=> $action,
4c79b5
							'delmarked'		=> true,
4c79b5
							'mark'			=> $marked))
4c79b5
						);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
4c79b5
				$sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
4c79b5
4c79b5
				$sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
4c79b5
4c79b5
				$s_sort_key = '';
4c79b5
				foreach ($sk_text as $key => $value)
4c79b5
				{
4c79b5
					$selected = ($sort_key == $key) ? ' selected="selected"' : '';
4c79b5
					$s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
				}
4c79b5
4c79b5
				$s_sort_dir = '';
4c79b5
				foreach ($sd_text as $key => $value)
4c79b5
				{
4c79b5
					$selected = ($sort_dir == $key) ? ' selected="selected"' : '';
4c79b5
					$s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
				}
4c79b5
4c79b5
				if (!isset($sk_sql[$sort_key]))
4c79b5
				{
4c79b5
					$sort_key = 'a';
4c79b5
				}
4c79b5
4c79b5
				$order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
4c79b5
4c79b5
				$sql = 'SELECT COUNT(attach_id) as num_attachments
4c79b5
					FROM ' . ATTACHMENTS_TABLE . "
4c79b5
					WHERE poster_id = $user_id
4c79b5
						AND is_orphan = 0";
4c79b5
				$result = $db->sql_query_limit($sql, 1);
4c79b5
				$num_attachments = (int) $db->sql_fetchfield('num_attachments');
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
4c79b5
					FROM ' . ATTACHMENTS_TABLE . ' a
4c79b5
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
4c79b5
							AND a.in_message = 0)
4c79b5
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
4c79b5
							AND a.in_message = 1)
4c79b5
					WHERE a.poster_id = ' . $user_id . "
4c79b5
						AND a.is_orphan = 0
4c79b5
					ORDER BY $order_by";
4c79b5
				$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					if ($row['in_message'])
4c79b5
					{
4c79b5
						$view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&p={$row['post_msg_id']}");
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
4c79b5
					}
4c79b5
4c79b5
					$template->assign_block_vars('attach', array(
4c79b5
						'REAL_FILENAME'		=> $row['real_filename'],
4c79b5
						'COMMENT'			=> nl2br($row['attach_comment']),
4c79b5
						'EXTENSION'			=> $row['extension'],
4c79b5
						'SIZE'				=> get_formatted_filesize($row['filesize']),
4c79b5
						'DOWNLOAD_COUNT'	=> $row['download_count'],
4c79b5
						'POST_TIME'			=> $user->format_date($row['filetime']),
4c79b5
						'TOPIC_TITLE'		=> ($row['in_message']) ? $row['message_title'] : $row['topic_title'],
4c79b5
4c79b5
						'ATTACH_ID'			=> $row['attach_id'],
4c79b5
						'POST_ID'			=> $row['post_msg_id'],
4c79b5
						'TOPIC_ID'			=> $row['topic_id'],
4c79b5
4c79b5
						'S_IN_MESSAGE'		=> $row['in_message'],
4c79b5
4c79b5
						'U_DOWNLOAD'		=> append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&id=' . $row['attach_id']),
4c79b5
						'U_VIEW_TOPIC'		=> $view_topic)
4c79b5
					);
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_ATTACHMENTS'		=> true,
4c79b5
					'S_ON_PAGE'			=> on_page($num_attachments, $config['topics_per_page'], $start),
4c79b5
					'S_SORT_KEY'		=> $s_sort_key,
4c79b5
					'S_SORT_DIR'		=> $s_sort_dir,
4c79b5
4c79b5
					'PAGINATION'		=> generate_pagination($this->u_action . "&u=$user_id&sk=$sort_key&sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start, true))
4c79b5
				);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'groups':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
				$user->add_lang(array('groups', 'acp/groups'));
4c79b5
				$group_id = request_var('g', 0);
4c79b5
4c79b5
				if ($group_id)
4c79b5
				{
4c79b5
					// Check the founder only entry for this group to make sure everything is well
4c79b5
					$sql = 'SELECT group_founder_manage
4c79b5
						FROM ' . GROUPS_TABLE . '
4c79b5
						WHERE group_id = ' . $group_id;
4c79b5
					$result = $db->sql_query($sql);
4c79b5
					$founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
4c79b5
					{
4c79b5
						trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$founder_manage = 0;
4c79b5
				}
4c79b5
4c79b5
				switch ($action)
4c79b5
				{
4c79b5
					case 'demote':
4c79b5
					case 'promote':
4c79b5
					case 'default':
4c79b5
						if (!$group_id)
4c79b5
						{
4c79b5
							trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
						}
4c79b5
						group_user_attributes($action, $group_id, $user_id);
4c79b5
4c79b5
						if ($action == 'default')
4c79b5
						{
4c79b5
							$user_row['group_id'] = $group_id;
4c79b5
						}
4c79b5
					break;
4c79b5
4c79b5
					case 'delete':
4c79b5
4c79b5
						if (confirm_box(true))
4c79b5
						{
4c79b5
							if (!$group_id)
4c79b5
							{
4c79b5
								trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							if ($error = group_user_del($group_id, $user_id))
4c79b5
							{
4c79b5
								trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							$error = array();
4c79b5
						}
4c79b5
						else
4c79b5
						{
4c79b5
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
								'u'				=> $user_id,
4c79b5
								'i'				=> $id,
4c79b5
								'mode'			=> $mode,
4c79b5
								'action'		=> $action,
4c79b5
								'g'				=> $group_id))
4c79b5
							);
4c79b5
						}
4c79b5
4c79b5
					break;
4c79b5
				}
4c79b5
4c79b5
				// Add user to group?
4c79b5
				if ($submit)
4c79b5
				{
4c79b5
4c79b5
					if (!check_form_key($form_name))
4c79b5
					{
4c79b5
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					if (!$group_id)
4c79b5
					{
4c79b5
						trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					// Add user/s to group
4c79b5
					if ($error = group_user_add($group_id, $user_id))
4c79b5
					{
4c79b5
						trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$error = array();
4c79b5
				}
4c79b5
4c79b5
4c79b5
				$sql = 'SELECT ug.*, g.*
4c79b5
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
4c79b5
					WHERE ug.user_id = $user_id
4c79b5
						AND g.group_id = ug.group_id
4c79b5
					ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$i = 0;
4c79b5
				$group_data = $id_ary = array();
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal');
4c79b5
4c79b5
					$group_data[$type][$i]['group_id']		= $row['group_id'];
4c79b5
					$group_data[$type][$i]['group_name']	= $row['group_name'];
4c79b5
					$group_data[$type][$i]['group_leader']	= ($row['group_leader']) ? 1 : 0;
4c79b5
4c79b5
					$id_ary[] = $row['group_id'];
4c79b5
4c79b5
					$i++;
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				// Select box for other groups
4c79b5
				$sql = 'SELECT group_id, group_name, group_type, group_founder_manage
4c79b5
					FROM ' . GROUPS_TABLE . '
4c79b5
					' . ((sizeof($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
4c79b5
					ORDER BY group_type DESC, group_name ASC';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$s_group_options = '';
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					// Do not display those groups not allowed to be managed
4c79b5
					if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
4c79b5
					{
4c79b5
						continue;
4c79b5
					}
4c79b5
4c79b5
					$s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$current_type = '';
4c79b5
				foreach ($group_data as $group_type => $data_ary)
4c79b5
				{
4c79b5
					if ($current_type != $group_type)
4c79b5
					{
4c79b5
						$template->assign_block_vars('group', array(
4c79b5
							'S_NEW_GROUP_TYPE'		=> true,
4c79b5
							'GROUP_TYPE'			=> $user->lang['USER_GROUP_' . strtoupper($group_type)])
4c79b5
						);
4c79b5
					}
4c79b5
4c79b5
					foreach ($data_ary as $data)
4c79b5
					{
4c79b5
						$template->assign_block_vars('group', array(
4c79b5
							'U_EDIT_GROUP'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=groups&mode=manage&action=edit&u=$user_id&g={$data['group_id']}&back_link=acp_users_groups"),
4c79b5
							'U_DEFAULT'			=> $this->u_action . "&action=default&u=$user_id&g=" . $data['group_id'],
4c79b5
							'U_DEMOTE_PROMOTE'	=> $this->u_action . '&action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&u=$user_id&g=" . $data['group_id'],
4c79b5
							'U_DELETE'			=> $this->u_action . "&action=delete&u=$user_id&g=" . $data['group_id'],
4c79b5
4c79b5
							'GROUP_NAME'		=> ($group_type == 'special') ? $user->lang['G_' . $data['group_name']] : $data['group_name'],
4c79b5
							'L_DEMOTE_PROMOTE'	=> ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],
4c79b5
4c79b5
							'S_NO_DEFAULT'		=> ($user_row['group_id'] != $data['group_id']) ? true : false,
4c79b5
							'S_SPECIAL_GROUP'	=> ($group_type == 'special') ? true : false,
4c79b5
							)
4c79b5
						);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_GROUPS'			=> true,
4c79b5
					'S_GROUP_OPTIONS'	=> $s_group_options)
4c79b5
				);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'perm':
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
4c79b5
4c79b5
				$auth_admin = new auth_admin();
4c79b5
4c79b5
				$user->add_lang('acp/permissions');
4c79b5
				add_permission_language();
4c79b5
4c79b5
				$forum_id = request_var('f', 0);
4c79b5
4c79b5
				// Global Permissions
4c79b5
				if (!$forum_id)
4c79b5
				{
4c79b5
					// Select auth options
4c79b5
					$sql = 'SELECT auth_option, is_local, is_global
4c79b5
						FROM ' . ACL_OPTIONS_TABLE . '
4c79b5
						WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
4c79b5
							AND is_global = 1
4c79b5
						ORDER BY auth_option';
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					$hold_ary = array();
4c79b5
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
4c79b5
						$auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
4c79b5
					unset($hold_ary);
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$sql = 'SELECT auth_option, is_local, is_global
4c79b5
						FROM ' . ACL_OPTIONS_TABLE . "
4c79b5
						WHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "
4c79b5
							AND is_local = 1
4c79b5
						ORDER BY is_global DESC, auth_option";
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					while ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
4c79b5
						$auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
4c79b5
					}
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
4c79b5
				$s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
4c79b5
				$s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_PERMISSIONS'				=> true,
4c79b5
4c79b5
					'S_GLOBAL'					=> (!$forum_id) ? true : false,
4c79b5
					'S_FORUM_OPTIONS'			=> $s_forum_options,
4c79b5
4c79b5
					'U_ACTION'					=> $this->u_action . '&u=' . $user_id,
4c79b5
					'U_USER_PERMISSIONS'		=> append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&mode=setting_user_global&user_id[]=' . $user_id),
4c79b5
					'U_USER_FORUM_PERMISSIONS'	=> append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&mode=setting_user_local&user_id[]=' . $user_id))
4c79b5
				);
4c79b5
4c79b5
			break;
4c79b5
4c79b5
		}
4c79b5
4c79b5
		// Assign general variables
4c79b5
		$template->assign_vars(array(
4c79b5
			'S_ERROR'			=> (sizeof($error)) ? true : false,
4c79b5
			'ERROR_MSG'			=> (sizeof($error)) ? implode('
', $error) : '')
4c79b5
		);
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Optionset replacement for this module based on $user->optionset
4c79b5
	*/
4c79b5
	function optionset(&$user_row, $key, $value, $data = false)
4c79b5
	{
4c79b5
		global $user;
4c79b5
4c79b5
		$var = ($data) ? $data : $user_row['user_options'];
4c79b5
4c79b5
		if ($value && !($var & 1 << $user->keyoptions[$key]))
4c79b5
		{
4c79b5
			$var += 1 << $user->keyoptions[$key];
4c79b5
		}
4c79b5
		else if (!$value && ($var & 1 << $user->keyoptions[$key]))
4c79b5
		{
4c79b5
			$var -= 1 << $user->keyoptions[$key];
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			return ($data) ? $var : false;
4c79b5
		}
4c79b5
4c79b5
		if (!$data)
4c79b5
		{
4c79b5
			$user_row['user_options'] = $var;
4c79b5
			return true;
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			return $var;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	/**
4c79b5
	* Optionget replacement for this module based on $user->optionget
4c79b5
	*/
4c79b5
	function optionget(&$user_row, $key, $data = false)
4c79b5
	{
4c79b5
		global $user;
4c79b5
4c79b5
		$var = ($data) ? $data : $user_row['user_options'];
4c79b5
		return ($var & 1 << $user->keyoptions[$key]) ? true : false;
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>