Memberlist.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /* This file contains the functions for displaying and searching in the
  15. members list. It does so with these functions:
  16. void MemberList()
  17. - shows a list of registered members.
  18. - if a subaction is not specified, lists all registered members.
  19. - allows searching for members with the 'search' sub action.
  20. - calls MLAll or MLSearch depending on the sub action.
  21. - uses the Memberlist template with the main sub template.
  22. - requires the view_mlist permission.
  23. - is accessed via ?action=mlist.
  24. void MLAll()
  25. - used to display all members on a page by page basis with sorting.
  26. - called from MemberList().
  27. - can be passed a sort parameter, to order the display of members.
  28. - calls printMemberListRows to retrieve the results of the query.
  29. void MLSearch()
  30. - used to search for members or display search results.
  31. - called by MemberList().
  32. - if variable 'search' is empty displays search dialog box, using the
  33. search sub template.
  34. - calls printMemberListRows to retrieve the results of the query.
  35. void printMemberListRows(resource request)
  36. - retrieves results of the request passed to it
  37. - puts results of request into the context for the sub template.
  38. */
  39. // Show a listing of the registered members.
  40. function Memberlist()
  41. {
  42. global $scripturl, $txt, $modSettings, $context, $settings, $modSettings;
  43. // Make sure they can view the memberlist.
  44. isAllowedTo('view_mlist');
  45. loadTemplate('Memberlist');
  46. $context['listing_by'] = !empty($_GET['sa']) ? $_GET['sa'] : 'all';
  47. // $subActions array format:
  48. // 'subaction' => array('label', 'function', 'is_selected')
  49. $subActions = array(
  50. 'all' => array($txt['view_all_members'], 'MLAll', $context['listing_by'] == 'all'),
  51. 'search' => array($txt['mlist_search'], 'MLSearch', $context['listing_by'] == 'search'),
  52. );
  53. // Set up the sort links.
  54. $context['sort_links'] = array();
  55. foreach ($subActions as $act => $text)
  56. $context['sort_links'][] = array(
  57. 'label' => $text[0],
  58. 'action' => $act,
  59. 'selected' => $text[2],
  60. );
  61. $context['num_members'] = $modSettings['totalMembers'];
  62. // Set up the columns...
  63. $context['columns'] = array(
  64. 'is_online' => array(
  65. 'label' => $txt['status'],
  66. 'width' => '60',
  67. 'class' => 'first_th',
  68. ),
  69. 'real_name' => array(
  70. 'label' => $txt['username']
  71. ),
  72. 'email_address' => array(
  73. 'label' => $txt['email'],
  74. 'width' => '25'
  75. ),
  76. 'website_url' => array(
  77. 'label' => $txt['website'],
  78. 'width' => '70',
  79. 'link_with' => 'website',
  80. ),
  81. 'icq' => array(
  82. 'label' => $txt['icq'],
  83. 'width' => '30'
  84. ),
  85. 'aim' => array(
  86. 'label' => $txt['aim'],
  87. 'width' => '30'
  88. ),
  89. 'yim' => array(
  90. 'label' => $txt['yim'],
  91. 'width' => '30'
  92. ),
  93. 'msn' => array(
  94. 'label' => $txt['msn'],
  95. 'width' => '30'
  96. ),
  97. 'id_group' => array(
  98. 'label' => $txt['position']
  99. ),
  100. 'registered' => array(
  101. 'label' => $txt['date_registered']
  102. ),
  103. 'posts' => array(
  104. 'label' => $txt['posts'],
  105. 'width' => '115',
  106. 'colspan' => '2',
  107. 'default_sort_rev' => true,
  108. )
  109. );
  110. $context['colspan'] = 0;
  111. $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
  112. foreach ($context['columns'] as $key => $column)
  113. {
  114. if (isset($context['disabled_fields'][$key]) || (isset($column['link_with']) && isset($context['disabled_fields'][$column['link_with']])))
  115. {
  116. unset($context['columns'][$key]);
  117. continue;
  118. }
  119. $context['colspan'] += isset($column['colspan']) ? $column['colspan'] : 1;
  120. }
  121. // Aesthetic stuff.
  122. end($context['columns']);
  123. $context['columns'][key($context['columns'])]['class'] = 'last_th';
  124. $context['linktree'][] = array(
  125. 'url' => $scripturl . '?action=mlist',
  126. 'name' => $txt['members_list']
  127. );
  128. $context['can_send_pm'] = allowedTo('pm_send');
  129. // Jump to the sub action.
  130. if (isset($subActions[$context['listing_by']]))
  131. $subActions[$context['listing_by']][1]();
  132. else
  133. $subActions['all'][1]();
  134. }
  135. // List all members, page by page.
  136. function MLAll()
  137. {
  138. global $txt, $scripturl, $user_info;
  139. global $modSettings, $context, $smcFunc;
  140. // The chunk size for the cached index.
  141. $cache_step_size = 500;
  142. // Only use caching if:
  143. // 1. there are at least 2k members,
  144. // 2. the default sorting method (real_name) is being used,
  145. // 3. the page shown is high enough to make a DB filesort unprofitable.
  146. $use_cache = $modSettings['totalMembers'] > 2000 && (!isset($_REQUEST['sort']) || $_REQUEST['sort'] === 'real_name') && isset($_REQUEST['start']) && $_REQUEST['start'] > $cache_step_size;
  147. if ($use_cache)
  148. {
  149. // Maybe there's something cached already.
  150. if (!empty($modSettings['memberlist_cache']))
  151. $memberlist_cache = @unserialize($modSettings['memberlist_cache']);
  152. // The chunk size for the cached index.
  153. $cache_step_size = 500;
  154. // Only update the cache if something changed or no cache existed yet.
  155. if (empty($memberlist_cache) || empty($modSettings['memberlist_updated']) || $memberlist_cache['last_update'] < $modSettings['memberlist_updated'])
  156. {
  157. $request = $smcFunc['db_query']('', '
  158. SELECT real_name
  159. FROM {db_prefix}members
  160. WHERE is_activated = {int:is_activated}
  161. ORDER BY real_name',
  162. array(
  163. 'is_activated' => 1,
  164. )
  165. );
  166. $memberlist_cache = array(
  167. 'last_update' => time(),
  168. 'num_members' => $smcFunc['db_num_rows']($request),
  169. 'index' => array(),
  170. );
  171. for ($i = 0, $n = $smcFunc['db_num_rows']($request); $i < $n; $i += $cache_step_size)
  172. {
  173. $smcFunc['db_data_seek']($request, $i);
  174. list($memberlist_cache['index'][$i]) = $smcFunc['db_fetch_row']($request);
  175. }
  176. $smcFunc['db_data_seek']($request, $memberlist_cache['num_members'] - 1);
  177. list ($memberlist_cache['index'][$i]) = $smcFunc['db_fetch_row']($request);
  178. $smcFunc['db_free_result']($request);
  179. // Now we've got the cache...store it.
  180. updateSettings(array('memberlist_cache' => serialize($memberlist_cache)));
  181. }
  182. $context['num_members'] = $memberlist_cache['num_members'];
  183. }
  184. // Without cache we need an extra query to get the amount of members.
  185. else
  186. {
  187. $request = $smcFunc['db_query']('', '
  188. SELECT COUNT(*)
  189. FROM {db_prefix}members
  190. WHERE is_activated = {int:is_activated}',
  191. array(
  192. 'is_activated' => 1,
  193. )
  194. );
  195. list ($context['num_members']) = $smcFunc['db_fetch_row']($request);
  196. $smcFunc['db_free_result']($request);
  197. }
  198. // Set defaults for sort (real_name) and start. (0)
  199. if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
  200. $_REQUEST['sort'] = 'real_name';
  201. if (!is_numeric($_REQUEST['start']))
  202. {
  203. if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0)
  204. fatal_error('Hacker?', false);
  205. $_REQUEST['start'] = $match[0];
  206. $request = $smcFunc['db_query']('substring', '
  207. SELECT COUNT(*)
  208. FROM {db_prefix}members
  209. WHERE LOWER(SUBSTRING(real_name, 1, 1)) < {string:first_letter}
  210. AND is_activated = {int:is_activated}',
  211. array(
  212. 'is_activated' => 1,
  213. 'first_letter' => $_REQUEST['start'],
  214. )
  215. );
  216. list ($_REQUEST['start']) = $smcFunc['db_fetch_row']($request);
  217. $smcFunc['db_free_result']($request);
  218. }
  219. $context['letter_links'] = '';
  220. for ($i = 97; $i < 123; $i++)
  221. $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> ';
  222. // Sort out the column information.
  223. foreach ($context['columns'] as $col => $column_details)
  224. {
  225. $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0';
  226. if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev'])))
  227. $context['columns'][$col]['href'] .= ';desc';
  228. $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>';
  229. $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col;
  230. }
  231. $context['sort_by'] = $_REQUEST['sort'];
  232. $context['sort_direction'] = !isset($_REQUEST['desc']) ? 'up' : 'down';
  233. // Construct the page index.
  234. $context['page_index'] = constructPageIndex($scripturl . '?action=mlist;sort=' . $_REQUEST['sort'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $context['num_members'], $modSettings['defaultMaxMembers']);
  235. // Send the data to the template.
  236. $context['start'] = $_REQUEST['start'] + 1;
  237. $context['end'] = min($_REQUEST['start'] + $modSettings['defaultMaxMembers'], $context['num_members']);
  238. $context['can_moderate_forum'] = allowedTo('moderate_forum');
  239. $context['page_title'] = sprintf($txt['viewing_members'], $context['start'], $context['end']);
  240. $context['linktree'][] = array(
  241. 'url' => $scripturl . '?action=mlist;sort=' . $_REQUEST['sort'] . ';start=' . $_REQUEST['start'],
  242. 'name' => &$context['page_title'],
  243. 'extra_after' => ' (' . sprintf($txt['of_total_members'], $context['num_members']) . ')'
  244. );
  245. // List out the different sorting methods...
  246. $sort_methods = array(
  247. 'is_online' => array(
  248. 'down' => allowedTo('moderate_forum') ? 'IFNULL(lo.log_time, 1) ASC, real_name ASC' : 'IF(mem.show_online, IFNULL(lo.log_time, 1), 1) ASC, real_name ASC',
  249. 'up' => allowedTo('moderate_forum') ? 'IFNULL(lo.log_time, 1) DESC, real_name DESC' : 'IF(mem.show_online, IFNULL(lo.log_time, 1), 1) DESC, real_name DESC'
  250. ),
  251. 'real_name' => array(
  252. 'down' => 'mem.real_name DESC',
  253. 'up' => 'mem.real_name ASC'
  254. ),
  255. 'email_address' => array(
  256. 'down' => allowedTo('moderate_forum') ? 'mem.email_address DESC' : 'mem.hide_email DESC, mem.email_address DESC',
  257. 'up' => allowedTo('moderate_forum') ? 'mem.email_address ASC' : 'mem.hide_email ASC, mem.email_address ASC'
  258. ),
  259. 'website_url' => array(
  260. 'down' => 'LENGTH(mem.website_url) > 0 ASC, IFNULL(mem.website_url, 1=1) DESC, mem.website_url DESC',
  261. 'up' => 'LENGTH(mem.website_url) > 0 DESC, IFNULL(mem.website_url, 1=1) ASC, mem.website_url ASC'
  262. ),
  263. 'icq' => array(
  264. 'down' => 'LENGTH(mem.icq) > 0 ASC, mem.icq = 0 DESC, mem.icq DESC',
  265. 'up' => 'LENGTH(mem.icq) > 0 DESC, mem.icq = 0 ASC, mem.icq ASC'
  266. ),
  267. 'aim' => array(
  268. 'down' => 'LENGTH(mem.aim) > 0 ASC, IFNULL(mem.aim, 1=1) DESC, mem.aim DESC',
  269. 'up' => 'LENGTH(mem.aim) > 0 DESC, IFNULL(mem.aim, 1=1) ASC, mem.aim ASC'
  270. ),
  271. 'yim' => array(
  272. 'down' => 'LENGTH(mem.yim) > 0 ASC, IFNULL(mem.yim, 1=1) DESC, mem.yim DESC',
  273. 'up' => 'LENGTH(mem.yim) > 0 DESC, IFNULL(mem.yim, 1=1) ASC, mem.yim ASC'
  274. ),
  275. 'msn' => array(
  276. 'down' => 'LENGTH(mem.msn) > 0 ASC, IFNULL(mem.msn, 1=1) DESC, mem.msn DESC',
  277. 'up' => 'LENGTH(mem.msn) > 0 DESC, IFNULL(mem.msn, 1=1) ASC, mem.msn ASC'
  278. ),
  279. 'registered' => array(
  280. 'down' => 'mem.date_registered DESC',
  281. 'up' => 'mem.date_registered ASC'
  282. ),
  283. 'id_group' => array(
  284. 'down' => 'IFNULL(mg.group_name, 1=1) DESC, mg.group_name DESC',
  285. 'up' => 'IFNULL(mg.group_name, 1=1) ASC, mg.group_name ASC'
  286. ),
  287. 'posts' => array(
  288. 'down' => 'mem.posts DESC',
  289. 'up' => 'mem.posts ASC'
  290. )
  291. );
  292. $limit = $_REQUEST['start'];
  293. $query_parameters = array(
  294. 'regular_id_group' => 0,
  295. 'is_activated' => 1,
  296. 'sort' => $sort_methods[$_REQUEST['sort']][$context['sort_direction']],
  297. );
  298. // Using cache allows to narrow down the list to be retrieved.
  299. if ($use_cache && $_REQUEST['sort'] === 'real_name' && !isset($_REQUEST['desc']))
  300. {
  301. $first_offset = $_REQUEST['start'] - ($_REQUEST['start'] % $cache_step_size);
  302. $second_offset = ceil(($_REQUEST['start'] + $modSettings['defaultMaxMembers']) / $cache_step_size) * $cache_step_size;
  303. $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}';
  304. $query_parameters['real_name_low'] = $memberlist_cache['index'][$first_offset];
  305. $query_parameters['real_name_high'] = $memberlist_cache['index'][$second_offset];
  306. $limit -= $first_offset;
  307. }
  308. // Reverse sorting is a bit more complicated...
  309. elseif ($use_cache && $_REQUEST['sort'] === 'real_name')
  310. {
  311. $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
  312. if ($first_offset < 0)
  313. $first_offset = 0;
  314. $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size;
  315. $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}';
  316. $query_parameters['real_name_low'] = $memberlist_cache['index'][$first_offset];
  317. $query_parameters['real_name_high'] = $memberlist_cache['index'][$second_offset];
  318. $limit = $second_offset - ($memberlist_cache['num_members'] - $_REQUEST['start']) - ($second_offset > $memberlist_cache['num_members'] ? $cache_step_size - ($memberlist_cache['num_members'] % $cache_step_size) : 0);
  319. }
  320. // Select the members from the database.
  321. $request = $smcFunc['db_query']('', '
  322. SELECT mem.id_member
  323. FROM {db_prefix}members AS mem' . ($_REQUEST['sort'] === 'is_online' ? '
  324. LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)' : '') . ($_REQUEST['sort'] === 'id_group' ? '
  325. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' : '') . '
  326. WHERE mem.is_activated = {int:is_activated}' . (empty($where) ? '' : '
  327. AND ' . $where) . '
  328. ORDER BY {raw:sort}
  329. LIMIT ' . $limit . ', ' . $modSettings['defaultMaxMembers'],
  330. $query_parameters
  331. );
  332. printMemberListRows($request);
  333. $smcFunc['db_free_result']($request);
  334. // Add anchors at the start of each letter.
  335. if ($_REQUEST['sort'] == 'real_name')
  336. {
  337. $last_letter = '';
  338. foreach ($context['members'] as $i => $dummy)
  339. {
  340. $this_letter = $smcFunc['strtolower']($smcFunc['substr']($context['members'][$i]['name'], 0, 1));
  341. if ($this_letter != $last_letter && preg_match('~[a-z]~', $this_letter) === 1)
  342. {
  343. $context['members'][$i]['sort_letter'] = htmlspecialchars($this_letter);
  344. $last_letter = $this_letter;
  345. }
  346. }
  347. }
  348. }
  349. // Search for members...
  350. function MLSearch()
  351. {
  352. global $txt, $scripturl, $context, $user_info, $modSettings, $smcFunc;
  353. $context['page_title'] = $txt['mlist_search'];
  354. $context['can_moderate_forum'] = allowedTo('moderate_forum');
  355. // Can they search custom fields?
  356. $request = $smcFunc['db_query']('', '
  357. SELECT col_name, field_name, field_desc
  358. FROM {db_prefix}custom_fields
  359. WHERE active = {int:active}
  360. ' . (allowedTo('admin_forum') ? '' : ' AND private < {int:private_level}') . '
  361. AND can_search = {int:can_search}
  362. AND (field_type = {string:field_type_text} OR field_type = {string:field_type_textarea})',
  363. array(
  364. 'active' => 1,
  365. 'can_search' => 1,
  366. 'private_level' => 2,
  367. 'field_type_text' => 'text',
  368. 'field_type_textarea' => 'textarea',
  369. )
  370. );
  371. $context['custom_search_fields'] = array();
  372. while ($row = $smcFunc['db_fetch_assoc']($request))
  373. $context['custom_search_fields'][$row['col_name']] = array(
  374. 'colname' => $row['col_name'],
  375. 'name' => $row['field_name'],
  376. 'desc' => $row['field_desc'],
  377. );
  378. $smcFunc['db_free_result']($request);
  379. // They're searching..
  380. if (isset($_REQUEST['search']) && isset($_REQUEST['fields']))
  381. {
  382. $_POST['search'] = trim(isset($_GET['search']) ? $_GET['search'] : $_POST['search']);
  383. $_POST['fields'] = isset($_GET['fields']) ? explode(',', $_GET['fields']) : $_POST['fields'];
  384. $context['old_search'] = $_REQUEST['search'];
  385. $context['old_search_value'] = urlencode($_REQUEST['search']);
  386. // No fields? Use default...
  387. if (empty($_POST['fields']))
  388. $_POST['fields'] = array('name');
  389. $query_parameters = array(
  390. 'regular_id_group' => 0,
  391. 'is_activated' => 1,
  392. 'blank_string' => '',
  393. 'search' => '%' . strtr($smcFunc['htmlspecialchars']($_POST['search'], ENT_QUOTES), array('_' => '\\_', '%' => '\\%', '*' => '%')) . '%',
  394. );
  395. // Search for a name?
  396. if (in_array('name', $_POST['fields']))
  397. $fields = array('member_name', 'real_name');
  398. else
  399. $fields = array();
  400. // Search for messengers...
  401. if (in_array('messenger', $_POST['fields']) && (!$user_info['is_guest'] || empty($modSettings['guest_hideContacts'])))
  402. $fields += array(3 => 'msn', 'aim', 'icq', 'yim');
  403. // Search for websites.
  404. if (in_array('website', $_POST['fields']))
  405. $fields += array(7 => 'website_title', 'website_url');
  406. // Search for groups.
  407. if (in_array('group', $_POST['fields']))
  408. $fields += array(9 => 'IFNULL(group_name, {string:blank_string})');
  409. // Search for an email address?
  410. if (in_array('email', $_POST['fields']))
  411. {
  412. $fields += array(2 => allowedTo('moderate_forum') ? 'email_address' : '(hide_email = 0 AND email_address');
  413. $condition = allowedTo('moderate_forum') ? '' : ')';
  414. }
  415. else
  416. $condition = '';
  417. $customJoin = array();
  418. $customCount = 10;
  419. // Any custom fields to search for - these being tricky?
  420. foreach ($_POST['fields'] as $field)
  421. {
  422. $curField = substr($field, 5);
  423. if (substr($field, 0, 5) == 'cust_' && isset($context['custom_search_fields'][$curField]))
  424. {
  425. $customJoin[] = 'LEFT JOIN {db_prefix}themes AS t' . $curField . ' ON (t' . $curField . '.variable = {string:t' . $curField . '} AND t' . $curField . '.id_theme = 1 AND t' . $curField . '.id_member = mem.id_member)';
  426. $query_parameters['t' . $curField] = $curField;
  427. $fields += array($customCount++ => 'IFNULL(t' . $curField . '.value, {string:blank_string})');
  428. }
  429. }
  430. $query = $_POST['search'] == '' ? '= {string:blank_string}' : 'LIKE {string:search}';
  431. $request = $smcFunc['db_query']('', '
  432. SELECT COUNT(*)
  433. FROM {db_prefix}members AS mem
  434. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' .
  435. (empty($customJoin) ? '' : implode('
  436. ', $customJoin)) . '
  437. WHERE (' . implode( ' ' . $query . ' OR ', $fields) . ' ' . $query . $condition . ')
  438. AND mem.is_activated = {int:is_activated}',
  439. $query_parameters
  440. );
  441. list ($numResults) = $smcFunc['db_fetch_row']($request);
  442. $smcFunc['db_free_result']($request);
  443. $context['page_index'] = constructPageIndex($scripturl . '?action=mlist;sa=search;search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']), $_REQUEST['start'], $numResults, $modSettings['defaultMaxMembers']);
  444. // Find the members from the database.
  445. // !!!SLOW This query is slow.
  446. $request = $smcFunc['db_query']('', '
  447. SELECT mem.id_member
  448. FROM {db_prefix}members AS mem
  449. LEFT JOIN {db_prefix}log_online AS lo ON (lo.id_member = mem.id_member)
  450. LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' .
  451. (empty($customJoin) ? '' : implode('
  452. ', $customJoin)) . '
  453. WHERE (' . implode( ' ' . $query . ' OR ', $fields) . ' ' . $query . $condition . ')
  454. AND mem.is_activated = {int:is_activated}
  455. LIMIT ' . $_REQUEST['start'] . ', ' . $modSettings['defaultMaxMembers'],
  456. $query_parameters
  457. );
  458. printMemberListRows($request);
  459. $smcFunc['db_free_result']($request);
  460. }
  461. else
  462. {
  463. // These are all the possible fields.
  464. $context['search_fields'] = array(
  465. 'name' => $txt['mlist_search_name'],
  466. 'email' => $txt['mlist_search_email'],
  467. 'messenger' => $txt['mlist_search_messenger'],
  468. 'website' => $txt['mlist_search_website'],
  469. 'group' => $txt['mlist_search_group'],
  470. );
  471. foreach ($context['custom_search_fields'] as $field)
  472. $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']);
  473. // What do we search for by default?
  474. $context['search_defaults'] = array('name', 'email');
  475. $context['sub_template'] = 'search';
  476. $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? htmlspecialchars($_POST['search']) : '');
  477. }
  478. $context['linktree'][] = array(
  479. 'url' => $scripturl . '?action=mlist;sa=search',
  480. 'name' => &$context['page_title']
  481. );
  482. }
  483. function printMemberListRows($request)
  484. {
  485. global $scripturl, $txt, $user_info, $modSettings;
  486. global $context, $settings, $memberContext, $smcFunc;
  487. // Get the most posts.
  488. $result = $smcFunc['db_query']('', '
  489. SELECT MAX(posts)
  490. FROM {db_prefix}members',
  491. array(
  492. )
  493. );
  494. list ($MOST_POSTS) = $smcFunc['db_fetch_row']($result);
  495. $smcFunc['db_free_result']($result);
  496. // Avoid division by zero...
  497. if ($MOST_POSTS == 0)
  498. $MOST_POSTS = 1;
  499. $members = array();
  500. while ($row = $smcFunc['db_fetch_assoc']($request))
  501. $members[] = $row['id_member'];
  502. // Load all the members for display.
  503. loadMemberData($members);
  504. $context['members'] = array();
  505. foreach ($members as $member)
  506. {
  507. if (!loadMemberContext($member))
  508. continue;
  509. $context['members'][$member] = $memberContext[$member];
  510. $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $MOST_POSTS);
  511. $context['members'][$member]['registered_date'] = strftime('%Y-%m-%d', $context['members'][$member]['registered_timestamp']);
  512. }
  513. }
  514. ?>