Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

memberlist.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 49.00 KiB


 0001  <?php
 0002  /**
 0003  *
 0004  * This file is part of the phpBB Forum Software package.
 0005  *
 0006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 0007  * @license GNU General Public License, version 2 (GPL-2.0)
 0008  *
 0009  * For full copyright and license information, please see
 0010  * the docs/CREDITS.txt file.
 0011  *
 0012  */
 0013   
 0014  /**
 0015  * @ignore
 0016  */
 0017  define('IN_PHPBB', true);
 0018  $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 0019  $phpEx = substr(strrchr(__FILE__, '.'), 1);
 0020  include($phpbb_root_path . 'common.' . $phpEx);
 0021  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 0022   
 0023  $mode = request_var('mode', '');
 0024   
 0025  if ($mode === 'contactadmin')
 0026  {
 0027      define('SKIP_CHECK_BAN', true);
 0028      define('SKIP_CHECK_DISABLED', true);
 0029  }
 0030   
 0031  // Start session management
 0032  $user->session_begin();
 0033  $auth->acl($user->data);
 0034  $user->setup(array('memberlist', 'groups'));
 0035   
 0036  // Setting a variable to let the style designer know where he is...
 0037  $template->assign_var('S_IN_MEMBERLIST', true);
 0038   
 0039  // Grab data
 0040  $action        = request_var('action', '');
 0041  $user_id    = request_var('u', ANONYMOUS);
 0042  $username    = request_var('un', '', true);
 0043  $group_id    = request_var('g', 0);
 0044  $topic_id    = request_var('t', 0);
 0045   
 0046  // Redirect when old mode is used
 0047  if ($mode == 'leaders')
 0048  {
 0049      send_status_line(301, 'Moved Permanently');
 0050      redirect(append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=team'));
 0051  }
 0052   
 0053  // Check our mode...
 0054  if (!in_array($mode, array('', 'group', 'viewprofile', 'email', 'contact', 'contactadmin', 'searchuser', 'team', 'livesearch')))
 0055  {
 0056      trigger_error('NO_MODE');
 0057  }
 0058   
 0059  switch ($mode)
 0060  {
 0061      case 'email':
 0062      case 'contactadmin':
 0063      break;
 0064   
 0065      case 'livesearch':
 0066          if (!$config['allow_live_searches'])
 0067          {
 0068              trigger_error('LIVE_SEARCHES_NOT_ALLOWED');
 0069          }
 0070          // No break
 0071   
 0072      default:
 0073          // Can this user view profiles/memberlist?
 0074          if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
 0075          {
 0076              if ($user->data['user_id'] != ANONYMOUS)
 0077              {
 0078                  trigger_error('NO_VIEW_USERS');
 0079              }
 0080   
 0081              login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_MEMBERLIST']));
 0082          }
 0083      break;
 0084  }
 0085   
 0086  $start    = request_var('start', 0);
 0087  $submit = (isset($_POST['submit'])) ? true : false;
 0088   
 0089  $default_key = 'c';
 0090  $sort_key = request_var('sk', $default_key);
 0091  $sort_dir = request_var('sd', 'a');
 0092   
 0093  // What do you want to do today? ... oops, I think that line is taken ...
 0094  switch ($mode)
 0095  {
 0096      case 'team':
 0097          // Display a listing of board admins, moderators
 0098          include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 0099   
 0100          $page_title = $user->lang['THE_TEAM'];
 0101          $template_html = 'memberlist_team.html';
 0102   
 0103          $sql = 'SELECT *
 0104              FROM ' . TEAMPAGE_TABLE . '
 0105              ORDER BY teampage_position ASC';
 0106          $result = $db->sql_query($sql, 3600);
 0107          $teampage_data = $db->sql_fetchrowset($result);
 0108          $db->sql_freeresult($result);
 0109   
 0110          $sql_ary = array(
 0111              'SELECT'    => 'g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id, t.teampage_id',
 0112   
 0113              'FROM'        => array(GROUPS_TABLE => 'g'),
 0114   
 0115              'LEFT_JOIN'    => array(
 0116                  array(
 0117                      'FROM'    => array(TEAMPAGE_TABLE => 't'),
 0118                      'ON'    => 't.group_id = g.group_id',
 0119                  ),
 0120                  array(
 0121                      'FROM'    => array(USER_GROUP_TABLE => 'ug'),
 0122                      'ON'    => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . (int) $user->data['user_id'],
 0123                  ),
 0124              ),
 0125          );
 0126   
 0127          $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
 0128   
 0129          $group_ids = $groups_ary = array();
 0130          while ($row = $db->sql_fetchrow($result))
 0131          {
 0132              if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id'])
 0133              {
 0134                  $row['group_name'] = $user->lang['GROUP_UNDISCLOSED'];
 0135                  $row['u_group'] = '';
 0136              }
 0137              else
 0138              {
 0139                  $row['group_name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
 0140                  $row['u_group'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']);
 0141              }
 0142   
 0143              if ($row['teampage_id'])
 0144              {
 0145                  // Only put groups into the array we want to display.
 0146                  // We are fetching all groups, to ensure we got all data for default groups.
 0147                  $group_ids[] = (int) $row['group_id'];
 0148              }
 0149              $groups_ary[(int) $row['group_id']] = $row;
 0150          }
 0151          $db->sql_freeresult($result);
 0152   
 0153          $sql_ary = array(
 0154              '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',
 0155   
 0156              'FROM'        => array(
 0157                  USER_GROUP_TABLE => 'ug',
 0158              ),
 0159   
 0160              'LEFT_JOIN'    => array(
 0161                  array(
 0162                      'FROM'    => array(USERS_TABLE => 'u'),
 0163                      'ON'    => 'ug.user_id = u.user_id AND ug.user_pending = 0',
 0164                  ),
 0165                  array(
 0166                      'FROM'    => array(GROUPS_TABLE => 'g'),
 0167                      'ON'    => 'ug.group_id = g.group_id',
 0168                  ),
 0169              ),
 0170   
 0171              'WHERE'        => $db->sql_in_set('g.group_id', $group_ids, false, true),
 0172   
 0173              'ORDER_BY'    => 'u.username_clean ASC',
 0174          );
 0175   
 0176          $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
 0177   
 0178          $user_ary = $user_ids = $group_users = array();
 0179          while ($row = $db->sql_fetchrow($result))
 0180          {
 0181              $row['forums'] = '';
 0182              $row['forums_ary'] = array();
 0183              $user_ary[(int) $row['user_id']] = $row;
 0184              $user_ids[] = (int) $row['user_id'];
 0185              $group_users[(int) $row['group_id']][] = (int) $row['user_id'];
 0186          }
 0187          $db->sql_freeresult($result);
 0188   
 0189          $user_ids = array_unique($user_ids);
 0190   
 0191          if (!empty($user_ids) && $config['teampage_forums'])
 0192          {
 0193              $template->assign_var('S_DISPLAY_MODERATOR_FORUMS', true);
 0194              // Get all moderators
 0195              $perm_ary = $auth->acl_get_list($user_ids, array('m_'), false);
 0196   
 0197              foreach ($perm_ary as $forum_id => $forum_ary)
 0198              {
 0199                  foreach ($forum_ary as $auth_option => $id_ary)
 0200                  {
 0201                      foreach ($id_ary as $id)
 0202                      {
 0203                          if (!$forum_id)
 0204                          {
 0205                              $user_ary[$id]['forums'] = $user->lang['ALL_FORUMS'];
 0206                          }
 0207                          else
 0208                          {
 0209                              $user_ary[$id]['forums_ary'][] = $forum_id;
 0210                          }
 0211                      }
 0212                  }
 0213              }
 0214   
 0215              $sql = 'SELECT forum_id, forum_name
 0216                  FROM ' . FORUMS_TABLE;
 0217              $result = $db->sql_query($sql);
 0218   
 0219              $forums = array();
 0220              while ($row = $db->sql_fetchrow($result))
 0221              {
 0222                  $forums[$row['forum_id']] = $row['forum_name'];
 0223              }
 0224              $db->sql_freeresult($result);
 0225   
 0226              foreach ($user_ary as $user_id => $user_data)
 0227              {
 0228                  if (!$user_data['forums'])
 0229                  {
 0230                      foreach ($user_data['forums_ary'] as $forum_id)
 0231                      {
 0232                          $user_ary[$user_id]['forums_options'] = true;
 0233                          if (isset($forums[$forum_id]))
 0234                          {
 0235                              if ($auth->acl_get('f_list', $forum_id))
 0236                              {
 0237                                  $user_ary[$user_id]['forums'] .= '<option value="">' . $forums[$forum_id] . '</option>';
 0238                              }
 0239                          }
 0240                      }
 0241                  }
 0242              }
 0243          }
 0244   
 0245          $parent_team = 0;
 0246          foreach ($teampage_data as $team_data)
 0247          {
 0248              // If this team entry has no group, it's a category
 0249              if (!$team_data['group_id'])
 0250              {
 0251                  $template->assign_block_vars('group', array(
 0252                      'GROUP_NAME'  => $team_data['teampage_name'],
 0253                  ));
 0254   
 0255                  $parent_team = (int) $team_data['teampage_id'];
 0256                  continue;
 0257              }
 0258   
 0259              $group_data = $groups_ary[(int) $team_data['group_id']];
 0260              $group_id = (int) $team_data['group_id'];
 0261   
 0262              if (!$team_data['teampage_parent'])
 0263              {
 0264                  // If the group does not have a parent category, we display the groupname as category
 0265                  $template->assign_block_vars('group', array(
 0266                      'GROUP_NAME'    => $group_data['group_name'],
 0267                      'GROUP_COLOR'    => $group_data['group_colour'],
 0268                      'U_GROUP'        => $group_data['u_group'],
 0269                  ));
 0270              }
 0271   
 0272              // Display group members.
 0273              if (!empty($group_users[$group_id]))
 0274              {
 0275                  foreach ($group_users[$group_id] as $user_id)
 0276                  {
 0277                      if (isset($user_ary[$user_id]))
 0278                      {
 0279                          $row = $user_ary[$user_id];
 0280                          if ($config['teampage_memberships'] == 1 && ($group_id != $groups_ary[$row['default_group']]['group_id']) && $groups_ary[$row['default_group']]['teampage_id'])
 0281                          {
 0282                              // Display users in their primary group, instead of the first group, when it is displayed on the teampage.
 0283                              continue;
 0284                          }
 0285   
 0286                          $user_rank_data = phpbb_get_user_rank($row, (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']));
 0287   
 0288                          $template->assign_block_vars('group.user', array(
 0289                              'USER_ID'        => $row['user_id'],
 0290                              'FORUMS'        => $row['forums'],
 0291                              'FORUM_OPTIONS'    => (isset($row['forums_options'])) ? true : false,
 0292                              'RANK_TITLE'    => $user_rank_data['title'],
 0293   
 0294                              'GROUP_NAME'    => $groups_ary[$row['default_group']]['group_name'],
 0295                              'GROUP_COLOR'    => $groups_ary[$row['default_group']]['group_colour'],
 0296                              'U_GROUP'        => $groups_ary[$row['default_group']]['u_group'],
 0297   
 0298                              'RANK_IMG'        => $user_rank_data['img'],
 0299                              'RANK_IMG_SRC'    => $user_rank_data['img_src'],
 0300   
 0301                              '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']) : '',
 0302   
 0303                              'USERNAME_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
 0304                              'USERNAME'            => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
 0305                              'USER_COLOR'        => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
 0306                              'U_VIEW_PROFILE'    => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
 0307                          ));
 0308   
 0309                          if ($config['teampage_memberships'] != 2)
 0310                          {
 0311                              unset($user_ary[$user_id]);
 0312                          }
 0313                      }
 0314                  }
 0315              }
 0316          }
 0317   
 0318          $template->assign_vars(array(
 0319              'PM_IMG'        => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']))
 0320          );
 0321      break;
 0322   
 0323      case 'contact':
 0324   
 0325          $page_title = $user->lang['IM_USER'];
 0326          $template_html = 'memberlist_im.html';
 0327   
 0328          if (!$auth->acl_get('u_sendim'))
 0329          {
 0330              trigger_error('NOT_AUTHORISED');
 0331          }
 0332   
 0333          $presence_img = '';
 0334          switch ($action)
 0335          {
 0336              case 'jabber':
 0337                  $lang = 'JABBER';
 0338                  $sql_field = 'user_jabber';
 0339                  $s_select = (@extension_loaded('xml') && $config['jab_enable']) ? 'S_SEND_JABBER' : 'S_NO_SEND_JABBER';
 0340                  $s_action = append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=contact&amp;action=$action&amp;u=$user_id");
 0341              break;
 0342   
 0343              default:
 0344                  trigger_error('NO_MODE', E_USER_ERROR);
 0345              break;
 0346          }
 0347   
 0348          // Grab relevant data
 0349          $sql = "SELECT user_id, username, user_email, user_lang, $sql_field
 0350              FROM " . USERS_TABLE . "
 0351              WHERE user_id = $user_id
 0352                  AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
 0353          $result = $db->sql_query($sql);
 0354          $row = $db->sql_fetchrow($result);
 0355          $db->sql_freeresult($result);
 0356   
 0357          if (!$row)
 0358          {
 0359              trigger_error('NO_USER');
 0360          }
 0361          else if (empty($row[$sql_field]))
 0362          {
 0363              trigger_error('IM_NO_DATA');
 0364          }
 0365   
 0366          // Post data grab actions
 0367          switch ($action)
 0368          {
 0369              case 'jabber':
 0370                  add_form_key('memberlist_messaging');
 0371   
 0372                  if ($submit && @extension_loaded('xml') && $config['jab_enable'])
 0373                  {
 0374                      if (check_form_key('memberlist_messaging'))
 0375                      {
 0376   
 0377                          include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 0378   
 0379                          $subject = sprintf($user->lang['IM_JABBER_SUBJECT'], $user->data['username'], $config['server_name']);
 0380                          $message = utf8_normalize_nfc(request_var('message', '', true));
 0381   
 0382                          if (empty($message))
 0383                          {
 0384                              trigger_error('EMPTY_MESSAGE_IM');
 0385                          }
 0386   
 0387                          $messenger = new messenger(false);
 0388   
 0389                          $messenger->template('profile_send_im', $row['user_lang']);
 0390                          $messenger->subject(htmlspecialchars_decode($subject));
 0391   
 0392                          $messenger->replyto($user->data['user_email']);
 0393                          $messenger->set_addresses($row);
 0394   
 0395                          $messenger->assign_vars(array(
 0396                              'BOARD_CONTACT'    => phpbb_get_board_contact($config, $phpEx),
 0397                              'FROM_USERNAME'    => htmlspecialchars_decode($user->data['username']),
 0398                              'TO_USERNAME'    => htmlspecialchars_decode($row['username']),
 0399                              'MESSAGE'        => htmlspecialchars_decode($message))
 0400                          );
 0401   
 0402                          $messenger->send(NOTIFY_IM);
 0403   
 0404                          $s_select = 'S_SENT_JABBER';
 0405                      }
 0406                      else
 0407                      {
 0408                          trigger_error('FORM_INVALID');
 0409                      }
 0410                  }
 0411              break;
 0412          }
 0413   
 0414          // Send vars to the template
 0415          $template->assign_vars(array(
 0416              'IM_CONTACT'    => $row[$sql_field],
 0417              'A_IM_CONTACT'    => addslashes($row[$sql_field]),
 0418   
 0419              'USERNAME'        => $row['username'],
 0420              'CONTACT_NAME'    => $row[$sql_field],
 0421              'SITENAME'        => $config['sitename'],
 0422   
 0423              'PRESENCE_IMG'        => $presence_img,
 0424   
 0425              'L_SEND_IM_EXPLAIN'    => $user->lang['IM_' . $lang],
 0426              'L_IM_SENT_JABBER'    => sprintf($user->lang['IM_SENT_JABBER'], $row['username']),
 0427   
 0428              $s_select            => true,
 0429              'S_IM_ACTION'        => $s_action)
 0430          );
 0431   
 0432      break;
 0433   
 0434      case 'viewprofile':
 0435          // Display a profile
 0436          if ($user_id == ANONYMOUS && !$username)
 0437          {
 0438              trigger_error('NO_USER');
 0439          }
 0440   
 0441          // Get user...
 0442          $sql = 'SELECT *
 0443              FROM ' . USERS_TABLE . '
 0444              WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
 0445          $result = $db->sql_query($sql);
 0446          $member = $db->sql_fetchrow($result);
 0447          $db->sql_freeresult($result);
 0448   
 0449          if (!$member)
 0450          {
 0451              trigger_error('NO_USER');
 0452          }
 0453   
 0454          // a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
 0455          // Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
 0456          if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER)
 0457          {
 0458              if ($member['user_type'] == USER_IGNORE)
 0459              {
 0460                  trigger_error('NO_USER');
 0461              }
 0462              else if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE)
 0463              {
 0464                  trigger_error('NO_USER');
 0465              }
 0466          }
 0467   
 0468          $user_id = (int) $member['user_id'];
 0469   
 0470          // Get group memberships
 0471          // Also get visiting user's groups to determine hidden group memberships if necessary.
 0472          $auth_hidden_groups = ($user_id === (int) $user->data['user_id'] || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false;
 0473          $sql_uid_ary = ($auth_hidden_groups) ? array($user_id) : array($user_id, (int) $user->data['user_id']);
 0474   
 0475          // Do the SQL thang
 0476          $sql = 'SELECT g.group_id, g.group_name, g.group_type, ug.user_id
 0477              FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
 0478              WHERE ' . $db->sql_in_set('ug.user_id', $sql_uid_ary) . '
 0479                  AND g.group_id = ug.group_id
 0480                  AND ug.user_pending = 0';
 0481          $result = $db->sql_query($sql);
 0482   
 0483          // Divide data into profile data and current user data
 0484          $profile_groups = $user_groups = array();
 0485          while ($row = $db->sql_fetchrow($result))
 0486          {
 0487              $row['user_id'] = (int) $row['user_id'];
 0488              $row['group_id'] = (int) $row['group_id'];
 0489   
 0490              if ($row['user_id'] == $user_id)
 0491              {
 0492                  $profile_groups[] = $row;
 0493              }
 0494              else
 0495              {
 0496                  $user_groups[$row['group_id']] = $row['group_id'];
 0497              }
 0498          }
 0499          $db->sql_freeresult($result);
 0500   
 0501          // Filter out hidden groups and sort groups by name
 0502          $group_data = $group_sort = array();
 0503          foreach ($profile_groups as $row)
 0504          {
 0505              if ($row['group_type'] == GROUP_SPECIAL)
 0506              {
 0507                  // Lookup group name in language dictionary
 0508                  if (isset($user->lang['G_' . $row['group_name']]))
 0509                  {
 0510                      $row['group_name'] = $user->lang['G_' . $row['group_name']];
 0511                  }
 0512              }
 0513              else if (!$auth_hidden_groups && $row['group_type'] == GROUP_HIDDEN && !isset($user_groups[$row['group_id']]))
 0514              {
 0515                  // Skip over hidden groups the user cannot see
 0516                  continue;
 0517              }
 0518   
 0519              $group_sort[$row['group_id']] = utf8_clean_string($row['group_name']);
 0520              $group_data[$row['group_id']] = $row;
 0521          }
 0522          unset($profile_groups);
 0523          unset($user_groups);
 0524          asort($group_sort);
 0525   
 0526          $group_options = '';
 0527          foreach ($group_sort as $group_id => $null)
 0528          {
 0529              $row = $group_data[$group_id];
 0530   
 0531              $group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . $row['group_name'] . '</option>';
 0532          }
 0533          unset($group_data);
 0534          unset($group_sort);
 0535   
 0536          // What colour is the zebra
 0537          $sql = 'SELECT friend, foe
 0538              FROM ' . ZEBRA_TABLE . "
 0539              WHERE zebra_id = $user_id
 0540                  AND user_id = {$user->data['user_id']}";
 0541   
 0542          $result = $db->sql_query($sql);
 0543          $row = $db->sql_fetchrow($result);
 0544          $foe = ($row['foe']) ? true : false;
 0545          $friend = ($row['friend']) ? true : false;
 0546          $db->sql_freeresult($result);
 0547   
 0548          if ($config['load_onlinetrack'])
 0549          {
 0550              $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
 0551                  FROM ' . SESSIONS_TABLE . "
 0552                  WHERE session_user_id = $user_id";
 0553              $result = $db->sql_query($sql);
 0554              $row = $db->sql_fetchrow($result);
 0555              $db->sql_freeresult($result);
 0556   
 0557              $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
 0558              $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] :    0;
 0559              unset($row);
 0560          }
 0561   
 0562          if ($config['load_user_activity'])
 0563          {
 0564              display_user_activity($member);
 0565          }
 0566   
 0567          // Do the relevant calculations
 0568          $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
 0569          $posts_per_day = $member['user_posts'] / $memberdays;
 0570          $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
 0571   
 0572   
 0573          if ($member['user_sig'])
 0574          {
 0575              $parse_flags = ($member['user_sig_bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
 0576              $member['user_sig'] = generate_text_for_display($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield'], $parse_flags, true);
 0577          }
 0578   
 0579          // We need to check if the modules 'zebra' ('friends' & 'foes' mode),  'notes' ('user_notes' mode) and  'warn' ('warn_user' mode) are accessible to decide if we can display appropriate links
 0580          $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false;
 0581   
 0582          // Only check if the user is logged in
 0583          if ($user->data['is_registered'])
 0584          {
 0585              if (!class_exists('p_master'))
 0586              {
 0587                  include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
 0588              }
 0589              $module = new p_master();
 0590   
 0591              $module->list_modules('ucp');
 0592              $module->list_modules('mcp');
 0593   
 0594              $user_notes_enabled = ($module->loaded('mcp_notes', 'user_notes')) ? true : false;
 0595              $warn_user_enabled = ($module->loaded('mcp_warn', 'warn_user')) ? true : false;
 0596              $zebra_enabled = ($module->loaded('ucp_zebra')) ? true : false;
 0597              $friends_enabled = ($module->loaded('ucp_zebra', 'friends')) ? true : false;
 0598              $foes_enabled = ($module->loaded('ucp_zebra', 'foes')) ? true : false;
 0599   
 0600              unset($module);
 0601          }
 0602   
 0603          // Custom Profile Fields
 0604          $profile_fields = array();
 0605          if ($config['load_cpf_viewprofile'])
 0606          {
 0607              $cp = $phpbb_container->get('profilefields.manager');
 0608              $profile_fields = $cp->grab_profile_fields_data($user_id);
 0609              $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields[$user_id]) : array();
 0610          }
 0611   
 0612          /**
 0613          * Modify user data before we display the profile
 0614          *
 0615          * @event core.memberlist_view_profile
 0616          * @var    array    member                    Array with user's data
 0617          * @var    bool    user_notes_enabled        Is the mcp user notes module enabled?
 0618          * @var    bool    warn_user_enabled        Is the mcp warnings module enabled?
 0619          * @var    bool    zebra_enabled            Is the ucp zebra module enabled?
 0620          * @var    bool    friends_enabled            Is the ucp friends module enabled?
 0621          * @var    bool    foes_enabled            Is the ucp foes module enabled?
 0622          * @var    bool    friend                    Is the user friend?
 0623          * @var    bool    foe                        Is the user foe?
 0624          * @var    array    profile_fields            Array with user's profile field data
 0625          * @since 3.1.0-a1
 0626          * @changed 3.1.0-b2 Added friend and foe status
 0627          * @changed 3.1.0-b3 Added profile fields data
 0628          */
 0629          $vars = array(
 0630              'member',
 0631              'user_notes_enabled',
 0632              'warn_user_enabled',
 0633              'zebra_enabled',
 0634              'friends_enabled',
 0635              'foes_enabled',
 0636              'friend',
 0637              'foe',
 0638              'profile_fields',
 0639          );
 0640          extract($phpbb_dispatcher->trigger_event('core.memberlist_view_profile', compact($vars)));
 0641   
 0642          $template->assign_vars(phpbb_show_profile($member, $user_notes_enabled, $warn_user_enabled));
 0643   
 0644          // If the user has m_approve permission or a_user permission, then list then display unapproved posts
 0645          if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
 0646          {
 0647              $sql = 'SELECT COUNT(post_id) as posts_in_queue
 0648                  FROM ' . POSTS_TABLE . '
 0649                  WHERE poster_id = ' . $user_id . '
 0650                      AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
 0651              $result = $db->sql_query($sql);
 0652              $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
 0653              $db->sql_freeresult($result);
 0654          }
 0655          else
 0656          {
 0657              $member['posts_in_queue'] = 0;
 0658          }
 0659   
 0660          $template->assign_vars(array(
 0661              'L_POSTS_IN_QUEUE'    => $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
 0662   
 0663              'POSTS_DAY'            => $user->lang('POST_DAY', $posts_per_day),
 0664              'POSTS_PCT'            => $user->lang('POST_PCT', $percentage),
 0665   
 0666              'SIGNATURE'        => $member['user_sig'],
 0667              'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
 0668   
 0669              'PM_IMG'        => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
 0670              'L_SEND_EMAIL_USER'    => $user->lang('SEND_EMAIL_USER', $member['username']),
 0671              'EMAIL_IMG'        => $user->img('icon_contact_email', $user->lang['EMAIL']),
 0672              'JABBER_IMG'    => $user->img('icon_contact_jabber', $user->lang['JABBER']),
 0673              'SEARCH_IMG'    => $user->img('icon_user_search', $user->lang['SEARCH']),
 0674   
 0675              'S_PROFILE_ACTION'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
 0676              'S_GROUP_OPTIONS'    => $group_options,
 0677              'S_CUSTOM_FIELDS'    => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
 0678   
 0679              'U_USER_ADMIN'            => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview&amp;u=' . $user_id, true, $user->session_id) : '',
 0680              'U_USER_BAN'            => ($auth->acl_get('m_ban') && $user_id != $user->data['user_id']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=ban&amp;mode=user&amp;u=' . $user_id, true, $user->session_id) : '',
 0681              'U_MCP_QUEUE'            => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
 0682   
 0683              'U_SWITCH_PERMISSIONS'    => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_id}&amp;hash=" . generate_link_hash('switchperm')) : '',
 0684              'U_EDIT_SELF'            => ($user_id == $user->data['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=ucp_profile&amp;mode=profile_info') : '',
 0685   
 0686              'S_USER_NOTES'        => ($user_notes_enabled) ? true : false,
 0687              'S_WARN_USER'        => ($warn_user_enabled) ? true : false,
 0688              'S_ZEBRA'            => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
 0689              'U_ADD_FRIEND'        => (!$friend && !$foe && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
 0690              'U_ADD_FOE'            => (!$friend && !$foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;mode=foes&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
 0691              'U_REMOVE_FRIEND'    => ($friend && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
 0692              'U_REMOVE_FOE'        => ($foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;mode=foes&amp;usernames[]=' . $user_id) : '',
 0693   
 0694              'U_CANONICAL'    => generate_board_url() . '/' . append_sid("memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_id, true, ''),
 0695          ));
 0696   
 0697          if (!empty($profile_fields['row']))
 0698          {
 0699              $template->assign_vars($profile_fields['row']);
 0700          }
 0701   
 0702          if (!empty($profile_fields['blockrow']))
 0703          {
 0704              foreach ($profile_fields['blockrow'] as $field_data)
 0705              {
 0706                  $template->assign_block_vars('custom_fields', $field_data);
 0707              }
 0708          }
 0709   
 0710          // Inactive reason/account?
 0711          if ($member['user_type'] == USER_INACTIVE)
 0712          {
 0713              $user->add_lang('acp/common');
 0714   
 0715              $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
 0716   
 0717              switch ($member['user_inactive_reason'])
 0718              {
 0719                  case INACTIVE_REGISTER:
 0720                      $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
 0721                  break;
 0722   
 0723                  case INACTIVE_PROFILE:
 0724                      $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
 0725                  break;
 0726   
 0727                  case INACTIVE_MANUAL:
 0728                      $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
 0729                  break;
 0730   
 0731                  case INACTIVE_REMIND:
 0732                      $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
 0733                  break;
 0734              }
 0735   
 0736              $template->assign_vars(array(
 0737                  'S_USER_INACTIVE'        => true,
 0738                  'USER_INACTIVE_REASON'    => $inactive_reason)
 0739              );
 0740          }
 0741   
 0742          // Now generate page title
 0743          $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
 0744          $template_html = 'memberlist_view.html';
 0745   
 0746      break;
 0747   
 0748      case 'contactadmin':
 0749      case 'email':
 0750          if (!class_exists('messenger'))
 0751          {
 0752              include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 0753          }
 0754   
 0755          $user_id    = request_var('u', 0);
 0756          $topic_id    = request_var('t', 0);
 0757   
 0758          if ($user_id)
 0759          {
 0760              $form_name = 'user';
 0761          }
 0762          else if ($topic_id)
 0763          {
 0764              $form_name = 'topic';
 0765          }
 0766          else if ($mode === 'contactadmin')
 0767          {
 0768              $form_name = 'admin';
 0769          }
 0770          else
 0771          {
 0772              trigger_error('NO_EMAIL');
 0773          }
 0774          $form = $phpbb_container->get('message.form.' . $form_name);
 0775   
 0776          $form->bind($request);
 0777          $error = $form->check_allow();
 0778          if ($error)
 0779          {
 0780              trigger_error($error);
 0781          }
 0782   
 0783          if ($request->is_set_post('submit'))
 0784          {
 0785              $messenger = new messenger(false);
 0786              $form->submit($messenger);
 0787          }
 0788   
 0789          $page_title = $form->get_page_title();
 0790          $template_html = $form->get_template_file();
 0791          $form->render($template);
 0792   
 0793      break;
 0794   
 0795      case 'livesearch':
 0796   
 0797          $username_chars = $request->variable('username', '', true);
 0798   
 0799          $sql = 'SELECT username, user_id, user_colour
 0800              FROM ' . USERS_TABLE . '
 0801              WHERE ' . $db->sql_in_set('user_type', array(USER_NORMAL, USER_FOUNDER)) . '
 0802                  AND username_clean ' . $db->sql_like_expression(utf8_clean_string($username_chars) . $db->get_any_char());
 0803          $result = $db->sql_query_limit($sql, 10);
 0804          $user_list = array();
 0805   
 0806          while ($row = $db->sql_fetchrow($result))
 0807          {
 0808              $user_list[] = array(
 0809                  'user_id'        => (int) $row['user_id'],
 0810                  'result'        => $row['username'],
 0811                  'username_full'    => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
 0812                  'display'        => get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour']),
 0813              );
 0814          }
 0815          $db->sql_freeresult($result);
 0816          $json_response = new \phpbb\json_response();
 0817          $json_response->send(array(
 0818              'keyword' => $username_chars,
 0819              'results' => $user_list,
 0820          ));
 0821   
 0822      break;
 0823   
 0824      case 'group':
 0825      default:
 0826          // The basic memberlist
 0827          $page_title = $user->lang['MEMBERLIST'];
 0828          $template_html = 'memberlist_body.html';
 0829          $pagination = $phpbb_container->get('pagination');
 0830   
 0831          // Sorting
 0832          $sort_key_text = array('a' => $user->lang['SORT_USERNAME'], 'c' => $user->lang['SORT_JOINED'], 'd' => $user->lang['SORT_POST_COUNT']);
 0833          $sort_key_sql = array('a' => 'u.username_clean', 'c' => 'u.user_regdate', 'd' => 'u.user_posts');
 0834   
 0835          if ($config['jab_enable'])
 0836          {
 0837              $sort_key_text['k'] = $user->lang['JABBER'];
 0838              $sort_key_sql['k'] = 'u.user_jabber';
 0839          }
 0840   
 0841          if ($auth->acl_get('a_user'))
 0842          {
 0843              $sort_key_text['e'] = $user->lang['SORT_EMAIL'];
 0844              $sort_key_sql['e'] = 'u.user_email';
 0845          }
 0846   
 0847          if ($auth->acl_get('u_viewonline'))
 0848          {
 0849              $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
 0850              $sort_key_sql['l'] = 'u.user_lastvisit';
 0851          }
 0852   
 0853          $sort_key_text['m'] = $user->lang['SORT_RANK'];
 0854          $sort_key_sql['m'] = 'u.user_rank';
 0855   
 0856          $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
 0857   
 0858          $s_sort_key = '';
 0859          foreach ($sort_key_text as $key => $value)
 0860          {
 0861              $selected = ($sort_key == $key) ? ' selected="selected"' : '';
 0862              $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 0863          }
 0864   
 0865          $s_sort_dir = '';
 0866          foreach ($sort_dir_text as $key => $value)
 0867          {
 0868              $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
 0869              $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 0870          }
 0871   
 0872          // Additional sorting options for user search ... if search is enabled, if not
 0873          // then only admins can make use of this (for ACP functionality)
 0874          $sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
 0875   
 0876   
 0877          $form            = request_var('form', '');
 0878          $field            = request_var('field', '');
 0879          $select_single     = request_var('select_single', false);
 0880   
 0881          // Search URL parameters, if any of these are in the URL we do a search
 0882          $search_params = array('username', 'email', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
 0883   
 0884          // We validate form and field here, only id/class allowed
 0885          $form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
 0886          $field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
 0887          if ((($mode == '' || $mode == 'searchuser') || sizeof(array_intersect($request->variable_names(\phpbb\request\request_interface::GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
 0888          {
 0889              $username    = request_var('username', '', true);
 0890              $email        = strtolower(request_var('email', ''));
 0891              $jabber        = request_var('jabber', '');
 0892              $search_group_id    = request_var('search_group_id', 0);
 0893   
 0894              // when using these, make sure that we actually have values defined in $find_key_match
 0895              $joined_select    = request_var('joined_select', 'lt');
 0896              $active_select    = request_var('active_select', 'lt');
 0897              $count_select    = request_var('count_select', 'eq');
 0898   
 0899              $joined            = explode('-', request_var('joined', ''));
 0900              $active            = explode('-', request_var('active', ''));
 0901              $count            = (request_var('count', '') !== '') ? request_var('count', 0) : '';
 0902              $ipdomain        = request_var('ip', '');
 0903   
 0904              $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
 0905   
 0906              $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
 0907              $s_find_count = '';
 0908              foreach ($find_count as $key => $value)
 0909              {
 0910                  $selected = ($count_select == $key) ? ' selected="selected"' : '';
 0911                  $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 0912              }
 0913   
 0914              $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
 0915              $s_find_join_time = '';
 0916              foreach ($find_time as $key => $value)
 0917              {
 0918                  $selected = ($joined_select == $key) ? ' selected="selected"' : '';
 0919                  $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 0920              }
 0921   
 0922              $s_find_active_time = '';
 0923              foreach ($find_time as $key => $value)
 0924              {
 0925                  $selected = ($active_select == $key) ? ' selected="selected"' : '';
 0926                  $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
 0927              }
 0928   
 0929              $sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), utf8_clean_string($username))) : '';
 0930              $sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), $email)) . ' ' : '';
 0931              $sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->get_any_char(), $jabber)) . ' ' : '';
 0932              $sql_where .= (is_numeric($count) && isset($find_key_match[$count_select])) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
 0933   
 0934              if (isset($find_key_match[$joined_select]) && sizeof($joined) == 3)
 0935              {
 0936                  $joined_time = gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]);
 0937   
 0938                  if ($joined_time !== false)
 0939                  {
 0940                      $sql_where .= " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . $joined_time;
 0941                  }
 0942              }
 0943   
 0944              if (isset($find_key_match[$active_select]) && sizeof($active) == 3 && $auth->acl_get('u_viewonline'))
 0945              {
 0946                  $active_time = gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
 0947   
 0948                  if ($active_time !== false)
 0949                  {
 0950                      $sql_where .= " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . $active_time;
 0951                  }
 0952              }
 0953   
 0954              $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
 0955   
 0956              if ($search_group_id)
 0957              {
 0958                  $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
 0959              }
 0960   
 0961              if ($ipdomain && $auth->acl_getf_global('m_info'))
 0962              {
 0963                  if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
 0964                  {
 0965                      $hostnames = gethostbynamel($ipdomain);
 0966   
 0967                      if ($hostnames !== false)
 0968                      {
 0969                          $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)))) . "'";
 0970                      }
 0971                      else
 0972                      {
 0973                          $ips = false;
 0974                      }
 0975                  }
 0976                  else
 0977                  {
 0978                      $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
 0979                  }
 0980   
 0981                  if ($ips === false)
 0982                  {
 0983                      // A minor fudge but it does the job :D
 0984                      $sql_where .= " AND u.user_id = 0";
 0985                  }
 0986                  else
 0987                  {
 0988                      $ip_forums = array_keys($auth->acl_getf('m_info', true));
 0989   
 0990                      $sql = 'SELECT DISTINCT poster_id
 0991                          FROM ' . POSTS_TABLE . '
 0992                          WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
 0993                              AND " . $db->sql_in_set('forum_id', $ip_forums);
 0994                      $result = $db->sql_query($sql);
 0995   
 0996                      if ($row = $db->sql_fetchrow($result))
 0997                      {
 0998                          $ip_sql = array();
 0999                          do
 1000                          {
 1001                              $ip_sql[] = $row['poster_id'];
 1002                          }
 1003                          while ($row = $db->sql_fetchrow($result));
 1004   
 1005                          $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
 1006                      }
 1007                      else
 1008                      {
 1009                          // A minor fudge but it does the job :D
 1010                          $sql_where .= " AND u.user_id = 0";
 1011                      }
 1012                      unset($ip_forums);
 1013   
 1014                      $db->sql_freeresult($result);
 1015                  }
 1016              }
 1017          }
 1018   
 1019          $first_char = request_var('first_char', '');
 1020   
 1021          if ($first_char == 'other')
 1022          {
 1023              for ($i = 97; $i < 123; $i++)
 1024              {
 1025                  $sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->get_any_char());
 1026              }
 1027          }
 1028          else if ($first_char)
 1029          {
 1030              $sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->get_any_char());
 1031          }
 1032   
 1033          // Are we looking at a usergroup? If so, fetch additional info
 1034          // and further restrict the user info query
 1035          if ($mode == 'group')
 1036          {
 1037              // We JOIN here to save a query for determining membership for hidden groups. ;)
 1038              $sql = 'SELECT g.*, ug.user_id
 1039                  FROM ' . GROUPS_TABLE . ' g
 1040                  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)
 1041                  WHERE g.group_id = $group_id";
 1042              $result = $db->sql_query($sql);
 1043              $group_row = $db->sql_fetchrow($result);
 1044              $db->sql_freeresult($result);
 1045   
 1046              if (!$group_row)
 1047              {
 1048                  trigger_error('NO_GROUP');
 1049              }
 1050   
 1051              switch ($group_row['group_type'])
 1052              {
 1053                  case GROUP_OPEN:
 1054                      $group_row['l_group_type'] = 'OPEN';
 1055                  break;
 1056   
 1057                  case GROUP_CLOSED:
 1058                      $group_row['l_group_type'] = 'CLOSED';
 1059                  break;
 1060   
 1061                  case GROUP_HIDDEN:
 1062                      $group_row['l_group_type'] = 'HIDDEN';
 1063   
 1064                      // Check for membership or special permissions
 1065                      if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
 1066                      {
 1067                          trigger_error('NO_GROUP');
 1068                      }
 1069                  break;
 1070   
 1071                  case GROUP_SPECIAL:
 1072                      $group_row['l_group_type'] = 'SPECIAL';
 1073                  break;
 1074   
 1075                  case GROUP_FREE:
 1076                      $group_row['l_group_type'] = 'FREE';
 1077                  break;
 1078              }
 1079   
 1080              $avatar_img = phpbb_get_group_avatar($group_row);
 1081   
 1082              // ... same for group rank
 1083              $user_rank_data = array(
 1084                  'title'        => null,
 1085                  'img'        => null,
 1086                  'img_src'    => null,
 1087              );
 1088              if ($group_row['group_rank'])
 1089              {
 1090                  $user_rank_data = phpbb_get_user_rank($group_row, false);
 1091   
 1092                  if ($user_rank_data['img'])
 1093                  {
 1094                      $user_rank_data['img'] .= '<br />';
 1095                  }
 1096              }
 1097   
 1098              $template->assign_vars(array(
 1099                  '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']),
 1100                  'GROUP_NAME'    => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
 1101                  'GROUP_COLOR'    => $group_row['group_colour'],
 1102                  'GROUP_TYPE'    => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
 1103                  'GROUP_RANK'    => $user_rank_data['title'],
 1104   
 1105                  'AVATAR_IMG'    => $avatar_img,
 1106                  'RANK_IMG'        => $user_rank_data['img'],
 1107                  'RANK_IMG_SRC'    => $user_rank_data['img_src'],
 1108   
 1109                  'U_PM'            => ($auth->acl_get('u_sendpm') && $auth->acl_get('u_masspm_group') && $group_row['group_receive_pm'] && $config['allow_privmsg'] && $config['allow_mass_pm']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=compose&amp;g=' . $group_id) : '',)
 1110              );
 1111   
 1112              $sql_select = ', ug.group_leader';
 1113              $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
 1114              $order_by = 'ug.group_leader DESC, ';
 1115   
 1116              $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
 1117              $sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
 1118          }
 1119   
 1120          // Sorting and order
 1121          if (!isset($sort_key_sql[$sort_key]))
 1122          {
 1123              $sort_key = $default_key;
 1124          }
 1125   
 1126          $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
 1127   
 1128          // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
 1129          if ($sort_key == 'm')
 1130          {
 1131              $order_by .= ', u.user_posts DESC';
 1132          }
 1133   
 1134          // Count the users ...
 1135          if ($sql_where)
 1136          {
 1137              $sql = 'SELECT COUNT(u.user_id) AS total_users
 1138                  FROM ' . USERS_TABLE . " u$sql_from
 1139                  WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
 1140                  $sql_where";
 1141              $result = $db->sql_query($sql);
 1142              $total_users = (int) $db->sql_fetchfield('total_users');
 1143              $db->sql_freeresult($result);
 1144          }
 1145          else
 1146          {
 1147              $total_users = $config['num_users'];
 1148          }
 1149   
 1150          // Build a relevant pagination_url
 1151          $params = $sort_params = array();
 1152   
 1153          // We do not use request_var() here directly to save some calls (not all variables are set)
 1154          $check_params = array(
 1155              'g'                => array('g', 0),
 1156              'sk'            => array('sk', $default_key),
 1157              'sd'            => array('sd', 'a'),
 1158              'form'            => array('form', ''),
 1159              'field'            => array('field', ''),
 1160              'select_single'    => array('select_single', $select_single),
 1161              'username'        => array('username', '', true),
 1162              'email'            => array('email', ''),
 1163              'jabber'        => array('jabber', ''),
 1164              'search_group_id'    => array('search_group_id', 0),
 1165              'joined_select'    => array('joined_select', 'lt'),
 1166              'active_select'    => array('active_select', 'lt'),
 1167              'count_select'    => array('count_select', 'eq'),
 1168              'joined'        => array('joined', ''),
 1169              'active'        => array('active', ''),
 1170              'count'            => (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
 1171              'ip'            => array('ip', ''),
 1172              'first_char'    => array('first_char', ''),
 1173          );
 1174   
 1175          $u_first_char_params = array();
 1176          foreach ($check_params as $key => $call)
 1177          {
 1178              if (!isset($_REQUEST[$key]))
 1179              {
 1180                  continue;
 1181              }
 1182   
 1183              $param = call_user_func_array('request_var', $call);
 1184              $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
 1185              $params[] = $param;
 1186   
 1187              if ($key != 'first_char')
 1188              {
 1189                  $u_first_char_params[] = $param;
 1190              }
 1191              if ($key != 'sk' && $key != 'sd')
 1192              {
 1193                  $sort_params[] = $param;
 1194              }
 1195          }
 1196   
 1197          $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&amp;' . implode('&amp;', $params) : ''));
 1198   
 1199          if ($mode)
 1200          {
 1201              $params[] = "mode=$mode";
 1202              $u_first_char_params[] = "mode=$mode";
 1203          }
 1204          $sort_params[] = "mode=$mode";
 1205   
 1206          $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
 1207          $sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $sort_params));
 1208   
 1209          unset($search_params, $sort_params);
 1210   
 1211          $u_first_char_params = implode('&amp;', $u_first_char_params);
 1212          $u_first_char_params .= ($u_first_char_params) ? '&amp;' : '';
 1213   
 1214          $first_characters = array();
 1215          $first_characters[''] = $user->lang['ALL'];
 1216          for ($i = 97; $i < 123; $i++)
 1217          {
 1218              $first_characters[chr($i)] = chr($i - 32);
 1219          }
 1220          $first_characters['other'] = $user->lang['OTHER'];
 1221   
 1222          foreach ($first_characters as $char => $desc)
 1223          {
 1224              $template->assign_block_vars('first_char', array(
 1225                  'DESC'            => $desc,
 1226                  'VALUE'            => $char,
 1227                  'S_SELECTED'    => ($first_char == $char) ? true : false,
 1228                  'U_SORT'        => append_sid("{$phpbb_root_path}memberlist.$phpEx", $u_first_char_params . 'first_char=' . $char) . '#memberlist',
 1229              ));
 1230          }
 1231   
 1232          // Some search user specific data
 1233          if (($mode == '' || $mode == 'searchuser') && ($config['load_search'] || $auth->acl_get('a_')))
 1234          {
 1235              $group_selected = request_var('search_group_id', 0);
 1236              $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
 1237              $group_ids = array();
 1238   
 1239              /**
 1240              * @todo add this to a separate function (function is responsible for returning the groups the user is able to see based on the users group membership)
 1241              */
 1242   
 1243              if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
 1244              {
 1245                  $sql = 'SELECT group_id, group_name, group_type
 1246                      FROM ' . GROUPS_TABLE;
 1247   
 1248                  if (!$config['coppa_enable'])
 1249                  {
 1250                      $sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
 1251                  }
 1252   
 1253                  $sql .= ' ORDER BY group_name ASC';
 1254              }
 1255              else
 1256              {
 1257                  $sql = 'SELECT g.group_id, g.group_name, g.group_type
 1258                      FROM ' . GROUPS_TABLE . ' g
 1259                      LEFT JOIN ' . USER_GROUP_TABLE . ' ug
 1260                          ON (
 1261                              g.group_id = ug.group_id
 1262                              AND ug.user_id = ' . $user->data['user_id'] . '
 1263                              AND ug.user_pending = 0
 1264                          )
 1265                      WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
 1266   
 1267                  if (!$config['coppa_enable'])
 1268                  {
 1269                      $sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
 1270                  }
 1271   
 1272                  $sql .= ' ORDER BY g.group_name ASC';
 1273              }
 1274              $result = $db->sql_query($sql);
 1275   
 1276              while ($row = $db->sql_fetchrow($result))
 1277              {
 1278                  $group_ids[] = $row['group_id'];
 1279                  $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>';
 1280              }
 1281              $db->sql_freeresult($result);
 1282   
 1283              if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
 1284              {
 1285                  trigger_error('NO_GROUP');
 1286              }
 1287   
 1288              $template->assign_vars(array(
 1289                  'USERNAME'    => $username,
 1290                  'EMAIL'        => $email,
 1291                  'JABBER'    => $jabber,
 1292                  'JOINED'    => implode('-', $joined),
 1293                  'ACTIVE'    => implode('-', $active),
 1294                  'COUNT'        => $count,
 1295                  'IP'        => $ipdomain,
 1296   
 1297                  'S_IP_SEARCH_ALLOWED'    => ($auth->acl_getf_global('m_info')) ? true : false,
 1298                  'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
 1299                  'S_JABBER_ENABLED'        => $config['jab_enable'],
 1300                  'S_IN_SEARCH_POPUP'        => ($form && $field) ? true : false,
 1301                  'S_SEARCH_USER'            => ($mode == 'searchuser' || ($mode == '' && $submit)),
 1302                  'S_FORM_NAME'            => $form,
 1303                  'S_FIELD_NAME'            => $field,
 1304                  'S_SELECT_SINGLE'        => $select_single,
 1305                  'S_COUNT_OPTIONS'        => $s_find_count,
 1306                  'S_SORT_OPTIONS'        => $s_sort_key,
 1307                  'S_JOINED_TIME_OPTIONS'    => $s_find_join_time,
 1308                  'S_ACTIVE_TIME_OPTIONS'    => $s_find_active_time,
 1309                  'S_GROUP_SELECT'        => $s_group_select,
 1310                  'S_USER_SEARCH_ACTION'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=$form&amp;field=$field"))
 1311              );
 1312          }
 1313   
 1314          $start = $pagination->validate_start($start, $config['topics_per_page'], $config['num_users']);
 1315   
 1316          // Get us some users :D
 1317          $sql = "SELECT u.user_id
 1318              FROM " . USERS_TABLE . " u
 1319                  $sql_from
 1320              WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
 1321                  $sql_where
 1322              ORDER BY $order_by";
 1323          $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 1324   
 1325          $user_list = array();
 1326          while ($row = $db->sql_fetchrow($result))
 1327          {
 1328              $user_list[] = (int) $row['user_id'];
 1329          }
 1330          $db->sql_freeresult($result);
 1331   
 1332          // Load custom profile fields
 1333          if ($config['load_cpf_memberlist'])
 1334          {
 1335              $cp = $phpbb_container->get('profilefields.manager');
 1336   
 1337              $cp_row = $cp->generate_profile_fields_template_headlines('field_show_on_ml');
 1338              foreach ($cp_row as $profile_field)
 1339              {
 1340                  $template->assign_block_vars('custom_fields', $profile_field);
 1341              }
 1342          }
 1343   
 1344          $leaders_set = false;
 1345          // So, did we get any users?
 1346          if (sizeof($user_list))
 1347          {
 1348              // Session time?! Session time...
 1349              $sql = 'SELECT session_user_id, MAX(session_time) AS session_time
 1350                  FROM ' . SESSIONS_TABLE . '
 1351                  WHERE session_time >= ' . (time() - $config['session_length']) . '
 1352                      AND ' . $db->sql_in_set('session_user_id', $user_list) . '
 1353                  GROUP BY session_user_id';
 1354              $result = $db->sql_query($sql);
 1355   
 1356              $session_times = array();
 1357              while ($row = $db->sql_fetchrow($result))
 1358              {
 1359                  $session_times[$row['session_user_id']] = $row['session_time'];
 1360              }
 1361              $db->sql_freeresult($result);
 1362   
 1363              // Do the SQL thang
 1364              if ($mode == 'group')
 1365              {
 1366                  $sql = "SELECT u.*
 1367                          $sql_select
 1368                      FROM " . USERS_TABLE . " u
 1369                          $sql_from
 1370                      WHERE " . $db->sql_in_set('u.user_id', $user_list) . "
 1371                          $sql_where_data";
 1372              }
 1373              else
 1374              {
 1375                  $sql = 'SELECT *
 1376                      FROM ' . USERS_TABLE . '
 1377                      WHERE ' . $db->sql_in_set('user_id', $user_list);
 1378              }
 1379              $result = $db->sql_query($sql);
 1380   
 1381              $id_cache = array();
 1382              while ($row = $db->sql_fetchrow($result))
 1383              {
 1384                  $row['session_time'] = (!empty($session_times[$row['user_id']])) ? $session_times[$row['user_id']] : 0;
 1385                  $row['last_visit'] = (!empty($row['session_time'])) ? $row['session_time'] : $row['user_lastvisit'];
 1386   
 1387                  $id_cache[$row['user_id']] = $row;
 1388              }
 1389              $db->sql_freeresult($result);
 1390   
 1391              // Load custom profile fields
 1392              if ($config['load_cpf_memberlist'])
 1393              {
 1394                  // Grab all profile fields from users in id cache for later use - similar to the poster cache
 1395                  $profile_fields_cache = $cp->grab_profile_fields_data($user_list);
 1396   
 1397                  // Filter the fields we don't want to show
 1398                  foreach ($profile_fields_cache as $user_id => $user_profile_fields)
 1399                  {
 1400                      foreach ($user_profile_fields as $field_ident => $profile_field)
 1401                      {
 1402                          if (!$profile_field['data']['field_show_on_ml'])
 1403                          {
 1404                              unset($profile_fields_cache[$user_id][$field_ident]);
 1405                          }
 1406                      }
 1407                  }
 1408              }
 1409   
 1410              // If we sort by last active date we need to adjust the id cache due to user_lastvisit not being the last active date...
 1411              if ($sort_key == 'l')
 1412              {
 1413  //                uasort($id_cache, create_function('$first, $second', "return (\$first['last_visit'] == \$second['last_visit']) ? 0 : ((\$first['last_visit'] < \$second['last_visit']) ? $lesser_than : ($lesser_than * -1));"));
 1414                  usort($user_list,  'phpbb_sort_last_active');
 1415              }
 1416   
 1417              for ($i = 0, $end = sizeof($user_list); $i < $end; ++$i)
 1418              {
 1419                  $user_id = $user_list[$i];
 1420                  $row = $id_cache[$user_id];
 1421                  $is_leader = (isset($row['group_leader']) && $row['group_leader']) ? true : false;
 1422                  $leaders_set = ($leaders_set || $is_leader);
 1423   
 1424                  $cp_row = array();
 1425                  if ($config['load_cpf_memberlist'])
 1426                  {
 1427                      $cp_row = (isset($profile_fields_cache[$user_id])) ? $cp->generate_profile_fields_template_data($profile_fields_cache[$user_id], false) : array();
 1428                  }
 1429   
 1430                  $memberrow = array_merge(phpbb_show_profile($row, false, false, false), array(
 1431                      'ROW_NUMBER'        => $i + ($start + 1),
 1432   
 1433                      'S_CUSTOM_PROFILE'    => (isset($cp_row['row']) && sizeof($cp_row['row'])) ? true : false,
 1434                      'S_GROUP_LEADER'    => $is_leader,
 1435   
 1436                      'U_VIEW_PROFILE'    => get_username_string('profile', $user_id, $row['username']),
 1437                  ));
 1438   
 1439                  if (isset($cp_row['row']) && sizeof($cp_row['row']))
 1440                  {
 1441                      $memberrow = array_merge($memberrow, $cp_row['row']);
 1442                  }
 1443   
 1444                  $template->assign_block_vars('memberrow', $memberrow);
 1445   
 1446                  if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
 1447                  {
 1448                      foreach ($cp_row['blockrow'] as $field_data)
 1449                      {
 1450                          $template->assign_block_vars('memberrow.custom_fields', $field_data);
 1451                      }
 1452                  }
 1453   
 1454                  unset($id_cache[$user_id]);
 1455              }
 1456          }
 1457   
 1458          $pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_users, $config['topics_per_page'], $start);
 1459   
 1460          // Generate page
 1461          $template->assign_vars(array(
 1462              'TOTAL_USERS'    => $user->lang('LIST_USERS', (int) $total_users),
 1463   
 1464              'PROFILE_IMG'    => $user->img('icon_user_profile', $user->lang['PROFILE']),
 1465              'PM_IMG'        => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
 1466              'EMAIL_IMG'        => $user->img('icon_contact_email', $user->lang['EMAIL']),
 1467              'JABBER_IMG'    => $user->img('icon_contact_jabber', $user->lang['JABBER']),
 1468              'SEARCH_IMG'    => $user->img('icon_user_search', $user->lang['SEARCH']),
 1469   
 1470              'U_FIND_MEMBER'            => ($config['load_search'] || $auth->acl_get('a_')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser' . (($start) ? "&amp;start=$start" : '') . (!empty($params) ? '&amp;' . implode('&amp;', $params) : '')) : '',
 1471              'U_HIDE_FIND_MEMBER'    => ($mode == 'searchuser' || ($mode == '' && $submit)) ? $u_hide_find_member : '',
 1472              'U_LIVE_SEARCH'            => ($config['allow_live_searches']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=livesearch') : false,
 1473              'U_SORT_USERNAME'        => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'a' && $sort_dir == 'a') ? 'd' : 'a'),
 1474              'U_SORT_JOINED'            => $sort_url . '&amp;sk=c&amp;sd=' . (($sort_key == 'c' && $sort_dir == 'a') ? 'd' : 'a'),
 1475              'U_SORT_POSTS'            => $sort_url . '&amp;sk=d&amp;sd=' . (($sort_key == 'd' && $sort_dir == 'a') ? 'd' : 'a'),
 1476              'U_SORT_EMAIL'            => $sort_url . '&amp;sk=e&amp;sd=' . (($sort_key == 'e' && $sort_dir == 'a') ? 'd' : 'a'),
 1477              'U_SORT_ACTIVE'            => ($auth->acl_get('u_viewonline')) ? $sort_url . '&amp;sk=l&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a') : '',
 1478              'U_SORT_RANK'            => $sort_url . '&amp;sk=m&amp;sd=' . (($sort_key == 'm' && $sort_dir == 'a') ? 'd' : 'a'),
 1479              'U_LIST_CHAR'            => $sort_url . '&amp;sk=a&amp;sd=' . (($sort_key == 'l' && $sort_dir == 'a') ? 'd' : 'a'),
 1480   
 1481              'S_SHOW_GROUP'        => ($mode == 'group') ? true : false,
 1482              'S_VIEWONLINE'        => $auth->acl_get('u_viewonline'),
 1483              'S_LEADERS_SET'        => $leaders_set,
 1484              'S_MODE_SELECT'        => $s_sort_key,
 1485              'S_ORDER_SELECT'    => $s_sort_dir,
 1486              'S_MODE_ACTION'        => $pagination_url)
 1487          );
 1488  }
 1489   
 1490  // Output the page
 1491  page_header($page_title);
 1492   
 1493  $template->set_filenames(array(
 1494      'body' => $template_html)
 1495  );
 1496  make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
 1497   
 1498  page_footer();
 1499