PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/phpBB3/memberlist.php

http://pbb-png1.googlecode.com/
PHP | 1686 lines | 1319 code | 272 blank | 95 comment | 288 complexity | 71242b89818d62f6dd5d93292f19fac3 MD5 | raw file

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

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