PageRenderTime 37ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/php/Sources/ManageMembers.php

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