PageRenderTime 84ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/forum/memberlist.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 1757 lines | 1375 code | 282 blank | 100 comment | 318 complexity | 2db7a67596e2b38c243e8a3aa112f62a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.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$
  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. '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. // Get group memberships
  358. // Also get visiting user's groups to determine hidden group memberships if necessary.
  359. $auth_hidden_groups = ($user_id === (int) $user->data['user_id'] || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false;
  360. $sql_uid_ary = ($auth_hidden_groups) ? array($user_id) : array($user_id, (int) $user->data['user_id']);
  361. // Do the SQL thang
  362. $sql = 'SELECT g.group_id, g.group_name, g.group_type, ug.user_id
  363. FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
  364. WHERE ' . $db->sql_in_set('ug.user_id', $sql_uid_ary) . '
  365. AND g.group_id = ug.group_id
  366. AND ug.user_pending = 0';
  367. $result = $db->sql_query($sql);
  368. // Divide data into profile data and current user data
  369. $profile_groups = $user_groups = array();
  370. while ($row = $db->sql_fetchrow($result))
  371. {
  372. $row['user_id'] = (int) $row['user_id'];
  373. $row['group_id'] = (int) $row['group_id'];
  374. if ($row['user_id'] == $user_id)
  375. {
  376. $profile_groups[] = $row;
  377. }
  378. else
  379. {
  380. $user_groups[$row['group_id']] = $row['group_id'];
  381. }
  382. }
  383. $db->sql_freeresult($result);
  384. // Filter out hidden groups and sort groups by name
  385. $group_data = $group_sort = array();
  386. foreach ($profile_groups as $row)
  387. {
  388. if ($row['group_type'] == GROUP_SPECIAL)
  389. {
  390. // Lookup group name in language dictionary
  391. if (isset($user->lang['G_' . $row['group_name']]))
  392. {
  393. $row['group_name'] = $user->lang['G_' . $row['group_name']];
  394. }
  395. }
  396. else if (!$auth_hidden_groups && $row['group_type'] == GROUP_HIDDEN && !isset($user_groups[$row['group_id']]))
  397. {
  398. // Skip over hidden groups the user cannot see
  399. continue;
  400. }
  401. $group_sort[$row['group_id']] = utf8_clean_string($row['group_name']);
  402. $group_data[$row['group_id']] = $row;
  403. }
  404. unset($profile_groups);
  405. unset($user_groups);
  406. asort($group_sort);
  407. $group_options = '';
  408. foreach ($group_sort as $group_id => $null)
  409. {
  410. $row = $group_data[$group_id];
  411. $group_options .= '<option value="' . $row['group_id'] . '"' . (($row['group_id'] == $member['group_id']) ? ' selected="selected"' : '') . '>' . $row['group_name'] . '</option>';
  412. }
  413. unset($group_data);
  414. unset($group_sort);
  415. // What colour is the zebra
  416. $sql = 'SELECT friend, foe
  417. FROM ' . ZEBRA_TABLE . "
  418. WHERE zebra_id = $user_id
  419. AND user_id = {$user->data['user_id']}";
  420. $result = $db->sql_query($sql);
  421. $row = $db->sql_fetchrow($result);
  422. $foe = ($row['foe']) ? true : false;
  423. $friend = ($row['friend']) ? true : false;
  424. $db->sql_freeresult($result);
  425. if ($config['load_onlinetrack'])
  426. {
  427. $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
  428. FROM ' . SESSIONS_TABLE . "
  429. WHERE session_user_id = $user_id";
  430. $result = $db->sql_query($sql);
  431. $row = $db->sql_fetchrow($result);
  432. $db->sql_freeresult($result);
  433. $member['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
  434. $member['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
  435. unset($row);
  436. }
  437. if ($config['load_user_activity'])
  438. {
  439. display_user_activity($member);
  440. }
  441. // Do the relevant calculations
  442. $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
  443. $posts_per_day = $member['user_posts'] / $memberdays;
  444. $percentage = ($config['num_posts']) ? min(100, ($member['user_posts'] / $config['num_posts']) * 100) : 0;
  445. if ($member['user_sig'])
  446. {
  447. $member['user_sig'] = censor_text($member['user_sig']);
  448. if ($member['user_sig_bbcode_bitfield'])
  449. {
  450. include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  451. $bbcode = new bbcode();
  452. $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
  453. }
  454. $member['user_sig'] = bbcode_nl2br($member['user_sig']);
  455. $member['user_sig'] = smiley_text($member['user_sig']);
  456. }
  457. $poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']);
  458. // We need to check if the modules 'zebra' ('friends' & 'foes' mode), 'notes' ('user_notes' mode) and 'warn' ('warn_user' mode) are accessible to decide if we can display appropriate links
  459. $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false;
  460. // Only check if the user is logged in
  461. if ($user->data['is_registered'])
  462. {
  463. if (!class_exists('p_master'))
  464. {
  465. include($phpbb_root_path . 'includes/functions_module.' . $phpEx);
  466. }
  467. $module = new p_master();
  468. $module->list_modules('ucp');
  469. $module->list_modules('mcp');
  470. $user_notes_enabled = ($module->loaded('notes', 'user_notes')) ? true : false;
  471. $warn_user_enabled = ($module->loaded('warn', 'warn_user')) ? true : false;
  472. $zebra_enabled = ($module->loaded('zebra')) ? true : false;
  473. $friends_enabled = ($module->loaded('zebra', 'friends')) ? true : false;
  474. $foes_enabled = ($module->loaded('zebra', 'foes')) ? true : false;
  475. unset($module);
  476. }
  477. $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled));
  478. // Custom Profile Fields
  479. $profile_fields = array();
  480. if ($config['load_cpf_viewprofile'])
  481. {
  482. include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
  483. $cp = new custom_profile();
  484. $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
  485. $profile_fields = (isset($profile_fields[$user_id])) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
  486. }
  487. // If the user has m_approve permission or a_user permission, then list then display unapproved posts
  488. if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user'))
  489. {
  490. $sql = 'SELECT COUNT(post_id) as posts_in_queue
  491. FROM ' . POSTS_TABLE . '
  492. WHERE poster_id = ' . $user_id . '
  493. AND post_approved = 0';
  494. $result = $db->sql_query($sql);
  495. $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
  496. $db->sql_freeresult($result);
  497. }
  498. else
  499. {
  500. $member['posts_in_queue'] = 0;
  501. }
  502. $template->assign_vars(array(
  503. 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $member['posts_in_queue']),
  504. 'POSTS_DAY' => sprintf($user->lang['POST_DAY'], $posts_per_day),
  505. 'POSTS_PCT' => sprintf($user->lang['POST_PCT'], $percentage),
  506. 'OCCUPATION' => (!empty($member['user_occ'])) ? censor_text($member['user_occ']) : '',
  507. 'INTERESTS' => (!empty($member['user_interests'])) ? censor_text($member['user_interests']) : '',
  508. 'SIGNATURE' => $member['user_sig'],
  509. 'POSTS_IN_QUEUE'=> $member['posts_in_queue'],
  510. 'AVATAR_IMG' => $poster_avatar,
  511. 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']),
  512. 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']),
  513. 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']),
  514. 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']),
  515. 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']),
  516. 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']),
  517. 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']),
  518. 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']),
  519. 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']),
  520. 'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group'),
  521. 'S_GROUP_OPTIONS' => $group_options,
  522. 'S_CUSTOM_FIELDS' => (isset($profile_fields['row']) && sizeof($profile_fields['row'])) ? true : false,
  523. '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) : '',
  524. '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) : '',
  525. 'U_MCP_QUEUE' => ($auth->acl_getf_global('m_approve')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue', true, $user->session_id) : '',
  526. 'U_SWITCH_PERMISSIONS' => ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_id) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_id}&amp;hash=" . generate_link_hash('switchperm')) : '',
  527. 'S_USER_NOTES' => ($user_notes_enabled) ? true : false,
  528. 'S_WARN_USER' => ($warn_user_enabled) ? true : false,
  529. 'S_ZEBRA' => ($user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled) ? true : false,
  530. 'U_ADD_FRIEND' => (!$friend && !$foe && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
  531. 'U_ADD_FOE' => (!$friend && !$foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;mode=foes&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '',
  532. 'U_REMOVE_FRIEND' => ($friend && $friends_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '',
  533. 'U_REMOVE_FOE' => ($foe && $foes_enabled) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=zebra&amp;remove=1&amp;mode=foes&amp;usernames[]=' . $user_id) : '',
  534. ));
  535. if (!empty($profile_fields['row']))
  536. {
  537. $template->assign_vars($profile_fields['row']);
  538. }
  539. if (!empty($profile_fields['blockrow']))
  540. {
  541. foreach ($profile_fields['blockrow'] as $field_data)
  542. {
  543. $template->assign_block_vars('custom_fields', $field_data);
  544. }
  545. }
  546. // Inactive reason/account?
  547. if ($member['user_type'] == USER_INACTIVE)
  548. {
  549. $user->add_lang('acp/common');
  550. $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
  551. switch ($member['user_inactive_reason'])
  552. {
  553. case INACTIVE_REGISTER:
  554. $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
  555. break;
  556. case INACTIVE_PROFILE:
  557. $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
  558. break;
  559. case INACTIVE_MANUAL:
  560. $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
  561. break;
  562. case INACTIVE_REMIND:
  563. $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
  564. break;
  565. }
  566. $template->assign_vars(array(
  567. 'S_USER_INACTIVE' => true,
  568. 'USER_INACTIVE_REASON' => $inactive_reason)
  569. );
  570. }
  571. // Now generate page title
  572. $page_title = sprintf($user->lang['VIEWING_PROFILE'], $member['username']);
  573. $template_html = 'memberlist_view.html';
  574. break;
  575. case 'email':
  576. // Send an email
  577. $page_title = $user->lang['SEND_EMAIL'];
  578. $template_html = 'memberlist_email.html';
  579. add_form_key('memberlist_email');
  580. if (!$config['email_enable'])
  581. {
  582. trigger_error('EMAIL_DISABLED');
  583. }
  584. if (!$auth->acl_get('u_sendemail'))
  585. {
  586. trigger_error('NO_EMAIL');
  587. }
  588. // Are we trying to abuse the facility?
  589. if (time() - $user->data['user_emailtime'] < $config['flood_interval'])
  590. {
  591. trigger_error('FLOOD_EMAIL_LIMIT');
  592. }
  593. // Determine action...
  594. $user_id = request_var('u', 0);
  595. $topic_id = request_var('t', 0);
  596. // Send email to user...
  597. if ($user_id)
  598. {
  599. if ($user_id == ANONYMOUS || !$config['board_email_form'])
  600. {
  601. trigger_error('NO_EMAIL');
  602. }
  603. // Get the appropriate username, etc.
  604. $sql = 'SELECT username, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
  605. FROM ' . USERS_TABLE . "
  606. WHERE user_id = $user_id
  607. AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
  608. $result = $db->sql_query($sql);
  609. $row = $db->sql_fetchrow($result);
  610. $db->sql_freeresult($result);
  611. if (!$row)
  612. {
  613. trigger_error('NO_USER');
  614. }
  615. // Can we send email to this user?
  616. if (!$row['user_allow_viewemail'] && !$auth->acl_get('a_user'))
  617. {
  618. trigger_error('NO_EMAIL');
  619. }
  620. }
  621. else if ($topic_id)
  622. {
  623. // Send topic heads-up to email address
  624. $sql = 'SELECT forum_id, topic_title
  625. FROM ' . TOPICS_TABLE . "
  626. WHERE topic_id = $topic_id";
  627. $result = $db->sql_query($sql);
  628. $row = $db->sql_fetchrow($result);
  629. $db->sql_freeresult($result);
  630. if (!$row)
  631. {
  632. trigger_error('NO_TOPIC');
  633. }
  634. if ($row['forum_id'])
  635. {
  636. if (!$auth->acl_get('f_read', $row['forum_id']))
  637. {
  638. trigger_error('SORRY_AUTH_READ');
  639. }
  640. if (!$auth->acl_get('f_email', $row['forum_id']))
  641. {
  642. trigger_error('NO_EMAIL');
  643. }
  644. }
  645. else
  646. {
  647. // If global announcement, we need to check if the user is able to at least read and email in one forum...
  648. if (!$auth->acl_getf_global('f_read'))
  649. {
  650. trigger_error('SORRY_AUTH_READ');
  651. }
  652. if (!$auth->acl_getf_global('f_email'))
  653. {
  654. trigger_error('NO_EMAIL');
  655. }
  656. }
  657. }
  658. else
  659. {
  660. trigger_error('NO_EMAIL');
  661. }
  662. $error = array();
  663. $name = utf8_normalize_nfc(request_var('name', '', true));
  664. $email = request_var('email', '');
  665. $email_lang = request_var('lang', $config['default_lang']);
  666. $subject = utf8_normalize_nfc(request_var('subject', '', true));
  667. $message = utf8_normalize_nfc(request_var('message', '', true));
  668. $cc = (isset($_POST['cc_email'])) ? true : false;
  669. $submit = (isset($_POST['submit'])) ? true : false;
  670. if ($submit)
  671. {
  672. if (!check_form_key('memberlist_email'))
  673. {
  674. $error[] = 'FORM_INVALID';
  675. }
  676. if ($user_id)
  677. {
  678. if (!$subject)
  679. {
  680. $error[] = $user->lang['EMPTY_SUBJECT_EMAIL'];
  681. }
  682. if (!$message)
  683. {
  684. $error[] = $user->lang['EMPTY_MESSAGE_EMAIL'];
  685. }
  686. $name = $row['username'];
  687. $email_lang = $row['user_lang'];
  688. $email = $row['user_email'];
  689. }
  690. else
  691. {
  692. if (!$email || !preg_match('/^' . get_preg_expression('email') . '$/i', $email))
  693. {
  694. $error[] = $user->lang['EMPTY_ADDRESS_EMAIL'];
  695. }
  696. if (!$name)
  697. {
  698. $error[] = $user->lang['EMPTY_NAME_EMAIL'];
  699. }
  700. }
  701. if (!sizeof($error))
  702. {
  703. $sql = 'UPDATE ' . USERS_TABLE . '
  704. SET user_emailtime = ' . time() . '
  705. WHERE user_id = ' . $user->data['user_id'];
  706. $result = $db->sql_query($sql);
  707. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  708. $messenger = new messenger(false);
  709. $email_tpl = ($user_id) ? 'profile_send_email' : 'email_notify';
  710. $mail_to_users = array();
  711. $mail_to_users[] = array(
  712. 'email_lang' => $email_lang,
  713. 'email' => $email,
  714. 'name' => $name,
  715. 'username' => ($user_id) ? $row['username'] : '',
  716. 'to_name' => $name,
  717. 'user_jabber' => ($user_id) ? $row['user_jabber'] : '',
  718. 'user_notify_type' => ($user_id) ? $row['user_notify_type'] : NOTIFY_EMAIL,
  719. 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
  720. 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
  721. );
  722. // Ok, now the same email if CC specified, but without exposing the users email address
  723. if ($cc)
  724. {
  725. $mail_to_users[] = array(
  726. 'email_lang' => $user->data['user_lang'],
  727. 'email' => $user->data['user_email'],
  728. 'name' => $user->data['username'],
  729. 'username' => $user->data['username'],
  730. 'to_name' => $name,
  731. 'user_jabber' => $user->data['user_jabber'],
  732. 'user_notify_type' => ($user_id) ? $user->data['user_notify_type'] : NOTIFY_EMAIL,
  733. 'topic_title' => (!$user_id) ? $row['topic_title'] : '',
  734. 'forum_id' => (!$user_id) ? $row['forum_id'] : 0,
  735. );
  736. }
  737. foreach ($mail_to_users as $row)
  738. {
  739. $messenger->template($email_tpl, $row['email_lang']);
  740. $messenger->replyto($user->data['user_email']);
  741. $messenger->to($row['email'], $row['name']);
  742. if ($user_id)
  743. {
  744. $messenger->subject(htmlspecialchars_decode($subject));
  745. $messenger->im($row['user_jabber'], $row['username']);
  746. $notify_type = $row['user_notify_type'];
  747. }
  748. else
  749. {
  750. $notify_type = NOTIFY_EMAIL;
  751. }
  752. $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
  753. $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
  754. $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
  755. $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
  756. $messenger->assign_vars(array(
  757. 'BOARD_CONTACT' => $config['board_contact'],
  758. 'TO_USERNAME' => htmlspecialchars_decode($row['to_name']),
  759. 'FROM_USERNAME' => htmlspecialchars_decode($user->data['username']),
  760. 'MESSAGE' => htmlspecialchars_decode($message))
  761. );
  762. if ($topic_id)
  763. {
  764. $messenger->assign_vars(array(
  765. 'TOPIC_NAME' => htmlspecialchars_decode($row['topic_title']),
  766. 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=" . $row['forum_id'] . "&t=$topic_id")
  767. );
  768. }
  769. $messenger->send($notify_type);
  770. }
  771. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  772. $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>');
  773. trigger_error($user->lang['EMAIL_SENT'] . '<br /><br />' . $message);
  774. }
  775. }
  776. if ($user_id)
  777. {
  778. $template->assign_vars(array(
  779. 'S_SEND_USER' => true,
  780. 'USERNAME' => $row['username'],
  781. 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_BODY_EXPLAIN'],
  782. 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;u=' . $user_id))
  783. );
  784. }
  785. else
  786. {
  787. $template->assign_vars(array(
  788. 'EMAIL' => $email,
  789. 'NAME' => $name,
  790. 'S_LANG_OPTIONS' => language_select($email_lang),
  791. 'L_EMAIL_BODY_EXPLAIN' => $user->lang['EMAIL_TOPIC_EXPLAIN'],
  792. 'S_POST_ACTION' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&amp;t=' . $topic_id))
  793. );
  794. }
  795. $template->assign_vars(array(
  796. 'ERROR_MESSAGE' => (sizeof($error)) ? implode('<br />', $error) : '',
  797. 'SUBJECT' => $subject,
  798. 'MESSAGE' => $message,
  799. )
  800. );
  801. break;
  802. case 'group':
  803. default:
  804. // The basic memberlist
  805. $page_title = $user->lang['MEMBERLIST'];
  806. $template_html = 'memberlist_body.html';
  807. // Sorting
  808. $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']);
  809. $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');
  810. if ($auth->acl_get('a_user'))
  811. {
  812. $sort_key_text['e'] = $user->lang['SORT_EMAIL'];
  813. $sort_key_sql['e'] = 'u.user_email';
  814. }
  815. if ($auth->acl_get('u_viewonline'))
  816. {
  817. $sort_key_text['l'] = $user->lang['SORT_LAST_ACTIVE'];
  818. $sort_key_sql['l'] = 'u.user_lastvisit';
  819. }
  820. $sort_key_text['m'] = $user->lang['SORT_RANK'];
  821. $sort_key_sql['m'] = 'u.user_rank';
  822. $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
  823. $s_sort_key = '';
  824. foreach ($sort_key_text as $key => $value)
  825. {
  826. $selected = ($sort_key == $key) ? ' selected="selected"' : '';
  827. $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  828. }
  829. $s_sort_dir = '';
  830. foreach ($sort_dir_text as $key => $value)
  831. {
  832. $selected = ($sort_dir == $key) ? ' selected="selected"' : '';
  833. $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  834. }
  835. // Additional sorting options for user search ... if search is enabled, if not
  836. // then only admins can make use of this (for ACP functionality)
  837. $sql_select = $sql_where_data = $sql_from = $sql_where = $order_by = '';
  838. $form = request_var('form', '');
  839. $field = request_var('field', '');
  840. $select_single = request_var('select_single', false);
  841. // Search URL parameters, if any of these are in the URL we do a search
  842. $search_params = array('username', 'email', 'icq', 'aim', 'yahoo', 'msn', 'jabber', 'search_group_id', 'joined_select', 'active_select', 'count_select', 'joined', 'active', 'count', 'ip');
  843. // We validate form and field here, only id/class allowed
  844. $form = (!preg_match('/^[a-z0-9_-]+$/i', $form)) ? '' : $form;
  845. $field = (!preg_match('/^[a-z0-9_-]+$/i', $field)) ? '' : $field;
  846. if (($mode == 'searchuser' || sizeof(array_intersect(array_keys($_GET), $search_params)) > 0) && ($config['load_search'] || $auth->acl_get('a_')))
  847. {
  848. $username = request_var('username', '', true);
  849. $email = strtolower(request_var('email', ''));
  850. $icq = request_var('icq', '');
  851. $aim = request_var('aim', '');
  852. $yahoo = request_var('yahoo', '');
  853. $msn = request_var('msn', '');
  854. $jabber = request_var('jabber', '');
  855. $search_group_id = request_var('search_group_id', 0);
  856. // when using these, make sure that we actually have values defined in $find_key_match
  857. $joined_select = request_var('joined_select', 'lt');
  858. $active_select = request_var('active_select', 'lt');
  859. $count_select = request_var('count_select', 'eq');
  860. $joined = explode('-', request_var('joined', ''));
  861. $active = explode('-', request_var('active', ''));
  862. $count = (request_var('count', '') !== '') ? request_var('count', 0) : '';
  863. $ipdomain = request_var('ip', '');
  864. $find_key_match = array('lt' => '<', 'gt' => '>', 'eq' => '=');
  865. $find_count = array('lt' => $user->lang['LESS_THAN'], 'eq' => $user->lang['EQUAL_TO'], 'gt' => $user->lang['MORE_THAN']);
  866. $s_find_count = '';
  867. foreach ($find_count as $key => $value)
  868. {
  869. $selected = ($count_select == $key) ? ' selected="selected"' : '';
  870. $s_find_count .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  871. }
  872. $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']);
  873. $s_find_join_time = '';
  874. foreach ($find_time as $key => $value)
  875. {
  876. $selected = ($joined_select == $key) ? ' selected="selected"' : '';
  877. $s_find_join_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  878. }
  879. $s_find_active_time = '';
  880. foreach ($find_time as $key => $value)
  881. {
  882. $selected = ($active_select == $key) ? ' selected="selected"' : '';
  883. $s_find_active_time .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
  884. }
  885. $sql_where .= ($username) ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
  886. $sql_where .= ($auth->acl_get('a_user') && $email) ? ' AND u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
  887. $sql_where .= ($icq) ? ' AND u.user_icq ' . $db->sql_like_expression(str_replace('*', $db->any_char, $icq)) . ' ' : '';
  888. $sql_where .= ($aim) ? ' AND u.user_aim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $aim)) . ' ' : '';
  889. $sql_where .= ($yahoo) ? ' AND u.user_yim ' . $db->sql_like_expression(str_replace('*', $db->any_char, $yahoo)) . ' ' : '';
  890. $sql_where .= ($msn) ? ' AND u.user_msnm ' . $db->sql_like_expression(str_replace('*', $db->any_char, $msn)) . ' ' : '';
  891. $sql_where .= ($jabber) ? ' AND u.user_jabber ' . $db->sql_like_expression(str_replace('*', $db->any_char, $jabber)) . ' ' : '';
  892. $sql_where .= (is_numeric($count) && isset($find_key_match[$count_select])) ? ' AND u.user_posts ' . $find_key_match[$count_select] . ' ' . (int) $count . ' ' : '';
  893. if (isset($find_key_match[$joined_select]) && sizeof($joined) == 3)
  894. {
  895. // Before PHP 5.1 an error value -1 can be returned instead of false.
  896. // Theoretically gmmktime() can also legitimately return -1 as an actual timestamp.
  897. // But since we do not pass the $second parameter to gmmktime(),
  898. // an actual unix timestamp -1 cannot be returned in this case.
  899. // Thus we can check whether it is -1 and treat -1 as an error.
  900. $joined_time = gmmktime(0, 0, 0, (int) $joined[1], (int) $joined[2], (int) $joined[0]);
  901. if ($joined_time !== false && $joined_time !== -1)
  902. {
  903. $sql_where .= " AND u.user_regdate " . $find_key_match[$joined_select] . ' ' . $joined_time;
  904. }
  905. }
  906. if (isset($find_key_match[$active_select]) && sizeof($active) == 3 && $auth->acl_get('u_viewonline'))
  907. {
  908. $active_time = gmmktime(0, 0, 0, (int) $active[1], (int) $active[2], (int) $active[0]);
  909. if ($active_time !== false && $active_time !== -1)
  910. {
  911. $sql_where .= " AND u.user_lastvisit " . $find_key_match[$active_select] . ' ' . $active_time;
  912. }
  913. }
  914. $sql_where .= ($search_group_id) ? " AND u.user_id = ug.user_id AND ug.group_id = $search_group_id AND ug.user_pending = 0 " : '';
  915. if ($search_group_id)
  916. {
  917. $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
  918. }
  919. if ($ipdomain && $auth->acl_getf_global('m_info'))
  920. {
  921. if (strspn($ipdomain, 'abcdefghijklmnopqrstuvwxyz'))
  922. {
  923. $hostnames = gethostbynamel($ipdomain);
  924. if ($hostnames !== false)
  925. {
  926. $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)))) . "'";
  927. }
  928. else
  929. {
  930. $ips = false;
  931. }
  932. }
  933. else
  934. {
  935. $ips = "'" . str_replace('*', '%', $db->sql_escape($ipdomain)) . "'";
  936. }
  937. if ($ips === false)
  938. {
  939. // A minor fudge but it does the job :D
  940. $sql_where .= " AND u.user_id = 0";
  941. }
  942. else
  943. {
  944. $ip_forums = array_keys($auth->acl_getf('m_info', true));
  945. $sql = 'SELECT DISTINCT poster_id
  946. FROM ' . POSTS_TABLE . '
  947. WHERE poster_ip ' . ((strpos($ips, '%') !== false) ? 'LIKE' : 'IN') . " ($ips)
  948. AND forum_id IN (0, " . implode(', ', $ip_forums) . ')';
  949. $result = $db->sql_query($sql);
  950. if ($row = $db->sql_fetchrow($result))
  951. {
  952. $ip_sql = array();
  953. do
  954. {
  955. $ip_sql[] = $row['poster_id'];
  956. }
  957. while ($row = $db->sql_fetchrow($result));
  958. $sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $ip_sql);
  959. }
  960. else
  961. {
  962. // A minor fudge but it does the job :D
  963. $sql_where .= " AND u.user_id = 0";
  964. }
  965. unset($ip_forums);
  966. $db->sql_freeresult($result);
  967. }
  968. }
  969. }
  970. $first_char = request_var('first_char', '');
  971. if ($first_char == 'other')
  972. {
  973. for ($i = 97; $i < 123; $i++)
  974. {
  975. $sql_where .= ' AND u.username_clean NOT ' . $db->sql_like_expression(chr($i) . $db->any_char);
  976. }
  977. }
  978. else if ($first_char)
  979. {
  980. $sql_where .= ' AND u.username_clean ' . $db->sql_like_expression(substr($first_char, 0, 1) . $db->any_char);
  981. }
  982. // Are we looking at a usergroup? If so, fetch additional info
  983. // and further restrict the user info query
  984. if ($mode == 'group')
  985. {
  986. // We JOIN here to save a query for determining membership for hidden groups. ;)
  987. $sql = 'SELECT g.*, ug.user_id
  988. FROM ' . GROUPS_TABLE . ' g
  989. 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)
  990. WHERE g.group_id = $group_id";
  991. $result = $db->sql_query($sql);
  992. $group_row = $db->sql_fetchrow($result);
  993. $db->sql_freeresult($result);
  994. if (!$group_row)
  995. {
  996. trigger_error('NO_GROUP');
  997. }
  998. switch ($group_row['group_type'])
  999. {
  1000. case GROUP_OPEN:
  1001. $group_row['l_group_type'] = 'OPEN';
  1002. break;
  1003. case GROUP_CLOSED:
  1004. $group_row['l_group_type'] = 'CLOSED';
  1005. break;
  1006. case GROUP_HIDDEN:
  1007. $group_row['l_group_type'] = 'HIDDEN';
  1008. // Check for membership or special permissions
  1009. if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $group_row['user_id'] != $user->data['user_id'])
  1010. {
  1011. trigger_error('NO_GROUP');
  1012. }
  1013. break;
  1014. case GROUP_SPECIAL:
  1015. $group_row['l_group_type'] = 'SPECIAL';
  1016. break;
  1017. case GROUP_FREE:
  1018. $group_row['l_group_type'] = 'FREE';
  1019. break;
  1020. }
  1021. // Misusing the avatar function for displaying group avatars...
  1022. $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');
  1023. $rank_title = $rank_img = $rank_img_src = '';
  1024. if ($group_row['group_rank'])
  1025. {
  1026. if (isset($ranks['special'][$group_row['group_rank']]))
  1027. {
  1028. $rank_title = $ranks['special'][$group_row['group_rank']]['rank_title'];
  1029. }
  1030. $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 />' : '';
  1031. $rank_img_src = (!empty($ranks['special'][$group_row['group_rank']]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$group_row['group_rank']]['rank_image'] : '';
  1032. }
  1033. else
  1034. {
  1035. $rank_title = '';
  1036. $rank_img = '';
  1037. $rank_img_src = '';
  1038. }
  1039. $template->assign_vars(array(
  1040. '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']),
  1041. 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
  1042. 'GROUP_COLOR' => $group_row['group_colour'],
  1043. 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']],
  1044. 'GROUP_RANK' => $rank_title,
  1045. 'AVATAR_IMG' => $avatar_img,
  1046. 'RANK_IMG' => $rank_img,
  1047. 'RANK_IMG_SRC' => $rank_img_src,
  1048. '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) : '',)
  1049. );
  1050. $sql_select = ', ug.group_leader';
  1051. $sql_from = ', ' . USER_GROUP_TABLE . ' ug ';
  1052. $order_by = 'ug.group_leader DESC, ';
  1053. $sql_where .= " AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = $group_id";
  1054. $sql_where_data = " AND u.user_id = ug.user_id AND ug.group_id = $group_id";
  1055. }
  1056. // Sorting and order
  1057. if (!isset($sort_key_sql[$sort_key]))
  1058. {
  1059. $sort_key = $default_key;
  1060. }
  1061. $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');
  1062. // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
  1063. if ($sort_key == 'm')
  1064. {
  1065. $order_by .= ', u.user_posts DESC';
  1066. }
  1067. // Count the users ...
  1068. if ($sql_where)
  1069. {
  1070. $sql = 'SELECT COUNT(u.user_id) AS total_users
  1071. FROM ' . USERS_TABLE . " u$sql_from
  1072. WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
  1073. $sql_where";
  1074. $result = $db->sql_query($sql);
  1075. $total_users = (int) $db->sql_fetchfield('total_users');
  1076. $db->sql_freeresult($result);
  1077. }
  1078. else
  1079. {
  1080. $total_users = $config['num_users'];
  1081. }
  1082. $s_char_options = '<option value=""' . ((!$first_char) ? ' selected="selected"' : '') . '>&nbsp; &nbsp;</option>';
  1083. for ($i = 97; $i < 123; $i++)
  1084. {
  1085. $s_char_options .= '<option value="' . chr($i) . '"' . (($first_char == chr($i)) ? ' selected="selected"' : '') . '>' . chr($i-32) . '</option>';
  1086. }
  1087. $s_char_options .= '<option value="other"' . (($first_char == 'other') ? ' selected="selected"' : '') . '>' . $user->lang['OTHER'] . '</option>';
  1088. // Build a relevant pagination_url
  1089. $params = $sort_params = array();
  1090. // We do not use request_var() here directly to save some calls (not all variables are set)
  1091. $check_params = array(
  1092. 'g' => array('g', 0),
  1093. 'sk' => array('sk', $default_key),
  1094. 'sd' => array('sd', 'a'),
  1095. 'form' => array('form', ''),
  1096. 'field' => array('field', ''),
  1097. 'select_single' => array('select_single', $select_single),
  1098. 'username' => array('username', '', true),
  1099. 'email' => array('email', ''),
  1100. 'icq' => array('icq', ''),
  1101. 'aim' => array('aim', ''),
  1102. 'yahoo' => array('yahoo', ''),
  1103. 'msn' => array('msn', ''),
  1104. 'jabber' => array('jabber', ''),
  1105. 'search_group_id' => array('search_group_id', 0),
  1106. 'joined_select' => array('joined_select', 'lt'),
  1107. 'active_select' => array('active_select', 'lt'),
  1108. 'count_select' => array('count_select', 'eq'),
  1109. 'joined' => array('joined', ''),
  1110. 'active' => array('active', ''),
  1111. 'count' => (request_var('count', '') !== '') ? array('count', 0) : array('count', ''),
  1112. 'ip' => array('ip', ''),
  1113. 'first_char' => array('first_char', ''),
  1114. );
  1115. foreach ($check_params as $key => $call)
  1116. {
  1117. if (!isset($_REQUEST[$key]))
  1118. {
  1119. continue;
  1120. }
  1121. $param = call_user_func_array('request_var', $call);
  1122. $param = urlencode($key) . '=' . ((is_string($param)) ? urlencode($param) : $param);
  1123. $params[] = $param;
  1124. if ($key != 'sk' && $key != 'sd')
  1125. {
  1126. $sort_params[] = $param;
  1127. }
  1128. }
  1129. $u_hide_find_member = append_sid("{$phpbb_root_path}memberlist.$phpEx", "start=$start" . (!empty($params) ? '&amp;' . implode('&amp;', $params) : ''));
  1130. if ($mode)
  1131. {
  1132. $params[] = "mode=$mode";
  1133. }
  1134. $sort_params[] = "mode=$mode";
  1135. $pagination_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $params));
  1136. $sort_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", implode('&amp;', $sort_params));
  1137. unset($search_params, $sort_params);
  1138. // Some search user specific data
  1139. if ($mode == 'searchuser' && ($config['load_search'] || $auth->acl_get('a_')))
  1140. {
  1141. $group_selected = request_var('search_group_id', 0);
  1142. $s_group_select = '<option value="0"' . ((!$group_selected) ? ' selected="selected"' : '') . '>&nbsp;</option>';
  1143. $group_ids = array();
  1144. /**
  1145. * @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)
  1146. */
  1147. if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
  1148. {
  1149. $sql = 'SELECT group_id, group_name, group_type
  1150. FROM ' . GROUPS_TABLE;
  1151. if (!$config['coppa_enable'])
  1152. {
  1153. $sql .= " WHERE group_name <> 'REGISTERED_COPPA'";
  1154. }
  1155. $sql .= ' ORDER BY group_name ASC';
  1156. }
  1157. else
  1158. {
  1159. $sql = 'SELECT g.group_id, g.group_name, g.group_type
  1160. FROM ' . GROUPS_TABLE . ' g
  1161. LEFT JOIN ' . USER_GROUP_TABLE . ' ug
  1162. ON (
  1163. g.group_id = ug.group_id
  1164. AND ug.user_id = ' . $user->data['user_id'] . '
  1165. AND ug.user_pending = 0
  1166. )
  1167. WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
  1168. if (!$config['coppa_enable'])
  1169. {
  1170. $sql .= " AND g.group_name <> 'REGISTERED_COPPA'";
  1171. }
  1172. $sql .= ' ORDER BY g.group_name ASC';
  1173. }
  1174. $result = $db->sql_query($sql);
  1175. while ($row = $db->sql_fetchrow($result))
  1176. {
  1177. $group_ids[] = $row['group_id'];
  1178. $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>';
  1179. }
  1180. $db->sql_freeresult($result);
  1181. if ($group_selected !== 0 && !in_array($group_selected, $group_ids))
  1182. {
  1183. trigger_error('NO_GROUP');
  1184. }
  1185. $template->assign_vars(array(
  1186. 'USERNAME' => $username,
  1187. 'EMAIL' => $email,
  1188. 'ICQ' => $icq,
  1189. 'AIM' => $aim,
  1190. 'YAHOO' => $yahoo,
  1191. 'MSNM' => $msn,
  1192. 'JABBER' => $jabber,
  1193. 'JOINED' => implode('-', $joined),
  1194. 'ACTIVE' => implode('-', $active),
  1195. 'COUNT' => $count,
  1196. 'IP' => $ipdomain,
  1197. 'S_IP_SEARCH_ALLOWED' => ($auth->acl_getf_global('m_info')) ? true : false,
  1198. 'S_EMAIL_SEARCH_ALLOWED'=> ($auth->acl_get('a_user')) ? true : false,
  1199. 'S_IN_SEARCH_POPUP' => ($form && $field) ? true : false,
  1200. 'S_SEARCH_USER'

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