[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/ -> memberlist.php (source)

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


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1