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 = NULL;
61: if (!$this->checkPerm($group, $plugin, $action, $item)) {
62: $perm = parent::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:
72: return $perm;
73: }
74:
75: 76: 77: 78: 79: 80: 81: 82:
83: public function setPerm($group, $plugin, $action, $item) {
84: $this->create($group, $plugin, $action, $item);
85: }
86:
87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99:
100: public function checkPerm($group, $plugin, $action, $item, $useLang = false) {
101: global $lang;
102:
103:
104:
105: $group = (int) $group;
106: $plugin = $this->_frontendPermission->_inFilter($plugin);
107: $action = $this->_frontendPermission->_inFilter($action);
108: $item = $this->_frontendPermission->_inFilter($item);
109:
110:
111: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '__GLOBAL__'");
112: if ($this->next()) {
113: return true;
114: }
115:
116:
117: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '" . $item . "'");
118: return ($this->next()) ? true : false;
119: }
120:
121: 122: 123: 124: 125: 126: 127: 128: 129: 130:
131: public function removePerm($group, $plugin, $action, $item, $useLang = false) {
132: global $lang;
133:
134:
135:
136: $group = (int) $group;
137: $plugin = $this->_frontendPermission->_inFilter($plugin);
138: $action = $this->_frontendPermission->_inFilter($action);
139: $item = $this->_frontendPermission->_inFilter($item);
140:
141: $this->select("idlang = " . $lang . " AND idfrontendgroup = " . $group . " AND plugin = '" . $plugin . "' AND action = '" . $action . "' AND item = '" . $item . "'");
142: if (($myitem = $this->next()) !== false) {
143: return $this->delete($myitem->get('idfrontendpermission'));
144: }
145: return false;
146: }
147: }
148:
149: 150: 151: 152: 153: 154:
155: class cApiFrontendPermission extends Item {
156:
157: 158: 159: 160: 161:
162: public function __construct($mId = false) {
163: global $cfg;
164: parent::__construct($cfg['tab']['frontendpermissions'], 'idfrontendpermission');
165: if ($mId !== false) {
166: $this->loadByPrimaryKey($mId);
167: }
168: }
169: }
170: