1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/memberlist.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1772 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package phpBB3
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +define('IN_PHPBB', true);
1.18 +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
1.19 +$phpEx = substr(strrchr(__FILE__, '.'), 1);
1.20 +include($phpbb_root_path . 'common.' . $phpEx);
1.21 +include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.22 +
1.23 +// Start session management
1.24 +$user->session_begin();
1.25 +$auth->acl($user->data);
1.26 +$user->setup(array('memberlist', 'groups'));
1.27 +
1.28 +// Grab data
1.29 +$mode = request_var('mode', '');
1.30 +$action = request_var('action', '');
1.31 +$user_id = request_var('u', ANONYMOUS);
1.32 +$username = request_var('un', '', true);
1.33 +$group_id = request_var('g', 0);
1.34 +$topic_id = request_var('t', 0);
1.35 +
1.36 +// Check our mode...
1.37 +if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'searchuser', 'leaders')))
1.38 +{
1.39 + trigger_error('NO_MODE');
1.40 +}
1.41 +
1.42 +switch ($mode)
1.43 +{
1.44 + case 'email':
1.45 + break;
1.46 +
1.47 + default:
1.48 + // Can this user view profiles/memberlist?
1.49 + if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
1.50 + {
1.51 + if ($user->data['user_id'] != ANONYMOUS)
1.52 + {
1.53 + trigger_error('NO_VIEW_USERS');
1.54 + }
1.55 +
1.56 + login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
1.57 + }
1.58 + break;
1.59 +}
1.60 +
1.61 +$start = request_var('start', 0);
1.62 +$submit = (isset($_POST['submit'])) ? true : false;
1.63 +
1.64 +$default_key = 'c';
1.65 +$sort_key = request_var('sk', $default_key);
1.66 +$sort_dir = request_var('sd', 'a');
1.67 +
1.68 +
1.69 +// Grab rank information for later
1.70 +$ranks = $cache->obtain_ranks();
1.71 +
1.72 +
1.73 +// What do you want to do today? ... oops, I think that line is taken ...
1.74 +switch ($mode)
1.75 +{
1.76 + case 'leaders':
1.77 + // Display a listing of board admins, moderators
1.78 + include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.79 +
1.80 + $page_title = $user->lang['THE_TEAM'];
1.81 + $template_html = 'memberlist_leaders.html';
1.82 +
1.83 + $user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false);
1.84 +
1.85 + $admin_id_ary = $global_mod_id_ary = $mod_id_ary = $forum_id_ary = array();
1.86 + foreach ($user_ary as $forum_id => $forum_ary)
1.87 + {
1.88 + foreach ($forum_ary as $auth_option => $id_ary)
1.89 + {
1.90 + if (!$forum_id)
1.91 + {
1.92 + if ($auth_option == 'a_')
1.93 + {
1.94 + $admin_id_ary = array_merge($admin_id_ary, $id_ary);
1.95 + }
1.96 + else
1.97 + {
1.98 + $global_mod_id_ary = array_merge($global_mod_id_ary, $id_ary);
1.99 + }
1.100 + continue;
1.101 + }
1.102 + else
1.103 + {
1.104 + $mod_id_ary = array_merge($mod_id_ary, $id_ary);
1.105 + }
1.106 +
1.107 + if ($forum_id)
1.108 + {
1.109 + foreach ($id_ary as $id)
1.110 + {
1.111 + $forum_id_ary[$id][] = $forum_id;
1.112 + }
1.113 + }
1.114 + }
1.115 + }
1.116 +
1.117 + $admin_id_ary = array_unique($admin_id_ary);
1.118 + $global_mod_id_ary = array_unique($global_mod_id_ary);
1.119 +
1.120 + $mod_id_ary = array_merge($mod_id_ary, $global_mod_id_ary);
1.121 + $mod_id_ary = array_unique($mod_id_ary);
1.122 +
1.123 + // Admin group id...
1.124 + $sql = 'SELECT group_id
1.125 + FROM ' . GROUPS_TABLE . "
1.126 + WHERE group_name = 'ADMINISTRATORS'";
1.127 + $result = $db->sql_query($sql);
1.128 + $admin_group_id = (int) $db->sql_fetchfield('group_id');
1.129 + $db->sql_freeresult($result);
1.130 +
1.131 + // Get group memberships for the admin id ary...
1.132 + $admin_memberships = group_memberships($admin_group_id, $admin_id_ary);
1.133 +
1.134 + $admin_user_ids = array();
1.135 +
1.136 + if (!empty($admin_memberships))
1.137 + {
1.138 + // ok, we only need the user ids...
1.139 + foreach ($admin_memberships as $row)
1.140 + {
1.141 + $admin_user_ids[$row['user_id']] = true;
1.142 + }
1.143 + }
1.144 + unset($admin_memberships);
1.145 +
1.146 + $sql = 'SELECT forum_id, forum_name
1.147 + FROM ' . FORUMS_TABLE;
1.148 + $result = $db->sql_query($sql);
1.149 +
1.150 + $forums = array();
1.151 + while ($row = $db->sql_fetchrow($result))
1.152 + {
1.153 + $forums[$row['forum_id']] = $row['forum_name'];
1.154 + }
1.155 + $db->sql_freeresult($result);
1.156 +
1.157 + $sql = $db->sql_build_query('SELECT', array(
1.158 + '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',
1.159 +
1.160 + 'FROM' => array(
1.161 + USERS_TABLE => 'u',
1.162 + GROUPS_TABLE => 'g'
1.163 + ),
1.164 +
1.165 + 'LEFT_JOIN' => array(
1.166 + array(
1.167 + 'FROM' => array(USER_GROUP_TABLE => 'ug'),
1.168 + 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id']
1.169 + )
1.170 + ),
1.171 +
1.172 + 'WHERE' => $db->sql_in_set('u.user_id', array_unique(array_merge($admin_id_ary, $mod_id_ary)), false, true) . '
1.173 + AND u.group_id = g.group_id',
1.174 +
1.175 + 'ORDER_BY' => 'g.group_name ASC, u.username_clean ASC'
1.176 + ));
1.177 + $result = $db->sql_query($sql);
1.178 +
1.179 + while ($row = $db->sql_fetchrow($result))
1.180 + {
1.181 + $which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod';
1.182 +
1.183 + // We sort out admins not within the 'Administrators' group.
1.184 + // Else, we will list those as admin only having the permission to view logs for example.
1.185 + if ($which_row == 'admin' && empty($admin_user_ids[$row['user_id']]))
1.186 + {
1.187 + // Remove from admin_id_ary, because the user may be a mod instead
1.188 + unset($admin_id_ary[array_search($row['user_id'], $admin_id_ary)]);
1.189 +
1.190 + if (!in_array($row['user_id'], $mod_id_ary) && !in_array($row['user_id'], $global_mod_id_ary))
1.191 + {
1.192 + continue;
1.193 + }
1.194 + else
1.195 + {
1.196 + $which_row = 'mod';
1.197 + }
1.198 + }
1.199 +
1.200 + $s_forum_select = '';
1.201 + $undisclosed_forum = false;
1.202 +
1.203 + if (isset($forum_id_ary[$row['user_id']]) && !in_array($row['user_id'], $global_mod_id_ary))
1.204 + {
1.205 + if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']])))
1.206 + {
1.207 + foreach ($forum_id_ary[$row['user_id']] as $forum_id)
1.208 + {
1.209 + if (isset($forums[$forum_id]))
1.210 + {
1.211 + if ($auth->acl_get('f_list', $forum_id))
1.212 + {
1.213 + $s_forum_select .= '<option value="">' . $forums[$forum_id] . '</option>';
1.214 + }
1.215 + else
1.216 + {
1.217 + $undisclosed_forum = true;
1.218 + }
1.219 + }
1.220 + }
1.221 + }
1.222 + }
1.223 +
1.224 + // If the mod is only moderating non-viewable forums we skip the user. There is no gain in displaying the person then...
1.225 + if (!$s_forum_select && $undisclosed_forum)
1.226 + {
1.227 +// $s_forum_select = '<option value="">' . $user->lang['FORUM_UNDISCLOSED'] . '</option>';
1.228 + continue;
1.229 + }
1.230 +
1.231 + // The person is moderating several "public" forums, therefore the person should be listed, but not giving the real group name if hidden.
1.232 + if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
1.233 + {
1.234 + $group_name = $user->lang['GROUP_UNDISCLOSED'];
1.235 + $u_group = '';
1.236 + }
1.237 + else
1.238 + {
1.239 + $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
1.240 + $u_group = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']);
1.241 + }
1.242 +
1.243 + $rank_title = $rank_img = '';
1.244 + get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);
1.245 +
1.246 + $template->assign_block_vars($which_row, array(
1.247 + 'USER_ID' => $row['user_id'],
1.248 + 'FORUMS' => $s_forum_select,
1.249 + 'RANK_TITLE' => $rank_title,
1.250 + 'GROUP_NAME' => $group_name,
1.251 + 'GROUP_COLOR' => $row['group_colour'],
1.252 +
1.253 + 'RANK_IMG' => $rank_img,
1.254 + 'RANK_IMG_SRC' => $rank_img_src,
1.255 +
1.256 + 'U_GROUP' => $u_group,
1.257 + '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']) : '',
1.258 +
1.259 + 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
1.260 + 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
1.261 + 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
1.262 + 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
1.263 + ));
1.264 + }
1.265 + $db->sql_freeresult($result);
1.266 +
1.267 + $template->assign_vars(array(
1.268 + 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
1.269 + );
1.270 + break;
1.271 +
1.272 + case 'contact':
1.273 +
1.274 + $page_title = $user->lang['IM_USER'];
1.275 + $template_html = 'memberlist_im.html';
1.276 +
1.277 + if (!$auth->acl_get('u_sendim'))
1.278 + {
1.279 + trigger_error('NOT_AUTHORISED');
1.280 + }
1.281 +
1.282 + $presence_img = '';
1.283 + switch ($action)
1.284 + {
1.285 + case 'aim':
1.286 + $lang = 'AIM';
1.287 + $sql_field = 'user_aim';
1.288 + $s_select = 'S_SEND_AIM';
1.289 + $s_action = '';
1.290 + break;
1.291 +
1.292 + case 'msnm':
1.293 + $lang = 'MSNM';
1.294 + $sql_field = 'user_msnm';
1.295 + $s_select = 'S_SEND_MSNM';
1.296 + $s_action = '';
1.297 + break;
1.298 +
1.299 + case 'jabber':
1.300 + $lang = 'JABBER';
1.301 + $sql_field = 'user_jabber';
1.302 + $s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
1.303 + $s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&action=$action&u=$user_id");
1.304 + break;
1.305 +
1.306 + default:
1.307 + trigger_error('NO_MODE', E_USER_ERROR);
1.308 + break;
1.309 + }
1.310 +
1.311 + // Grab relevant data
1.312 + $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
1.313 + FROM " . USERS_TABLE . "
1.314 + WHERE user_id = $user_id
1.315 + AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
1.316 + $result = $db->sql_query($sql);
1.317 + $row = $db->sql_fetchrow($result);
1.318 + $db->sql_freeresult($result);
1.319 +
1.320 + if (!$row)
1.321 + {
1.322 + trigger_error('NO_USER');
1.323 + }
1.324 + else if (empty($row[$sql_field]))
1.325 + {
1.326 + trigger_error('IM_NO_DATA');
1.327 + }
1.328 +
1.329 + // Post data grab actions
1.330 + switch ($action)
1.331 + {
1.332 + case 'jabber':
1.333 + add_form_key('memberlist_messaging');
1.334 +
1.335 + if ($submit && @extension_loaded('xml') && $config['jab_enable'])
1.336 + {
1.337 + if (check_form_key('memberlist_messaging'))
1.338 + {
1.339 +
1.340 + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
1.341 +
1.342 + $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
1.343 + $message = utf8_normalize_nfc(request_var('message', '', true));
1.344 +
1.345 + if (empty($message))
1.346 + {
1.347 + trigger_error('EMPTY_MESSAGE_IM');
1.348 + }
1.349 +
1.350 + $messenger = new messenger(false);
1.351 +
1.352 + $messenger->template('profile_send_im', $row['user_lang']);
1.353 + $messenger->subject(htmlspecialchars_decode($subject));
1.354 +
1.355 + $messenger->replyto($user->data['user_email']);
1.356 + $messenger->im($row['user_jabber'], $row['username']);
1.357 +
1.358 + $messenger->assign_vars(array(
1.359 + 'BOARD_CONTACT' => $config['board_contact'],
1.360 + 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
1.361 + 'TO_USERNAME' => htmlspecialchars_decode($row['username']),
1.362 + 'MESSAGE' => htmlspecialchars_decode($message))
1.363 + );
1.364 +
1.365 + $messenger->send(NOTIFY_IM);
1.366 +
1.367 + $s_select = 'S_SENT_JABBER';
1.368 + }
1.369 + else
1.370 + {
1.371 + trigger_error('FORM_INVALID');
1.372 + }
1.373 + }
1.374 + break;
1.375 + }
1.376 +
1.377 + // Send vars to the template
1.378 + $template->assign_vars(array(
1.379 + 'IM_CONTACT' => $row[$sql_field],
1.380 + 'A_IM_CONTACT' => addslashes($row[$sql_field]),
1.381 +
1.382 + 'U_AIM_CONTACT' => ($action == 'aim') ? 'aim:addbuddy?screenname=' . urlencode($row[$sql_field]) : '',
1.383 + 'U_AIM_MESSAGE' => ($action == 'aim') ? 'aim:goim?screenname=' . urlencode($row[$sql_field]) . '&message=' . urlencode($config['sitename']) : '',
1.384 +
1.385 + 'USERNAME' => $row['username'],
1.386 + 'CONTACT_NAME' => $row[$sql_field],
1.387 + 'SITENAME' => $config['sitename'],
1.388 +
1.389 + 'PRESENCE_IMG' => $presence_img,
1.390 +
1.391 + 'L_SEND_IM_EXPLAIN' => $user->lang['IM_' . $lang],
1.392 + 'L_IM_SENT_JABBER' => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
1.393 +
1.394 + $s_select => true,
1.395 + 'S_IM_ACTION' => $s_action)
1.396 + );
1.397 +
1.398 + break;
1.399 +
1.400 + case 'viewprofile':
1.401 + // Display a profile
1.402 + if ($user_id == ANONYMOUS && !$username)
1.403 + {
1.404 + trigger_error('NO_USER');
1.405 + }
1.406 +
1.407 + // Get user...
1.408 + $sql = 'SELECT *
1.409 + FROM ' . USERS_TABLE . '
1.410 + WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
1.411 + $result = $db->sql_query($sql);
1.412 + $member = $db->sql_fetchrow($result);
1.413 + $db->sql_freeresult($result);
1.414 +
1.415 + if (!$member)
1.416 + {
1.417 + trigger_error('NO_USER');
1.418 + }
1.419 +
1.420 + // a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
1.421 + // Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
1.422 + if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
1.423 + {
1.424 + if ($member['user_type'] == USER_IGNORE)
1.425 + {
1.426 + trigger_error('NO_USER');
1.427 + }
1.428 + else if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE)
1.429 + {
1.430 + trigger_error('NO_USER');
1.431 + }
1.432 + }
1.433 +
1.434 + $user_id = (int) $member['user_id'];
1.435 +
1.436 + // Get group memberships
1.437 + // Also get visiting user's groups to determine hidden group memberships if necessary.
1.438 + $auth_hidden_groups = ($user_id === (int) $user->data['user_id'] || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false;
1.439 + $sql_uid_ary = ($auth_hidden_groups) ? array($user_id) : array($user_id, (int) $user->data['user_id']);
1.440 +
1.441 + // Do the SQL thang
1.442 + $sql = 'SELECT g.group_id, g.group_name, g.group_type, ug.user_id
1.443 + FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
1.444 + WHERE ' . $db->sql_in_set('ug.user_id', $sql_uid_ary) . '
1.445 + AND g.group_id = ug.group_id
1.446 + AND ug.user_pending = 0';
1.447 + $result = $db->sql_query($sql);
1.448 +
1.449 + // Divide data into profile data and current user data
1.450 + $profile_groups = $user_groups = array();
1.451 + while ($row = $db->sql_fetchrow($result))
1.452 + {
1.453 + $row['user_id'] = (int) $row['user_id'];
1.454 + $row['group_id'] = (int) $row['group_id'];
1.455 +
1.456 + if ($row['user_id'] == $user_id)
1.457 + {
1.458 + $profile_groups[] = $row;
1.459 + }
1.460 + else
1.461 + {
1.462 + $user_groups[$row['group_id']] = $row['group_id'];
1.463 + }
1.464 + }
1.465 + $db->sql_freeresult($result);
1.466 +
1.467 + // Filter out hidden groups and sort groups by name
1.468 + $group_data = $group_sort = array();
1.469 + foreach ($profile_groups as $row)
1.470 + {
1.471 + if ($row['group_type'] == GROUP_SPECIAL)
1.472 + {
1.473 + // Lookup group name in language dictionary
1.474 + if (isset($user->lang['G_' . $row['group_name']]))
1.475 + {
1.476 + $row['group_name'] = $user->lang['G_' . $row['group_name']];
1.477 + }
1.478 + }
1.479 + else if (!$auth_hidden_groups && $row['group_type'] == GROUP_HIDDEN && !isset($user_groups[$row['group_id']]))
1.480 + {
1.481 + // Skip over hidden groups the user cannot see
1.482 + continue;
1.483 + }
1.484 +
1.485 + $group_sort[$row['group_id']] = utf8_clean_string($row['group_name']);
1.486 + $group_data[$row['group_id']] = $row;
1.487 + }
1.488 + unset($profile_groups);
1.489 + unset($user_groups);
1.490 + asort($group_sort);
1.491 +
1.492 + $group_options = '';
1.493 + foreach ($group_sort as $group_id => $null)
1.494 + {
1.495 + $row = $group_data[$group_id];
1.496 +
1.497 + $group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . $row['group_name'] . '</option>';
1.498 + }
1.499 + unset($group_data);
1.500 + unset($group_sort);
1.501 +
1.502 + // What colour is the zebra
1.503 + $sql = 'SELECT friend, foe
1.504 + FROM ' . ZEBRA_TABLE . "
1.505 + WHERE zebra_id = $user_id
1.506 + AND user_id = {$user->data['user_id']}";
1.507 +
1.508 + $result = $db->sql_query($sql);
1.509 + $row = $db->sql_fetchrow($result);
1.510 + $foe = ($row['foe']) ? true : false;
1.511 + $friend = ($row['friend']) ? true : false;
1.512 + $db->sql_freeresult($result);
1.513 +
1.514 + if ($config['load_onlinetrack'])
1.515 + {
1.516 + $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
1.517 + FROM ' . SESSIONS_TABLE . "
1.518 + WHERE session_user_id = $user_id";
1.519 + $result = $db->sql_query($sql);
1.520 + $row = $db->sql_fetchrow($result);
1.521 + $db->sql_freeresult($result);
1.522 +
1.523 + $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
1.524 + $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
1.525 + unset($row);
1.526 + }
1.527 +
1.528 + if ($config['load_user_activity'])
1.529 + {
1.530 + display_user_activity($member);
1.531 + }
1.532 +
1.533 + // Do the relevant calculations
1.534 + $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
1.535 + $posts_per_day = $member['user_posts'] / $memberdays;
1.536 + $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
1.537 +
1.538 +
1.539 + if ($member['user_sig'])
1.540 + {
1.541 + $member['user_sig'] = censor_text($member['user_sig']);
1.542 +
1.543 + if ($member['user_sig_bbcode_bitfield'])
1.544 + {
1.545 + include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
1.546 + $bbcode = new bbcode();
1.547 + $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
1.548 + }
1.549 +
1.550 + $member['user_sig'] = bbcode_nl2br($member['user_sig']);
1.551 + $member['user_sig'] = smiley_text($member['user_sig']);
1.552 + }
1.553 +
1.554 + $poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']);
1.555 +
1.556 + // We need to check if the modules 'zebra' ('friends' & 'foes' mode), 'notes' ('user_notes' mode) and 'warn' ('warn_user' mode) are accessible to decide if we can display appropriate links
1.557 + $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false;
1.558 +
1.559 + // Only check if the user is logged in
1.560 + if ($user->data['is_registered'])
1.561 + {
1.562 + if (!class_exists('p_master'))
1.563 + {
1.564 + include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
1.565 + }
1.566 + $module = new p_master();
1.567 +
1.568 + $module->list_modules('ucp');
1.569 + $module->list_modules('mcp');
1.570 +
1.571 + $user_notes_enabled = ($module->loaded('notes', 'user_notes')) ? true : false;
1.572 + $warn_user_enabled = ($module->loaded('warn', 'warn_user')) ? true : false;
1.573 + $zebra_enabled = ($module->loaded('zebra')) ? true : false;
1.574 + $friends_enabled = ($module->loaded('zebra', 'friends')) ? true : false;
1.575 + $foes_enabled = ($module->loaded('zebra', 'foes')) ? true : false;
1.576 +
1.577 + unset($module);
1.578 + }
1.579 +
1.580 + $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled));
1.581 +
1.582 + // Custom Profile Fields
1.583 + $profile_fields = array();
1.584 + if ($config['load_cpf_viewprofile'])
1.585 + {
1.586 + include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1.587 + $cp = new custom_profile();
1.588 + $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
1.589 + $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
1.590 + }
1.591 +
1.592 + // If the user has m_approve permission or a_user permission, then list then display unapproved posts
1.593 + if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
1.594 + {
1.595 + $sql = 'SELECT COUNT(post_id) as posts_in_queue
1.596 + FROM ' . POSTS_TABLE . '
1.597 + WHERE poster_id = ' . $user_id . '
1.598 + AND post_approved = 0';
1.599 + $result = $db->sql_query($sql);
1.600 + $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
1.601 + $db->sql_freeresult($result);
1.602 + }
1.603 + else
1.604 + {
1.605 + $member['posts_in_queue'] = 0;
1.606 + }
1.607 +
1.608 + $template->assign_vars(array(
1.609 + 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
1.610 +
1.611 + 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day),
1.612 + 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage),
1.613 +
1.614 + 'OCCUPATION' => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
1.615 + 'INTERESTS' => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
1.616 + 'SIGNATURE' => $member['user_sig'],
1.617 + 'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
1.618 +
1.619 + 'AVATAR_IMG' => $poster_avatar,
1.620 + 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
1.621 + 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
1.622 + 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
1.623 + 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
1.624 + 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
1.625 + 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
1.626 + 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
1.627 + 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
1.628 + 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
1.629 +
1.630 + 'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
1.631 + 'S_GROUP_OPTIONS' => $group_options,
1.632 + 'S_CUSTOM_FIELDS' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
1.633 +
1.634 + '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) : '',
1.635 + '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) : '',
1.636 + 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
1.637 +
1.638 + '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}&hash=" . generate_link_hash('switchperm')) : '',
1.639 +
1.640 + 'S_USER_NOTES' => ($user_notes_enabled) ? true : false,
1.641 + 'S_WARN_USER' => ($warn_user_enabled) ? true : false,
1.642 + 'S_ZEBRA' => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
1.643 + 'U_ADD_FRIEND' => (!$friend && !$foe && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
1.644 + 'U_ADD_FOE' => (!$friend && !$foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&mode=foes&add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
1.645 + 'U_REMOVE_FRIEND' => ($friend && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&remove=1&usernames[]=' . $user_id) : '',
1.646 + 'U_REMOVE_FOE' => ($foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&remove=1&mode=foes&usernames[]=' . $user_id) : '',
1.647 + ));
1.648 +
1.649 + if (!empty($profile_fields['row']))
1.650 + {
1.651 + $template->assign_vars($profile_fields['row']);
1.652 + }
1.653 +
1.654 + if (!empty($profile_fields['blockrow']))
1.655 + {
1.656 + foreach ($profile_fields['blockrow'] as $field_data)
1.657 + {
1.658 + $template->assign_block_vars('custom_fields', $field_data);
1.659 + }
1.660 + }
1.661 +
1.662 + // Inactive reason/account?
1.663 + if ($member['user_type'] == USER_INACTIVE)
1.664 + {
1.665 + $user->add_lang('acp/common');
1.666 +
1.667 + $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
1.668 +
1.669 + switch ($member['user_inactive_reason'])
1.670 + {
1.671 + case INACTIVE_REGISTER:
1.672 + $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
1.673 + break;
1.674 +
1.675 + case INACTIVE_PROFILE:
1.676 + $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
1.677 + break;
1.678 +
1.679 + case INACTIVE_MANUAL:
1.680 + $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
1.681 + break;
1.682 +
1.683 + case INACTIVE_REMIND:
1.684 + $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
1.685 + break;
1.686 + }
1.687 +
1.688 + $template->assign_vars(array(
1.689 + 'S_USER_INACTIVE' => true,
1.690 + 'USER_INACTIVE_REASON' => $inactive_reason)
1.691 + );
1.692 + }
1.693 +
1.694 + // Now generate page title
1.695 + $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
1.696 + $template_html = 'memberlist_view.html';
1.697 +
1.698 + break;
1.699 +
1.700 + case 'email':
1.701 +
1.702 + // Send an email
1.703 + $page_title = $user->lang['SEND_EMAIL'];
1.704 + $template_html = 'memberlist_email.html';
1.705 +
1.706 + add_form_key('memberlist_email');
1.707 +
1.708 + if (!$config['email_enable'])
1.709 + {
1.710 + trigger_error('EMAIL_DISABLED');
1.711 + }
1.712 +
1.713 + if (!$auth->acl_get('u_sendemail'))
1.714 + {
1.715 + trigger_error('NO_EMAIL');
1.716 + }
1.717 +
1.718 + // Are we trying to abuse the facility?
1.719 + if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
1.720 + {
1.721 + trigger_error('FLOOD_EMAIL_LIMIT');
1.722 + }
1.723 +
1.724 + // Determine action...
1.725 + $user_id = request_var('u', 0);
1.726 + $topic_id = request_var('t', 0);
1.727 +
1.728 + // Send email to user...
1.729 + if ($user_id)
1.730 + {
1.731 + if ($user_id == ANONYMOUS || !$config['board_email_form'])
1.732 + {
1.733 + trigger_error('NO_EMAIL');
1.734 + }
1.735 +
1.736 + // Get the appropriate username, etc.
1.737 + $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
1.738 + FROM ' . USERS_TABLE . "
1.739 + WHERE user_id = $user_id
1.740 + AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
1.741 + $result = $db->sql_query($sql);
1.742 + $row = $db->sql_fetchrow($result);
1.743 + $db->sql_freeresult($result);
1.744 +
1.745 + if (!$row)
1.746 + {
1.747 + trigger_error('NO_USER');
1.748 + }
1.749 +
1.750 + // Can we send email to this user?
1.751 + if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
1.752 + {
1.753 + trigger_error('NO_EMAIL');
1.754 + }
1.755 + }
1.756 + else if ($topic_id)
1.757 + {
1.758 + // Send topic heads-up to email address
1.759 + $sql = 'SELECT forum_id, topic_title
1.760 + FROM ' . TOPICS_TABLE . "
1.761 + WHERE topic_id = $topic_id";
1.762 + $result = $db->sql_query($sql);
1.763 + $row = $db->sql_fetchrow($result);
1.764 + $db->sql_freeresult($result);
1.765 +
1.766 + if (!$row)
1.767 + {
1.768 + trigger_error('NO_TOPIC');
1.769 + }
1.770 +
1.771 + if ($row['forum_id'])
1.772 + {
1.773 + if (!$auth->acl_get('f_read', $row['forum_id']))
1.774 + {
1.775 + trigger_error('SORRY_AUTH_READ');
1.776 + }
1.777 +
1.778 + if (!$auth->acl_get('f_email', $row['forum_id']))
1.779 + {
1.780 + trigger_error('NO_EMAIL');
1.781 + }
1.782 + }
1.783 + else
1.784 + {
1.785 + // If global announcement, we need to check if the user is able to at least read and email in one forum...
1.786 + if (!$auth->acl_getf_global('f_read'))
1.787 + {
1.788 + trigger_error('SORRY_AUTH_READ');
1.789 + }
1.790 +
1.791 + if (!$auth->acl_getf_global('f_email'))
1.792 + {
1.793 + trigger_error('NO_EMAIL');
1.794 + }
1.795 + }
1.796 + }
1.797 + else
1.798 + {
1.799 + trigger_error('NO_EMAIL');
1.800 + }
1.801 +
1.802 + $error = array();
1.803 +
1.804 + $name = utf8_normalize_nfc(request_var('name', '', true));
1.805 + $email = request_var('email', '');
1.806 + $email_lang = request_var('lang', $config['default_lang']);
1.807 + $subject = utf8_normalize_nfc(request_var('subject', '', true));
1.808 + $message = utf8_normalize_nfc(request_var('message', '', true));
1.809 + $cc = (isset($_POST['cc_email'])) ? true : false;
1.810 + $submit = (isset($_POST['submit'])) ? true : false;
1.811 +
1.812 + if ($submit)
1.813 + {
1.814 + if (!check_form_key('memberlist_email'))
1.815 + {
1.816 + $error[] = 'FORM_INVALID';
1.817 + }
1.818 + if ($user_id)
1.819 + {
1.820 + if (!$subject)
1.821 + {
1.822 + $error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
1.823 + }
1.824 +
1.825 + if (!$message)
1.826 + {
1.827 + $error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
1.828 + }
1.829 +
1.830 + $name = $row['username'];
1.831 + $email_lang = $row['user_lang'];
1.832 + $email = $row['user_email'];
1.833 + }
1.834 + else
1.835 + {
1.836 + if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email))
1.837 + {
1.838 + $error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
1.839 + }
1.840 +
1.841 + if (!$name)
1.842 + {
1.843 + $error[] = $user->lang['EMPTY_NAME_EMAIL'];
1.844 + }
1.845 + }
1.846 +
1.847 + if (!sizeof($error))
1.848 + {
1.849 + $sql = 'UPDATE ' . USERS_TABLE . '
1.850 + SET user_emailtime = ' . time() . '
1.851 + WHERE user_id = ' . $user->data['user_id'];
1.852 + $result = $db->sql_query($sql);
1.853 +
1.854 + include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
1.855 + $messenger = new messenger(false);
1.856 + $email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify';
1.857 +
1.858 + $mail_to_users = array();
1.859 +
1.860 + $mail_to_users[] = array(
1.861 + 'email_lang' => $email_lang,
1.862 + 'email' => $email,
1.863 + 'name' => $name,
1.864 + 'username' => ($user_id) ? $row['username'] : '',
1.865 + 'to_name' => $name,
1.866 + 'user_jabber' => ($user_id) ? $row['user_jabber'] : '',
1.867 + 'user_notify_type' => ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL,
1.868 + 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
1.869 + 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
1.870 + );
1.871 +
1.872 + // Ok, now the same email if CC specified, but without exposing the users email address
1.873 + if ($cc)
1.874 + {
1.875 + $mail_to_users[] = array(
1.876 + 'email_lang' => $user->data['user_lang'],
1.877 + 'email' => $user->data['user_email'],
1.878 + 'name' => $user->data['username'],
1.879 + 'username' => $user->data['username'],
1.880 + 'to_name' => $name,
1.881 + 'user_jabber' => $user->data['user_jabber'],
1.882 + 'user_notify_type' => ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL,
1.883 + 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
1.884 + 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
1.885 + );
1.886 + }
1.887 +
1.888 + foreach ($mail_to_users as $row)
1.889 + {
1.890 + $messenger->template($email_tpl, $row['email_lang']);
1.891 + $messenger->replyto($user->data['user_email']);
1.892 + $messenger->to($row['email'], $row['name']);
1.893 +
1.894 + if ($user_id)
1.895 + {
1.896 + $messenger->subject(htmlspecialchars_decode($subject));
1.897 + $messenger->im($row['user_jabber'], $row['username']);
1.898 + $notify_type = $row['user_notify_type'];
1.899 + }
1.900 + else
1.901 + {
1.902 + $notify_type = NOTIFY_EMAIL;
1.903 + }
1.904 +
1.905 + $messenger->anti_abuse_headers($config, $user);
1.906 +
1.907 + $messenger->assign_vars(array(
1.908 + 'BOARD_CONTACT' => $config['board_contact'],
1.909 + 'TO_USERNAME' => htmlspecialchars_decode($row['to_name']),
1.910 + 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
1.911 + 'MESSAGE' => htmlspecialchars_decode($message))
1.912 + );
1.913 +
1.914 + if ($topic_id)
1.915 + {
1.916 + $messenger->assign_vars(array(
1.917 + 'TOPIC_NAME' => htmlspecialchars_decode($row['topic_title']),
1.918 + 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id")
1.919 + );
1.920 + }
1.921 +
1.922 + $messenger->send($notify_type);
1.923 + }
1.924 +
1.925 + meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
1.926 + $message = ($user_id) ? sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>') : sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$row['forum_id']}&t=$topic_id") . '">', '</a>');
1.927 + trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message);
1.928 + }
1.929 + }
1.930 +
1.931 + if ($user_id)
1.932 + {
1.933 + $template->assign_vars(array(
1.934 + 'S_SEND_USER' => true,
1.935 + 'USERNAME' => $row['username'],
1.936 +
1.937 + 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_BODY_EXPLAIN'],
1.938 + 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id))
1.939 + );
1.940 + }
1.941 + else
1.942 + {
1.943 + $template->assign_vars(array(
1.944 + 'EMAIL' => $email,
1.945 + 'NAME' => $name,
1.946 + 'S_LANG_OPTIONS' => language_select($email_lang),
1.947 +
1.948 + 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_TOPIC_EXPLAIN'],
1.949 + 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&t=' . $topic_id))
1.950 + );
1.951 + }
1.952 +
1.953 + $template->assign_vars(array(
1.954 + 'ERROR_MESSAGE' => (sizeof($error)) ? implode('<br />', $error) : '',
1.955 + 'SUBJECT' => $subject,
1.956 + 'MESSAGE' => $message,
1.957 + )
1.958 + );
1.959 +
1.960 + break;
1.961 +
1.962 + case 'group':
1.963 + default:
1.964 + // The basic memberlist
1.965 + $page_title = $user->lang['MEMBERLIST'];
1.966 + $template_html = 'memberlist_body.html';
1.967 +
1.968 + // Sorting
1.969 + $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']);
1.970 + $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');
1.971 +
1.972 + if ($auth->acl_get('a_user'))
1.973 + {
1.974 + $sort_key_text['e'] = $user->lang['SORT_EMAIL'];
1.975 + $sort_key_sql['e'] = 'u.user_email';
1.976 + }
1.977 +
1.978 + if ($auth->acl_get('u_viewonline'))
1.979 + {
1.980 + $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
1.981 + $sort_key_sql['l'] = 'u.user_lastvisit';
1.982 + }
1.983 +
1.984 + $sort_key_text['m'] = $user->lang['SORT_RANK'];
1.985 + $sort_key_sql['m'] = 'u.user_rank';
1.986 +
1.987 + $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
1.988 +
1.989 + $s_sort_key = '';
1.990 + foreach ($sort_key_text as $key => $value)
1.991 + {
1.992 + $selected = ($sort_key == $key) ? ' selected="selected"' : '';
1.993 + $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1.994 + }
1.995 +
1.996 + $s_sort_dir = '';
1.997 + foreach ($sort_dir_text as $key => $value)
1.998 + {
1.999 + $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
1.1000 + $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1.1001 + }
1.1002 +
1.1003 + // Additional sorting options for user search ... if search is enabled, if not
1.1004 + // then only admins can make use of this (for ACP functionality)
1.1005 + $sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
1.1006 +
1.1007 +
1.1008 + $form = request_var('form', '');
1.1009 + $field = request_var('field', '');
1.1010 + $select_single = request_var('select_single', false);
1.1011 +
1.1012 + // Search URL parameters, if any of these are in the URL we do a search
1.1013 + $search_params = array('username', 'email', 'icq', 'aim', 'yahoo', 'msn', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
1.1014 +
1.1015 + // We validate form and field here, only id/class allowed
1.1016 + $form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
1.1017 + $field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
1.1018 + if (($mode == 'searchuser' || sizeof(array_intersect(array_keys($_GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
1.1019 + {
1.1020 + $username = request_var('username', '', true);
1.1021 + $email = strtolower(request_var('email', ''));
1.1022 + $icq = request_var('icq', '');
1.1023 + $aim = request_var('aim', '');
1.1024 + $yahoo = request_var('yahoo', '');
1.1025 + $msn = request_var('msn', '');
1.1026 + $jabber = request_var('jabber', '');
1.1027 + $search_group_id = request_var('search_group_id', 0);
1.1028 +
1.1029 + // when using these, make sure that we actually have values defined in $find_key_match
1.1030 + $joined_select = request_var('joined_select', 'lt');
1.1031 + $active_select = request_var('active_select', 'lt');
1.1032 + $count_select = request_var('count_select', 'eq');
1.1033 +
1.1034 + $joined = explode('-', request_var('joined', ''));
1.1035 + $active = explode('-', request_var('active', ''));
1.1036 + $count = (request_var('count', '') !== '') ? request_var('count', 0) : '';
1.1037 + $ipdomain = request_var('ip', '');
1.1038 +
1.1039 + $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
1.1040 +
1.1041 + $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
1.1042 + $s_find_count = '';
1.1043 + foreach ($find_count as $key => $value)
1.1044 + {
1.1045 + $selected = ($count_select == $key) ? ' selected="selected"' : '';
1.1046 + $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1.1047 + }
1.1048 +
1.1049 + $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
1.1050 + $s_find_join_time = '';
1.1051 + foreach ($find_time as $key => $value)
1.1052 + {
1.1053 + $selected = ($joined_select == $key) ? ' selected="selected"' : '';
1.1054 + $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1.1055 + }
1.1056 +
1.1057 + $s_find_active_time = '';
1.1058 + foreach ($find_time as $key => $value)
1.1059 + {
1.1060 + $selected = ($active_select == $key) ? ' selected="selected"' : '';
1.1061 + $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1.1062 + }
1.1063 +
1.1064 + $sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
1.1065 + $sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
1.1066 + $sql_where .= ($icq) ? ' AND u.user_icq ' . $db->sql_like_expression(str_replace('*', $db->any_char, $icq)) . ' ' : '';
1.1067 + $sql_where .= ($aim) ? ' AND u.user_aim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $aim)) . ' ' : '';
1.1068 + $sql_where .= ($yahoo) ? ' AND u.user_yim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $yahoo)) . ' ' : '';
1.1069 + $sql_where .= ($msn) ? ' AND u.user_msnm ' . $db->sql_like_expression(str_replace('*', $db->any_char, $msn)) . ' ' : '';
1.1070 + $sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->any_char, $jabber)) . ' ' : '';
1.1071 + $sql_where .= (is_numeric($count) && isset($find_key_match[$count_select])) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
1.1072 +
1.1073 + if (isset($find_key_match[$joined_select]) && sizeof($joined) == 3)
1.1074 + {
1.1075 + // Before PHP 5.1 an error value -1 can be returned instead of false.
1.1076 + // Theoretically gmmktime() can also legitimately return -1 as an actual timestamp.
1.1077 + // But since we do not pass the $second parameter to gmmktime(),
1.1078 + // an actual unix timestamp -1 cannot be returned in this case.
1.1079 + // Thus we can check whether it is -1 and treat -1 as an error.
1.1080 + $joined_time = gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]);
1.1081 +
1.1082 + if ($joined_time !== false && $joined_time !== -1)
1.1083 + {
1.1084 + $sql_where .= " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . $joined_time;
1.1085 + }
1.1086 + }
1.1087 +
1.1088 + if (isset($find_key_match[$active_select]) && sizeof($active) == 3 && $auth->acl_get('u_viewonline'))
1.1089 + {
1.1090 + $active_time = gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
1.1091 +
1.1092 + if ($active_time !== false && $active_time !== -1)
1.1093 + {
1.1094 + $sql_where .= " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . $active_time;
1.1095 + }
1.1096 + }
1.1097 +
1.1098 + $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
1.1099 +
1.1100 + if ($search_group_id)
1.1101 + {
1.1102 + $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
1.1103 + }
1.1104 +
1.1105 + if ($ipdomain && $auth->acl_getf_global('m_info'))
1.1106 + {
1.1107 + if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
1.1108 + {
1.1109 + $hostnames = gethostbynamel($ipdomain);
1.1110 +
1.1111 + if ($hostnames !== false)
1.1112 + {
1.1113 + $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)))) . "'";
1.1114 + }
1.1115 + else
1.1116 + {
1.1117 + $ips = false;
1.1118 + }
1.1119 + }
1.1120 + else
1.1121 + {
1.1122 + $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
1.1123 + }
1.1124 +
1.1125 + if ($ips === false)
1.1126 + {
1.1127 + // A minor fudge but it does the job :D
1.1128 + $sql_where .= " AND u.user_id = 0";
1.1129 + }
1.1130 + else
1.1131 + {
1.1132 + $ip_forums = array_keys($auth->acl_getf('m_info', true));
1.1133 +
1.1134 + $sql = 'SELECT DISTINCT poster_id
1.1135 + FROM ' . POSTS_TABLE . '
1.1136 + WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
1.1137 + AND forum_id IN (0, " . implode(', ', $ip_forums) . ')';
1.1138 + $result = $db->sql_query($sql);
1.1139 +
1.1140 + if ($row = $db->sql_fetchrow($result))
1.1141 + {
1.1142 + $ip_sql = array();
1.1143 + do
1.1144 + {
1.1145 + $ip_sql[] = $row['poster_id'];
1.1146 + }
1.1147 + while ($row = $db->sql_fetchrow($result));
1.1148 +
1.1149 + $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
1.1150 + }
1.1151 + else
1.1152 + {
1.1153 + // A minor fudge but it does the job :D
1.1154 + $sql_where .= " AND u.user_id = 0";
1.1155 + }
1.1156 + unset($ip_forums);
1.1157 +
1.1158 + $db->sql_freeresult($result);
1.1159 + }
1.1160 + }
1.1161 + }
1.1162 +
1.1163 + $first_char = request_var('first_char', '');
1.1164 +
1.1165 + if ($first_char == 'other')
1.1166 + {
1.1167 + for ($i = 97; $i < 123; $i++)
1.1168 + {
1.1169 + $sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->any_char);
1.1170 + }
1.1171 + }
1.1172 + else if ($first_char)
1.1173 + {
1.1174 + $sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->any_char);
1.1175 + }
1.1176 +
1.1177 + // Are we looking at a usergroup? If so, fetch additional info
1.1178 + // and further restrict the user info query
1.1179 + if ($mode == 'group')
1.1180 + {
1.1181 + // We JOIN here to save a query for determining membership for hidden groups. ;)
1.1182 + $sql = 'SELECT g.*, ug.user_id
1.1183 + FROM ' . GROUPS_TABLE . ' g
1.1184 + 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)
1.1185 + WHERE g.group_id = $group_id";
1.1186 + $result = $db->sql_query($sql);
1.1187 + $group_row = $db->sql_fetchrow($result);
1.1188 + $db->sql_freeresult($result);
1.1189 +
1.1190 + if (!$group_row)
1.1191 + {
1.1192 + trigger_error('NO_GROUP');
1.1193 + }
1.1194 +
1.1195 + switch ($group_row['group_type'])
1.1196 + {
1.1197 + case GROUP_OPEN:
1.1198 + $group_row['l_group_type'] = 'OPEN';
1.1199 + break;
1.1200 +
1.1201 + case GROUP_CLOSED:
1.1202 + $group_row['l_group_type'] = 'CLOSED';
1.1203 + break;
1.1204 +
1.1205 + case GROUP_HIDDEN:
1.1206 + $group_row['l_group_type'] = 'HIDDEN';
1.1207 +
1.1208 + // Check for membership or special permissions
1.1209 + if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
1.1210 + {
1.1211 + trigger_error('NO_GROUP');
1.1212 + }
1.1213 + break;
1.1214 +
1.1215 + case GROUP_SPECIAL:
1.1216 + $group_row['l_group_type'] = 'SPECIAL';
1.1217 + break;
1.1218 +
1.1219 + case GROUP_FREE:
1.1220 + $group_row['l_group_type'] = 'FREE';
1.1221 + break;
1.1222 + }
1.1223 +
1.1224 + // Misusing the avatar function for displaying group avatars...
1.1225 + $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');
1.1226 +
1.1227 + $rank_title = $rank_img = $rank_img_src = '';
1.1228 + if ($group_row['group_rank'])
1.1229 + {
1.1230 + if (isset($ranks['special'][$group_row['group_rank']]))
1.1231 + {
1.1232 + $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
1.1233 + }
1.1234 + $rank_img = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] . '" alt="' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '" title="' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '" /><br />' : '';
1.1235 + $rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : '';
1.1236 + }
1.1237 + else
1.1238 + {
1.1239 + $rank_title = '';
1.1240 + $rank_img = '';
1.1241 + $rank_img_src = '';
1.1242 + }
1.1243 +
1.1244 + $template->assign_vars(array(
1.1245 + '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']),
1.1246 + 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
1.1247 + 'GROUP_COLOR' => $group_row['group_colour'],
1.1248 + 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
1.1249 + 'GROUP_RANK' => $rank_title,
1.1250 +
1.1251 + 'AVATAR_IMG' => $avatar_img,
1.1252 + 'RANK_IMG' => $rank_img,
1.1253 + 'RANK_IMG_SRC' => $rank_img_src,
1.1254 +
1.1255 + '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) : '',)
1.1256 + );
1.1257 +
1.1258 + $sql_select = ', ug.group_leader';
1.1259 + $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
1.1260 + $order_by = 'ug.group_leader DESC, ';
1.1261 +
1.1262 + $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
1.1263 + $sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
1.1264 + }
1.1265 +
1.1266 + // Sorting and order
1.1267 + if (!isset($sort_key_sql[$sort_key]))
1.1268 + {
1.1269 + $sort_key = $default_key;
1.1270 + }
1.1271 +
1.1272 + $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
1.1273 +
1.1274 + // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
1.1275 + if ($sort_key == 'm')
1.1276 + {
1.1277 + $order_by .= ', u.user_posts DESC';
1.1278 + }
1.1279 +
1.1280 + // Count the users ...
1.1281 + if ($sql_where)
1.1282 + {
1.1283 + $sql = 'SELECT COUNT(u.user_id) AS total_users
1.1284 + FROM ' . USERS_TABLE . " u$sql_from
1.1285 + WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1.1286 + $sql_where";
1.1287 + $result = $db->sql_query($sql);
1.1288 + $total_users = (int) $db->sql_fetchfield('total_users');
1.1289 + $db->sql_freeresult($result);
1.1290 + }
1.1291 + else
1.1292 + {
1.1293 + $total_users = $config['num_users'];
1.1294 + }
1.1295 +
1.1296 + // Build a relevant pagination_url
1.1297 + $params = $sort_params = array();
1.1298 +
1.1299 + // We do not use request_var() here directly to save some calls (not all variables are set)
1.1300 + $check_params = array(
1.1301 + 'g' => array('g', 0),
1.1302 + 'sk' => array('sk', $default_key),
1.1303 + 'sd' => array('sd', 'a'),
1.1304 + 'form' => array('form', ''),
1.1305 + 'field' => array('field', ''),
1.1306 + 'select_single' => array('select_single', $select_single),
1.1307 + 'username' => array('username', '', true),
1.1308 + 'email' => array('email', ''),
1.1309 + 'icq' => array('icq', ''),
1.1310 + 'aim' => array('aim', ''),
1.1311 + 'yahoo' => array('yahoo', ''),
1.1312 + 'msn' => array('msn', ''),
1.1313 + 'jabber' => array('jabber', ''),
1.1314 + 'search_group_id' => array('search_group_id', 0),
1.1315 + 'joined_select' => array('joined_select', 'lt'),
1.1316 + 'active_select' => array('active_select', 'lt'),
1.1317 + 'count_select' => array('count_select', 'eq'),
1.1318 + 'joined' => array('joined', ''),
1.1319 + 'active' => array('active', ''),
1.1320 + 'count' => (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
1.1321 + 'ip' => array('ip', ''),
1.1322 + 'first_char' => array('first_char', ''),
1.1323 + );
1.1324 +
1.1325 + $u_first_char_params = array();
1.1326 + foreach ($check_params as $key => $call)
1.1327 + {
1.1328 + if (!isset($_REQUEST[$key]))
1.1329 + {
1.1330 + continue;
1.1331 + }
1.1332 +
1.1333 + $param = call_user_func_array('request_var', $call);
1.1334 + $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
1.1335 + $params[] = $param;
1.1336 +
1.1337 + if ($key != 'first_char')
1.1338 + {
1.1339 + $u_first_char_params[] = $param;
1.1340 + }
1.1341 + if ($key != 'sk' && $key != 'sd')
1.1342 + {
1.1343 + $sort_params[] = $param;
1.1344 + }
1.1345 + }
1.1346 +
1.1347 + $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&' . implode('&', $params) : ''));
1.1348 +
1.1349 + if ($mode)
1.1350 + {
1.1351 + $params[] = "mode=$mode";
1.1352 + }
1.1353 + $sort_params[] = "mode=$mode";
1.1354 +
1.1355 + $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&', $params));
1.1356 + $sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&', $sort_params));
1.1357 +
1.1358 + unset($search_params, $sort_params);
1.1359 +
1.1360 + $u_first_char_params = implode('&', $u_first_char_params);
1.1361 + $u_first_char_params .= ($u_first_char_params) ? '&' : '';
1.1362 +
1.1363 + $first_characters = array();
1.1364 + $first_characters[''] = $user->lang['ALL'];
1.1365 + for ($i = 97; $i < 123; $i++)
1.1366 + {
1.1367 + $first_characters[chr($i)] = chr($i - 32);
1.1368 + }
1.1369 + $first_characters['other'] = $user->lang['OTHER'];
1.1370 +
1.1371 + foreach ($first_characters as $char => $desc)
1.1372 + {
1.1373 + $template->assign_block_vars('first_char', array(
1.1374 + 'DESC' => $desc,
1.1375 + 'VALUE' => $char,
1.1376 + 'S_SELECTED' => ($first_char == $char) ? true : false,
1.1377 + 'U_SORT' => append_sid("{$phpbb_root_path}memberlist.$phpEx", $u_first_char_params . 'first_char=' . $char) . '#memberlist',
1.1378 + ));
1.1379 + }
1.1380 +
1.1381 + // Some search user specific data
1.1382 + if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
1.1383 + {
1.1384 + $group_selected = request_var('search_group_id', 0);
1.1385 + $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '> </option>';
1.1386 + $group_ids = array();
1.1387 +
1.1388 + /**
1.1389 + * @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)
1.1390 + */
1.1391 +
1.1392 + if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
1.1393 + {
1.1394 + $sql = 'SELECT group_id, group_name, group_type
1.1395 + FROM ' . GROUPS_TABLE;
1.1396 +
1.1397 + if (!$config['coppa_enable'])
1.1398 + {
1.1399 + $sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
1.1400 + }
1.1401 +
1.1402 + $sql .= ' ORDER BY group_name ASC';
1.1403 + }
1.1404 + else
1.1405 + {
1.1406 + $sql = 'SELECT g.group_id, g.group_name, g.group_type
1.1407 + FROM ' . GROUPS_TABLE . ' g
1.1408 + LEFT JOIN ' . USER_GROUP_TABLE . ' ug
1.1409 + ON (
1.1410 + g.group_id = ug.group_id
1.1411 + AND ug.user_id = ' . $user->data['user_id'] . '
1.1412 + AND ug.user_pending = 0
1.1413 + )
1.1414 + WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
1.1415 +
1.1416 + if (!$config['coppa_enable'])
1.1417 + {
1.1418 + $sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
1.1419 + }
1.1420 +
1.1421 + $sql .= ' ORDER BY g.group_name ASC';
1.1422 + }
1.1423 + $result = $db->sql_query($sql);
1.1424 +
1.1425 + while ($row = $db->sql_fetchrow($result))
1.1426 + {
1.1427 + $group_ids[] = $row['group_id'];
1.1428 + $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>';
1.1429 + }
1.1430 + $db->sql_freeresult($result);
1.1431 +
1.1432 + if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
1.1433 + {
1.1434 + trigger_error('NO_GROUP');
1.1435 + }
1.1436 +
1.1437 + $template->assign_vars(array(
1.1438 + 'USERNAME' => $username,
1.1439 + 'EMAIL' => $email,
1.1440 + 'ICQ' => $icq,
1.1441 + 'AIM' => $aim,
1.1442 + 'YAHOO' => $yahoo,
1.1443 + 'MSNM' => $msn,
1.1444 + 'JABBER' => $jabber,
1.1445 + 'JOINED' => implode('-', $joined),
1.1446 + 'ACTIVE' => implode('-', $active),
1.1447 + 'COUNT' => $count,
1.1448 + 'IP' => $ipdomain,
1.1449 +
1.1450 + 'S_IP_SEARCH_ALLOWED' => ($auth->acl_getf_global('m_info')) ? true : false,
1.1451 + 'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
1.1452 + 'S_IN_SEARCH_POPUP' => ($form && $field) ? true : false,
1.1453 + 'S_SEARCH_USER' => true,
1.1454 + 'S_FORM_NAME' => $form,
1.1455 + 'S_FIELD_NAME' => $field,
1.1456 + 'S_SELECT_SINGLE' => $select_single,
1.1457 + 'S_COUNT_OPTIONS' => $s_find_count,
1.1458 + 'S_SORT_OPTIONS' => $s_sort_key,
1.1459 + 'S_JOINED_TIME_OPTIONS' => $s_find_join_time,
1.1460 + 'S_ACTIVE_TIME_OPTIONS' => $s_find_active_time,
1.1461 + 'S_GROUP_SELECT' => $s_group_select,
1.1462 + 'S_USER_SEARCH_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&form=$form&field=$field"))
1.1463 + );
1.1464 + }
1.1465 +
1.1466 + // Get us some users :D
1.1467 + $sql = "SELECT u.user_id
1.1468 + FROM " . USERS_TABLE . " u
1.1469 + $sql_from
1.1470 + WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1.1471 + $sql_where
1.1472 + ORDER BY $order_by";
1.1473 + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1.1474 +
1.1475 + $user_list = array();
1.1476 + while ($row = $db->sql_fetchrow($result))
1.1477 + {
1.1478 + $user_list[] = (int) $row['user_id'];
1.1479 + }
1.1480 + $db->sql_freeresult($result);
1.1481 + $leaders_set = false;
1.1482 + // So, did we get any users?
1.1483 + if (sizeof($user_list))
1.1484 + {
1.1485 + // Session time?! Session time...
1.1486 + $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
1.1487 + FROM ' . SESSIONS_TABLE . '
1.1488 + WHERE session_time >= ' . (time() - $config['session_length']) . '
1.1489 + AND ' . $db->sql_in_set('session_user_id', $user_list) . '
1.1490 + GROUP BY session_user_id';
1.1491 + $result = $db->sql_query($sql);
1.1492 +
1.1493 + $session_times = array();
1.1494 + while ($row = $db->sql_fetchrow($result))
1.1495 + {
1.1496 + $session_times[$row['session_user_id']] = $row['session_time'];
1.1497 + }
1.1498 + $db->sql_freeresult($result);
1.1499 +
1.1500 + // Do the SQL thang
1.1501 + if ($mode == 'group')
1.1502 + {
1.1503 + $sql = "SELECT u.*
1.1504 + $sql_select
1.1505 + FROM " . USERS_TABLE . " u
1.1506 + $sql_from
1.1507 + WHERE " . $db->sql_in_set('u.user_id', $user_list) . "
1.1508 + $sql_where_data";
1.1509 + }
1.1510 + else
1.1511 + {
1.1512 + $sql = 'SELECT *
1.1513 + FROM ' . USERS_TABLE . '
1.1514 + WHERE ' . $db->sql_in_set('user_id', $user_list);
1.1515 + }
1.1516 + $result = $db->sql_query($sql);
1.1517 +
1.1518 + $id_cache = array();
1.1519 + while ($row = $db->sql_fetchrow($result))
1.1520 + {
1.1521 + $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : 0;
1.1522 + $row['last_visit'] = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
1.1523 +
1.1524 + $id_cache[$row['user_id']] = $row;
1.1525 + }
1.1526 + $db->sql_freeresult($result);
1.1527 +
1.1528 + // Load custom profile fields
1.1529 + if ($config['load_cpf_memberlist'])
1.1530 + {
1.1531 + include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1.1532 + $cp = new custom_profile();
1.1533 +
1.1534 + // Grab all profile fields from users in id cache for later use - similar to the poster cache
1.1535 + $profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
1.1536 + }
1.1537 +
1.1538 + // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...
1.1539 + if ($sort_key == 'l')
1.1540 + {
1.1541 +// 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));"));
1.1542 + usort($user_list, '_sort_last_active');
1.1543 + }
1.1544 +
1.1545 + for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i)
1.1546 + {
1.1547 + $user_id = $user_list[$i];
1.1548 + $row =& $id_cache[$user_id];
1.1549 + $is_leader = (isset($row['group_leader']) && $row['group_leader']) ? true : false;
1.1550 + $leaders_set = ($leaders_set || $is_leader);
1.1551 +
1.1552 + $cp_row = array();
1.1553 + if ($config['load_cpf_memberlist'])
1.1554 + {
1.1555 + $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
1.1556 + }
1.1557 +
1.1558 + $memberrow = array_merge(show_profile($row), array(
1.1559 + 'ROW_NUMBER' => $i + ($start + 1),
1.1560 +
1.1561 + 'S_CUSTOM_PROFILE' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1.1562 + 'S_GROUP_LEADER' => $is_leader,
1.1563 +
1.1564 + 'U_VIEW_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u=' . $user_id))
1.1565 + );
1.1566 +
1.1567 + if (isset($cp_row['row']) && sizeof($cp_row['row']))
1.1568 + {
1.1569 + $memberrow = array_merge($memberrow, $cp_row['row']);
1.1570 + }
1.1571 +
1.1572 + $template->assign_block_vars('memberrow', $memberrow);
1.1573 +
1.1574 + if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
1.1575 + {
1.1576 + foreach ($cp_row['blockrow'] as $field_data)
1.1577 + {
1.1578 + $template->assign_block_vars('memberrow.custom_fields', $field_data);
1.1579 + }
1.1580 + }
1.1581 +
1.1582 + unset($id_cache[$user_id]);
1.1583 + }
1.1584 + }
1.1585 +
1.1586 + // Generate page
1.1587 + $template->assign_vars(array(
1.1588 + 'PAGINATION' => generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
1.1589 + 'PAGE_NUMBER' => on_page($total_users, $config['topics_per_page'], $start),
1.1590 + 'TOTAL_USERS' => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
1.1591 +
1.1592 + 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['PROFILE']),
1.1593 + 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
1.1594 + 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
1.1595 + 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
1.1596 + 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
1.1597 + 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
1.1598 + 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
1.1599 + 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
1.1600 + 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
1.1601 + 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
1.1602 +
1.1603 + '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) : '')) : '',
1.1604 + 'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser') ? $u_hide_find_member : '',
1.1605 + 'U_SORT_USERNAME' => $sort_url . '&sk=a&sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
1.1606 + 'U_SORT_FROM' => $sort_url . '&sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1.1607 + 'U_SORT_JOINED' => $sort_url . '&sk=c&sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
1.1608 + 'U_SORT_POSTS' => $sort_url . '&sk=d&sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
1.1609 + 'U_SORT_EMAIL' => $sort_url . '&sk=e&sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
1.1610 + 'U_SORT_WEBSITE' => $sort_url . '&sk=f&sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
1.1611 + 'U_SORT_LOCATION' => $sort_url . '&sk=b&sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1.1612 + 'U_SORT_ICQ' => $sort_url . '&sk=g&sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
1.1613 + 'U_SORT_AIM' => $sort_url . '&sk=h&sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
1.1614 + 'U_SORT_MSN' => $sort_url . '&sk=i&sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
1.1615 + 'U_SORT_YIM' => $sort_url . '&sk=j&sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
1.1616 + 'U_SORT_ACTIVE' => ($auth->acl_get('u_viewonline')) ? $sort_url . '&sk=l&sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
1.1617 + 'U_SORT_RANK' => $sort_url . '&sk=m&sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
1.1618 + 'U_LIST_CHAR' => $sort_url . '&sk=a&sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
1.1619 +
1.1620 + 'S_SHOW_GROUP' => ($mode == 'group') ? true : false,
1.1621 + 'S_VIEWONLINE' => $auth->acl_get('u_viewonline'),
1.1622 + 'S_LEADERS_SET' => $leaders_set,
1.1623 + 'S_MODE_SELECT' => $s_sort_key,
1.1624 + 'S_ORDER_SELECT' => $s_sort_dir,
1.1625 + 'S_MODE_ACTION' => $pagination_url)
1.1626 + );
1.1627 +}
1.1628 +
1.1629 +// Output the page
1.1630 +page_header($page_title, false);
1.1631 +
1.1632 +$template->set_filenames(array(
1.1633 + 'body' => $template_html)
1.1634 +);
1.1635 +make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1.1636 +
1.1637 +page_footer();
1.1638 +
1.1639 +/**
1.1640 +* Prepare profile data
1.1641 +*/
1.1642 +function show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false)
1.1643 +{
1.1644 + global $config, $auth, $template, $user, $phpEx, $phpbb_root_path;
1.1645 +
1.1646 + $username = $data['username'];
1.1647 + $user_id = $data['user_id'];
1.1648 +
1.1649 + $rank_title = $rank_img = $rank_img_src = '';
1.1650 + get_user_rank($data['user_rank'], (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src);
1.1651 +
1.1652 + if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user'))
1.1653 + {
1.1654 + $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']);
1.1655 + }
1.1656 + else
1.1657 + {
1.1658 + $email = '';
1.1659 + }
1.1660 +
1.1661 + if ($config['load_onlinetrack'])
1.1662 + {
1.1663 + $update_time = $config['load_online_time'] * 60;
1.1664 + $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1.1665 + }
1.1666 + else
1.1667 + {
1.1668 + $online = false;
1.1669 + }
1.1670 +
1.1671 + if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))
1.1672 + {
1.1673 + $last_visit = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
1.1674 + }
1.1675 + else
1.1676 + {
1.1677 + $last_visit = '';
1.1678 + }
1.1679 +
1.1680 + $age = '';
1.1681 +
1.1682 + if ($config['allow_birthdays'] && $data['user_birthday'])
1.1683 + {
1.1684 + list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));
1.1685 +
1.1686 + if ($bday_year)
1.1687 + {
1.1688 + $now = phpbb_gmgetdate(time() + $user->timezone + $user->dst);
1.1689 +
1.1690 + $diff = $now['mon'] - $bday_month;
1.1691 + if ($diff == 0)
1.1692 + {
1.1693 + $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1.1694 + }
1.1695 + else
1.1696 + {
1.1697 + $diff = ($diff < 0) ? 1 : 0;
1.1698 + }
1.1699 +
1.1700 + $age = max(0, (int) ($now['year'] - $bday_year - $diff));
1.1701 + }
1.1702 + }
1.1703 +
1.1704 + // Dump it out to the template
1.1705 + return array(
1.1706 + 'AGE' => $age,
1.1707 + 'RANK_TITLE' => $rank_title,
1.1708 + 'JOINED' => $user->format_date($data['user_regdate']),
1.1709 + 'VISITED' => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
1.1710 + 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0,
1.1711 + 'WARNINGS' => isset($data['user_warnings']) ? $data['user_warnings'] : 0,
1.1712 +
1.1713 + 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $data['user_colour']),
1.1714 + 'USERNAME' => get_username_string('username', $user_id, $username, $data['user_colour']),
1.1715 + 'USER_COLOR' => get_username_string('colour', $user_id, $username, $data['user_colour']),
1.1716 + 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $username, $data['user_colour']),
1.1717 +
1.1718 + 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])),
1.1719 +
1.1720 + 'AVATAR_IMG' => get_user_avatar($data['user_avatar'], $data['user_avatar_type'], $data['user_avatar_width'], $data['user_avatar_height']),
1.1721 + 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
1.1722 + 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false,
1.1723 + 'RANK_IMG' => $rank_img,
1.1724 + 'RANK_IMG_SRC' => $rank_img_src,
1.1725 + 'ICQ_STATUS_IMG' => (!empty($data['user_icq'])) ? '<img src="http://web.icq.com/whitepages/online?icq=' . $data['user_icq'] . '&img=5" width="18" height="18" />' : '',
1.1726 + 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false,
1.1727 +
1.1728 + 'S_WARNINGS' => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false,
1.1729 +
1.1730 + 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&sr=posts") : '',
1.1731 + 'U_NOTES' => ($user_notes_enabled && $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $user_id, true, $user->session_id) : '',
1.1732 + 'U_WARN' => ($warn_user_enabled && $auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $user_id, true, $user->session_id) : '',
1.1733 + '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) : '',
1.1734 + 'U_EMAIL' => $email,
1.1735 + 'U_WWW' => (!empty($data['user_website'])) ? $data['user_website'] : '',
1.1736 + 'U_SHORT_WWW' => (!empty($data['user_website'])) ? ((strlen($data['user_website']) > 55) ? substr($data['user_website'], 0, 39) . ' ... ' . substr($data['user_website'], -10) : $data['user_website']) : '',
1.1737 + 'U_ICQ' => ($data['user_icq']) ? 'http://www.icq.com/people/' . urlencode($data['user_icq']) . '/' : '',
1.1738 + 'U_AIM' => ($data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $user_id) : '',
1.1739 + 'U_YIM' => ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($data['user_yim']) . '&.src=pg' : '',
1.1740 + 'U_MSN' => ($data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $user_id) : '',
1.1741 + 'U_JABBER' => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $user_id) : '',
1.1742 + 'LOCATION' => ($data['user_from']) ? $data['user_from'] : '',
1.1743 +
1.1744 + 'USER_ICQ' => $data['user_icq'],
1.1745 + 'USER_AIM' => $data['user_aim'],
1.1746 + 'USER_YIM' => $data['user_yim'],
1.1747 + 'USER_MSN' => $data['user_msnm'],
1.1748 + 'USER_JABBER' => $data['user_jabber'],
1.1749 + 'USER_JABBER_IMG' => ($data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '',
1.1750 +
1.1751 + 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username),
1.1752 + );
1.1753 +}
1.1754 +
1.1755 +function _sort_last_active($first, $second)
1.1756 +{
1.1757 + global $id_cache, $sort_dir;
1.1758 +
1.1759 + $lesser_than = ($sort_dir === 'd') ? -1 : 1;
1.1760 +
1.1761 + if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader']))
1.1762 + {
1.1763 + return -1;
1.1764 + }
1.1765 + else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader'])
1.1766 + {
1.1767 + return 1;
1.1768 + }
1.1769 + else
1.1770 + {
1.1771 + return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']);
1.1772 + }
1.1773 +}
1.1774 +
1.1775 +?>
1.1776 \ No newline at end of file