1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file currently just shows group info, and allows certain priviledged members to add/remove members. |
5
|
|
|
* |
6
|
|
|
* Simple Machines Forum (SMF) |
7
|
|
|
* |
8
|
|
|
* @package SMF |
9
|
|
|
* @author Simple Machines https://www.simplemachines.org |
10
|
|
|
* @copyright 2022 Simple Machines and individual contributors |
11
|
|
|
* @license https://www.simplemachines.org/about/smf/license.php BSD |
12
|
|
|
* |
13
|
|
|
* @version 2.1.2 |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
if (!defined('SMF')) |
17
|
|
|
die('No direct access...'); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Entry point function, permission checks, admin bars, etc. |
21
|
|
|
* It allows moderators and users to access the group showing functions. |
22
|
|
|
* It handles permission checks, and puts the moderation bar on as required. |
23
|
|
|
*/ |
24
|
|
|
function Groups() |
25
|
|
|
{ |
26
|
|
|
global $context, $txt, $scripturl, $sourcedir, $user_info; |
27
|
|
|
|
28
|
|
|
// The sub-actions that we can do. Format "Function Name, Mod Bar Index if appropriate". |
29
|
|
|
$subActions = array( |
30
|
|
|
'index' => array('GroupList', 'view_groups'), |
31
|
|
|
'members' => array('MembergroupMembers', 'view_groups'), |
32
|
|
|
'requests' => array('GroupRequests', 'group_requests'), |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
// Default to sub action 'index'. |
36
|
|
|
$_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'index'; |
37
|
|
|
|
38
|
|
|
// Get the template stuff up and running. |
39
|
|
|
loadLanguage('ManageMembers'); |
40
|
|
|
loadLanguage('ModerationCenter'); |
41
|
|
|
loadTemplate('ManageMembergroups'); |
42
|
|
|
|
43
|
|
|
// If we can see the moderation center, and this has a mod bar entry, add the mod center bar. |
44
|
|
|
if (allowedTo('access_mod_center') || $user_info['mod_cache']['bq'] != '0=1' || $user_info['mod_cache']['gq'] != '0=1' || allowedTo('manage_membergroups')) |
45
|
|
|
{ |
46
|
|
|
require_once($sourcedir . '/ModerationCenter.php'); |
47
|
|
|
$_GET['area'] = $_REQUEST['sa'] == 'requests' ? 'groups' : 'viewgroups'; |
48
|
|
|
ModerationMain(true); |
49
|
|
|
} |
50
|
|
|
// Otherwise add something to the link tree, for normal people. |
51
|
|
|
else |
52
|
|
|
{ |
53
|
|
|
isAllowedTo('view_mlist'); |
54
|
|
|
|
55
|
|
|
$context['linktree'][] = array( |
56
|
|
|
'url' => $scripturl . '?action=groups', |
57
|
|
|
'name' => $txt['groups'], |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// CRUD $subActions as needed. |
62
|
|
|
call_integration_hook('integrate_manage_groups', array(&$subActions)); |
63
|
|
|
|
64
|
|
|
// Call the actual function. |
65
|
|
|
call_helper($subActions[$_REQUEST['sa']][0]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* This very simply lists the groups, nothing snazy. |
70
|
|
|
*/ |
71
|
|
|
function GroupList() |
72
|
|
|
{ |
73
|
|
|
global $txt, $context, $sourcedir, $scripturl; |
74
|
|
|
|
75
|
|
|
$context['page_title'] = $txt['viewing_groups']; |
76
|
|
|
|
77
|
|
|
// Making a list is not hard with this beauty. |
78
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
79
|
|
|
|
80
|
|
|
// Use the standard templates for showing this. |
81
|
|
|
$listOptions = array( |
82
|
|
|
'id' => 'group_lists', |
83
|
|
|
'title' => $context['page_title'], |
84
|
|
|
'base_href' => $scripturl . '?action=moderate;area=viewgroups;sa=view', |
85
|
|
|
'default_sort_col' => 'group', |
86
|
|
|
'get_items' => array( |
87
|
|
|
'file' => $sourcedir . '/Subs-Membergroups.php', |
88
|
|
|
'function' => 'list_getMembergroups', |
89
|
|
|
'params' => array( |
90
|
|
|
'regular', |
91
|
|
|
), |
92
|
|
|
), |
93
|
|
|
'columns' => array( |
94
|
|
|
'group' => array( |
95
|
|
|
'header' => array( |
96
|
|
|
'value' => $txt['name'], |
97
|
|
|
), |
98
|
|
|
'data' => array( |
99
|
|
|
'function' => function($rowData) use ($scripturl) |
100
|
|
|
{ |
101
|
|
|
// Since the moderator group has no explicit members, no link is needed. |
102
|
|
|
if ($rowData['id_group'] == 3) |
103
|
|
|
$group_name = $rowData['group_name']; |
104
|
|
|
else |
105
|
|
|
{ |
106
|
|
|
$color_style = empty($rowData['online_color']) ? '' : sprintf(' style="color: %1$s;"', $rowData['online_color']); |
107
|
|
|
|
108
|
|
|
if (allowedTo('manage_membergroups')) |
109
|
|
|
{ |
110
|
|
|
$group_name = sprintf('<a href="%1$s?action=admin;area=membergroups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
111
|
|
|
} |
112
|
|
|
else |
113
|
|
|
{ |
114
|
|
|
$group_name = sprintf('<a href="%1$s?action=groups;sa=members;group=%2$d"%3$s>%4$s</a>', $scripturl, $rowData['id_group'], $color_style, $rowData['group_name']); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// Add a help option for moderator and administrator. |
119
|
|
|
if ($rowData['id_group'] == 1) |
120
|
|
|
$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_administrator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
121
|
|
|
elseif ($rowData['id_group'] == 3) |
122
|
|
|
$group_name .= sprintf(' (<a href="%1$s?action=helpadmin;help=membergroup_moderator" onclick="return reqOverlayDiv(this.href);">?</a>)', $scripturl); |
123
|
|
|
|
124
|
|
|
return $group_name; |
125
|
|
|
}, |
126
|
|
|
), |
127
|
|
|
'sort' => array( |
128
|
|
|
'default' => 'CASE WHEN mg.id_group < 4 THEN mg.id_group ELSE 4 END, mg.group_name', |
129
|
|
|
'reverse' => 'CASE WHEN mg.id_group < 4 THEN mg.id_group ELSE 4 END, mg.group_name DESC', |
130
|
|
|
), |
131
|
|
|
), |
132
|
|
|
'icons' => array( |
133
|
|
|
'header' => array( |
134
|
|
|
'value' => $txt['membergroups_icons'], |
135
|
|
|
), |
136
|
|
|
'data' => array( |
137
|
|
|
'db' => 'icons', |
138
|
|
|
), |
139
|
|
|
'sort' => array( |
140
|
|
|
'default' => 'mg.icons', |
141
|
|
|
'reverse' => 'mg.icons DESC', |
142
|
|
|
) |
143
|
|
|
), |
144
|
|
|
'moderators' => array( |
145
|
|
|
'header' => array( |
146
|
|
|
'value' => $txt['moderators'], |
147
|
|
|
), |
148
|
|
|
'data' => array( |
149
|
|
|
'function' => function($group) use ($txt) |
150
|
|
|
{ |
151
|
|
|
return empty($group['moderators']) ? '<em>' . $txt['membergroups_new_copy_none'] . '</em>' : implode(', ', $group['moderators']); |
152
|
|
|
}, |
153
|
|
|
), |
154
|
|
|
), |
155
|
|
|
'members' => array( |
156
|
|
|
'header' => array( |
157
|
|
|
'value' => $txt['membergroups_members_top'], |
158
|
|
|
), |
159
|
|
|
'data' => array( |
160
|
|
|
'function' => function($rowData) use ($txt) |
161
|
|
|
{ |
162
|
|
|
// No explicit members for the moderator group. |
163
|
|
|
return $rowData['id_group'] == 3 ? $txt['membergroups_guests_na'] : comma_format($rowData['num_members']); |
164
|
|
|
}, |
165
|
|
|
'class' => 'centercol', |
166
|
|
|
), |
167
|
|
|
'sort' => array( |
168
|
|
|
'default' => 'CASE WHEN mg.id_group < 4 THEN mg.id_group ELSE 4 END, 1', |
169
|
|
|
'reverse' => 'CASE WHEN mg.id_group < 4 THEN mg.id_group ELSE 4 END, 1 DESC', |
170
|
|
|
), |
171
|
|
|
), |
172
|
|
|
), |
173
|
|
|
); |
174
|
|
|
|
175
|
|
|
// Create the request list. |
176
|
|
|
createList($listOptions); |
177
|
|
|
|
178
|
|
|
$context['sub_template'] = 'show_list'; |
179
|
|
|
$context['default_list'] = 'group_lists'; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Display members of a group, and allow adding of members to a group. Silly function name though ;) |
184
|
|
|
* It can be called from ManageMembergroups if it needs templating within the admin environment. |
185
|
|
|
* It shows a list of members that are part of a given membergroup. |
186
|
|
|
* It is called by ?action=moderate;area=viewgroups;sa=members;group=x |
187
|
|
|
* It requires the manage_membergroups permission. |
188
|
|
|
* It allows to add and remove members from the selected membergroup. |
189
|
|
|
* It allows sorting on several columns. |
190
|
|
|
* It redirects to itself. |
191
|
|
|
* |
192
|
|
|
* @uses template_group_members() |
193
|
|
|
* @todo: use createList |
194
|
|
|
*/ |
195
|
|
|
function MembergroupMembers() |
196
|
|
|
{ |
197
|
|
|
global $txt, $scripturl, $context, $modSettings, $sourcedir, $user_info, $settings, $smcFunc; |
198
|
|
|
|
199
|
|
|
$_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0; |
200
|
|
|
|
201
|
|
|
// No browsing of guests, membergroup 0 or moderators. |
202
|
|
|
if (in_array($_REQUEST['group'], array(-1, 0, 3))) |
203
|
|
|
fatal_lang_error('membergroup_does_not_exist', false); |
204
|
|
|
|
205
|
|
|
// Load up the group details. |
206
|
|
|
$request = $smcFunc['db_query']('', ' |
207
|
|
|
SELECT id_group AS id, group_name AS name, CASE WHEN min_posts = {int:min_posts} THEN 1 ELSE 0 END AS assignable, hidden, online_color, |
208
|
|
|
icons, description, CASE WHEN min_posts != {int:min_posts} THEN 1 ELSE 0 END AS is_post_group, group_type |
209
|
|
|
FROM {db_prefix}membergroups |
210
|
|
|
WHERE id_group = {int:id_group} |
211
|
|
|
LIMIT 1', |
212
|
|
|
array( |
213
|
|
|
'min_posts' => -1, |
214
|
|
|
'id_group' => $_REQUEST['group'], |
215
|
|
|
) |
216
|
|
|
); |
217
|
|
|
// Doesn't exist? |
218
|
|
|
if ($smcFunc['db_num_rows']($request) == 0) |
219
|
|
|
fatal_lang_error('membergroup_does_not_exist', false); |
220
|
|
|
$context['group'] = $smcFunc['db_fetch_assoc']($request); |
221
|
|
|
$smcFunc['db_free_result']($request); |
222
|
|
|
|
223
|
|
|
// Fix the membergroup icons. |
224
|
|
|
$context['group']['icons'] = explode('#', $context['group']['icons']); |
225
|
|
|
$context['group']['icons'] = !empty($context['group']['icons'][0]) && !empty($context['group']['icons'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/membericons/' . $context['group']['icons'][1] . '" alt="*">', $context['group']['icons'][0]) : ''; |
226
|
|
|
$context['group']['can_moderate'] = allowedTo('manage_membergroups') && (allowedTo('admin_forum') || $context['group']['group_type'] != 1); |
227
|
|
|
|
228
|
|
|
$context['linktree'][] = array( |
229
|
|
|
'url' => $scripturl . '?action=groups;sa=members;group=' . $context['group']['id'], |
230
|
|
|
'name' => $context['group']['name'], |
231
|
|
|
); |
232
|
|
|
$context['can_send_email'] = allowedTo('moderate_forum'); |
233
|
|
|
|
234
|
|
|
// Load all the group moderators, for fun. |
235
|
|
|
$request = $smcFunc['db_query']('', ' |
236
|
|
|
SELECT mem.id_member, mem.real_name |
237
|
|
|
FROM {db_prefix}group_moderators AS mods |
238
|
|
|
INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member) |
239
|
|
|
WHERE mods.id_group = {int:id_group}', |
240
|
|
|
array( |
241
|
|
|
'id_group' => $_REQUEST['group'], |
242
|
|
|
) |
243
|
|
|
); |
244
|
|
|
$context['group']['moderators'] = array(); |
245
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
246
|
|
|
{ |
247
|
|
|
$context['group']['moderators'][] = array( |
248
|
|
|
'id' => $row['id_member'], |
249
|
|
|
'name' => $row['real_name'] |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) |
253
|
|
|
$context['group']['can_moderate'] = true; |
254
|
|
|
} |
255
|
|
|
$smcFunc['db_free_result']($request); |
256
|
|
|
|
257
|
|
|
// If this group is hidden then it can only "exists" if the user can moderate it! |
258
|
|
|
if ($context['group']['hidden'] && !$context['group']['can_moderate']) |
259
|
|
|
fatal_lang_error('membergroup_does_not_exist', false); |
260
|
|
|
|
261
|
|
|
// You can only assign membership if you are the moderator and/or can manage groups! |
262
|
|
|
if (!$context['group']['can_moderate']) |
263
|
|
|
$context['group']['assignable'] = 0; |
264
|
|
|
// Non-admins cannot assign admins. |
265
|
|
|
elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) |
266
|
|
|
$context['group']['assignable'] = 0; |
267
|
|
|
|
268
|
|
|
// Removing member from group? |
269
|
|
|
if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $context['group']['assignable']) |
270
|
|
|
{ |
271
|
|
|
checkSession(); |
272
|
|
|
validateToken('mod-mgm'); |
273
|
|
|
|
274
|
|
|
// Only proven admins can remove admins. |
275
|
|
|
if ($context['group']['id'] == 1) |
276
|
|
|
validateSession(); |
277
|
|
|
|
278
|
|
|
// Make sure we're dealing with integers only. |
279
|
|
|
foreach ($_REQUEST['rem'] as $key => $group) |
280
|
|
|
$_REQUEST['rem'][$key] = (int) $group; |
281
|
|
|
|
282
|
|
|
require_once($sourcedir . '/Subs-Membergroups.php'); |
283
|
|
|
removeMembersFromGroups($_REQUEST['rem'], $_REQUEST['group'], true); |
284
|
|
|
} |
285
|
|
|
// Must be adding new members to the group... |
286
|
|
|
elseif (isset($_REQUEST['add']) && (!empty($_REQUEST['toAdd']) || !empty($_REQUEST['member_add'])) && $context['group']['assignable']) |
287
|
|
|
{ |
288
|
|
|
// Demand an admin password before adding new admins -- every time, no matter what. |
289
|
|
|
if ($context['group']['id'] == 1) |
290
|
|
|
validateSession('admin', true); |
|
|
|
|
291
|
|
|
|
292
|
|
|
checkSession(); |
293
|
|
|
validateToken('mod-mgm'); |
294
|
|
|
|
295
|
|
|
$member_query = array(); |
296
|
|
|
$member_parameters = array(); |
297
|
|
|
|
298
|
|
|
// Get all the members to be added... taking into account names can be quoted ;) |
299
|
|
|
$_REQUEST['toAdd'] = strtr($smcFunc['htmlspecialchars']($_REQUEST['toAdd'], ENT_QUOTES), array('"' => '"')); |
300
|
|
|
preg_match_all('~"([^"]+)"~', $_REQUEST['toAdd'], $matches); |
301
|
|
|
$member_names = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_REQUEST['toAdd'])))); |
302
|
|
|
|
303
|
|
|
foreach ($member_names as $index => $member_name) |
304
|
|
|
{ |
305
|
|
|
$member_names[$index] = trim($smcFunc['strtolower']($member_names[$index])); |
306
|
|
|
|
307
|
|
|
if (strlen($member_names[$index]) == 0) |
308
|
|
|
unset($member_names[$index]); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
// Any passed by ID? |
312
|
|
|
$member_ids = array(); |
313
|
|
|
if (!empty($_REQUEST['member_add'])) |
314
|
|
|
foreach ($_REQUEST['member_add'] as $id) |
315
|
|
|
if ($id > 0) |
316
|
|
|
$member_ids[] = (int) $id; |
317
|
|
|
|
318
|
|
|
// Construct the query pelements. |
319
|
|
|
if (!empty($member_ids)) |
320
|
|
|
{ |
321
|
|
|
$member_query[] = 'id_member IN ({array_int:member_ids})'; |
322
|
|
|
$member_parameters['member_ids'] = $member_ids; |
323
|
|
|
} |
324
|
|
|
if (!empty($member_names)) |
325
|
|
|
{ |
326
|
|
|
$member_query[] = 'LOWER(member_name) IN ({array_string:member_names})'; |
327
|
|
|
$member_query[] = 'LOWER(real_name) IN ({array_string:member_names})'; |
328
|
|
|
$member_parameters['member_names'] = $member_names; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
$members = array(); |
332
|
|
|
if (!empty($member_query)) |
333
|
|
|
{ |
334
|
|
|
$request = $smcFunc['db_query']('', ' |
335
|
|
|
SELECT id_member |
336
|
|
|
FROM {db_prefix}members |
337
|
|
|
WHERE (' . implode(' OR ', $member_query) . ') |
338
|
|
|
AND id_group != {int:id_group} |
339
|
|
|
AND FIND_IN_SET({int:id_group}, additional_groups) = 0', |
340
|
|
|
array_merge($member_parameters, array( |
341
|
|
|
'id_group' => $_REQUEST['group'], |
342
|
|
|
)) |
343
|
|
|
); |
344
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
345
|
|
|
$members[] = $row['id_member']; |
346
|
|
|
$smcFunc['db_free_result']($request); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
// @todo Add $_POST['additional'] to templates! |
350
|
|
|
|
351
|
|
|
// Do the updates... |
352
|
|
|
if (!empty($members)) |
353
|
|
|
{ |
354
|
|
|
require_once($sourcedir . '/Subs-Membergroups.php'); |
355
|
|
|
addMembersToGroup($members, $_REQUEST['group'], isset($_POST['additional']) || $context['group']['hidden'] ? 'only_additional' : 'auto', true); |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
// Sort out the sorting! |
360
|
|
|
$sort_methods = array( |
361
|
|
|
'name' => 'real_name', |
362
|
|
|
'email' => 'email_address', |
363
|
|
|
'active' => 'last_login', |
364
|
|
|
'registered' => 'date_registered', |
365
|
|
|
'posts' => 'posts', |
366
|
|
|
); |
367
|
|
|
|
368
|
|
|
// They didn't pick one, default to by name.. |
369
|
|
|
if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) |
370
|
|
|
{ |
371
|
|
|
$context['sort_by'] = 'name'; |
372
|
|
|
$querySort = 'real_name'; |
373
|
|
|
} |
374
|
|
|
// Otherwise default to ascending. |
375
|
|
|
else |
376
|
|
|
{ |
377
|
|
|
$context['sort_by'] = $_REQUEST['sort']; |
378
|
|
|
$querySort = $sort_methods[$_REQUEST['sort']]; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
382
|
|
|
|
383
|
|
|
// The where on the query is interesting. Non-moderators should only see people who are in this group as primary. |
384
|
|
|
if ($context['group']['can_moderate']) |
385
|
|
|
$where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; |
386
|
|
|
else |
387
|
|
|
$where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; |
388
|
|
|
|
389
|
|
|
// Count members of the group. |
390
|
|
|
$request = $smcFunc['db_query']('', ' |
391
|
|
|
SELECT COUNT(*) |
392
|
|
|
FROM {db_prefix}members |
393
|
|
|
WHERE ' . $where, |
394
|
|
|
array( |
395
|
|
|
'group' => $_REQUEST['group'], |
396
|
|
|
) |
397
|
|
|
); |
398
|
|
|
list ($context['total_members']) = $smcFunc['db_fetch_row']($request); |
399
|
|
|
$smcFunc['db_free_result']($request); |
400
|
|
|
|
401
|
|
|
// Create the page index. |
402
|
|
|
$context['page_index'] = constructPageIndex($scripturl . '?action=' . ($context['group']['can_moderate'] ? 'moderate;area=viewgroups' : 'groups') . ';sa=members;group=' . $_REQUEST['group'] . ';sort=' . $context['sort_by'] . (isset($_REQUEST['desc']) ? ';desc' : ''), $_REQUEST['start'], $context['total_members'], $modSettings['defaultMaxMembers']); |
403
|
|
|
$context['total_members'] = comma_format($context['total_members']); |
404
|
|
|
$context['start'] = $_REQUEST['start']; |
405
|
|
|
$context['can_moderate_forum'] = allowedTo('moderate_forum'); |
406
|
|
|
|
407
|
|
|
// Load up all members of this group. |
408
|
|
|
$request = $smcFunc['db_query']('', ' |
409
|
|
|
SELECT id_member, member_name, real_name, email_address, member_ip, date_registered, last_login, |
410
|
|
|
posts, is_activated, real_name |
411
|
|
|
FROM {db_prefix}members |
412
|
|
|
WHERE ' . $where . ' |
413
|
|
|
ORDER BY ' . $querySort . ' ' . ($context['sort_direction'] == 'down' ? 'DESC' : 'ASC') . ' |
414
|
|
|
LIMIT {int:start}, {int:max}', |
415
|
|
|
array( |
416
|
|
|
'group' => $_REQUEST['group'], |
417
|
|
|
'start' => $context['start'], |
418
|
|
|
'max' => $modSettings['defaultMaxMembers'], |
419
|
|
|
) |
420
|
|
|
); |
421
|
|
|
$context['members'] = array(); |
422
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
423
|
|
|
{ |
424
|
|
|
$row['member_ip'] = inet_dtop($row['member_ip']); |
425
|
|
|
$last_online = empty($row['last_login']) ? $txt['never'] : timeformat($row['last_login']); |
426
|
|
|
|
427
|
|
|
// Italicize the online note if they aren't activated. |
428
|
|
|
if ($row['is_activated'] % 10 != 1) |
429
|
|
|
$last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; |
430
|
|
|
|
431
|
|
|
$context['members'][] = array( |
432
|
|
|
'id' => $row['id_member'], |
433
|
|
|
'name' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', |
434
|
|
|
'email' => $row['email_address'], |
435
|
|
|
'ip' => '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['member_ip'] . '">' . $row['member_ip'] . '</a>', |
436
|
|
|
'registered' => timeformat($row['date_registered']), |
437
|
|
|
'last_online' => $last_online, |
438
|
|
|
'posts' => comma_format($row['posts']), |
439
|
|
|
'is_activated' => $row['is_activated'] % 10 == 1, |
440
|
|
|
); |
441
|
|
|
} |
442
|
|
|
$smcFunc['db_free_result']($request); |
443
|
|
|
|
444
|
|
|
// Select the template. |
445
|
|
|
$context['sub_template'] = 'group_members'; |
446
|
|
|
$context['page_title'] = $txt['membergroups_members_title'] . ': ' . $context['group']['name']; |
447
|
|
|
createToken('mod-mgm'); |
448
|
|
|
|
449
|
|
|
if ($context['group']['assignable']) |
450
|
|
|
loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest'); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* Show and manage all group requests. |
455
|
|
|
*/ |
456
|
|
|
function GroupRequests() |
457
|
|
|
{ |
458
|
|
|
global $txt, $context, $scripturl, $user_info, $sourcedir, $smcFunc, $modSettings; |
459
|
|
|
|
460
|
|
|
// Set up the template stuff... |
461
|
|
|
$context['page_title'] = $txt['mc_group_requests']; |
462
|
|
|
$context['sub_template'] = 'show_list'; |
463
|
|
|
|
464
|
|
|
// Verify we can be here. |
465
|
|
|
if ($user_info['mod_cache']['gq'] == '0=1') |
466
|
|
|
isAllowedTo('manage_membergroups'); |
467
|
|
|
|
468
|
|
|
// Normally, we act normally... |
469
|
|
|
$where = ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']); |
470
|
|
|
|
471
|
|
|
if (isset($_GET['closed'])) |
472
|
|
|
$where .= ' AND lgr.status != {int:status_open}'; |
473
|
|
|
else |
474
|
|
|
$where .= ' AND lgr.status = {int:status_open}'; |
475
|
|
|
|
476
|
|
|
$where_parameters = array( |
477
|
|
|
'status_open' => 0, |
478
|
|
|
); |
479
|
|
|
|
480
|
|
|
// We've submitted? |
481
|
|
|
if (isset($_POST[$context['session_var']]) && !empty($_POST['groupr']) && !empty($_POST['req_action'])) |
482
|
|
|
{ |
483
|
|
|
checkSession(); |
484
|
|
|
validateToken('mod-gr'); |
485
|
|
|
|
486
|
|
|
// Clean the values. |
487
|
|
|
foreach ($_POST['groupr'] as $k => $request) |
488
|
|
|
$_POST['groupr'][$k] = (int) $request; |
489
|
|
|
|
490
|
|
|
$log_changes = array(); |
491
|
|
|
|
492
|
|
|
// If we are giving a reason (And why shouldn't we?), then we don't actually do much. |
493
|
|
|
if ($_POST['req_action'] == 'reason') |
494
|
|
|
{ |
495
|
|
|
// Different sub template... |
496
|
|
|
$context['sub_template'] = 'group_request_reason'; |
497
|
|
|
// And a limitation. We don't care that the page number bit makes no sense, as we don't need it! |
498
|
|
|
$where .= ' AND lgr.id_request IN ({array_int:request_ids})'; |
499
|
|
|
$where_parameters['request_ids'] = $_POST['groupr']; |
500
|
|
|
|
501
|
|
|
$context['group_requests'] = list_getGroupRequests(0, $modSettings['defaultMaxListItems'], 'lgr.id_request', $where, $where_parameters); |
502
|
|
|
|
503
|
|
|
// Need to make another token for this. |
504
|
|
|
createToken('mod-gr'); |
505
|
|
|
|
506
|
|
|
// Let obExit etc sort things out. |
507
|
|
|
obExit(); |
508
|
|
|
} |
509
|
|
|
// Otherwise we do something! |
510
|
|
|
else |
511
|
|
|
{ |
512
|
|
|
$request = $smcFunc['db_query']('', ' |
513
|
|
|
SELECT lgr.id_request |
514
|
|
|
FROM {db_prefix}log_group_requests AS lgr |
515
|
|
|
WHERE ' . $where . ' |
516
|
|
|
AND lgr.id_request IN ({array_int:request_list})', |
517
|
|
|
array( |
518
|
|
|
'request_list' => $_POST['groupr'], |
519
|
|
|
'status_open' => 0, |
520
|
|
|
) |
521
|
|
|
); |
522
|
|
|
$request_list = array(); |
523
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
524
|
|
|
{ |
525
|
|
|
if (!isset($log_changes[$row['id_request']])) |
526
|
|
|
$log_changes[$row['id_request']] = array( |
527
|
|
|
'id_request' => $row['id_request'], |
528
|
|
|
'status' => $_POST['req_action'] == 'approve' ? 1 : 2, // 1 = approved, 2 = rejected |
529
|
|
|
'id_member_acted' => $user_info['id'], |
530
|
|
|
'member_name_acted' => $user_info['name'], |
531
|
|
|
'time_acted' => time(), |
532
|
|
|
'act_reason' => $_POST['req_action'] != 'approve' && !empty($_POST['groupreason']) && !empty($_POST['groupreason'][$row['id_request']]) ? $smcFunc['htmlspecialchars']($_POST['groupreason'][$row['id_request']], ENT_QUOTES) : '', |
533
|
|
|
); |
534
|
|
|
$request_list[] = $row['id_request']; |
535
|
|
|
} |
536
|
|
|
$smcFunc['db_free_result']($request); |
537
|
|
|
|
538
|
|
|
// Add a background task to handle notifying people of this request |
539
|
|
|
$data = $smcFunc['json_encode'](array('member_id' => $user_info['id'], 'member_ip' => $user_info['ip'], 'request_list' => $request_list, 'status' => $_POST['req_action'], 'reason' => isset($_POST['groupreason']) ? $_POST['groupreason'] : '', 'time' => time())); |
540
|
|
|
$smcFunc['db_insert']('insert', '{db_prefix}background_tasks', |
541
|
|
|
array('task_file' => 'string-255', 'task_class' => 'string-255', 'task_data' => 'string', 'claimed_time' => 'int'), |
542
|
|
|
array('$sourcedir/tasks/GroupAct-Notify.php', 'GroupAct_Notify_Background', $data, 0), array() |
543
|
|
|
); |
544
|
|
|
|
545
|
|
|
// Some changes to log? |
546
|
|
|
if (!empty($log_changes)) |
547
|
|
|
{ |
548
|
|
|
foreach ($log_changes as $id_request => $details) |
549
|
|
|
{ |
550
|
|
|
$smcFunc['db_query']('', ' |
551
|
|
|
UPDATE {db_prefix}log_group_requests |
552
|
|
|
SET status = {int:status}, |
553
|
|
|
id_member_acted = {int:id_member_acted}, |
554
|
|
|
member_name_acted = {string:member_name_acted}, |
555
|
|
|
time_acted = {int:time_acted}, |
556
|
|
|
act_reason = {string:act_reason} |
557
|
|
|
WHERE id_request = {int:id_request}', |
558
|
|
|
$details |
559
|
|
|
); |
560
|
|
|
} |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
// We're going to want this for making our list. |
566
|
|
|
require_once($sourcedir . '/Subs-List.php'); |
567
|
|
|
|
568
|
|
|
// This is all the information required for a group listing. |
569
|
|
|
$listOptions = array( |
570
|
|
|
'id' => 'group_request_list', |
571
|
|
|
'width' => '100%', |
572
|
|
|
'items_per_page' => $modSettings['defaultMaxListItems'], |
573
|
|
|
'no_items_label' => $txt['mc_groupr_none_found'], |
574
|
|
|
'base_href' => $scripturl . '?action=groups;sa=requests', |
575
|
|
|
'default_sort_col' => 'member', |
576
|
|
|
'get_items' => array( |
577
|
|
|
'function' => 'list_getGroupRequests', |
578
|
|
|
'params' => array( |
579
|
|
|
$where, |
580
|
|
|
$where_parameters, |
581
|
|
|
), |
582
|
|
|
), |
583
|
|
|
'get_count' => array( |
584
|
|
|
'function' => 'list_getGroupRequestCount', |
585
|
|
|
'params' => array( |
586
|
|
|
$where, |
587
|
|
|
$where_parameters, |
588
|
|
|
), |
589
|
|
|
), |
590
|
|
|
'columns' => array( |
591
|
|
|
'member' => array( |
592
|
|
|
'header' => array( |
593
|
|
|
'value' => $txt['mc_groupr_member'], |
594
|
|
|
), |
595
|
|
|
'data' => array( |
596
|
|
|
'db' => 'member_link', |
597
|
|
|
), |
598
|
|
|
'sort' => array( |
599
|
|
|
'default' => 'mem.member_name', |
600
|
|
|
'reverse' => 'mem.member_name DESC', |
601
|
|
|
), |
602
|
|
|
), |
603
|
|
|
'group' => array( |
604
|
|
|
'header' => array( |
605
|
|
|
'value' => $txt['mc_groupr_group'], |
606
|
|
|
), |
607
|
|
|
'data' => array( |
608
|
|
|
'db' => 'group_link', |
609
|
|
|
), |
610
|
|
|
'sort' => array( |
611
|
|
|
'default' => 'mg.group_name', |
612
|
|
|
'reverse' => 'mg.group_name DESC', |
613
|
|
|
), |
614
|
|
|
), |
615
|
|
|
'reason' => array( |
616
|
|
|
'header' => array( |
617
|
|
|
'value' => $txt['mc_groupr_reason'], |
618
|
|
|
), |
619
|
|
|
'data' => array( |
620
|
|
|
'db' => 'reason', |
621
|
|
|
), |
622
|
|
|
), |
623
|
|
|
'date' => array( |
624
|
|
|
'header' => array( |
625
|
|
|
'value' => $txt['date'], |
626
|
|
|
'style' => 'width: 18%; white-space:nowrap;', |
627
|
|
|
), |
628
|
|
|
'data' => array( |
629
|
|
|
'db' => 'time_submitted', |
630
|
|
|
), |
631
|
|
|
), |
632
|
|
|
'action' => array( |
633
|
|
|
'header' => array( |
634
|
|
|
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);">', |
635
|
|
|
'style' => 'width: 4%;', |
636
|
|
|
'class' => 'centercol', |
637
|
|
|
), |
638
|
|
|
'data' => array( |
639
|
|
|
'sprintf' => array( |
640
|
|
|
'format' => '<input type="checkbox" name="groupr[]" value="%1$d">', |
641
|
|
|
'params' => array( |
642
|
|
|
'id' => false, |
643
|
|
|
), |
644
|
|
|
), |
645
|
|
|
'class' => 'centercol', |
646
|
|
|
), |
647
|
|
|
), |
648
|
|
|
), |
649
|
|
|
'form' => array( |
650
|
|
|
'href' => $scripturl . '?action=groups;sa=requests', |
651
|
|
|
'include_sort' => true, |
652
|
|
|
'include_start' => true, |
653
|
|
|
'hidden_fields' => array( |
654
|
|
|
$context['session_var'] => $context['session_id'], |
655
|
|
|
), |
656
|
|
|
'token' => 'mod-gr', |
657
|
|
|
), |
658
|
|
|
'additional_rows' => array( |
659
|
|
|
array( |
660
|
|
|
'position' => 'bottom_of_list', |
661
|
|
|
'value' => ' |
662
|
|
|
<select id="req_action" name="req_action" onchange="if (this.value != 0 && (this.value == \'reason\' || confirm(\'' . $txt['mc_groupr_warning'] . '\'))) this.form.submit();"> |
663
|
|
|
<option value="0">' . $txt['with_selected'] . ':</option> |
664
|
|
|
<option value="0" disabled>---------------------</option> |
665
|
|
|
<option value="approve">' . $txt['mc_groupr_approve'] . '</option> |
666
|
|
|
<option value="reject">' . $txt['mc_groupr_reject'] . '</option> |
667
|
|
|
<option value="reason">' . $txt['mc_groupr_reject_w_reason'] . '</option> |
668
|
|
|
</select> |
669
|
|
|
<input type="submit" name="go" value="' . $txt['go'] . '" onclick="var sel = document.getElementById(\'req_action\'); if (sel.value != 0 && sel.value != \'reason\' && !confirm(\'' . $txt['mc_groupr_warning'] . '\')) return false;" class="button">', |
670
|
|
|
'class' => 'floatright', |
671
|
|
|
), |
672
|
|
|
), |
673
|
|
|
); |
674
|
|
|
|
675
|
|
|
if (isset($_GET['closed'])) |
676
|
|
|
{ |
677
|
|
|
// Closed requests don't require interaction. |
678
|
|
|
unset($listOptions['columns']['action'], $listOptions['form'], $listOptions['additional_rows'][0]); |
679
|
|
|
$listOptions['base_href'] .= 'closed'; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
// Create the request list. |
683
|
|
|
createToken('mod-gr'); |
684
|
|
|
createList($listOptions); |
685
|
|
|
|
686
|
|
|
$context['default_list'] = 'group_request_list'; |
687
|
|
|
$context[$context['moderation_menu_name']]['tab_data'] = array( |
688
|
|
|
'title' => $txt['mc_group_requests'], |
689
|
|
|
); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* Callback function for createList(). |
694
|
|
|
* |
695
|
|
|
* @param string $where The WHERE clause for the query |
696
|
|
|
* @param array $where_parameters The parameters for the WHERE clause |
697
|
|
|
* @return int The number of group requests |
698
|
|
|
*/ |
699
|
|
|
function list_getGroupRequestCount($where, $where_parameters) |
700
|
|
|
{ |
701
|
|
|
global $smcFunc; |
702
|
|
|
|
703
|
|
|
$request = $smcFunc['db_query']('', ' |
704
|
|
|
SELECT COUNT(*) |
705
|
|
|
FROM {db_prefix}log_group_requests AS lgr |
706
|
|
|
WHERE ' . $where, |
707
|
|
|
array_merge($where_parameters, array( |
708
|
|
|
)) |
709
|
|
|
); |
710
|
|
|
list ($totalRequests) = $smcFunc['db_fetch_row']($request); |
711
|
|
|
$smcFunc['db_free_result']($request); |
712
|
|
|
|
713
|
|
|
return $totalRequests; |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
/** |
717
|
|
|
* Callback function for createList() |
718
|
|
|
* |
719
|
|
|
* @param int $start The result to start with |
720
|
|
|
* @param int $items_per_page The number of items per page |
721
|
|
|
* @param string $sort An SQL sort expression (column/direction) |
722
|
|
|
* @param string $where Data for the WHERE clause |
723
|
|
|
* @param string $where_parameters Parameter values to be inserted into the WHERE clause |
724
|
|
|
* @return array An array of group requests |
725
|
|
|
* Each group request has: |
726
|
|
|
* 'id' |
727
|
|
|
* 'member_link' |
728
|
|
|
* 'group_link' |
729
|
|
|
* 'reason' |
730
|
|
|
* 'time_submitted' |
731
|
|
|
*/ |
732
|
|
|
function list_getGroupRequests($start, $items_per_page, $sort, $where, $where_parameters) |
733
|
|
|
{ |
734
|
|
|
global $smcFunc, $scripturl, $txt; |
735
|
|
|
|
736
|
|
|
$request = $smcFunc['db_query']('', ' |
737
|
|
|
SELECT |
738
|
|
|
lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, lgr.reason, |
739
|
|
|
lgr.status, lgr.id_member_acted, lgr.member_name_acted, lgr.time_acted, lgr.act_reason, |
740
|
|
|
mem.member_name, mg.group_name, mg.online_color, mem.real_name |
741
|
|
|
FROM {db_prefix}log_group_requests AS lgr |
742
|
|
|
INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) |
743
|
|
|
INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) |
744
|
|
|
WHERE ' . $where . ' |
745
|
|
|
ORDER BY {raw:sort} |
746
|
|
|
LIMIT {int:start}, {int:max}', |
747
|
|
|
array_merge($where_parameters, array( |
|
|
|
|
748
|
|
|
'sort' => $sort, |
749
|
|
|
'start' => $start, |
750
|
|
|
'max' => $items_per_page, |
751
|
|
|
)) |
752
|
|
|
); |
753
|
|
|
$group_requests = array(); |
754
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
755
|
|
|
{ |
756
|
|
|
if (empty($row['reason'])) |
757
|
|
|
$reason = '<em>(' . $txt['mc_groupr_no_reason'] . ')</em>'; |
758
|
|
|
else |
759
|
|
|
$reason = censorText($row['reason']); |
760
|
|
|
|
761
|
|
|
if (isset($_GET['closed'])) |
762
|
|
|
{ |
763
|
|
|
if ($row['status'] == 1) |
764
|
|
|
$reason .= '<br><br><strong>' . $txt['mc_groupr_approved'] . '</strong>'; |
765
|
|
|
elseif ($row['status'] == 2) |
766
|
|
|
$reason .= '<br><br><strong>' . $txt['mc_groupr_rejected'] . '</strong>'; |
767
|
|
|
|
768
|
|
|
$reason .= ' (' . timeformat($row['time_acted']) . ')'; |
769
|
|
|
if (!empty($row['act_reason'])) |
770
|
|
|
$reason .= '<br><br>' . censorText($row['act_reason']); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
$group_requests[] = array( |
774
|
|
|
'id' => $row['id_request'], |
775
|
|
|
'member_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', |
776
|
|
|
'group_link' => '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>', |
777
|
|
|
'reason' => $reason, |
778
|
|
|
'time_submitted' => timeformat($row['time_applied']), |
779
|
|
|
); |
780
|
|
|
} |
781
|
|
|
$smcFunc['db_free_result']($request); |
782
|
|
|
|
783
|
|
|
return $group_requests; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
?> |