ManageMembers.php 44 KB

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