source: trunk/forum/memberlist.php @ 1596

Revision 1596, 61.0 KB checked in by Gongwei.Yu, 2 years ago (diff)
Line 
1<?php
2/**
3*
4* @package phpBB3
5* @version $Id: memberlist.php 9482 2009-04-24 17:27:10Z terrafrost $
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14define('IN_PHPBB', true);
15$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16$phpEx = substr(strrchr(__FILE__, '.'), 1);
17include($phpbb_root_path . 'common.' . $phpEx);
18include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
19
20// Start session management
21$user->session_begin();
22$auth->acl($user->data);
23$user->setup(array('memberlist', 'groups'));
24
25// www.phpBB-SEO.com SEO TOOLKIT BEGIN
26if (!empty($_REQUEST['un'])) {
27        $_REQUEST['un'] = rawurldecode($_REQUEST['un']);
28        if (!$phpbb_seo->is_utf8($_REQUEST['un'])) {
29                $_REQUEST['un'] = utf8_normalize_nfc(utf8_recode($_REQUEST['un'], 'ISO-8859-1'));
30        }
31}
32// www.phpBB-SEO.com SEO TOOLKIT END
33
34// Grab data
35$mode           = request_var('mode', '');
36$action         = request_var('action', '');
37$user_id        = request_var('u', ANONYMOUS);
38$username       = request_var('un', '', true);
39$group_id       = request_var('g', 0);
40$topic_id       = request_var('t', 0);
41
42// Check our mode...
43if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'searchuser', 'leaders')))
44{
45        trigger_error('NO_MODE');
46}
47
48switch ($mode)
49{
50        case 'email':
51        break;
52
53        default:
54                // Can this user view profiles/memberlist?
55                if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
56                {
57                        if ($user->data['user_id'] != ANONYMOUS)
58                        {
59                                trigger_error('NO_VIEW_USERS');
60                        }
61
62                        login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
63                }
64        break;
65}
66
67$start  = request_var('start', 0);
68$submit = (isset($_POST['submit'])) ? true : false;
69
70$default_key = 'c';
71$sort_key = request_var('sk', $default_key);
72$sort_dir = request_var('sd', 'a');
73
74
75// Grab rank information for later
76$ranks = $cache->obtain_ranks();
77
78
79// What do you want to do today? ... oops, I think that line is taken ...
80switch ($mode)
81{
82        case 'leaders':
83                // Display a listing of board admins, moderators
84                include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
85
86                $page_title = $user->lang['THE_TEAM'];
87                $template_html = 'memberlist_leaders.html';
88
89                $user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false);
90
91                $admin_id_ary = $global_mod_id_ary = $mod_id_ary = $forum_id_ary = array();
92                foreach ($user_ary as $forum_id => $forum_ary)
93                {
94                        foreach ($forum_ary as $auth_option => $id_ary)
95                        {
96                                if (!$forum_id)
97                                {
98                                        if ($auth_option == 'a_')
99                                        {
100                                                $admin_id_ary = array_merge($admin_id_ary, $id_ary);
101                                        }
102                                        else
103                                        {
104                                                $global_mod_id_ary = array_merge($global_mod_id_ary, $id_ary);
105                                        }
106                                        continue;
107                                }
108                                else
109                                {
110                                        $mod_id_ary = array_merge($mod_id_ary, $id_ary);
111                                }
112
113                                if ($forum_id)
114                                {
115                                        foreach ($id_ary as $id)
116                                        {
117                                                $forum_id_ary[$id][] = $forum_id;
118                                        }
119                                }
120                        }
121                }
122
123                $admin_id_ary = array_unique($admin_id_ary);
124                $global_mod_id_ary = array_unique($global_mod_id_ary);
125
126                $mod_id_ary = array_merge($mod_id_ary, $global_mod_id_ary);
127                $mod_id_ary = array_unique($mod_id_ary);
128
129                // Admin group id...
130                $sql = 'SELECT group_id
131                        FROM ' . GROUPS_TABLE . "
132                        WHERE group_name = 'ADMINISTRATORS'";
133                $result = $db->sql_query($sql);
134                $admin_group_id = (int) $db->sql_fetchfield('group_id');
135                $db->sql_freeresult($result);
136
137                // Get group memberships for the admin id ary...
138                $admin_memberships = group_memberships($admin_group_id, $admin_id_ary);
139
140                $admin_user_ids = array();
141
142                if (!empty($admin_memberships))
143                {
144                        // ok, we only need the user ids...
145                        foreach ($admin_memberships as $row)
146                        {
147                                $admin_user_ids[$row['user_id']] = true;
148                        }
149                }
150                unset($admin_memberships);
151
152                $sql = 'SELECT forum_id, forum_name
153                        FROM ' . FORUMS_TABLE;
154                $result = $db->sql_query($sql);
155
156                $forums = array();
157                while ($row = $db->sql_fetchrow($result))
158                {
159                        $forums[$row['forum_id']] = $row['forum_name'];
160                }
161                $db->sql_freeresult($result);
162
163                $sql = $db->sql_build_query('SELECT', array(
164                        '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',
165
166                        'FROM'          => array(
167                                USERS_TABLE             => 'u',
168                                GROUPS_TABLE    => 'g'
169                        ),
170
171                        'LEFT_JOIN'     => array(
172                                array(
173                                        'FROM'  => array(USER_GROUP_TABLE => 'ug'),
174                                        'ON'    => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id']
175                                )
176                        ),
177
178                        'WHERE'         => $db->sql_in_set('u.user_id', array_unique(array_merge($admin_id_ary, $mod_id_ary)), false, true) . '
179                                AND u.group_id = g.group_id',
180
181                        'ORDER_BY'      => 'g.group_name ASC, u.username_clean ASC'
182                ));
183                $result = $db->sql_query($sql);
184
185                while ($row = $db->sql_fetchrow($result))
186                {
187                        $which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod';
188
189                        // We sort out admins not within the 'Administrators' group.
190                        // Else, we will list those as admin only having the permission to view logs for example.
191                        if ($which_row == 'admin' && empty($admin_user_ids[$row['user_id']]))
192                        {
193                                // Remove from admin_id_ary, because the user may be a mod instead
194                                unset($admin_id_ary[array_search($row['user_id'], $admin_id_ary)]);
195
196                                if (!in_array($row['user_id'], $mod_id_ary) && !in_array($row['user_id'], $global_mod_id_ary))
197                                {
198                                        continue;
199                                }
200                                else
201                                {
202                                        $which_row = 'mod';
203                                }
204                        }
205
206                        $s_forum_select = '';
207                        $undisclosed_forum = false;
208
209                        if (isset($forum_id_ary[$row['user_id']]) && !in_array($row['user_id'], $global_mod_id_ary))
210                        {
211                                if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']])))
212                                {
213                                        foreach ($forum_id_ary[$row['user_id']] as $forum_id)
214                                        {
215                                                if (isset($forums[$forum_id]))
216                                                {
217                                                        if ($auth->acl_get('f_list', $forum_id))
218                                                        {
219                                                                $s_forum_select .= '<option value="">' . $forums[$forum_id] . '</option>';
220                                                        }
221                                                        else
222                                                        {
223                                                                $undisclosed_forum = true;
224                                                        }
225                                                }
226                                        }
227                                }
228                        }
229
230                        // If the mod is only moderating non-viewable forums we skip the user. There is no gain in displaying the person then...
231                        if (!$s_forum_select && $undisclosed_forum)
232                        {
233//                              $s_forum_select = '<option value="">' . $user->lang['FORUM_UNDISCLOSED'] . '</option>';
234                                continue;
235                        }
236
237                        // The person is moderating several "public" forums, therefore the person should be listed, but not giving the real group name if hidden.
238                        if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
239                        {
240                                $group_name = $user->lang['GROUP_UNDISCLOSED'];
241                                $u_group = '';
242                        }
243                        else
244                        {
245                                $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
246                                // www.phpBB-SEO.com SEO TOOLKIT BEGIN
247                                $phpbb_seo->prepare_url('group', $row['group_name'], $row['group_id']);
248                                // www.phpBB-SEO.com SEO TOOLKIT END
249                                $u_group = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']);
250                        }
251
252                        $rank_title = $rank_img = '';
253                        get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);
254
255                        $template->assign_block_vars($which_row, array(
256                                'USER_ID'               => $row['user_id'],
257                                'FORUMS'                => $s_forum_select,
258                                'RANK_TITLE'    => $rank_title,
259                                'GROUP_NAME'    => $group_name,
260                                'GROUP_COLOR'   => $row['group_colour'],
261
262                                'RANK_IMG'              => $rank_img,
263                                'RANK_IMG_SRC'  => $rank_img_src,
264
265                                'U_GROUP'                       => $u_group,
266                                '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&amp;mode=compose&amp;u=' . $row['user_id']) : '',
267
268                                'USERNAME_FULL'         => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
269                                'USERNAME'                      => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
270                                'USER_COLOR'            => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
271                                'U_VIEW_PROFILE'        => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
272                        ));
273                }
274                $db->sql_freeresult($result);
275
276                $template->assign_vars(array(
277                        'PM_IMG'                => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
278                );
279        break;
280
281        case 'contact':
282
283                $page_title = $user->lang['IM_USER'];
284                $template_html = 'memberlist_im.html';
285
286                if (!$auth->acl_get('u_sendim'))
287                {
288                        trigger_error('NOT_AUTHORISED');
289                }
290
291                $presence_img = '';
292                switch ($action)
293                {
294                        case 'aim':
295                                $lang = 'AIM';
296                                $sql_field = 'user_aim';
297                                $s_select = 'S_SEND_AIM';
298                                $s_action = '';
299                        break;
300
301                        case 'msnm':
302                                $lang = 'MSNM';
303                                $sql_field = 'user_msnm';
304                                $s_select = 'S_SEND_MSNM';
305                                $s_action = '';
306                        break;
307
308                        case 'jabber':
309                                $lang = 'JABBER';
310                                $sql_field = 'user_jabber';
311                                $s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
312                                $s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=$action&amp;u=$user_id");
313                        break;
314
315                        default:
316                                trigger_error('NO_MODE', E_USER_ERROR);
317                        break;
318                }
319
320                // Grab relevant data
321                $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
322                        FROM " . USERS_TABLE . "
323                        WHERE user_id = $user_id
324                                AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
325                $result = $db->sql_query($sql);
326                $row = $db->sql_fetchrow($result);
327                $db->sql_freeresult($result);
328
329                if (!$row)
330                {
331                        trigger_error('NO_USER');
332                }
333                else if (empty($row[$sql_field]))
334                {
335                        trigger_error('IM_NO_DATA');
336                }
337
338                // Post data grab actions
339                switch ($action)
340                {
341                        case 'jabber':
342                                add_form_key('memberlist_messaging');
343
344                                if ($submit && @extension_loaded('xml') && $config['jab_enable'])
345                                {
346                                        if (check_form_key('memberlist_messaging'))
347                                        {
348
349                                                include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
350
351                                                $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
352                                                $message = utf8_normalize_nfc(request_var('message', '', true));
353
354                                                if (empty($message))
355                                                {
356                                                        trigger_error('EMPTY_MESSAGE_IM');
357                                                }
358
359                                                $messenger = new messenger(false);
360
361                                                $messenger->template('profile_send_im', $row['user_lang']);
362                                                $messenger->subject(htmlspecialchars_decode($subject));
363
364                                                $messenger->replyto($user->data['user_email']);
365                                                $messenger->im($row['user_jabber'], $row['username']);
366
367                                                $messenger->assign_vars(array(
368                                                        'BOARD_CONTACT' => $config['board_contact'],
369                                                        'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
370                                                        'TO_USERNAME'   => htmlspecialchars_decode($row['username']),
371                                                        'MESSAGE'               => htmlspecialchars_decode($message))
372                                                );
373
374                                                $messenger->send(NOTIFY_IM);
375
376                                                $s_select = 'S_SENT_JABBER';
377                                        }
378                                        else
379                                        {
380                                                trigger_error('FORM_INVALID');
381                                        }
382                                }
383                        break;
384                }
385
386                // Send vars to the template
387                $template->assign_vars(array(
388                        'IM_CONTACT'    => $row[$sql_field],
389                        'A_IM_CONTACT'  => addslashes($row[$sql_field]),
390
391                        'U_AIM_CONTACT' => ($action == 'aim') ? 'aim:addbuddy?screenname=' . urlencode($row[$sql_field]) : '',
392                        'U_AIM_MESSAGE' => ($action == 'aim') ? 'aim:goim?screenname=' . urlencode($row[$sql_field]) . '&amp;message=' . urlencode($config['sitename']) : '',
393
394                        'USERNAME'              => $row['username'],
395                        'CONTACT_NAME'  => $row[$sql_field],
396                        'SITENAME'              => $config['sitename'],
397
398                        'PRESENCE_IMG'          => $presence_img,
399
400                        'L_SEND_IM_EXPLAIN'     => $user->lang['IM_' . $lang],
401                        'L_IM_SENT_JABBER'      => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
402
403                        $s_select                       => true,
404                        'S_IM_ACTION'           => $s_action)
405                );
406
407        break;
408
409        case 'viewprofile':
410                // Display a profile
411                if ($user_id == ANONYMOUS && !$username)
412                {
413                        trigger_error('NO_USER');
414                }
415
416                // Get user...
417                $sql = 'SELECT *
418                        FROM ' . USERS_TABLE . '
419                        WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
420                $result = $db->sql_query($sql);
421                $member = $db->sql_fetchrow($result);
422                $db->sql_freeresult($result);
423
424                if (!$member)
425                {
426                        trigger_error('NO_USER');
427                }
428
429                // a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
430                // Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
431                if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
432                {
433                        if ($member['user_type'] == USER_IGNORE)
434                        {
435                                trigger_error('NO_USER');
436                        }
437                        else if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE)
438                        {
439                                trigger_error('NO_USER');
440                        }
441                }
442
443                $user_id = (int) $member['user_id'];
444                // www.phpBB-SEO.com SEO TOOLKIT BEGIN
445                $phpbb_seo->set_user_url( $member['username'], $user_id );
446                // www.phpBB-SEO.com SEO TOOLKIT END
447
448                // Do the SQL thang
449                $sql = 'SELECT g.group_id, g.group_name, g.group_type
450                        FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
451                        WHERE ug.user_id = $user_id
452                                AND g.group_id = ug.group_id" . ((!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' AND g.group_type <> ' . GROUP_HIDDEN : '') . '
453                                AND ug.user_pending = 0
454                        ORDER BY g.group_type, g.group_name';
455                $result = $db->sql_query($sql);
456
457                $group_options = '';
458                while ($row = $db->sql_fetchrow($result))
459                {
460                        $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>';
461                }
462                $db->sql_freeresult($result);
463
464                // What colour is the zebra
465                $sql = 'SELECT friend, foe
466                        FROM ' . ZEBRA_TABLE . "
467                        WHERE zebra_id = $user_id
468                                AND user_id = {$user->data['user_id']}";
469
470                $result = $db->sql_query($sql);
471                $row = $db->sql_fetchrow($result);
472                $foe = ($row['foe']) ? true : false;
473                $friend = ($row['friend']) ? true : false;
474                $db->sql_freeresult($result);
475
476                if ($config['load_onlinetrack'])
477                {
478                        $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
479                                FROM ' . SESSIONS_TABLE . "
480                                WHERE session_user_id = $user_id";
481                        $result = $db->sql_query($sql);
482                        $row = $db->sql_fetchrow($result);
483                        $db->sql_freeresult($result);
484
485                        $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
486                        $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] :      0;
487                        unset($row);
488                }
489
490                if ($config['load_user_activity'])
491                {
492                        display_user_activity($member);
493                }
494
495                // Do the relevant calculations
496                $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
497                $posts_per_day = $member['user_posts'] / $memberdays;
498                $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
499
500
501                if ($member['user_sig'])
502                {
503                        $member['user_sig'] = censor_text($member['user_sig']);
504
505                        if ($member['user_sig_bbcode_bitfield'])
506                        {
507                                include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
508                                $bbcode = new bbcode();
509                                $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
510                        }
511
512                        $member['user_sig'] = bbcode_nl2br($member['user_sig']);
513                        $member['user_sig'] = smiley_text($member['user_sig']);
514                }
515
516                $poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']);
517
518                $template->assign_vars(show_profile($member));
519
520                // Custom Profile Fields
521                $profile_fields = array();
522                if ($config['load_cpf_viewprofile'])
523                {
524                        include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
525                        $cp = new custom_profile();
526                        $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
527                        $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
528                }
529
530                // We need to check if the module 'zebra' is accessible
531                $zebra_enabled = false;
532
533                if ($user->data['user_id'] != $user_id && $user->data['is_registered'])
534                {
535                        include_once($phpbb_root_path . 'includes/functions_module.' . $phpEx);
536                        $module = new p_master();
537                        $module->list_modules('ucp');
538                        $module->set_active('zebra');
539
540                        $zebra_enabled = ($module->active_module === false) ? false : true;
541
542                        unset($module);
543                }
544
545                // If the user has m_approve permission or a_user permission, then list then display unapproved posts
546                if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
547                {
548                        $sql = 'SELECT COUNT(post_id) as posts_in_queue
549                                FROM ' . POSTS_TABLE . '
550                                WHERE poster_id = ' . $user_id . '
551                                        AND post_approved = 0';
552                        $result = $db->sql_query($sql);
553                        $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
554                        $db->sql_freeresult($result);
555                }
556                else
557                {
558                        $member['posts_in_queue'] = 0;
559                }
560
561                $template->assign_vars(array(
562                        'L_POSTS_IN_QUEUE'      => $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
563
564                        'POSTS_DAY'                     => sprintf($user->lang['POST_DAY'], $posts_per_day),
565                        'POSTS_PCT'                     => sprintf($user->lang['POST_PCT'], $percentage),
566
567                        'OCCUPATION'    => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
568                        'INTERESTS'             => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
569                        'SIGNATURE'             => $member['user_sig'],
570                        'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
571
572                        'AVATAR_IMG'    => $poster_avatar,
573                        'PM_IMG'                => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
574                        'EMAIL_IMG'             => $user->img('icon_contact_email', $user->lang['EMAIL']),
575                        'WWW_IMG'               => $user->img('icon_contact_www', $user->lang['WWW']),
576                        'ICQ_IMG'               => $user->img('icon_contact_icq', $user->lang['ICQ']),
577                        'AIM_IMG'               => $user->img('icon_contact_aim', $user->lang['AIM']),
578                        'MSN_IMG'               => $user->img('icon_contact_msnm', $user->lang['MSNM']),
579                        'YIM_IMG'               => $user->img('icon_contact_yahoo', $user->lang['YIM']),
580                        'JABBER_IMG'    => $user->img('icon_contact_jabber', $user->lang['JABBER']),
581                        'SEARCH_IMG'    => $user->img('icon_user_search', $user->lang['SEARCH']),
582
583                        'S_PROFILE_ACTION'      => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
584                        'S_GROUP_OPTIONS'       => $group_options,
585                        'S_CUSTOM_FIELDS'       => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
586
587                        'U_USER_ADMIN'                  => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=users&amp;mode=overview&amp;u=' . $user_id, true, $user->session_id) : '',
588                        'U_USER_BAN'                    => ($auth->acl_get('m_ban') && $user_id != $user->data['user_id']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=ban&amp;mode=user&amp;u=' . $user_id, true, $user->session_id) : '',
589                        'U_MCP_QUEUE'                   => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
590
591                        'U_SWITCH_PERMISSIONS'  => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_id}") : '',
592
593                        'S_ZEBRA'                       => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
594                        'U_ADD_FRIEND'          => (!$friend) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
595                        'U_ADD_FOE'                     => (!$foe) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;mode=foes&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
596                        'U_REMOVE_FRIEND'       => ($friend) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
597                        'U_REMOVE_FOE'          => ($foe) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;mode=foes&amp;usernames[]=' . $user_id) : '',
598                ));
599
600                if (!empty($profile_fields['row']))
601                {
602                        $template->assign_vars($profile_fields['row']);
603                }
604
605                if (!empty($profile_fields['blockrow']))
606                {
607                        foreach ($profile_fields['blockrow'] as $field_data)
608                        {
609                                $template->assign_block_vars('custom_fields', $field_data);
610                        }
611                }
612
613                // Inactive reason/account?
614                if ($member['user_type'] == USER_INACTIVE)
615                {
616                        $user->add_lang('acp/common');
617
618                        $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
619
620                        switch ($member['user_inactive_reason'])
621                        {
622                                case INACTIVE_REGISTER:
623                                        $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
624                                break;
625
626                                case INACTIVE_PROFILE:
627                                        $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
628                                break;
629
630                                case INACTIVE_MANUAL:
631                                        $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
632                                break;
633
634                                case INACTIVE_REMIND:
635                                        $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
636                                break;
637                        }
638
639                        $template->assign_vars(array(
640                                'S_USER_INACTIVE'               => true,
641                                'USER_INACTIVE_REASON'  => $inactive_reason)
642                        );
643                }
644
645                // Now generate page title
646                $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
647                $template_html = 'memberlist_view.html';
648
649        break;
650
651        case 'email':
652
653                // Send an email
654                $page_title = $user->lang['SEND_EMAIL'];
655                $template_html = 'memberlist_email.html';
656
657                add_form_key('memberlist_email');
658
659                if (!$config['email_enable'])
660                {
661                        trigger_error('EMAIL_DISABLED');
662                }
663
664                if (!$auth->acl_get('u_sendemail'))
665                {
666                        trigger_error('NO_EMAIL');
667                }
668
669                // Are we trying to abuse the facility?
670                if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
671                {
672                        trigger_error('FLOOD_EMAIL_LIMIT');
673                }
674
675                // Determine action...
676                $user_id = request_var('u', 0);
677                $topic_id = request_var('t', 0);
678
679                // Send email to user...
680                if ($user_id)
681                {
682                        if ($user_id == ANONYMOUS || !$config['board_email_form'])
683                        {
684                                trigger_error('NO_EMAIL');
685                        }
686
687                        // Get the appropriate username, etc.
688                        $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
689                                FROM ' . USERS_TABLE . "
690                                WHERE user_id = $user_id
691                                        AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
692                        $result = $db->sql_query($sql);
693                        $row = $db->sql_fetchrow($result);
694                        $db->sql_freeresult($result);
695
696                        if (!$row)
697                        {
698                                trigger_error('NO_USER');
699                        }
700
701                        // Can we send email to this user?
702                        if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
703                        {
704                                trigger_error('NO_EMAIL');
705                        }
706                }
707                else if ($topic_id)
708                {
709                        // Send topic heads-up to email address
710                        $sql = 'SELECT forum_id, topic_title
711                                FROM ' . TOPICS_TABLE . "
712                                WHERE topic_id = $topic_id";
713                        $result = $db->sql_query($sql);
714                        $row = $db->sql_fetchrow($result);
715                        $db->sql_freeresult($result);
716
717                        if (!$row)
718                        {
719                                trigger_error('NO_TOPIC');
720                        }
721
722                        if ($row['forum_id'])
723                        {
724                                if (!$auth->acl_get('f_read', $row['forum_id']))
725                                {
726                                        trigger_error('SORRY_AUTH_READ');
727                                }
728
729                                if (!$auth->acl_get('f_email', $row['forum_id']))
730                                {
731                                        trigger_error('NO_EMAIL');
732                                }
733                        }
734                        else
735                        {
736                                // If global announcement, we need to check if the user is able to at least read and email in one forum...
737                                if (!$auth->acl_getf_global('f_read'))
738                                {
739                                        trigger_error('SORRY_AUTH_READ');
740                                }
741
742                                if (!$auth->acl_getf_global('f_email'))
743                                {
744                                        trigger_error('NO_EMAIL');
745                                }
746                        }
747                }
748                else
749                {
750                        trigger_error('NO_EMAIL');
751                }
752
753                $error = array();
754
755                $name           = utf8_normalize_nfc(request_var('name', '', true));
756                $email          = request_var('email', '');
757                $email_lang = request_var('lang', $config['default_lang']);
758                $subject        = utf8_normalize_nfc(request_var('subject', '', true));
759                $message        = utf8_normalize_nfc(request_var('message', '', true));
760                $cc                     = (isset($_POST['cc_email'])) ? true : false;
761                $submit         = (isset($_POST['submit'])) ? true : false;
762
763                if ($submit)
764                {
765                        if (!check_form_key('memberlist_email'))
766                        {
767                                $error[] = 'FORM_INVALID';
768                        }
769                        if ($user_id)
770                        {
771                                if (!$subject)
772                                {
773                                        $error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
774                                }
775
776                                if (!$message)
777                                {
778                                        $error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
779                                }
780
781                                $name = $row['username'];
782                                $email_lang = $row['user_lang'];
783                                $email = $row['user_email'];
784                        }
785                        else
786                        {
787                                if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email))
788                                {
789                                        $error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
790                                }
791
792                                if (!$name)
793                                {
794                                        $error[] = $user->lang['EMPTY_NAME_EMAIL'];
795                                }
796                        }
797
798                        if (!sizeof($error))
799                        {
800                                $sql = 'UPDATE ' . USERS_TABLE . '
801                                        SET user_emailtime = ' . time() . '
802                                        WHERE user_id = ' . $user->data['user_id'];
803                                $result = $db->sql_query($sql);
804
805                                include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
806                                $messenger = new messenger(false);
807                                $email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify';
808
809                                $mail_to_users = array();
810
811                                $mail_to_users[] = array(
812                                        'email_lang'            => $email_lang,
813                                        'email'                         => $email,
814                                        'name'                          => $name,
815                                        'username'                      => ($user_id) ? $row['username'] : '',
816                                        'to_name'                       => $name,
817                                        'user_jabber'           => ($user_id) ? $row['user_jabber'] : '',
818                                        'user_notify_type'      => ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL,
819                                        'topic_title'           => (!$user_id) ? $row['topic_title'] : '',
820                                        'forum_id'                      => (!$user_id) ? $row['forum_id'] : 0,
821                                );
822
823                                // Ok, now the same email if CC specified, but without exposing the users email address
824                                if ($cc)
825                                {
826                                        $mail_to_users[] = array(
827                                                'email_lang'            => $user->data['user_lang'],
828                                                'email'                         => $user->data['user_email'],
829                                                'name'                          => $user->data['username'],
830                                                'username'                      => $user->data['username'],
831                                                'to_name'                       => $name,
832                                                'user_jabber'           => $user->data['user_jabber'],
833                                                'user_notify_type'      => ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL,
834                                                'topic_title'           => (!$user_id) ? $row['topic_title'] : '',
835                                                'forum_id'                      => (!$user_id) ? $row['forum_id'] : 0,
836                                        );
837                                }
838
839                                foreach ($mail_to_users as $row)
840                                {
841                                        $messenger->template($email_tpl, $row['email_lang']);
842                                        $messenger->replyto($user->data['user_email']);
843                                        $messenger->to($row['email'], $row['name']);
844
845                                        if ($user_id)
846                                        {
847                                                $messenger->subject(htmlspecialchars_decode($subject));
848                                                $messenger->im($row['user_jabber'], $row['username']);
849                                                $notify_type = $row['user_notify_type'];
850                                        }
851                                        else
852                                        {
853                                                $notify_type = NOTIFY_EMAIL;
854                                        }
855
856                                        $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
857                                        $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
858                                        $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
859                                        $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
860
861                                        $messenger->assign_vars(array(
862                                                'BOARD_CONTACT' => $config['board_contact'],
863                                                'TO_USERNAME'   => htmlspecialchars_decode($row['to_name']),
864                                                'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
865                                                'MESSAGE'               => htmlspecialchars_decode($message))
866                                        );
867
868                                        if ($topic_id)
869                                        {
870                                                $messenger->assign_vars(array(
871                                                        'TOPIC_NAME'    => htmlspecialchars_decode($row['topic_title']),
872                                                        'U_TOPIC'               => generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id")
873                                                );
874                                        }
875
876                                        $messenger->send($notify_type);
877                                }
878
879                                meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
880                                $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']}&amp;t=$topic_id") . '">', '</a>');
881                                trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message);
882                        }
883                }
884
885                if ($user_id)
886                {
887                        $template->assign_vars(array(
888                                'S_SEND_USER'   => true,
889                                'USERNAME'              => $row['username'],
890
891                                'L_EMAIL_BODY_EXPLAIN'  => $user->lang['EMAIL_BODY_EXPLAIN'],
892                                'S_POST_ACTION'                 => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id))
893                        );
894                }
895                else
896                {
897                        $template->assign_vars(array(
898                                'EMAIL'                         => $email,
899                                'NAME'                          => $name,
900                                'S_LANG_OPTIONS'        => language_select($email_lang),
901
902                                'L_EMAIL_BODY_EXPLAIN'  => $user->lang['EMAIL_TOPIC_EXPLAIN'],
903                                'S_POST_ACTION'                 => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;t=' . $topic_id))
904                        );
905                }
906
907                $template->assign_vars(array(
908                        'ERROR_MESSAGE'         => (sizeof($error)) ? implode('<br />', $error) : '',
909                        'SUBJECT'                       => $subject,
910                        'MESSAGE'                       => $message,
911                        )
912                );
913
914        break;
915
916        case 'group':
917        default:
918                // The basic memberlist
919                $page_title = $user->lang['MEMBERLIST'];
920                $template_html = 'memberlist_body.html';
921
922                // Sorting
923                $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']);
924                $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');
925
926                if ($auth->acl_get('a_user'))
927                {
928                        $sort_key_text['e'] = $user->lang['SORT_EMAIL'];
929                        $sort_key_sql['e'] = 'u.user_email';
930                }
931
932                if ($auth->acl_get('u_viewonline'))
933                {
934                        $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
935                        $sort_key_sql['l'] = 'u.user_lastvisit';
936                }
937
938                $sort_key_text['m'] = $user->lang['SORT_RANK'];
939                $sort_key_sql['m'] = 'u.user_rank';
940
941                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
942
943                $s_sort_key = '';
944                foreach ($sort_key_text as $key => $value)
945                {
946                        $selected = ($sort_key == $key) ? ' selected="selected"' : '';
947                        $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
948                }
949
950                $s_sort_dir = '';
951                foreach ($sort_dir_text as $key => $value)
952                {
953                        $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
954                        $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
955                }
956
957                // Additional sorting options for user search ... if search is enabled, if not
958                // then only admins can make use of this (for ACP functionality)
959                $sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
960
961
962                $form                   = request_var('form', '');
963                $field                  = request_var('field', '');
964                $select_single  = request_var('select_single', false);
965
966                // Search URL parameters, if any of these are in the URL we do a search
967                $search_params = array('username', 'email', 'icq', 'aim', 'yahoo', 'msn', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
968
969                // We validate form and field here, only id/class allowed
970                $form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
971                $field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
972                if (($mode == 'searchuser' || sizeof(array_intersect(array_keys($_GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
973                {
974                        $username       = request_var('username', '', true);
975                        $email          = strtolower(request_var('email', ''));
976                        $icq            = request_var('icq', '');
977                        $aim            = request_var('aim', '');
978                        $yahoo          = request_var('yahoo', '');
979                        $msn            = request_var('msn', '');
980                        $jabber         = request_var('jabber', '');
981                        $search_group_id        = request_var('search_group_id', 0);
982
983                        $joined_select  = request_var('joined_select', 'lt');
984                        $active_select  = request_var('active_select', 'lt');
985                        $count_select   = request_var('count_select', 'eq');
986                        $joined                 = explode('-', request_var('joined', ''));
987                        $active                 = explode('-', request_var('active', ''));
988                        $count                  = (request_var('count', '') !== '') ? request_var('count', 0) : '';
989                        $ipdomain               = request_var('ip', '');
990
991                        $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
992
993                        $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
994                        $s_find_count = '';
995                        foreach ($find_count as $key => $value)
996                        {
997                                $selected = ($count_select == $key) ? ' selected="selected"' : '';
998                                $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
999                        }
1000
1001                        $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
1002                        $s_find_join_time = '';
1003                        foreach ($find_time as $key => $value)
1004                        {
1005                                $selected = ($joined_select == $key) ? ' selected="selected"' : '';
1006                                $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1007                        }
1008
1009                        $s_find_active_time = '';
1010                        foreach ($find_time as $key => $value)
1011                        {
1012                                $selected = ($active_select == $key) ? ' selected="selected"' : '';
1013                                $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
1014                        }
1015
1016                        $sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
1017                        $sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
1018                        $sql_where .= ($icq) ? ' AND u.user_icq ' . $db->sql_like_expression(str_replace('*', $db->any_char, $icq)) . ' ' : '';
1019                        $sql_where .= ($aim) ? ' AND u.user_aim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $aim)) . ' ' : '';
1020                        $sql_where .= ($yahoo) ? ' AND u.user_yim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $yahoo)) . ' ' : '';
1021                        $sql_where .= ($msn) ? ' AND u.user_msnm ' . $db->sql_like_expression(str_replace('*', $db->any_char, $msn)) . ' ' : '';
1022                        $sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->any_char, $jabber)) . ' ' : '';
1023                        $sql_where .= (is_numeric($count)) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
1024                        $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])) : '';
1025                        $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])) : '';
1026                        $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
1027
1028                        if ($search_group_id)
1029                        {
1030                                $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
1031                        }
1032
1033                        if ($ipdomain && $auth->acl_getf_global('m_info'))
1034                        {
1035                                if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
1036                                {
1037                                        $hostnames = gethostbynamel($ipdomain);
1038
1039                                        if ($hostnames !== false)
1040                                        {
1041                                                $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)))) . "'";
1042                                        }
1043                                        else
1044                                        {
1045                                                $ips = false;
1046                                        }
1047                                }
1048                                else
1049                                {
1050                                        $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
1051                                }
1052
1053                                if ($ips === false)
1054                                {
1055                                        // A minor fudge but it does the job :D
1056                                        $sql_where .= " AND u.user_id = 0";
1057                                }
1058                                else
1059                                {
1060                                        $ip_forums = array_keys($auth->acl_getf('m_info', true));
1061
1062                                        $sql = 'SELECT DISTINCT poster_id
1063                                                FROM ' . POSTS_TABLE . '
1064                                                WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
1065                                                        AND forum_id IN (0, " . implode(', ', $ip_forums) . ')';
1066                                        $result = $db->sql_query($sql);
1067
1068                                        if ($row = $db->sql_fetchrow($result))
1069                                        {
1070                                                $ip_sql = array();
1071                                                do
1072                                                {
1073                                                        $ip_sql[] = $row['poster_id'];
1074                                                }
1075                                                while ($row = $db->sql_fetchrow($result));
1076
1077                                                $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
1078                                        }
1079                                        else
1080                                        {
1081                                                // A minor fudge but it does the job :D
1082                                                $sql_where .= " AND u.user_id = 0";
1083                                        }
1084                                        unset($ip_forums);
1085
1086                                        $db->sql_freeresult($result);
1087                                }
1088                        }
1089                }
1090
1091                $first_char = request_var('first_char', '');
1092
1093                if ($first_char == 'other')
1094                {
1095                        for ($i = 97; $i < 123; $i++)
1096                        {
1097                                $sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->any_char);
1098                        }
1099                }
1100                else if ($first_char)
1101                {
1102                        $sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->any_char);
1103                }
1104
1105                // Are we looking at a usergroup? If so, fetch additional info
1106                // and further restrict the user info query
1107                if ($mode == 'group')
1108                {
1109                        // We JOIN here to save a query for determining membership for hidden groups. ;)
1110                        $sql = 'SELECT g.*, ug.user_id
1111                                FROM ' . GROUPS_TABLE . ' g
1112                                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)
1113                                WHERE g.group_id = $group_id";
1114                        $result = $db->sql_query($sql);
1115                        $group_row = $db->sql_fetchrow($result);
1116                        $db->sql_freeresult($result);
1117
1118                        if (!$group_row)
1119                        {
1120                                trigger_error('NO_GROUP');
1121                        }
1122
1123                        switch ($group_row['group_type'])
1124                        {
1125                                case GROUP_OPEN:
1126                                        $group_row['l_group_type'] = 'OPEN';
1127                                break;
1128
1129                                case GROUP_CLOSED:
1130                                        $group_row['l_group_type'] = 'CLOSED';
1131                                break;
1132
1133                                case GROUP_HIDDEN:
1134                                        $group_row['l_group_type'] = 'HIDDEN';
1135
1136                                        // Check for membership or special permissions
1137                                        if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
1138                                        {
1139                                                trigger_error('NO_GROUP');
1140                                        }
1141                                break;
1142
1143                                case GROUP_SPECIAL:
1144                                        $group_row['l_group_type'] = 'SPECIAL';
1145                                break;
1146
1147                                case GROUP_FREE:
1148                                        $group_row['l_group_type'] = 'FREE';
1149                                break;
1150                        }
1151
1152                        // Misusing the avatar function for displaying group avatars...
1153                        $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');
1154
1155                        $rank_title = $rank_img = $rank_img_src = '';
1156                        if ($group_row['group_rank'])
1157                        {
1158                                if (isset($ranks['special'][$group_row['group_rank']]))
1159                                {
1160                                        $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
1161                                }
1162                                $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 />' : '';
1163                                $rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : '';
1164                        }
1165                        else
1166                        {
1167                                $rank_title = '';
1168                                $rank_img = '';
1169                                $rank_img_src = '';
1170                        }
1171
1172                        $template->assign_vars(array(
1173                                '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']),
1174                                'GROUP_NAME'    => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
1175                                'GROUP_COLOR'   => $group_row['group_colour'],
1176                                'GROUP_TYPE'    => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
1177                                'GROUP_RANK'    => $rank_title,
1178
1179                                'AVATAR_IMG'    => $avatar_img,
1180                                'RANK_IMG'              => $rank_img,
1181                                'RANK_IMG_SRC'  => $rank_img_src,
1182
1183                                '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&amp;mode=compose&amp;g=' . $group_id) : '',)
1184                        );
1185
1186                        $sql_select = ', ug.group_leader';
1187                        $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
1188                        $order_by = 'ug.group_leader DESC, ';
1189
1190                        $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
1191                        $sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
1192                }
1193
1194                // Sorting and order
1195                if (!isset($sort_key_sql[$sort_key]))
1196                {
1197                        $sort_key = $default_key;
1198                }
1199
1200                $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
1201
1202                // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
1203                if ($sort_key == 'm')
1204                {
1205                        $order_by .= ', u.user_posts DESC';
1206                }
1207
1208                // Count the users ...
1209                if ($sql_where)
1210                {
1211                        $sql = 'SELECT COUNT(u.user_id) AS total_users
1212                                FROM ' . USERS_TABLE . " u$sql_from
1213                                WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1214                                $sql_where";
1215                        $result = $db->sql_query($sql);
1216                        $total_users = (int) $db->sql_fetchfield('total_users');
1217                        $db->sql_freeresult($result);
1218                }
1219                else
1220                {
1221                        $total_users = $config['num_users'];
1222                }
1223
1224                $s_char_options = '<option value=""' . ((!$first_char) ? ' selected="selected"' : '') . '>&nbsp; &nbsp;</option>';
1225                for ($i = 97; $i < 123; $i++)
1226                {
1227                        $s_char_options .= '<option value="' . chr($i) . '"' . (($first_char == chr($i)) ? ' selected="selected"' : '') . '>' . chr($i-32) . '</option>';
1228                }
1229                $s_char_options .= '<option value="other"' . (($first_char == 'other') ? ' selected="selected"' : '') . '>' . $user->lang['OTHER'] . '</option>';
1230
1231                // Build a relevant pagination_url
1232                $params = $sort_params = array();
1233
1234                // We do not use request_var() here directly to save some calls (not all variables are set)
1235                $check_params = array(
1236                        'g'                             => array('g', 0),
1237                        'sk'                    => array('sk', $default_key),
1238                        'sd'                    => array('sd', 'a'),
1239                        'form'                  => array('form', ''),
1240                        'field'                 => array('field', ''),
1241                        'select_single' => array('select_single', $select_single),
1242                        'username'              => array('username', '', true),
1243                        'email'                 => array('email', ''),
1244                        'icq'                   => array('icq', ''),
1245                        'aim'                   => array('aim', ''),
1246                        'yahoo'                 => array('yahoo', ''),
1247                        'msn'                   => array('msn', ''),
1248                        'jabber'                => array('jabber', ''),
1249                        'search_group_id'       => array('search_group_id', 0),
1250                        'joined_select' => array('joined_select', 'lt'),
1251                        'active_select' => array('active_select', 'lt'),
1252                        'count_select'  => array('count_select', 'eq'),
1253                        'joined'                => array('joined', ''),
1254                        'active'                => array('active', ''),
1255                        'count'                 => (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
1256                        'ipdomain'              => array('ip', ''),
1257                        'first_char'    => array('first_char', ''),
1258                );
1259
1260                foreach ($check_params as $key => $call)
1261                {
1262                        if (!isset($_REQUEST[$key]))
1263                        {
1264                                continue;
1265                        }
1266
1267                        $param = call_user_func_array('request_var', $call);
1268                        $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
1269                        $params[] = $param;
1270
1271                        if ($key != 'sk' && $key != 'sd')
1272                        {
1273                                $sort_params[] = $param;
1274                        }
1275                }
1276
1277                $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&amp;' . implode('&amp;', $params) : ''));
1278
1279                if ($mode)
1280                {
1281                        $params[] = "mode=$mode";
1282                }
1283                $sort_params[] = "mode=$mode";
1284
1285                $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
1286                $sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $sort_params));
1287
1288                unset($search_params, $sort_params);
1289
1290                // Some search user specific data
1291                if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
1292                {
1293                        $group_selected = request_var('search_group_id', 0);
1294                        $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
1295                        $group_ids = array();
1296
1297                        /**
1298                        * @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)
1299                        */
1300
1301                        if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
1302                        {
1303                                $sql = 'SELECT group_id, group_name, group_type
1304                                        FROM ' . GROUPS_TABLE;
1305
1306                                if (!$config['coppa_enable'])
1307                                {
1308                                        $sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
1309                                }
1310
1311                                $sql .= ' ORDER BY group_name ASC';
1312                        }
1313                        else
1314                        {
1315                                $sql = 'SELECT g.group_id, g.group_name, g.group_type
1316                                        FROM ' . GROUPS_TABLE . ' g
1317                                        LEFT JOIN ' . USER_GROUP_TABLE . ' ug
1318                                                ON (
1319                                                        g.group_id = ug.group_id
1320                                                        AND ug.user_id = ' . $user->data['user_id'] . '
1321                                                        AND ug.user_pending = 0
1322                                                )
1323                                        WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
1324
1325                                if (!$config['coppa_enable'])
1326                                {
1327                                        $sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
1328                                }
1329
1330                                $sql .= ' ORDER BY g.group_name ASC';
1331                        }
1332                        $result = $db->sql_query($sql);
1333
1334                        while ($row = $db->sql_fetchrow($result))
1335                        {
1336                                $group_ids[] = $row['group_id'];
1337                                $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>';
1338                        }
1339                        $db->sql_freeresult($result);
1340
1341                        if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
1342                        {
1343                                trigger_error('NO_GROUP');
1344                        }
1345
1346                        $template->assign_vars(array(
1347                                'USERNAME'      => $username,
1348                                'EMAIL'         => $email,
1349                                'ICQ'           => $icq,
1350                                'AIM'           => $aim,
1351                                'YAHOO'         => $yahoo,
1352                                'MSNM'          => $msn,
1353                                'JABBER'        => $jabber,
1354                                'JOINED'        => implode('-', $joined),
1355                                'ACTIVE'        => implode('-', $active),
1356                                'COUNT'         => $count,
1357                                'IP'            => $ipdomain,
1358
1359                                'S_IP_SEARCH_ALLOWED'   => ($auth->acl_getf_global('m_info')) ? true : false,
1360                                'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
1361                                'S_IN_SEARCH_POPUP'             => ($form && $field) ? true : false,
1362                                'S_SEARCH_USER'                 => true,
1363                                'S_FORM_NAME'                   => $form,
1364                                'S_FIELD_NAME'                  => $field,
1365                                'S_SELECT_SINGLE'               => $select_single,
1366                                'S_COUNT_OPTIONS'               => $s_find_count,
1367                                'S_SORT_OPTIONS'                => $s_sort_key,
1368                                'S_JOINED_TIME_OPTIONS' => $s_find_join_time,
1369                                'S_ACTIVE_TIME_OPTIONS' => $s_find_active_time,
1370                                'S_GROUP_SELECT'                => $s_group_select,
1371                                'S_USER_SEARCH_ACTION'  => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=$form&amp;field=$field"))
1372                        );
1373                }
1374
1375                // Get us some users :D
1376                $sql = "SELECT u.user_id
1377                        FROM " . USERS_TABLE . " u
1378                                $sql_from
1379                        WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1380                                $sql_where
1381                        ORDER BY $order_by";
1382                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1383
1384                $user_list = array();
1385                while ($row = $db->sql_fetchrow($result))
1386                {
1387                        $user_list[] = (int) $row['user_id'];
1388                }
1389                $db->sql_freeresult($result);
1390                $leaders_set = false;
1391                // So, did we get any users?
1392                if (sizeof($user_list))
1393                {
1394                        // Session time?! Session time...
1395                        $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
1396                                FROM ' . SESSIONS_TABLE . '
1397                                WHERE session_time >= ' . (time() - $config['session_length']) . '
1398                                        AND ' . $db->sql_in_set('session_user_id', $user_list) . '
1399                                GROUP BY session_user_id';
1400                        $result = $db->sql_query($sql);
1401
1402                        $session_times = array();
1403                        while ($row = $db->sql_fetchrow($result))
1404                        {
1405                                $session_times[$row['session_user_id']] = $row['session_time'];
1406                        }
1407                        $db->sql_freeresult($result);
1408
1409                        // Do the SQL thang
1410                        if ($mode == 'group')
1411                        {
1412                                $sql = "SELECT u.*
1413                                                $sql_select
1414                                        FROM " . USERS_TABLE . " u
1415                                                $sql_from
1416                                        WHERE " . $db->sql_in_set('u.user_id', $user_list) . "
1417                                                $sql_where_data";
1418                        }
1419                        else
1420                        {
1421                                $sql = 'SELECT *
1422                                        FROM ' . USERS_TABLE . '
1423                                        WHERE ' . $db->sql_in_set('user_id', $user_list);
1424                        }
1425                        $result = $db->sql_query($sql);
1426
1427                        $id_cache = array();
1428                        while ($row = $db->sql_fetchrow($result))
1429                        {
1430                                $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : 0;
1431                                $row['last_visit'] = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
1432
1433                                $id_cache[$row['user_id']] = $row;
1434                        }
1435                        $db->sql_freeresult($result);
1436
1437                        // Load custom profile fields
1438                        if ($config['load_cpf_memberlist'])
1439                        {
1440                                include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1441                                $cp = new custom_profile();
1442
1443                                // Grab all profile fields from users in id cache for later use - similar to the poster cache
1444                                $profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
1445                        }
1446
1447                        // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...
1448                        if ($sort_key == 'l')
1449                        {
1450//                              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));"));
1451                                usort($user_list,  '_sort_last_active');
1452                        }
1453
1454                        for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i)
1455                        {
1456                                $user_id = $user_list[$i];
1457                                $row =& $id_cache[$user_id];
1458                                $is_leader = (isset($row['group_leader']) && $row['group_leader']) ? true : false;
1459                                $leaders_set = ($leaders_set || $is_leader);
1460
1461                                $cp_row = array();
1462                                if ($config['load_cpf_memberlist'])
1463                                {
1464                                        $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
1465                                }
1466
1467                                $memberrow = array_merge(show_profile($row), array(
1468                                        'ROW_NUMBER'            => $i + ($start + 1),
1469
1470                                        'S_CUSTOM_PROFILE'      => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1471                                        'S_GROUP_LEADER'        => $is_leader,
1472
1473                                        'U_VIEW_PROFILE'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id))
1474                                );
1475
1476                                if (isset($cp_row['row']) && sizeof($cp_row['row']))
1477                                {
1478                                        $memberrow = array_merge($memberrow, $cp_row['row']);
1479                                }
1480
1481                                $template->assign_block_vars('memberrow', $memberrow);
1482
1483                                if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
1484                                {
1485                                        foreach ($cp_row['blockrow'] as $field_data)
1486                                        {
1487                                                $template->assign_block_vars('memberrow.custom_fields', $field_data);
1488                                        }
1489                                }
1490
1491                                unset($id_cache[$user_id]);
1492                        }
1493                }
1494               
1495                // www.phpBB-SEO.com SEO TOOLKIT BEGIN
1496                $seo_sep = strpos($sort_url, '?') === false ? '?' : '&amp;';
1497                // www.phpBB-SEO.com SEO TOOLKIT END
1498
1499                // Generate page
1500                $template->assign_vars(array(
1501                        'PAGINATION'    => generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
1502                        'PAGE_NUMBER'   => on_page($total_users, $config['topics_per_page'], $start),
1503                        'TOTAL_USERS'   => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
1504
1505                        'PROFILE_IMG'   => $user->img('icon_user_profile', $user->lang['PROFILE']),
1506                        'PM_IMG'                => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
1507                        'EMAIL_IMG'             => $user->img('icon_contact_email', $user->lang['EMAIL']),
1508                        'WWW_IMG'               => $user->img('icon_contact_www', $user->lang['WWW']),
1509                        'ICQ_IMG'               => $user->img('icon_contact_icq', $user->lang['ICQ']),
1510                        'AIM_IMG'               => $user->img('icon_contact_aim', $user->lang['AIM']),
1511                        'MSN_IMG'               => $user->img('icon_contact_msnm', $user->lang['MSNM']),
1512                        'YIM_IMG'               => $user->img('icon_contact_yahoo', $user->lang['YIM']),
1513                        'JABBER_IMG'    => $user->img('icon_contact_jabber', $user->lang['JABBER']),
1514                        'SEARCH_IMG'    => $user->img('icon_user_search', $user->lang['SEARCH']),
1515
1516                        'U_FIND_MEMBER'                 => ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser' . (($start) ? "&amp;start=$start" : '') . (!empty($params) ? '&amp;' . implode('&amp;', $params) : '')) : '',
1517                        'U_HIDE_FIND_MEMBER'    => ($mode == 'searchuser') ? $u_hide_find_member : '',
1518                        //'U_SORT_USERNAME'             => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
1519                        //'U_SORT_FROM'                 => $sort_url . '&amp;sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1520                        //'U_SORT_JOINED'                       => $sort_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
1521                        //'U_SORT_POSTS'                        => $sort_url . '&amp;sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
1522                        //'U_SORT_EMAIL'                        => $sort_url . '&amp;sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
1523                        //'U_SORT_WEBSITE'              => $sort_url . '&amp;sk=f&amp;sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
1524                        //'U_SORT_LOCATION'             => $sort_url . '&amp;sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1525                        //'U_SORT_ICQ'                  => $sort_url . '&amp;sk=g&amp;sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
1526                        //'U_SORT_AIM'                  => $sort_url . '&amp;sk=h&amp;sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
1527                        //'U_SORT_MSN'                  => $sort_url . '&amp;sk=i&amp;sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
1528                        //'U_SORT_YIM'                  => $sort_url . '&amp;sk=j&amp;sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
1529                        //'U_SORT_ACTIVE'                       => ($auth->acl_get('u_viewonline')) ? $sort_url . '&amp;sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
1530                        //'U_SORT_RANK'                 => $sort_url . '&amp;sk=m&amp;sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
1531                        //'U_LIST_CHAR'                 => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
1532                        // www.phpBB-SEO.com SEO TOOLKIT BEGIN
1533                        'U_SORT_USERNAME'               => $sort_url . $seo_sep . 'sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
1534                        'U_SORT_FROM'                   => $sort_url . $seo_sep . 'sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1535                        'U_SORT_JOINED'                 => $sort_url . $seo_sep . 'sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
1536                        'U_SORT_POSTS'                  => $sort_url . $seo_sep . 'sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
1537                        'U_SORT_EMAIL'                  => $sort_url . $seo_sep . 'sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
1538                        'U_SORT_WEBSITE'                => $sort_url . $seo_sep . 'sk=f&amp;sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
1539                        'U_SORT_LOCATION'               => $sort_url . $seo_sep . 'sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1540                        'U_SORT_ICQ'                    => $sort_url . $seo_sep . 'sk=g&amp;sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
1541                        'U_SORT_AIM'                    => $sort_url . $seo_sep . 'sk=h&amp;sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
1542                        'U_SORT_MSN'                    => $sort_url . $seo_sep . 'sk=i&amp;sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
1543                        'U_SORT_YIM'                    => $sort_url . $seo_sep . 'sk=j&amp;sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
1544                        'U_SORT_ACTIVE'                 => ($auth->acl_get('u_viewonline')) ? $sort_url . $seo_sep . 'sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
1545                        'U_SORT_RANK'                   => $sort_url . $seo_sep . 'sk=m&amp;sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
1546                        'U_LIST_CHAR'                   => $sort_url . $seo_sep . 'sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
1547                        // www.phpBB-SEO.com SEO TOOLKIT END
1548
1549                        'S_SHOW_GROUP'          => ($mode == 'group') ? true : false,
1550                        'S_VIEWONLINE'          => $auth->acl_get('u_viewonline'),
1551                        'S_LEADERS_SET'         => $leaders_set,
1552                        'S_MODE_SELECT'         => $s_sort_key,
1553                        'S_ORDER_SELECT'        => $s_sort_dir,
1554                        'S_CHAR_OPTIONS'        => $s_char_options,
1555                        //'S_MODE_ACTION'               => $pagination_url)
1556                        // www.phpBB-SEO.com SEO TOOLKIT BEGIN
1557                        // Here we circumvent because our append_sid does not allow
1558                        // an url to end with an ?, as it should.
1559                        'S_MODE_ACTION'         => $pagination_url . (strpos($pagination_url, '?') !== false ? '' : '?') )
1560                        // www.phpBB-SEO.com SEO TOOLKIT END
1561                );
1562}
1563
1564// Output the page
1565page_header($page_title);
1566
1567$template->set_filenames(array(
1568        'body' => $template_html)
1569);
1570make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1571
1572page_footer();
1573
1574/**
1575* Prepare profile data
1576*/
1577function show_profile($data)
1578{
1579        global $config, $auth, $template, $user, $phpEx, $phpbb_root_path;
1580
1581        $username = $data['username'];
1582        $user_id = $data['user_id'];
1583
1584        $rank_title = $rank_img = $rank_img_src = '';
1585        get_user_rank($data['user_rank'], (($user_id == ANONYMOUS) ? false : $data['user_posts']), $rank_title, $rank_img, $rank_img_src);
1586
1587        if (!empty($data['user_allow_viewemail']) || $auth->acl_get('a_user'))
1588        {
1589                $email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']);
1590        }
1591        else
1592        {
1593                $email = '';
1594        }
1595
1596        if ($config['load_onlinetrack'])
1597        {
1598                $update_time = $config['load_online_time'] * 60;
1599                $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1600        }
1601        else
1602        {
1603                $online = false;
1604        }
1605
1606        if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))
1607        {
1608                $last_visit = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
1609        }
1610        else
1611        {
1612                $last_visit = '';
1613        }
1614
1615        $age = '';
1616
1617        if ($config['allow_birthdays'] && $data['user_birthday'])
1618        {
1619                list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));
1620
1621                if ($bday_year)
1622                {
1623                        $now = getdate(time() + $user->timezone + $user->dst - date('Z'));
1624
1625                        $diff = $now['mon'] - $bday_month;
1626                        if ($diff == 0)
1627                        {
1628                                $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1629                        }
1630                        else
1631                        {
1632                                $diff = ($diff < 0) ? 1 : 0;
1633                        }
1634
1635                        $age = (int) ($now['year'] - $bday_year - $diff);
1636                }
1637        }
1638
1639        // Dump it out to the template
1640        return array(
1641                'AGE'                   => $age,
1642                'RANK_TITLE'    => $rank_title,
1643                'JOINED'                => $user->format_date($data['user_regdate']),
1644                'VISITED'               => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
1645                'POSTS'                 => ($data['user_posts']) ? $data['user_posts'] : 0,
1646                'WARNINGS'              => isset($data['user_warnings']) ? $data['user_warnings'] : 0,
1647
1648                'USERNAME_FULL'         => get_username_string('full', $user_id, $username, $data['user_colour']),
1649                'USERNAME'                      => get_username_string('username', $user_id, $username, $data['user_colour']),
1650                'USER_COLOR'            => get_username_string('colour', $user_id, $username, $data['user_colour']),
1651                'U_VIEW_PROFILE'        => get_username_string('profile', $user_id, $username, $data['user_colour']),
1652
1653                'A_USERNAME'            => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])),
1654
1655                'AVATAR_IMG'            => get_user_avatar($data['user_avatar'], $data['user_avatar_type'], $data['user_avatar_width'], $data['user_avatar_height']),
1656                'ONLINE_IMG'            => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
1657                'S_ONLINE'                      => ($config['load_onlinetrack'] && $online) ? true : false,
1658                'RANK_IMG'                      => $rank_img,
1659                'RANK_IMG_SRC'          => $rank_img_src,
1660                'ICQ_STATUS_IMG'        => (!empty($data['user_icq'])) ? '<img src="http://web.icq.com/whitepages/online?icq=' . $data['user_icq'] . '&amp;img=5" width="18" height="18" />' : '',
1661                'S_JABBER_ENABLED'      => ($config['jab_enable']) ? true : false,
1662
1663                'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&amp;sr=posts") : '',
1664                'U_NOTES'               => $auth->acl_getf_global('m_') ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $user_id, true, $user->session_id) : '',
1665                'U_WARN'                => $auth->acl_get('m_warn') ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $user_id, true, $user->session_id) : '',
1666                '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&amp;mode=compose&amp;u=' . $user_id) : '',
1667                'U_EMAIL'               => $email,
1668                'U_WWW'                 => (!empty($data['user_website'])) ? $data['user_website'] : '',
1669                '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']) : '',
1670                'U_ICQ'                 => ($data['user_icq']) ? 'http://www.icq.com/people/webmsg.php?to=' . urlencode($data['user_icq']) : '',
1671                'U_AIM'                 => ($data['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=aim&amp;u=' . $user_id) : '',
1672                'U_YIM'                 => ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($data['user_yim']) . '&amp;.src=pg' : '',
1673                'U_MSN'                 => ($data['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=msnm&amp;u=' . $user_id) : '',
1674                'U_JABBER'              => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $user_id) : '',
1675                'LOCATION'              => ($data['user_from']) ? $data['user_from'] : '',
1676
1677                'USER_ICQ'                      => $data['user_icq'],
1678                'USER_AIM'                      => $data['user_aim'],
1679                'USER_YIM'                      => $data['user_yim'],
1680                'USER_MSN'                      => $data['user_msnm'],
1681                'USER_JABBER'           => $data['user_jabber'],
1682                'USER_JABBER_IMG'       => ($data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '',
1683
1684                'L_VIEWING_PROFILE'     => sprintf($user->lang['VIEWING_PROFILE'], $username),
1685        );
1686}
1687
1688function _sort_last_active($first, $second)
1689{
1690        global $id_cache, $sort_dir;
1691
1692        $lesser_than = ($sort_dir === 'd') ? -1 : 1;
1693
1694        if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader']))
1695        {
1696                return -1;
1697        }
1698        else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader'])
1699        {
1700                return 1;
1701        }
1702        else
1703        {
1704                return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']);
1705        }
1706}
1707
1708?>
Note: See TracBrowser for help on using the repository browser.