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