ManageMembers.php 45 KB

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