XOOPS  2.6.0
groupperm.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
21 // Include XOOPS control panel header
22 include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
23 
25 $xoops->loadLocale('system');
26 
27 $modid = isset($_POST['modid']) ? intval($_POST['modid']) : 0;
28 
29 // we dont want system module permissions to be changed here
30 if ($modid <= 1 || !$xoops->isUser() || !$xoops->user->isAdmin($modid)) {
31  $xoops->redirect($xoops->url('index.php'), 1, XoopsLocale::E_NO_ACCESS_PERMISSION);
32 }
33 $module = $xoops->getModuleById($modid);
34 if (!is_object($module) || !$module->getVar('isactive')) {
35  $xoops->redirect($xoops->url('admin.php'), 1, XoopsLocale::E_NO_MODULE);
36 }
37 
38 $msg = array();
39 
40 $member_handler = $xoops->getHandlerMember();
41 $group_list = $member_handler->getGroupList();
42 if (is_array($_POST['perms']) && !empty($_POST['perms'])) {
43  $gperm_handler = $xoops->getHandlerGroupperm();
44  foreach ($_POST['perms'] as $perm_name => $perm_data) {
45  if (!$xoops->security()->check(true, false, $perm_name)) {
46  continue;
47  }
48  if (false == $gperm_handler->deleteByModule($modid, $perm_name)) {
49  $msg[] = sprintf(SystemLocale::EF_COULD_NOT_RESET_GROUP_PERMISSION_FOR_MODULE, $module->getVar('name') . '(' . $perm_name . ')');
50  }
51  if (!array_key_exists('groups', $perm_data)){
52  $msg[] = sprintf(SystemLocale::SF_ADDED_PERMISSION_FOR_GROUP, $module->getVar('name'), $perm_name, ' /');
53  }else{
54  foreach ($perm_data['groups'] as $group_id => $item_ids) {
55  foreach ($item_ids as $item_id => $selected) {
56  if ($selected == 1) {
57  // make sure that all parent ids are selected as well
58  if ($perm_data['parents'][$item_id] != '') {
59  $parent_ids = explode(':', $perm_data['parents'][$item_id]);
60  foreach ($parent_ids as $pid) {
61  if ($pid != 0 && !in_array($pid, array_keys($item_ids))) {
62  // one of the parent items were not selected, so skip this item
63  $msg[] = sprintf(SystemLocale::EF_COULD_NOT_ADD_PERMISSION_FOR_GROUP, '<strong>' . $perm_name . '</strong>', '<strong>' . $perm_data['itemname'][$item_id] . '</strong>', '<strong>' . $group_list[$group_id] . '</strong>') . ' (' . XoopsLocale::E_ALL_PARENT_ITEMS_MUST_BE_SELECTED . ')';
64  continue 2;
65  }
66  }
67  }
68  $gperm = $gperm_handler->create();
69  $gperm->setVar('gperm_groupid', $group_id);
70  $gperm->setVar('gperm_name', $perm_name);
71  $gperm->setVar('gperm_modid', $modid);
72  $gperm->setVar('gperm_itemid', $item_id);
73  if (!$gperm_handler->insert($gperm)) {
74  $msg[] = sprintf(SystemLocale::EF_COULD_NOT_ADD_PERMISSION_FOR_GROUP, '<strong>' . $perm_name . '</strong>', '<strong>' . $perm_data['itemname'][$item_id] . '</strong>', '<strong>' . $group_list[$group_id] . '</strong>');
75  } else {
76  $msg[] = sprintf(SystemLocale::SF_ADDED_PERMISSION_FOR_GROUP, '<strong>' . $perm_name . '</strong>', '<strong>' . $perm_data['itemname'][$item_id] . '</strong>', '<strong>' . $group_list[$group_id] . '</strong>');
77  }
78  unset($gperm);
79  }
80  }
81  }
82  }
83  }
84 }
85 $backlink = $xoops->getEnv("HTTP_REFERER");
86 if ($module->getVar('hasadmin')) {
87  $adminindex = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : $module->getInfo('adminindex');
88  if ($adminindex) {
89  $backlink = $xoops->url('modules/' . $module->getVar('dirname') . '/' . $adminindex);
90  }
91 }
92 $backlink = ($backlink) ? $backlink : \XoopsBaseConfig::get('url') . '/admin.php';
93 
94 $xoops->redirect($backlink, 2, implode("<br />", $msg));
const SF_ADDED_PERMISSION_FOR_GROUP
Definition: en_US.php:376
static getInstance()
Definition: Xoops.php:160
$xoops
Definition: groupperm.php:24
$pid
Definition: admin_menu.php:37
$modid
Definition: groupperm.php:27
$group_list
Definition: groupperm.php:41
$gperm_handler
if($modid<=1||!$xoops->isUser()||!$xoops->user->isAdmin($modid)) $module
Definition: groupperm.php:33
const EF_COULD_NOT_RESET_GROUP_PERMISSION_FOR_MODULE
Definition: en_US.php:276
if(is_array($_POST['perms'])&&!empty($_POST['perms'])) $backlink
Definition: groupperm.php:85
const E_NO_MODULE
Definition: en_US.php:353
static get($name)
$member_handler
Definition: groupperm.php:40
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
const EF_COULD_NOT_ADD_PERMISSION_FOR_GROUP
Definition: en_US.php:273
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
const E_ALL_PARENT_ITEMS_MUST_BE_SELECTED
Definition: en_US.php:312