ManageMembers.php 45 KB

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