phpBB
Statistics
| Revision:

root / tags / milestone_3 / phpBB / memberlist.php

History | View | Annotate | Download (43.9 kB)

1
<?php
2
/** 
3
*
4
* @package phpBB3
5
* @version $Id: memberlist.php 5247 2005-10-02 18:47:06Z acydburn $
6
* @copyright (c) 2005 phpBB Group 
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
8
*
9
*/
10
11
/**
12
*/
13
define('IN_PHPBB', true);
14
$phpbb_root_path = './';
15
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16
include($phpbb_root_path . 'common.'.$phpEx);
17
18
// Start session management
19
$user->session_begin();
20
$auth->acl($user->data);
21
$user->setup(array('memberlist', 'groups'));
22
23
// Grab data
24
$mode                = request_var('mode', '');
25
$action                = request_var('action', '');
26
$user_id        = request_var('u', ANONYMOUS);
27
$group_id        = request_var('g', 0);
28
$topic_id        = request_var('t', 0);
29
30
switch ($mode)
31
{
32
        case 'email':
33
                break;
34
35
        default:
36
                // Can this user view profiles/memberlist?
37
                if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
38
                {
39
                        if ($user->data['user_id'] != ANONYMOUS)
40
                        {
41
                                trigger_error('NO_VIEW_USERS');
42
                        }
43
44
                        login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
45
                }
46
                break;
47
}
48
49
50
$start        = request_var('start', 0);
51
$submit = (isset($_POST['submit'])) ? true : false;
52
53
$sort_key = request_var('sk', 'c');
54
$sort_dir = request_var('sd', 'a');
55
56
57
// Grab rank information for later
58
$ranks = array();
59
$cache->obtain_ranks($ranks);
60
61
62
// What do you want to do today? ... oops, I think that line is taken ...
63
switch ($mode)
64
{
65
        case 'leaders':
66
                // Display a listing of board admins, moderators
67
68
                $user->add_lang('groups');
69
                
70
                $page_title = $user->lang['THE_TEAM'];
71
                $template_html = 'memberlist_leaders.html';
72
73
                $user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false);
74
75
                $admin_id_ary = $mod_id_ary = $forum_id_ary = array();
76
                foreach ($user_ary as $forum_id => $forum_ary)
77
                {
78
                        foreach ($forum_ary as $auth_option => $id_ary)
79
                        {
80
                                (!$forum_id && $auth_option == 'a_') ? $admin_id_ary += $id_ary : $mod_id_ary += $id_ary;
81
82
                                if ($forum_id)
83
                                {
84
                                        foreach ($id_ary as $id)
85
                                        {
86
                                                $forum_id_ary[$id][] = $forum_id;
87
                                        }
88
                                }
89
                        }
90
                }
91
92
                $sql = 'SELECT forum_id, forum_name 
93
                        FROM ' . FORUMS_TABLE . '
94
                        WHERE forum_type = ' . FORUM_POST;
95
                $result = $db->sql_query($sql);
96
                
97
                $forums = array();
98
                while ($row = $db->sql_fetchrow($result))
99
                {
100
                        $forums[$row['forum_id']] = $row['forum_name'];
101
                }
102
                $db->sql_freeresult($result);
103
104
                $sql = 'SELECT u.user_id, u.username, u.user_colour, u.user_rank, u.user_posts, g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id
105
                        FROM ' . USERS_TABLE . ' u, ' . GROUPS_TABLE . ' g
106
                        LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.group_id = g.group_id AND ug.user_id = ' . $user->data['user_id'] . ')
107
                        WHERE u.user_id IN (' . implode(', ', $admin_id_ary + $mod_id_ary) . ')
108
                                AND u.group_id = g.group_id
109
                        ORDER BY g.group_name ASC, u.username ASC';
110
                $result = $db->sql_query($sql);
111
112
                while ($row = $db->sql_fetchrow($result))
113
                {
114
                        $which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod';
115
116
                        $s_forum_select = '';
117
                        if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']])))
118
                        {
119
                                foreach ($forum_id_ary[$row['user_id']] as $forum_id)
120
                                {
121
                                        if (isset($forums[$forum_id]) && $auth->acl_get('f_list', $forum_id))
122
                                        {
123
                                                $s_forum_select .= '<option value="">' . $forums[$forum_id] . '</option>';
124
                                        }
125
                                }
126
                        }
127
                        
128
                        if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
129
                        {
130
                                $group_name = $user->lang['UNDISCLOSED'];
131
                                $u_group = '';
132
                        }
133
                        else
134
                        {
135
                                $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
136
                                $u_group = "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=group&amp;g={$row['group_id']}";
137
                        }
138
139
                        $rank_title = $rank_img = '';
140
                        get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img);
141
142
                        $template->assign_block_vars($which_row, array(
143
                                'USER_ID'                => $row['user_id'],
144
                                'FORUMS'                => $s_forum_select,
145
                                'USERNAME'                => $row['username'],
146
                                'USER_COLOR'        => $row['user_colour'],
147
                                'RANK_TITLE'        => $rank_title,
148
                                'GROUP_NAME'        => $group_name,
149
                                'GROUP_COLOR'        => $row['group_colour'],
150
151
                                'RANK_IMG'                => $rank_img,
152
153
                                'U_GROUP'                => $u_group,
154
                                'U_VIEWPROFILE'        => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u={$row['user_id']}",
155
                                'U_PM'                        => ($auth->acl_get('u_sendpm')) ? "{$phpbb_root_path}ucp.$phpEx$SID&amp;i=pm&amp;mode=compose&amp;u={$row['user_id']}" : '')
156
                        );
157
                }
158
                $db->sql_freeresult($result);
159
160
                $template->assign_vars(array(
161
                        'PM_IMG'                => $user->img('btn_pm', $user->lang['MESSAGE']))
162
                );
163
                break;
164
165
        case 'contact':
166
                $page_title = $user->lang['IM_USER'];
167
                $template_html = 'memberlist_im.html';
168
169
                $presence_img = '';
170
                switch ($action)
171
                {
172
                        case 'icq':
173
                                $lang = 'ICQ';
174
                                $sql_field = 'user_icq';
175
                                $s_select = 'S_SEND_ICQ';
176
                                $s_action = 'http://wwp.icq.com/scripts/WWPMsg.dll';
177
                                break;
178
179
                        case 'aim':
180
                                $lang = 'AIM';
181
                                $sql_field = 'user_aim';
182
                                $s_select = 'S_SEND_AIM';
183
                                $s_action = '';
184
                                break;
185
186
                        case 'msnm':
187
                                $lang = 'MSNM';
188
                                $sql_field = 'user_msnm';
189
                                $s_select = 'S_SEND_MSNM';
190
                                $s_action = '';
191
                                break;
192
193
                        case 'jabber':
194
                                $lang = 'JABBER';
195
                                $sql_field = 'user_jabber';
196
                                $s_select = (@extension_loaded('xml')) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
197
                                $s_action = "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=contact&amp;action=$action&amp;u=$user_id";
198
                                break;
199
200
                        default:
201
                                $sql_field = '';
202
                                break;
203
                }
204
205
                // Grab relevant data
206
                $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
207
                        FROM " . USERS_TABLE . "
208
                        WHERE user_id = $user_id
209
                                AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
210
                $result = $db->sql_query($sql);
211
212
                if (!($row = $db->sql_fetchrow($result)))
213
                {
214
                        trigger_error('NO_USER_DATA');
215
                }
216
                $db->sql_freeresult($result);
217
218
                // Post data grab actions
219
                switch ($action)
220
                {
221
                        case 'icq':
222
                                $presence_img = '<img src="http://web.icq.com/whitepages/online?icq=' . $row[$sql_field] . '&amp;img=5" width="18" height="18" alt="" />';
223
                                break;
224
225
                        case 'jabber':
226
                                if ($submit && @extension_loaded('xml'))
227
                                {
228
                                        include_once($phpbb_root_path . 'includes/functions_messenger.'.$phpEx);
229
230
                                        $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
231
                                        $message = $_POST['message'];
232
233
                                        $messenger = new messenger();
234
235
                                        $messenger->template('profile_send_email', $row['user_lang']);
236
                                        $messenger->subject($subject);
237
238
                                        $messenger->replyto($user->data['user_email']);
239
                                        $messenger->im($row['user_jabber'], $row['username']);
240
241
                                        $messenger->assign_vars(array(
242
                                                'SITENAME'                => $config['sitename'],
243
                                                'BOARD_EMAIL'        => $config['board_contact'],
244
                                                'FROM_USERNAME' => $user->data['username'],
245
                                                'TO_USERNAME'        => $row['username'],
246
                                                'MESSAGE'                => $message)
247
                                        );
248
249
                                        $messenger->send(NOTIFY_IM);
250
                                        $messenger->save_queue();
251
252
                                        $s_select = 'S_SENT_JABBER';
253
                                }
254
                                break;
255
                }
256
257
                // Send vars to the template
258
                $template->assign_vars(array(
259
                        'IM_CONTACT'        => $row[$sql_field],
260
                        'USERNAME'                => addslashes($row['username']),
261
                        'EMAIL'                        => $row['user_email'],
262
                        'CONTACT_NAME'        => $row[$sql_field],
263
                        'SITENAME'                => addslashes($config['sitename']),
264
265
                        'PRESENCE_IMG'                => $presence_img,
266
267
                        'L_SEND_IM_EXPLAIN'        => $user->lang['IM_' . $lang],
268
                        'L_IM_SENT_JABBER'        => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
269
270
                        $s_select                        => true,
271
                        'S_IM_ACTION'                => $s_action)
272
                );
273
274
                break;
275
276
        case 'viewprofile':
277
                // Display a profile
278
                if ($user_id == ANONYMOUS)
279
                {
280
                        trigger_error('NO_USER');
281
                }
282
283
                // Do the SQL thang
284
                $sql = 'SELECT g.group_id, g.group_name, g.group_type
285
                        FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
286
                        WHERE ug.user_id = $user_id
287
                                AND g.group_id = ug.group_id" . ((!$auth->acl_gets('a_group')) ? ' AND group_type <> ' . GROUP_HIDDEN : '') . '
288
                        ORDER BY group_type, group_name';
289
                $result = $db->sql_query($sql);
290
291
                $group_options = '';
292
                while ($row = $db->sql_fetchrow($result))
293
                {
294
                        $group_options .= '<option value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
295
                }
296
297
                // We left join on the session table to see if the user is currently online
298
                $sql = 'SELECT username, user_id, user_type, user_colour, user_permissions, user_sig, user_sig_bbcode_uid, user_sig_bbcode_bitfield, user_allow_viewemail, user_posts, user_regdate, user_rank, user_from, user_occ, user_interests, user_website, user_email, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_avatar, user_avatar_width, user_avatar_height, user_avatar_type, user_lastvisit
299
                        FROM ' . USERS_TABLE . "
300
                        WHERE user_id = $user_id
301
                                AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
302
                $result = $db->sql_query($sql);
303
304
                if (!($member = $db->sql_fetchrow($result)))
305
                {
306
                        trigger_error('NO_USER');
307
                }
308
                $db->sql_freeresult($result);
309
310
                $sql = 'SELECT MAX(session_time) AS session_time
311
                        FROM ' . SESSIONS_TABLE . "
312
                        WHERE session_user_id = $user_id";
313
                $result = $db->sql_query($sql);
314
315
                $row = $db->sql_fetchrow($result);
316
                $db->sql_freeresult($result);
317
318
                $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
319
                unset($row);
320
321
                // Obtain list of forums where this users post count is incremented
322
                $auth2 = new auth();
323
                $auth2->acl($member);
324
                $f_postcount_ary = $auth2->acl_getf('f_postcount');
325
326
                $sql_forums = array();
327
                foreach ($f_postcount_ary as $forum_id => $allow)
328
                {
329
                        if ($allow['f_postcount'])
330
                        {
331
                                $sql_forums[] = $forum_id;
332
                        }
333
                }
334
335
                $post_count_sql = (sizeof($sql_forums)) ? 'AND f.forum_id IN (' . implode(', ', $sql_forums) . ')' : '';
336
                unset($sql_forums, $f_postcount_ary, $auth2);
337
338
                // Grab all the relevant data
339
                $sql = 'SELECT COUNT(p.post_id) AS num_posts
340
                        FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f
341
                        WHERE p.poster_id = $user_id
342
                                AND f.forum_id = p.forum_id
343
                                $post_count_sql";
344
                $result = $db->sql_query($sql);
345
346
                $num_real_posts = min($user->data['user_posts'], $db->sql_fetchfield('num_posts', 0, $result));
347
                $db->sql_freeresult($result);
348
349
                // Change post_count_sql to an forum_id array the user is able to see
350
                $f_forum_ary = $auth->acl_getf('f_read');
351
352
                $sql_forums = array();
353
                foreach ($f_forum_ary as $forum_id => $allow)
354
                {
355
                        if (isset($allow['f_read']) && $allow['f_read'])
356
                        {
357
                                $sql_forums[] = $forum_id;
358
                        }
359
                }
360
361
                $post_count_sql = (sizeof($sql_forums)) ? 'AND f.forum_id IN (' . implode(', ', $sql_forums) . ')' : '';
362
                unset($sql_forums, $f_forum_ary);
363
364
                if ($post_count_sql)
365
                {
366
                        $sql = 'SELECT f.forum_id, f.forum_name, COUNT(post_id) AS num_posts
367
                                FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f
368
                                WHERE p.poster_id = $user_id
369
                                        AND f.forum_id = p.forum_id
370
                                        $post_count_sql
371
                                GROUP BY f.forum_id, f.forum_name
372
                                ORDER BY num_posts DESC";
373
                        $result = $db->sql_query_limit($sql, 1);
374
375
                        $active_f_row = $db->sql_fetchrow($result);
376
                        $db->sql_freeresult($result);
377
378
                        $sql = 'SELECT t.topic_id, t.topic_title, COUNT(p.post_id) AS num_posts
379
                                FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
380
                                WHERE p.poster_id = $user_id
381
                                        AND t.topic_id = p.topic_id
382
                                        AND f.forum_id = t.forum_id
383
                                        $post_count_sql
384
                                GROUP BY t.topic_id, t.topic_title
385
                                ORDER BY num_posts DESC";
386
                        $result = $db->sql_query_limit($sql, 1);
387
388
                        $active_t_row = $db->sql_fetchrow($result);
389
                        $db->sql_freeresult($result);
390
                }
391
                else
392
                {
393
                        $active_f_row = $active_t_row = array();
394
                }
395
396
                // Do the relevant calculations
397
                $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
398
                $posts_per_day = $member['user_posts'] / $memberdays;
399
                $percentage = ($config['num_posts']) ? min(100, ($num_real_posts / $config['num_posts']) * 100) : 0;
400
401
                $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
402
                if (!empty($active_f_row['num_posts']))
403
                {
404
                        $active_f_name = $active_f_row['forum_name'];
405
                        $active_f_id = $active_f_row['forum_id'];
406
                        $active_f_count = $active_f_row['num_posts'];
407
                        $active_f_pct = ($member['user_posts']) ? ($active_f_count / $member['user_posts']) * 100 : 0;
408
                }
409
                unset($active_f_row);
410
411
                $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
412
                if (!empty($active_t_row['num_posts']))
413
                {
414
                        $active_t_name = $active_t_row['topic_title'];
415
                        $active_t_id = $active_t_row['topic_id'];
416
                        $active_t_count = $active_t_row['num_posts'];
417
                        $active_t_pct = ($member['user_posts']) ? ($active_t_count / $member['user_posts']) * 100 : 0;
418
                }
419
                unset($active_t_row);
420
421
                if ($member['user_sig_bbcode_bitfield'] && $member['user_sig'])
422
                {
423
                        include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx);
424
                        $bbcode = new bbcode();
425
                        $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
426
                }
427
428
                if ($member['user_sig'])
429
                {
430
                        $member['user_sig'] = censor_text(smiley_text($member['user_sig']));
431
                }
432
433
                $poster_avatar = '';
434
                if (!empty($member['user_avatar']))
435
                {
436
                        switch ($member['user_avatar_type'])
437
                        {
438
                                case AVATAR_UPLOAD:
439
                                        $poster_avatar = $config['avatar_path'] . '/';
440
                                        break;
441
                                case AVATAR_GALLERY:
442
                                        $poster_avatar = $config['avatar_gallery_path'] . '/';
443
                                        break;
444
                        }
445
                        $poster_avatar .= $member['user_avatar'];
446
447
                        $poster_avatar = '<img src="' . $poster_avatar . '" width="' . $member['user_avatar_width'] . '" height="' . $member['user_avatar_height'] . '" border="0" alt="" />';
448
                }
449
450
                $template->assign_vars(show_profile($member));
451
452
                // Custom Profile Fields
453
                $profile_fields = array();
454
                if ($config['load_cpf_viewprofile'])
455
                {
456
                        include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
457
                        $cp = new custom_profile();
458
                        $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
459
                        $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
460
                }
461
462
                $template->assign_vars(array(
463
                        'POSTS_DAY'                        => sprintf($user->lang['POST_DAY'], $posts_per_day),
464
                        'POSTS_PCT'                        => sprintf($user->lang['POST_PCT'], $percentage),
465
                        'ACTIVE_FORUM'                => $active_f_name,
466
                        'ACTIVE_FORUM_POSTS'=> ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
467
                        'ACTIVE_FORUM_PCT'        => sprintf($user->lang['POST_PCT'], $active_f_pct),
468
                        'ACTIVE_TOPIC'                => censor_text($active_t_name),
469
                        'ACTIVE_TOPIC_POSTS'=> ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
470
                        'ACTIVE_TOPIC_PCT'        => sprintf($user->lang['POST_PCT'], $active_t_pct),
471
472
                        'OCCUPATION'        => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
473
                        'INTERESTS'                => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
474
                        'SIGNATURE'                => (!empty($member['user_sig'])) ? str_replace("\n", '<br />', $member['user_sig']) : '',
475
476
                        'AVATAR_IMG'        => $poster_avatar,
477
                        'PM_IMG'                => $user->img('btn_pm', $user->lang['MESSAGE']),
478
                        'EMAIL_IMG'                => $user->img('btn_email', $user->lang['EMAIL']),
479
                        'WWW_IMG'                => $user->img('btn_www', $user->lang['WWW']),
480
                        'ICQ_IMG'                => $user->img('btn_icq', $user->lang['ICQ']),
481
                        'AIM_IMG'                => $user->img('btn_aim', $user->lang['AIM']),
482
                        'MSN_IMG'                => $user->img('btn_msnm', $user->lang['MSNM']),
483
                        'YIM_IMG'                => $user->img('btn_yim', $user->lang['YIM']),
484
                        'JABBER_IMG'        => $user->img('btn_jabber', $user->lang['JABBER']),
485
                        'SEARCH_IMG'        => $user->img('btn_search', $user->lang['SEARCH']),
486
487
                        'S_PROFILE_ACTION'        => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=group",
488
                        'S_GROUP_OPTIONS'        => $group_options,
489
                        'S_CUSTOM_FIELDS'        => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
490
491
                        'U_ADD_FRIEND'                => "ucp.$phpEx$SID&amp;i=zebra&amp;add=" . urlencode($member['username']),
492
                        'U_ADD_FOE'                        => "ucp.$phpEx$SID&amp;i=zebra&amp;mode=foes&amp;add=" . urlencode($member['username']),
493
                        'U_ACTIVE_FORUM'        => "viewforum.$phpEx$SID&amp;f=$active_f_id",
494
                        'U_ACTIVE_TOPIC'        => "viewtopic.$phpEx$SID&amp;t=$active_t_id",)
495
                );
496
497
                if (isset($profile_fields['row']) && sizeof($profile_fields['row']))
498
                {
499
                        $template->assign_vars($profile_fields['row']);
500
                }
501
502
                if (isset($profile_fields['blockrow']) && sizeof($profile_fields['blockrow']))
503
                {
504
                        foreach ($profile_fields['blockrow'] as $field_data)
505
                        {
506
                                $template->assign_block_vars('custom_fields', $field_data);
507
                        }
508
                }
509
510
                // Now generate page tilte
511
                $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
512
                $template_html = 'memberlist_view.html';
513
514
        break;
515
516
        case 'email':
517
                // Send an email
518
                $page_title = $user->lang['SEND_EMAIL'];
519
                $template_html = 'memberlist_email.html';
520
521
                if (!$config['email_enable'])
522
                {
523
                        trigger_error('EMAIL_DISABLED');
524
                }
525
526
                if (($user_id == ANONYMOUS || !$config['board_email_form']) && !$topic_id)
527
                {
528
                        trigger_error('NO_EMAIL');
529
                }
530
531
                if (!$auth->acl_get('u_sendemail'))
532
                {
533
                        trigger_error('NO_EMAIL');
534
                }
535
536
                // Are we trying to abuse the facility?
537
                if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
538
                {
539
                        trigger_error('FLOOD_EMAIL_LIMIT');
540
                }
541
542
                $name                = strip_tags(request_var('name', ''));
543
                $email                = strip_tags(request_var('email', ''));
544
                $email_lang = request_var('lang', '');
545
                $subject        = request_var('subject', '');
546
                $message        = request_var('message', '');
547
                $cc                        = (!empty($_POST['cc_email'])) ? true : false;
548
549
                // Are we sending an email to a user on this board? Or are we sending a
550
                // topic heads-up message?
551
                if (!$topic_id)
552
                {
553
                        // Get the appropriate username, etc.
554
                        $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
555
                                FROM ' . USERS_TABLE . "
556
                                WHERE user_id = $user_id
557
                                        AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
558
                        $result = $db->sql_query($sql);
559
560
                        if (!($row = $db->sql_fetchrow($result)))
561
                        {
562
                                trigger_error('NO_USER');
563
                        }
564
                        $db->sql_freeresult($result);
565
566
                        // Can we send email to this user?
567
                        if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
568
                        {
569
                                trigger_error('NO_EMAIL');
570
                        }
571
                }
572
                else
573
                {
574
                        $sql = 'SELECT forum_id, topic_title
575
                                FROM ' . TOPICS_TABLE . "
576
                                WHERE topic_id = $topic_id";
577
                        $result = $db->sql_query($sql);
578
579
                        if (!($row = $db->sql_fetchrow($result)))
580
                        {
581
                                trigger_error('NO_TOPIC');
582
                        }
583
                        $db->sql_freeresult($result);
584
585
                        if (!$auth->acl_get('f_read', $row['forum_id']))
586
                        {
587
                                trigger_error('NO_FORUM_READ');
588
                        }
589
590
                        if (!$auth->acl_get('f_email', $row['forum_id']))
591
                        {
592
                                trigger_error('NO_EMAIL');
593
                        }
594
                }
595
596
                // User has submitted a message, handle it
597
                $error = array();
598
                if ($submit)
599
                {
600
                        if (!$topic_id)
601
                        {
602
                                if (!$subject)
603
                                {
604
                                        $error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
605
                                }
606
607
                                if (!$message)
608
                                {
609
                                        $error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
610
                                }
611
                        }
612
                        else
613
                        {
614
                                if (!$email || !preg_match('#^.*?@(.*?\.)?[a-z0-9\-]+\.[a-z]{2,4}$#i', $email))
615
                                {
616
                                        $error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
617
                                }
618
619
                                if (!$name)
620
                                {
621
                                        $error[] = $user->lang['EMPTY_NAME_EMAIL'];
622
                                }
623
                        }
624
625
                        if (!sizeof($error))
626
                        {
627
                                $sql = 'UPDATE ' . USERS_TABLE . '
628
                                        SET user_emailtime = ' . time() . '
629
                                        WHERE user_id = ' . $user->data['user_id'];
630
                                $result = $db->sql_query($sql);
631
632
                                include_once($phpbb_root_path . 'includes/functions_messenger.'.$phpEx);
633
634
                                $email_tpl        = (!$topic_id) ? 'profile_send_email' : 'email_notify';
635
                                $email_lang = (!$topic_id) ? $row['user_lang'] : $email_lang;
636
                                $email                = (!$topic_id) ? $row['user_email'] : $email;
637
638
                                $messenger = new messenger();
639
640
                                $messenger->template($email_tpl, $email_lang);
641
                                $messenger->subject($subject);
642
643
                                $messenger->replyto($user->data['user_email']);
644
                                $messenger->to($email, $row['username']);
645
646
                                if (!$topic_id)
647
                                {
648
                                        $messenger->im($row['user_jabber'], $row['username']);
649
                                }
650
651
                                if ($cc)
652
                                {
653
                                        $messenger->cc($user->data['user_email'], $user->data['username']);
654
                                }
655
656
                                $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
657
                                $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
658
                                $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
659
                                $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
660
661
                                $messenger->assign_vars(array(
662
                                        'SITENAME'                => $config['sitename'],
663
                                        'BOARD_EMAIL'        => $config['board_contact'],
664
                                        'FROM_USERNAME' => stripslashes($user->data['username']),
665
                                        'TO_USERNAME'        => ($topic_id) ? stripslashes($name) : stripslashes($row['username']),
666
                                        'MESSAGE'                => $message,
667
                                        'TOPIC_NAME'        => ($topic_id) ? strtr($row['topic_title'], array_flip(get_html_translation_table(HTML_ENTITIES))) : '',
668
669
                                        'U_TOPIC'        => ($topic_id) ? generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id" : '')
670
                                );
671
672
                                $messenger->send($row['user_notify_type']);
673
                                $messenger->save_queue();
674
675
                                meta_refresh(3, "index.$phpEx$SID");
676
                                $message = (!$topic_id) ? sprintf($user->lang['RETURN_INDEX'],  '<a href="' . "index.$phpEx$SID" . '">', '</a>') : sprintf($user->lang['RETURN_TOPIC'],  "<a href=\"viewtopic.$phpEx$SID&amp;f=$forum_id&amp;t=" . $row['topic_id'] . '">', '</a>');
677
                                trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message);
678
                        }
679
                }
680
681
                if ($topic_id)
682
                {
683
                        $template->assign_vars(array(
684
                                'EMAIL'                        => htmlspecialchars($email),
685
                                'NAME'                        => htmlspecialchars($name),
686
                                'TOPIC_TITLE'        => $row['topic_title'],
687
688
                                'U_TOPIC'        => "{$phpbb_root_path}viewtopic.$phpEx$SID&amp;f={$row['forum_id']}&amp;t=$topic_id",
689
690
                                'S_LANG_OPTIONS'=> ($topic_id) ? language_select($email_lang) : '')
691
                        );
692
                }
693
694
                $template->assign_vars(array(
695
                        'USERNAME'                => (!$topic_id) ? addslashes($row['username']) : '',
696
                        'ERROR_MESSAGE'        => (sizeof($error)) ? implode('<br />', $error) : '',
697
698
                        'L_EMAIL_BODY_EXPLAIN'        => (!$topic_id) ? $user->lang['EMAIL_BODY_EXPLAIN'] : $user->lang['EMAIL_TOPIC_EXPLAIN'],
699
700
                        'S_POST_ACTION' => (!$topic_id) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=email&amp;u=$user_id" : "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=email&amp;f=$forum_id&amp;t=$topic_id",
701
                        'S_SEND_USER'        => (!$topic_id) ? true : false)
702
                );
703
                break;
704
705
        case 'group':
706
        default:
707
                // The basic memberlist
708
                $page_title = $user->lang['MEMBERLIST'];
709
                $template_html = 'memberlist_body.html';
710
711
                // Sorting
712
                $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'], 'e' => $user->lang['SORT_EMAIL'], 'f' => $user->lang['WEBSITE'], 'g' => $user->lang['ICQ'], 'h' => $user->lang['AIM'], 'i' => $user->lang['MSNM'], 'j' => $user->lang['YIM'], 'k' => $user->lang['JABBER'], 'l' => $user->lang['SORT_LAST_ACTIVE'], 'm' => $user->lang['SORT_RANK']);
713
                $sort_key_sql = array('a' => 'u.username', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'e' => 'u.user_email', 'f' => 'u.user_website', 'g' => 'u.user_icq', 'h' => 'u.user_aim', 'i' => 'u.user_msnm', 'j' => 'u.user_yim', 'k' => 'u.user_jabber', 'l' => 'u.user_lastvisit', 'm' => 'u.user_rank DESC, u.user_posts');
714
715
                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
716
717
                $s_sort_key = '';
718
                foreach ($sort_key_text as $key => $value)
719
                {
720
                        $selected = ($sort_key == $key) ? ' selected="selected"' : '';
721
                        $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
722
                }
723
724
                $s_sort_dir = '';
725
                foreach ($sort_dir_text as $key => $value)
726
                {
727
                        $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
728
                        $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
729
                }
730
731
                // Additional sorting options for user search ... if search is enabled, if not
732
                // then only admins can make use of this (for ACP functionality)
733
                $sql_select = $sql_from = $sql_where = $order_by = '';
734
                
735
                $form        = request_var('form', '');
736
                $field        = request_var('field', '');
737
738
                if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
739
                {
740
                        $username        = request_var('username', '');
741
                        $email                = request_var('email', '');
742
                        $icq                = request_var('icq', '');
743
                        $aim                = request_var('aim', '');
744
                        $yahoo                = request_var('yahoo', '');
745
                        $msn                = request_var('msn', '');
746
                        $jabber                = request_var('jabber', '');
747
                        $search_group_id        = request_var('search_group_id', 0);
748
749
                        $joined_select        = request_var('joined_select', 'lt');
750
                        $active_select        = request_var('active_select', 'lt');
751
                        $count_select        = request_var('count_select', 'eq');
752
                        $joined                        = explode('-', request_var('joined', ''));
753
                        $active                        = explode('-', request_var('active', ''));
754
                        $count                        = (request_var('count', '')) ? request_var('count', 0) : '';
755
                        $ipdomain                = request_var('ip', '');
756
757
                        $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
758
759
                        $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
760
                        $s_find_count = '';
761
                        foreach ($find_count as $key => $value)
762
                        {
763
                                $selected = ($count_select == $key) ? ' selected="selected"' : '';
764
                                $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
765
                        }
766
767
                        $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
768
                        $s_find_join_time = '';
769
                        foreach ($find_time as $key => $value)
770
                        {
771
                                $selected = ($joined_select == $key) ? ' selected="selected"' : '';
772
                                $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
773
                        }
774
775
                        $s_find_active_time = '';
776
                        foreach ($find_time as $key => $value)
777
                        {
778
                                $selected = ($active_select == $key) ? ' selected="selected"' : '';
779
                                $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
780
                        }
781
782
                        $sql_where .= ($username) ? " AND u.username LIKE '" . str_replace('*', '%', $db->sql_escape($username)) . "'" : '';
783
                        $sql_where .= ($email) ? " AND u.user_email LIKE '" . str_replace('*', '%', $db->sql_escape($email)) . "' " : '';
784
                        $sql_where .= ($icq) ? " AND u.user_icq LIKE '" . str_replace('*', '%', $db->sql_escape($icq)) . "' " : '';
785
                        $sql_where .= ($aim) ? " AND u.user_aim LIKE '" . str_replace('*', '%', $db->sql_escape($aim)) . "' " : '';
786
                        $sql_where .= ($yahoo) ? " AND u.user_yim LIKE '" . str_replace('*', '%', $db->sql_escape($yahoo)) . "' " : '';
787
                        $sql_where .= ($msn) ? " AND u.user_msnm LIKE '" . str_replace('*', '%', $db->sql_escape($msn)) . "' " : '';
788
                        $sql_where .= ($jabber) ? " AND u.user_jabber LIKE '" . str_replace('*', '%', $db->sql_escape($jabber)) . "' " : '';
789
                        $sql_where .= (is_numeric($count)) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
790
                        $sql_where .= (sizeof($joined) > 1) ? " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . gmmktime(0, 0, 0, intval($joined[1]), intval($joined[2]), intval($joined[0])) : '';
791
                        $sql_where .= (sizeof($active) > 1) ? " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . gmmktime(0, 0, 0, $active[1], intval($active[2]), intval($active[0])) : '';
792
                        $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id " : '';
793
                        
794
                        if ($search_group_id)
795
                        {
796
                                $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
797
                        }
798
799
                        if ($ipdomain && $auth->acl_get('m_ip'))
800
                        {
801
                                $ips = (preg_match('#[a-z]#', $ipdomain)) ? implode(', ', 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))) : "'" . str_replace('*', '%', $ipdomain) . "'";
802
803
                                $sql = 'SELECT DISTINCT poster_id
804
                                        FROM ' . POSTS_TABLE . '
805
                                        WHERE poster_ip ' . ((preg_match('#%#', $ips)) ? 'LIKE' : 'IN') . " ($ips)";
806
                                $result = $db->sql_query($sql);
807
808
                                if ($row = $db->sql_fetchrow($result))
809
                                {
810
                                        $ip_sql = array();
811
                                        do
812
                                        {
813
                                                $ip_sql[] = $row['poster_id'];
814
                                        }
815
                                        while ($row = $db->sql_fetchrow($result));
816
817
                                        $sql_where .= ' AND u.user_id IN (' . implode(', ', $ip_sql) . ')';
818
                                }
819
                                else
820
                                {
821
                                        // A minor fudge but it does the job :D
822
                                        $sql_where .= " AND u.user_id IN ('-1')";
823
                                }
824
                        }
825
                }
826
827
                $first_char = request_var('first_char', '');
828
829
                if ($first_char == 'other')
830
                {
831
                        $sql_where = '';
832
                        for ($i = 65; $i < 91; $i++)
833
                        {
834
                                $sql_where .= " AND u.username NOT LIKE '" . chr($i) . "%'";
835
                        }
836
                }
837
                else if ($first_char)
838
                {
839
                        $sql_where = " AND u.username LIKE '" . $db->sql_escape(substr($first_char, 0, 1)) . "%'";
840
                }
841
                
842
                // Are we looking at a usergroup? If so, fetch additional info
843
                // and further restrict the user info query
844
                if ($mode == 'group')
845
                {
846
                        // We JOIN here to save a query for determining membership for hidden groups. ;)
847
                        $sql = 'SELECT g.*, ug.user_id
848
                                FROM ' . GROUPS_TABLE . ' g
849
                                LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.user_id = ' . $user->data['user_id'] . " AND ug.group_id = $group_id)
850
                                WHERE g.group_id = $group_id";
851
                        $result = $db->sql_query($sql);
852
853
                        if (!$group_row = $db->sql_fetchrow($result))
854
                        {
855
                                trigger_error('NO_GROUP');
856
                        }
857
                        $db->sql_freeresult($result);
858
859
                        switch ($group_row['group_type'])
860
                        {
861
                                case GROUP_OPEN:
862
                                        $group_row['l_group_type'] = 'OPEN';
863
                                        break;
864
                                case GROUP_CLOSED:
865
                                        $group_row['l_group_type'] = 'CLOSED';
866
                                        break;
867
                                case GROUP_HIDDEN:
868
                                        $group_row['l_group_type'] = 'HIDDEN';
869
870
                                        // Check for membership or special permissions
871
                                        if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
872
                                        {
873
                                                trigger_error('NO_GROUP');
874
                                        }
875
                                        break;
876
                                case GROUP_SPECIAL:
877
                                        $group_row['l_group_type'] = 'SPECIAL';
878
                                        break;
879
                                case GROUP_FREE:
880
                                        $group_row['l_group_type'] = 'FREE';
881
                                        break;
882
                        }
883
884
                        $avatar_img = '';
885
                        if ($group_row['group_avatar'])
886
                        {
887
                                switch ($group_row['group_avatar_type'])
888
                                {
889
                                        case AVATAR_UPLOAD:
890
                                                $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
891
                                                break;
892
                                        case AVATAR_GALLERY:
893
                                                $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
894
                                                break;
895
                                }
896
                                $avatar_img .= $group_row['group_avatar'];
897
898
                                $avatar_img = '<img src="' . $avatar_img . '" width="' . $group_row['group_avatar_width'] . '" height="' . $group_row['group_avatar_height'] . '" border="0" alt="" />';
899
                        }
900
901
                        $rank_title = $rank_img = '';
902
                        if ($group_row['group_rank'] != -1)
903
                        {
904
                                $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
905
                                $rank_img = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] . '" border="0" alt="' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '" title="' . $ranks['special'][$group_row['group_rank']]['rank_title'] . '" /><br />' : '';
906
                        }
907
                        else if ($group_row['group_rank'] == -1)
908
                        {
909
                                $rank_title = '';
910
                                $rank_img = '';
911
                        }
912
913
                        $template->assign_vars(array(
914
                                'GROUP_DESC'        => $group_row['group_description'],
915
                                'GROUP_NAME'        => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
916
                                'GROUP_COLOR'        => $group_row['group_colour'],
917
                                'GROUP_TYPE'        => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
918
                                'GROUP_RANK'        => $rank_title,
919
920
                                'AVATAR_IMG'        => $avatar_img,
921
                                'RANK_IMG'                => $rank_img,
922
923
                                'U_PM'                        => ($auth->acl_get('u_sendpm') && $group_row['group_receive_pm'] && $config['allow_mass_pm']) ? "{$phpbb_root_path}ucp.$phpEx$SID&amp;i=pm&amp;mode=compose&amp;g=$group_id" : '',)
924
                        );
925
926
                        $sql_select = ', ug.group_leader';
927
                        $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
928
                        $order_by = 'ug.group_leader DESC, ';
929
930
                        $sql_where .= " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
931
                }
932
                
933
                // Sorting and order
934
                $order_by .= $sort_key_sql[$sort_key] . '  ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
935
936
                // Count the users ...
937
                if ($sql_where)
938
                {
939
                        $sql = 'SELECT COUNT(u.user_id) AS total_users
940
                                FROM ' . USERS_TABLE . " u$sql_from
941
                                WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
942
                                $sql_where";
943
                        $result = $db->sql_query($sql);
944
945
                        $total_users = ($row = $db->sql_fetchrow($result)) ? $row['total_users'] : 0;
946
                        $db->sql_freeresult($result);
947
                }
948
                else
949
                {
950
                        $total_users = $config['num_users'];
951
                }
952
953
                $s_char_options = '<option value=""' . ((!$first_char) ? ' selected="selected"' : '') . '>&nbsp; &nbsp;</option>';
954
                for ($i = 65; $i < 91; $i++)
955
                {
956
                        $s_char_options .= '<option value="' . chr($i) . '"' . (($first_char == chr($i)) ? ' selected="selected"' : '') . '>' . chr($i) . '</option>';
957
                }
958
                $s_char_options .= '<option value="other"' . (($first_char == 'other') ? ' selected="selected"' : '') . '>Other</option>';
959
960
                // Pagination string
961
                $pagination_url = "{$phpbb_root_path}memberlist.$phpEx$SID";
962
963
                // Build a relevant pagination_url
964
                $global_var = ($submit) ? '_POST' : '_GET';
965
                foreach ($$global_var as $key => $var)
966
                {
967
                        if (in_array($key, array('submit', 'start', 'mode')) || !$var)
968
                        {
969
                                continue;
970
                        }
971
                        $pagination_url .= '&amp;' . $key . '=' . urlencode(htmlspecialchars($var));
972
                }
973
974
                $u_hide_find_member = $pagination_url;
975
                $pagination_url .= "&amp;mode=$mode&amp;first_char=$first_char";
976
977
                // Some search user specific data
978
                if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
979
                {
980
                        $group_selected = request_var('search_group_id', 0);
981
                        $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
982
983
                        $sql = 'SELECT group_id, group_name, group_type
984
                                FROM ' . GROUPS_TABLE . '
985
                                WHERE group_type <> ' . GROUP_HIDDEN . '
986
                                ORDER BY group_name ASC';
987
                        $result = $db->sql_query($sql);
988
989
                        while ($row = $db->sql_fetchrow($result))
990
                        {
991
                                $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>';
992
                        }
993
                        $db->sql_freeresult($result);
994
995
                        $template->assign_vars(array(
996
                                'USERNAME'        => $username,
997
                                'EMAIL'                => $email,
998
                                'ICQ'                => $icq,
999
                                'AIM'                => $aim,
1000
                                'YAHOO'                => $yahoo,
1001
                                'MSNM'                => $msn,
1002
                                'JABBER'        => $jabber,
1003
                                'JOINED'        => implode('-', $joined),
1004
                                'ACTIVE'        => implode('-', $active),
1005
                                'COUNT'                => $count,
1006
                                'IP'                => $ipdomain,
1007
1008
                                'S_SEARCH_USER'                 => true,
1009
                                'S_FORM_NAME'                         => $form,
1010
                                'S_FIELD_NAME'                         => $field,
1011
                                'S_COUNT_OPTIONS'                 => $s_find_count,
1012
                                'S_SORT_OPTIONS'                 => $s_sort_key,
1013
                                'S_JOINED_TIME_OPTIONS' => $s_find_join_time,
1014
                                'S_ACTIVE_TIME_OPTIONS' => $s_find_active_time,
1015
                                'S_GROUP_SELECT'                => $s_group_select,
1016
                                'S_SEARCH_ACTION'                 => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=searchuser&amp;form=$form&amp;field=$field")
1017
                        );
1018
                }
1019
1020
                $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
1021
                        FROM ' . SESSIONS_TABLE . '
1022
                        WHERE session_time >= ' . (time() - $config['session_length']) . '
1023
                                AND session_user_id <> ' . ANONYMOUS . '
1024
                        GROUP BY session_user_id';
1025
                $result = $db->sql_query($sql);
1026
1027
                $session_times = array();
1028
                while ($row = $db->sql_fetchrow($result))
1029
                {
1030
                        $session_times[$row['session_user_id']] = $row['session_time'];
1031
                }
1032
                $db->sql_freeresult($result);
1033
1034
                // Do the SQL thang
1035
                $sql = "SELECT u.username, u.user_id, u.user_colour, u.user_allow_viewemail, u.user_posts, u.user_regdate, u.user_rank, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_msnm, u.user_jabber, u.user_avatar, u.user_avatar_type, u.user_lastvisit
1036
                                $sql_select
1037
                        FROM " . USERS_TABLE . " u
1038
                                $sql_from
1039
                        WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1040
                                $sql_where
1041
                        ORDER BY $order_by";
1042
                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1043
1044
                $id_cache = array();
1045
                while ($row = $db->sql_fetchrow($result))
1046
                {
1047
                        $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : '';
1048
1049
                        $id_cache[$row['user_id']] = $row;
1050
                }
1051
                $db->sql_freeresult($result);
1052
                        
1053
                // Load custom profile fields
1054
                if ($config['load_cpf_memberlist'])
1055
                {
1056
                        include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1057
                        $cp = new custom_profile();
1058
1059
                        // Grab all profile fields from users in id cache for later use - similar to the poster cache
1060
                        $profile_fields_cache = $cp->generate_profile_fields_template('grab', array_keys($id_cache));
1061
                }
1062
                
1063
                $i = 0;
1064
                foreach ($id_cache as $user_id => $row)
1065
                {
1066
                        $cp_row = array();
1067
                        if ($config['load_cpf_memberlist'])
1068
                        {
1069
                                $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
1070
                        }
1071
1072
                        $memberrow = array_merge(show_profile($row), array(
1073
                                'ROW_NUMBER'                => $i + ($start + 1),
1074
1075
                                'S_CUSTOM_PROFILE'        => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1076
                                'S_GROUP_LEADER'        => (isset($row['group_leader']) && $row['group_leader']) ? true : false,
1077
                                
1078
                                'U_VIEWPROFILE'                => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=$user_id")
1079
                        );
1080
1081
                        if (isset($cp_row['row']) && sizeof($cp_row['row']))
1082
                        {
1083
                                $memberrow = array_merge($memberrow, $cp_row['row']);
1084
                        }
1085
1086
                        $template->assign_block_vars('memberrow', $memberrow);
1087
1088
                        if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
1089
                        {
1090
                                foreach ($cp_row['blockrow'] as $field_data)
1091
                                {
1092
                                        $template->assign_block_vars('memberrow.custom_fields', $field_data);
1093
                                }
1094
                        }
1095
1096
                        $i++;
1097
                        unset($id_cache[$user_id]);
1098
                }
1099
        
1100
                // Generate page
1101
                $template->assign_vars(array(
1102
                        'PAGINATION'         => generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
1103
                        'PAGE_NUMBER'         => on_page($total_users, $config['topics_per_page'], $start),
1104
                        'TOTAL_USERS'        => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
1105
1106
                        'PROFILE_IMG'        => $user->img('btn_profile', $user->lang['PROFILE']),
1107
                        'PM_IMG'                => $user->img('btn_pm', $user->lang['MESSAGE']),
1108
                        'EMAIL_IMG'                => $user->img('btn_email', $user->lang['EMAIL']),
1109
                        'WWW_IMG'                => $user->img('btn_www', $user->lang['WWW']),
1110
                        'ICQ_IMG'                => $user->img('btn_icq', $user->lang['ICQ']),
1111
                        'AIM_IMG'                => $user->img('btn_aim', $user->lang['AIM']),
1112
                        'MSN_IMG'                => $user->img('btn_msnm', $user->lang['MSNM']),
1113
                        'YIM_IMG'                => $user->img('btn_yim', $user->lang['YIM']),
1114
                        'JABBER_IMG'        => $user->img('btn_jabber', $user->lang['JABBER']),
1115
                        'SEARCH_IMG'        => $user->img('btn_search', $user->lang['SEARCH']),
1116
1117
                        'U_FIND_MEMBER'                => ($config['load_search'] || $auth->acl_get('a_')) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=searchuser" : '',
1118
                        'U_HIDE_FIND_MEMBER'=> ($mode == 'searchuser') ? $u_hide_find_member : '',
1119
                        'U_SORT_USERNAME'        => $pagination_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
1120
                        'U_SORT_FROM'                => $pagination_url . '&amp;sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1121
                        'U_SORT_JOINED'                => $pagination_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
1122
                        'U_SORT_POSTS'                => $pagination_url . '&amp;sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
1123
                        'U_SORT_EMAIL'                => $pagination_url . '&amp;sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
1124
                        'U_SORT_WEBSITE'        => $pagination_url . '&amp;sk=f&amp;sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
1125
                        'U_SORT_ICQ'                => $pagination_url . '&amp;sk=g&amp;sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
1126
                        'U_SORT_AIM'                => $pagination_url . '&amp;sk=h&amp;sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
1127
                        'U_SORT_MSN'                => $pagination_url . '&amp;sk=i&amp;sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
1128
                        'U_SORT_YIM'                => $pagination_url . '&amp;sk=j&amp;sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
1129
                        'U_SORT_ACTIVE'                => $pagination_url . '&amp;sk=k&amp;sd=' . (($sort_key == 'k' && $sort_dir == 'a') ? 'd' : 'a'),
1130
                        'U_SORT_RANK'                => $pagination_url . '&amp;sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
1131
                        'U_LIST_CHAR'                => $pagination_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
1132
1133
                        'S_SHOW_GROUP'                => ($mode == 'group') ? true : false,
1134
                        'S_MODE_SELECT'                => $s_sort_key,
1135
                        'S_ORDER_SELECT'        => $s_sort_dir,
1136
                        'S_CHAR_OPTIONS'        => $s_char_options,
1137
                        'S_MODE_ACTION'                => $pagination_url . "&amp;form=$form")
1138
                );
1139
}
1140
1141
// Output the page
1142
page_header($page_title);
1143
1144
$template->set_filenames(array(
1145
        'body' => $template_html)
1146
);
1147
make_jumpbox('viewforum.'.$phpEx);
1148
1149
page_footer();
1150
1151
/**
1152
* Get user rank title and image
1153
*/
1154
function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img)
1155
{
1156
        global $ranks, $config;
1157
1158
        if (!empty($user_rank))
1159
        {
1160
                $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1161
                $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
1162
        }
1163
        else
1164
        {
1165
                if (isset($ranks['normal']))
1166
                {
1167
                        foreach ($ranks['normal'] as $rank)
1168
                        {
1169
                                if ($user_posts >= $rank['rank_min'])
1170
                                {
1171
                                        $rank_title = $rank['rank_title'];
1172
                                        $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1173
                                        break;
1174
                                }
1175
                        }
1176
                }
1177
        }
1178
}
1179
1180
/**
1181
* Prepare profile data
1182
*/
1183
function show_profile($data)
1184
{
1185
        global $config, $auth, $template, $user, $SID, $phpEx, $phpbb_root_path;
1186
1187
        $username = $data['username'];
1188
        $user_id = $data['user_id'];
1189
1190
        $rank_title = $rank_img = '';
1191
        get_user_rank($data['user_rank'], $data['user_posts'], $rank_title, $rank_img);
1192
        
1193
        if (!empty($data['user_allow_viewemail']) || $auth->acl_get('a_email'))
1194
        {
1195
                $email = ($config['board_email_form'] && $config['email_enable']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=email&amp;u=$user_id" : (($config['board_hide_emails'] && !$auth->acl_get('a_email')) ? '' : 'mailto:' . $data['user_email']);
1196
        }
1197
        else
1198
        {
1199
                $email = '';
1200
        }
1201
1202
        $last_visit = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
1203
1204
        // Dump it out to the template
1205
        // TODO
1206
        // Add permission check for IM clients
1207
        return array(
1208
                'USERNAME'                => $username,
1209
                'USER_COLOR'        => (!empty($data['user_colour'])) ? $data['user_colour'] : '',
1210
                'RANK_TITLE'        => $rank_title,
1211
                'JOINED'                => $user->format_date($data['user_regdate'], $user->lang['DATE_FORMAT']),
1212
                'VISITED'                => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit, $user->lang['DATE_FORMAT']),
1213
                'POSTS'                        => ($data['user_posts']) ? $data['user_posts'] : 0,
1214
1215
                'ONLINE_IMG'        => (intval($data['session_time']) >= time() - ($config['load_online_time'] * 60)) ? $user->img('btn_online', $user->lang['USER_ONLINE']) : $user->img('btn_offline', $user->lang['USER_ONLINE']),
1216
                'RANK_IMG'                => $rank_img,
1217
                '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" border="0" />' : '',
1218
1219
                'U_PROFILE'                => "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=viewprofile&amp;u=$user_id",
1220
                'U_SEARCH_USER'        => ($auth->acl_get('u_search')) ? "{$phpbb_root_path}search.$phpEx$SID&amp;search_author=" . urlencode($username) . "&amp;show_results=posts" : '',
1221
                'U_PM'                        => ($auth->acl_get('u_sendpm')) ? "{$phpbb_root_path}ucp.$phpEx$SID&amp;i=pm&amp;mode=compose&amp;u=$user_id" : '',
1222
                'U_EMAIL'                => $email,
1223
                'U_WWW'                        => (!empty($data['user_website'])) ? $data['user_website'] : '',
1224
                'U_ICQ'                        => ($data['user_icq']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=contact&amp;action=icq&amp;u=$user_id" : '',
1225
                'U_AIM'                        => ($data['user_aim']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=contact&amp;action=aim&amp;u=$user_id" : '',
1226
                'U_YIM'                        => ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $data['user_yim'] . '&.src=pg' : '',
1227
                'U_MSN'                        => ($data['user_msnm']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=contact&amp;action=msnm&amp;u=$user_id" : '',
1228
                'U_JABBER'                => ($data['user_jabber']) ? "{$phpbb_root_path}memberlist.$phpEx$SID&amp;mode=contact&amp;action=jabber&amp;u=$user_id" : '',
1229
1230
                'S_ONLINE'        => (intval($data['session_time']) >= time() - ($config['load_online_time'] * 60)) ? true : false
1231
        );
1232
}
1233
1234
?>