- a bunch of fixes
[phpbb.git] / phpBB / memberlist.php
blob8b35a162e5cc013600058d481df8eed44096fac4
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 define('IN_PHPBB', true);
15 $phpbb_root_path = './';
16 $phpEx = substr(strrchr(__FILE__, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
19 // Start session management
20 $user->session_begin();
21 $auth->acl($user->data);
22 $user->setup(array('memberlist', 'groups'));
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);
32 switch ($mode)
34 case 'email':
35 break;
37 default:
38 // Can this user view profiles/memberlist?
39 if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
41 if ($user->data['user_id'] != ANONYMOUS)
43 trigger_error('NO_VIEW_USERS');
46 login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
48 break;
52 $start = request_var('start', 0);
53 $submit = (isset($_POST['submit'])) ? true : false;
55 $default_key = 'c';
56 $sort_key = request_var('sk', $default_key);
57 $sort_dir = request_var('sd', 'a');
60 // Grab rank information for later
61 $ranks = $cache->obtain_ranks();
64 // What do you want to do today? ... oops, I think that line is taken ...
65 switch ($mode)
67 case 'leaders':
68 // Display a listing of board admins, moderators
69 $user->add_lang('groups');
71 $page_title = $user->lang['THE_TEAM'];
72 $template_html = 'memberlist_leaders.html';
74 $user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false);
76 $admin_id_ary = $mod_id_ary = $forum_id_ary = array();
77 foreach ($user_ary as $forum_id => $forum_ary)
79 foreach ($forum_ary as $auth_option => $id_ary)
81 if (!$forum_id && $auth_option == 'a_')
83 $admin_id_ary = array_merge($admin_id_ary, $id_ary);
84 continue;
86 else
88 $mod_id_ary = array_merge($mod_id_ary, $id_ary);
91 if ($forum_id)
93 foreach ($id_ary as $id)
95 $forum_id_ary[$id][] = $forum_id;
101 $admin_id_ary = array_unique($admin_id_ary);
102 $mod_id_ary = array_unique($mod_id_ary);
104 // Admin group id...
105 $sql = 'SELECT group_id
106 FROM ' . GROUPS_TABLE . "
107 WHERE group_name = 'ADMINISTRATORS'";
108 $result = $db->sql_query($sql);
109 $admin_group_id = (int) $db->sql_fetchfield('group_id');
110 $db->sql_freeresult($result);
112 $sql = 'SELECT forum_id, forum_name
113 FROM ' . FORUMS_TABLE . '
114 WHERE forum_type = ' . FORUM_POST;
115 $result = $db->sql_query($sql);
117 $forums = array();
118 while ($row = $db->sql_fetchrow($result))
120 $forums[$row['forum_id']] = $row['forum_name'];
122 $db->sql_freeresult($result);
124 $sql = $db->sql_build_query('SELECT', array(
125 'SELECT' => 'u.user_id, u.group_id as default_group, u.username, u.username_clean, u.user_colour, u.user_rank, u.user_posts, u.user_allow_pm, g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id',
127 'FROM' => array(
128 USERS_TABLE => 'u',
129 GROUPS_TABLE => 'g'
132 'LEFT_JOIN' => array(
133 array(
134 'FROM' => array(USER_GROUP_TABLE => 'ug'),
135 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id']
139 'WHERE' => $db->sql_in_set('u.user_id', array_unique(array_merge($admin_id_ary, $mod_id_ary))) . '
140 AND u.group_id = g.group_id',
142 'ORDER_BY' => 'g.group_name ASC, u.username_clean ASC'
145 $result = $db->sql_query($sql);
147 while ($row = $db->sql_fetchrow($result))
149 $which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod';
151 // We sort out admins not having the admin group as default
152 // The drawback is that only those admins are displayed which are within
153 // the special group 'Administrators' and also having it assigned as their default group.
154 // - might change
155 if ($which_row == 'admin' && $row['default_group'] != $admin_group_id)
157 // Remove from admin_id_ary, because the user may be a mod instead
158 unset($admin_id_ary[array_search($row['user_id'], $admin_id_ary)]);
160 if (!in_array($row['user_id'], $mod_id_ary))
162 continue;
164 else
166 $which_row = 'mod';
170 $s_forum_select = '';
171 $undisclosed_forum = false;
173 if (isset($forum_id_ary[$row['user_id']]))
175 if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']])))
177 foreach ($forum_id_ary[$row['user_id']] as $forum_id)
179 if (isset($forums[$forum_id]))
181 if ($auth->acl_get('f_list', $forum_id))
183 $s_forum_select .= '<option value="">' . $forums[$forum_id] . '</option>';
185 else
187 $undisclosed_forum = true;
194 // If the mod is only moderating non-viewable forums let us display this circumstance
195 // instead of saying they are moderating all forums
196 if (!$s_forum_select && $undisclosed_forum)
198 $s_forum_select = '<option value="">' . $user->lang['FORUM_UNDISCLOSED'] . '</option>';
201 if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
203 $group_name = $user->lang['GROUP_UNDISCLOSED'];
204 $u_group = '';
206 else
208 $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
209 $u_group = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']);
212 $rank_title = $rank_img = '';
213 get_user_rank($row['user_rank'], $row['user_posts'], $rank_title, $rank_img, $rank_img_src);
215 $template->assign_block_vars($which_row, array(
216 'USER_ID' => $row['user_id'],
217 'FORUMS' => $s_forum_select,
218 'RANK_TITLE' => $rank_title,
219 'GROUP_NAME' => $group_name,
220 'GROUP_COLOR' => $row['group_colour'],
222 'RANK_IMG' => $rank_img,
223 'RANK_IMG_SRC' => $rank_img_src,
225 'U_GROUP' => $u_group,
226 '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']) : '',
228 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
229 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
230 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
231 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
234 $db->sql_freeresult($result);
236 $template->assign_vars(array(
237 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
239 break;
241 case 'contact':
242 $page_title = $user->lang['IM_USER'];
243 $template_html = 'memberlist_im.html';
245 $presence_img = '';
246 switch ($action)
248 case 'aim':
249 $lang = 'AIM';
250 $sql_field = 'user_aim';
251 $s_select = 'S_SEND_AIM';
252 $s_action = '';
253 break;
255 case 'msnm':
256 $lang = 'MSNM';
257 $sql_field = 'user_msnm';
258 $s_select = 'S_SEND_MSNM';
259 $s_action = '';
260 break;
262 case 'jabber':
263 $lang = 'JABBER';
264 $sql_field = 'user_jabber';
265 $s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
266 $s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=$action&amp;u=$user_id");
267 break;
269 default:
270 trigger_error('This contact option is not supported', E_USER_ERROR);
271 break;
274 // Grab relevant data
275 $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
276 FROM " . USERS_TABLE . "
277 WHERE user_id = $user_id
278 AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
279 $result = $db->sql_query($sql);
280 $row = $db->sql_fetchrow($result);
281 $db->sql_freeresult($result);
283 if (!$row)
285 trigger_error('NO_USER_DATA');
288 // Post data grab actions
289 switch ($action)
291 case 'jabber':
292 if ($submit && @extension_loaded('xml') && $config['jab_enable'])
294 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
296 $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
297 $message = request_var('message', '', true);
299 $messenger = new messenger(false);
301 $messenger->template('profile_send_im', $row['user_lang']);
302 $messenger->subject(htmlspecialchars_decode($subject));
304 $messenger->replyto($user->data['user_email']);
305 $messenger->im($row['user_jabber'], $row['username']);
307 $messenger->assign_vars(array(
308 'BOARD_EMAIL' => $config['board_contact'],
309 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
310 'TO_USERNAME' => htmlspecialchars_decode($row['username']),
311 'MESSAGE' => htmlspecialchars_decode($message))
314 $messenger->send(NOTIFY_IM);
316 $s_select = 'S_SENT_JABBER';
318 break;
321 // Send vars to the template
322 $template->assign_vars(array(
323 'IM_CONTACT' => $row[$sql_field],
324 'USERNAME' => $row['username'],
325 'CONTACT_NAME' => $row[$sql_field],
326 'SITENAME' => $config['sitename'],
328 'PRESENCE_IMG' => $presence_img,
330 'L_SEND_IM_EXPLAIN' => $user->lang['IM_' . $lang],
331 'L_IM_SENT_JABBER' => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
333 $s_select => true,
334 'S_IM_ACTION' => $s_action)
337 break;
339 case 'viewprofile':
340 // Display a profile
341 if ($user_id == ANONYMOUS && !$username)
343 trigger_error('NO_USER');
346 // Get user...
347 if ($username)
349 $sql = 'SELECT *
350 FROM ' . USERS_TABLE . "
351 WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
353 else
355 $sql = 'SELECT *
356 FROM ' . USERS_TABLE . "
357 WHERE user_id = $user_id";
360 // a_user admins and founder are able to view inactive users and bots to be able to
361 // manage them more easily
362 if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
364 $sql .= ' AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
367 $result = $db->sql_query($sql);
368 $member = $db->sql_fetchrow($result);
369 $db->sql_freeresult($result);
371 if (!$member)
373 trigger_error('NO_USER');
376 $user_id = (int) $member['user_id'];
378 // Do the SQL thang
379 $sql = 'SELECT g.group_id, g.group_name, g.group_type
380 FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
381 WHERE ug.user_id = $user_id
382 AND g.group_id = ug.group_id" . ((!$auth->acl_get('a_group')) ? ' AND group_type <> ' . GROUP_HIDDEN : '') . '
383 ORDER BY group_type, group_name';
384 $result = $db->sql_query($sql);
386 $group_options = '';
387 while ($row = $db->sql_fetchrow($result))
389 $group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
391 $db->sql_freeresult($result);
393 // What colour is the zebra
394 $sql = 'SELECT friend, foe
395 FROM ' . ZEBRA_TABLE . "
396 WHERE zebra_id = $user_id
397 AND user_id = {$user->data['user_id']}";
399 $result = $db->sql_query($sql);
400 $row = $db->sql_fetchrow($result);
401 $foe = ($row['foe']) ? true : false;
402 $friend = ($row['friend']) ? true : false;
403 $db->sql_freeresult($result);
405 if ($config['load_onlinetrack'])
407 $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
408 FROM ' . SESSIONS_TABLE . "
409 WHERE session_user_id = $user_id";
410 $result = $db->sql_query($sql);
411 $row = $db->sql_fetchrow($result);
412 $db->sql_freeresult($result);
414 $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
415 $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
416 unset($row);
419 if ($config['load_user_activity'])
421 if (!function_exists('display_user_activity'))
423 include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
425 display_user_activity($member);
428 // Do the relevant calculations
429 $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
430 $posts_per_day = $member['user_posts'] / $memberdays;
431 $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
434 if ($member['user_sig'])
436 $member['user_sig'] = censor_text($member['user_sig']);
437 $member['user_sig'] = str_replace("\n", '<br />', $member['user_sig']);
439 if ($member['user_sig_bbcode_bitfield'])
441 include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
442 $bbcode = new bbcode();
443 $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
446 $member['user_sig'] = smiley_text($member['user_sig']);
449 $poster_avatar = '';
450 if (!empty($member['user_avatar']))
452 switch ($member['user_avatar_type'])
454 case AVATAR_UPLOAD:
455 $poster_avatar = $config['avatar_path'] . '/';
456 break;
458 case AVATAR_GALLERY:
459 $poster_avatar = $config['avatar_gallery_path'] . '/';
460 break;
462 $poster_avatar .= $member['user_avatar'];
464 $poster_avatar = '<img src="' . $poster_avatar . '" width="' . $member['user_avatar_width'] . '" height="' . $member['user_avatar_height'] . '" alt="" />';
467 $template->assign_vars(show_profile($member));
469 // Custom Profile Fields
470 $profile_fields = array();
471 if ($config['load_cpf_viewprofile'])
473 include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
474 $cp = new custom_profile();
475 $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
476 $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
479 // We need to check if the module 'zebra' is accessible
480 $zebra_enabled = false;
482 if ($user->data['user_id'] != $user_id && $user->data['is_registered'])
484 include_once($phpbb_root_path . 'includes/functions_module.' . $phpEx);
485 $module = new p_master();
486 $module->list_modules('ucp');
487 $module->set_active('zebra');
489 $zebra_enabled = ($module->active_module === false) ? false : true;
491 unset($module);
494 $template->assign_vars(array(
495 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day),
496 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage),
498 'OCCUPATION' => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
499 'INTERESTS' => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
500 'SIGNATURE' => $member['user_sig'],
502 'AVATAR_IMG' => $poster_avatar,
503 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
504 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
505 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
506 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
507 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
508 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
509 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
510 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
511 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
513 'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
514 'S_GROUP_OPTIONS' => $group_options,
515 'S_CUSTOM_FIELDS' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
517 '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) : '',
518 '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}") : '',
520 'S_ZEBRA' => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
521 'U_ADD_FRIEND' => (!$friend) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;add=' . urlencode($member['username'])) : '',
522 'U_ADD_FOE' => (!$foe) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;mode=foes&amp;add=' . urlencode($member['username'])) : '',
523 'U_REMOVE_FRIEND' => ($friend) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
524 'U_REMOVE_FOE' => ($foe) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
527 if (!empty($profile_fields['row']))
529 $template->assign_vars($profile_fields['row']);
532 if (!empty($profile_fields['blockrow']))
534 foreach ($profile_fields['blockrow'] as $field_data)
536 $template->assign_block_vars('custom_fields', $field_data);
540 // Inactive reason/account?
541 if ($member['user_type'] == USER_INACTIVE)
543 $user->add_lang('acp/common');
545 $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
547 switch ($member['user_inactive_reason'])
549 case INACTIVE_REGISTER:
550 $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
551 break;
553 case INACTIVE_PROFILE:
554 $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
555 break;
557 case INACTIVE_MANUAL:
558 $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
559 break;
561 case INACTIVE_REMIND:
562 $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
563 break;
566 $template->assign_vars(array(
567 'S_USER_INACTIVE' => true,
568 'USER_INACTIVE_REASON' => $inactive_reason)
572 // Now generate page tilte
573 $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
574 $template_html = 'memberlist_view.html';
576 break;
578 case 'email':
580 // Send an email
581 $page_title = $user->lang['SEND_EMAIL'];
582 $template_html = 'memberlist_email.html';
584 if (!$config['email_enable'])
586 trigger_error('EMAIL_DISABLED');
589 if (!$auth->acl_get('u_sendemail'))
591 trigger_error('NO_EMAIL');
594 // Are we trying to abuse the facility?
595 if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
597 trigger_error('FLOOD_EMAIL_LIMIT');
600 // Determine action...
601 $user_id = request_var('u', 0);
602 $topic_id = request_var('t', 0);
604 // Send email to user...
605 if ($user_id)
607 if ($user_id == ANONYMOUS || !$config['board_email_form'])
609 trigger_error('NO_EMAIL');
612 // Get the appropriate username, etc.
613 $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
614 FROM ' . USERS_TABLE . "
615 WHERE user_id = $user_id
616 AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
617 $result = $db->sql_query($sql);
618 $row = $db->sql_fetchrow($result);
619 $db->sql_freeresult($result);
621 if (!$row)
623 trigger_error('NO_USER');
626 // Can we send email to this user?
627 if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
629 trigger_error('NO_EMAIL');
632 else if ($topic_id)
634 // Send topic heads-up to email address
635 $sql = 'SELECT forum_id, topic_title
636 FROM ' . TOPICS_TABLE . "
637 WHERE topic_id = $topic_id";
638 $result = $db->sql_query($sql);
639 $row = $db->sql_fetchrow($result);
640 $db->sql_freeresult($result);
642 if (!$row)
644 trigger_error('NO_TOPIC');
647 if ($row['forum_id'])
649 if (!$auth->acl_get('f_read', $row['forum_id']))
651 trigger_error($user->lang['SORRY_AUTH_READ']);
654 if (!$auth->acl_get('f_email', $row['forum_id']))
656 trigger_error('NO_EMAIL');
659 else
661 // If global announcement, we need to check if the user is able to at least read and email in one forum...
662 if (!$auth->acl_getf_global('f_read'))
664 trigger_error($user->lang['SORRY_AUTH_READ']);
667 if (!$auth->acl_getf_global('f_email'))
669 trigger_error('NO_EMAIL');
673 else
675 trigger_error('NO_EMAIL');
678 $error = array();
680 $name = request_var('name', '', true);
681 $email = request_var('email', '');
682 $email_lang = request_var('lang', $config['default_lang']);
683 $subject = request_var('subject', '', true);
684 $message = request_var('message', '', true);
685 $cc = (isset($_POST['cc_email'])) ? true : false;
686 $submit = (isset($_POST['submit'])) ? true : false;
688 if ($submit)
690 if ($user_id)
692 if (!$subject)
694 $error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
697 if (!$message)
699 $error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
702 $name = $row['username'];
703 $email_lang = $row['user_lang'];
704 $email = $row['user_email'];
706 else
708 if (!$email || !preg_match('#^.*?@(.*?\.)?[a-z0-9\-]+\.[a-z]{2,4}$#i', $email))
710 $error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
713 if (!$name)
715 $error[] = $user->lang['EMPTY_NAME_EMAIL'];
719 if (!sizeof($error))
721 $sql = 'UPDATE ' . USERS_TABLE . '
722 SET user_emailtime = ' . time() . '
723 WHERE user_id = ' . $user->data['user_id'];
724 $result = $db->sql_query($sql);
726 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
727 $messenger = new messenger(false);
728 $email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify';
730 $mail_to_users = array();
732 $mail_to_users[] = array(
733 'email_lang' => $email_lang,
734 'email' => $email,
735 'name' => $name,
736 'username' => ($user_id) ? $row['username'] : '',
737 'to_name' => $name,
738 'user_jabber' => ($user_id) ? $row['user_jabber'] : '',
739 'user_notify_type' => ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL,
740 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
741 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
744 // Ok, now the same email if CC specified, but without exposing the users email address
745 if ($cc)
747 $mail_to_users[] = array(
748 'email_lang' => $user->data['user_lang'],
749 'email' => $user->data['user_email'],
750 'name' => $user->data['username'],
751 'username' => $user->data['username'],
752 'to_name' => $name,
753 'user_jabber' => $user->data['user_jabber'],
754 'user_notify_type' => ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL,
755 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
756 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
760 foreach ($mail_to_users as $row)
762 $messenger->template($email_tpl, $row['email_lang']);
763 $messenger->replyto($user->data['user_email']);
764 $messenger->to($row['email'], $row['name']);
766 if ($user_id)
768 $messenger->subject(htmlspecialchars_decode($subject));
769 $messenger->im($row['user_jabber'], $row['username']);
770 $notify_type = $row['user_notify_type'];
772 else
774 $notify_type = NOTIFY_EMAIL;
777 $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
778 $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
779 $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
780 $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
782 $messenger->assign_vars(array(
783 'BOARD_EMAIL' => $config['board_contact'],
784 'TO_USERNAME' => htmlspecialchars_decode($row['to_name']),
785 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
786 'MESSAGE' => htmlspecialchars_decode($message))
789 if ($topic_id)
791 $messenger->assign_vars(array(
792 'TOPIC_NAME' => htmlspecialchars_decode($row['topic_title']),
793 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id")
797 $messenger->send($notify_type);
800 meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
801 $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>');
802 trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message);
806 if ($user_id)
808 $template->assign_vars(array(
809 'S_SEND_USER' => true,
810 'USERNAME' => $row['username'],
812 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_BODY_EXPLAIN'],
813 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id))
816 else
818 $template->assign_vars(array(
819 'EMAIL' => $email,
820 'NAME' => $name,
821 'S_LANG_OPTIONS' => language_select($email_lang),
823 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_TOPIC_EXPLAIN'],
824 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;t=' . $topic_id))
828 $template->assign_vars(array(
829 'ERROR_MESSAGE' => (sizeof($error)) ? implode('<br />', $error) : '')
832 break;
834 case 'group':
835 default:
836 // The basic memberlist
837 $page_title = $user->lang['MEMBERLIST'];
838 $template_html = 'memberlist_body.html';
840 // Sorting
841 $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']);
843 if ($auth->acl_get('u_viewonline'))
845 $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
847 $sort_key_text['m'] = $user->lang['SORT_RANK'];
849 $sort_key_sql = array('a' => 'u.username_clean', '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');
851 if ($auth->acl_get('u_viewonline'))
853 $sort_key_sql['l'] = 'u.user_lastvisit';
855 $sort_key_sql['m'] = 'u.user_rank DESC, u.user_posts';
857 $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
859 $s_sort_key = '';
860 foreach ($sort_key_text as $key => $value)
862 $selected = ($sort_key == $key) ? ' selected="selected"' : '';
863 $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
866 $s_sort_dir = '';
867 foreach ($sort_dir_text as $key => $value)
869 $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
870 $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
873 // Additional sorting options for user search ... if search is enabled, if not
874 // then only admins can make use of this (for ACP functionality)
875 $sql_select = $sql_from = $sql_where = $order_by = '';
877 $form = request_var('form', '');
878 $field = request_var('field', '');
880 if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
882 $username = request_var('username', '', true);
883 $email = strtolower(request_var('email', ''));
884 $icq = request_var('icq', '');
885 $aim = request_var('aim', '');
886 $yahoo = request_var('yahoo', '');
887 $msn = request_var('msn', '');
888 $jabber = request_var('jabber', '');
889 $search_group_id = request_var('search_group_id', 0);
891 $joined_select = request_var('joined_select', 'lt');
892 $active_select = request_var('active_select', 'lt');
893 $count_select = request_var('count_select', 'eq');
894 $joined = explode('-', request_var('joined', ''));
895 $active = explode('-', request_var('active', ''));
896 $count = (request_var('count', '') !== '') ? request_var('count', 0) : '';
897 $ipdomain = request_var('ip', '');
899 $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
901 $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
902 $s_find_count = '';
903 foreach ($find_count as $key => $value)
905 $selected = ($count_select == $key) ? ' selected="selected"' : '';
906 $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
909 $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
910 $s_find_join_time = '';
911 foreach ($find_time as $key => $value)
913 $selected = ($joined_select == $key) ? ' selected="selected"' : '';
914 $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
917 $s_find_active_time = '';
918 foreach ($find_time as $key => $value)
920 $selected = ($active_select == $key) ? ' selected="selected"' : '';
921 $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
924 $sql_where .= ($username) ? " AND u.username_clean LIKE '" . str_replace('*', '%', $db->sql_escape(utf8_clean_string($username))) . "'" : '';
925 $sql_where .= ($email) ? " AND u.user_email LIKE '" . str_replace('*', '%', $db->sql_escape($email)) . "' " : '';
926 $sql_where .= ($icq) ? " AND u.user_icq LIKE '" . str_replace('*', '%', $db->sql_escape($icq)) . "' " : '';
927 $sql_where .= ($aim) ? " AND u.user_aim LIKE '" . str_replace('*', '%', $db->sql_escape($aim)) . "' " : '';
928 $sql_where .= ($yahoo) ? " AND u.user_yim LIKE '" . str_replace('*', '%', $db->sql_escape($yahoo)) . "' " : '';
929 $sql_where .= ($msn) ? " AND u.user_msnm LIKE '" . str_replace('*', '%', $db->sql_escape($msn)) . "' " : '';
930 $sql_where .= ($jabber) ? " AND u.user_jabber LIKE '" . str_replace('*', '%', $db->sql_escape($jabber)) . "' " : '';
931 $sql_where .= (is_numeric($count)) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
932 $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])) : '';
933 $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])) : '';
934 $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id " : '';
936 if ($search_group_id)
938 $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
941 if ($ipdomain && $auth->acl_getf_global('m_info'))
943 if (preg_match('#[a-z]#', $ipdomain))
945 $hostnames = gethostbynamel($ipdomain);
947 if ($hostnames !== false)
949 $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)))) . "'";
951 else
953 $ips = false;
956 else
958 $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
961 if ($ips === false)
963 // A minor fudge but it does the job :D
964 $sql_where .= " AND u.user_id = 0";
966 else
968 $ip_forums = array_keys($auth->acl_getf('m_info', true));
970 $sql = 'SELECT DISTINCT poster_id
971 FROM ' . POSTS_TABLE . '
972 WHERE poster_ip ' . ((preg_match('#%#', $ips)) ? 'LIKE' : 'IN') . " ($ips)
973 AND forum_id IN (0, " . implode(', ', $ip_forums) . ')';
974 $result = $db->sql_query($sql);
976 if ($row = $db->sql_fetchrow($result))
978 $ip_sql = array();
981 $ip_sql[] = $row['poster_id'];
983 while ($row = $db->sql_fetchrow($result));
985 $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
987 else
989 // A minor fudge but it does the job :D
990 $sql_where .= " AND u.user_id = 0";
992 unset($ip_forums);
994 $db->sql_freeresult($result);
999 $first_char = request_var('first_char', '');
1001 if ($first_char == 'other')
1003 for ($i = 97; $i < 123; $i++)
1005 $sql_where .= " AND u.username_clean NOT LIKE '" . chr($i) . "%'";
1008 else if ($first_char)
1010 $sql_where .= " AND u.username_clean LIKE '" . $db->sql_escape(substr($first_char, 0, 1)) . "%'";
1013 // Are we looking at a usergroup? If so, fetch additional info
1014 // and further restrict the user info query
1015 if ($mode == 'group')
1017 // We JOIN here to save a query for determining membership for hidden groups. ;)
1018 $sql = 'SELECT g.*, ug.user_id
1019 FROM ' . GROUPS_TABLE . ' g
1020 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)
1021 WHERE g.group_id = $group_id";
1022 $result = $db->sql_query($sql);
1023 $group_row = $db->sql_fetchrow($result);
1024 $db->sql_freeresult($result);
1026 if (!$group_row)
1028 trigger_error('NO_GROUP');
1031 switch ($group_row['group_type'])
1033 case GROUP_OPEN:
1034 $group_row['l_group_type'] = 'OPEN';
1035 break;
1037 case GROUP_CLOSED:
1038 $group_row['l_group_type'] = 'CLOSED';
1039 break;
1041 case GROUP_HIDDEN:
1042 $group_row['l_group_type'] = 'HIDDEN';
1044 // Check for membership or special permissions
1045 if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
1047 trigger_error('NO_GROUP');
1049 break;
1051 case GROUP_SPECIAL:
1052 $group_row['l_group_type'] = 'SPECIAL';
1053 break;
1055 case GROUP_FREE:
1056 $group_row['l_group_type'] = 'FREE';
1057 break;
1060 $avatar_img = '';
1062 if ($group_row['group_avatar'])
1064 switch ($group_row['group_avatar_type'])
1066 case AVATAR_UPLOAD:
1067 $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
1068 break;
1070 case AVATAR_GALLERY:
1071 $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
1072 break;
1075 $avatar_img .= $group_row['group_avatar'];
1076 $avatar_img = '<img src="' . $avatar_img . '" width="' . $group_row['group_avatar_width'] . '" height="' . $group_row['group_avatar_height'] . '" alt="" />';
1079 $rank_title = $rank_img = $rank_img_src = '';
1080 if ($group_row['group_rank'])
1082 if (isset($ranks['special'][$group_row['group_rank']]))
1084 $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
1086 $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 />' : '';
1087 $rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : '';
1089 else
1091 $rank_title = '';
1092 $rank_img = '';
1093 $rank_img_src = '';
1096 $template->assign_vars(array(
1097 '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']),
1098 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
1099 'GROUP_COLOR' => $group_row['group_colour'],
1100 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
1101 'GROUP_RANK' => $rank_title,
1103 'AVATAR_IMG' => $avatar_img,
1104 'RANK_IMG' => $rank_img,
1105 'RANK_IMG_SRC' => $rank_img_src,
1107 'U_PM' => ($auth->acl_get('u_sendpm') && $auth->acl_get('u_masspm') && $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) : '',)
1110 $sql_select = ', ug.group_leader';
1111 $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
1112 $order_by = 'ug.group_leader DESC, ';
1114 $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
1117 // Sorting and order
1118 if (!isset($sort_key_sql[$sort_key]))
1120 $sort_key = $default_key;
1123 $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
1125 // Count the users ...
1126 if ($sql_where)
1128 $sql = 'SELECT COUNT(u.user_id) AS total_users
1129 FROM ' . USERS_TABLE . " u$sql_from
1130 WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1131 $sql_where";
1132 $result = $db->sql_query($sql);
1133 $total_users = (int) $db->sql_fetchfield('total_users');
1134 $db->sql_freeresult($result);
1136 else
1138 $total_users = $config['num_users'];
1141 $s_char_options = '<option value=""' . ((!$first_char) ? ' selected="selected"' : '') . '>&nbsp; &nbsp;</option>';
1142 for ($i = 97; $i < 123; $i++)
1144 $s_char_options .= '<option value="' . chr($i) . '"' . (($first_char == chr($i)) ? ' selected="selected"' : '') . '>' . chr($i-32) . '</option>';
1146 $s_char_options .= '<option value="other"' . (($first_char == 'other') ? ' selected="selected"' : '') . '>' . $user->lang['OTHER'] . '</option>';
1148 // Build a relevant pagination_url
1149 $params = array();
1150 foreach (array('_POST', '_GET') as $global_var)
1152 foreach ($$global_var as $key => $var)
1154 if ($global_var == '_POST')
1156 unset($_GET[$key]);
1159 if (in_array($key, array('submit', 'start', 'mode', 'char')) || empty($var))
1161 continue;
1164 $params[] = urlencode($key) . '=' . urlencode(htmlspecialchars($var));
1168 $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
1170 $params[] = "mode=$mode";
1171 $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
1173 // Some search user specific data
1174 if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
1176 $group_selected = request_var('search_group_id', 0);
1177 $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
1179 $sql = 'SELECT group_id, group_name, group_type
1180 FROM ' . GROUPS_TABLE . '
1181 WHERE group_type <> ' . GROUP_HIDDEN . '
1182 ORDER BY group_name ASC';
1183 $result = $db->sql_query($sql);
1185 while ($row = $db->sql_fetchrow($result))
1187 $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>';
1189 $db->sql_freeresult($result);
1191 $template->assign_vars(array(
1192 'USERNAME' => $username,
1193 'EMAIL' => $email,
1194 'ICQ' => $icq,
1195 'AIM' => $aim,
1196 'YAHOO' => $yahoo,
1197 'MSNM' => $msn,
1198 'JABBER' => $jabber,
1199 'JOINED' => implode('-', $joined),
1200 'ACTIVE' => implode('-', $active),
1201 'COUNT' => $count,
1202 'IP' => $ipdomain,
1204 'S_SEARCH_USER' => true,
1205 'S_FORM_NAME' => $form,
1206 'S_FIELD_NAME' => $field,
1207 'S_COUNT_OPTIONS' => $s_find_count,
1208 'S_SORT_OPTIONS' => $s_sort_key,
1209 'S_JOINED_TIME_OPTIONS' => $s_find_join_time,
1210 'S_ACTIVE_TIME_OPTIONS' => $s_find_active_time,
1211 'S_GROUP_SELECT' => $s_group_select,
1212 'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=$form&amp;field=$field"))
1216 $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
1217 FROM ' . SESSIONS_TABLE . '
1218 WHERE session_time >= ' . (time() - $config['session_length']) . '
1219 AND session_user_id <> ' . ANONYMOUS . '
1220 GROUP BY session_user_id';
1221 $result = $db->sql_query($sql);
1223 $session_times = array();
1224 while ($row = $db->sql_fetchrow($result))
1226 $session_times[$row['session_user_id']] = $row['session_time'];
1228 $db->sql_freeresult($result);
1230 // Do the SQL thang
1231 $sql = "SELECT u.*
1232 $sql_select
1233 FROM " . USERS_TABLE . " u
1234 $sql_from
1235 WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
1236 $sql_where
1237 ORDER BY $order_by";
1238 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1240 $id_cache = array();
1241 while ($row = $db->sql_fetchrow($result))
1243 $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : '';
1245 $id_cache[$row['user_id']] = $row;
1247 $db->sql_freeresult($result);
1249 // Load custom profile fields
1250 if ($config['load_cpf_memberlist'])
1252 include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1253 $cp = new custom_profile();
1255 // Grab all profile fields from users in id cache for later use - similar to the poster cache
1256 $profile_fields_cache = $cp->generate_profile_fields_template('grab', array_keys($id_cache));
1259 $i = 0;
1260 foreach ($id_cache as $user_id => $row)
1262 $cp_row = array();
1263 if ($config['load_cpf_memberlist'])
1265 $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields_cache[$user_id]) : array();
1268 $memberrow = array_merge(show_profile($row), array(
1269 'ROW_NUMBER' => $i + ($start + 1),
1271 'S_CUSTOM_PROFILE' => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
1272 'S_GROUP_LEADER' => (isset($row['group_leader']) && $row['group_leader']) ? true : false,
1274 'U_VIEW_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id))
1277 if (isset($cp_row['row']) && sizeof($cp_row['row']))
1279 $memberrow = array_merge($memberrow, $cp_row['row']);
1282 $template->assign_block_vars('memberrow', $memberrow);
1284 if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
1286 foreach ($cp_row['blockrow'] as $field_data)
1288 $template->assign_block_vars('memberrow.custom_fields', $field_data);
1292 $i++;
1293 unset($id_cache[$user_id]);
1296 // Generate page
1297 $template->assign_vars(array(
1298 'PAGINATION' => generate_pagination($pagination_url, $total_users, $config['topics_per_page'], $start),
1299 'PAGE_NUMBER' => on_page($total_users, $config['topics_per_page'], $start),
1300 'TOTAL_USERS' => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users),
1302 'PROFILE_IMG' => $user->img('icon_user_profile', $user->lang['PROFILE']),
1303 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
1304 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
1305 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
1306 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
1307 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
1308 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
1309 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
1310 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
1311 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
1313 'U_FIND_MEMBER' => ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser') : '',
1314 'U_HIDE_FIND_MEMBER' => ($mode == 'searchuser') ? $u_hide_find_member : '',
1315 'U_SORT_USERNAME' => $pagination_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
1316 'U_SORT_FROM' => $pagination_url . '&amp;sk=b&amp;sd=' . (($sort_key == 'b' && $sort_dir == 'a') ? 'd' : 'a'),
1317 'U_SORT_JOINED' => $pagination_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
1318 'U_SORT_POSTS' => $pagination_url . '&amp;sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
1319 'U_SORT_EMAIL' => $pagination_url . '&amp;sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
1320 'U_SORT_WEBSITE' => $pagination_url . '&amp;sk=f&amp;sd=' . (($sort_key == 'f' && $sort_dir == 'a') ? 'd' : 'a'),
1321 'U_SORT_LOCATION' => $pagination_url . '&amp;sk=n&amp;sd=' . (($sort_key == 'n' && $sort_dir == 'a') ? 'd' : 'a'),
1322 'U_SORT_ICQ' => $pagination_url . '&amp;sk=g&amp;sd=' . (($sort_key == 'g' && $sort_dir == 'a') ? 'd' : 'a'),
1323 'U_SORT_AIM' => $pagination_url . '&amp;sk=h&amp;sd=' . (($sort_key == 'h' && $sort_dir == 'a') ? 'd' : 'a'),
1324 'U_SORT_MSN' => $pagination_url . '&amp;sk=i&amp;sd=' . (($sort_key == 'i' && $sort_dir == 'a') ? 'd' : 'a'),
1325 'U_SORT_YIM' => $pagination_url . '&amp;sk=j&amp;sd=' . (($sort_key == 'j' && $sort_dir == 'a') ? 'd' : 'a'),
1326 'U_SORT_ACTIVE' => $pagination_url . '&amp;sk=k&amp;sd=' . (($sort_key == 'k' && $sort_dir == 'a') ? 'd' : 'a'),
1327 'U_SORT_RANK' => $pagination_url . '&amp;sk=m&amp;sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
1328 'U_LIST_CHAR' => $pagination_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
1330 'S_SHOW_GROUP' => ($mode == 'group') ? true : false,
1331 'S_MODE_SELECT' => $s_sort_key,
1332 'S_ORDER_SELECT' => $s_sort_dir,
1333 'S_CHAR_OPTIONS' => $s_char_options,
1334 'S_MODE_ACTION' => $pagination_url . "&amp;form=$form")
1338 // Output the page
1339 page_header($page_title);
1341 $template->set_filenames(array(
1342 'body' => $template_html)
1344 make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
1346 page_footer();
1349 * Get user rank title and image
1351 function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
1353 global $ranks, $config;
1355 if (!empty($user_rank))
1357 $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
1358 $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'] . '" />' : '';
1359 $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
1361 else
1363 if (isset($ranks['normal']))
1365 foreach ($ranks['normal'] as $rank)
1367 if ($user_posts >= $rank['rank_min'])
1369 $rank_title = $rank['rank_title'];
1370 $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
1371 $rank_img_src = (!empty($rank['rank_image'])) ? $config['ranks_path'] . '/' . $rank['rank_image'] : '';
1372 break;
1380 * Prepare profile data
1382 function show_profile($data)
1384 global $config, $auth, $template, $user, $phpEx, $phpbb_root_path;
1386 $username = $data['username'];
1387 $user_id = $data['user_id'];
1389 $rank_title = $rank_img = $rank_img_src = '';
1390 get_user_rank($data['user_rank'], $data['user_posts'], $rank_title, $rank_img, $rank_img_src);
1392 if (!empty($data['user_allow_viewemail']) || $auth->acl_get('a_email'))
1394 $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_email')) ? '' : 'mailto:' . $data['user_email']);
1396 else
1398 $email = '';
1401 if ($config['load_onlinetrack'])
1403 $update_time = $config['load_online_time'] * 60;
1404 $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['user_allow_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
1406 else
1408 $online = false;
1411 if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))
1413 $last_visit = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit'];
1415 else
1417 $last_visit = '';
1420 $age = '';
1422 if ($data['user_birthday'])
1424 list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));
1426 if ($bday_year)
1428 $now = getdate(time() + $user->timezone + $user->dst - (date('H', time()) - gmdate('H', time())) * 3600);
1430 $diff = $now['mon'] - $bday_month;
1431 if ($diff == 0)
1433 $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
1435 else
1437 $diff = ($diff < 0) ? 1 : 0;
1440 $age = (int) ($now['year'] - $bday_year - $diff);
1444 // Dump it out to the template
1445 return array(
1446 'AGE' => $age,
1447 'USERNAME' => $username,
1448 'USER_COLOR' => (!empty($data['user_colour'])) ? $data['user_colour'] : '',
1449 'RANK_TITLE' => $rank_title,
1450 'JOINED' => $user->format_date($data['user_regdate']),
1451 'VISITED' => (empty($last_visit)) ? ' - ' : $user->format_date($last_visit),
1452 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0,
1453 'WARNINGS' => isset($data['user_warnings']) ? $data['user_warnings'] : 0,
1455 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')),
1456 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false,
1457 'RANK_IMG' => $rank_img,
1458 'RANK_IMG_SRC' => $rank_img_src,
1459 '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" />' : '',
1460 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false,
1462 'U_PROFILE' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id),
1463 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&amp;sr=posts") : '',
1464 'U_NOTES' => $auth->acl_getf_global('m_') ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $user_id, true, $user->session_id) : '',
1465 'U_WARN' => $auth->acl_getf_global('m_warn') ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $user_id, true, $user->session_id) : '',
1466 '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) : '',
1467 'U_EMAIL' => $email,
1468 'U_WWW' => (!empty($data['user_website'])) ? $data['user_website'] : '',
1469 'U_ICQ' => ($data['user_icq']) ? 'http://www.icq.com/people/webmsg.php?to=' . $data['user_icq'] : '',
1470 'U_AIM' => ($data['user_aim']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=aim&amp;u=' . $user_id) : '',
1471 'U_YIM' => ($data['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . $data['user_yim'] . '&amp;.src=pg' : '',
1472 'U_MSN' => ($data['user_msnm']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=msnm&amp;u=' . $user_id) : '',
1473 'U_JABBER' => ($data['user_jabber']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&amp;action=jabber&amp;u=' . $user_id) : '',
1474 'LOCATION' => ($data['user_from']) ? $data['user_from'] : '',
1476 'L_VIEWING_PROFILE' => sprintf($user->lang['VIEWING_PROFILE'], $username),