XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
groupperm.php
Go to the documentation of this file.
1 <?php
2 // $Id: groupperm.php 10981 2013-02-04 19:37:48Z trabis $
3 
4 include '../../../include/cp_header.php';
5 $modid = isset($_POST['modid']) ? intval($_POST['modid']) : 0;
6 
7 // we dont want system module permissions to be changed here
8 if ($modid <= 1 || !is_object($xoopsUser) || !$xoopsUser->isAdmin($modid)) {
9  redirect_header(XOOPS_URL.'/index.php', 1, _NOPERM);
10  exit();
11 }
14 if (!is_object($module) || !$module->getVar('isactive')) {
15  redirect_header(XOOPS_URL.'/admin.php', 1, _MODULENOEXIST);
16  exit();
17 }
18 
19 $msg = array();
20 
22 $group_list = $member_handler->getGroupList();
23 
24 if (is_array($_POST['perms']) && !empty($_POST['perms'])) {
25  $gperm_handler = xoops_gethandler('groupperm');
26  foreach ($_POST['perms'] as $perm_name => $perm_data) {
27  if ($GLOBALS['xoopsSecurity']->check(true, false, $perm_name) && false != $gperm_handler->deleteByModule($modid, $perm_name)) {
28  foreach ($perm_data['groups'] as $group_id => $item_ids) {
29  foreach ($item_ids as $item_id => $selected) {
30  if ($selected == 1) {
31  // make sure that all parent ids are selected as well
32  if ($perm_data['parents'][$item_id] != '') {
33  $parent_ids = explode(':', $perm_data['parents'][$item_id]);
34  foreach ($parent_ids as $pid) {
35  if ($pid != 0 && !in_array($pid, array_keys($item_ids))) {
36  // one of the parent items were not selected, so skip this item
37  $msg[] = sprintf(_MD_AM_PERMADDNG, '<strong>'.$perm_name.'</strong>', '<strong>'.$perm_data['itemname'][$item_id].'</strong>', '<strong>'.$group_list[$group_id].'</strong>').' ('._MD_AM_PERMADDNGP.')';
38  continue 2;
39  }
40  }
41  }
42  $gperm =& $gperm_handler->create();
43  $gperm->setVar('gperm_groupid', $group_id);
44  $gperm->setVar('gperm_name', $perm_name);
45  $gperm->setVar('gperm_modid', $modid);
46  $gperm->setVar('gperm_itemid', $item_id);
47  if (!$gperm_handler->insert($gperm)) {
48  $msg[] = sprintf(_MD_AM_PERMADDNG, '<strong>'.$perm_name.'</strong>', '<strong>'.$perm_data['itemname'][$item_id].'</strong>', '<strong>'.$group_list[$group_id].'</strong>');
49  } else {
50  $msg[] = sprintf(_MD_AM_PERMADDOK, '<strong>'.$perm_name.'</strong>', '<strong>'.$perm_data['itemname'][$item_id].'</strong>', '<strong>'.$group_list[$group_id].'</strong>');
51  }
52  unset($gperm);
53  }
54  }
55  }
56  } else {
57  $msg[] = sprintf(_MD_AM_PERMRESETNG, $module->getVar('name').'('.$perm_name.')');
58  }
59  }
60 }
61 
62 $backlink = xoops_getenv("HTTP_REFERER");
63 if ($module->getVar('hasadmin')) {
64  $adminindex = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : $module->getInfo('adminindex');
65  if ($adminindex) {
66  $backlink = XOOPS_URL.'/modules/'.$module->getVar('dirname').'/'.$adminindex;
67  }
68 }
69 $backlink = ($backlink) ? $backlink : XOOPS_URL.'/admin.php';
70 
71 redirect_header($backlink, 2, implode("<br />", $msg));
72 ?>