PageRenderTime 78ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/sources/admin/ManageMembers.php

https://github.com/Arantor/Elkarte
PHP | 1299 lines | 1029 code | 107 blank | 163 comment | 163 complexity | cb27f96996ef9ca34723d134b13c8e4c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /**
  3. * @name ElkArte Forum
  4. * @copyright ElkArte Forum contributors
  5. * @license BSD http://opensource.org/licenses/BSD-3-Clause
  6. *
  7. * This software is a derived product, based on:
  8. *
  9. * Simple Machines Forum (SMF)
  10. * copyright: 2011 Simple Machines (http://www.simplemachines.org)
  11. * license: BSD, See included LICENSE.TXT for terms and conditions.
  12. *
  13. * @version 1.0 Alpha
  14. *
  15. * Show a list of members or a selection of members.
  16. *
  17. */
  18. if (!defined('ELKARTE'))
  19. die('No access...');
  20. /**
  21. * The main entrance point for the Manage Members screen.
  22. * As everyone else, it calls a function based on the given sub-action.
  23. * Called by ?action=admin;area=viewmembers.
  24. * Requires the moderate_forum permission.
  25. *
  26. * @uses ManageMembers template
  27. * @uses ManageMembers language file.
  28. */
  29. function ViewMembers()
  30. {
  31. global $txt, $scripturl, $context, $modSettings, $smcFunc;
  32. $subActions = array(
  33. 'all' => array('ViewMemberlist', 'moderate_forum'),
  34. 'approve' => array('AdminApprove', 'moderate_forum'),
  35. 'browse' => array('MembersAwaitingActivation', 'moderate_forum'),
  36. 'search' => array('SearchMembers', 'moderate_forum'),
  37. 'query' => array('ViewMemberlist', 'moderate_forum'),
  38. );
  39. call_integration_hook('integrate_manage_members', array($subActions));
  40. // Default to sub action 'index' or 'settings' depending on permissions.
  41. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'all';
  42. // We know the sub action, now we know what you're allowed to do.
  43. isAllowedTo($subActions[$_REQUEST['sa']][1]);
  44. // Load the essentials.
  45. loadLanguage('ManageMembers');
  46. loadTemplate('ManageMembers');
  47. // Get counts on every type of activation - for sections and filtering alike.
  48. $request = $smcFunc['db_query']('', '
  49. SELECT COUNT(*) AS total_members, is_activated
  50. FROM {db_prefix}members
  51. WHERE is_activated != {int:is_activated}
  52. GROUP BY is_activated',
  53. array(
  54. 'is_activated' => 1,
  55. )
  56. );
  57. $context['activation_numbers'] = array();
  58. $context['awaiting_activation'] = 0;
  59. $context['awaiting_approval'] = 0;
  60. while ($row = $smcFunc['db_fetch_assoc']($request))
  61. $context['activation_numbers'][$row['is_activated']] = $row['total_members'];
  62. $smcFunc['db_free_result']($request);
  63. foreach ($context['activation_numbers'] as $activation_type => $total_members)
  64. {
  65. if (in_array($activation_type, array(0, 2)))
  66. $context['awaiting_activation'] += $total_members;
  67. elseif (in_array($activation_type, array(3, 4, 5)))
  68. $context['awaiting_approval'] += $total_members;
  69. }
  70. // For the page header... do we show activation?
  71. $context['show_activate'] = (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) || !empty($context['awaiting_activation']);
  72. // What about approval?
  73. $context['show_approve'] = (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 2) || !empty($context['awaiting_approval']) || !empty($modSettings['approveAccountDeletion']);
  74. // Setup the admin tabs.
  75. $context[$context['admin_menu_name']]['tab_data'] = array(
  76. 'title' => $txt['admin_members'],
  77. 'help' => 'view_members',
  78. 'description' => $txt['admin_members_list'],
  79. 'tabs' => array(),
  80. );
  81. $context['tabs'] = array(
  82. 'viewmembers' => array(
  83. 'label' => $txt['view_all_members'],
  84. 'description' => $txt['admin_members_list'],
  85. 'url' => $scripturl . '?action=admin;area=viewmembers;sa=all',
  86. 'is_selected' => $_REQUEST['sa'] == 'all',
  87. ),
  88. 'search' => array(
  89. 'label' => $txt['mlist_search'],
  90. 'description' => $txt['admin_members_list'],
  91. 'url' => $scripturl . '?action=admin;area=viewmembers;sa=search',
  92. 'is_selected' => $_REQUEST['sa'] == 'search' || $_REQUEST['sa'] == 'query',
  93. ),
  94. 'approve' => array(
  95. 'label' => sprintf($txt['admin_browse_awaiting_approval'], $context['awaiting_approval']),
  96. 'description' => $txt['admin_browse_approve_desc'],
  97. 'url' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=approve',
  98. 'is_selected' => false,
  99. ),
  100. 'activate' => array(
  101. 'label' => sprintf($txt['admin_browse_awaiting_activate'], $context['awaiting_activation']),
  102. 'description' => $txt['admin_browse_activate_desc'],
  103. 'url' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=activate',
  104. 'is_selected' => false,
  105. 'is_last' => true,
  106. ),
  107. );
  108. // Sort out the tabs for the ones which may not exist!
  109. if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
  110. {
  111. $context['tabs']['approve']['is_last'] = true;
  112. unset($context['tabs']['activate']);
  113. }
  114. if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
  115. {
  116. if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
  117. $context['tabs']['search']['is_last'] = true;
  118. unset($context['tabs']['approve']);
  119. }
  120. $subActions[$_REQUEST['sa']][0]();
  121. }
  122. /**
  123. * View all members list. It allows sorting on several columns, and deletion of
  124. * selected members. It also handles the search query sent by
  125. * ?action=admin;area=viewmembers;sa=search.
  126. * Called by ?action=admin;area=viewmembers;sa=all or ?action=admin;area=viewmembers;sa=query.
  127. * Requires the moderate_forum permission.
  128. *
  129. * @uses the view_members sub template of the ManageMembers template.
  130. */
  131. function ViewMemberlist()
  132. {
  133. global $txt, $scripturl, $context, $modSettings, $smcFunc, $user_info;
  134. // Set the current sub action.
  135. $context['sub_action'] = $_REQUEST['sa'];
  136. // Are we performing a delete?
  137. if (isset($_POST['delete_members']) && !empty($_POST['delete']) && allowedTo('profile_remove_any'))
  138. {
  139. checkSession();
  140. // Clean the input.
  141. foreach ($_POST['delete'] as $key => $value)
  142. {
  143. // Don't delete yourself, idiot.
  144. if ($value != $user_info['id'])
  145. $delete[$key] = (int) $value;
  146. }
  147. if (!empty($delete))
  148. {
  149. // Delete all the selected members.
  150. require_once(SUBSDIR . '/Members.subs.php');
  151. deleteMembers($delete, true);
  152. }
  153. }
  154. // Check input after a member search has been submitted.
  155. if ($context['sub_action'] == 'query')
  156. {
  157. // Retrieving the membergroups and postgroups.
  158. $context['membergroups'] = array(
  159. array(
  160. 'id' => 0,
  161. 'name' => $txt['membergroups_members'],
  162. 'can_be_additional' => false
  163. )
  164. );
  165. $context['postgroups'] = array();
  166. $request = $smcFunc['db_query']('', '
  167. SELECT id_group, group_name, min_posts
  168. FROM {db_prefix}membergroups
  169. WHERE id_group != {int:moderator_group}
  170. ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
  171. array(
  172. 'moderator_group' => 3,
  173. 'newbie_group' => 4,
  174. )
  175. );
  176. while ($row = $smcFunc['db_fetch_assoc']($request))
  177. {
  178. if ($row['min_posts'] == -1)
  179. $context['membergroups'][] = array(
  180. 'id' => $row['id_group'],
  181. 'name' => $row['group_name'],
  182. 'can_be_additional' => true
  183. );
  184. else
  185. $context['postgroups'][] = array(
  186. 'id' => $row['id_group'],
  187. 'name' => $row['group_name']
  188. );
  189. }
  190. $smcFunc['db_free_result']($request);
  191. // Some data about the form fields and how they are linked to the database.
  192. $params = array(
  193. 'mem_id' => array(
  194. 'db_fields' => array('id_member'),
  195. 'type' => 'int',
  196. 'range' => true
  197. ),
  198. 'age' => array(
  199. 'db_fields' => array('birthdate'),
  200. 'type' => 'age',
  201. 'range' => true
  202. ),
  203. 'posts' => array(
  204. 'db_fields' => array('posts'),
  205. 'type' => 'int',
  206. 'range' => true
  207. ),
  208. 'reg_date' => array(
  209. 'db_fields' => array('date_registered'),
  210. 'type' => 'date',
  211. 'range' => true
  212. ),
  213. 'last_online' => array(
  214. 'db_fields' => array('last_login'),
  215. 'type' => 'date',
  216. 'range' => true
  217. ),
  218. 'gender' => array(
  219. 'db_fields' => array('gender'),
  220. 'type' => 'checkbox',
  221. 'values' => array('0', '1', '2'),
  222. ),
  223. 'activated' => array(
  224. 'db_fields' => array('CASE WHEN is_activated IN (1, 11) THEN 1 ELSE 0 END'),
  225. 'type' => 'checkbox',
  226. 'values' => array('0', '1'),
  227. ),
  228. 'membername' => array(
  229. 'db_fields' => array('member_name', 'real_name'),
  230. 'type' => 'string'
  231. ),
  232. 'email' => array(
  233. 'db_fields' => array('email_address'),
  234. 'type' => 'string'
  235. ),
  236. 'website' => array(
  237. 'db_fields' => array('website_title', 'website_url'),
  238. 'type' => 'string'
  239. ),
  240. 'location' => array(
  241. 'db_fields' => array('location'),
  242. 'type' => 'string'
  243. ),
  244. 'ip' => array(
  245. 'db_fields' => array('member_ip'),
  246. 'type' => 'string'
  247. )
  248. );
  249. $range_trans = array(
  250. '--' => '<',
  251. '-' => '<=',
  252. '=' => '=',
  253. '+' => '>=',
  254. '++' => '>'
  255. );
  256. call_integration_hook('integrate_view_members_params', array($params));
  257. $search_params = array();
  258. if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
  259. $search_params = @unserialize(base64_decode($_REQUEST['params']));
  260. elseif (!empty($_POST))
  261. {
  262. $search_params['types'] = $_POST['types'];
  263. foreach ($params as $param_name => $param_info)
  264. if (isset($_POST[$param_name]))
  265. $search_params[$param_name] = $_POST[$param_name];
  266. }
  267. $search_url_params = isset($search_params) ? base64_encode(serialize($search_params)) : null;
  268. // @todo Validate a little more.
  269. // Loop through every field of the form.
  270. $query_parts = array();
  271. $where_params = array();
  272. foreach ($params as $param_name => $param_info)
  273. {
  274. // Not filled in?
  275. if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
  276. continue;
  277. // Make sure numeric values are really numeric.
  278. if (in_array($param_info['type'], array('int', 'age')))
  279. $search_params[$param_name] = (int) $search_params[$param_name];
  280. // Date values have to match the specified format.
  281. elseif ($param_info['type'] == 'date')
  282. {
  283. // Check if this date format is valid.
  284. if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
  285. continue;
  286. $search_params[$param_name] = strtotime($search_params[$param_name]);
  287. }
  288. // Those values that are in some kind of range (<, <=, =, >=, >).
  289. if (!empty($param_info['range']))
  290. {
  291. // Default to '=', just in case...
  292. if (empty($range_trans[$search_params['types'][$param_name]]))
  293. $search_params['types'][$param_name] = '=';
  294. // Handle special case 'age'.
  295. if ($param_info['type'] == 'age')
  296. {
  297. // All people that were born between $lowerlimit and $upperlimit are currently the specified age.
  298. $datearray = getdate(forum_time());
  299. $upperlimit = sprintf('%04d-%02d-%02d', $datearray['year'] - $search_params[$param_name], $datearray['mon'], $datearray['mday']);
  300. $lowerlimit = sprintf('%04d-%02d-%02d', $datearray['year'] - $search_params[$param_name] - 1, $datearray['mon'], $datearray['mday']);
  301. if (in_array($search_params['types'][$param_name], array('-', '--', '=')))
  302. {
  303. $query_parts[] = ($param_info['db_fields'][0]) . ' > {string:' . $param_name . '_minlimit}';
  304. $where_params[$param_name . '_minlimit'] = ($search_params['types'][$param_name] == '--' ? $upperlimit : $lowerlimit);
  305. }
  306. if (in_array($search_params['types'][$param_name], array('+', '++', '=')))
  307. {
  308. $query_parts[] = ($param_info['db_fields'][0]) . ' <= {string:' . $param_name . '_pluslimit}';
  309. $where_params[$param_name . '_pluslimit'] = ($search_params['types'][$param_name] == '++' ? $lowerlimit : $upperlimit);
  310. // Make sure that members that didn't set their birth year are not queried.
  311. $query_parts[] = ($param_info['db_fields'][0]) . ' > {date:dec_zero_date}';
  312. $where_params['dec_zero_date'] = '0004-12-31';
  313. }
  314. }
  315. // Special case - equals a date.
  316. elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
  317. {
  318. $query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
  319. }
  320. else
  321. $query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
  322. }
  323. // Checkboxes.
  324. elseif ($param_info['type'] == 'checkbox')
  325. {
  326. // Each checkbox or no checkbox at all is checked -> ignore.
  327. if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
  328. continue;
  329. $query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
  330. $where_params[$param_name . '_check'] = $search_params[$param_name];
  331. }
  332. else
  333. {
  334. // Replace the wildcard characters ('*' and '?') into MySQL ones.
  335. $parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
  336. if ($smcFunc['db_case_sensitive'])
  337. $query_parts[] = '(LOWER(' . implode( ') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
  338. else
  339. $query_parts[] = '(' . implode( ' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
  340. $where_params[$param_name . '_normal'] = '%' . $parameter . '%';
  341. }
  342. }
  343. // Set up the membergroup query part.
  344. $mg_query_parts = array();
  345. // Primary membergroups, but only if at least was was not selected.
  346. if (!empty($search_params['membergroups'][1]) && count($context['membergroups']) != count($search_params['membergroups'][1]))
  347. {
  348. $mg_query_parts[] = 'mem.id_group IN ({array_int:group_check})';
  349. $where_params['group_check'] = $search_params['membergroups'][1];
  350. }
  351. // Additional membergroups (these are only relevant if not all primary groups where selected!).
  352. if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
  353. foreach ($search_params['membergroups'][2] as $mg)
  354. {
  355. $mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
  356. $where_params['add_group_' . $mg] = $mg;
  357. }
  358. // Combine the one or two membergroup parts into one query part linked with an OR.
  359. if (!empty($mg_query_parts))
  360. $query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
  361. // Get all selected post count related membergroups.
  362. if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
  363. {
  364. $query_parts[] = 'id_post_group IN ({array_int:post_groups})';
  365. $where_params['post_groups'] = $search_params['postgroups'];
  366. }
  367. // Construct the where part of the query.
  368. $where = empty($query_parts) ? '1' : implode('
  369. AND ', $query_parts);
  370. }
  371. else
  372. $search_url_params = null;
  373. // Construct the additional URL part with the query info in it.
  374. $context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
  375. // Get the title and sub template ready..
  376. $context['page_title'] = $txt['admin_members'];
  377. $listOptions = array(
  378. 'id' => 'member_list',
  379. 'title' => $txt['members_list'],
  380. 'items_per_page' => $modSettings['defaultMaxMembers'],
  381. 'base_href' => $scripturl . '?action=admin;area=viewmembers' . $context['params_url'],
  382. 'default_sort_col' => 'user_name',
  383. 'get_items' => array(
  384. 'file' => SUBSDIR . '/Members.subs.php',
  385. 'function' => 'list_getMembers',
  386. 'params' => array(
  387. isset($where) ? $where : '1=1',
  388. isset($where_params) ? $where_params : array(),
  389. ),
  390. ),
  391. 'get_count' => array(
  392. 'file' => SUBSDIR . '/Members.subs.php',
  393. 'function' => 'list_getNumMembers',
  394. 'params' => array(
  395. isset($where) ? $where : '1=1',
  396. isset($where_params) ? $where_params : array(),
  397. ),
  398. ),
  399. 'columns' => array(
  400. 'id_member' => array(
  401. 'header' => array(
  402. 'value' => $txt['member_id'],
  403. ),
  404. 'data' => array(
  405. 'db' => 'id_member',
  406. ),
  407. 'sort' => array(
  408. 'default' => 'id_member',
  409. 'reverse' => 'id_member DESC',
  410. ),
  411. ),
  412. 'user_name' => array(
  413. 'header' => array(
  414. 'value' => $txt['username'],
  415. ),
  416. 'data' => array(
  417. 'sprintf' => array(
  418. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
  419. 'params' => array(
  420. 'id_member' => false,
  421. 'member_name' => false,
  422. ),
  423. ),
  424. ),
  425. 'sort' => array(
  426. 'default' => 'member_name',
  427. 'reverse' => 'member_name DESC',
  428. ),
  429. ),
  430. 'display_name' => array(
  431. 'header' => array(
  432. 'value' => $txt['display_name'],
  433. ),
  434. 'data' => array(
  435. 'sprintf' => array(
  436. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
  437. 'params' => array(
  438. 'id_member' => false,
  439. 'real_name' => false,
  440. ),
  441. ),
  442. ),
  443. 'sort' => array(
  444. 'default' => 'real_name',
  445. 'reverse' => 'real_name DESC',
  446. ),
  447. ),
  448. 'email' => array(
  449. 'header' => array(
  450. 'value' => $txt['email_address'],
  451. ),
  452. 'data' => array(
  453. 'sprintf' => array(
  454. 'format' => '<a href="mailto:%1$s">%1$s</a>',
  455. 'params' => array(
  456. 'email_address' => true,
  457. ),
  458. ),
  459. ),
  460. 'sort' => array(
  461. 'default' => 'email_address',
  462. 'reverse' => 'email_address DESC',
  463. ),
  464. ),
  465. 'ip' => array(
  466. 'header' => array(
  467. 'value' => $txt['ip_address'],
  468. ),
  469. 'data' => array(
  470. 'sprintf' => array(
  471. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=trackip;searchip=%1$s">%1$s</a>',
  472. 'params' => array(
  473. 'member_ip' => false,
  474. ),
  475. ),
  476. ),
  477. 'sort' => array(
  478. 'default' => 'INET_ATON(member_ip)',
  479. 'reverse' => 'INET_ATON(member_ip) DESC',
  480. ),
  481. ),
  482. 'last_active' => array(
  483. 'header' => array(
  484. 'value' => $txt['viewmembers_online'],
  485. ),
  486. 'data' => array(
  487. 'function' => create_function('$rowData', '
  488. global $txt;
  489. // Calculate number of days since last online.
  490. if (empty($rowData[\'last_login\']))
  491. $difference = $txt[\'never\'];
  492. else
  493. {
  494. $num_days_difference = jeffsdatediff($rowData[\'last_login\']);
  495. // Today.
  496. if (empty($num_days_difference))
  497. $difference = $txt[\'viewmembers_today\'];
  498. // Yesterday.
  499. elseif ($num_days_difference == 1)
  500. $difference = sprintf(\'1 %1$s\', $txt[\'viewmembers_day_ago\']);
  501. // X days ago.
  502. else
  503. $difference = sprintf(\'%1$d %2$s\', $num_days_difference, $txt[\'viewmembers_days_ago\']);
  504. }
  505. // Show it in italics if they\'re not activated...
  506. if ($rowData[\'is_activated\'] % 10 != 1)
  507. $difference = sprintf(\'<em title="%1$s">%2$s</em>\', $txt[\'not_activated\'], $difference);
  508. return $difference;
  509. '),
  510. ),
  511. 'sort' => array(
  512. 'default' => 'last_login DESC',
  513. 'reverse' => 'last_login',
  514. ),
  515. ),
  516. 'posts' => array(
  517. 'header' => array(
  518. 'value' => $txt['member_postcount'],
  519. ),
  520. 'data' => array(
  521. 'db' => 'posts',
  522. ),
  523. 'sort' => array(
  524. 'default' => 'posts',
  525. 'reverse' => 'posts DESC',
  526. ),
  527. ),
  528. 'check' => array(
  529. 'header' => array(
  530. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  531. 'class' => 'centercol',
  532. ),
  533. 'data' => array(
  534. 'function' => create_function('$rowData', '
  535. global $user_info;
  536. return \'<input type="checkbox" name="delete[]" value="\' . $rowData[\'id_member\'] . \'" class="input_check" \' . ($rowData[\'id_member\'] == $user_info[\'id\'] || $rowData[\'id_group\'] == 1 || in_array(1, explode(\',\', $rowData[\'additional_groups\'])) ? \'disabled="disabled"\' : \'\') . \' />\';
  537. '),
  538. 'class' => 'centercol',
  539. ),
  540. ),
  541. ),
  542. 'form' => array(
  543. 'href' => $scripturl . '?action=admin;area=viewmembers' . $context['params_url'],
  544. 'include_start' => true,
  545. 'include_sort' => true,
  546. ),
  547. 'additional_rows' => array(
  548. array(
  549. 'position' => 'below_table_data',
  550. 'value' => '<input type="submit" name="delete_members" value="' . $txt['admin_delete_members'] . '" onclick="return confirm(\'' . $txt['confirm_delete_members'] . '\');" class="button_submit" />',
  551. ),
  552. ),
  553. );
  554. // Without enough permissions, don't show 'delete members' checkboxes.
  555. if (!allowedTo('profile_remove_any'))
  556. unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
  557. require_once(SUBSDIR . '/List.subs.php');
  558. createList($listOptions);
  559. $context['sub_template'] = 'show_list';
  560. $context['default_list'] = 'member_list';
  561. }
  562. /**
  563. * Search the member list, using one or more criteria.
  564. * Called by ?action=admin;area=viewmembers;sa=search.
  565. * Requires the moderate_forum permission.
  566. * form is submitted to action=admin;area=viewmembers;sa=query.
  567. *
  568. * @uses the search_members sub template of the ManageMembers template.
  569. */
  570. function SearchMembers()
  571. {
  572. global $context, $txt, $smcFunc;
  573. // Get a list of all the membergroups and postgroups that can be selected.
  574. $context['membergroups'] = array(
  575. array(
  576. 'id' => 0,
  577. 'name' => $txt['membergroups_members'],
  578. 'can_be_additional' => false
  579. )
  580. );
  581. $context['postgroups'] = array();
  582. $request = $smcFunc['db_query']('', '
  583. SELECT id_group, group_name, min_posts
  584. FROM {db_prefix}membergroups
  585. WHERE id_group != {int:moderator_group}
  586. ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
  587. array(
  588. 'moderator_group' => 3,
  589. 'newbie_group' => 4,
  590. )
  591. );
  592. while ($row = $smcFunc['db_fetch_assoc']($request))
  593. {
  594. if ($row['min_posts'] == -1)
  595. $context['membergroups'][] = array(
  596. 'id' => $row['id_group'],
  597. 'name' => $row['group_name'],
  598. 'can_be_additional' => true
  599. );
  600. else
  601. $context['postgroups'][] = array(
  602. 'id' => $row['id_group'],
  603. 'name' => $row['group_name']
  604. );
  605. }
  606. $smcFunc['db_free_result']($request);
  607. $context['page_title'] = $txt['admin_members'];
  608. $context['sub_template'] = 'search_members';
  609. }
  610. /**
  611. * List all members who are awaiting approval / activation, sortable on different columns.
  612. * It allows instant approval or activation of (a selection of) members.
  613. * Called by ?action=admin;area=viewmembers;sa=browse;type=approve
  614. * or ?action=admin;area=viewmembers;sa=browse;type=activate.
  615. * The form submits to ?action=admin;area=viewmembers;sa=approve.
  616. * Requires the moderate_forum permission.
  617. *
  618. * @uses the admin_browse sub template of the ManageMembers template.
  619. */
  620. function MembersAwaitingActivation()
  621. {
  622. global $txt, $context, $scripturl, $modSettings, $smcFunc;
  623. // Not a lot here!
  624. $context['page_title'] = $txt['admin_members'];
  625. $context['sub_template'] = 'admin_browse';
  626. $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
  627. if (isset($context['tabs'][$context['browse_type']]))
  628. $context['tabs'][$context['browse_type']]['is_selected'] = true;
  629. // Allowed filters are those we can have, in theory.
  630. $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
  631. $context['current_filter'] = isset($_REQUEST['filter']) && in_array($_REQUEST['filter'], $context['allowed_filters']) && !empty($context['activation_numbers'][$_REQUEST['filter']]) ? (int) $_REQUEST['filter'] : -1;
  632. // Sort out the different sub areas that we can actually filter by.
  633. $context['available_filters'] = array();
  634. foreach ($context['activation_numbers'] as $type => $amount)
  635. {
  636. // We have some of these...
  637. if (in_array($type, $context['allowed_filters']) && $amount > 0)
  638. $context['available_filters'][] = array(
  639. 'type' => $type,
  640. 'amount' => $amount,
  641. 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
  642. 'selected' => $type == $context['current_filter']
  643. );
  644. }
  645. // If the filter was not sent, set it to whatever has people in it!
  646. if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
  647. $context['current_filter'] = $context['available_filters'][0]['type'];
  648. // This little variable is used to determine if we should flag where we are looking.
  649. $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
  650. // The columns that can be sorted.
  651. $context['columns'] = array(
  652. 'id_member' => array('label' => $txt['admin_browse_id']),
  653. 'member_name' => array('label' => $txt['admin_browse_username']),
  654. 'email_address' => array('label' => $txt['admin_browse_email']),
  655. 'member_ip' => array('label' => $txt['admin_browse_ip']),
  656. 'date_registered' => array('label' => $txt['admin_browse_registered']),
  657. );
  658. // Are we showing duplicate information?
  659. if (isset($_GET['showdupes']))
  660. $_SESSION['showdupes'] = (int) $_GET['showdupes'];
  661. $context['show_duplicates'] = !empty($_SESSION['showdupes']);
  662. // Determine which actions we should allow on this page.
  663. if ($context['browse_type'] == 'approve')
  664. {
  665. // If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
  666. if ($context['current_filter'] == 4)
  667. $context['allowed_actions'] = array(
  668. 'reject' => $txt['admin_browse_w_approve_deletion'],
  669. 'ok' => $txt['admin_browse_w_reject'],
  670. );
  671. else
  672. $context['allowed_actions'] = array(
  673. 'ok' => $txt['admin_browse_w_approve'],
  674. 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
  675. 'require_activation' => $txt['admin_browse_w_approve_require_activate'],
  676. 'reject' => $txt['admin_browse_w_reject'],
  677. 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
  678. );
  679. }
  680. elseif ($context['browse_type'] == 'activate')
  681. $context['allowed_actions'] = array(
  682. 'ok' => $txt['admin_browse_w_activate'],
  683. 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
  684. 'delete' => $txt['admin_browse_w_delete'],
  685. 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
  686. 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
  687. );
  688. // Create an option list for actions allowed to be done with selected members.
  689. $allowed_actions = '
  690. <option selected="selected" value="">' . $txt['admin_browse_with_selected'] . ':</option>
  691. <option value="" disabled="disabled">-----------------------------</option>';
  692. foreach ($context['allowed_actions'] as $key => $desc)
  693. $allowed_actions .= '
  694. <option value="' . $key . '">' . $desc . '</option>';
  695. // Setup the Javascript function for selecting an action for the list.
  696. $javascript = '
  697. function onSelectChange()
  698. {
  699. if (document.forms.postForm.todo.value == "")
  700. return;
  701. var message = "";';
  702. // We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
  703. if ($context['current_filter'] == 4)
  704. $javascript .= '
  705. if (document.forms.postForm.todo.value.indexOf("reject") != -1)
  706. message = "' . $txt['admin_browse_w_delete'] . '";
  707. else
  708. message = "' . $txt['admin_browse_w_reject'] . '";';
  709. // Otherwise a nice standard message.
  710. else
  711. $javascript .= '
  712. if (document.forms.postForm.todo.value.indexOf("delete") != -1)
  713. message = "' . $txt['admin_browse_w_delete'] . '";
  714. else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
  715. message = "' . $txt['admin_browse_w_reject'] . '";
  716. else if (document.forms.postForm.todo.value == "remind")
  717. message = "' . $txt['admin_browse_w_remind'] . '";
  718. else
  719. message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
  720. $javascript .= '
  721. if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
  722. document.forms.postForm.submit();
  723. }';
  724. $listOptions = array(
  725. 'id' => 'approve_list',
  726. // 'title' => $txt['members_approval_title'],
  727. 'items_per_page' => $modSettings['defaultMaxMembers'],
  728. 'base_href' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=' . $context['browse_type'] . (!empty($context['show_filter']) ? ';filter=' . $context['current_filter'] : ''),
  729. 'default_sort_col' => 'date_registered',
  730. 'get_items' => array(
  731. 'file' => SUBSDIR . '/Members.subs.php',
  732. 'function' => 'list_getMembers',
  733. 'params' => array(
  734. 'is_activated = {int:activated_status}',
  735. array('activated_status' => $context['current_filter']),
  736. $context['show_duplicates'],
  737. ),
  738. ),
  739. 'get_count' => array(
  740. 'file' => SUBSDIR . '/Members.subs.php',
  741. 'function' => 'list_getNumMembers',
  742. 'params' => array(
  743. 'is_activated = {int:activated_status}',
  744. array('activated_status' => $context['current_filter']),
  745. ),
  746. ),
  747. 'columns' => array(
  748. 'id_member' => array(
  749. 'header' => array(
  750. 'value' => $txt['member_id'],
  751. ),
  752. 'data' => array(
  753. 'db' => 'id_member',
  754. ),
  755. 'sort' => array(
  756. 'default' => 'id_member',
  757. 'reverse' => 'id_member DESC',
  758. ),
  759. ),
  760. 'user_name' => array(
  761. 'header' => array(
  762. 'value' => $txt['username'],
  763. ),
  764. 'data' => array(
  765. 'sprintf' => array(
  766. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
  767. 'params' => array(
  768. 'id_member' => false,
  769. 'member_name' => false,
  770. ),
  771. ),
  772. ),
  773. 'sort' => array(
  774. 'default' => 'member_name',
  775. 'reverse' => 'member_name DESC',
  776. ),
  777. ),
  778. 'email' => array(
  779. 'header' => array(
  780. 'value' => $txt['email_address'],
  781. ),
  782. 'data' => array(
  783. 'sprintf' => array(
  784. 'format' => '<a href="mailto:%1$s">%1$s</a>',
  785. 'params' => array(
  786. 'email_address' => true,
  787. ),
  788. ),
  789. ),
  790. 'sort' => array(
  791. 'default' => 'email_address',
  792. 'reverse' => 'email_address DESC',
  793. ),
  794. ),
  795. 'ip' => array(
  796. 'header' => array(
  797. 'value' => $txt['ip_address'],
  798. ),
  799. 'data' => array(
  800. 'sprintf' => array(
  801. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=trackip;searchip=%1$s">%1$s</a>',
  802. 'params' => array(
  803. 'member_ip' => false,
  804. ),
  805. ),
  806. ),
  807. 'sort' => array(
  808. 'default' => 'INET_ATON(member_ip)',
  809. 'reverse' => 'INET_ATON(member_ip) DESC',
  810. ),
  811. ),
  812. 'hostname' => array(
  813. 'header' => array(
  814. 'value' => $txt['hostname'],
  815. ),
  816. 'data' => array(
  817. 'function' => create_function('$rowData', '
  818. global $modSettings;
  819. return host_from_ip($rowData[\'member_ip\']);
  820. '),
  821. 'class' => 'smalltext',
  822. ),
  823. ),
  824. 'date_registered' => array(
  825. 'header' => array(
  826. 'value' => $context['current_filter'] == 4 ? $txt['viewmembers_online'] : $txt['date_registered'],
  827. ),
  828. 'data' => array(
  829. 'function' => create_function('$rowData', '
  830. return timeformat($rowData[\'' . ($context['current_filter'] == 4 ? 'last_login' : 'date_registered') . '\']);
  831. '),
  832. ),
  833. 'sort' => array(
  834. 'default' => $context['current_filter'] == 4 ? 'mem.last_login DESC' : 'date_registered DESC',
  835. 'reverse' => $context['current_filter'] == 4 ? 'mem.last_login' : 'date_registered',
  836. ),
  837. ),
  838. 'duplicates' => array(
  839. 'header' => array(
  840. 'value' => $txt['duplicates'],
  841. // Make sure it doesn't go too wide.
  842. 'style' => 'width: 20%;',
  843. ),
  844. 'data' => array(
  845. 'function' => create_function('$rowData', '
  846. global $scripturl, $txt;
  847. $member_links = array();
  848. foreach ($rowData[\'duplicate_members\'] as $member)
  849. {
  850. if ($member[\'id\'])
  851. $member_links[] = \'<a href="\' . $scripturl . \'?action=profile;u=\' . $member[\'id\'] . \'" \' . (!empty($member[\'is_banned\']) ? \'style="color: red;"\' : \'\') . \'>\' . $member[\'name\'] . \'</a>\';
  852. else
  853. $member_links[] = $member[\'name\'] . \' (\' . $txt[\'guest\'] . \')\';
  854. }
  855. return implode (\', \', $member_links);
  856. '),
  857. 'class' => 'smalltext',
  858. ),
  859. ),
  860. 'check' => array(
  861. 'header' => array(
  862. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  863. 'class' => 'centercol',
  864. ),
  865. 'data' => array(
  866. 'sprintf' => array(
  867. 'format' => '<input type="checkbox" name="todoAction[]" value="%1$d" class="input_check" />',
  868. 'params' => array(
  869. 'id_member' => false,
  870. ),
  871. ),
  872. 'class' => 'centercol',
  873. ),
  874. ),
  875. ),
  876. 'javascript' => $javascript,
  877. 'form' => array(
  878. 'href' => $scripturl . '?action=admin;area=viewmembers;sa=approve;type=' . $context['browse_type'],
  879. 'name' => 'postForm',
  880. 'include_start' => true,
  881. 'include_sort' => true,
  882. 'hidden_fields' => array(
  883. 'orig_filter' => $context['current_filter'],
  884. ),
  885. ),
  886. 'additional_rows' => array(
  887. array(
  888. 'position' => 'below_table_data',
  889. 'value' => '
  890. [<a href="' . $scripturl . '?action=admin;area=viewmembers;sa=browse;showdupes=' . ($context['show_duplicates'] ? 0 : 1) . ';type=' . $context['browse_type'] . (!empty($context['show_filter']) ? ';filter=' . $context['current_filter'] : '') . ';' . $context['session_var'] . '=' . $context['session_id'] . '">' . ($context['show_duplicates'] ? $txt['dont_check_for_duplicate'] : $txt['check_for_duplicate']) . '</a>]
  891. <select name="todo" onchange="onSelectChange();">
  892. ' . $allowed_actions . '
  893. </select>
  894. <noscript><input type="submit" value="' . $txt['go'] . '" class="button_submit" /><br class="clear_right" /></noscript>
  895. ',
  896. 'class' => 'floatright',
  897. ),
  898. ),
  899. );
  900. // Pick what column to actually include if we're showing duplicates.
  901. if ($context['show_duplicates'])
  902. unset($listOptions['columns']['email']);
  903. else
  904. unset($listOptions['columns']['duplicates']);
  905. // Only show hostname on duplicates as it takes a lot of time.
  906. if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
  907. unset($listOptions['columns']['hostname']);
  908. // Is there any need to show filters?
  909. if (isset($context['available_filters']) && count($context['available_filters']) > 1)
  910. {
  911. $filterOptions = '
  912. <strong>' . $txt['admin_browse_filter_by'] . ':</strong>
  913. <select name="filter" onchange="this.form.submit();">';
  914. foreach ($context['available_filters'] as $filter)
  915. $filterOptions .= '
  916. <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected="selected"' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
  917. $filterOptions .= '
  918. </select>
  919. <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit" /></noscript>';
  920. $listOptions['additional_rows'][] = array(
  921. 'position' => 'top_of_list',
  922. 'value' => $filterOptions,
  923. 'class' => 'righttext',
  924. );
  925. }
  926. // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
  927. if (!empty($context['show_filter']) && !empty($context['available_filters']))
  928. $listOptions['additional_rows'][] = array(
  929. 'position' => 'above_column_headers',
  930. 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
  931. 'class' => 'smalltext floatright',
  932. );
  933. // Now that we have all the options, create the list.
  934. require_once(SUBSDIR . '/List.subs.php');
  935. createList($listOptions);
  936. }
  937. /**
  938. * This function handles the approval, rejection, activation or deletion of members.
  939. * Called by ?action=admin;area=viewmembers;sa=approve.
  940. * Requires the moderate_forum permission.
  941. * Redirects to ?action=admin;area=viewmembers;sa=browse
  942. * with the same parameters as the calling page.
  943. */
  944. function AdminApprove()
  945. {
  946. global $txt, $context, $scripturl, $modSettings, $language, $user_info, $smcFunc;
  947. // First, check our session.
  948. checkSession();
  949. require_once(SUBSDIR . '/Mail.subs.php');
  950. // We also need to the login languages here - for emails.
  951. loadLanguage('Login');
  952. // Sort out where we are going...
  953. $browse_type = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
  954. $current_filter = (int) $_REQUEST['orig_filter'];
  955. // If we are applying a filter do just that - then redirect.
  956. if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
  957. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
  958. // Nothing to do?
  959. if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
  960. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
  961. // Are we dealing with members who have been waiting for > set amount of time?
  962. if (isset($_POST['time_passed']))
  963. {
  964. $timeBefore = time() - 86400 * (int) $_POST['time_passed'];
  965. $condition = '
  966. AND date_registered < {int:time_before}';
  967. }
  968. // Coming from checkboxes - validate the members passed through to us.
  969. else
  970. {
  971. $members = array();
  972. foreach ($_POST['todoAction'] as $id)
  973. $members[] = (int) $id;
  974. $condition = '
  975. AND id_member IN ({array_int:members})';
  976. }
  977. // Get information on each of the members, things that are important to us, like email address...
  978. $request = $smcFunc['db_query']('', '
  979. SELECT id_member, member_name, real_name, email_address, validation_code, lngfile
  980. FROM {db_prefix}members
  981. WHERE is_activated = {int:activated_status}' . $condition . '
  982. ORDER BY lngfile',
  983. array(
  984. 'activated_status' => $current_filter,
  985. 'time_before' => empty($timeBefore) ? 0 : $timeBefore,
  986. 'members' => empty($members) ? array() : $members,
  987. )
  988. );
  989. $member_count = $smcFunc['db_num_rows']($request);
  990. // If no results then just return!
  991. if ($member_count == 0)
  992. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
  993. $member_info = array();
  994. $members = array();
  995. // Fill the info array.
  996. while ($row = $smcFunc['db_fetch_assoc']($request))
  997. {
  998. $members[] = $row['id_member'];
  999. $member_info[] = array(
  1000. 'id' => $row['id_member'],
  1001. 'username' => $row['member_name'],
  1002. 'name' => $row['real_name'],
  1003. 'email' => $row['email_address'],
  1004. 'language' => empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'],
  1005. 'code' => $row['validation_code']
  1006. );
  1007. }
  1008. $smcFunc['db_free_result']($request);
  1009. // Are we activating or approving the members?
  1010. if ($_POST['todo'] == 'ok' || $_POST['todo'] == 'okemail')
  1011. {
  1012. // Approve/activate this member.
  1013. $smcFunc['db_query']('', '
  1014. UPDATE {db_prefix}members
  1015. SET validation_code = {string:blank_string}, is_activated = {int:is_activated}
  1016. WHERE is_activated = {int:activated_status}' . $condition,
  1017. array(
  1018. 'is_activated' => 1,
  1019. 'time_before' => empty($timeBefore) ? 0 : $timeBefore,
  1020. 'members' => empty($members) ? array() : $members,
  1021. 'activated_status' => $current_filter,
  1022. 'blank_string' => '',
  1023. )
  1024. );
  1025. // Do we have to let the integration code know about the activations?
  1026. if (!empty($modSettings['integrate_activate']))
  1027. {
  1028. foreach ($member_info as $member)
  1029. call_integration_hook('integrate_activate', array($member['username']));
  1030. }
  1031. // Check for email.
  1032. if ($_POST['todo'] == 'okemail')
  1033. {
  1034. foreach ($member_info as $member)
  1035. {
  1036. $replacements = array(
  1037. 'NAME' => $member['name'],
  1038. 'USERNAME' => $member['username'],
  1039. 'PROFILELINK' => $scripturl . '?action=profile;u=' . $member['id'],
  1040. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  1041. );
  1042. $emaildata = loadEmailTemplate('admin_approve_accept', $replacements, $member['language']);
  1043. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  1044. }
  1045. }
  1046. }
  1047. // Maybe we're sending it off for activation?
  1048. elseif ($_POST['todo'] == 'require_activation')
  1049. {
  1050. require_once(SUBSDIR . '/Members.subs.php');
  1051. // We have to do this for each member I'm afraid.
  1052. foreach ($member_info as $member)
  1053. {
  1054. // Generate a random activation code.
  1055. $validation_code = generateValidationCode();
  1056. // Set these members for activation - I know this includes two id_member checks but it's safer than bodging $condition ;).
  1057. $smcFunc['db_query']('', '
  1058. UPDATE {db_prefix}members
  1059. SET validation_code = {string:validation_code}, is_activated = {int:not_activated}
  1060. WHERE is_activated = {int:activated_status}
  1061. ' . $condition . '
  1062. AND id_member = {int:selected_member}',
  1063. array(
  1064. 'not_activated' => 0,
  1065. 'activated_status' => $current_filter,
  1066. 'selected_member' => $member['id'],
  1067. 'validation_code' => $validation_code,
  1068. 'time_before' => empty($timeBefore) ? 0 : $timeBefore,
  1069. 'members' => empty($members) ? array() : $members,
  1070. )
  1071. );
  1072. $replacements = array(
  1073. 'USERNAME' => $member['name'],
  1074. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $member['id'] . ';code=' . $validation_code,
  1075. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $member['id'],
  1076. 'ACTIVATIONCODE' => $validation_code,
  1077. );
  1078. $emaildata = loadEmailTemplate('admin_approve_activation', $replacements, $member['language']);
  1079. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  1080. }
  1081. }
  1082. // Are we rejecting them?
  1083. elseif ($_POST['todo'] == 'reject' || $_POST['todo'] == 'rejectemail')
  1084. {
  1085. require_once(SUBSDIR . '/Members.subs.php');
  1086. deleteMembers($members);
  1087. // Send email telling them they aren't welcome?
  1088. if ($_POST['todo'] == 'rejectemail')
  1089. {
  1090. foreach ($member_info as $member)
  1091. {
  1092. $replacements = array(
  1093. 'USERNAME' => $member['name'],
  1094. );
  1095. $emaildata = loadEmailTemplate('admin_approve_reject', $replacements, $member['language']);
  1096. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 1);
  1097. }
  1098. }
  1099. }
  1100. // A simple delete?
  1101. elseif ($_POST['todo'] == 'delete' || $_POST['todo'] == 'deleteemail')
  1102. {
  1103. require_once(SUBSDIR . '/Members.subs.php');
  1104. deleteMembers($members);
  1105. // Send email telling them they aren't welcome?
  1106. if ($_POST['todo'] == 'deleteemail')
  1107. {
  1108. foreach ($member_info as $member)
  1109. {
  1110. $replacements = array(
  1111. 'USERNAME' => $member['name'],
  1112. );
  1113. $emaildata = loadEmailTemplate('admin_approve_delete', $replacements, $member['language']);
  1114. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 1);
  1115. }
  1116. }
  1117. }
  1118. // Remind them to activate their account?
  1119. elseif ($_POST['todo'] == 'remind')
  1120. {
  1121. foreach ($member_info as $member)
  1122. {
  1123. $replacements = array(
  1124. 'USERNAME' => $member['name'],
  1125. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $member['id'] . ';code=' . $member['code'],
  1126. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $member['id'],
  1127. 'ACTIVATIONCODE' => $member['code'],
  1128. );
  1129. $emaildata = loadEmailTemplate('admin_approve_remind', $replacements, $member['language']);
  1130. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 1);
  1131. }
  1132. }
  1133. // @todo current_language is never set, no idea what this is for. Remove?
  1134. // Back to the user's language!
  1135. if (isset($current_language) && $current_language != $user_info['language'])
  1136. {
  1137. loadLanguage('index');
  1138. loadLanguage('ManageMembers');
  1139. }
  1140. // Log what we did?
  1141. if (!empty($modSettings['modlog_enabled']) && in_array($_POST['todo'], array('ok', 'okemail', 'require_activation', 'remind')))
  1142. {
  1143. $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
  1144. $log_inserts = array();
  1145. require_once(SOURCEDIR . '/Logging.php');
  1146. foreach ($member_info as $member)
  1147. logAction($log_action, array('member' => $member['id']), 'admin');
  1148. }
  1149. // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
  1150. if (in_array($current_filter, array(3, 4)))
  1151. updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
  1152. // Update the member's stats. (but, we know the member didn't change their name.)
  1153. updateStats('member', false);
  1154. // If they haven't been deleted, update the post group statistics on them...
  1155. if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
  1156. updateStats('postgroups', $members);
  1157. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
  1158. }
  1159. /**
  1160. * Nifty function to calculate the number of days ago a given date was.
  1161. * Requires a unix timestamp as input, returns an integer.
  1162. * Named in honour of Jeff Lewis, the original creator of...this function.
  1163. *
  1164. * @param $old
  1165. * @return int, the returned number of days, based on the forum time.
  1166. */
  1167. function jeffsdatediff($old)
  1168. {
  1169. // Get the current time as the user would see it...
  1170. $forumTime = forum_time();
  1171. // Calculate the seconds that have passed since midnight.
  1172. $sinceMidnight = date('H', $forumTime) * 60 * 60 + date('i', $forumTime) * 60 + date('s', $forumTime);
  1173. // Take the difference between the two times.
  1174. $dis = time() - $old;
  1175. // Before midnight?
  1176. if ($dis < $sinceMidnight)
  1177. return 0;
  1178. else
  1179. $dis -= $sinceMidnight;
  1180. // Divide out the seconds in a day to get the number of days.
  1181. return ceil($dis / (24 * 60 * 60));
  1182. }