phpBB
Statistics
| Revision:

root / trunk / phpBB / memberlist.php

History | View | Annotate | Download (61.1 kB)

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