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