PageRenderTime 570ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

/station/forum/memberlist.php

https://github.com/bryanveloso/sayonarane
PHP | 1648 lines | 1301 code | 263 blank | 84 comment | 282 complexity | edae4ec8d3d8f2df936e272d8daf7426 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file