Blame Extras/phpBB/3.0.4/memberlist.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package phpBB3
4c79b5
* @version $Id: memberlist.php 9156 2008-12-02 18:48:25Z 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
define('IN_PHPBB', true);
4c79b5
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
4c79b5
$phpEx = substr(strrchr(__FILE__, '.'), 1);
4c79b5
include($phpbb_root_path . 'common.' . $phpEx);
4c79b5
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
// Start session management
4c79b5
$user->session_begin();
4c79b5
$auth->acl($user->data);
4c79b5
$user->setup(array('memberlist', 'groups'));
4c79b5
4c79b5
// Grab data
4c79b5
$mode		= request_var('mode', '');
4c79b5
$action		= request_var('action', '');
4c79b5
$user_id	= request_var('u', ANONYMOUS);
4c79b5
$username	= request_var('un', '', true);
4c79b5
$group_id	= request_var('g', 0);
4c79b5
$topic_id	= request_var('t', 0);
4c79b5
4c79b5
// Check our mode...
4c79b5
if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'searchuser', 'leaders')))
4c79b5
{
4c79b5
	trigger_error('NO_MODE');
4c79b5
}
4c79b5
4c79b5
switch ($mode)
4c79b5
{
4c79b5
	case 'email':
4c79b5
	break;
4c79b5
4c79b5
	default:
4c79b5
		// Can this user view profiles/memberlist?
4c79b5
		if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
4c79b5
		{
4c79b5
			if ($user->data['user_id'] != ANONYMOUS)
4c79b5
			{
4c79b5
				trigger_error('NO_VIEW_USERS');
4c79b5
			}
4c79b5
4c79b5
			login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
4c79b5
		}
4c79b5
	break;
4c79b5
}
4c79b5
4c79b5
$start	= request_var('start', 0);
4c79b5
$submit = (isset($_POST['submit'])) ? true : false;
4c79b5
4c79b5
$default_key = 'c';
4c79b5
$sort_key = request_var('sk', $default_key);
4c79b5
$sort_dir = request_var('sd', 'a');
4c79b5
4c79b5
4c79b5
// Grab rank information for later
4c79b5
$ranks = $cache->obtain_ranks();
4c79b5
4c79b5
4c79b5
// What do you want to do today? ... oops, I think that line is taken ...
4c79b5
switch ($mode)
4c79b5
{
4c79b5
	case 'leaders':
4c79b5
		// Display a listing of board admins, moderators
4c79b5
		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
		$page_title = $user->lang['THE_TEAM'];
4c79b5
		$template_html = 'memberlist_leaders.html';
4c79b5
4c79b5
		$user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false);
4c79b5
4c79b5
		$admin_id_ary = $global_mod_id_ary = $mod_id_ary = $forum_id_ary = array();
4c79b5
		foreach ($user_ary as $forum_id => $forum_ary)
4c79b5
		{
4c79b5
			foreach ($forum_ary as $auth_option => $id_ary)
4c79b5
			{
4c79b5
				if (!$forum_id)
4c79b5
				{
4c79b5
					if ($auth_option == 'a_')
4c79b5
					{
4c79b5
						$admin_id_ary = array_merge($admin_id_ary, $id_ary);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$global_mod_id_ary = array_merge($global_mod_id_ary, $id_ary);
4c79b5
					}
4c79b5
					continue;
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$mod_id_ary = array_merge($mod_id_ary, $id_ary);
4c79b5
				}
4c79b5
4c79b5
				if ($forum_id)
4c79b5
				{
4c79b5
					foreach ($id_ary as $id)
4c79b5
					{
4c79b5
						$forum_id_ary[$id][] = $forum_id;
4c79b5
					}
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$admin_id_ary = array_unique($admin_id_ary);
4c79b5
		$global_mod_id_ary = array_unique($global_mod_id_ary);
4c79b5
4c79b5
		$mod_id_ary = array_merge($mod_id_ary, $global_mod_id_ary);
4c79b5
		$mod_id_ary = array_unique($mod_id_ary);
4c79b5
4c79b5
		// Admin group id...
4c79b5
		$sql = 'SELECT group_id
4c79b5
			FROM ' . GROUPS_TABLE . "
4c79b5
			WHERE group_name = 'ADMINISTRATORS'";
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$admin_group_id = (int) $db->sql_fetchfield('group_id');
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		// Get group memberships for the admin id ary...
4c79b5
		$admin_memberships = group_memberships($admin_group_id, $admin_id_ary);
4c79b5
4c79b5
		$admin_user_ids = array();
4c79b5
4c79b5
		if (!empty($admin_memberships))
4c79b5
		{
4c79b5
			// ok, we only need the user ids...
4c79b5
			foreach ($admin_memberships as $row)
4c79b5
			{
4c79b5
				$admin_user_ids[$row['user_id']] = true;
4c79b5
			}
4c79b5
		}
4c79b5
		unset($admin_memberships);
4c79b5
4c79b5
		$sql = 'SELECT forum_id, forum_name
4c79b5
			FROM ' . FORUMS_TABLE;
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$forums = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$forums[$row['forum_id']] = $row['forum_name'];
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$sql = $db->sql_build_query('SELECT', array(
4c79b5
			'SELECT'	=> 'u.user_id, u.group_id as default_group, u.username, u.username_clean, u.user_colour, u.user_rank, u.user_posts, u.user_allow_pm, g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id',
4c79b5
4c79b5
			'FROM'		=> array(
4c79b5
				USERS_TABLE		=> 'u',
4c79b5
				GROUPS_TABLE	=> 'g'
4c79b5
			),
4c79b5
4c79b5
			'LEFT_JOIN'	=> array(
4c79b5
				array(
4c79b5
					'FROM'	=> array(USER_GROUP_TABLE => 'ug'),
4c79b5
					'ON'	=> 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id']
4c79b5
				)
4c79b5
			),
4c79b5
4c79b5
			'WHERE'		=> $db->sql_in_set('u.user_id', array_unique(array_merge($admin_id_ary, $mod_id_ary)), false, true) . '
4c79b5
				AND u.group_id = g.group_id',
4c79b5
4c79b5
			'ORDER_BY'	=> 'g.group_name ASC, u.username_clean ASC'
4c79b5
		));
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod';
4c79b5
4c79b5
			// We sort out admins not within the 'Administrators' group.
4c79b5
			// Else, we will list those as admin only having the permission to view logs for example.
4c79b5
			if ($which_row == 'admin' && empty($admin_user_ids[$row['user_id']]))
4c79b5
			{
4c79b5
				// Remove from admin_id_ary, because the user may be a mod instead
4c79b5
				unset($admin_id_ary[array_search($row['user_id'], $admin_id_ary)]);
4c79b5
4c79b5
				if (!in_array($row['user_id'], $mod_id_ary) && !in_array($row['user_id'], $global_mod_id_ary))
4c79b5
				{
4c79b5
					continue;
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$which_row = 'mod';
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			$s_forum_select = '';
4c79b5
			$undisclosed_forum = false;
4c79b5
4c79b5
			if (isset($forum_id_ary[$row['user_id']]) && !in_array($row['user_id'], $global_mod_id_ary))
4c79b5
			{
4c79b5
				if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']])))
4c79b5
				{
4c79b5
					foreach ($forum_id_ary[$row['user_id']] as $forum_id)
4c79b5
					{
4c79b5
						if (isset($forums[$forum_id]))
4c79b5
						{
4c79b5
							if ($auth->acl_get('f_list', $forum_id))
4c79b5
							{
4c79b5
								$s_forum_select .= '<option value="">' . $forums[$forum_id] . '</option>';
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								$undisclosed_forum = true;
4c79b5
							}
4c79b5
						}
4c79b5
					}
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			// If the mod is only moderating non-viewable forums we skip the user. There is no gain in displaying the person then...
4c79b5
			if (!$s_forum_select && $undisclosed_forum)
4c79b5
			{
4c79b5
//				$s_forum_select = '<option value="">' . $user->lang['FORUM_UNDISCLOSED'] . '</option>';
4c79b5
				continue;
4c79b5
			}
4c79b5
4c79b5
			// The person is moderating several "public" forums, therefore the person should be listed, but not giving the real group name if hidden.
4c79b5
			if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
4c79b5
			{
4c79b5
				$group_name = $user->lang['GROUP_UNDISCLOSED'];
4c79b5
				$u_group = '';
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
4c79b5
				$u_group = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']);
4c79b5
			}
4c79b5
4c79b5
			$rank_title = $rank_img = '';
4c79b5
			get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);
4c79b5
4c79b5
			$template->assign_block_vars($which_row, array(
4c79b5
				'USER_ID'		=> $row['user_id'],
4c79b5
				'FORUMS'		=> $s_forum_select,
4c79b5
				'RANK_TITLE'	=> $rank_title,
4c79b5
				'GROUP_NAME'	=> $group_name,
4c79b5
				'GROUP_COLOR'	=> $row['group_colour'],
4c79b5
4c79b5
				'RANK_IMG'		=> $rank_img,
4c79b5
				'RANK_IMG_SRC'	=> $rank_img_src,
4c79b5
4c79b5
				'U_GROUP'			=> $u_group,
4c79b5
				'U_PM'				=> ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $row['user_id']) : '',
4c79b5
4c79b5
				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
4c79b5
				'USERNAME'			=> get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
4c79b5
				'USER_COLOR'		=> get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
4c79b5
				'U_VIEW_PROFILE'	=> get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
4c79b5
			));
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'PM_IMG'		=> $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
4c79b5
		);
4c79b5
	break;
4c79b5
4c79b5
	case 'contact':
4c79b5
4c79b5
		$page_title = $user->lang['IM_USER'];
4c79b5
		$template_html = 'memberlist_im.html';
4c79b5
4c79b5
		if (!$auth->acl_get('u_sendim'))
4c79b5
		{
4c79b5
			trigger_error('NOT_AUTHORISED');
4c79b5
		}
4c79b5
4c79b5
		$presence_img = '';
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'aim':
4c79b5
				$lang = 'AIM';
4c79b5
				$sql_field = 'user_aim';
4c79b5
				$s_select = 'S_SEND_AIM';
4c79b5
				$s_action = '';
4c79b5
			break;
4c79b5
4c79b5
			case 'msnm':
4c79b5
				$lang = 'MSNM';
4c79b5
				$sql_field = 'user_msnm';
4c79b5
				$s_select = 'S_SEND_MSNM';
4c79b5
				$s_action = '';
4c79b5
			break;
4c79b5
4c79b5
			case 'jabber':
4c79b5
				$lang = 'JABBER';
4c79b5
				$sql_field = 'user_jabber';
4c79b5
				$s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
4c79b5
				$s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=$action&u=$user_id");
4c79b5
			break;
4c79b5
4c79b5
			default:
4c79b5
				trigger_error('NO_MODE', E_USER_ERROR);
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		// Grab relevant data
4c79b5
		$sql = "SELECT user_id, username, user_email, user_lang, $sql_field
4c79b5
			FROM " . USERS_TABLE . "
4c79b5
			WHERE user_id = $user_id
4c79b5
				AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$row = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (!$row)
4c79b5
		{
4c79b5
			trigger_error('NO_USER');
4c79b5
		}
4c79b5
		else if (empty($row[$sql_field]))
4c79b5
		{
4c79b5
			trigger_error('IM_NO_DATA');
4c79b5
		}
4c79b5
4c79b5
		// Post data grab actions
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'jabber':
4c79b5
				add_form_key('memberlist_messaging');
4c79b5
4c79b5
				if ($submit && @extension_loaded('xml') && $config['jab_enable'])
4c79b5
				{
4c79b5
					if (check_form_key('memberlist_messaging'))
4c79b5
					{
4c79b5
4c79b5
						include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
4c79b5
4c79b5
						$subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
4c79b5
						$message = utf8_normalize_nfc(request_var('message', '', true));
4c79b5
4c79b5
						if (empty($message))
4c79b5
						{
4c79b5
							trigger_error('EMPTY_MESSAGE_IM');
4c79b5
						}
4c79b5
4c79b5
						$messenger = new messenger(false);
4c79b5
4c79b5
						$messenger->template('profile_send_im', $row['user_lang']);
4c79b5
						$messenger->subject(htmlspecialchars_decode($subject));
4c79b5
4c79b5
						$messenger->replyto($user->data['user_email']);
4c79b5
						$messenger->im($row['user_jabber'], $row['username']);
4c79b5
4c79b5
						$messenger->assign_vars(array(
4c79b5
							'BOARD_CONTACT'	=> $config['board_contact'],
4c79b5
							'FROM_USERNAME'	=> htmlspecialchars_decode($user->data['username']),
4c79b5
							'TO_USERNAME'	=> htmlspecialchars_decode($row['username']),
4c79b5
							'MESSAGE'		=> htmlspecialchars_decode($message))
4c79b5
						);
4c79b5
4c79b5
						$messenger->send(NOTIFY_IM);
4c79b5
4c79b5
						$s_select = 'S_SENT_JABBER';
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						trigger_error('FORM_INVALID');
4c79b5
					}
4c79b5
				}
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		// Send vars to the template
4c79b5
		$template->assign_vars(array(
4c79b5
			'IM_CONTACT'	=> $row[$sql_field],
4c79b5
			'A_IM_CONTACT'	=> addslashes($row[$sql_field]),
4c79b5
4c79b5
			'U_AIM_CONTACT'	=> ($action == 'aim') ? 'aim:addbuddy?screenname=' . urlencode($row[$sql_field]) : '',
4c79b5
			'U_AIM_MESSAGE'	=> ($action == 'aim') ? 'aim:goim?screenname=' . urlencode($row[$sql_field]) . '&message=' . urlencode($config['sitename']) : '',
4c79b5
4c79b5
			'USERNAME'		=> $row['username'],
4c79b5
			'CONTACT_NAME'	=> $row[$sql_field],
4c79b5
			'SITENAME'		=> $config['sitename'],
4c79b5
4c79b5
			'PRESENCE_IMG'		=> $presence_img,
4c79b5
4c79b5
			'L_SEND_IM_EXPLAIN'	=> $user->lang['IM_' . $lang],
4c79b5
			'L_IM_SENT_JABBER'	=> sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
4c79b5
4c79b5
			$s_select			=> true,
4c79b5
			'S_IM_ACTION'		=> $s_action)
4c79b5
		);
4c79b5
4c79b5
	break;
4c79b5
4c79b5
	case 'viewprofile':
4c79b5
		// Display a profile
4c79b5
		if ($user_id == ANONYMOUS && !$username)
4c79b5
		{
4c79b5
			trigger_error('NO_USER');
4c79b5
		}
4c79b5
4c79b5
		// Get user...
4c79b5
		$sql = 'SELECT *
4c79b5
			FROM ' . USERS_TABLE . '
4c79b5
			WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$member = $db->sql_fetchrow($result);
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		if (!$member)
4c79b5
		{
4c79b5
			trigger_error('NO_USER');
4c79b5
		}
4c79b5
4c79b5
		// a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
4c79b5
		// Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
4c79b5
		if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
4c79b5
		{
4c79b5
			if ($member['user_type'] == USER_IGNORE)
4c79b5
			{
4c79b5
				trigger_error('NO_USER');
4c79b5
			}
4c79b5
			else if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE)
4c79b5
			{
4c79b5
				trigger_error('NO_USER');
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$user_id = (int) $member['user_id'];
4c79b5
4c79b5
		// Do the SQL thang
4c79b5
		$sql = 'SELECT g.group_id, g.group_name, g.group_type
4c79b5
			FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
4c79b5
			WHERE ug.user_id = $user_id
4c79b5
				AND g.group_id = ug.group_id" . ((!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' AND g.group_type <> ' . GROUP_HIDDEN : '') . '
4c79b5
				AND ug.user_pending = 0
4c79b5
			ORDER BY g.group_type, g.group_name';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$group_options = '';
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		// What colour is the zebra
4c79b5
		$sql = 'SELECT friend, foe
4c79b5
			FROM ' . ZEBRA_TABLE . "
4c79b5
			WHERE zebra_id = $user_id
4c79b5
				AND user_id = {$user->data['user_id']}";
4c79b5
4c79b5
		$result = $db->sql_query($sql);
4c79b5
		$row = $db->sql_fetchrow($result);
4c79b5
		$foe = ($row['foe']) ? true : false;
4c79b5
		$friend = ($row['friend']) ? true : false;
4c79b5
		$db->sql_freeresult($result);
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
			$member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
4c79b5
			$member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] :	0;
4c79b5
			unset($row);
4c79b5
		}
4c79b5
4c79b5
		if ($config['load_user_activity'])
4c79b5
		{
4c79b5
			display_user_activity($member);
4c79b5
		}
4c79b5
4c79b5
		// Do the relevant calculations
4c79b5
		$memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
4c79b5
		$posts_per_day = $member['user_posts'] / $memberdays;
4c79b5
		$percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
4c79b5
4c79b5
4c79b5
		if ($member['user_sig'])
4c79b5
		{
4c79b5
			$member['user_sig'] = censor_text($member['user_sig']);
4c79b5
4c79b5
			if ($member['user_sig_bbcode_bitfield'])
4c79b5
			{
4c79b5
				include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
4c79b5
				$bbcode = new bbcode();
4c79b5
				$bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
4c79b5
			}
4c79b5
4c79b5
			$member['user_sig'] = bbcode_nl2br($member['user_sig']);
4c79b5
			$member['user_sig'] = smiley_text($member['user_sig']);
4c79b5
		}
4c79b5
4c79b5
		$poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']);
4c79b5
4c79b5
		$template->assign_vars(show_profile($member));
4c79b5
4c79b5
		// Custom Profile Fields
4c79b5
		$profile_fields = array();
4c79b5
		if ($config['load_cpf_viewprofile'])
4c79b5
		{
4c79b5
			include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
4c79b5
			$cp = new custom_profile();
4c79b5
			$profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
4c79b5
			$profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
4c79b5
		}
4c79b5
4c79b5
		// We need to check if the module 'zebra' is accessible
4c79b5
		$zebra_enabled = false;
4c79b5
4c79b5
		if ($user->data['user_id'] != $user_id && $user->data['is_registered'])
4c79b5
		{
4c79b5
			include_once($phpbb_root_path . 'includes/functions_module.' . $phpEx);
4c79b5
			$module = new p_master();
4c79b5
			$module->list_modules('ucp');
4c79b5
			$module->set_active('zebra');
4c79b5
4c79b5
			$zebra_enabled = ($module->active_module === false) ? false : true;
4c79b5
4c79b5
			unset($module);
4c79b5
		}
4c79b5
4c79b5
		// If the user has m_approve permission or a_user permission, then list then display unapproved posts
4c79b5
		if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
4c79b5
		{
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
			$member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$member['posts_in_queue'] = 0;
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'L_POSTS_IN_QUEUE'	=> $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
4c79b5
4c79b5
			'POSTS_DAY'			=> sprintf($user->lang['POST_DAY'], $posts_per_day),
4c79b5
			'POSTS_PCT'			=> sprintf($user->lang['POST_PCT'], $percentage),
4c79b5
4c79b5
			'OCCUPATION'	=> (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
4c79b5
			'INTERESTS'		=> (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
4c79b5
			'SIGNATURE'		=> $member['user_sig'],
4c79b5
			'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
4c79b5
4c79b5
			'AVATAR_IMG'	=> $poster_avatar,
4c79b5
			'PM_IMG'		=> $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
4c79b5
			'EMAIL_IMG'		=> $user->img('icon_contact_email', $user->lang['EMAIL']),
4c79b5
			'WWW_IMG'		=> $user->img('icon_contact_www', $user->lang['WWW']),
4c79b5
			'ICQ_IMG'		=> $user->img('icon_contact_icq', $user->lang['ICQ']),
4c79b5
			'AIM_IMG'		=> $user->img('icon_contact_aim', $user->lang['AIM']),
4c79b5
			'MSN_IMG'		=> $user->img('icon_contact_msnm', $user->lang['MSNM']),
4c79b5
			'YIM_IMG'		=> $user->img('icon_contact_yahoo', $user->lang['YIM']),
4c79b5
			'JABBER_IMG'	=> $user->img('icon_contact_jabber', $user->lang['JABBER']),
4c79b5
			'SEARCH_IMG'	=> $user->img('icon_user_search', $user->lang['SEARCH']),
4c79b5
4c79b5
			'S_PROFILE_ACTION'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
4c79b5
			'S_GROUP_OPTIONS'	=> $group_options,
4c79b5
			'S_CUSTOM_FIELDS'	=> (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
4c79b5
4c79b5
			'U_USER_ADMIN'			=> ($auth->acl_get('a_user')) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=users&mode=overview&u=' . $user_id, true, $user->session_id) : '',
4c79b5
			'U_USER_BAN'			=> ($auth->acl_get('m_ban') && $user_id != $user->data['user_id']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=ban&mode=user&u=' . $user_id, true, $user->session_id) : '',
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_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&u={$user_id}") : '',
4c79b5
4c79b5
			'S_ZEBRA'			=> ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
4c79b5
			'U_ADD_FRIEND'		=> (!$friend) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
4c79b5
			'U_ADD_FOE'			=> (!$foe) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&mode=foes&add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
4c79b5
			'U_REMOVE_FRIEND'	=> ($friend) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&remove=1&usernames[]=' . $user_id) : '',
4c79b5
			'U_REMOVE_FOE'		=> ($foe) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&remove=1&mode=foes&usernames[]=' . $user_id) : '',
4c79b5
		));
4c79b5
4c79b5
		if (!empty($profile_fields['row']))
4c79b5
		{
4c79b5
			$template->assign_vars($profile_fields['row']);
4c79b5
		}
4c79b5
4c79b5
		if (!empty($profile_fields['blockrow']))
4c79b5
		{
4c79b5
			foreach ($profile_fields['blockrow'] as $field_data)
4c79b5
			{
4c79b5
				$template->assign_block_vars('custom_fields', $field_data);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Inactive reason/account?
4c79b5
		if ($member['user_type'] == USER_INACTIVE)
4c79b5
		{
4c79b5
			$user->add_lang('acp/common');
4c79b5
4c79b5
			$inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
4c79b5
4c79b5
			switch ($member['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
			$template->assign_vars(array(
4c79b5
				'S_USER_INACTIVE'		=> true,
4c79b5
				'USER_INACTIVE_REASON'	=> $inactive_reason)
4c79b5
			);
4c79b5
		}
4c79b5
4c79b5
		// Now generate page title
4c79b5
		$page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
4c79b5
		$template_html = 'memberlist_view.html';
4c79b5
4c79b5
	break;
4c79b5
4c79b5
	case 'email':
4c79b5
4c79b5
		// Send an email
4c79b5
		$page_title = $user->lang['SEND_EMAIL'];
4c79b5
		$template_html = 'memberlist_email.html';
4c79b5
4c79b5
		add_form_key('memberlist_email');
4c79b5
4c79b5
		if (!$config['email_enable'])
4c79b5
		{
4c79b5
			trigger_error('EMAIL_DISABLED');
4c79b5
		}
4c79b5
4c79b5
		if (!$auth->acl_get('u_sendemail'))
4c79b5
		{
4c79b5
			trigger_error('NO_EMAIL');
4c79b5
		}
4c79b5
4c79b5
		// Are we trying to abuse the facility?
4c79b5
		if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
4c79b5
		{
4c79b5
			trigger_error('FLOOD_EMAIL_LIMIT');
4c79b5
		}
4c79b5
4c79b5
		// Determine action...
4c79b5
		$user_id = request_var('u', 0);
4c79b5
		$topic_id = request_var('t', 0);
4c79b5
4c79b5
		// Send email to user...
4c79b5
		if ($user_id)
4c79b5
		{
4c79b5
			if ($user_id == ANONYMOUS || !$config['board_email_form'])
4c79b5
			{
4c79b5
				trigger_error('NO_EMAIL');
4c79b5
			}
4c79b5
4c79b5
			// Get the appropriate username, etc.
4c79b5
			$sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
4c79b5
				FROM ' . USERS_TABLE . "
4c79b5
				WHERE user_id = $user_id
4c79b5
					AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$row = $db->sql_fetchrow($result);
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (!$row)
4c79b5
			{
4c79b5
				trigger_error('NO_USER');
4c79b5
			}
4c79b5
4c79b5
			// Can we send email to this user?
4c79b5
			if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
4c79b5
			{
4c79b5
				trigger_error('NO_EMAIL');
4c79b5
			}
4c79b5
		}
4c79b5
		else if ($topic_id)
4c79b5
		{
4c79b5
			// Send topic heads-up to email address
4c79b5
			$sql = 'SELECT forum_id, topic_title
4c79b5
				FROM ' . TOPICS_TABLE . "
4c79b5
				WHERE topic_id = $topic_id";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$row = $db->sql_fetchrow($result);
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (!$row)
4c79b5
			{
4c79b5
				trigger_error('NO_TOPIC');
4c79b5
			}
4c79b5
4c79b5
			if ($row['forum_id'])
4c79b5
			{
4c79b5
				if (!$auth->acl_get('f_read', $row['forum_id']))
4c79b5
				{
4c79b5
					trigger_error('SORRY_AUTH_READ');
4c79b5
				}
4c79b5
4c79b5
				if (!$auth->acl_get('f_email', $row['forum_id']))
4c79b5
				{
4c79b5
					trigger_error('NO_EMAIL');
4c79b5
				}
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				// If global announcement, we need to check if the user is able to at least read and email in one forum...
4c79b5
				if (!$auth->acl_getf_global('f_read'))
4c79b5
				{
4c79b5
					trigger_error('SORRY_AUTH_READ');
4c79b5
				}
4c79b5
4c79b5
				if (!$auth->acl_getf_global('f_email'))
4c79b5
				{
4c79b5
					trigger_error('NO_EMAIL');
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			trigger_error('NO_EMAIL');
4c79b5
		}
4c79b5
4c79b5
		$error = array();
4c79b5
4c79b5
		$name		= utf8_normalize_nfc(request_var('name', '', true));
4c79b5
		$email		= request_var('email', '');
4c79b5
		$email_lang = request_var('lang', $config['default_lang']);
4c79b5
		$subject	= utf8_normalize_nfc(request_var('subject', '', true));
4c79b5
		$message	= utf8_normalize_nfc(request_var('message', '', true));
4c79b5
		$cc			= (isset($_POST['cc_email'])) ? true : false;
4c79b5
		$submit		= (isset($_POST['submit'])) ? true : false;
4c79b5
4c79b5
		if ($submit)
4c79b5
		{
4c79b5
			if (!check_form_key('memberlist_email'))
4c79b5
			{
4c79b5
				$error[] = 'FORM_INVALID';
4c79b5
			}
4c79b5
			if ($user_id)
4c79b5
			{
4c79b5
				if (!$subject)
4c79b5
				{
4c79b5
					$error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
4c79b5
				}
4c79b5
4c79b5
				if (!$message)
4c79b5
				{
4c79b5
					$error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
4c79b5
				}
4c79b5
4c79b5
				$name = $row['username'];
4c79b5
				$email_lang = $row['user_lang'];
4c79b5
				$email = $row['user_email'];
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email))
4c79b5
				{
4c79b5
					$error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
4c79b5
				}
4c79b5
4c79b5
				if (!$name)
4c79b5
				{
4c79b5
					$error[] = $user->lang['EMPTY_NAME_EMAIL'];
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if (!sizeof($error))
4c79b5
			{
4c79b5
				$sql = 'UPDATE ' . USERS_TABLE . '
4c79b5
					SET user_emailtime = ' . time() . '
4c79b5
					WHERE user_id = ' . $user->data['user_id'];
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
4c79b5
				$messenger = new messenger(false);
4c79b5
				$email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify';
4c79b5
4c79b5
				$mail_to_users = array();
4c79b5
4c79b5
				$mail_to_users[] = array(
4c79b5
					'email_lang'		=> $email_lang,
4c79b5
					'email'				=> $email,
4c79b5
					'name'				=> $name,
4c79b5
					'username'			=> ($user_id) ? $row['username'] : '',
4c79b5
					'to_name'			=> $name,
4c79b5
					'user_jabber'		=> ($user_id) ? $row['user_jabber'] : '',
4c79b5
					'user_notify_type'	=> ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL,
4c79b5
					'topic_title'		=> (!$user_id) ? $row['topic_title'] : '',
4c79b5
					'forum_id'			=> (!$user_id) ? $row['forum_id'] : 0,
4c79b5
				);
4c79b5
4c79b5
				// Ok, now the same email if CC specified, but without exposing the users email address
4c79b5
				if ($cc)
4c79b5
				{
4c79b5
					$mail_to_users[] = array(
4c79b5
						'email_lang'		=> $user->data['user_lang'],
4c79b5
						'email'				=> $user->data['user_email'],
4c79b5
						'name'				=> $user->data['username'],
4c79b5
						'username'			=> $user->data['username'],
4c79b5
						'to_name'			=> $name,
4c79b5
						'user_jabber'		=> $user->data['user_jabber'],
4c79b5
						'user_notify_type'	=> ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL,
4c79b5
						'topic_title'		=> (!$user_id) ? $row['topic_title'] : '',
4c79b5
						'forum_id'			=> (!$user_id) ? $row['forum_id'] : 0,
4c79b5
					);
4c79b5
				}
4c79b5
4c79b5
				foreach ($mail_to_users as $row)
4c79b5
				{
4c79b5
					$messenger->template($email_tpl, $row['email_lang']);
4c79b5
					$messenger->replyto($user->data['user_email']);
4c79b5
					$messenger->to($row['email'], $row['name']);
4c79b5
4c79b5
					if ($user_id)
4c79b5
					{
4c79b5
						$messenger->subject(htmlspecialchars_decode($subject));
4c79b5
						$messenger->im($row['user_jabber'], $row['username']);
4c79b5
						$notify_type = $row['user_notify_type'];
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$notify_type = NOTIFY_EMAIL;
4c79b5
					}
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
						'BOARD_CONTACT'	=> $config['board_contact'],
4c79b5
						'TO_USERNAME'	=> htmlspecialchars_decode($row['to_name']),
4c79b5
						'FROM_USERNAME'	=> htmlspecialchars_decode($user->data['username']),
4c79b5
						'MESSAGE'		=> htmlspecialchars_decode($message))
4c79b5
					);
4c79b5
4c79b5
					if ($topic_id)
4c79b5
					{
4c79b5
						$messenger->assign_vars(array(
4c79b5
							'TOPIC_NAME'	=> htmlspecialchars_decode($row['topic_title']),
4c79b5
							'U_TOPIC'		=> generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id")
4c79b5
						);
4c79b5
					}
4c79b5
4c79b5
					$messenger->send($notify_type);
4c79b5
				}
4c79b5
4c79b5
				meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
4c79b5
				$message = ($user_id) ? sprintf($user->lang['RETURN_INDEX'], '', '') : sprintf($user->lang['RETURN_TOPIC'],  '', '');
4c79b5
				trigger_error($user->lang['EMAIL_SENT'] . '

' . $message);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ($user_id)
4c79b5
		{
4c79b5
			$template->assign_vars(array(
4c79b5
				'S_SEND_USER'	=> true,
4c79b5
				'USERNAME'		=> $row['username'],
4c79b5
4c79b5
				'L_EMAIL_BODY_EXPLAIN'	=> $user->lang['EMAIL_BODY_EXPLAIN'],
4c79b5
				'S_POST_ACTION'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id))
4c79b5
			);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$template->assign_vars(array(
4c79b5
				'EMAIL'				=> $email,
4c79b5
				'NAME'				=> $name,
4c79b5
				'S_LANG_OPTIONS'	=> language_select($email_lang),
4c79b5
4c79b5
				'L_EMAIL_BODY_EXPLAIN'	=> $user->lang['EMAIL_TOPIC_EXPLAIN'],
4c79b5
				'S_POST_ACTION'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&t=' . $topic_id))
4c79b5
			);
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'ERROR_MESSAGE'		=> (sizeof($error)) ? implode('
', $error) : '')
4c79b5
		);
4c79b5
4c79b5
	break;
4c79b5
4c79b5
	case 'group':
4c79b5
	default:
4c79b5
		// The basic memberlist
4c79b5
		$page_title = $user->lang['MEMBERLIST'];
4c79b5
		$template_html = 'memberlist_body.html';
4c79b5
4c79b5
		// Sorting
4c79b5
		$sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_LOCATION'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT'], 'f' => $user->lang['WEBSITE'], 'g' => $user->lang['ICQ'], 'h' => $user->lang['AIM'], 'i' => $user->lang['MSNM'], 'j' => $user->lang['YIM'], 'k' => $user->lang['JABBER']);
4c79b5
		$sort_key_sql = array('a' => 'u.username_clean', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'f' => 'u.user_website', 'g' => 'u.user_icq', 'h' => 'u.user_aim', 'i' => 'u.user_msnm', 'j' => 'u.user_yim', 'k' => 'u.user_jabber');
4c79b5
4c79b5
		if ($auth->acl_get('a_user'))
4c79b5
		{
4c79b5
			$sort_key_text['e'] = $user->lang['SORT_EMAIL'];
4c79b5
			$sort_key_sql['e'] = 'u.user_email';
4c79b5
		}
4c79b5
4c79b5
		if ($auth->acl_get('u_viewonline'))
4c79b5
		{
4c79b5
			$sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
4c79b5
			$sort_key_sql['l'] = 'u.user_lastvisit';
4c79b5
		}
4c79b5
4c79b5
		$sort_key_text['m'] = $user->lang['SORT_RANK'];
4c79b5
		$sort_key_sql['m'] = 'u.user_rank';
4c79b5
4c79b5
		$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
4c79b5
4c79b5
		$s_sort_key = '';
4c79b5
		foreach ($sort_key_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 ($sort_dir_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
		// Additional sorting options for user search ... if search is enabled, if not
4c79b5
		// then only admins can make use of this (for ACP functionality)
4c79b5
		$sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
4c79b5
4c79b5
4c79b5
		$form			= request_var('form', '');
4c79b5
		$field			= request_var('field', '');
4c79b5
		$select_single 	= request_var('select_single', false);
4c79b5
4c79b5
		// Search URL parameters, if any of these are in the URL we do a search
4c79b5
		$search_params = array('username', 'email', 'icq', 'aim', 'yahoo', 'msn', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
4c79b5
4c79b5
		// We validate form and field here, only id/class allowed
4c79b5
		$form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
4c79b5
		$field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
4c79b5
		if (($mode == 'searchuser' || sizeof(array_intersect(array_keys($_GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
4c79b5
		{
4c79b5
			$username	= request_var('username', '', true);
4c79b5
			$email		= strtolower(request_var('email', ''));
4c79b5
			$icq		= request_var('icq', '');
4c79b5
			$aim		= request_var('aim', '');
4c79b5
			$yahoo		= request_var('yahoo', '');
4c79b5
			$msn		= request_var('msn', '');
4c79b5
			$jabber		= request_var('jabber', '');
4c79b5
			$search_group_id	= request_var('search_group_id', 0);
4c79b5
4c79b5
			$joined_select	= request_var('joined_select', 'lt');
4c79b5
			$active_select	= request_var('active_select', 'lt');
4c79b5
			$count_select	= request_var('count_select', 'eq');
4c79b5
			$joined			= explode('-', request_var('joined', ''));
4c79b5
			$active			= explode('-', request_var('active', ''));
4c79b5
			$count			= (request_var('count', '') !== '') ? request_var('count', 0) : '';
4c79b5
			$ipdomain		= request_var('ip', '');
4c79b5
4c79b5
			$find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
4c79b5
4c79b5
			$find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
4c79b5
			$s_find_count = '';
4c79b5
			foreach ($find_count as $key => $value)
4c79b5
			{
4c79b5
				$selected = ($count_select == $key) ? ' selected="selected"' : '';
4c79b5
				$s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
			}
4c79b5
4c79b5
			$find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
4c79b5
			$s_find_join_time = '';
4c79b5
			foreach ($find_time as $key => $value)
4c79b5
			{
4c79b5
				$selected = ($joined_select == $key) ? ' selected="selected"' : '';
4c79b5
				$s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
			}
4c79b5
4c79b5
			$s_find_active_time = '';
4c79b5
			foreach ($find_time as $key => $value)
4c79b5
			{
4c79b5
				$selected = ($active_select == $key) ? ' selected="selected"' : '';
4c79b5
				$s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
4c79b5
			}
4c79b5
4c79b5
			$sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
4c79b5
			$sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
4c79b5
			$sql_where .= ($icq) ? ' AND u.user_icq ' . $db->sql_like_expression(str_replace('*', $db->any_char, $icq)) . ' ' : '';
4c79b5
			$sql_where .= ($aim) ? ' AND u.user_aim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $aim)) . ' ' : '';
4c79b5
			$sql_where .= ($yahoo) ? ' AND u.user_yim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $yahoo)) . ' ' : '';
4c79b5
			$sql_where .= ($msn) ? ' AND u.user_msnm ' . $db->sql_like_expression(str_replace('*', $db->any_char, $msn)) . ' ' : '';
4c79b5
			$sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->any_char, $jabber)) . ' ' : '';
4c79b5
			$sql_where .= (is_numeric($count)) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
4c79b5
			$sql_where .= (sizeof($joined) > 1) ? " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . gmmktime(0, 0, 0, intval($joined[1]), intval($joined[2]), intval($joined[0])) : '';
4c79b5
			$sql_where .= ($auth->acl_get('u_viewonline') && sizeof($active) > 1) ? " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . gmmktime(0, 0, 0, $active[1], intval($active[2]), intval($active[0])) : '';
4c79b5
			$sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
4c79b5
4c79b5
			if ($search_group_id)
4c79b5
			{
4c79b5
				$sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
4c79b5
			}
4c79b5
4c79b5
			if ($ipdomain && $auth->acl_getf_global('m_info'))
4c79b5
			{
4c79b5
				if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
4c79b5
				{
4c79b5
					$hostnames = gethostbynamel($ipdomain);
4c79b5
4c79b5
					if ($hostnames !== false)
4c79b5
					{
4c79b5
						$ips = "'" . implode('\', \'', array_map(array($db, 'sql_escape'), preg_replace('#([0-9]{1,3}\.[0-9]{1,3}[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#', "\\1", gethostbynamel($ipdomain)))) . "'";
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						$ips = false;
4c79b5
					}
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
4c79b5
				}
4c79b5
4c79b5
				if ($ips === false)
4c79b5
				{
4c79b5
					// A minor fudge but it does the job :D
4c79b5
					$sql_where .= " AND u.user_id = 0";
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$ip_forums = array_keys($auth->acl_getf('m_info', true));
4c79b5
4c79b5
					$sql = 'SELECT DISTINCT poster_id
4c79b5
						FROM ' . POSTS_TABLE . '
4c79b5
						WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
4c79b5
							AND forum_id IN (0, " . implode(', ', $ip_forums) . ')';
4c79b5
					$result = $db->sql_query($sql);
4c79b5
4c79b5
					if ($row = $db->sql_fetchrow($result))
4c79b5
					{
4c79b5
						$ip_sql = array();
4c79b5
						do
4c79b5
						{
4c79b5
							$ip_sql[] = $row['poster_id'];
4c79b5
						}
4c79b5
						while ($row = $db->sql_fetchrow($result));
4c79b5
4c79b5
						$sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						// A minor fudge but it does the job :D
4c79b5
						$sql_where .= " AND u.user_id = 0";
4c79b5
					}
4c79b5
					unset($ip_forums);
4c79b5
4c79b5
					$db->sql_freeresult($result);
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$first_char = request_var('first_char', '');
4c79b5
4c79b5
		if ($first_char == 'other')
4c79b5
		{
4c79b5
			for ($i = 97; $i < 123; $i++)
4c79b5
			{
4c79b5
				$sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->any_char);
4c79b5
			}
4c79b5
		}
4c79b5
		else if ($first_char)
4c79b5
		{
4c79b5
			$sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->any_char);
4c79b5
		}
4c79b5
4c79b5
		// Are we looking at a usergroup? If so, fetch additional info
4c79b5
		// and further restrict the user info query
4c79b5
		if ($mode == 'group')
4c79b5
		{
4c79b5
			// We JOIN here to save a query for determining membership for hidden groups. ;)
4c79b5
			$sql = 'SELECT g.*, ug.user_id
4c79b5
				FROM ' . GROUPS_TABLE . ' g
4c79b5
				LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id'] . " AND ug.group_id = $group_id)
4c79b5
				WHERE g.group_id = $group_id";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$group_row = $db->sql_fetchrow($result);
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (!$group_row)
4c79b5
			{
4c79b5
				trigger_error('NO_GROUP');
4c79b5
			}
4c79b5
4c79b5
			switch ($group_row['group_type'])
4c79b5
			{
4c79b5
				case GROUP_OPEN:
4c79b5
					$group_row['l_group_type'] = 'OPEN';
4c79b5
				break;
4c79b5
4c79b5
				case GROUP_CLOSED:
4c79b5
					$group_row['l_group_type'] = 'CLOSED';
4c79b5
				break;
4c79b5
4c79b5
				case GROUP_HIDDEN:
4c79b5
					$group_row['l_group_type'] = 'HIDDEN';
4c79b5
4c79b5
					// Check for membership or special permissions
4c79b5
					if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
4c79b5
					{
4c79b5
						trigger_error('NO_GROUP');
4c79b5
					}
4c79b5
				break;
4c79b5
4c79b5
				case GROUP_SPECIAL:
4c79b5
					$group_row['l_group_type'] = 'SPECIAL';
4c79b5
				break;
4c79b5
4c79b5
				case GROUP_FREE:
4c79b5
					$group_row['l_group_type'] = 'FREE';
4c79b5
				break;
4c79b5
			}
4c79b5
4c79b5
			// Misusing the avatar function for displaying group avatars...
4c79b5
			$avatar_img = get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR');
4c79b5
4c79b5
			$rank_title = $rank_img = $rank_img_src = '';
4c79b5
			if ($group_row['group_rank'])
4c79b5
			{
4c79b5
				if (isset($ranks['special'][$group_row['group_rank']]))
4c79b5
				{
4c79b5
					$rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
4c79b5
				}
4c79b5
				$rank_img = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? '' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '
' : '';
4c79b5
				$rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : '';
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$rank_title = '';
4c79b5
				$rank_img = '';
4c79b5
				$rank_img_src = '';
4c79b5
			}
4c79b5
4c79b5
			$template->assign_vars(array(
4c79b5
				'GROUP_DESC'	=> generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']),
4c79b5
				'GROUP_NAME'	=> ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
4c79b5
				'GROUP_COLOR'	=> $group_row['group_colour'],
4c79b5
				'GROUP_TYPE'	=> $user->lang['GROUP_IS_' . $group_row['l_group_type']],
4c79b5
				'GROUP_RANK'	=> $rank_title,
4c79b5
4c79b5
				'AVATAR_IMG'	=> $avatar_img,
4c79b5
				'RANK_IMG'		=> $rank_img,
4c79b5
				'RANK_IMG_SRC'	=> $rank_img_src,
4c79b5
4c79b5
				'U_PM'			=> ($auth->acl_get('u_sendpm') && $auth->acl_get('u_masspm_group') && $group_row['group_receive_pm'] && $config['allow_privmsg'] && $config['allow_mass_pm']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&g=' . $group_id) : '',)
4c79b5
			);
4c79b5
4c79b5
			$sql_select = ', ug.group_leader';
4c79b5
			$sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
4c79b5
			$order_by = 'ug.group_leader DESC, ';
4c79b5
4c79b5
			$sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
4c79b5
			$sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
4c79b5
		}
4c79b5
4c79b5
		// Sorting and order
4c79b5
		if (!isset($sort_key_sql[$sort_key]))
4c79b5
		{
4c79b5
			$sort_key = $default_key;
4c79b5
		}
4c79b5
4c79b5
		$order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
4c79b5
4c79b5
		// Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
4c79b5
		if ($sort_key == 'm')
4c79b5
		{
4c79b5
			$order_by .= ', u.user_posts DESC';
4c79b5
		}
4c79b5
4c79b5
		// Count the users ...
4c79b5
		if ($sql_where)
4c79b5
		{
4c79b5
			$sql = 'SELECT COUNT(u.user_id) AS total_users
4c79b5
				FROM ' . USERS_TABLE . " u$sql_from
4c79b5
				WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
4c79b5
				$sql_where";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$total_users = (int) $db->sql_fetchfield('total_users');
4c79b5
			$db->sql_freeresult($result);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$total_users = $config['num_users'];
4c79b5
		}
4c79b5
4c79b5
		$s_char_options = '<option value=""' . ((!$first_char) ? ' selected="selected"' : '') . '>   </option>';
4c79b5
		for ($i = 97; $i < 123; $i++)
4c79b5
		{
4c79b5
			$s_char_options .= '<option value="' . chr($i) . '"' . (($first_char == chr($i)) ? ' selected="selected"' : '') . '>' . chr($i-32) . '</option>';
4c79b5
		}
4c79b5
		$s_char_options .= '<option value="other"' . (($first_char == 'other') ? ' selected="selected"' : '') . '>' . $user->lang['OTHER'] . '</option>';
4c79b5
4c79b5
		// Build a relevant pagination_url
4c79b5
		$params = $sort_params = array();
4c79b5
4c79b5
		// We do not use request_var() here directly to save some calls (not all variables are set)
4c79b5
		$check_params = array(
4c79b5
			'g'				=> array('g', 0),
4c79b5
			'sk'			=> array('sk', $default_key),
4c79b5
			'sd'			=> array('sd', 'a'),
4c79b5
			'form'			=> array('form', ''),
4c79b5
			'field'			=> array('field', ''),
4c79b5
			'select_single'	=> array('select_single', $select_single),
4c79b5
			'username'		=> array('username', '', true),
4c79b5
			'email'			=> array('email', ''),
4c79b5
			'icq'			=> array('icq', ''),
4c79b5
			'aim'			=> array('aim', ''),
4c79b5
			'yahoo'			=> array('yahoo', ''),
4c79b5
			'msn'			=> array('msn', ''),
4c79b5
			'jabber'		=> array('jabber', ''),
4c79b5
			'search_group_id'	=> array('search_group_id', 0),
4c79b5
			'joined_select'	=> array('joined_select', 'lt'),
4c79b5
			'active_select'	=> array('active_select', 'lt'),
4c79b5
			'count_select'	=> array('count_select', 'eq'),
4c79b5
			'joined'		=> array('joined', ''),
4c79b5
			'active'		=> array('active', ''),
4c79b5
			'count'			=> (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
4c79b5
			'ipdomain'		=> array('ip', ''),
4c79b5
			'first_char'	=> array('first_char', ''),
4c79b5
		);
4c79b5
4c79b5
		foreach ($check_params as $key => $call)
4c79b5
		{
4c79b5
			if (!isset($_REQUEST[$key]))
4c79b5
			{
4c79b5
				continue;
4c79b5
			}
4c79b5
4c79b5
			$param = call_user_func_array('request_var', $call);
4c79b5
			$param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
4c79b5
			$params[] = $param;
4c79b5
4c79b5
			if ($key != 'sk' && $key != 'sd')
4c79b5
			{
4c79b5
				$sort_params[] = $param;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&' . implode('&', $params) : ''));
4c79b5
4c79b5
		if ($mode)
4c79b5
		{
4c79b5
			$params[] = "mode=$mode";
4c79b5
		}
4c79b5
		$sort_params[] = "mode=$mode";
4c79b5
4c79b5
		$pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&', $params));
4c79b5
		$sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&', $sort_params));
4c79b5
4c79b5
		unset($search_params, $sort_params);
4c79b5
4c79b5
		// Some search user specific data
4c79b5
		if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
4c79b5
		{
4c79b5
			$group_selected = request_var('search_group_id', 0);
4c79b5
			$s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '> </option>';
4c79b5
			$group_ids = array();
4c79b5
4c79b5
			/**
4c79b5
			* @todo add this to a separate function (function is responsible for returning the groups the user is able to see based on the users group membership)
4c79b5
			*/
4c79b5
4c79b5
			if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
4c79b5
			{
4c79b5
				$sql = 'SELECT group_id, group_name, group_type
4c79b5
					FROM ' . GROUPS_TABLE;
4c79b5
4c79b5
				if (!$config['coppa_enable'])
4c79b5
				{
4c79b5
					$sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
4c79b5
				}
4c79b5
4c79b5
				$sql .= ' ORDER BY group_name ASC';
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$sql = 'SELECT g.group_id, g.group_name, g.group_type
4c79b5
					FROM ' . GROUPS_TABLE . ' g
4c79b5
					LEFT JOIN ' . USER_GROUP_TABLE . ' ug
4c79b5
						ON (
4c79b5
							g.group_id = ug.group_id
4c79b5
							AND ug.user_id = ' . $user->data['user_id'] . '
4c79b5
							AND ug.user_pending = 0
4c79b5
						)
4c79b5
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
4c79b5
4c79b5
				if (!$config['coppa_enable'])
4c79b5
				{
4c79b5
					$sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
4c79b5
				}
4c79b5
4c79b5
				$sql .= ' ORDER BY g.group_name ASC';
4c79b5
			}
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$group_ids[] = $row['group_id'];
4c79b5
				$s_group_select .= '<option value="' . $row['group_id'] . '"' . (($group_selected == $row['group_id']) ? ' selected="selected"' : '') . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
4c79b5
			{
4c79b5
				trigger_error('NO_GROUP');
4c79b5
			}
4c79b5
4c79b5
			$template->assign_vars(array(
4c79b5
				'USERNAME'	=> $username,
4c79b5
				'EMAIL'		=> $email,
4c79b5
				'ICQ'		=> $icq,
4c79b5
				'AIM'		=> $aim,
4c79b5
				'YAHOO'		=> $yahoo,
4c79b5
				'MSNM'		=> $msn,
4c79b5
				'JABBER'	=> $jabber,
4c79b5
				'JOINED'	=> implode('-', $joined),
4c79b5
				'ACTIVE'	=> implode('-', $active),
4c79b5
				'COUNT'		=> $count,
4c79b5
				'IP'		=> $ipdomain,
4c79b5
4c79b5
				'S_IP_SEARCH_ALLOWED'	=> ($auth->acl_getf_global('m_info')) ? true : false,
4c79b5
				'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
4c79b5
				'S_IN_SEARCH_POPUP'		=> ($form && $field) ? true : false,
4c79b5
				'S_SEARCH_USER'			=> true,
4c79b5
				'S_FORM_NAME'			=> $form,
4c79b5
				'S_FIELD_NAME'			=> $field,
4c79b5
				'S_SELECT_SINGLE'		=> $select_single,
4c79b5
				'S_COUNT_OPTIONS'		=> $s_find_count,
4c79b5
				'S_SORT_OPTIONS'		=> $s_sort_key,
4c79b5
				'S_JOINED_TIME_OPTIONS'	=> $s_find_join_time,
4c79b5
				'S_ACTIVE_TIME_OPTIONS'	=> $s_find_active_time,
4c79b5
				'S_GROUP_SELECT'		=> $s_group_select,
4c79b5
				'S_USER_SEARCH_ACTION'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&form=$form&field=$field"))
4c79b5
			);
4c79b5
		}
4c79b5
4c79b5
		// Get us some users :D
4c79b5
		$sql = "SELECT u.user_id
4c79b5
			FROM " . USERS_TABLE . " u
4c79b5
				$sql_from
4c79b5
			WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
4c79b5
				$sql_where
4c79b5
			ORDER BY $order_by";
4c79b5
		$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
4c79b5
4c79b5
		$user_list = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$user_list[] = (int) $row['user_id'];
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
		$leaders_set = false;
4c79b5
		// So, did we get any users?
4c79b5
		if (sizeof($user_list))
4c79b5
		{
4c79b5
			// Session time?! Session time...
4c79b5
			$sql = 'SELECT session_user_id, MAX(session_time) AS session_time
4c79b5
				FROM ' . SESSIONS_TABLE . '
4c79b5
				WHERE session_time >= ' . (time() - $config['session_length']) . '
4c79b5
					AND ' . $db->sql_in_set('session_user_id', $user_list) . '
4c79b5
				GROUP BY session_user_id';
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			$session_times = array();
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$session_times[$row['session_user_id']] = $row['session_time'];
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			// Do the SQL thang
4c79b5
			if ($mode == 'group')
4c79b5
			{
4c79b5
				$sql = "SELECT u.*
4c79b5
						$sql_select
4c79b5
					FROM " . USERS_TABLE . " u
4c79b5
						$sql_from
4c79b5
					WHERE " . $db->sql_in_set('u.user_id', $user_list) . "
4c79b5
						$sql_where_data";
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . USERS_TABLE . '
4c79b5
					WHERE ' . $db->sql_in_set('user_id', $user_list);
4c79b5
			}
4c79b5
			$result = $db->sql_query($sql);
4c79b5
4c79b5
			$id_cache = array();
4c79b5
			while ($row = $db->sql_fetchrow($result))
4c79b5
			{
4c79b5
				$row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : 0;
4c79b5
				$row['last_visit'] = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
4c79b5
4c79b5
				$id_cache[$row['user_id']] = $row;
4c79b5
			}
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			// Load custom profile fields
4c79b5
			if ($config['load_cpf_memberlist'])
4c79b5
			{
4c79b5
				include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
4c79b5
				$cp = new custom_profile();
4c79b5
4c79b5
				// Grab all profile fields from users in id cache for later use - similar to the poster cache
4c79b5
				$profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
4c79b5
			}
4c79b5
4c79b5
			// If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...
4c79b5
			if ($sort_key == 'l')
4c79b5
			{
4c79b5
//				uasort($id_cache, create_function('$first, $second', "return (\$first['last_visit'] == \$second['last_visit']) ? 0 : ((\$first['last_visit'] < \$second['last_visit']) ? $lesser_than : ($lesser_than * -1));"));
4c79b5
				usort($user_list,  '_sort_last_active');
4c79b5
			}
4c79b5
4c79b5
			for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i)
4c79b5
			{
4c79b5
				$user_id = $user_list[$i];
4c79b5
				$row =& $id_cache[$user_id];
4c79b5
				$is_leader = (isset($row['group_leader']) && $row['group_leader']) ? true : false;
4c79b5
				$leaders_set = ($leaders_set || $is_leader);
4c79b5
4c79b5
				$cp_row = array();
4c79b5
				if ($config['load_cpf_memberlist'])
4c79b5
				{
4c79b5
					$cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
4c79b5
				}
4c79b5
4c79b5
				$memberrow = array_merge(show_profile($row), array(
4c79b5
					'ROW_NUMBER'		=> $i + ($start + 1),
4c79b5
4c79b5
					'S_CUSTOM_PROFILE'	=> (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
4c79b5
					'S_GROUP_LEADER'	=> $is_leader,
4c79b5
4c79b5
					'U_VIEW_PROFILE'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $user_id))
4c79b5
				);
4c79b5
4c79b5
				if (isset($cp_row['row']) && sizeof($cp_row['row']))
4c79b5
				{
4c79b5
					$memberrow = array_merge($memberrow, $cp_row['row']);
4c79b5
				}
4c79b5
4c79b5
				$template->assign_block_vars('memberrow', $memberrow);
4c79b5
4c79b5
				if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
4c79b5
				{
4c79b5
					foreach ($cp_row['blockrow'] as $field_data)
4c79b5
					{
4c79b5
						$template->assign_block_vars('memberrow.custom_fields', $field_data);
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				unset($id_cache[$user_id]);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Generate page
4c79b5
		$template->assign_vars(array(
4c79b5
			'PAGINATION'	=> generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
4c79b5
			'PAGE_NUMBER'	=> on_page($total_users, $config['topics_per_page'], $start),
4c79b5
			'TOTAL_USERS'	=> ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
4c79b5
4c79b5
			'PROFILE_IMG'	=> $user->img('icon_user_profile', $user->lang['PROFILE']),
4c79b5
			'PM_IMG'		=> $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
4c79b5
			'EMAIL_IMG'		=> $user->img('icon_contact_email', $user->lang['EMAIL']),
4c79b5
			'WWW_IMG'		=> $user->img('icon_contact_www', $user->lang['WWW']),
4c79b5
			'ICQ_IMG'		=> $user->img('icon_contact_icq', $user->lang['ICQ']),
4c79b5
			'AIM_IMG'		=> $user->img('icon_contact_aim', $user->lang['AIM']),
4c79b5
			'MSN_IMG'		=> $user->img('icon_contact_msnm', $user->lang['MSNM']),
4c79b5
			'YIM_IMG'		=> $user->img('icon_contact_yahoo', $user->lang['YIM']),
4c79b5
			'JABBER_IMG'	=> $user->img('icon_contact_jabber', $user->lang['JABBER']),
4c79b5
			'SEARCH_IMG'	=> $user->img('icon_user_search', $user->lang['SEARCH']),
4c79b5
4c79b5
			'U_FIND_MEMBER'			=> ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser' . (($start) ? "&start=$start" : '') . (!empty($params) ? '&' . implode('&', $params) : '')) : '',
4c79b5
			'U_HIDE_FIND_MEMBER'	=> ($mode == 'searchuser') ? $u_hide_find_member : '',
4c79b5
			'U_SORT_USERNAME'		=> $sort_url . '&sk=a&sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_FROM'			=> $sort_url . '&sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_JOINED'			=> $sort_url . '&sk=c&sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_POSTS'			=> $sort_url . '&sk=d&sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_EMAIL'			=> $sort_url . '&sk=e&sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_WEBSITE'		=> $sort_url . '&sk=f&sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_LOCATION'		=> $sort_url . '&sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_ICQ'			=> $sort_url . '&sk=g&sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_AIM'			=> $sort_url . '&sk=h&sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_MSN'			=> $sort_url . '&sk=i&sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_YIM'			=> $sort_url . '&sk=j&sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_SORT_ACTIVE'			=> ($auth->acl_get('u_viewonline')) ? $sort_url . '&sk=l&sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
4c79b5
			'U_SORT_RANK'			=> $sort_url . '&sk=m&sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
			'U_LIST_CHAR'			=> $sort_url . '&sk=a&sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
4c79b5
4c79b5
			'S_SHOW_GROUP'		=> ($mode == 'group') ? true : false,
4c79b5
			'S_VIEWONLINE'		=> $auth->acl_get('u_viewonline'),
4c79b5
			'S_LEADERS_SET'		=> $leaders_set,
4c79b5
			'S_MODE_SELECT'		=> $s_sort_key,
4c79b5
			'S_ORDER_SELECT'	=> $s_sort_dir,
4c79b5
			'S_CHAR_OPTIONS'	=> $s_char_options,
4c79b5
			'S_MODE_ACTION'		=> $pagination_url)
4c79b5
		);
4c79b5
}
4c79b5
4c79b5
// Output the page
4c79b5
page_header($page_title);
4c79b5
4c79b5
$template->set_filenames(array(
4c79b5
	'body' => $template_html)
4c79b5
);
4c79b5
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
4c79b5
4c79b5
page_footer();
4c79b5
4c79b5
/**
4c79b5
* Prepare profile data
4c79b5
*/
4c79b5
function show_profile($data)
4c79b5
{
4c79b5
	global $config, $auth, $template, $user, $phpEx, $phpbb_root_path;
4c79b5
4c79b5
	$username = $data['username'];
4c79b5
	$user_id = $data['user_id'];
4c79b5
4c79b5
	$rank_title = $rank_img = $rank_img_src = '';
4c79b5
	get_user_rank($data['user_rank'], (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src);
4c79b5
4c79b5
	if (!empty($data['user_allow_viewemail']) || $auth->acl_get('a_user'))
4c79b5
	{
4c79b5
		$email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']);
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$email = '';
4c79b5
	}
4c79b5
4c79b5
	if ($config['load_onlinetrack'])
4c79b5
	{
4c79b5
		$update_time = $config['load_online_time'] * 60;
4c79b5
		$online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$online = false;
4c79b5
	}
4c79b5
4c79b5
	if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))
4c79b5
	{
4c79b5
		$last_visit = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		$last_visit = '';
4c79b5
	}
4c79b5
4c79b5
	$age = '';
4c79b5
4c79b5
	if ($config['allow_birthdays'] && $data['user_birthday'])
4c79b5
	{
4c79b5
		list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));
4c79b5
4c79b5
		if ($bday_year)
4c79b5
		{
4c79b5
			$now = getdate(time() + $user->timezone + $user->dst - date('Z'));
4c79b5
4c79b5
			$diff = $now['mon'] - $bday_month;
4c79b5
			if ($diff == 0)
4c79b5
			{
4c79b5
				$diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				$diff = ($diff < 0) ? 1 : 0;
4c79b5
			}
4c79b5
4c79b5
			$age = (int) ($now['year'] - $bday_year - $diff);
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	// Dump it out to the template
4c79b5
	return array(
4c79b5
		'AGE'			=> $age,
4c79b5
		'RANK_TITLE'	=> $rank_title,
4c79b5
		'JOINED'		=> $user->format_date($data['user_regdate']),
4c79b5
		'VISITED'		=> (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
4c79b5
		'POSTS'			=> ($data['user_posts']) ? $data['user_posts'] : 0,
4c79b5
		'WARNINGS'		=> isset($data['user_warnings']) ? $data['user_warnings'] : 0,
4c79b5
4c79b5
		'USERNAME_FULL'		=> get_username_string('full', $user_id, $username, $data['user_colour']),
4c79b5
		'USERNAME'			=> get_username_string('username', $user_id, $username, $data['user_colour']),
4c79b5
		'USER_COLOR'		=> get_username_string('colour', $user_id, $username, $data['user_colour']),
4c79b5
		'U_VIEW_PROFILE'	=> get_username_string('profile', $user_id, $username, $data['user_colour']),
4c79b5
4c79b5
		'A_USERNAME'		=> addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])),
4c79b5
4c79b5
		'AVATAR_IMG'		=> get_user_avatar($data['user_avatar'], $data['user_avatar_type'], $data['user_avatar_width'], $data['user_avatar_height']),
4c79b5
		'ONLINE_IMG'		=> (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
4c79b5
		'S_ONLINE'			=> ($config['load_onlinetrack'] && $online) ? true : false,
4c79b5
		'RANK_IMG'			=> $rank_img,
4c79b5
		'RANK_IMG_SRC'		=> $rank_img_src,
4c79b5
		'ICQ_STATUS_IMG'	=> (!empty($data['user_icq'])) ? '' : '',
4c79b5
		'S_JABBER_ENABLED'	=> ($config['jab_enable']) ? true : false,
4c79b5
4c79b5
		'U_SEARCH_USER'	=> ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&sr=posts") : '',
4c79b5
		'U_NOTES'		=> $auth->acl_getf_global('m_') ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $user_id, true, $user->session_id) : '',
4c79b5
		'U_WARN'		=> $auth->acl_get('m_warn') ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $user_id, true, $user->session_id) : '',
4c79b5
		'U_PM'			=> ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $user_id) : '',
4c79b5
		'U_EMAIL'		=> $email,
4c79b5
		'U_WWW'			=> (!empty($data['user_website'])) ? $data['user_website'] : '',
4c79b5
		'U_ICQ'			=> ($data['user_icq']) ? 'http://www.icq.com/people/webmsg.php?to=' . urlencode($data['user_icq']) : '',
4c79b5
		'U_AIM'			=> ($data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $user_id) : '',
4c79b5
		'U_YIM'			=> ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($data['user_yim']) . '&.src=pg' : '',
4c79b5
		'U_MSN'			=> ($data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $user_id) : '',
4c79b5
		'U_JABBER'		=> ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $user_id) : '',
4c79b5
		'LOCATION'		=> ($data['user_from']) ? $data['user_from'] : '',
4c79b5
4c79b5
		'USER_ICQ'			=> $data['user_icq'],
4c79b5
		'USER_AIM'			=> $data['user_aim'],
4c79b5
		'USER_YIM'			=> $data['user_yim'],
4c79b5
		'USER_MSN'			=> $data['user_msnm'],
4c79b5
		'USER_JABBER'		=> $data['user_jabber'],
4c79b5
		'USER_JABBER_IMG'	=> ($data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '',
4c79b5
4c79b5
		'L_VIEWING_PROFILE'	=> sprintf($user->lang['VIEWING_PROFILE'], $username),
4c79b5
	);
4c79b5
}
4c79b5
4c79b5
function _sort_last_active($first, $second)
4c79b5
{
4c79b5
	global $id_cache, $sort_dir;
4c79b5
4c79b5
	$lesser_than = ($sort_dir === 'd') ? -1 : 1;
4c79b5
4c79b5
	if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader']))
4c79b5
	{
4c79b5
		return -1;
4c79b5
	}
4c79b5
	else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader'])
4c79b5
	{
4c79b5
		return 1;
4c79b5
	}
4c79b5
	else
4c79b5
	{
4c79b5
		return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']);
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>