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