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 cBackend {
25:
26: 27: 28: 29: 30:
31: protected $_actions = array();
32:
33: 34: 35: 36: 37:
38: protected $_files = array();
39:
40: 41: 42: 43: 44:
45: protected $_frame = 0;
46:
47: 48: 49: 50: 51:
52: protected $_errors = array();
53:
54: 55: 56: 57: 58:
59: protected $_area = '';
60:
61: 62: 63:
64: public function setFrame($frame_nr = 0) {
65: $frame_nr = cSecurity::toInteger($frame_nr);
66: $this->_frame = $frame_nr;
67: }
68:
69: 70: 71: 72: 73: 74:
75: public function select($area) {
76:
77: global $cfg, $client, $lang, $db, $perm, $action, $idcat;
78: global $idcat, $idtpl, $idmod, $idlay;
79:
80: if (isset($idcat)) {
81: $itemid = $idcat;
82: } elseif (isset($idtpl)) {
83: $itemid = $idtpl;
84: } elseif (isset($idmod)) {
85: $itemid = $idmod;
86: } elseif (isset($idlay)) {
87: $itemid = $idlay;
88: } else {
89: $itemid = 0;
90: }
91:
92: $itemid = cSecurity::toInteger($itemid);
93: $area = cSecurity::escapeDB($area, $db);
94:
95:
96: $this->_area = $area;
97:
98:
99: $sql = 'SELECT
100: b.name AS name,
101: b.code AS code,
102: b.relevant as relevant_action,
103: a.relevant as relevant_area
104: FROM
105: ' . $cfg['tab']['area'] . ' AS a,
106: ' . $cfg['tab']['actions'] . " AS b
107: WHERE
108: a.name = '" . $area . "' AND
109: b.idarea = a.idarea AND
110: a.online = '1'";
111:
112:
113:
114:
115:
116:
117: if (!$perm->have_perm_area_action($area)) {
118: $sql .= " AND a.relevant = '0'";
119: }
120:
121: $db->query($sql);
122:
123: while ($db->nextRecord()) {
124:
125:
126:
127:
128:
129:
130: if ($db->f('relevant_action') == 1 && $db->f('relevant_area') == 1) {
131:
132: if ($perm->have_perm_area_action_item($area, $db->f('name'), $itemid)) {
133: $this->_actions[$area][$db->f('name')] = $db->f('code');
134: }
135:
136: if ($itemid == 0) {
137:
138:
139:
140:
141: if ($action == 'mod_edit' || $action == 'tpl_edit' || $action == 'lay_edit') {
142: if ($perm->have_perm_area_action_anyitem($area, $db->f('name'))) {
143: $this->_actions[$area][$db->f('name')] = $db->f('code');
144: }
145: }
146: }
147: } else {
148: $this->_actions[$area][$db->f('name')] = $db->f('code');
149: }
150: }
151:
152: $sql = 'SELECT
153: b.filename AS name,
154: b.filetype AS type,
155: a.parent_id AS parent_id
156: FROM
157: ' . $cfg['tab']['area'] . ' AS a,
158: ' . $cfg['tab']['files'] . ' AS b,
159: ' . $cfg['tab']['framefiles'] . " AS c
160: WHERE
161: a.name = '" . $area . "' AND
162: b.idarea = a.idarea AND
163: b.idfile = c.idfile AND
164: c.idarea = a.idarea AND
165: c.idframe = '" . $this->_frame . "' AND
166: a.online = '1'";
167:
168:
169:
170:
171: if (!$perm->have_perm_area_action($area)) {
172: $sql .= " AND a.relevant = '0'";
173: }
174: $sql .= ' ORDER BY b.filename';
175:
176: $db->query($sql);
177:
178: while ($db->nextRecord()) {
179:
180:
181: if (strstr($db->f('name'), '/')) {
182: $filepath = $cfg['path']['plugins'] . $db->f('name');
183: } else {
184: $filepath = $cfg['path']['includes'] . $db->f('name');
185: }
186:
187:
188: if ($db->f('parent_id') != 0 && $db->f('type') == 'main') {
189: $this->_files['sub'][] = $filepath;
190: }
191:
192: $this->_files[$db->f('type')][] = $filepath;
193: }
194:
195: $debug = "Files:\n" . print_r($this->_files, true) . "\n" . "Actions:\n" . print_r($this->_actions[$this->_area], true) . "\n" . "Information:\n" . "Area: $area\n" . "Action: $action\n" . "Client: $client\n" . "Lang: $lang\n";
196: cDebug::out($debug);
197: }
198:
199: 200: 201: 202: 203: 204: 205:
206: public function getCode($action) {
207: $actionCodeFile = cRegistry::getBackendPath() . 'includes/type/action/include.' . $action . '.action.php';
208: if (cFileHandler::exists($actionCodeFile)) {
209: return cFileHandler::read($actionCodeFile);
210: }
211:
212: return '';
213: }
214:
215: 216: 217: 218: 219: 220: 221: 222: 223:
224: public function getFile($which) {
225: if (isset($this->_files[$which])) {
226: return $this->_files[$which];
227: }
228: }
229:
230: 231: 232: 233: 234: 235: 236: 237: 238:
239: public function log($idcat, $idart, $client, $lang, $idaction) {
240: global $perm, $auth;
241:
242: if (!cSecurity::isInteger($client)) {
243: return;
244: } elseif (!cSecurity::isInteger($lang)) {
245: return;
246: }
247:
248: $oDb = cRegistry::getDb();
249:
250: $timestamp = date('Y-m-d H:i:s');
251: $idcatart = 0;
252:
253: $idcat = (int) $idcat;
254: $idart = (int) $idart;
255: $client = (int) $client;
256: $lang = (int) $lang;
257: $idaction = $oDb->escape($idaction);
258:
259: if ($idcat > 0 && $idart > 0) {
260: $oCatArtColl = new cApiCategoryArticleCollection();
261: $oCatArt = $oCatArtColl->fetchByCategoryIdAndArticleId($idcat, $idart);
262: $idcatart = $oCatArt->get('idcatart');
263: }
264:
265: $oldaction = $idaction;
266: $idaction = $perm->getIDForAction($idaction);
267:
268: if ($idaction != '') {
269: $oActionLogColl = new cApiActionlogCollection();
270: $oActionLogColl->create($auth->auth['uid'], $client, $lang, $idaction, $idcatart, $timestamp);
271: } else {
272: echo $oldaction . ' is not in the actions table!<br><br>';
273: }
274: }
275:
276: }
277: