ManageMembers.php 45 KB

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