ManageMembers.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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. ),
  407. 'sort' => array(
  408. 'default' => 'id_member',
  409. 'reverse' => 'id_member DESC',
  410. ),
  411. ),
  412. 'user_name' => array(
  413. 'header' => array(
  414. 'value' => $txt['username'],
  415. ),
  416. 'data' => array(
  417. 'sprintf' => array(
  418. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
  419. 'params' => array(
  420. 'id_member' => false,
  421. 'member_name' => false,
  422. ),
  423. ),
  424. ),
  425. 'sort' => array(
  426. 'default' => 'member_name',
  427. 'reverse' => 'member_name DESC',
  428. ),
  429. ),
  430. 'display_name' => array(
  431. 'header' => array(
  432. 'value' => $txt['display_name'],
  433. ),
  434. 'data' => array(
  435. 'sprintf' => array(
  436. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
  437. 'params' => array(
  438. 'id_member' => false,
  439. 'real_name' => false,
  440. ),
  441. ),
  442. ),
  443. 'sort' => array(
  444. 'default' => 'real_name',
  445. 'reverse' => 'real_name DESC',
  446. ),
  447. ),
  448. 'email' => array(
  449. 'header' => array(
  450. 'value' => $txt['email_address'],
  451. ),
  452. 'data' => array(
  453. 'sprintf' => array(
  454. 'format' => '<a href="mailto:%1$s">%1$s</a>',
  455. 'params' => array(
  456. 'email_address' => true,
  457. ),
  458. ),
  459. ),
  460. 'sort' => array(
  461. 'default' => 'email_address',
  462. 'reverse' => 'email_address DESC',
  463. ),
  464. ),
  465. 'ip' => array(
  466. 'header' => array(
  467. 'value' => $txt['ip_address'],
  468. ),
  469. 'data' => array(
  470. 'sprintf' => array(
  471. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=trackip;searchip=%1$s">%1$s</a>',
  472. 'params' => array(
  473. 'member_ip' => false,
  474. ),
  475. ),
  476. ),
  477. 'sort' => array(
  478. 'default' => 'INET_ATON(member_ip)',
  479. 'reverse' => 'INET_ATON(member_ip) DESC',
  480. ),
  481. ),
  482. 'last_active' => array(
  483. 'header' => array(
  484. 'value' => $txt['viewmembers_online'],
  485. ),
  486. 'data' => array(
  487. 'function' => create_function('$rowData', '
  488. global $txt;
  489. // Calculate number of days since last online.
  490. if (empty($rowData[\'last_login\']))
  491. $difference = $txt[\'never\'];
  492. else
  493. {
  494. $num_days_difference = jeffsdatediff($rowData[\'last_login\']);
  495. // Today.
  496. if (empty($num_days_difference))
  497. $difference = $txt[\'viewmembers_today\'];
  498. // Yesterday.
  499. elseif ($num_days_difference == 1)
  500. $difference = sprintf(\'1 %1$s\', $txt[\'viewmembers_day_ago\']);
  501. // X days ago.
  502. else
  503. $difference = sprintf(\'%1$d %2$s\', $num_days_difference, $txt[\'viewmembers_days_ago\']);
  504. }
  505. // Show it in italics if they\'re not activated...
  506. if ($rowData[\'is_activated\'] % 10 != 1)
  507. $difference = sprintf(\'<em title="%1$s">%2$s</em>\', $txt[\'not_activated\'], $difference);
  508. return $difference;
  509. '),
  510. ),
  511. 'sort' => array(
  512. 'default' => 'last_login DESC',
  513. 'reverse' => 'last_login',
  514. ),
  515. ),
  516. 'posts' => array(
  517. 'header' => array(
  518. 'value' => $txt['member_postcount'],
  519. ),
  520. 'data' => array(
  521. 'db' => 'posts',
  522. ),
  523. 'sort' => array(
  524. 'default' => 'posts',
  525. 'reverse' => 'posts DESC',
  526. ),
  527. ),
  528. 'check' => array(
  529. 'header' => array(
  530. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  531. 'class' => 'centercol',
  532. ),
  533. 'data' => array(
  534. 'function' => create_function('$rowData', '
  535. global $user_info;
  536. return \'<input type="checkbox" name="delete[]" value="\' . $rowData[\'id_member\'] . \'" class="input_check" \' . ($rowData[\'id_member\'] == $user_info[\'id\'] || $rowData[\'id_group\'] == 1 || in_array(1, explode(\',\', $rowData[\'additional_groups\'])) ? \'disabled="disabled"\' : \'\') . \' />\';
  537. '),
  538. 'class' => 'centercol',
  539. ),
  540. ),
  541. ),
  542. 'form' => array(
  543. 'href' => $scripturl . '?action=admin;area=viewmembers' . $context['params_url'],
  544. 'include_start' => true,
  545. 'include_sort' => true,
  546. ),
  547. 'additional_rows' => array(
  548. array(
  549. 'position' => 'below_table_data',
  550. 'value' => '<input type="submit" name="delete_members" value="' . $txt['admin_delete_members'] . '" onclick="return confirm(\'' . $txt['confirm_delete_members'] . '\');" class="button_submit" />',
  551. ),
  552. ),
  553. );
  554. // Without enough permissions, don't show 'delete members' checkboxes.
  555. if (!allowedTo('profile_remove_any'))
  556. unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
  557. require_once($sourcedir . '/Subs-List.php');
  558. createList($listOptions);
  559. $context['sub_template'] = 'show_list';
  560. $context['default_list'] = 'member_list';
  561. }
  562. /**
  563. * Search the member list, using one or more criteria.
  564. * Called by ?action=admin;area=viewmembers;sa=search.
  565. * Requires the moderate_forum permission.
  566. * form is submitted to action=admin;area=viewmembers;sa=query.
  567. *
  568. * @uses the search_members sub template of the ManageMembers template.
  569. */
  570. function SearchMembers()
  571. {
  572. global $context, $txt, $smcFunc;
  573. // Get a list of all the membergroups and postgroups that can be selected.
  574. $context['membergroups'] = array(
  575. array(
  576. 'id' => 0,
  577. 'name' => $txt['membergroups_members'],
  578. 'can_be_additional' => false
  579. )
  580. );
  581. $context['postgroups'] = array();
  582. $request = $smcFunc['db_query']('', '
  583. SELECT id_group, group_name, min_posts
  584. FROM {db_prefix}membergroups
  585. WHERE id_group != {int:moderator_group}
  586. ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
  587. array(
  588. 'moderator_group' => 3,
  589. 'newbie_group' => 4,
  590. )
  591. );
  592. while ($row = $smcFunc['db_fetch_assoc']($request))
  593. {
  594. if ($row['min_posts'] == -1)
  595. $context['membergroups'][] = array(
  596. 'id' => $row['id_group'],
  597. 'name' => $row['group_name'],
  598. 'can_be_additional' => true
  599. );
  600. else
  601. $context['postgroups'][] = array(
  602. 'id' => $row['id_group'],
  603. 'name' => $row['group_name']
  604. );
  605. }
  606. $smcFunc['db_free_result']($request);
  607. $context['page_title'] = $txt['admin_members'];
  608. $context['sub_template'] = 'search_members';
  609. }
  610. /**
  611. * List all members who are awaiting approval / activation, sortable on different columns.
  612. * It allows instant approval or activation of (a selection of) members.
  613. * Called by ?action=admin;area=viewmembers;sa=browse;type=approve
  614. * or ?action=admin;area=viewmembers;sa=browse;type=activate.
  615. * The form submits to ?action=admin;area=viewmembers;sa=approve.
  616. * Requires the moderate_forum permission.
  617. *
  618. * @uses the admin_browse sub template of the ManageMembers template.
  619. */
  620. function MembersAwaitingActivation()
  621. {
  622. global $txt, $context, $scripturl, $modSettings, $smcFunc;
  623. global $sourcedir;
  624. // Not a lot here!
  625. $context['page_title'] = $txt['admin_members'];
  626. $context['sub_template'] = 'admin_browse';
  627. $context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
  628. if (isset($context['tabs'][$context['browse_type']]))
  629. $context['tabs'][$context['browse_type']]['is_selected'] = true;
  630. // Allowed filters are those we can have, in theory.
  631. $context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
  632. $context['current_filter'] = isset($_REQUEST['filter']) && in_array($_REQUEST['filter'], $context['allowed_filters']) && !empty($context['activation_numbers'][$_REQUEST['filter']]) ? (int) $_REQUEST['filter'] : -1;
  633. // Sort out the different sub areas that we can actually filter by.
  634. $context['available_filters'] = array();
  635. foreach ($context['activation_numbers'] as $type => $amount)
  636. {
  637. // We have some of these...
  638. if (in_array($type, $context['allowed_filters']) && $amount > 0)
  639. $context['available_filters'][] = array(
  640. 'type' => $type,
  641. 'amount' => $amount,
  642. 'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
  643. 'selected' => $type == $context['current_filter']
  644. );
  645. }
  646. // If the filter was not sent, set it to whatever has people in it!
  647. if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
  648. $context['current_filter'] = $context['available_filters'][0]['type'];
  649. // This little variable is used to determine if we should flag where we are looking.
  650. $context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
  651. // The columns that can be sorted.
  652. $context['columns'] = array(
  653. 'id_member' => array('label' => $txt['admin_browse_id']),
  654. 'member_name' => array('label' => $txt['admin_browse_username']),
  655. 'email_address' => array('label' => $txt['admin_browse_email']),
  656. 'member_ip' => array('label' => $txt['admin_browse_ip']),
  657. 'date_registered' => array('label' => $txt['admin_browse_registered']),
  658. );
  659. // Are we showing duplicate information?
  660. if (isset($_GET['showdupes']))
  661. $_SESSION['showdupes'] = (int) $_GET['showdupes'];
  662. $context['show_duplicates'] = !empty($_SESSION['showdupes']);
  663. // Determine which actions we should allow on this page.
  664. if ($context['browse_type'] == 'approve')
  665. {
  666. // If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
  667. if ($context['current_filter'] == 4)
  668. $context['allowed_actions'] = array(
  669. 'reject' => $txt['admin_browse_w_approve_deletion'],
  670. 'ok' => $txt['admin_browse_w_reject'],
  671. );
  672. else
  673. $context['allowed_actions'] = array(
  674. 'ok' => $txt['admin_browse_w_approve'],
  675. 'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
  676. 'require_activation' => $txt['admin_browse_w_approve_require_activate'],
  677. 'reject' => $txt['admin_browse_w_reject'],
  678. 'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
  679. );
  680. }
  681. elseif ($context['browse_type'] == 'activate')
  682. $context['allowed_actions'] = array(
  683. 'ok' => $txt['admin_browse_w_activate'],
  684. 'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
  685. 'delete' => $txt['admin_browse_w_delete'],
  686. 'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
  687. 'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
  688. );
  689. // Create an option list for actions allowed to be done with selected members.
  690. $allowed_actions = '
  691. <option selected="selected" value="">' . $txt['admin_browse_with_selected'] . ':</option>
  692. <option value="" disabled="disabled">-----------------------------</option>';
  693. foreach ($context['allowed_actions'] as $key => $desc)
  694. $allowed_actions .= '
  695. <option value="' . $key . '">' . $desc . '</option>';
  696. // Setup the Javascript function for selecting an action for the list.
  697. $javascript = '
  698. function onSelectChange()
  699. {
  700. if (document.forms.postForm.todo.value == "")
  701. return;
  702. var message = "";';
  703. // We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
  704. if ($context['current_filter'] == 4)
  705. $javascript .= '
  706. if (document.forms.postForm.todo.value.indexOf("reject") != -1)
  707. message = "' . $txt['admin_browse_w_delete'] . '";
  708. else
  709. message = "' . $txt['admin_browse_w_reject'] . '";';
  710. // Otherwise a nice standard message.
  711. else
  712. $javascript .= '
  713. if (document.forms.postForm.todo.value.indexOf("delete") != -1)
  714. message = "' . $txt['admin_browse_w_delete'] . '";
  715. else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
  716. message = "' . $txt['admin_browse_w_reject'] . '";
  717. else if (document.forms.postForm.todo.value == "remind")
  718. message = "' . $txt['admin_browse_w_remind'] . '";
  719. else
  720. message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
  721. $javascript .= '
  722. if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
  723. document.forms.postForm.submit();
  724. }';
  725. $listOptions = array(
  726. 'id' => 'approve_list',
  727. // 'title' => $txt['members_approval_title'],
  728. 'items_per_page' => $modSettings['defaultMaxMembers'],
  729. 'base_href' => $scripturl . '?action=admin;area=viewmembers;sa=browse;type=' . $context['browse_type'] . (!empty($context['show_filter']) ? ';filter=' . $context['current_filter'] : ''),
  730. 'default_sort_col' => 'date_registered',
  731. 'get_items' => array(
  732. 'file' => $sourcedir . '/Subs-Members.php',
  733. 'function' => 'list_getMembers',
  734. 'params' => array(
  735. 'is_activated = {int:activated_status}',
  736. array('activated_status' => $context['current_filter']),
  737. $context['show_duplicates'],
  738. ),
  739. ),
  740. 'get_count' => array(
  741. 'file' => $sourcedir . '/Subs-Members.php',
  742. 'function' => 'list_getNumMembers',
  743. 'params' => array(
  744. 'is_activated = {int:activated_status}',
  745. array('activated_status' => $context['current_filter']),
  746. ),
  747. ),
  748. 'columns' => array(
  749. 'id_member' => array(
  750. 'header' => array(
  751. 'value' => $txt['member_id'],
  752. ),
  753. 'data' => array(
  754. 'db' => 'id_member',
  755. ),
  756. 'sort' => array(
  757. 'default' => 'id_member',
  758. 'reverse' => 'id_member DESC',
  759. ),
  760. ),
  761. 'user_name' => array(
  762. 'header' => array(
  763. 'value' => $txt['username'],
  764. ),
  765. 'data' => array(
  766. 'sprintf' => array(
  767. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
  768. 'params' => array(
  769. 'id_member' => false,
  770. 'member_name' => false,
  771. ),
  772. ),
  773. ),
  774. 'sort' => array(
  775. 'default' => 'member_name',
  776. 'reverse' => 'member_name DESC',
  777. ),
  778. ),
  779. 'email' => array(
  780. 'header' => array(
  781. 'value' => $txt['email_address'],
  782. ),
  783. 'data' => array(
  784. 'sprintf' => array(
  785. 'format' => '<a href="mailto:%1$s">%1$s</a>',
  786. 'params' => array(
  787. 'email_address' => true,
  788. ),
  789. ),
  790. ),
  791. 'sort' => array(
  792. 'default' => 'email_address',
  793. 'reverse' => 'email_address DESC',
  794. ),
  795. ),
  796. 'ip' => array(
  797. 'header' => array(
  798. 'value' => $txt['ip_address'],
  799. ),
  800. 'data' => array(
  801. 'sprintf' => array(
  802. 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=trackip;searchip=%1$s">%1$s</a>',
  803. 'params' => array(
  804. 'member_ip' => false,
  805. ),
  806. ),
  807. ),
  808. 'sort' => array(
  809. 'default' => 'INET_ATON(member_ip)',
  810. 'reverse' => 'INET_ATON(member_ip) DESC',
  811. ),
  812. ),
  813. 'hostname' => array(
  814. 'header' => array(
  815. 'value' => $txt['hostname'],
  816. ),
  817. 'data' => array(
  818. 'function' => create_function('$rowData', '
  819. global $modSettings;
  820. return host_from_ip($rowData[\'member_ip\']);
  821. '),
  822. 'class' => 'smalltext',
  823. ),
  824. ),
  825. 'date_registered' => array(
  826. 'header' => array(
  827. 'value' => $context['current_filter'] == 4 ? $txt['viewmembers_online'] : $txt['date_registered'],
  828. ),
  829. 'data' => array(
  830. 'function' => create_function('$rowData', '
  831. return timeformat($rowData[\'' . ($context['current_filter'] == 4 ? 'last_login' : 'date_registered') . '\']);
  832. '),
  833. ),
  834. 'sort' => array(
  835. 'default' => $context['current_filter'] == 4 ? 'mem.last_login DESC' : 'date_registered DESC',
  836. 'reverse' => $context['current_filter'] == 4 ? 'mem.last_login' : 'date_registered',
  837. ),
  838. ),
  839. 'duplicates' => array(
  840. 'header' => array(
  841. 'value' => $txt['duplicates'],
  842. // Make sure it doesn't go too wide.
  843. 'style' => 'width: 20%;',
  844. ),
  845. 'data' => array(
  846. 'function' => create_function('$rowData', '
  847. global $scripturl, $txt;
  848. $member_links = array();
  849. foreach ($rowData[\'duplicate_members\'] as $member)
  850. {
  851. if ($member[\'id\'])
  852. $member_links[] = \'<a href="\' . $scripturl . \'?action=profile;u=\' . $member[\'id\'] . \'" \' . (!empty($member[\'is_banned\']) ? \'style="color: red;"\' : \'\') . \'>\' . $member[\'name\'] . \'</a>\';
  853. else
  854. $member_links[] = $member[\'name\'] . \' (\' . $txt[\'guest\'] . \')\';
  855. }
  856. return implode (\', \', $member_links);
  857. '),
  858. 'class' => 'smalltext',
  859. ),
  860. ),
  861. 'check' => array(
  862. 'header' => array(
  863. 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
  864. 'class' => 'centercol',
  865. ),
  866. 'data' => array(
  867. 'sprintf' => array(
  868. 'format' => '<input type="checkbox" name="todoAction[]" value="%1$d" class="input_check" />',
  869. 'params' => array(
  870. 'id_member' => false,
  871. ),
  872. ),
  873. 'class' => 'centercol',
  874. ),
  875. ),
  876. ),
  877. 'javascript' => $javascript,
  878. 'form' => array(
  879. 'href' => $scripturl . '?action=admin;area=viewmembers;sa=approve;type=' . $context['browse_type'],
  880. 'name' => 'postForm',
  881. 'include_start' => true,
  882. 'include_sort' => true,
  883. 'hidden_fields' => array(
  884. 'orig_filter' => $context['current_filter'],
  885. ),
  886. ),
  887. 'additional_rows' => array(
  888. array(
  889. 'position' => 'below_table_data',
  890. 'value' => '
  891. [<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>]
  892. <select name="todo" onchange="onSelectChange();">
  893. ' . $allowed_actions . '
  894. </select>
  895. <noscript><input type="submit" value="' . $txt['go'] . '" class="button_submit" /><br class="clear_right" /></noscript>
  896. ',
  897. 'class' => 'floatright',
  898. ),
  899. ),
  900. );
  901. // Pick what column to actually include if we're showing duplicates.
  902. if ($context['show_duplicates'])
  903. unset($listOptions['columns']['email']);
  904. else
  905. unset($listOptions['columns']['duplicates']);
  906. // Only show hostname on duplicates as it takes a lot of time.
  907. if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
  908. unset($listOptions['columns']['hostname']);
  909. // Is there any need to show filters?
  910. if (isset($context['available_filters']) && count($context['available_filters']) > 1)
  911. {
  912. $filterOptions = '
  913. <strong>' . $txt['admin_browse_filter_by'] . ':</strong>
  914. <select name="filter" onchange="this.form.submit();">';
  915. foreach ($context['available_filters'] as $filter)
  916. $filterOptions .= '
  917. <option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected="selected"' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
  918. $filterOptions .= '
  919. </select>
  920. <noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button_submit" /></noscript>';
  921. $listOptions['additional_rows'][] = array(
  922. 'position' => 'top_of_list',
  923. 'value' => $filterOptions,
  924. 'class' => 'righttext',
  925. );
  926. }
  927. // What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
  928. if (!empty($context['show_filter']) && !empty($context['available_filters']))
  929. $listOptions['additional_rows'][] = array(
  930. 'position' => 'above_column_headers',
  931. 'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
  932. 'class' => 'smalltext floatright',
  933. );
  934. // Now that we have all the options, create the list.
  935. require_once($sourcedir . '/Subs-List.php');
  936. createList($listOptions);
  937. }
  938. /**
  939. * This function handles the approval, rejection, activation or deletion of members.
  940. * Called by ?action=admin;area=viewmembers;sa=approve.
  941. * Requires the moderate_forum permission.
  942. * Redirects to ?action=admin;area=viewmembers;sa=browse
  943. * with the same parameters as the calling page.
  944. */
  945. function AdminApprove()
  946. {
  947. global $txt, $context, $scripturl, $modSettings, $sourcedir, $language, $user_info, $smcFunc;
  948. // First, check our session.
  949. checkSession();
  950. require_once($sourcedir . '/Subs-Post.php');
  951. // We also need to the login languages here - for emails.
  952. loadLanguage('Login');
  953. // Sort out where we are going...
  954. $browse_type = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
  955. $current_filter = (int) $_REQUEST['orig_filter'];
  956. // If we are applying a filter do just that - then redirect.
  957. if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
  958. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
  959. // Nothing to do?
  960. if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
  961. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
  962. // Are we dealing with members who have been waiting for > set amount of time?
  963. if (isset($_POST['time_passed']))
  964. {
  965. $timeBefore = time() - 86400 * (int) $_POST['time_passed'];
  966. $condition = '
  967. AND date_registered < {int:time_before}';
  968. }
  969. // Coming from checkboxes - validate the members passed through to us.
  970. else
  971. {
  972. $members = array();
  973. foreach ($_POST['todoAction'] as $id)
  974. $members[] = (int) $id;
  975. $condition = '
  976. AND id_member IN ({array_int:members})';
  977. }
  978. // Get information on each of the members, things that are important to us, like email address...
  979. $request = $smcFunc['db_query']('', '
  980. SELECT id_member, member_name, real_name, email_address, validation_code, lngfile
  981. FROM {db_prefix}members
  982. WHERE is_activated = {int:activated_status}' . $condition . '
  983. ORDER BY lngfile',
  984. array(
  985. 'activated_status' => $current_filter,
  986. 'time_before' => empty($timeBefore) ? 0 : $timeBefore,
  987. 'members' => empty($members) ? array() : $members,
  988. )
  989. );
  990. $member_count = $smcFunc['db_num_rows']($request);
  991. // If no results then just return!
  992. if ($member_count == 0)
  993. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
  994. $member_info = array();
  995. $members = array();
  996. // Fill the info array.
  997. while ($row = $smcFunc['db_fetch_assoc']($request))
  998. {
  999. $members[] = $row['id_member'];
  1000. $member_info[] = array(
  1001. 'id' => $row['id_member'],
  1002. 'username' => $row['member_name'],
  1003. 'name' => $row['real_name'],
  1004. 'email' => $row['email_address'],
  1005. 'language' => empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'],
  1006. 'code' => $row['validation_code']
  1007. );
  1008. }
  1009. $smcFunc['db_free_result']($request);
  1010. // Are we activating or approving the members?
  1011. if ($_POST['todo'] == 'ok' || $_POST['todo'] == 'okemail')
  1012. {
  1013. // Approve/activate this member.
  1014. $smcFunc['db_query']('', '
  1015. UPDATE {db_prefix}members
  1016. SET validation_code = {string:blank_string}, is_activated = {int:is_activated}
  1017. WHERE is_activated = {int:activated_status}' . $condition,
  1018. array(
  1019. 'is_activated' => 1,
  1020. 'time_before' => empty($timeBefore) ? 0 : $timeBefore,
  1021. 'members' => empty($members) ? array() : $members,
  1022. 'activated_status' => $current_filter,
  1023. 'blank_string' => '',
  1024. )
  1025. );
  1026. // Do we have to let the integration code know about the activations?
  1027. if (!empty($modSettings['integrate_activate']))
  1028. {
  1029. foreach ($member_info as $member)
  1030. call_integration_hook('integrate_activate', array($member['username']));
  1031. }
  1032. // Check for email.
  1033. if ($_POST['todo'] == 'okemail')
  1034. {
  1035. foreach ($member_info as $member)
  1036. {
  1037. $replacements = array(
  1038. 'NAME' => $member['name'],
  1039. 'USERNAME' => $member['username'],
  1040. 'PROFILELINK' => $scripturl . '?action=profile;u=' . $member['id'],
  1041. 'FORGOTPASSWORDLINK' => $scripturl . '?action=reminder',
  1042. );
  1043. $emaildata = loadEmailTemplate('admin_approve_accept', $replacements, $member['language']);
  1044. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  1045. }
  1046. }
  1047. }
  1048. // Maybe we're sending it off for activation?
  1049. elseif ($_POST['todo'] == 'require_activation')
  1050. {
  1051. require_once($sourcedir . '/Subs-Members.php');
  1052. // We have to do this for each member I'm afraid.
  1053. foreach ($member_info as $member)
  1054. {
  1055. // Generate a random activation code.
  1056. $validation_code = generateValidationCode();
  1057. // Set these members for activation - I know this includes two id_member checks but it's safer than bodging $condition ;).
  1058. $smcFunc['db_query']('', '
  1059. UPDATE {db_prefix}members
  1060. SET validation_code = {string:validation_code}, is_activated = {int:not_activated}
  1061. WHERE is_activated = {int:activated_status}
  1062. ' . $condition . '
  1063. AND id_member = {int:selected_member}',
  1064. array(
  1065. 'not_activated' => 0,
  1066. 'activated_status' => $current_filter,
  1067. 'selected_member' => $member['id'],
  1068. 'validation_code' => $validation_code,
  1069. 'time_before' => empty($timeBefore) ? 0 : $timeBefore,
  1070. 'members' => empty($members) ? array() : $members,
  1071. )
  1072. );
  1073. $replacements = array(
  1074. 'USERNAME' => $member['name'],
  1075. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $member['id'] . ';code=' . $validation_code,
  1076. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $member['id'],
  1077. 'ACTIVATIONCODE' => $validation_code,
  1078. );
  1079. $emaildata = loadEmailTemplate('admin_approve_activation', $replacements, $member['language']);
  1080. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 0);
  1081. }
  1082. }
  1083. // Are we rejecting them?
  1084. elseif ($_POST['todo'] == 'reject' || $_POST['todo'] == 'rejectemail')
  1085. {
  1086. require_once($sourcedir . '/Subs-Members.php');
  1087. deleteMembers($members);
  1088. // Send email telling them they aren't welcome?
  1089. if ($_POST['todo'] == 'rejectemail')
  1090. {
  1091. foreach ($member_info as $member)
  1092. {
  1093. $replacements = array(
  1094. 'USERNAME' => $member['name'],
  1095. );
  1096. $emaildata = loadEmailTemplate('admin_approve_reject', $replacements, $member['language']);
  1097. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 1);
  1098. }
  1099. }
  1100. }
  1101. // A simple delete?
  1102. elseif ($_POST['todo'] == 'delete' || $_POST['todo'] == 'deleteemail')
  1103. {
  1104. require_once($sourcedir . '/Subs-Members.php');
  1105. deleteMembers($members);
  1106. // Send email telling them they aren't welcome?
  1107. if ($_POST['todo'] == 'deleteemail')
  1108. {
  1109. foreach ($member_info as $member)
  1110. {
  1111. $replacements = array(
  1112. 'USERNAME' => $member['name'],
  1113. );
  1114. $emaildata = loadEmailTemplate('admin_approve_delete', $replacements, $member['language']);
  1115. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 1);
  1116. }
  1117. }
  1118. }
  1119. // Remind them to activate their account?
  1120. elseif ($_POST['todo'] == 'remind')
  1121. {
  1122. foreach ($member_info as $member)
  1123. {
  1124. $replacements = array(
  1125. 'USERNAME' => $member['name'],
  1126. 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $member['id'] . ';code=' . $member['code'],
  1127. 'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $member['id'],
  1128. 'ACTIVATIONCODE' => $member['code'],
  1129. );
  1130. $emaildata = loadEmailTemplate('admin_approve_remind', $replacements, $member['language']);
  1131. sendmail($member['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 1);
  1132. }
  1133. }
  1134. // @todo current_language is never set, no idea what this is for. Remove?
  1135. // Back to the user's language!
  1136. if (isset($current_language) && $current_language != $user_info['language'])
  1137. {
  1138. loadLanguage('index');
  1139. loadLanguage('ManageMembers');
  1140. }
  1141. // Log what we did?
  1142. if (!empty($modSettings['modlog_enabled']) && in_array($_POST['todo'], array('ok', 'okemail', 'require_activation', 'remind')))
  1143. {
  1144. $log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
  1145. $log_inserts = array();
  1146. require_once($sourcedir . '/Logging.php');
  1147. foreach ($member_info as $member)
  1148. logAction($log_action, array('member' => $member['id']), 'admin');
  1149. }
  1150. // Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
  1151. if (in_array($current_filter, array(3, 4)))
  1152. updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
  1153. // Update the member's stats. (but, we know the member didn't change their name.)
  1154. updateStats('member', false);
  1155. // If they haven't been deleted, update the post group statistics on them...
  1156. if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
  1157. updateStats('postgroups', $members);
  1158. redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
  1159. }
  1160. /**
  1161. * Nifty function to calculate the number of days ago a given date was.
  1162. * Requires a unix timestamp as input, returns an integer.
  1163. * Named in honour of Jeff Lewis, the original creator of...this function.
  1164. *
  1165. * @param $old
  1166. * @return int, the returned number of days, based on the forum time.
  1167. */
  1168. function jeffsdatediff($old)
  1169. {
  1170. // Get the current time as the user would see it...
  1171. $forumTime = forum_time();
  1172. // Calculate the seconds that have passed since midnight.
  1173. $sinceMidnight = date('H', $forumTime) * 60 * 60 + date('i', $forumTime) * 60 + date('s', $forumTime);
  1174. // Take the difference between the two times.
  1175. $dis = time() - $old;
  1176. // Before midnight?
  1177. if ($dis < $sinceMidnight)
  1178. return 0;
  1179. else
  1180. $dis -= $sinceMidnight;
  1181. // Divide out the seconds in a day to get the number of days.
  1182. return ceil($dis / (24 * 60 * 60));
  1183. }
  1184. ?>