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: 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: public function create($group, $plugin, $action, $item) {
57: global $lang;
58:
59: $perm = null;
60: if (!$this->checkPerm($group, $plugin, $action, $item)) {
61: $perm = parent::createNewItem();
62: $perm->set('idlang', $lang);
63: $perm->set('idfrontendgroup', $group);
64: $perm->set('plugin', $plugin);
65: $perm->set('action', $action);
66: $perm->set('item', $item);
67:
68: $perm->store();
69: }
70:
71: return $perm;
72: }
73:
74: 75: 76: 77: 78: 79: 80: 81:
82: public function setPerm($group, $plugin, $action, $item) {
83: $this->create($group, $plugin, $action, $item);
84: }
85:
86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98:
99: public function checkPerm($group, $plugin, $action, $item, $useLang = false) {
100: global $lang;
101:
102:
103:
104: $group = (int) $group;
105: $plugin = $this->_frontendPermission->_inFilter($plugin);
106: $action = $this->_frontendPermission->_inFilter($action);
107: $item = $this->_frontendPermission->_inFilter($item);
108:
109:
110: $this->select("idlang=" . $lang . " AND idfrontendgroup=" . $group . " AND plugin='" . $plugin . "' AND action='" . $action . "' AND item='__GLOBAL__'");
111: if ($this->next()) {
112: return true;
113: }
114:
115:
116: $this->select("idlang=" . $lang . " AND idfrontendgroup=" . $group . " AND plugin='" . $plugin . "' AND action='" . $action . "' AND item='" . $item . "'");
117: return ($this->next())? true : false;
118: }
119:
120: 121: 122: 123: 124: 125: 126: 127: 128: 129:
130: public function removePerm($group, $plugin, $action, $item, $useLang = false) {
131: global $lang;
132:
133:
134:
135: $group = (int) $group;
136: $plugin = $this->_frontendPermission->_inFilter($plugin);
137: $action = $this->_frontendPermission->_inFilter($action);
138: $item = $this->_frontendPermission->_inFilter($item);
139:
140: $this->select("idlang=" . $lang . " AND idfrontendgroup=" . $group . " AND plugin='" . $plugin . "' AND action='" . $action . "' AND item='" . $item . "'");
141: if (($myitem = $this->next()) !== false) {
142: return $this->delete($myitem->get('idfrontendpermission'));
143: }
144: return false;
145: }
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: }
171: