1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cApiFrontendPermissionCollection extends ItemCollection {
25:
26: 27: 28: 29: 30:
31: protected $_frontendPermission;
32:
33: 34: 35:
36: public function __construct() {
37: global $cfg;
38: $this->_frontendPermission = new cApiFrontendPermission();
39:
40: parent::__construct($cfg['tab']['frontendpermissions'], 'idfrontendpermission');
41: $this->_setItemClass('cApiFrontendPermission');
42:
43:
44: $this->_setJoinPartner('cApiFrontendGroupCollection');
45: $this->_setJoinPartner('cApiLanguageCollection');
46: }
47:
48: 49: 50: 51: 52: 53: 54: 55: 56:
57: public function create($group, $plugin, $action, $item) {
58: global $lang;
59:
60: $perm = false;
61: if (!$this->checkPerm($group, $plugin, $action, $item)) {
62: $perm = $this->createNewItem();
63: $perm->set('idlang', $lang);
64: $perm->set('idfrontendgroup', $group);
65: $perm->set('plugin', $plugin);
66: $perm->set('action', $action);
67: $perm->set('item', $item);
68:
69: $perm->store();
70:
71: return $perm;
72: }
73:
74: }
75:
76: 77: 78: 79: 80: 81: 82: 83:
84: public function setPerm($group, $plugin, $action, $item) {
85: $this->create($group, $plugin, $action, $item);
86: }
87:
88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100:
101: public function checkPerm($group, $plugin, $action, $item, $useLang = false) {
102: global $lang;
103:
104:
105:
106: $group = (int) $group;
107: $plugin = $this->_frontendPermission->_inFilter($plugin);
108: $action = $this->_frontendPermission->_inFilter($action);
109: $item = $this->_frontendPermission->_inFilter($item);
110:
111:
112: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '__GLOBAL__'");
113: if ($this->next()) {
114: return true;
115: }
116:
117:
118: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '" . $item . "'");
119: return ($this->next()) ? true : false;
120: }
121:
122: 123: 124: 125: 126: 127: 128: 129: 130: 131:
132: public function removePerm($group, $plugin, $action, $item, $useLang = false) {
133: global $lang;
134:
135:
136:
137: $group = (int) $group;
138: $plugin = $this->_frontendPermission->_inFilter($plugin);
139: $action = $this->_frontendPermission->_inFilter($action);
140: $item = $this->_frontendPermission->_inFilter($item);
141:
142: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '" . $item . "'");
143: if (($myitem = $this->next()) !== false) {
144: return $this->delete($myitem->get('idfrontendpermission'));
145: }
146: return false;
147: }
148: }
149:
150: 151: 152: 153: 154: 155:
156: class cApiFrontendPermission extends Item {
157:
158: 159: 160: 161: 162:
163: public function __construct($mId = false) {
164: global $cfg;
165: parent::__construct($cfg['tab']['frontendpermissions'], 'idfrontendpermission');
166: if ($mId !== false) {
167: $this->loadByPrimaryKey($mId);
168: }
169: }
170: }
171: