Mercurial > hg > vamp-website
comparison forum/Sources/Groups.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* This file currently just shows group info, and allows certain privaledged members to add/remove members. | |
18 | |
19 void Groups() | |
20 - allows moderators and users to access the group showing functions. | |
21 - handles permission checks, and puts the moderation bar on as required. | |
22 | |
23 void MembergroupMembers() | |
24 - can be called from ManageMembergroups if it needs templating within the admin environment. | |
25 - show a list of members that are part of a given membergroup. | |
26 - called by ?action=moderate;area=viewgroups;sa=members;group=x | |
27 - requires the manage_membergroups permission. | |
28 - uses the group_members sub template of ManageMembergroups. | |
29 - allows to add and remove members from the selected membergroup. | |
30 - allows sorting on several columns. | |
31 - redirects to itself. | |
32 | |
33 int list_getGroupRequestCount(string where) | |
34 - callback function for createList() | |
35 - returns the count of group requests | |
36 | |
37 array list_getGroupRequests(int start, int items_per_page, string sort, string where) | |
38 - callback function for createList() | |
39 - returns an array of group requests | |
40 - each group request has: | |
41 'id' | |
42 'member_link' | |
43 'group_link' | |
44 'reason' | |
45 'time_submitted' | |
46 | |
47 */ | |
48 | |
49 // Entry point, permission checks, admin bars, etc. | |
50 function Groups() | |
51 { | |
52 global $context, $txt, $scripturl, $sourcedir, $user_info; | |
53 | |
54 // The sub-actions that we can do. Format "Function Name, Mod Bar Index if appropriate". | |
55 $subActions = array( | |
56 'index' => array('GroupList', 'view_groups'), | |
57 'members' => array('MembergroupMembers', 'view_groups'), | |
58 'requests' => array('GroupRequests', 'group_requests'), | |
59 ); | |
60 | |
61 // Default to sub action 'index' or 'settings' depending on permissions. | |
62 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : 'index'; | |
63 | |
64 // Get the template stuff up and running. | |
65 loadLanguage('ManageMembers'); | |
66 loadLanguage('ModerationCenter'); | |
67 loadTemplate('ManageMembergroups'); | |
68 | |
69 // If we can see the moderation center, and this has a mod bar entry, add the mod center bar. | |
70 if (allowedTo('access_mod_center') || $user_info['mod_cache']['bq'] != '0=1' || $user_info['mod_cache']['gq'] != '0=1' || allowedTo('manage_membergroups')) | |
71 { | |
72 require_once($sourcedir . '/ModerationCenter.php'); | |
73 $_GET['area'] = $_REQUEST['sa'] == 'requests' ? 'groups' : 'viewgroups'; | |
74 ModerationMain(true); | |
75 } | |
76 // Otherwise add something to the link tree, for normal people. | |
77 else | |
78 { | |
79 isAllowedTo('view_mlist'); | |
80 | |
81 $context['linktree'][] = array( | |
82 'url' => $scripturl . '?action=groups', | |
83 'name' => $txt['groups'], | |
84 ); | |
85 } | |
86 | |
87 // Call the actual function. | |
88 $subActions[$_REQUEST['sa']][0](); | |
89 } | |
90 | |
91 // This very simply lists the groups, nothing snazy. | |
92 function GroupList() | |
93 { | |
94 global $txt, $scripturl, $user_profile, $user_info, $context, $settings, $modSettings, $smcFunc, $sourcedir; | |
95 | |
96 // Yep, find the groups... | |
97 $request = $smcFunc['db_query']('', ' | |
98 SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden, | |
99 mg.stars, IFNULL(gm.id_member, 0) AS can_moderate | |
100 FROM {db_prefix}membergroups AS mg | |
101 LEFT JOIN {db_prefix}group_moderators AS gm ON (gm.id_group = mg.id_group AND gm.id_member = {int:current_member}) | |
102 WHERE mg.min_posts = {int:min_posts} | |
103 AND mg.id_group != {int:mod_group}' . (allowedTo('admin_forum') ? '' : ' | |
104 AND mg.group_type != {int:is_protected}') . ' | |
105 ORDER BY group_name', | |
106 array( | |
107 'current_member' => $user_info['id'], | |
108 'min_posts' => -1, | |
109 'mod_group' => 3, | |
110 'is_protected' => 1, | |
111 ) | |
112 ); | |
113 // This is where we store our groups. | |
114 $context['groups'] = array(); | |
115 $group_ids = array(); | |
116 $context['can_moderate'] = allowedTo('manage_membergroups'); | |
117 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
118 { | |
119 // We only list the groups they can see. | |
120 if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) | |
121 continue; | |
122 | |
123 $row['stars'] = explode('#', $row['stars']); | |
124 | |
125 $context['groups'][$row['id_group']] = array( | |
126 'id' => $row['id_group'], | |
127 'name' => $row['group_name'], | |
128 'desc' => $row['description'], | |
129 'color' => $row['online_color'], | |
130 'type' => $row['group_type'], | |
131 'num_members' => 0, | |
132 'stars' => !empty($row['stars'][0]) && !empty($row['stars'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/' . $row['stars'][1] . '" alt="*" />', $row['stars'][0]) : '', | |
133 ); | |
134 | |
135 $context['can_moderate'] |= $row['can_moderate']; | |
136 $group_ids[] = $row['id_group']; | |
137 } | |
138 $smcFunc['db_free_result']($request); | |
139 | |
140 // Count up the members separately... | |
141 if (!empty($group_ids)) | |
142 { | |
143 $query = $smcFunc['db_query']('', ' | |
144 SELECT id_group, COUNT(*) AS num_members | |
145 FROM {db_prefix}members | |
146 WHERE id_group IN ({array_int:group_list}) | |
147 GROUP BY id_group', | |
148 array( | |
149 'group_list' => $group_ids, | |
150 ) | |
151 ); | |
152 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
153 $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; | |
154 $smcFunc['db_free_result']($query); | |
155 | |
156 // Only do additional groups if we can moderate... | |
157 if ($context['can_moderate']) | |
158 { | |
159 $query = $smcFunc['db_query']('', ' | |
160 SELECT mg.id_group, COUNT(*) AS num_members | |
161 FROM {db_prefix}membergroups AS mg | |
162 INNER JOIN {db_prefix}members AS mem ON (mem.additional_groups != {string:blank_screen} | |
163 AND mem.id_group != mg.id_group | |
164 AND FIND_IN_SET(mg.id_group, mem.additional_groups) != 0) | |
165 WHERE mg.id_group IN ({array_int:group_list}) | |
166 GROUP BY mg.id_group', | |
167 array( | |
168 'group_list' => $group_ids, | |
169 'blank_screen' => '', | |
170 ) | |
171 ); | |
172 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
173 $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; | |
174 $smcFunc['db_free_result']($query); | |
175 } | |
176 } | |
177 | |
178 $context['sub_template'] = 'group_index'; | |
179 $context['page_title'] = $txt['viewing_groups']; | |
180 | |
181 // Making a list is not hard with this beauty. | |
182 require_once($sourcedir . '/Subs-List.php'); | |
183 | |
184 // Use the standard templates for showing this. | |
185 $listOptions = array( | |
186 'id' => 'group_lists', | |
187 'title' => $context['page_title'], | |
188 'get_items' => array( | |
189 'function' => 'list_getGroups', | |
190 ), | |
191 'columns' => array( | |
192 'group' => array( | |
193 'header' => array( | |
194 'value' => $txt['name'], | |
195 ), | |
196 'data' => array( | |
197 'function' => create_function('$group', ' | |
198 global $scripturl, $context; | |
199 | |
200 $output = \'<a href="\' . $scripturl . \'?action=\' . $context[\'current_action\'] . (isset($context[\'admin_area\']) ? \';area=\' . $context[\'admin_area\'] : \'\') . \';sa=members;group=\' . $group[\'id\'] . \'" \' . ($group[\'color\'] ? \'style="color: \' . $group[\'color\'] . \';"\' : \'\') . \'>\' . $group[\'name\'] . \'</a>\'; | |
201 | |
202 if ($group[\'desc\']) | |
203 $output .= \'<div class="smalltext">\' . $group[\'desc\'] . \'</div>\'; | |
204 | |
205 return $output; | |
206 '), | |
207 'style' => 'width: 50%;', | |
208 ), | |
209 ), | |
210 'stars' => array( | |
211 'header' => array( | |
212 'value' => $txt['membergroups_stars'], | |
213 ), | |
214 'data' => array( | |
215 'db' => 'stars', | |
216 ), | |
217 ), | |
218 'moderators' => array( | |
219 'header' => array( | |
220 'value' => $txt['moderators'], | |
221 ), | |
222 'data' => array( | |
223 'function' => create_function('$group', ' | |
224 global $txt; | |
225 | |
226 return empty($group[\'moderators\']) ? \'<em>\' . $txt[\'membergroups_new_copy_none\'] . \'</em>\' : implode(\', \', $group[\'moderators\']); | |
227 '), | |
228 ), | |
229 ), | |
230 'members' => array( | |
231 'header' => array( | |
232 'value' => $txt['membergroups_members_top'], | |
233 ), | |
234 'data' => array( | |
235 'comma_format' => true, | |
236 'db' => 'num_members', | |
237 ), | |
238 ), | |
239 ), | |
240 ); | |
241 | |
242 // Create the request list. | |
243 createList($listOptions); | |
244 | |
245 $context['sub_template'] = 'show_list'; | |
246 $context['default_list'] = 'group_lists'; | |
247 } | |
248 | |
249 // Get the group information for the list. | |
250 function list_getGroups($start, $items_per_page, $sort) | |
251 { | |
252 global $smcFunc, $txt, $scripturl, $user_info, $settings; | |
253 | |
254 // Yep, find the groups... | |
255 $request = $smcFunc['db_query']('', ' | |
256 SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden, | |
257 mg.stars, IFNULL(gm.id_member, 0) AS can_moderate | |
258 FROM {db_prefix}membergroups AS mg | |
259 LEFT JOIN {db_prefix}group_moderators AS gm ON (gm.id_group = mg.id_group AND gm.id_member = {int:current_member}) | |
260 WHERE mg.min_posts = {int:min_posts} | |
261 AND mg.id_group != {int:mod_group}' . (allowedTo('admin_forum') ? '' : ' | |
262 AND mg.group_type != {int:is_protected}') . ' | |
263 ORDER BY group_name', | |
264 array( | |
265 'current_member' => $user_info['id'], | |
266 'min_posts' => -1, | |
267 'mod_group' => 3, | |
268 'is_protected' => 1, | |
269 ) | |
270 ); | |
271 // Start collecting the data. | |
272 $groups = array(); | |
273 $group_ids = array(); | |
274 $context['can_moderate'] = allowedTo('manage_membergroups'); | |
275 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
276 { | |
277 // We only list the groups they can see. | |
278 if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) | |
279 continue; | |
280 | |
281 $row['stars'] = explode('#', $row['stars']); | |
282 | |
283 $groups[$row['id_group']] = array( | |
284 'id' => $row['id_group'], | |
285 'name' => $row['group_name'], | |
286 'desc' => $row['description'], | |
287 'color' => $row['online_color'], | |
288 'type' => $row['group_type'], | |
289 'num_members' => 0, | |
290 'moderators' => array(), | |
291 'stars' => !empty($row['stars'][0]) && !empty($row['stars'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/' . $row['stars'][1] . '" alt="*" />', $row['stars'][0]) : '', | |
292 ); | |
293 | |
294 $context['can_moderate'] |= $row['can_moderate']; | |
295 $group_ids[] = $row['id_group']; | |
296 } | |
297 $smcFunc['db_free_result']($request); | |
298 | |
299 // Count up the members separately... | |
300 if (!empty($group_ids)) | |
301 { | |
302 $query = $smcFunc['db_query']('', ' | |
303 SELECT id_group, COUNT(*) AS num_members | |
304 FROM {db_prefix}members | |
305 WHERE id_group IN ({array_int:group_list}) | |
306 GROUP BY id_group', | |
307 array( | |
308 'group_list' => $group_ids, | |
309 ) | |
310 ); | |
311 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
312 $groups[$row['id_group']]['num_members'] += $row['num_members']; | |
313 $smcFunc['db_free_result']($query); | |
314 | |
315 // Only do additional groups if we can moderate... | |
316 if ($context['can_moderate']) | |
317 { | |
318 $query = $smcFunc['db_query']('', ' | |
319 SELECT mg.id_group, COUNT(*) AS num_members | |
320 FROM {db_prefix}membergroups AS mg | |
321 INNER JOIN {db_prefix}members AS mem ON (mem.additional_groups != {string:blank_screen} | |
322 AND mem.id_group != mg.id_group | |
323 AND FIND_IN_SET(mg.id_group, mem.additional_groups) != 0) | |
324 WHERE mg.id_group IN ({array_int:group_list}) | |
325 GROUP BY mg.id_group', | |
326 array( | |
327 'group_list' => $group_ids, | |
328 'blank_screen' => '', | |
329 ) | |
330 ); | |
331 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
332 $groups[$row['id_group']]['num_members'] += $row['num_members']; | |
333 $smcFunc['db_free_result']($query); | |
334 } | |
335 } | |
336 | |
337 // Get any group moderators. | |
338 // Count up the members separately... | |
339 if (!empty($group_ids)) | |
340 { | |
341 $query = $smcFunc['db_query']('', ' | |
342 SELECT mods.id_group, mods.id_member, mem.member_name, mem.real_name | |
343 FROM {db_prefix}group_moderators AS mods | |
344 INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member) | |
345 WHERE mods.id_group IN ({array_int:group_list})', | |
346 array( | |
347 'group_list' => $group_ids, | |
348 ) | |
349 ); | |
350 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
351 $groups[$row['id_group']]['moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>'; | |
352 $smcFunc['db_free_result']($query); | |
353 } | |
354 | |
355 return $groups; | |
356 } | |
357 | |
358 // How many groups are there that are visible? | |
359 function list_getGroupCount() | |
360 { | |
361 global $smcFunc; | |
362 | |
363 $request = $smcFunc['db_query']('', ' | |
364 SELECT COUNT(id_group) AS group_count | |
365 FROM {db_prefix}membergroups | |
366 WHERE mg.min_posts = {int:min_posts} | |
367 AND mg.id_group != {int:mod_group}' . (allowedTo('admin_forum') ? '' : ' | |
368 AND mg.group_type != {int:is_protected}'), | |
369 array( | |
370 'min_posts' => -1, | |
371 'mod_group' => 3, | |
372 'is_protected' => 1, | |
373 ) | |
374 ); | |
375 list ($group_count) = $smcFunc['db_fetch_row']($request); | |
376 $smcFunc['db_free_result']($request); | |
377 | |
378 return $group_count; | |
379 } | |
380 | |
381 // Display members of a group, and allow adding of members to a group. Silly function name though ;) | |
382 function MembergroupMembers() | |
383 { | |
384 global $txt, $scripturl, $context, $modSettings, $sourcedir, $user_info, $settings, $smcFunc; | |
385 | |
386 $_REQUEST['group'] = isset($_REQUEST['group']) ? (int) $_REQUEST['group'] : 0; | |
387 | |
388 // No browsing of guests, membergroup 0 or moderators. | |
389 if (in_array($_REQUEST['group'], array(-1, 0, 3))) | |
390 fatal_lang_error('membergroup_does_not_exist', false); | |
391 | |
392 // Load up the group details. | |
393 $request = $smcFunc['db_query']('', ' | |
394 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, | |
395 stars, description, CASE WHEN min_posts != {int:min_posts} THEN 1 ELSE 0 END AS is_post_group, group_type | |
396 FROM {db_prefix}membergroups | |
397 WHERE id_group = {int:id_group} | |
398 LIMIT 1', | |
399 array( | |
400 'min_posts' => -1, | |
401 'id_group' => $_REQUEST['group'], | |
402 ) | |
403 ); | |
404 // Doesn't exist? | |
405 if ($smcFunc['db_num_rows']($request) == 0) | |
406 fatal_lang_error('membergroup_does_not_exist', false); | |
407 $context['group'] = $smcFunc['db_fetch_assoc']($request); | |
408 $smcFunc['db_free_result']($request); | |
409 | |
410 // Fix the stars. | |
411 $context['group']['stars'] = explode('#', $context['group']['stars']); | |
412 $context['group']['stars'] = !empty($context['group']['stars'][0]) && !empty($context['group']['stars'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/' . $context['group']['stars'][1] . '" alt="*" />', $context['group']['stars'][0]) : ''; | |
413 $context['group']['can_moderate'] = allowedTo('manage_membergroups') && (allowedTo('admin_forum') || $context['group']['group_type'] != 1); | |
414 | |
415 $context['linktree'][] = array( | |
416 'url' => $scripturl . '?action=groups;sa=members;group=' . $context['group']['id'], | |
417 'name' => $context['group']['name'], | |
418 ); | |
419 | |
420 // Load all the group moderators, for fun. | |
421 $request = $smcFunc['db_query']('', ' | |
422 SELECT mem.id_member, mem.real_name | |
423 FROM {db_prefix}group_moderators AS mods | |
424 INNER JOIN {db_prefix}members AS mem ON (mem.id_member = mods.id_member) | |
425 WHERE mods.id_group = {int:id_group}', | |
426 array( | |
427 'id_group' => $_REQUEST['group'], | |
428 ) | |
429 ); | |
430 $context['group']['moderators'] = array(); | |
431 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
432 { | |
433 $context['group']['moderators'][] = array( | |
434 'id' => $row['id_member'], | |
435 'name' => $row['real_name'] | |
436 ); | |
437 | |
438 if ($user_info['id'] == $row['id_member'] && $context['group']['group_type'] != 1) | |
439 $context['group']['can_moderate'] = true; | |
440 } | |
441 $smcFunc['db_free_result']($request); | |
442 | |
443 // If this group is hidden then it can only "exists" if the user can moderate it! | |
444 if ($context['group']['hidden'] && !$context['group']['can_moderate']) | |
445 fatal_lang_error('membergroup_does_not_exist', false); | |
446 | |
447 // You can only assign membership if you are the moderator and/or can manage groups! | |
448 if (!$context['group']['can_moderate']) | |
449 $context['group']['assignable'] = 0; | |
450 // Non-admins cannot assign admins. | |
451 elseif ($context['group']['id'] == 1 && !allowedTo('admin_forum')) | |
452 $context['group']['assignable'] = 0; | |
453 | |
454 // Removing member from group? | |
455 if (isset($_POST['remove']) && !empty($_REQUEST['rem']) && is_array($_REQUEST['rem']) && $context['group']['assignable']) | |
456 { | |
457 checkSession(); | |
458 | |
459 // Make sure we're dealing with integers only. | |
460 foreach ($_REQUEST['rem'] as $key => $group) | |
461 $_REQUEST['rem'][$key] = (int) $group; | |
462 | |
463 require_once($sourcedir . '/Subs-Membergroups.php'); | |
464 removeMembersFromGroups($_REQUEST['rem'], $_REQUEST['group'], true); | |
465 } | |
466 // Must be adding new members to the group... | |
467 elseif (isset($_REQUEST['add']) && (!empty($_REQUEST['toAdd']) || !empty($_REQUEST['member_add'])) && $context['group']['assignable']) | |
468 { | |
469 checkSession(); | |
470 | |
471 $member_query = array(); | |
472 $member_parameters = array(); | |
473 | |
474 // Get all the members to be added... taking into account names can be quoted ;) | |
475 $_REQUEST['toAdd'] = strtr($smcFunc['htmlspecialchars']($_REQUEST['toAdd'], ENT_QUOTES), array('"' => '"')); | |
476 preg_match_all('~"([^"]+)"~', $_REQUEST['toAdd'], $matches); | |
477 $member_names = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_REQUEST['toAdd'])))); | |
478 | |
479 foreach ($member_names as $index => $member_name) | |
480 { | |
481 $member_names[$index] = trim($smcFunc['strtolower']($member_names[$index])); | |
482 | |
483 if (strlen($member_names[$index]) == 0) | |
484 unset($member_names[$index]); | |
485 } | |
486 | |
487 // Any passed by ID? | |
488 $member_ids = array(); | |
489 if (!empty($_REQUEST['member_add'])) | |
490 foreach ($_REQUEST['member_add'] as $id) | |
491 if ($id > 0) | |
492 $member_ids[] = (int) $id; | |
493 | |
494 // Construct the query pelements. | |
495 if (!empty($member_ids)) | |
496 { | |
497 $member_query[] = 'id_member IN ({array_int:member_ids})'; | |
498 $member_parameters['member_ids'] = $member_ids; | |
499 } | |
500 if (!empty($member_names)) | |
501 { | |
502 $member_query[] = 'LOWER(member_name) IN ({array_string:member_names})'; | |
503 $member_query[] = 'LOWER(real_name) IN ({array_string:member_names})'; | |
504 $member_parameters['member_names'] = $member_names; | |
505 } | |
506 | |
507 $members = array(); | |
508 if (!empty($member_query)) | |
509 { | |
510 $request = $smcFunc['db_query']('', ' | |
511 SELECT id_member | |
512 FROM {db_prefix}members | |
513 WHERE (' . implode(' OR ', $member_query) . ') | |
514 AND id_group != {int:id_group} | |
515 AND FIND_IN_SET({int:id_group}, additional_groups) = 0', | |
516 array_merge($member_parameters, array( | |
517 'id_group' => $_REQUEST['group'], | |
518 )) | |
519 ); | |
520 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
521 $members[] = $row['id_member']; | |
522 $smcFunc['db_free_result']($request); | |
523 } | |
524 | |
525 // !!! Add $_POST['additional'] to templates! | |
526 | |
527 // Do the updates... | |
528 if (!empty($members)) | |
529 { | |
530 require_once($sourcedir . '/Subs-Membergroups.php'); | |
531 addMembersToGroup($members, $_REQUEST['group'], isset($_POST['additional']) || $context['group']['hidden'] ? 'only_additional' : 'auto', true); | |
532 } | |
533 } | |
534 | |
535 // Sort out the sorting! | |
536 $sort_methods = array( | |
537 'name' => 'real_name', | |
538 'email' => allowedTo('moderate_forum') ? 'email_address' : 'hide_email ' . (isset($_REQUEST['desc']) ? 'DESC' : 'ASC') . ', email_address', | |
539 'active' => 'last_login', | |
540 'registered' => 'date_registered', | |
541 'posts' => 'posts', | |
542 ); | |
543 | |
544 // They didn't pick one, default to by name.. | |
545 if (!isset($_REQUEST['sort']) || !isset($sort_methods[$_REQUEST['sort']])) | |
546 { | |
547 $context['sort_by'] = 'name'; | |
548 $querySort = 'real_name'; | |
549 } | |
550 // Otherwise default to ascending. | |
551 else | |
552 { | |
553 $context['sort_by'] = $_REQUEST['sort']; | |
554 $querySort = $sort_methods[$_REQUEST['sort']]; | |
555 } | |
556 | |
557 $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; | |
558 | |
559 // The where on the query is interesting. Non-moderators should only see people who are in this group as primary. | |
560 if ($context['group']['can_moderate']) | |
561 $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group} OR FIND_IN_SET({int:group}, additional_groups) != 0'; | |
562 else | |
563 $where = $context['group']['is_post_group'] ? 'id_post_group = {int:group}' : 'id_group = {int:group}'; | |
564 | |
565 // Count members of the group. | |
566 $request = $smcFunc['db_query']('', ' | |
567 SELECT COUNT(*) | |
568 FROM {db_prefix}members | |
569 WHERE ' . $where, | |
570 array( | |
571 'group' => $_REQUEST['group'], | |
572 ) | |
573 ); | |
574 list ($context['total_members']) = $smcFunc['db_fetch_row']($request); | |
575 $smcFunc['db_free_result']($request); | |
576 $context['total_members'] = comma_format($context['total_members']); | |
577 | |
578 // Create the page index. | |
579 $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']); | |
580 $context['start'] = $_REQUEST['start']; | |
581 $context['can_moderate_forum'] = allowedTo('moderate_forum'); | |
582 | |
583 // Load up all members of this group. | |
584 $request = $smcFunc['db_query']('', ' | |
585 SELECT id_member, member_name, real_name, email_address, member_ip, date_registered, last_login, | |
586 hide_email, posts, is_activated, real_name | |
587 FROM {db_prefix}members | |
588 WHERE ' . $where . ' | |
589 ORDER BY ' . $querySort . ' ' . ($context['sort_direction'] == 'down' ? 'DESC' : 'ASC') . ' | |
590 LIMIT ' . $context['start'] . ', ' . $modSettings['defaultMaxMembers'], | |
591 array( | |
592 'group' => $_REQUEST['group'], | |
593 ) | |
594 ); | |
595 $context['members'] = array(); | |
596 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
597 { | |
598 $last_online = empty($row['last_login']) ? $txt['never'] : timeformat($row['last_login']); | |
599 | |
600 // Italicize the online note if they aren't activated. | |
601 if ($row['is_activated'] % 10 != 1) | |
602 $last_online = '<em title="' . $txt['not_activated'] . '">' . $last_online . '</em>'; | |
603 | |
604 $context['members'][] = array( | |
605 'id' => $row['id_member'], | |
606 'name' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', | |
607 'email' => $row['email_address'], | |
608 'show_email' => showEmailAddress(!empty($row['hide_email']), $row['id_member']), | |
609 'ip' => '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['member_ip'] . '">' . $row['member_ip'] . '</a>', | |
610 'registered' => timeformat($row['date_registered']), | |
611 'last_online' => $last_online, | |
612 'posts' => comma_format($row['posts']), | |
613 'is_activated' => $row['is_activated'] % 10 == 1, | |
614 ); | |
615 } | |
616 $smcFunc['db_free_result']($request); | |
617 | |
618 // Select the template. | |
619 $context['sub_template'] = 'group_members'; | |
620 $context['page_title'] = $txt['membergroups_members_title'] . ': ' . $context['group']['name']; | |
621 } | |
622 | |
623 // Show and manage all group requests. | |
624 function GroupRequests() | |
625 { | |
626 global $txt, $context, $scripturl, $user_info, $sourcedir, $smcFunc, $modSettings, $language; | |
627 | |
628 // Set up the template stuff... | |
629 $context['page_title'] = $txt['mc_group_requests']; | |
630 $context['sub_template'] = 'show_list'; | |
631 | |
632 // Verify we can be here. | |
633 if ($user_info['mod_cache']['gq'] == '0=1') | |
634 isAllowedTo('manage_membergroups'); | |
635 | |
636 // Normally, we act normally... | |
637 $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']; | |
638 $where_parameters = array(); | |
639 | |
640 // We've submitted? | |
641 if (isset($_POST[$context['session_var']]) && !empty($_POST['groupr']) && !empty($_POST['req_action'])) | |
642 { | |
643 checkSession('post'); | |
644 | |
645 // Clean the values. | |
646 foreach ($_POST['groupr'] as $k => $request) | |
647 $_POST['groupr'][$k] = (int) $request; | |
648 | |
649 // If we are giving a reason (And why shouldn't we?), then we don't actually do much. | |
650 if ($_POST['req_action'] == 'reason') | |
651 { | |
652 // Different sub template... | |
653 $context['sub_template'] = 'group_request_reason'; | |
654 // And a limitation. We don't care that the page number bit makes no sense, as we don't need it! | |
655 $where .= ' AND lgr.id_request IN ({array_int:request_ids})'; | |
656 $where_parameters['request_ids'] = $_POST['groupr']; | |
657 | |
658 $context['group_requests'] = list_getGroupRequests(0, $modSettings['defaultMaxMessages'], 'lgr.id_request', $where, $where_parameters); | |
659 | |
660 // Let obExit etc sort things out. | |
661 obExit(); | |
662 } | |
663 // Otherwise we do something! | |
664 else | |
665 { | |
666 // Get the details of all the members concerned... | |
667 $request = $smcFunc['db_query']('', ' | |
668 SELECT lgr.id_request, lgr.id_member, lgr.id_group, mem.email_address, mem.id_group AS primary_group, | |
669 mem.additional_groups AS additional_groups, mem.lngfile, mem.member_name, mem.notify_types, | |
670 mg.hidden, mg.group_name | |
671 FROM {db_prefix}log_group_requests AS lgr | |
672 INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) | |
673 INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) | |
674 WHERE ' . $where . ' | |
675 AND lgr.id_request IN ({array_int:request_list}) | |
676 ORDER BY mem.lngfile', | |
677 array( | |
678 'request_list' => $_POST['groupr'], | |
679 ) | |
680 ); | |
681 $email_details = array(); | |
682 $group_changes = array(); | |
683 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
684 { | |
685 $row['lngfile'] = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; | |
686 | |
687 // If we are approving work out what their new group is. | |
688 if ($_POST['req_action'] == 'approve') | |
689 { | |
690 // For people with more than one request at once. | |
691 if (isset($group_changes[$row['id_member']])) | |
692 { | |
693 $row['additional_groups'] = $group_changes[$row['id_member']]['add']; | |
694 $row['primary_group'] = $group_changes[$row['id_member']]['primary']; | |
695 } | |
696 else | |
697 $row['additional_groups'] = explode(',', $row['additional_groups']); | |
698 | |
699 // Don't have it already? | |
700 if ($row['primary_group'] == $row['id_group'] || in_array($row['id_group'], $row['additional_groups'])) | |
701 continue; | |
702 | |
703 // Should it become their primary? | |
704 if ($row['primary_group'] == 0 && $row['hidden'] == 0) | |
705 $row['primary_group'] = $row['id_group']; | |
706 else | |
707 $row['additional_groups'][] = $row['id_group']; | |
708 | |
709 // Add them to the group master list. | |
710 $group_changes[$row['id_member']] = array( | |
711 'primary' => $row['primary_group'], | |
712 'add' => $row['additional_groups'], | |
713 ); | |
714 } | |
715 | |
716 // Add required information to email them. | |
717 if ($row['notify_types'] != 4) | |
718 $email_details[] = array( | |
719 'rid' => $row['id_request'], | |
720 'member_id' => $row['id_member'], | |
721 'member_name' => $row['member_name'], | |
722 'group_id' => $row['id_group'], | |
723 'group_name' => $row['group_name'], | |
724 'email' => $row['email_address'], | |
725 'language' => $row['lngfile'], | |
726 ); | |
727 } | |
728 $smcFunc['db_free_result']($request); | |
729 | |
730 // Remove the evidence... | |
731 $smcFunc['db_query']('', ' | |
732 DELETE FROM {db_prefix}log_group_requests | |
733 WHERE id_request IN ({array_int:request_list})', | |
734 array( | |
735 'request_list' => $_POST['groupr'], | |
736 ) | |
737 ); | |
738 | |
739 // Ensure everyone who is online gets their changes right away. | |
740 updateSettings(array('settings_updated' => time())); | |
741 | |
742 if (!empty($email_details)) | |
743 { | |
744 require_once($sourcedir . '/Subs-Post.php'); | |
745 | |
746 // They are being approved? | |
747 if ($_POST['req_action'] == 'approve') | |
748 { | |
749 // Make the group changes. | |
750 foreach ($group_changes as $id => $groups) | |
751 { | |
752 // Sanity check! | |
753 foreach ($groups['add'] as $key => $value) | |
754 if ($value == 0 || trim($value) == '') | |
755 unset($groups['add'][$key]); | |
756 | |
757 $smcFunc['db_query']('', ' | |
758 UPDATE {db_prefix}members | |
759 SET id_group = {int:primary_group}, additional_groups = {string:additional_groups} | |
760 WHERE id_member = {int:selected_member}', | |
761 array( | |
762 'primary_group' => $groups['primary'], | |
763 'selected_member' => $id, | |
764 'additional_groups' => implode(',', $groups['add']), | |
765 ) | |
766 ); | |
767 } | |
768 | |
769 $lastLng = $user_info['language']; | |
770 foreach ($email_details as $email) | |
771 { | |
772 $replacements = array( | |
773 'USERNAME' => $email['member_name'], | |
774 'GROUPNAME' => $email['group_name'], | |
775 ); | |
776 | |
777 $emaildata = loadEmailTemplate('mc_group_approve', $replacements, $email['language']); | |
778 | |
779 sendmail($email['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 2); | |
780 } | |
781 } | |
782 // Otherwise, they are getting rejected (With or without a reason). | |
783 else | |
784 { | |
785 // Same as for approving, kind of. | |
786 $lastLng = $user_info['language']; | |
787 foreach ($email_details as $email) | |
788 { | |
789 $custom_reason = isset($_POST['groupreason']) && isset($_POST['groupreason'][$email['rid']]) ? $_POST['groupreason'][$email['rid']] : ''; | |
790 | |
791 $replacements = array( | |
792 'USERNAME' => $email['member_name'], | |
793 'GROUPNAME' => $email['group_name'], | |
794 ); | |
795 | |
796 if (!empty($custom_reason)) | |
797 $replacements['REASON'] = $custom_reason; | |
798 | |
799 $emaildata = loadEmailTemplate(empty($custom_reason) ? 'mc_group_reject' : 'mc_group_reject_reason', $replacements, $email['language']); | |
800 | |
801 sendmail($email['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 2); | |
802 } | |
803 } | |
804 } | |
805 | |
806 // Restore the current language. | |
807 loadLanguage('ModerationCenter'); | |
808 } | |
809 } | |
810 | |
811 // We're going to want this for making our list. | |
812 require_once($sourcedir . '/Subs-List.php'); | |
813 | |
814 // This is all the information required for a group listing. | |
815 $listOptions = array( | |
816 'id' => 'group_request_list', | |
817 'title' => $txt['mc_group_requests'], | |
818 'width' => '100%', | |
819 'items_per_page' => $modSettings['defaultMaxMessages'], | |
820 'no_items_label' => $txt['mc_groupr_none_found'], | |
821 'base_href' => $scripturl . '?action=groups;sa=requests', | |
822 'default_sort_col' => 'member', | |
823 'get_items' => array( | |
824 'function' => 'list_getGroupRequests', | |
825 'params' => array( | |
826 $where, | |
827 $where_parameters, | |
828 ), | |
829 ), | |
830 'get_count' => array( | |
831 'function' => 'list_getGroupRequestCount', | |
832 'params' => array( | |
833 $where, | |
834 $where_parameters, | |
835 ), | |
836 ), | |
837 'columns' => array( | |
838 'member' => array( | |
839 'header' => array( | |
840 'value' => $txt['mc_groupr_member'], | |
841 ), | |
842 'data' => array( | |
843 'db' => 'member_link', | |
844 ), | |
845 'sort' => array( | |
846 'default' => 'mem.member_name', | |
847 'reverse' => 'mem.member_name DESC', | |
848 ), | |
849 ), | |
850 'group' => array( | |
851 'header' => array( | |
852 'value' => $txt['mc_groupr_group'], | |
853 ), | |
854 'data' => array( | |
855 'db' => 'group_link', | |
856 ), | |
857 'sort' => array( | |
858 'default' => 'mg.group_name', | |
859 'reverse' => 'mg.group_name DESC', | |
860 ), | |
861 ), | |
862 'reason' => array( | |
863 'header' => array( | |
864 'value' => $txt['mc_groupr_reason'], | |
865 ), | |
866 'data' => array( | |
867 'db' => 'reason', | |
868 ), | |
869 ), | |
870 'action' => array( | |
871 'header' => array( | |
872 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />', | |
873 'style' => 'width: 4%;', | |
874 ), | |
875 'data' => array( | |
876 'sprintf' => array( | |
877 'format' => '<input type="checkbox" name="groupr[]" value="%1$d" class="input_check" />', | |
878 'params' => array( | |
879 'id' => false, | |
880 ), | |
881 ), | |
882 'style' => 'text-align: center;', | |
883 ), | |
884 ), | |
885 ), | |
886 'form' => array( | |
887 'href' => $scripturl . '?action=groups;sa=requests', | |
888 'include_sort' => true, | |
889 'include_start' => true, | |
890 'hidden_fields' => array( | |
891 $context['session_var'] => $context['session_id'], | |
892 ), | |
893 ), | |
894 'additional_rows' => array( | |
895 array( | |
896 'position' => 'bottom_of_list', | |
897 'value' => ' | |
898 <select name="req_action" onchange="if (this.value != 0 && (this.value == \'reason\' || confirm(\'' . $txt['mc_groupr_warning'] . '\'))) this.form.submit();"> | |
899 <option value="0">' . $txt['with_selected'] . ':</option> | |
900 <option value="0">---------------------</option> | |
901 <option value="approve">' . $txt['mc_groupr_approve'] . '</option> | |
902 <option value="reject">' . $txt['mc_groupr_reject'] . '</option> | |
903 <option value="reason">' . $txt['mc_groupr_reject_w_reason'] . '</option> | |
904 </select> | |
905 <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_submit" />', | |
906 'align' => 'right', | |
907 ), | |
908 ), | |
909 ); | |
910 | |
911 // Create the request list. | |
912 createList($listOptions); | |
913 | |
914 $context['default_list'] = 'group_request_list'; | |
915 } | |
916 | |
917 function list_getGroupRequestCount($where, $where_parameters) | |
918 { | |
919 global $smcFunc; | |
920 | |
921 $request = $smcFunc['db_query']('', ' | |
922 SELECT COUNT(*) | |
923 FROM {db_prefix}log_group_requests AS lgr | |
924 WHERE ' . $where, | |
925 array_merge($where_parameters, array( | |
926 )) | |
927 ); | |
928 list ($totalRequests) = $smcFunc['db_fetch_row']($request); | |
929 $smcFunc['db_free_result']($request); | |
930 | |
931 return $totalRequests; | |
932 } | |
933 | |
934 function list_getGroupRequests($start, $items_per_page, $sort, $where, $where_parameters) | |
935 { | |
936 global $smcFunc, $txt, $scripturl; | |
937 | |
938 $request = $smcFunc['db_query']('', ' | |
939 SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, lgr.reason, | |
940 mem.member_name, mg.group_name, mg.online_color, mem.real_name | |
941 FROM {db_prefix}log_group_requests AS lgr | |
942 INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member) | |
943 INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group) | |
944 WHERE ' . $where . ' | |
945 ORDER BY {raw:sort} | |
946 LIMIT ' . $start . ', ' . $items_per_page, | |
947 array_merge($where_parameters, array( | |
948 'sort' => $sort, | |
949 )) | |
950 ); | |
951 $group_requests = array(); | |
952 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
953 { | |
954 $group_requests[] = array( | |
955 'id' => $row['id_request'], | |
956 'member_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>', | |
957 'group_link' => '<span style="color: ' . $row['online_color'] . '">' . $row['group_name'] . '</span>', | |
958 'reason' => censorText($row['reason']), | |
959 'time_submitted' => timeformat($row['time_applied']), | |
960 ); | |
961 } | |
962 $smcFunc['db_free_result']($request); | |
963 | |
964 return $group_requests; | |
965 } | |
966 | |
967 ?> |