[ Index ]

PHP Cross Reference of phpBB-3.1.10-deutsch

title

Body

[close]

/ -> memberlist.php (source)

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


Generated: Sun Feb 19 19:52:41 2017 Cross-referenced by PHPXref 0.7.1