XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Permission.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7define('USER_PERMISSION_NONE', 0);
8define('USER_PERMISSION_READ', 1);
9define('USER_PERMISSION_ADMIN', 2);
10
12{
13 public $mGroupId;
14 public $mName;
15 public $mValue = USER_PERMISSION_NONE;
16
20 public $mItem;
21
22 public function __construct($groupId, &$item)
23 {
24 $this->mGroupId = $groupId;
25 $this->mItem =& $item;
26 $this->_load();
27 }
28
29 public function getId()
30 {
31 return $this->mItem->getId();
32 }
33
34 public function getValue()
35 {
36 return $this->mValue;
37 }
38
39 public function setValue($value)
40 {
41 $value = (int)$value;
42 $this->mValue = $value & (USER_PERMISSION_READ | USER_PERMISSION_ADMIN);
43 }
44
45 public function _load()
46 {
47 $this->mValue = $this->mItem->loadPermission($this->mGroupId);
48 }
49
53 public function save()
54 {
55 $gpermHandler =& xoops_gethandler('groupperm');
56
57 $name = $this->mItem->getReadPermName();
58 if ($name) {
59 $gperm =& $this->_createGperm($name);
60 if (!$gpermHandler->insert($gperm)) {
61 return false;
62 }
63 }
64
65 $name = $this->mItem->getAdminPermName();
66 if ($name) {
67 $gperm =& $this->_createGperm($name);
68 if ($gpermHandler->insert($gperm)) {
69 return false;
70 }
71 }
72
73 return true;
74 }
75
76 public function _createGperm($gperm_name = null)
77 {
78 $gpermHandler =& xoops_gethandler('groupperm');
79 $gperm =& $gpermHandler->create();
80
81 $gperm->setVar('gperm_groupid', $this->mGroupId);
82 $gperm->setVar('gperm_itemid', $this->getId());
83 $gperm->setVar('gperm_modid', 1);
84 $gperm->setVar('gperm_name', $gperm_name);
85
86 return $gperm;
87 }
88}
89
91{
95 public function getId()
96 {
97 }
98
102 public function getName()
103 {
104 }
105
109 public function getAdminUrl()
110 {
111 }
112
116 public function isActive()
117 {
118 }
119
120 public function loadPermission($groupId)
121 {
122 }
123
127 public function getReadPermName()
128 {
129 return null;
130 }
131
135 public function getAdminPermName()
136 {
137 return null;
138 }
139}
140
142{
143 public $mModule;
144
145 public function __construct(&$module)
146 {
147 $this->mModule =& $module;
148 }
149
150 public function getId()
151 {
152 return $this->mModule->getVar('mid');
153 }
154
155 public function getName()
156 {
157 return $this->mModule->getProperty('name');
158 }
159
160 public function getAdminUrl()
161 {
162 }
163
164 public function isActive()
165 {
166 return true;
167 }
168
169 public function loadPermission($groupId)
170 {
171 $ret = USER_PERMISSION_NONE;
172
173 $gpermHandler =& xoops_gethandler('groupperm');
174 if ($gpermHandler->checkRight('module_admin', $this->mModule->getVar('mid'), $groupId)) {
175 $ret |= USER_PERMISSION_ADMIN;
176 }
177
178 if ($gpermHandler->checkRight('module_read', $this->mModule->getVar('mid'), $groupId)) {
179 $ret |= USER_PERMISSION_READ;
180 }
181
182 return $ret;
183 }
184
185 public function getReadPermName()
186 {
187 return 'module_read';
188 }
189
190 public function getAdminPermName()
191 {
192 return 'module_admin';
193 }
194}
195
197{
198 public $mBlock;
199
200 public function __construct(&$block)
201 {
202 $this->mBlock =& $block;
203 }
204
205 public function getId()
206 {
207 return $this->mBlock->getVar('bid');
208 }
209
210 public function getName()
211 {
212 return $this->mBlock->getProperty('title');
213 }
214
215 public function getAdminUrl()
216 {
217 }
218
219 public function isActive()
220 {
221 return 1 == $this->mBlock->getProperty('visible') ? true : false;
222 }
223
224 public function loadPermission($groupId)
225 {
226 $ret = USER_PERMISSION_NONE;
227
228 $gpermHandler =& xoops_gethandler('groupperm');
229 if ($gpermHandler->checkRight('block_read', $this->mBlock->getVar('bid'), $groupId, 1, true)) {
230 $ret |= USER_PERMISSION_READ;
231 }
232
233 return $ret;
234 }
235
236
237 public function getReadPermName()
238 {
239 return 'block_read';
240 }
241}
242
248{
249 public $mId;
250 public $mName;
251
252 public function __construct($id, $name)
253 {
254 $this->mId = $id;
255 $this->mName = $name;
256 }
257
258 public function getId()
259 {
260 return $this->mId;
261 }
262
263 public function getName()
264 {
265 return $this->mName;
266 }
267
268 public function getAdminUrl()
269 {
270 }
271
272 public function isActive()
273 {
274 return true;
275 }
276
277 public function loadPermission($groupId)
278 {
279 $ret = USER_PERMISSION_NONE;
280
281 $gpermHandler =& xoops_gethandler('groupperm');
282 if ($gpermHandler->checkRight('system_admin', $this->mId, $groupId)) {
283 $ret |= USER_PERMISSION_ADMIN;
284 }
285
286 return $ret;
287 }
288
289 public function getAdminPermName()
290 {
291 return 'system_admin';
292 }
293}