Mercurial > hg > vamp-website
comparison forum/Sources/ManagePermissions.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 /* ManagePermissions handles all possible permission stuff. The following | |
18 functions are used: | |
19 | |
20 void ModifyPermissions() | |
21 - calls the right function based on the given subaction. | |
22 - checks the permissions, based on the sub-action. | |
23 - called by ?action=managepermissions. | |
24 - loads the ManagePermissions language file. | |
25 | |
26 void PermissionIndex() | |
27 - sets up the permissions by membergroup index page. | |
28 - called by ?action=managepermissions | |
29 - uses the permission_index template of the ManageBoards template. | |
30 - loads the ManagePermissions language and template. | |
31 - creates an array of all the groups with the number of members and permissions. | |
32 | |
33 void SetQuickGroups() | |
34 - handles permission modification actions from the upper part of the | |
35 permission manager index. | |
36 // !!! | |
37 | |
38 void ModifyMembergroup() | |
39 // !!! | |
40 | |
41 void ModifyMembergroup2() | |
42 // !!! | |
43 | |
44 void GeneralPermissionSettings() | |
45 - a screen to set some general settings for permissions. | |
46 | |
47 void setPermissionLevel(string level, int group, int profile = 'null') | |
48 - internal function to modify permissions to a pre-defined profile. | |
49 // !!! | |
50 | |
51 void loadAllPermissions() | |
52 - internal function to load permissions into $context['permissions']. | |
53 // !!! | |
54 | |
55 void loadPermissionProfiles() | |
56 // !!! | |
57 | |
58 void EditPermissionProfiles() | |
59 // !!! | |
60 | |
61 void init_inline_permissions(array permissions) | |
62 - internal function to initialise the inline permission settings. | |
63 - loads the ManagePermissions language and template. | |
64 - loads a context variables for each permission. | |
65 - used by several settings screens to set specific permissions. | |
66 | |
67 void theme_inline_permissions(string permission) | |
68 - function called by templates to show a list of permissions settings. | |
69 - calls the template function template_inline_permissions(). | |
70 | |
71 save_inline_permissions(array permissions) | |
72 - general function to save the inline permissions sent by a form. | |
73 - does no session check. | |
74 | |
75 void updateChildPermissions(array parent, int profile = null) | |
76 // !!! | |
77 | |
78 void loadIllegalPermissions() | |
79 // !!! | |
80 | |
81 void loadIllegalGuestPermissions() | |
82 - loads the permissions that can not be given to guests. | |
83 - stores the permissions in $context['non_guest_permissions']. | |
84 | |
85 void ModifyPostModeration() | |
86 // !!! | |
87 */ | |
88 | |
89 function ModifyPermissions() | |
90 { | |
91 global $txt, $scripturl, $context; | |
92 | |
93 loadLanguage('ManagePermissions+ManageMembers'); | |
94 loadTemplate('ManagePermissions'); | |
95 | |
96 // Format: 'sub-action' => array('function_to_call', 'permission_needed'), | |
97 $subActions = array( | |
98 'board' => array('PermissionByBoard', 'manage_permissions'), | |
99 'index' => array('PermissionIndex', 'manage_permissions'), | |
100 'modify' => array('ModifyMembergroup', 'manage_permissions'), | |
101 'modify2' => array('ModifyMembergroup2', 'manage_permissions'), | |
102 'quick' => array('SetQuickGroups', 'manage_permissions'), | |
103 'quickboard' => array('SetQuickBoards', 'manage_permissions'), | |
104 'postmod' => array('ModifyPostModeration', 'manage_permissions'), | |
105 'profiles' => array('EditPermissionProfiles', 'manage_permissions'), | |
106 'settings' => array('GeneralPermissionSettings', 'admin_forum'), | |
107 ); | |
108 | |
109 $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('manage_permissions') ? 'index' : 'settings'); | |
110 isAllowedTo($subActions[$_REQUEST['sa']][1]); | |
111 | |
112 // Create the tabs for the template. | |
113 $context[$context['admin_menu_name']]['tab_data'] = array( | |
114 'title' => $txt['permissions_title'], | |
115 'help' => 'permissions', | |
116 'description' => '', | |
117 'tabs' => array( | |
118 'index' => array( | |
119 'description' => $txt['permissions_groups'], | |
120 ), | |
121 'board' => array( | |
122 'description' => $txt['permission_by_board_desc'], | |
123 ), | |
124 'profiles' => array( | |
125 'description' => $txt['permissions_profiles_desc'], | |
126 ), | |
127 'postmod' => array( | |
128 'description' => $txt['permissions_post_moderation_desc'], | |
129 ), | |
130 'settings' => array( | |
131 'description' => $txt['permission_settings_desc'], | |
132 ), | |
133 ), | |
134 ); | |
135 | |
136 $subActions[$_REQUEST['sa']][0](); | |
137 } | |
138 | |
139 function PermissionIndex() | |
140 { | |
141 global $txt, $scripturl, $context, $settings, $modSettings, $smcFunc; | |
142 | |
143 $context['page_title'] = $txt['permissions_title']; | |
144 | |
145 // Load all the permissions. We'll need them in the template. | |
146 loadAllPermissions(); | |
147 | |
148 // Also load profiles, we may want to reset. | |
149 loadPermissionProfiles(); | |
150 | |
151 // Are we going to show the advanced options? | |
152 $context['show_advanced_options'] = empty($context['admin_preferences']['app']); | |
153 | |
154 // Determine the number of ungrouped members. | |
155 $request = $smcFunc['db_query']('', ' | |
156 SELECT COUNT(*) | |
157 FROM {db_prefix}members | |
158 WHERE id_group = {int:regular_group}', | |
159 array( | |
160 'regular_group' => 0, | |
161 ) | |
162 ); | |
163 list ($num_members) = $smcFunc['db_fetch_row']($request); | |
164 $smcFunc['db_free_result']($request); | |
165 | |
166 // Fill the context variable with 'Guests' and 'Regular Members'. | |
167 $context['groups'] = array( | |
168 -1 => array( | |
169 'id' => -1, | |
170 'name' => $txt['membergroups_guests'], | |
171 'num_members' => $txt['membergroups_guests_na'], | |
172 'allow_delete' => false, | |
173 'allow_modify' => true, | |
174 'can_search' => false, | |
175 'href' => '', | |
176 'link' => '', | |
177 'is_post_group' => false, | |
178 'color' => '', | |
179 'stars' => '', | |
180 'children' => array(), | |
181 'num_permissions' => array( | |
182 'allowed' => 0, | |
183 // Can't deny guest permissions! | |
184 'denied' => '(' . $txt['permissions_none'] . ')' | |
185 ), | |
186 'access' => false | |
187 ), | |
188 0 => array( | |
189 'id' => 0, | |
190 'name' => $txt['membergroups_members'], | |
191 'num_members' => $num_members, | |
192 'allow_delete' => false, | |
193 'allow_modify' => true, | |
194 'can_search' => false, | |
195 'href' => $scripturl . '?action=moderate;area=viewgroups;sa=members;group=0', | |
196 'is_post_group' => false, | |
197 'color' => '', | |
198 'stars' => '', | |
199 'children' => array(), | |
200 'num_permissions' => array( | |
201 'allowed' => 0, | |
202 'denied' => 0 | |
203 ), | |
204 'access' => false | |
205 ), | |
206 ); | |
207 | |
208 $postGroups = array(); | |
209 $normalGroups = array(); | |
210 | |
211 // Query the database defined membergroups. | |
212 $query = $smcFunc['db_query']('', ' | |
213 SELECT id_group, id_parent, group_name, min_posts, online_color, stars | |
214 FROM {db_prefix}membergroups' . (empty($modSettings['permission_enable_postgroups']) ? ' | |
215 WHERE min_posts = {int:min_posts}' : '') . ' | |
216 ORDER BY id_parent = {int:not_inherited} DESC, min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name', | |
217 array( | |
218 'min_posts' => -1, | |
219 'not_inherited' => -2, | |
220 'newbie_group' => 4, | |
221 ) | |
222 ); | |
223 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
224 { | |
225 // If it's inherited, just add it as a child. | |
226 if ($row['id_parent'] != -2) | |
227 { | |
228 if (isset($context['groups'][$row['id_parent']])) | |
229 $context['groups'][$row['id_parent']]['children'][$row['id_group']] = $row['group_name']; | |
230 continue; | |
231 } | |
232 | |
233 $row['stars'] = explode('#', $row['stars']); | |
234 $context['groups'][$row['id_group']] = array( | |
235 'id' => $row['id_group'], | |
236 'name' => $row['group_name'], | |
237 'num_members' => $row['id_group'] != 3 ? 0 : $txt['membergroups_guests_na'], | |
238 'allow_delete' => $row['id_group'] > 4, | |
239 'allow_modify' => $row['id_group'] > 1, | |
240 'can_search' => $row['id_group'] != 3, | |
241 'href' => $scripturl . '?action=moderate;area=viewgroups;sa=members;group=' . $row['id_group'], | |
242 'is_post_group' => $row['min_posts'] != -1, | |
243 'color' => empty($row['online_color']) ? '' : $row['online_color'], | |
244 'stars' => !empty($row['stars'][0]) && !empty($row['stars'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/' . $row['stars'][1] . '" alt="*" />', $row['stars'][0]) : '', | |
245 'children' => array(), | |
246 'num_permissions' => array( | |
247 'allowed' => $row['id_group'] == 1 ? '(' . $txt['permissions_all'] . ')' : 0, | |
248 'denied' => $row['id_group'] == 1 ? '(' . $txt['permissions_none'] . ')' : 0 | |
249 ), | |
250 'access' => false, | |
251 ); | |
252 | |
253 if ($row['min_posts'] == -1) | |
254 $normalGroups[$row['id_group']] = $row['id_group']; | |
255 else | |
256 $postGroups[$row['id_group']] = $row['id_group']; | |
257 } | |
258 $smcFunc['db_free_result']($query); | |
259 | |
260 // Get the number of members in this post group. | |
261 if (!empty($postGroups)) | |
262 { | |
263 $query = $smcFunc['db_query']('', ' | |
264 SELECT id_post_group AS id_group, COUNT(*) AS num_members | |
265 FROM {db_prefix}members | |
266 WHERE id_post_group IN ({array_int:post_group_list}) | |
267 GROUP BY id_post_group', | |
268 array( | |
269 'post_group_list' => $postGroups, | |
270 ) | |
271 ); | |
272 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
273 $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; | |
274 $smcFunc['db_free_result']($query); | |
275 } | |
276 | |
277 if (!empty($normalGroups)) | |
278 { | |
279 // First, the easy one! | |
280 $query = $smcFunc['db_query']('', ' | |
281 SELECT id_group, COUNT(*) AS num_members | |
282 FROM {db_prefix}members | |
283 WHERE id_group IN ({array_int:normal_group_list}) | |
284 GROUP BY id_group', | |
285 array( | |
286 'normal_group_list' => $normalGroups, | |
287 ) | |
288 ); | |
289 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
290 $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; | |
291 $smcFunc['db_free_result']($query); | |
292 | |
293 // This one is slower, but it's okay... careful not to count twice! | |
294 $query = $smcFunc['db_query']('', ' | |
295 SELECT mg.id_group, COUNT(*) AS num_members | |
296 FROM {db_prefix}membergroups AS mg | |
297 INNER JOIN {db_prefix}members AS mem ON (mem.additional_groups != {string:blank_string} | |
298 AND mem.id_group != mg.id_group | |
299 AND FIND_IN_SET(mg.id_group, mem.additional_groups) != 0) | |
300 WHERE mg.id_group IN ({array_int:normal_group_list}) | |
301 GROUP BY mg.id_group', | |
302 array( | |
303 'normal_group_list' => $normalGroups, | |
304 'blank_string' => '', | |
305 ) | |
306 ); | |
307 while ($row = $smcFunc['db_fetch_assoc']($query)) | |
308 $context['groups'][$row['id_group']]['num_members'] += $row['num_members']; | |
309 $smcFunc['db_free_result']($query); | |
310 } | |
311 | |
312 foreach ($context['groups'] as $id => $data) | |
313 { | |
314 if ($data['href'] != '') | |
315 $context['groups'][$id]['link'] = '<a href="' . $data['href'] . '">' . $data['num_members'] . '</a>'; | |
316 } | |
317 | |
318 if (empty($_REQUEST['pid'])) | |
319 { | |
320 $request = $smcFunc['db_query']('', ' | |
321 SELECT id_group, COUNT(*) AS num_permissions, add_deny | |
322 FROM {db_prefix}permissions | |
323 ' . (empty($context['hidden_permissions']) ? '' : ' WHERE permission NOT IN ({array_string:hidden_permissions})') . ' | |
324 GROUP BY id_group, add_deny', | |
325 array( | |
326 'hidden_permissions' => !empty($context['hidden_permissions']) ? $context['hidden_permissions'] : array(), | |
327 ) | |
328 ); | |
329 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
330 if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) | |
331 $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] = $row['num_permissions']; | |
332 $smcFunc['db_free_result']($request); | |
333 | |
334 // Get the "default" profile permissions too. | |
335 $request = $smcFunc['db_query']('', ' | |
336 SELECT id_profile, id_group, COUNT(*) AS num_permissions, add_deny | |
337 FROM {db_prefix}board_permissions | |
338 WHERE id_profile = {int:default_profile} | |
339 ' . (empty($context['hidden_permissions']) ? '' : ' AND permission NOT IN ({array_string:hidden_permissions})') . ' | |
340 GROUP BY id_profile, id_group, add_deny', | |
341 array( | |
342 'default_profile' => 1, | |
343 'hidden_permissions' => !empty($context['hidden_permissions']) ? $context['hidden_permissions'] : array(), | |
344 ) | |
345 ); | |
346 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
347 { | |
348 if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) | |
349 $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions']; | |
350 } | |
351 $smcFunc['db_free_result']($request); | |
352 } | |
353 else | |
354 { | |
355 $_REQUEST['pid'] = (int) $_REQUEST['pid']; | |
356 | |
357 if (!isset($context['profiles'][$_REQUEST['pid']])) | |
358 fatal_lang_error('no_access', false); | |
359 | |
360 // Change the selected tab to better reflect that this really is a board profile. | |
361 $context[$context['admin_menu_name']]['current_subsection'] = 'profiles'; | |
362 | |
363 $request = $smcFunc['db_query']('', ' | |
364 SELECT id_profile, id_group, COUNT(*) AS num_permissions, add_deny | |
365 FROM {db_prefix}board_permissions | |
366 WHERE id_profile = {int:current_profile} | |
367 GROUP BY id_profile, id_group, add_deny', | |
368 array( | |
369 'current_profile' => $_REQUEST['pid'], | |
370 ) | |
371 ); | |
372 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
373 { | |
374 if (isset($context['groups'][(int) $row['id_group']]) && (!empty($row['add_deny']) || $row['id_group'] != -1)) | |
375 $context['groups'][(int) $row['id_group']]['num_permissions'][empty($row['add_deny']) ? 'denied' : 'allowed'] += $row['num_permissions']; | |
376 } | |
377 $smcFunc['db_free_result']($request); | |
378 | |
379 $context['profile'] = array( | |
380 'id' => $_REQUEST['pid'], | |
381 'name' => $context['profiles'][$_REQUEST['pid']]['name'], | |
382 ); | |
383 } | |
384 | |
385 // We can modify any permission set apart from the read only, reply only and no polls ones as they are redefined. | |
386 $context['can_modify'] = empty($_REQUEST['pid']) || $_REQUEST['pid'] == 1 || $_REQUEST['pid'] > 4; | |
387 | |
388 // Load the proper template. | |
389 $context['sub_template'] = 'permission_index'; | |
390 } | |
391 | |
392 function PermissionByBoard() | |
393 { | |
394 global $context, $modSettings, $txt, $smcFunc, $sourcedir, $cat_tree, $boardList, $boards; | |
395 | |
396 $context['page_title'] = $txt['permissions_boards']; | |
397 $context['edit_all'] = isset($_GET['edit']); | |
398 | |
399 // Saving? | |
400 if (!empty($_POST['save_changes']) && !empty($_POST['boardprofile'])) | |
401 { | |
402 checkSession('request'); | |
403 | |
404 $changes = array(); | |
405 foreach ($_POST['boardprofile'] as $board => $profile) | |
406 { | |
407 $changes[(int) $profile][] = (int) $board; | |
408 } | |
409 | |
410 if (!empty($changes)) | |
411 { | |
412 foreach ($changes as $profile => $boards) | |
413 $smcFunc['db_query']('', ' | |
414 UPDATE {db_prefix}boards | |
415 SET id_profile = {int:current_profile} | |
416 WHERE id_board IN ({array_int:board_list})', | |
417 array( | |
418 'board_list' => $boards, | |
419 'current_profile' => $profile, | |
420 ) | |
421 ); | |
422 } | |
423 | |
424 $context['edit_all'] = false; | |
425 } | |
426 | |
427 // Load all permission profiles. | |
428 loadPermissionProfiles(); | |
429 | |
430 // Get the board tree. | |
431 require_once($sourcedir . '/Subs-Boards.php'); | |
432 | |
433 getBoardTree(); | |
434 | |
435 // Build the list of the boards. | |
436 $context['categories'] = array(); | |
437 foreach ($cat_tree as $catid => $tree) | |
438 { | |
439 $context['categories'][$catid] = array( | |
440 'name' => &$tree['node']['name'], | |
441 'id' => &$tree['node']['id'], | |
442 'boards' => array() | |
443 ); | |
444 foreach ($boardList[$catid] as $boardid) | |
445 { | |
446 if (!isset($context['profiles'][$boards[$boardid]['profile']])) | |
447 $boards[$boardid]['profile'] = 1; | |
448 | |
449 $context['categories'][$catid]['boards'][$boardid] = array( | |
450 'id' => &$boards[$boardid]['id'], | |
451 'name' => &$boards[$boardid]['name'], | |
452 'description' => &$boards[$boardid]['description'], | |
453 'child_level' => &$boards[$boardid]['level'], | |
454 'profile' => &$boards[$boardid]['profile'], | |
455 'profile_name' => $context['profiles'][$boards[$boardid]['profile']]['name'], | |
456 ); | |
457 } | |
458 } | |
459 | |
460 $context['sub_template'] = 'by_board'; | |
461 } | |
462 | |
463 function SetQuickGroups() | |
464 { | |
465 global $context, $smcFunc; | |
466 | |
467 checkSession(); | |
468 | |
469 loadIllegalPermissions(); | |
470 loadIllegalGuestPermissions(); | |
471 | |
472 // Make sure only one of the quick options was selected. | |
473 if ((!empty($_POST['predefined']) && ((isset($_POST['copy_from']) && $_POST['copy_from'] != 'empty') || !empty($_POST['permissions']))) || (!empty($_POST['copy_from']) && $_POST['copy_from'] != 'empty' && !empty($_POST['permissions']))) | |
474 fatal_lang_error('permissions_only_one_option', false); | |
475 | |
476 if (empty($_POST['group']) || !is_array($_POST['group'])) | |
477 $_POST['group'] = array(); | |
478 | |
479 // Only accept numeric values for selected membergroups. | |
480 foreach ($_POST['group'] as $id => $group_id) | |
481 $_POST['group'][$id] = (int) $group_id; | |
482 $_POST['group'] = array_unique($_POST['group']); | |
483 | |
484 if (empty($_REQUEST['pid'])) | |
485 $_REQUEST['pid'] = 0; | |
486 else | |
487 $_REQUEST['pid'] = (int) $_REQUEST['pid']; | |
488 | |
489 // Fix up the old global to the new default! | |
490 $bid = max(1, $_REQUEST['pid']); | |
491 | |
492 // No modifying the predefined profiles. | |
493 if ($_REQUEST['pid'] > 1 && $_REQUEST['pid'] < 5) | |
494 fatal_lang_error('no_access', false); | |
495 | |
496 // Clear out any cached authority. | |
497 updateSettings(array('settings_updated' => time())); | |
498 | |
499 // No groups where selected. | |
500 if (empty($_POST['group'])) | |
501 redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); | |
502 | |
503 // Set a predefined permission profile. | |
504 if (!empty($_POST['predefined'])) | |
505 { | |
506 // Make sure it's a predefined permission set we expect. | |
507 if (!in_array($_POST['predefined'], array('restrict', 'standard', 'moderator', 'maintenance'))) | |
508 redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); | |
509 | |
510 foreach ($_POST['group'] as $group_id) | |
511 { | |
512 if (!empty($_REQUEST['pid'])) | |
513 setPermissionLevel($_POST['predefined'], $group_id, $_REQUEST['pid']); | |
514 else | |
515 setPermissionLevel($_POST['predefined'], $group_id); | |
516 } | |
517 } | |
518 // Set a permission profile based on the permissions of a selected group. | |
519 elseif ($_POST['copy_from'] != 'empty') | |
520 { | |
521 // Just checking the input. | |
522 if (!is_numeric($_POST['copy_from'])) | |
523 redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); | |
524 | |
525 // Make sure the group we're copying to is never included. | |
526 $_POST['group'] = array_diff($_POST['group'], array($_POST['copy_from'])); | |
527 | |
528 // No groups left? Too bad. | |
529 if (empty($_POST['group'])) | |
530 redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); | |
531 | |
532 if (empty($_REQUEST['pid'])) | |
533 { | |
534 // Retrieve current permissions of group. | |
535 $request = $smcFunc['db_query']('', ' | |
536 SELECT permission, add_deny | |
537 FROM {db_prefix}permissions | |
538 WHERE id_group = {int:copy_from}', | |
539 array( | |
540 'copy_from' => $_POST['copy_from'], | |
541 ) | |
542 ); | |
543 $target_perm = array(); | |
544 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
545 $target_perm[$row['permission']] = $row['add_deny']; | |
546 $smcFunc['db_free_result']($request); | |
547 | |
548 $inserts = array(); | |
549 foreach ($_POST['group'] as $group_id) | |
550 foreach ($target_perm as $perm => $add_deny) | |
551 { | |
552 // No dodgy permissions please! | |
553 if (!empty($context['illegal_permissions']) && in_array($perm, $context['illegal_permissions'])) | |
554 continue; | |
555 if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) | |
556 continue; | |
557 | |
558 if ($group_id != 1 && $group_id != 3) | |
559 $inserts[] = array($perm, $group_id, $add_deny); | |
560 } | |
561 | |
562 // Delete the previous permissions... | |
563 $smcFunc['db_query']('', ' | |
564 DELETE FROM {db_prefix}permissions | |
565 WHERE id_group IN ({array_int:group_list}) | |
566 ' . (empty($context['illegal_permissions']) ? '' : ' AND permission NOT IN ({array_string:illegal_permissions})'), | |
567 array( | |
568 'group_list' => $_POST['group'], | |
569 'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(), | |
570 ) | |
571 ); | |
572 | |
573 if (!empty($inserts)) | |
574 { | |
575 // ..and insert the new ones. | |
576 $smcFunc['db_insert']('', | |
577 '{db_prefix}permissions', | |
578 array( | |
579 'permission' => 'string', 'id_group' => 'int', 'add_deny' => 'int', | |
580 ), | |
581 $inserts, | |
582 array('permission', 'id_group') | |
583 ); | |
584 } | |
585 } | |
586 | |
587 // Now do the same for the board permissions. | |
588 $request = $smcFunc['db_query']('', ' | |
589 SELECT permission, add_deny | |
590 FROM {db_prefix}board_permissions | |
591 WHERE id_group = {int:copy_from} | |
592 AND id_profile = {int:current_profile}', | |
593 array( | |
594 'copy_from' => $_POST['copy_from'], | |
595 'current_profile' => $bid, | |
596 ) | |
597 ); | |
598 $target_perm = array(); | |
599 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
600 $target_perm[$row['permission']] = $row['add_deny']; | |
601 $smcFunc['db_free_result']($request); | |
602 | |
603 $inserts = array(); | |
604 foreach ($_POST['group'] as $group_id) | |
605 foreach ($target_perm as $perm => $add_deny) | |
606 { | |
607 // Are these for guests? | |
608 if ($group_id == -1 && in_array($perm, $context['non_guest_permissions'])) | |
609 continue; | |
610 | |
611 $inserts[] = array($perm, $group_id, $bid, $add_deny); | |
612 } | |
613 | |
614 // Delete the previous global board permissions... | |
615 $smcFunc['db_query']('', ' | |
616 DELETE FROM {db_prefix}board_permissions | |
617 WHERE id_group IN ({array_int:current_group_list}) | |
618 AND id_profile = {int:current_profile}', | |
619 array( | |
620 'current_group_list' => $_POST['group'], | |
621 'current_profile' => $bid, | |
622 ) | |
623 ); | |
624 | |
625 // And insert the copied permissions. | |
626 if (!empty($inserts)) | |
627 { | |
628 // ..and insert the new ones. | |
629 $smcFunc['db_insert']('', | |
630 '{db_prefix}board_permissions', | |
631 array('permission' => 'string', 'id_group' => 'int', 'id_profile' => 'int', 'add_deny' => 'int'), | |
632 $inserts, | |
633 array('permission', 'id_group', 'id_profile') | |
634 ); | |
635 } | |
636 | |
637 // Update any children out there! | |
638 updateChildPermissions($_POST['group'], $_REQUEST['pid']); | |
639 } | |
640 // Set or unset a certain permission for the selected groups. | |
641 elseif (!empty($_POST['permissions'])) | |
642 { | |
643 // Unpack two variables that were transported. | |
644 list ($permissionType, $permission) = explode('/', $_POST['permissions']); | |
645 | |
646 // Check whether our input is within expected range. | |
647 if (!in_array($_POST['add_remove'], array('add', 'clear', 'deny')) || !in_array($permissionType, array('membergroup', 'board'))) | |
648 redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); | |
649 | |
650 if ($_POST['add_remove'] == 'clear') | |
651 { | |
652 if ($permissionType == 'membergroup') | |
653 $smcFunc['db_query']('', ' | |
654 DELETE FROM {db_prefix}permissions | |
655 WHERE id_group IN ({array_int:current_group_list}) | |
656 AND permission = {string:current_permission} | |
657 ' . (empty($context['illegal_permissions']) ? '' : ' AND permission NOT IN ({array_string:illegal_permissions})'), | |
658 array( | |
659 'current_group_list' => $_POST['group'], | |
660 'current_permission' => $permission, | |
661 'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(), | |
662 ) | |
663 ); | |
664 else | |
665 $smcFunc['db_query']('', ' | |
666 DELETE FROM {db_prefix}board_permissions | |
667 WHERE id_group IN ({array_int:current_group_list}) | |
668 AND id_profile = {int:current_profile} | |
669 AND permission = {string:current_permission}', | |
670 array( | |
671 'current_group_list' => $_POST['group'], | |
672 'current_profile' => $bid, | |
673 'current_permission' => $permission, | |
674 ) | |
675 ); | |
676 } | |
677 // Add a permission (either 'set' or 'deny'). | |
678 else | |
679 { | |
680 $add_deny = $_POST['add_remove'] == 'add' ? '1' : '0'; | |
681 $permChange = array(); | |
682 foreach ($_POST['group'] as $groupID) | |
683 { | |
684 if ($groupID == -1 && in_array($permission, $context['non_guest_permissions'])) | |
685 continue; | |
686 | |
687 if ($permissionType == 'membergroup' && $groupID != 1 && $groupID != 3 && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) | |
688 $permChange[] = array($permission, $groupID, $add_deny); | |
689 elseif ($permissionType != 'membergroup') | |
690 $permChange[] = array($permission, $groupID, $bid, $add_deny); | |
691 } | |
692 | |
693 if (!empty($permChange)) | |
694 { | |
695 if ($permissionType == 'membergroup') | |
696 $smcFunc['db_insert']('replace', | |
697 '{db_prefix}permissions', | |
698 array('permission' => 'string', 'id_group' => 'int', 'add_deny' => 'int'), | |
699 $permChange, | |
700 array('permission', 'id_group') | |
701 ); | |
702 // Board permissions go into the other table. | |
703 else | |
704 $smcFunc['db_insert']('replace', | |
705 '{db_prefix}board_permissions', | |
706 array('permission' => 'string', 'id_group' => 'int', 'id_profile' => 'int', 'add_deny' => 'int'), | |
707 $permChange, | |
708 array('permission', 'id_group', 'id_profile') | |
709 ); | |
710 } | |
711 } | |
712 | |
713 // Another child update! | |
714 updateChildPermissions($_POST['group'], $_REQUEST['pid']); | |
715 } | |
716 | |
717 redirectexit('action=admin;area=permissions;pid=' . $_REQUEST['pid']); | |
718 } | |
719 | |
720 function ModifyMembergroup() | |
721 { | |
722 global $context, $txt, $modSettings, $smcFunc, $sourcedir; | |
723 | |
724 if (!isset($_GET['group'])) | |
725 fatal_lang_error('no_access', false); | |
726 | |
727 $context['group']['id'] = (int) $_GET['group']; | |
728 | |
729 // Are they toggling the view? | |
730 if (isset($_GET['view'])) | |
731 { | |
732 $context['admin_preferences']['pv'] = $_GET['view'] == 'classic' ? 'classic' : 'simple'; | |
733 | |
734 // Update the users preferences. | |
735 require_once($sourcedir . '/Subs-Admin.php'); | |
736 updateAdminPreferences(); | |
737 } | |
738 | |
739 $context['view_type'] = !empty($context['admin_preferences']['pv']) && $context['admin_preferences']['pv'] == 'classic' ? 'classic' : 'simple'; | |
740 | |
741 // It's not likely you'd end up here with this setting disabled. | |
742 if ($_GET['group'] == 1) | |
743 redirectexit('action=admin;area=permissions'); | |
744 | |
745 loadAllPermissions($context['view_type']); | |
746 loadPermissionProfiles(); | |
747 | |
748 if ($context['group']['id'] > 0) | |
749 { | |
750 $result = $smcFunc['db_query']('', ' | |
751 SELECT group_name, id_parent | |
752 FROM {db_prefix}membergroups | |
753 WHERE id_group = {int:current_group} | |
754 LIMIT 1', | |
755 array( | |
756 'current_group' => $context['group']['id'], | |
757 ) | |
758 ); | |
759 list ($context['group']['name'], $parent) = $smcFunc['db_fetch_row']($result); | |
760 $smcFunc['db_free_result']($result); | |
761 | |
762 // Cannot edit an inherited group! | |
763 if ($parent != -2) | |
764 fatal_lang_error('cannot_edit_permissions_inherited'); | |
765 } | |
766 elseif ($context['group']['id'] == -1) | |
767 $context['group']['name'] = $txt['membergroups_guests']; | |
768 else | |
769 $context['group']['name'] = $txt['membergroups_members']; | |
770 | |
771 $context['profile']['id'] = empty($_GET['pid']) ? 0 : (int) $_GET['pid']; | |
772 | |
773 // If this is a moderator and they are editing "no profile" then we only do boards. | |
774 if ($context['group']['id'] == 3 && empty($context['profile']['id'])) | |
775 { | |
776 // For sanity just check they have no general permissions. | |
777 $smcFunc['db_query']('', ' | |
778 DELETE FROM {db_prefix}permissions | |
779 WHERE id_group = {int:moderator_group}', | |
780 array( | |
781 'moderator_group' => 3, | |
782 ) | |
783 ); | |
784 | |
785 $context['profile']['id'] = 1; | |
786 } | |
787 | |
788 $context['permission_type'] = empty($context['profile']['id']) ? 'membergroup' : 'board'; | |
789 $context['profile']['can_modify'] = !$context['profile']['id'] || $context['profiles'][$context['profile']['id']]['can_modify']; | |
790 | |
791 // Set up things a little nicer for board related stuff... | |
792 if ($context['permission_type'] == 'board') | |
793 { | |
794 $context['profile']['name'] = $context['profiles'][$context['profile']['id']]['name']; | |
795 $context[$context['admin_menu_name']]['current_subsection'] = 'profiles'; | |
796 } | |
797 | |
798 // Fetch the current permissions. | |
799 $permissions = array( | |
800 'membergroup' => array('allowed' => array(), 'denied' => array()), | |
801 'board' => array('allowed' => array(), 'denied' => array()) | |
802 ); | |
803 | |
804 // General permissions? | |
805 if ($context['permission_type'] == 'membergroup') | |
806 { | |
807 $result = $smcFunc['db_query']('', ' | |
808 SELECT permission, add_deny | |
809 FROM {db_prefix}permissions | |
810 WHERE id_group = {int:current_group}', | |
811 array( | |
812 'current_group' => $_GET['group'], | |
813 ) | |
814 ); | |
815 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
816 $permissions['membergroup'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission']; | |
817 $smcFunc['db_free_result']($result); | |
818 } | |
819 | |
820 // Fetch current board permissions... | |
821 $result = $smcFunc['db_query']('', ' | |
822 SELECT permission, add_deny | |
823 FROM {db_prefix}board_permissions | |
824 WHERE id_group = {int:current_group} | |
825 AND id_profile = {int:current_profile}', | |
826 array( | |
827 'current_group' => $context['group']['id'], | |
828 'current_profile' => $context['permission_type'] == 'membergroup' ? 1 : $context['profile']['id'], | |
829 ) | |
830 ); | |
831 while ($row = $smcFunc['db_fetch_assoc']($result)) | |
832 $permissions['board'][empty($row['add_deny']) ? 'denied' : 'allowed'][] = $row['permission']; | |
833 $smcFunc['db_free_result']($result); | |
834 | |
835 // Loop through each permission and set whether it's checked. | |
836 foreach ($context['permissions'] as $permissionType => $tmp) | |
837 { | |
838 foreach ($tmp['columns'] as $position => $permissionGroups) | |
839 { | |
840 foreach ($permissionGroups as $permissionGroup => $permissionArray) | |
841 { | |
842 foreach ($permissionArray['permissions'] as $perm) | |
843 { | |
844 // Create a shortcut for the current permission. | |
845 $curPerm = &$context['permissions'][$permissionType]['columns'][$position][$permissionGroup]['permissions'][$perm['id']]; | |
846 if ($tmp['view'] == 'classic') | |
847 { | |
848 if ($perm['has_own_any']) | |
849 { | |
850 $curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'denied' : 'off'); | |
851 $curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'denied' : 'off'); | |
852 } | |
853 else | |
854 $curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'denied' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off'); | |
855 } | |
856 else | |
857 { | |
858 $curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'denied' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off'); | |
859 } | |
860 } | |
861 } | |
862 } | |
863 } | |
864 $context['sub_template'] = 'modify_group'; | |
865 $context['page_title'] = $txt['permissions_modify_group']; | |
866 } | |
867 | |
868 function ModifyMembergroup2() | |
869 { | |
870 global $modSettings, $smcFunc, $context; | |
871 | |
872 checkSession(); | |
873 | |
874 loadIllegalPermissions(); | |
875 | |
876 $_GET['group'] = (int) $_GET['group']; | |
877 $_GET['pid'] = (int) $_GET['pid']; | |
878 | |
879 // Cannot modify predefined profiles. | |
880 if ($_GET['pid'] > 1 && $_GET['pid'] < 5) | |
881 fatal_lang_error('no_access', false); | |
882 | |
883 // Verify this isn't inherited. | |
884 if ($_GET['group'] == -1 || $_GET['group'] == 0) | |
885 $parent = -2; | |
886 else | |
887 { | |
888 $result = $smcFunc['db_query']('', ' | |
889 SELECT id_parent | |
890 FROM {db_prefix}membergroups | |
891 WHERE id_group = {int:current_group} | |
892 LIMIT 1', | |
893 array( | |
894 'current_group' => $_GET['group'], | |
895 ) | |
896 ); | |
897 list ($parent) = $smcFunc['db_fetch_row']($result); | |
898 $smcFunc['db_free_result']($result); | |
899 } | |
900 | |
901 if ($parent != -2) | |
902 fatal_lang_error('cannot_edit_permissions_inherited'); | |
903 | |
904 $givePerms = array('membergroup' => array(), 'board' => array()); | |
905 | |
906 // Guest group, we need illegal, guest permissions. | |
907 if ($_GET['group'] == -1) | |
908 { | |
909 loadIllegalGuestPermissions(); | |
910 $context['illegal_permissions'] = array_merge($context['illegal_permissions'], $context['non_guest_permissions']); | |
911 } | |
912 | |
913 // Prepare all permissions that were set or denied for addition to the DB. | |
914 if (isset($_POST['perm']) && is_array($_POST['perm'])) | |
915 { | |
916 foreach ($_POST['perm'] as $perm_type => $perm_array) | |
917 { | |
918 if (is_array($perm_array)) | |
919 { | |
920 foreach ($perm_array as $permission => $value) | |
921 if ($value == 'on' || $value == 'deny') | |
922 { | |
923 // Don't allow people to escalate themselves! | |
924 if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) | |
925 continue; | |
926 | |
927 $givePerms[$perm_type][] = array($_GET['group'], $permission, $value == 'deny' ? 0 : 1); | |
928 } | |
929 } | |
930 } | |
931 } | |
932 | |
933 // Insert the general permissions. | |
934 if ($_GET['group'] != 3 && empty($_GET['pid'])) | |
935 { | |
936 $smcFunc['db_query']('', ' | |
937 DELETE FROM {db_prefix}permissions | |
938 WHERE id_group = {int:current_group} | |
939 ' . (empty($context['illegal_permissions']) ? '' : ' AND permission NOT IN ({array_string:illegal_permissions})'), | |
940 array( | |
941 'current_group' => $_GET['group'], | |
942 'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(), | |
943 ) | |
944 ); | |
945 | |
946 if (!empty($givePerms['membergroup'])) | |
947 { | |
948 $smcFunc['db_insert']('replace', | |
949 '{db_prefix}permissions', | |
950 array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), | |
951 $givePerms['membergroup'], | |
952 array('id_group', 'permission') | |
953 ); | |
954 } | |
955 } | |
956 | |
957 // Insert the boardpermissions. | |
958 $profileid = max(1, $_GET['pid']); | |
959 $smcFunc['db_query']('', ' | |
960 DELETE FROM {db_prefix}board_permissions | |
961 WHERE id_group = {int:current_group} | |
962 AND id_profile = {int:current_profile}', | |
963 array( | |
964 'current_group' => $_GET['group'], | |
965 'current_profile' => $profileid, | |
966 ) | |
967 ); | |
968 if (!empty($givePerms['board'])) | |
969 { | |
970 foreach ($givePerms['board'] as $k => $v) | |
971 $givePerms['board'][$k][] = $profileid; | |
972 $smcFunc['db_insert']('replace', | |
973 '{db_prefix}board_permissions', | |
974 array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int', 'id_profile' => 'int'), | |
975 $givePerms['board'], | |
976 array('id_group', 'permission', 'id_profile') | |
977 ); | |
978 } | |
979 | |
980 // Update any inherited permissions as required. | |
981 updateChildPermissions($_GET['group'], $_GET['pid']); | |
982 | |
983 // Clear cached privs. | |
984 updateSettings(array('settings_updated' => time())); | |
985 | |
986 redirectexit('action=admin;area=permissions;pid=' . $_GET['pid']); | |
987 } | |
988 | |
989 // Screen for modifying general permission settings. | |
990 function GeneralPermissionSettings($return_config = false) | |
991 { | |
992 global $context, $modSettings, $sourcedir, $txt, $scripturl, $smcFunc; | |
993 | |
994 // All the setting variables | |
995 $config_vars = array( | |
996 array('title', 'settings'), | |
997 // Inline permissions. | |
998 array('permissions', 'manage_permissions'), | |
999 '', | |
1000 // A few useful settings | |
1001 array('check', 'permission_enable_deny', 0, $txt['permission_settings_enable_deny'], 'help' => 'permissions_deny'), | |
1002 array('check', 'permission_enable_postgroups', 0, $txt['permission_settings_enable_postgroups'], 'help' => 'permissions_postgroups'), | |
1003 ); | |
1004 | |
1005 if ($return_config) | |
1006 return $config_vars; | |
1007 | |
1008 $context['page_title'] = $txt['permission_settings_title']; | |
1009 $context['sub_template'] = 'show_settings'; | |
1010 | |
1011 // Needed for the inline permission functions, and the settings template. | |
1012 require_once($sourcedir . '/ManageServer.php'); | |
1013 | |
1014 // Don't let guests have these permissions. | |
1015 $context['post_url'] = $scripturl . '?action=admin;area=permissions;save;sa=settings'; | |
1016 $context['permissions_excluded'] = array(-1); | |
1017 | |
1018 // Saving the settings? | |
1019 if (isset($_GET['save'])) | |
1020 { | |
1021 checkSession('post'); | |
1022 saveDBSettings($config_vars); | |
1023 | |
1024 // Clear all deny permissions...if we want that. | |
1025 if (empty($modSettings['permission_enable_deny'])) | |
1026 { | |
1027 $smcFunc['db_query']('', ' | |
1028 DELETE FROM {db_prefix}permissions | |
1029 WHERE add_deny = {int:denied}', | |
1030 array( | |
1031 'denied' => 0, | |
1032 ) | |
1033 ); | |
1034 $smcFunc['db_query']('', ' | |
1035 DELETE FROM {db_prefix}board_permissions | |
1036 WHERE add_deny = {int:denied}', | |
1037 array( | |
1038 'denied' => 0, | |
1039 ) | |
1040 ); | |
1041 } | |
1042 | |
1043 // Make sure there are no postgroup based permissions left. | |
1044 if (empty($modSettings['permission_enable_postgroups'])) | |
1045 { | |
1046 // Get a list of postgroups. | |
1047 $post_groups = array(); | |
1048 $request = $smcFunc['db_query']('', ' | |
1049 SELECT id_group | |
1050 FROM {db_prefix}membergroups | |
1051 WHERE min_posts != {int:min_posts}', | |
1052 array( | |
1053 'min_posts' => -1, | |
1054 ) | |
1055 ); | |
1056 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
1057 $post_groups[] = $row['id_group']; | |
1058 $smcFunc['db_free_result']($request); | |
1059 | |
1060 // Remove'em. | |
1061 $smcFunc['db_query']('', ' | |
1062 DELETE FROM {db_prefix}permissions | |
1063 WHERE id_group IN ({array_int:post_group_list})', | |
1064 array( | |
1065 'post_group_list' => $post_groups, | |
1066 ) | |
1067 ); | |
1068 $smcFunc['db_query']('', ' | |
1069 DELETE FROM {db_prefix}board_permissions | |
1070 WHERE id_group IN ({array_int:post_group_list})', | |
1071 array( | |
1072 'post_group_list' => $post_groups, | |
1073 ) | |
1074 ); | |
1075 $smcFunc['db_query']('', ' | |
1076 UPDATE {db_prefix}membergroups | |
1077 SET id_parent = {int:not_inherited} | |
1078 WHERE id_parent IN ({array_int:post_group_list})', | |
1079 array( | |
1080 'post_group_list' => $post_groups, | |
1081 'not_inherited' => -2, | |
1082 ) | |
1083 ); | |
1084 } | |
1085 | |
1086 redirectexit('action=admin;area=permissions;sa=settings'); | |
1087 } | |
1088 | |
1089 prepareDBSettingContext($config_vars); | |
1090 } | |
1091 | |
1092 // Set the permission level for a specific profile, group, or group for a profile. | |
1093 function setPermissionLevel($level, $group, $profile = 'null') | |
1094 { | |
1095 global $smcFunc, $context; | |
1096 | |
1097 loadIllegalPermissions(); | |
1098 loadIllegalGuestPermissions(); | |
1099 | |
1100 // Levels by group... restrict, standard, moderator, maintenance. | |
1101 $groupLevels = array( | |
1102 'board' => array('inherit' => array()), | |
1103 'group' => array('inherit' => array()) | |
1104 ); | |
1105 // Levels by board... standard, publish, free. | |
1106 $boardLevels = array('inherit' => array()); | |
1107 | |
1108 // Restrictive - ie. guests. | |
1109 $groupLevels['global']['restrict'] = array( | |
1110 'search_posts', | |
1111 'calendar_view', | |
1112 'view_stats', | |
1113 'who_view', | |
1114 'profile_view_own', | |
1115 'profile_identity_own', | |
1116 ); | |
1117 $groupLevels['board']['restrict'] = array( | |
1118 'poll_view', | |
1119 'post_new', | |
1120 'post_reply_own', | |
1121 'post_reply_any', | |
1122 'delete_own', | |
1123 'modify_own', | |
1124 'mark_any_notify', | |
1125 'mark_notify', | |
1126 'report_any', | |
1127 'send_topic', | |
1128 ); | |
1129 | |
1130 // Standard - ie. members. They can do anything Restrictive can. | |
1131 $groupLevels['global']['standard'] = array_merge($groupLevels['global']['restrict'], array( | |
1132 'view_mlist', | |
1133 'karma_edit', | |
1134 'pm_read', | |
1135 'pm_send', | |
1136 'profile_view_any', | |
1137 'profile_extra_own', | |
1138 'profile_server_avatar', | |
1139 'profile_upload_avatar', | |
1140 'profile_remote_avatar', | |
1141 'profile_remove_own', | |
1142 )); | |
1143 $groupLevels['board']['standard'] = array_merge($groupLevels['board']['restrict'], array( | |
1144 'poll_vote', | |
1145 'poll_edit_own', | |
1146 'poll_post', | |
1147 'poll_add_own', | |
1148 'post_attachment', | |
1149 'lock_own', | |
1150 'remove_own', | |
1151 'view_attachments', | |
1152 )); | |
1153 | |
1154 // Moderator - ie. moderators :P. They can do what standard can, and more. | |
1155 $groupLevels['global']['moderator'] = array_merge($groupLevels['global']['standard'], array( | |
1156 'calendar_post', | |
1157 'calendar_edit_own', | |
1158 'access_mod_center', | |
1159 'issue_warning', | |
1160 )); | |
1161 $groupLevels['board']['moderator'] = array_merge($groupLevels['board']['standard'], array( | |
1162 'make_sticky', | |
1163 'poll_edit_any', | |
1164 'delete_any', | |
1165 'modify_any', | |
1166 'lock_any', | |
1167 'remove_any', | |
1168 'move_any', | |
1169 'merge_any', | |
1170 'split_any', | |
1171 'poll_lock_any', | |
1172 'poll_remove_any', | |
1173 'poll_add_any', | |
1174 'approve_posts', | |
1175 )); | |
1176 | |
1177 // Maintenance - wannabe admins. They can do almost everything. | |
1178 $groupLevels['global']['maintenance'] = array_merge($groupLevels['global']['moderator'], array( | |
1179 'manage_attachments', | |
1180 'manage_smileys', | |
1181 'manage_boards', | |
1182 'moderate_forum', | |
1183 'manage_membergroups', | |
1184 'manage_bans', | |
1185 'admin_forum', | |
1186 'manage_permissions', | |
1187 'edit_news', | |
1188 'calendar_edit_any', | |
1189 'profile_identity_any', | |
1190 'profile_extra_any', | |
1191 'profile_title_any', | |
1192 )); | |
1193 $groupLevels['board']['maintenance'] = array_merge($groupLevels['board']['moderator'], array( | |
1194 )); | |
1195 | |
1196 // Standard - nothing above the group permissions. (this SHOULD be empty.) | |
1197 $boardLevels['standard'] = array( | |
1198 ); | |
1199 | |
1200 // Locked - just that, you can't post here. | |
1201 $boardLevels['locked'] = array( | |
1202 'poll_view', | |
1203 'mark_notify', | |
1204 'report_any', | |
1205 'send_topic', | |
1206 'view_attachments', | |
1207 ); | |
1208 | |
1209 // Publisher - just a little more... | |
1210 $boardLevels['publish'] = array_merge($boardLevels['locked'], array( | |
1211 'post_new', | |
1212 'post_reply_own', | |
1213 'post_reply_any', | |
1214 'delete_own', | |
1215 'modify_own', | |
1216 'mark_any_notify', | |
1217 'delete_replies', | |
1218 'modify_replies', | |
1219 'poll_vote', | |
1220 'poll_edit_own', | |
1221 'poll_post', | |
1222 'poll_add_own', | |
1223 'poll_remove_own', | |
1224 'post_attachment', | |
1225 'lock_own', | |
1226 'remove_own', | |
1227 )); | |
1228 | |
1229 // Free for All - Scary. Just scary. | |
1230 $boardLevels['free'] = array_merge($boardLevels['publish'], array( | |
1231 'poll_lock_any', | |
1232 'poll_edit_any', | |
1233 'poll_add_any', | |
1234 'poll_remove_any', | |
1235 'make_sticky', | |
1236 'lock_any', | |
1237 'remove_any', | |
1238 'delete_any', | |
1239 'split_any', | |
1240 'merge_any', | |
1241 'modify_any', | |
1242 'approve_posts', | |
1243 )); | |
1244 | |
1245 // Make sure we're not granting someone too many permissions! | |
1246 foreach ($groupLevels['global'][$level] as $k => $permission) | |
1247 { | |
1248 if (!empty($context['illegal_permissions']) && in_array($permission, $context['illegal_permissions'])) | |
1249 unset($groupLevels['global'][$level][$k]); | |
1250 | |
1251 if ($group == -1 && in_array($permission, $context['non_guest_permissions'])) | |
1252 unset($groupLevels['global'][$level][$k]); | |
1253 } | |
1254 if ($group == -1) | |
1255 foreach ($groupLevels['board'][$level] as $k => $permission) | |
1256 if (in_array($permission, $context['non_guest_permissions'])) | |
1257 unset($groupLevels['board'][$level][$k]); | |
1258 | |
1259 // Reset all cached permissions. | |
1260 updateSettings(array('settings_updated' => time())); | |
1261 | |
1262 // Setting group permissions. | |
1263 if ($profile === 'null' && $group !== 'null') | |
1264 { | |
1265 $group = (int) $group; | |
1266 | |
1267 if (empty($groupLevels['global'][$level])) | |
1268 return; | |
1269 | |
1270 $smcFunc['db_query']('', ' | |
1271 DELETE FROM {db_prefix}permissions | |
1272 WHERE id_group = {int:current_group} | |
1273 ' . (empty($context['illegal_permissions']) ? '' : ' AND permission NOT IN ({array_string:illegal_permissions})'), | |
1274 array( | |
1275 'current_group' => $group, | |
1276 'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(), | |
1277 ) | |
1278 ); | |
1279 $smcFunc['db_query']('', ' | |
1280 DELETE FROM {db_prefix}board_permissions | |
1281 WHERE id_group = {int:current_group} | |
1282 AND id_profile = {int:default_profile}', | |
1283 array( | |
1284 'current_group' => $group, | |
1285 'default_profile' => 1, | |
1286 ) | |
1287 ); | |
1288 | |
1289 $groupInserts = array(); | |
1290 foreach ($groupLevels['global'][$level] as $permission) | |
1291 $groupInserts[] = array($group, $permission); | |
1292 | |
1293 $smcFunc['db_insert']('insert', | |
1294 '{db_prefix}permissions', | |
1295 array('id_group' => 'int', 'permission' => 'string'), | |
1296 $groupInserts, | |
1297 array('id_group') | |
1298 ); | |
1299 | |
1300 $boardInserts = array(); | |
1301 foreach ($groupLevels['board'][$level] as $permission) | |
1302 $boardInserts[] = array(1, $group, $permission); | |
1303 | |
1304 $smcFunc['db_insert']('insert', | |
1305 '{db_prefix}board_permissions', | |
1306 array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string'), | |
1307 $boardInserts, | |
1308 array('id_profile', 'id_group') | |
1309 ); | |
1310 } | |
1311 // Setting profile permissions for a specific group. | |
1312 elseif ($profile !== 'null' && $group !== 'null' && ($profile == 1 || $profile > 4)) | |
1313 { | |
1314 $group = (int) $group; | |
1315 $profile = (int) $profile; | |
1316 | |
1317 if (!empty($groupLevels['global'][$level])) | |
1318 { | |
1319 $smcFunc['db_query']('', ' | |
1320 DELETE FROM {db_prefix}board_permissions | |
1321 WHERE id_group = {int:current_group} | |
1322 AND id_profile = {int:current_profile}', | |
1323 array( | |
1324 'current_group' => $group, | |
1325 'current_profile' => $profile, | |
1326 ) | |
1327 ); | |
1328 } | |
1329 | |
1330 if (!empty($groupLevels['board'][$level])) | |
1331 { | |
1332 $boardInserts = array(); | |
1333 foreach ($groupLevels['board'][$level] as $permission) | |
1334 $boardInserts[] = array($profile, $group, $permission); | |
1335 | |
1336 $smcFunc['db_insert']('insert', | |
1337 '{db_prefix}board_permissions', | |
1338 array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string'), | |
1339 $boardInserts, | |
1340 array('id_profile', 'id_group') | |
1341 ); | |
1342 } | |
1343 } | |
1344 // Setting profile permissions for all groups. | |
1345 elseif ($profile !== 'null' && $group === 'null' && ($profile == 1 || $profile > 4)) | |
1346 { | |
1347 $profile = (int) $profile; | |
1348 | |
1349 $smcFunc['db_query']('', ' | |
1350 DELETE FROM {db_prefix}board_permissions | |
1351 WHERE id_profile = {int:current_profile}', | |
1352 array( | |
1353 'current_profile' => $profile, | |
1354 ) | |
1355 ); | |
1356 | |
1357 if (empty($boardLevels[$level])) | |
1358 return; | |
1359 | |
1360 // Get all the groups... | |
1361 $query = $smcFunc['db_query']('', ' | |
1362 SELECT id_group | |
1363 FROM {db_prefix}membergroups | |
1364 WHERE id_group > {int:moderator_group} | |
1365 ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name', | |
1366 array( | |
1367 'moderator_group' => 3, | |
1368 'newbie_group' => 4, | |
1369 ) | |
1370 ); | |
1371 while ($row = $smcFunc['db_fetch_row']($query)) | |
1372 { | |
1373 $group = $row[0]; | |
1374 | |
1375 $boardInserts = array(); | |
1376 foreach ($boardLevels[$level] as $permission) | |
1377 $boardInserts[] = array($profile, $group, $permission); | |
1378 | |
1379 $smcFunc['db_insert']('insert', | |
1380 '{db_prefix}board_permissions', | |
1381 array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string'), | |
1382 $boardInserts, | |
1383 array('id_profile', 'id_group') | |
1384 ); | |
1385 } | |
1386 $smcFunc['db_free_result']($query); | |
1387 | |
1388 // Add permissions for ungrouped members. | |
1389 $boardInserts = array(); | |
1390 foreach ($boardLevels[$level] as $permission) | |
1391 $boardInserts[] = array($profile, 0, $permission); | |
1392 | |
1393 $smcFunc['db_insert']('insert', | |
1394 '{db_prefix}board_permissions', | |
1395 array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string'), | |
1396 $boardInserts, | |
1397 array('id_profile', 'id_group') | |
1398 ); | |
1399 } | |
1400 // $profile and $group are both null! | |
1401 else | |
1402 fatal_lang_error('no_access', false); | |
1403 } | |
1404 | |
1405 function loadAllPermissions($loadType = 'classic') | |
1406 { | |
1407 global $context, $txt, $modSettings; | |
1408 | |
1409 // List of all the groups dependant on the currently selected view - for the order so it looks pretty, yea? | |
1410 // Note to Mod authors - you don't need to stick your permission group here if you don't mind SMF sticking it the last group of the page. | |
1411 $permissionGroups = array( | |
1412 'membergroup' => array( | |
1413 'simple' => array( | |
1414 'view_basic_info', | |
1415 'use_pm_system', | |
1416 'post_calendar', | |
1417 'edit_profile', | |
1418 'delete_account', | |
1419 'use_avatar', | |
1420 'moderate_general', | |
1421 'administrate', | |
1422 ), | |
1423 'classic' => array( | |
1424 'general', | |
1425 'pm', | |
1426 'calendar', | |
1427 'maintenance', | |
1428 'member_admin', | |
1429 'profile', | |
1430 ), | |
1431 ), | |
1432 'board' => array( | |
1433 'simple' => array( | |
1434 'make_posts', | |
1435 'make_unapproved_posts', | |
1436 'post_polls', | |
1437 'participate', | |
1438 'modify', | |
1439 'notification', | |
1440 'attach', | |
1441 'moderate', | |
1442 ), | |
1443 'classic' => array( | |
1444 'general_board', | |
1445 'topic', | |
1446 'post', | |
1447 'poll', | |
1448 'notification', | |
1449 'attachment', | |
1450 ), | |
1451 ), | |
1452 ); | |
1453 | |
1454 /* The format of this list is as follows: | |
1455 'membergroup' => array( | |
1456 'permissions_inside' => array(has_multiple_options, classic_view_group, simple_view_group(_own)*, simple_view_group_any*), | |
1457 ), | |
1458 'board' => array( | |
1459 'permissions_inside' => array(has_multiple_options, classic_view_group, simple_view_group(_own)*, simple_view_group_any*), | |
1460 ); | |
1461 */ | |
1462 $permissionList = array( | |
1463 'membergroup' => array( | |
1464 'view_stats' => array(false, 'general', 'view_basic_info'), | |
1465 'view_mlist' => array(false, 'general', 'view_basic_info'), | |
1466 'who_view' => array(false, 'general', 'view_basic_info'), | |
1467 'search_posts' => array(false, 'general', 'view_basic_info'), | |
1468 'karma_edit' => array(false, 'general', 'moderate_general'), | |
1469 'pm_read' => array(false, 'pm', 'use_pm_system'), | |
1470 'pm_send' => array(false, 'pm', 'use_pm_system'), | |
1471 'calendar_view' => array(false, 'calendar', 'view_basic_info'), | |
1472 'calendar_post' => array(false, 'calendar', 'post_calendar'), | |
1473 'calendar_edit' => array(true, 'calendar', 'post_calendar', 'moderate_general'), | |
1474 'admin_forum' => array(false, 'maintenance', 'administrate'), | |
1475 'manage_boards' => array(false, 'maintenance', 'administrate'), | |
1476 'manage_attachments' => array(false, 'maintenance', 'administrate'), | |
1477 'manage_smileys' => array(false, 'maintenance', 'administrate'), | |
1478 'edit_news' => array(false, 'maintenance', 'administrate'), | |
1479 'access_mod_center' => array(false, 'maintenance', 'moderate_general'), | |
1480 'moderate_forum' => array(false, 'member_admin', 'moderate_general'), | |
1481 'manage_membergroups' => array(false, 'member_admin', 'administrate'), | |
1482 'manage_permissions' => array(false, 'member_admin', 'administrate'), | |
1483 'manage_bans' => array(false, 'member_admin', 'administrate'), | |
1484 'send_mail' => array(false, 'member_admin', 'administrate'), | |
1485 'issue_warning' => array(false, 'member_admin', 'moderate_general'), | |
1486 'profile_view' => array(true, 'profile', 'view_basic_info', 'view_basic_info'), | |
1487 'profile_identity' => array(true, 'profile', 'edit_profile', 'moderate_general'), | |
1488 'profile_extra' => array(true, 'profile', 'edit_profile', 'moderate_general'), | |
1489 'profile_title' => array(true, 'profile', 'edit_profile', 'moderate_general'), | |
1490 'profile_remove' => array(true, 'profile', 'delete_account', 'moderate_general'), | |
1491 'profile_server_avatar' => array(false, 'profile', 'use_avatar'), | |
1492 'profile_upload_avatar' => array(false, 'profile', 'use_avatar'), | |
1493 'profile_remote_avatar' => array(false, 'profile', 'use_avatar'), | |
1494 ), | |
1495 'board' => array( | |
1496 'moderate_board' => array(false, 'general_board', 'moderate'), | |
1497 'approve_posts' => array(false, 'general_board', 'moderate'), | |
1498 'post_new' => array(false, 'topic', 'make_posts'), | |
1499 'post_unapproved_topics' => array(false, 'topic', 'make_unapproved_posts'), | |
1500 'post_unapproved_replies' => array(true, 'topic', 'make_unapproved_posts', 'make_unapproved_posts'), | |
1501 'post_reply' => array(true, 'topic', 'make_posts', 'make_posts'), | |
1502 'merge_any' => array(false, 'topic', 'moderate'), | |
1503 'split_any' => array(false, 'topic', 'moderate'), | |
1504 'send_topic' => array(false, 'topic', 'moderate'), | |
1505 'make_sticky' => array(false, 'topic', 'moderate'), | |
1506 'move' => array(true, 'topic', 'moderate', 'moderate'), | |
1507 'lock' => array(true, 'topic', 'moderate', 'moderate'), | |
1508 'remove' => array(true, 'topic', 'modify', 'moderate'), | |
1509 'modify_replies' => array(false, 'topic', 'moderate'), | |
1510 'delete_replies' => array(false, 'topic', 'moderate'), | |
1511 'announce_topic' => array(false, 'topic', 'moderate'), | |
1512 'delete' => array(true, 'post', 'modify', 'moderate'), | |
1513 'modify' => array(true, 'post', 'modify', 'moderate'), | |
1514 'report_any' => array(false, 'post', 'participate'), | |
1515 'poll_view' => array(false, 'poll', 'participate'), | |
1516 'poll_vote' => array(false, 'poll', 'participate'), | |
1517 'poll_post' => array(false, 'poll', 'post_polls'), | |
1518 'poll_add' => array(true, 'poll', 'post_polls', 'moderate'), | |
1519 'poll_edit' => array(true, 'poll', 'modify', 'moderate'), | |
1520 'poll_lock' => array(true, 'poll', 'moderate', 'moderate'), | |
1521 'poll_remove' => array(true, 'poll', 'modify', 'moderate'), | |
1522 'mark_any_notify' => array(false, 'notification', 'notification'), | |
1523 'mark_notify' => array(false, 'notification', 'notification'), | |
1524 'view_attachments' => array(false, 'attachment', 'participate'), | |
1525 'post_unapproved_attachments' => array(false, 'attachment', 'make_unapproved_posts'), | |
1526 'post_attachment' => array(false, 'attachment', 'attach'), | |
1527 ), | |
1528 ); | |
1529 | |
1530 // All permission groups that will be shown in the left column on classic view. | |
1531 $leftPermissionGroups = array( | |
1532 'general', | |
1533 'calendar', | |
1534 'maintenance', | |
1535 'member_admin', | |
1536 'topic', | |
1537 'post', | |
1538 ); | |
1539 | |
1540 // We need to know what permissions we can't give to guests. | |
1541 loadIllegalGuestPermissions(); | |
1542 | |
1543 // Some permissions are hidden if features are off. | |
1544 $hiddenPermissions = array(); | |
1545 $relabelPermissions = array(); // Permissions to apply a different label to. | |
1546 $relabelGroups = array(); // As above but for groups. | |
1547 if (!in_array('cd', $context['admin_features'])) | |
1548 { | |
1549 $hiddenPermissions[] = 'calendar_view'; | |
1550 $hiddenPermissions[] = 'calendar_post'; | |
1551 $hiddenPermissions[] = 'calendar_edit'; | |
1552 } | |
1553 if (!in_array('w', $context['admin_features'])) | |
1554 $hiddenPermissions[] = 'issue_warning'; | |
1555 | |
1556 // Post moderation? | |
1557 if (!$modSettings['postmod_active']) | |
1558 { | |
1559 $hiddenPermissions[] = 'approve_posts'; | |
1560 $hiddenPermissions[] = 'post_unapproved_topics'; | |
1561 $hiddenPermissions[] = 'post_unapproved_replies'; | |
1562 $hiddenPermissions[] = 'post_unapproved_attachments'; | |
1563 } | |
1564 // If we show them on classic view we change the name. | |
1565 else | |
1566 { | |
1567 // Relabel the topics permissions | |
1568 $relabelPermissions['post_new'] = 'auto_approve_topics'; | |
1569 | |
1570 // Relabel the reply permissions | |
1571 $relabelPermissions['post_reply'] = 'auto_approve_replies'; | |
1572 | |
1573 // Relabel the attachment permissions | |
1574 $relabelPermissions['post_attachment'] = 'auto_approve_attachments'; | |
1575 } | |
1576 | |
1577 // Provide a practical way to modify permissions. | |
1578 call_integration_hook('integrate_load_permissions', array(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)); | |
1579 | |
1580 $context['permissions'] = array(); | |
1581 $context['hidden_permissions'] = array(); | |
1582 foreach ($permissionList as $permissionType => $permissionList) | |
1583 { | |
1584 $context['permissions'][$permissionType] = array( | |
1585 'id' => $permissionType, | |
1586 'view' => $loadType, | |
1587 'columns' => array() | |
1588 ); | |
1589 foreach ($permissionList as $permission => $permissionArray) | |
1590 { | |
1591 // If this is a guest permission we don't do it if it's the guest group. | |
1592 if (isset($context['group']['id']) && $context['group']['id'] == -1 && in_array($permission, $context['non_guest_permissions'])) | |
1593 continue; | |
1594 | |
1595 // What groups will this permission be in? | |
1596 $own_group = $permissionArray[($loadType == 'classic' ? 1 : 2)]; | |
1597 $any_group = $loadType == 'simple' && !empty($permissionArray[3]) ? $permissionArray[3] : ($loadType == 'simple' && $permissionArray[0] ? $permissionArray[2] : ''); | |
1598 | |
1599 // First, Do these groups actually exist - if not add them. | |
1600 if (!isset($permissionGroups[$permissionType][$loadType][$own_group])) | |
1601 $permissionGroups[$permissionType][$loadType][$own_group] = true; | |
1602 if (!empty($any_group) && !isset($permissionGroups[$permissionType][$loadType][$any_group])) | |
1603 $permissionGroups[$permissionType][$loadType][$any_group] = true; | |
1604 | |
1605 // What column should this be located into? | |
1606 $position = $loadType == 'classic' && !in_array($own_group, $leftPermissionGroups) ? 1 : 0; | |
1607 | |
1608 // If the groups have not yet been created be sure to create them. | |
1609 $bothGroups = array('own' => $own_group); | |
1610 $bothGroups = array(); | |
1611 | |
1612 // For guests, just reset the array. | |
1613 if (!isset($context['group']['id']) || !($context['group']['id'] == -1 && $any_group)) | |
1614 $bothGroups['own'] = $own_group; | |
1615 | |
1616 if ($any_group) | |
1617 { | |
1618 $bothGroups['any'] = $any_group; | |
1619 | |
1620 } | |
1621 | |
1622 foreach ($bothGroups as $group) | |
1623 if (!isset($context['permissions'][$permissionType]['columns'][$position][$group])) | |
1624 $context['permissions'][$permissionType]['columns'][$position][$group] = array( | |
1625 'type' => $permissionType, | |
1626 'id' => $group, | |
1627 'name' => $loadType == 'simple' ? (isset($txt['permissiongroup_simple_' . $group]) ? $txt['permissiongroup_simple_' . $group] : '') : $txt['permissiongroup_' . $group], | |
1628 'icon' => isset($txt['permissionicon_' . $group]) ? $txt['permissionicon_' . $group] : $txt['permissionicon'], | |
1629 'help' => isset($txt['permissionhelp_' . $group]) ? $txt['permissionhelp_' . $group] : '', | |
1630 'hidden' => false, | |
1631 'permissions' => array() | |
1632 ); | |
1633 | |
1634 // This is where we set up the permission dependant on the view. | |
1635 if ($loadType == 'classic') | |
1636 { | |
1637 $context['permissions'][$permissionType]['columns'][$position][$own_group]['permissions'][$permission] = array( | |
1638 'id' => $permission, | |
1639 'name' => !isset($relabelPermissions[$permission]) ? $txt['permissionname_' . $permission] : $txt[$relabelPermissions[$permission]], | |
1640 'show_help' => isset($txt['permissionhelp_' . $permission]), | |
1641 'note' => isset($txt['permissionnote_' . $permission]) ? $txt['permissionnote_' . $permission] : '', | |
1642 'has_own_any' => $permissionArray[0], | |
1643 'own' => array( | |
1644 'id' => $permission . '_own', | |
1645 'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_own'] : '' | |
1646 ), | |
1647 'any' => array( | |
1648 'id' => $permission . '_any', | |
1649 'name' => $permissionArray[0] ? $txt['permissionname_' . $permission . '_any'] : '' | |
1650 ), | |
1651 'hidden' => in_array($permission, $hiddenPermissions), | |
1652 ); | |
1653 } | |
1654 else | |
1655 { | |
1656 foreach ($bothGroups as $group_type => $group) | |
1657 { | |
1658 $context['permissions'][$permissionType]['columns'][$position][$group]['permissions'][$permission . ($permissionArray[0] ? '_' . $group_type : '')] = array( | |
1659 'id' => $permission . ($permissionArray[0] ? '_' . $group_type : ''), | |
1660 'name' => isset($txt['permissionname_simple_' . $permission . ($permissionArray[0] ? '_' . $group_type : '')]) ? $txt['permissionname_simple_' . $permission . ($permissionArray[0] ? '_' . $group_type : '')] : $txt['permissionname_' . $permission], | |
1661 'help_index' => isset($txt['permissionhelp_' . $permission]) ? 'permissionhelp_' . $permission : '', | |
1662 'hidden' => in_array($permission, $hiddenPermissions), | |
1663 ); | |
1664 } | |
1665 } | |
1666 | |
1667 if (in_array($permission, $hiddenPermissions)) | |
1668 { | |
1669 if ($permissionArray[0]) | |
1670 { | |
1671 $context['hidden_permissions'][] = $permission . '_own'; | |
1672 $context['hidden_permissions'][] = $permission . '_any'; | |
1673 } | |
1674 else | |
1675 $context['hidden_permissions'][] = $permission; | |
1676 } | |
1677 } | |
1678 ksort($context['permissions'][$permissionType]['columns']); | |
1679 } | |
1680 | |
1681 // Check we don't leave any empty groups - and mark hidden ones as such. | |
1682 foreach ($context['permissions'][$permissionType]['columns'] as $column => $groups) | |
1683 foreach ($groups as $id => $group) | |
1684 { | |
1685 if (empty($group['permissions'])) | |
1686 unset($context['permissions'][$permissionType]['columns'][$column][$id]); | |
1687 else | |
1688 { | |
1689 $foundNonHidden = false; | |
1690 foreach ($group['permissions'] as $permission) | |
1691 if (empty($permission['hidden'])) | |
1692 $foundNonHidden = true; | |
1693 if (!$foundNonHidden) | |
1694 $context['permissions'][$permissionType]['columns'][$column][$id]['hidden'] = true; | |
1695 } | |
1696 } | |
1697 } | |
1698 | |
1699 // Initialize a form with inline permissions. | |
1700 function init_inline_permissions($permissions, $excluded_groups = array()) | |
1701 { | |
1702 global $context, $txt, $modSettings, $smcFunc; | |
1703 | |
1704 loadLanguage('ManagePermissions'); | |
1705 loadTemplate('ManagePermissions'); | |
1706 $context['can_change_permissions'] = allowedTo('manage_permissions'); | |
1707 | |
1708 // Nothing to initialize here. | |
1709 if (!$context['can_change_permissions']) | |
1710 return; | |
1711 | |
1712 // Load the permission settings for guests | |
1713 foreach ($permissions as $permission) | |
1714 $context[$permission] = array( | |
1715 -1 => array( | |
1716 'id' => -1, | |
1717 'name' => $txt['membergroups_guests'], | |
1718 'is_postgroup' => false, | |
1719 'status' => 'off', | |
1720 ), | |
1721 0 => array( | |
1722 'id' => 0, | |
1723 'name' => $txt['membergroups_members'], | |
1724 'is_postgroup' => false, | |
1725 'status' => 'off', | |
1726 ), | |
1727 ); | |
1728 | |
1729 $request = $smcFunc['db_query']('', ' | |
1730 SELECT id_group, CASE WHEN add_deny = {int:denied} THEN {string:deny} ELSE {string:on} END AS status, permission | |
1731 FROM {db_prefix}permissions | |
1732 WHERE id_group IN (-1, 0) | |
1733 AND permission IN ({array_string:permissions})', | |
1734 array( | |
1735 'denied' => 0, | |
1736 'permissions' => $permissions, | |
1737 'deny' => 'deny', | |
1738 'on' => 'on', | |
1739 ) | |
1740 ); | |
1741 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
1742 $context[$row['permission']][$row['id_group']]['status'] = $row['status']; | |
1743 $smcFunc['db_free_result']($request); | |
1744 | |
1745 $request = $smcFunc['db_query']('', ' | |
1746 SELECT mg.id_group, mg.group_name, mg.min_posts, IFNULL(p.add_deny, -1) AS status, p.permission | |
1747 FROM {db_prefix}membergroups AS mg | |
1748 LEFT JOIN {db_prefix}permissions AS p ON (p.id_group = mg.id_group AND p.permission IN ({array_string:permissions})) | |
1749 WHERE mg.id_group NOT IN (1, 3) | |
1750 AND mg.id_parent = {int:not_inherited}' . (empty($modSettings['permission_enable_postgroups']) ? ' | |
1751 AND mg.min_posts = {int:min_posts}' : '') . ' | |
1752 ORDER BY mg.min_posts, CASE WHEN mg.id_group < {int:newbie_group} THEN mg.id_group ELSE 4 END, mg.group_name', | |
1753 array( | |
1754 'not_inherited' => -2, | |
1755 'min_posts' => -1, | |
1756 'newbie_group' => 4, | |
1757 'permissions' => $permissions, | |
1758 ) | |
1759 ); | |
1760 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
1761 { | |
1762 // Initialize each permission as being 'off' until proven otherwise. | |
1763 foreach ($permissions as $permission) | |
1764 if (!isset($context[$permission][$row['id_group']])) | |
1765 $context[$permission][$row['id_group']] = array( | |
1766 'id' => $row['id_group'], | |
1767 'name' => $row['group_name'], | |
1768 'is_postgroup' => $row['min_posts'] != -1, | |
1769 'status' => 'off', | |
1770 ); | |
1771 | |
1772 $context[$row['permission']][$row['id_group']]['status'] = empty($row['status']) ? 'deny' : ($row['status'] == 1 ? 'on' : 'off'); | |
1773 } | |
1774 $smcFunc['db_free_result']($request); | |
1775 | |
1776 // Some permissions cannot be given to certain groups. Remove the groups. | |
1777 foreach ($excluded_groups as $group) | |
1778 { | |
1779 foreach ($permissions as $permission) | |
1780 { | |
1781 if (isset($context[$permission][$group])) | |
1782 unset($context[$permission][$group]); | |
1783 } | |
1784 } | |
1785 } | |
1786 | |
1787 // Show a collapsible box to set a specific permission. | |
1788 function theme_inline_permissions($permission) | |
1789 { | |
1790 global $context; | |
1791 | |
1792 $context['current_permission'] = $permission; | |
1793 $context['member_groups'] = $context[$permission]; | |
1794 | |
1795 template_inline_permissions(); | |
1796 } | |
1797 | |
1798 // Save the permissions of a form containing inline permissions. | |
1799 function save_inline_permissions($permissions) | |
1800 { | |
1801 global $context, $smcFunc; | |
1802 | |
1803 // No permissions? Not a great deal to do here. | |
1804 if (!allowedTo('manage_permissions')) | |
1805 return; | |
1806 | |
1807 // Almighty session check, verify our ways. | |
1808 checkSession(); | |
1809 | |
1810 // Check they can't do certain things. | |
1811 loadIllegalPermissions(); | |
1812 | |
1813 $insertRows = array(); | |
1814 foreach ($permissions as $permission) | |
1815 { | |
1816 if (!isset($_POST[$permission])) | |
1817 continue; | |
1818 | |
1819 foreach ($_POST[$permission] as $id_group => $value) | |
1820 { | |
1821 if (in_array($value, array('on', 'deny')) && (empty($context['illegal_permissions']) || !in_array($permission, $context['illegal_permissions']))) | |
1822 $insertRows[] = array((int) $id_group, $permission, $value == 'on' ? 1 : 0); | |
1823 } | |
1824 } | |
1825 | |
1826 // Remove the old permissions... | |
1827 $smcFunc['db_query']('', ' | |
1828 DELETE FROM {db_prefix}permissions | |
1829 WHERE permission IN ({array_string:permissions}) | |
1830 ' . (empty($context['illegal_permissions']) ? '' : ' AND permission NOT IN ({array_string:illegal_permissions})'), | |
1831 array( | |
1832 'illegal_permissions' => !empty($context['illegal_permissions']) ? $context['illegal_permissions'] : array(), | |
1833 'permissions' => $permissions, | |
1834 ) | |
1835 ); | |
1836 | |
1837 // ...and replace them with new ones. | |
1838 if (!empty($insertRows)) | |
1839 $smcFunc['db_insert']('insert', | |
1840 '{db_prefix}permissions', | |
1841 array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), | |
1842 $insertRows, | |
1843 array('id_group', 'permission') | |
1844 ); | |
1845 | |
1846 // Do a full child update. | |
1847 updateChildPermissions(array(), -1); | |
1848 | |
1849 // Just in case we cached this. | |
1850 updateSettings(array('settings_updated' => time())); | |
1851 } | |
1852 | |
1853 function loadPermissionProfiles() | |
1854 { | |
1855 global $context, $txt, $smcFunc; | |
1856 | |
1857 $request = $smcFunc['db_query']('', ' | |
1858 SELECT id_profile, profile_name | |
1859 FROM {db_prefix}permission_profiles | |
1860 ORDER BY id_profile', | |
1861 array( | |
1862 ) | |
1863 ); | |
1864 $context['profiles'] = array(); | |
1865 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
1866 { | |
1867 // Format the label nicely. | |
1868 if (isset($txt['permissions_profile_' . $row['profile_name']])) | |
1869 $name = $txt['permissions_profile_' . $row['profile_name']]; | |
1870 else | |
1871 $name = $row['profile_name']; | |
1872 | |
1873 $context['profiles'][$row['id_profile']] = array( | |
1874 'id' => $row['id_profile'], | |
1875 'name' => $name, | |
1876 'can_modify' => $row['id_profile'] == 1 || $row['id_profile'] > 4, | |
1877 'unformatted_name' => $row['profile_name'], | |
1878 ); | |
1879 } | |
1880 $smcFunc['db_free_result']($request); | |
1881 } | |
1882 | |
1883 // Add/Edit/Delete profiles. | |
1884 function EditPermissionProfiles() | |
1885 { | |
1886 global $context, $txt, $smcFunc; | |
1887 | |
1888 // Setup the template, first for fun. | |
1889 $context['page_title'] = $txt['permissions_profile_edit']; | |
1890 $context['sub_template'] = 'edit_profiles'; | |
1891 | |
1892 // If we're creating a new one do it first. | |
1893 if (isset($_POST['create']) && trim($_POST['profile_name']) != '') | |
1894 { | |
1895 checkSession(); | |
1896 | |
1897 $_POST['copy_from'] = (int) $_POST['copy_from']; | |
1898 $_POST['profile_name'] = $smcFunc['htmlspecialchars']($_POST['profile_name']); | |
1899 | |
1900 // Insert the profile itself. | |
1901 $smcFunc['db_insert']('', | |
1902 '{db_prefix}permission_profiles', | |
1903 array( | |
1904 'profile_name' => 'string', | |
1905 ), | |
1906 array( | |
1907 $_POST['profile_name'], | |
1908 ), | |
1909 array('id_profile') | |
1910 ); | |
1911 $profile_id = $smcFunc['db_insert_id']('{db_prefix}permission_profiles', 'id_profile'); | |
1912 | |
1913 // Load the permissions from the one it's being copied from. | |
1914 $request = $smcFunc['db_query']('', ' | |
1915 SELECT id_group, permission, add_deny | |
1916 FROM {db_prefix}board_permissions | |
1917 WHERE id_profile = {int:copy_from}', | |
1918 array( | |
1919 'copy_from' => $_POST['copy_from'], | |
1920 ) | |
1921 ); | |
1922 $inserts = array(); | |
1923 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
1924 $inserts[] = array($profile_id, $row['id_group'], $row['permission'], $row['add_deny']); | |
1925 $smcFunc['db_free_result']($request); | |
1926 | |
1927 if (!empty($inserts)) | |
1928 $smcFunc['db_insert']('insert', | |
1929 '{db_prefix}board_permissions', | |
1930 array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), | |
1931 $inserts, | |
1932 array('id_profile', 'id_group', 'permission') | |
1933 ); | |
1934 } | |
1935 // Renaming? | |
1936 elseif (isset($_POST['rename'])) | |
1937 { | |
1938 checkSession(); | |
1939 | |
1940 // Just showing the boxes? | |
1941 if (!isset($_POST['rename_profile'])) | |
1942 $context['show_rename_boxes'] = true; | |
1943 else | |
1944 { | |
1945 foreach ($_POST['rename_profile'] as $id => $value) | |
1946 { | |
1947 $value = $smcFunc['htmlspecialchars']($value); | |
1948 | |
1949 if (trim($value) != '' && $id > 4) | |
1950 $smcFunc['db_query']('', ' | |
1951 UPDATE {db_prefix}permission_profiles | |
1952 SET profile_name = {string:profile_name} | |
1953 WHERE id_profile = {int:current_profile}', | |
1954 array( | |
1955 'current_profile' => (int) $id, | |
1956 'profile_name' => $value, | |
1957 ) | |
1958 ); | |
1959 } | |
1960 } | |
1961 } | |
1962 // Deleting? | |
1963 elseif (isset($_POST['delete']) && !empty($_POST['delete_profile'])) | |
1964 { | |
1965 checkSession('post'); | |
1966 | |
1967 $profiles = array(); | |
1968 foreach ($_POST['delete_profile'] as $profile) | |
1969 if ($profile > 4) | |
1970 $profiles[] = (int) $profile; | |
1971 | |
1972 // Verify it's not in use... | |
1973 $request = $smcFunc['db_query']('', ' | |
1974 SELECT id_board | |
1975 FROM {db_prefix}boards | |
1976 WHERE id_profile IN ({array_int:profile_list}) | |
1977 LIMIT 1', | |
1978 array( | |
1979 'profile_list' => $profiles, | |
1980 ) | |
1981 ); | |
1982 if ($smcFunc['db_num_rows']($request) != 0) | |
1983 fatal_lang_error('no_access', false); | |
1984 $smcFunc['db_free_result']($request); | |
1985 | |
1986 // Oh well, delete. | |
1987 $smcFunc['db_query']('', ' | |
1988 DELETE FROM {db_prefix}permission_profiles | |
1989 WHERE id_profile IN ({array_int:profile_list})', | |
1990 array( | |
1991 'profile_list' => $profiles, | |
1992 ) | |
1993 ); | |
1994 } | |
1995 | |
1996 // Clearly, we'll need this! | |
1997 loadPermissionProfiles(); | |
1998 | |
1999 // Work out what ones are in use. | |
2000 $request = $smcFunc['db_query']('', ' | |
2001 SELECT id_profile, COUNT(id_board) AS board_count | |
2002 FROM {db_prefix}boards | |
2003 GROUP BY id_profile', | |
2004 array( | |
2005 ) | |
2006 ); | |
2007 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
2008 if (isset($context['profiles'][$row['id_profile']])) | |
2009 { | |
2010 $context['profiles'][$row['id_profile']]['in_use'] = true; | |
2011 $context['profiles'][$row['id_profile']]['boards'] = $row['board_count']; | |
2012 $context['profiles'][$row['id_profile']]['boards_text'] = $row['board_count'] > 1 ? sprintf($txt['permissions_profile_used_by_many'], $row['board_count']) : $txt['permissions_profile_used_by_' . ($row['board_count'] ? 'one' : 'none')]; | |
2013 } | |
2014 $smcFunc['db_free_result']($request); | |
2015 | |
2016 // What can we do with these? | |
2017 $context['can_edit_something'] = false; | |
2018 foreach ($context['profiles'] as $id => $profile) | |
2019 { | |
2020 // Can't delete special ones. | |
2021 $context['profiles'][$id]['can_edit'] = isset($txt['permissions_profile_' . $profile['unformatted_name']]) ? false : true; | |
2022 if ($context['profiles'][$id]['can_edit']) | |
2023 $context['can_edit_something'] = true; | |
2024 | |
2025 // You can only delete it if you can edit it AND it's not in use. | |
2026 $context['profiles'][$id]['can_delete'] = $context['profiles'][$id]['can_edit'] && empty($profile['in_use']) ? true : false; | |
2027 } | |
2028 } | |
2029 | |
2030 // This function updates the permissions of any groups based off this group. | |
2031 function updateChildPermissions($parents, $profile = null) | |
2032 { | |
2033 global $smcFunc; | |
2034 | |
2035 // All the parent groups to sort out. | |
2036 if (!is_array($parents)) | |
2037 $parents = array($parents); | |
2038 | |
2039 // Find all the children of this group. | |
2040 $request = $smcFunc['db_query']('', ' | |
2041 SELECT id_parent, id_group | |
2042 FROM {db_prefix}membergroups | |
2043 WHERE id_parent != {int:not_inherited} | |
2044 ' . (empty($parents) ? '' : 'AND id_parent IN ({array_int:parent_list})'), | |
2045 array( | |
2046 'parent_list' => $parents, | |
2047 'not_inherited' => -2, | |
2048 ) | |
2049 ); | |
2050 $children = array(); | |
2051 $parents = array(); | |
2052 $child_groups = array(); | |
2053 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
2054 { | |
2055 $children[$row['id_parent']][] = $row['id_group']; | |
2056 $child_groups[] = $row['id_group']; | |
2057 $parents[] = $row['id_parent']; | |
2058 } | |
2059 $smcFunc['db_free_result']($request); | |
2060 | |
2061 $parents = array_unique($parents); | |
2062 | |
2063 // Not a sausage, or a child? | |
2064 if (empty($children)) | |
2065 return false; | |
2066 | |
2067 // First off, are we doing general permissions? | |
2068 if ($profile < 1 || $profile === null) | |
2069 { | |
2070 // Fetch all the parent permissions. | |
2071 $request = $smcFunc['db_query']('', ' | |
2072 SELECT id_group, permission, add_deny | |
2073 FROM {db_prefix}permissions | |
2074 WHERE id_group IN ({array_int:parent_list})', | |
2075 array( | |
2076 'parent_list' => $parents, | |
2077 ) | |
2078 ); | |
2079 $permissions = array(); | |
2080 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
2081 foreach ($children[$row['id_group']] as $child) | |
2082 $permissions[] = array($child, $row['permission'], $row['add_deny']); | |
2083 $smcFunc['db_free_result']($request); | |
2084 | |
2085 $smcFunc['db_query']('', ' | |
2086 DELETE FROM {db_prefix}permissions | |
2087 WHERE id_group IN ({array_int:child_groups})', | |
2088 array( | |
2089 'child_groups' => $child_groups, | |
2090 ) | |
2091 ); | |
2092 | |
2093 // Finally insert. | |
2094 if (!empty($permissions)) | |
2095 { | |
2096 $smcFunc['db_insert']('insert', | |
2097 '{db_prefix}permissions', | |
2098 array('id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), | |
2099 $permissions, | |
2100 array('id_group', 'permission') | |
2101 ); | |
2102 } | |
2103 } | |
2104 | |
2105 // Then, what about board profiles? | |
2106 if ($profile != -1) | |
2107 { | |
2108 $profileQuery = $profile === null ? '' : ' AND id_profile = {int:current_profile}'; | |
2109 | |
2110 // Again, get all the parent permissions. | |
2111 $request = $smcFunc['db_query']('', ' | |
2112 SELECT id_profile, id_group, permission, add_deny | |
2113 FROM {db_prefix}board_permissions | |
2114 WHERE id_group IN ({array_int:parent_groups}) | |
2115 ' . $profileQuery, | |
2116 array( | |
2117 'parent_groups' => $parents, | |
2118 'current_profile' => $profile !== null && $profile ? $profile : 1, | |
2119 ) | |
2120 ); | |
2121 $permissions = array(); | |
2122 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
2123 foreach ($children[$row['id_group']] as $child) | |
2124 $permissions[] = array($child, $row['id_profile'], $row['permission'], $row['add_deny']); | |
2125 $smcFunc['db_free_result']($request); | |
2126 | |
2127 $smcFunc['db_query']('', ' | |
2128 DELETE FROM {db_prefix}board_permissions | |
2129 WHERE id_group IN ({array_int:child_groups}) | |
2130 ' . $profileQuery, | |
2131 array( | |
2132 'child_groups' => $child_groups, | |
2133 'current_profile' => $profile !== null && $profile ? $profile : 1, | |
2134 ) | |
2135 ); | |
2136 | |
2137 // Do the insert. | |
2138 if (!empty($permissions)) | |
2139 { | |
2140 $smcFunc['db_insert']('insert', | |
2141 '{db_prefix}board_permissions', | |
2142 array('id_group' => 'int', 'id_profile' => 'int', 'permission' => 'string', 'add_deny' => 'int'), | |
2143 $permissions, | |
2144 array('id_group', 'id_profile', 'permission') | |
2145 ); | |
2146 } | |
2147 } | |
2148 } | |
2149 | |
2150 // Load permissions someone cannot grant. | |
2151 function loadIllegalPermissions() | |
2152 { | |
2153 global $context; | |
2154 | |
2155 $context['illegal_permissions'] = array(); | |
2156 if (!allowedTo('admin_forum')) | |
2157 $context['illegal_permissions'][] = 'admin_forum'; | |
2158 if (!allowedTo('manage_membergroups')) | |
2159 $context['illegal_permissions'][] = 'manage_membergroups'; | |
2160 if (!allowedTo('manage_permissions')) | |
2161 $context['illegal_permissions'][] = 'manage_permissions'; | |
2162 } | |
2163 | |
2164 // Load all the permissions that can not be given to guests. | |
2165 function loadIllegalGuestPermissions() | |
2166 { | |
2167 global $context; | |
2168 | |
2169 $context['non_guest_permissions'] = array( | |
2170 'delete_replies', | |
2171 'karma_edit', | |
2172 'poll_add_own', | |
2173 'pm_read', | |
2174 'pm_send', | |
2175 'profile_identity', | |
2176 'profile_extra', | |
2177 'profile_title', | |
2178 'profile_remove', | |
2179 'profile_server_avatar', | |
2180 'profile_upload_avatar', | |
2181 'profile_remote_avatar', | |
2182 'profile_view_own', | |
2183 'mark_any_notify', | |
2184 'mark_notify', | |
2185 'admin_forum', | |
2186 'manage_boards', | |
2187 'manage_attachments', | |
2188 'manage_smileys', | |
2189 'edit_news', | |
2190 'access_mod_center', | |
2191 'moderate_forum', | |
2192 'issue_warning', | |
2193 'manage_membergroups', | |
2194 'manage_permissions', | |
2195 'manage_bans', | |
2196 'move_own', | |
2197 'modify_replies', | |
2198 'send_mail', | |
2199 'approve_posts', | |
2200 ); | |
2201 } | |
2202 | |
2203 // Present a nice way of applying post moderation. | |
2204 function ModifyPostModeration() | |
2205 { | |
2206 global $context, $txt, $smcFunc, $modSettings; | |
2207 | |
2208 // Just in case. | |
2209 checkSession('get'); | |
2210 | |
2211 $context['page_title'] = $txt['permissions_post_moderation']; | |
2212 $context['sub_template'] = 'postmod_permissions'; | |
2213 $context['current_profile'] = isset($_REQUEST['pid']) ? (int) $_REQUEST['pid'] : 1; | |
2214 | |
2215 // Load all the permission profiles. | |
2216 loadPermissionProfiles(); | |
2217 | |
2218 // Mappings, our key => array(can_do_moderated, can_do_all) | |
2219 $mappings = array( | |
2220 'new_topic' => array('post_new', 'post_unapproved_topics'), | |
2221 'replies_own' => array('post_reply_own', 'post_unapproved_replies_own'), | |
2222 'replies_any' => array('post_reply_any', 'post_unapproved_replies_any'), | |
2223 'attachment' => array('post_attachment', 'post_unapproved_attachments'), | |
2224 ); | |
2225 | |
2226 // Start this with the guests/members. | |
2227 $context['profile_groups'] = array( | |
2228 -1 => array( | |
2229 'id' => -1, | |
2230 'name' => $txt['membergroups_guests'], | |
2231 'color' => '', | |
2232 'new_topic' => 'disallow', | |
2233 'replies_own' => 'disallow', | |
2234 'replies_any' => 'disallow', | |
2235 'attachment' => 'disallow', | |
2236 'children' => array(), | |
2237 ), | |
2238 0 => array( | |
2239 'id' => 0, | |
2240 'name' => $txt['membergroups_members'], | |
2241 'color' => '', | |
2242 'new_topic' => 'disallow', | |
2243 'replies_own' => 'disallow', | |
2244 'replies_any' => 'disallow', | |
2245 'attachment' => 'disallow', | |
2246 'children' => array(), | |
2247 ), | |
2248 ); | |
2249 | |
2250 // Load the groups. | |
2251 $request = $smcFunc['db_query']('', ' | |
2252 SELECT id_group, group_name, online_color, id_parent | |
2253 FROM {db_prefix}membergroups | |
2254 WHERE id_group != {int:admin_group} | |
2255 ' . (empty($modSettings['permission_enable_postgroups']) ? ' AND min_posts = {int:min_posts}' : '') . ' | |
2256 ORDER BY id_parent ASC', | |
2257 array( | |
2258 'admin_group' => 1, | |
2259 'min_posts' => -1, | |
2260 ) | |
2261 ); | |
2262 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
2263 { | |
2264 if ($row['id_parent'] == -2) | |
2265 { | |
2266 $context['profile_groups'][$row['id_group']] = array( | |
2267 'id' => $row['id_group'], | |
2268 'name' => $row['group_name'], | |
2269 'color' => $row['online_color'], | |
2270 'new_topic' => 'disallow', | |
2271 'replies_own' => 'disallow', | |
2272 'replies_any' => 'disallow', | |
2273 'attachment' => 'disallow', | |
2274 'children' => array(), | |
2275 ); | |
2276 } | |
2277 elseif (isset($context['profile_groups'][$row['id_parent']])) | |
2278 $context['profile_groups'][$row['id_parent']]['children'][] = $row['group_name']; | |
2279 } | |
2280 $smcFunc['db_free_result']($request); | |
2281 | |
2282 // What are the permissions we are querying? | |
2283 $all_permissions = array(); | |
2284 foreach ($mappings as $perm_set) | |
2285 $all_permissions = array_merge($all_permissions, $perm_set); | |
2286 | |
2287 // If we're saving the changes then do just that - save them. | |
2288 if (!empty($_POST['save_changes']) && ($context['current_profile'] == 1 || $context['current_profile'] > 4)) | |
2289 { | |
2290 // Start by deleting all the permissions relevant. | |
2291 $smcFunc['db_query']('', ' | |
2292 DELETE FROM {db_prefix}board_permissions | |
2293 WHERE id_profile = {int:current_profile} | |
2294 AND permission IN ({array_string:permissions}) | |
2295 AND id_group IN ({array_int:profile_group_list})', | |
2296 array( | |
2297 'profile_group_list' => array_keys($context['profile_groups']), | |
2298 'current_profile' => $context['current_profile'], | |
2299 'permissions' => $all_permissions, | |
2300 ) | |
2301 ); | |
2302 | |
2303 // Do it group by group. | |
2304 $new_permissions = array(); | |
2305 foreach ($context['profile_groups'] as $id => $group) | |
2306 { | |
2307 foreach ($mappings as $index => $data) | |
2308 { | |
2309 if (isset($_POST[$index][$group['id']])) | |
2310 { | |
2311 if ($_POST[$index][$group['id']] == 'allow') | |
2312 { | |
2313 // Give them both sets for fun. | |
2314 $new_permissions[] = array($context['current_profile'], $group['id'], $data[0], 1); | |
2315 $new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1); | |
2316 } | |
2317 elseif ($_POST[$index][$group['id']] == 'moderate') | |
2318 $new_permissions[] = array($context['current_profile'], $group['id'], $data[1], 1); | |
2319 } | |
2320 } | |
2321 } | |
2322 | |
2323 // Insert new permissions. | |
2324 if (!empty($new_permissions)) | |
2325 $smcFunc['db_insert']('', | |
2326 '{db_prefix}board_permissions', | |
2327 array('id_profile' => 'int', 'id_group' => 'int', 'permission' => 'string', 'add_deny' => 'int'), | |
2328 $new_permissions, | |
2329 array('id_profile', 'id_group', 'permission') | |
2330 ); | |
2331 } | |
2332 | |
2333 // Now get all the permissions! | |
2334 $request = $smcFunc['db_query']('', ' | |
2335 SELECT id_group, permission, add_deny | |
2336 FROM {db_prefix}board_permissions | |
2337 WHERE id_profile = {int:current_profile} | |
2338 AND permission IN ({array_string:permissions}) | |
2339 AND id_group IN ({array_int:profile_group_list})', | |
2340 array( | |
2341 'profile_group_list' => array_keys($context['profile_groups']), | |
2342 'current_profile' => $context['current_profile'], | |
2343 'permissions' => $all_permissions, | |
2344 ) | |
2345 ); | |
2346 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
2347 { | |
2348 foreach ($mappings as $key => $data) | |
2349 { | |
2350 foreach ($data as $index => $perm) | |
2351 { | |
2352 if ($perm == $row['permission']) | |
2353 { | |
2354 // Only bother if it's not denied. | |
2355 if ($row['add_deny']) | |
2356 { | |
2357 // Full allowance? | |
2358 if ($index == 0) | |
2359 $context['profile_groups'][$row['id_group']][$key] = 'allow'; | |
2360 // Otherwise only bother with moderate if not on allow. | |
2361 elseif ($context['profile_groups'][$row['id_group']][$key] != 'allow') | |
2362 $context['profile_groups'][$row['id_group']][$key] = 'moderate'; | |
2363 } | |
2364 } | |
2365 } | |
2366 } | |
2367 } | |
2368 $smcFunc['db_free_result']($request); | |
2369 } | |
2370 | |
2371 ?> |