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