XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
GroupPermAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/admin/actions/GroupPropertyAction.class.php';
13require_once XOOPS_MODULE_PATH . '/user/admin/forms/GroupPermEditForm.class.php';
14
15/***
16 * @internal
17 * This function keeps difficult problems that this depens on the column's
18 * block of X2 theme format.
19 */
21{
22 public $mActionForm = null;
23
24 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
25 {
26 $this->mActionForm =new User_GroupPermEditForm();
27 $this->mActionForm->prepare();
28 }
29
30 public function execute(&$controller, &$xoopsUser)
31 {
32 $this->_loadGroup();
33
34 if (!is_object($this->mGroup)) {
35 return USER_FRAME_VIEW_ERROR;
36 }
37
38 $this->mActionForm->fetch();
39 $this->mActionForm->validate();
40
41 if ($this->mActionForm->hasError()) {
42 return $this->getDefaultView($controller, $xoopsUser);
43 }
44
45 //
46 // Reset group permission
47 //
48 $gpermHandler =& xoops_gethandler('groupperm');
49
50 $criteria =new CriteriaCompo();
51 $criteria->add(new Criteria('gperm_groupid', $this->mGroup->get('groupid')));
52 $criteria->add(new Criteria('gperm_modid', 1));
53 $criteria->add(new Criteria('gperm_name', 'system_admin'));
54 $gpermHandler->deleteAll($criteria);
55
56 foreach ($this->mActionForm->get('system') as $sid => $value) {
57 $item =new User_PermissionSystemAdminItem($sid, null);
58 $perm =new User_Permission($this->mGroup->get('groupid'), $item);
59
60 $perm->save();
61
62 unset($item);
63 unset($perm);
64 }
65
66 $moduleHandler =& xoops_gethandler('module');
67 $modPerms = [];
68
69 //
70 // Store module read permission
71 //
72 $this->_loadActiveModules();
73 foreach ($this->_mActiveModules as $module) {
74 $value = $this->mActionForm->get('module', $module->get('mid'));
75 if ($value) {
76 $gpermHandler->addRight('module_read', $module->get('mid'), $this->mGroup->get('groupid'));
77 } else {
78 $gpermHandler->removeRight('module_read', $module->get('mid'), $this->mGroup->get('groupid'));
79 }
80 }
81
82 foreach ($this->_mActiveModules as $module) {
83 $value = $this->mActionForm->get('module_admin', $module->get('mid'));
84 if ($value) {
85 $gpermHandler->addRight('module_admin', $module->get('mid'), $this->mGroup->get('groupid'));
86 } else {
87 $gpermHandler->removeRight('module_admin', $module->get('mid'), $this->mGroup->get('groupid'));
88 }
89 }
90
91 $blockHandler =& xoops_gethandler('block');
92
93 $this->_loadActiveBlocks();
94 foreach ($this->_mActiveBlocks as $side => $blocks) {
95 foreach ($blocks as $block) {
96 $value = $this->mActionForm->get('block', $block->get('bid'));
97 if ($value) {
98 $gpermHandler->addRight('block_read', $block->get('bid'), $this->mGroup->get('groupid'));
99 } elseif (is_object($block) && !$value) {
100 $gpermHandler->removeRight('block_read', $block->get('bid'), $this->mGroup->get('groupid'));
101 }
102 }
103 }
104
105 return USER_FRAME_VIEW_SUCCESS;
106 }
107
108 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
109 {
110 $render->setTemplateName('group_perm.html');
111 $render->setAttribute('group', $this->mGroup);
112 $render->setAttribute('actionForm', $this->mActionForm);
113 $render->setAttribute('modulePermissions', $this->mPermissions);
114 $render->setAttribute('blockPermissions', $this->mBlockPermissions);
115 $render->setAttribute('systemPermissions', $this->mSystemPermissions);
116 }
117
118 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
119 {
120 $controller->executeForward('index.php?action=GroupPerm&groupid=' . $this->mGroup->getVar('groupid'));
121 }
122}