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