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