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 cAjaxRequest {
25:
26: 27: 28: 29: 30: 31:
32: public function handle($action) {
33: $backendPath = cRegistry::getBackendPath();
34: $string = '';
35:
36: $frontendURL = cRegistry::getFrontendUrl();
37: $frontendPath = cRegistry::getFrontendPath();
38:
39: switch ($action) {
40:
41:
42: case 'artsel':
43: $name = (string) $_REQUEST['name'];
44: $value = (int) $_REQUEST['value'];
45: $idCat = (int) $_REQUEST['idcat'];
46: $string = buildArticleSelect($name, $idCat, $value);
47: break;
48:
49: case 'dirlist':
50: global $cfgClient, $client;
51:
52: $dirName = (string) $_REQUEST['dir'];
53: $fileListId = (int) $_REQUEST['id'];
54: $idArtLang = (int) $_REQUEST['idartlang'];
55:
56: $art = new cApiArticleLanguage($idArtLang, true);
57: $artReturn = $art->getContent('CMS_FILELIST', $fileListId);
58: $fileList = new cContentTypeFilelist($artReturn, $fileListId, array());
59:
60: $string = $fileList->generateDirectoryList($fileList->buildDirectoryList($cfgClient[$client]['upl']['path'] . $dirName));
61: break;
62:
63: case 'filelist':
64: $dirName = (string) $_REQUEST['dir'];
65: $fileListId = (int) $_REQUEST['id'];
66: $idArtLang = (int) $_REQUEST['idartlang'];
67:
68: $art = new cApiArticleLanguage($idArtLang, true);
69: $artReturn = $art->getContent('CMS_FILELIST', $fileListId);
70: $fileList = new cContentTypeFilelist($artReturn, $fileListId, array());
71:
72: $string = $fileList->generateFileSelect($dirName);
73: break;
74:
75: case 'inused_layout':
76:
77: global $cfg;
78: if ((int) $_REQUEST['id'] > 0) {
79: $layout = new cApiLayout((int) $_REQUEST['id']);
80: if ($layout->isInUse(true)) {
81: $template = new cTemplate();
82: $usedTemplates = $layout->getUsedTemplates();
83: if (count($usedTemplates) > 0) {
84: $response = '<br>';
85: foreach ($usedTemplates as $i => $usedTemplate) {
86: if ($i % 2 == 0) {
87: $template->set('d', 'CLASS', 'grey');
88: } else {
89: $template->set('d', 'CLASS', 'white');
90: }
91: $template->set('d', 'NAME', $usedTemplate['tpl_name']);
92: $template->next();
93: }
94:
95: $string = '<div class="inuse_info" >' . $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_lay_mod'], true) . '</div>';
96: } else {
97: $string = i18n('No data found!');
98: }
99: }
100: }
101: break;
102:
103: case 'inused_module':
104:
105: global $cfg;
106: $module = new cApiModule();
107: if ((int) $_REQUEST['id'] > 0 && $module->moduleInUse((int) $_REQUEST['id'], true)) {
108: $template = new cTemplate();
109: $usedTemplates = $module->getUsedTemplates();
110: if (count($usedTemplates) > 0) {
111: foreach ($usedTemplates as $i => $usedTemplate) {
112: if ($i % 2 == 0) {
113: $template->set('d', 'CLASS', 'grey');
114: } else {
115: $template->set('d', 'CLASS', 'white');
116: }
117:
118: $template->set('d', 'NAME', $usedTemplate['tpl_name']);
119: $template->next();
120: }
121:
122: $string = '<div class="inuse_info" >' . $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_lay_mod'], true) . '</div>';
123: } else {
124: $string = i18n('No data found!');
125: }
126: }
127: break;
128:
129: case 'inused_template':
130:
131: global $cfg;
132: cInclude('backend', 'includes/functions.tpl.php');
133:
134: if ((int) $_REQUEST['id'] > 0) {
135: $template = new cTemplate();
136: $template->reset();
137: $usedData = tplGetInUsedData((int) $_REQUEST['id']);
138:
139: if (isset($usedData['cat'])) {
140: $template->set('s', 'HEAD_TYPE', i18n('Category'));
141: foreach ($usedData['cat'] as $i => $cat) {
142: $template->set('d', 'ID', $cat['idcat']);
143: $template->set('d', 'LANG', $cat['lang']);
144: $template->set('d', 'NAME', $cat['name']);
145: $template->next();
146: }
147: $template->set('s', 'HEAD_ID', i18n('idcat'));
148: $template->set('s', 'HEAD_LANG', i18n('idlang'));
149: $template->set('s', 'HEAD_NAME', i18n('Name'));
150: $response = $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_tpl'], true);
151: }
152:
153: $template->reset();
154:
155: if (isset($usedData['art'])) {
156: $template->set('s', 'HEAD_TYPE', i18n('Article'));
157: foreach ($usedData['art'] as $i => $aArt) {
158: $template->set('d', 'ID', $aArt['idart']);
159: $template->set('d', 'LANG', $aArt['lang']);
160: $template->set('d', 'NAME', $aArt['title']);
161: $template->next();
162: }
163: $template->set('s', 'HEAD_ID', i18n('idart'));
164: $template->set('s', 'HEAD_LANG', i18n('idlang'));
165: $template->set('s', 'HEAD_NAME', i18n('Name'));
166: $response .= $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_tpl'], true);
167: }
168:
169: $string = '<div class="inuse_info" >' . $response . '</div>';
170: } else {
171: $string = i18n('No data found!');
172: }
173:
174: break;
175:
176: case 'scaleImage':
177: $filename_a = $_REQUEST['url'];
178: $filename = str_replace($frontendURL, $frontendPath, $filename_a);
179:
180:
181: $filetype = substr($filename, strlen($filename) - 4, 4);
182: switch (strtolower($filetype)) {
183: case '.gif':
184: $string = cApiImgScale($filename, 428, 210);
185: break;
186: case '.png':
187: $string = cApiImgScale($filename, 428, 210);
188: break;
189: case '.jpg':
190: $string = cApiImgScale($filename, 428, 210);
191: break;
192: case 'jpeg':
193: $string = cApiImgScale($filename, 428, 210);
194: break;
195: default:
196: $string = $filename_a;
197: break;
198: }
199:
200:
201: if ($string == '') {
202: $filename = str_replace($frontendPath, $frontendURL, $filename_a);
203: $string = $filename;
204: }
205: break;
206:
207: case 'imagelist':
208: $dirName = (string) $_REQUEST['dir'];
209: $imageId = (int) $_REQUEST['id'];
210: $idArtLang = (int) $_REQUEST['idartlang'];
211:
212: $art = new cApiArticleLanguage($idArtLang, true);
213: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
214: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
215:
216: $string = $image->generateFileSelect($dirName);
217: break;
218:
219: case 'loadImageMeta':
220: $imageId = (int) $_REQUEST['id'];
221: $idArtLang = (int) $_REQUEST['idartlang'];
222:
223: $art = new cApiArticleLanguage($idArtLang, true);
224: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
225: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
226:
227: $filename = (string) basename($_REQUEST['filename']);
228: $dirname = (string) dirname($_REQUEST['filename']);
229: if ($dirname != '.') {
230: $dirname .= '/';
231: } else {
232: $dirname = '';
233: }
234:
235: $string = $image->getImageMeta($filename, $dirname);
236: break;
237:
238: case 'upl_mkdir':
239: $imageId = (int) $_REQUEST['id'];
240: $idArtLang = (int) $_REQUEST['idartlang'];
241: $path = (string) $_REQUEST['path'];
242: $name = (string) $_REQUEST['foldername'];
243:
244: $art = new cApiArticleLanguage($idArtLang, true);
245: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
246: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
247:
248: $string = $image->uplmkdir($path, $name);
249: switch ($string) {
250: case 1:
251: break;
252: case '0702':
253: $string = i18n('Directory already exist.');
254: break;
255: case '0703':
256: $string = i18n('Directories with special characters and spaces are not allowed.');
257: break;
258: }
259: break;
260:
261: case 'upl_upload':
262: $imageId = (int) $_REQUEST['id'];
263: $idArtLang = (int) $_REQUEST['idartlang'];
264: $path = (string) $_REQUEST['path'];
265:
266: $art = new cApiArticleLanguage($idArtLang, true);
267: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
268: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
269:
270: $string = $image->uplupload($path);
271: break;
272:
273: case 'linkeditorfilelist':
274: $id = (int) $_REQUEST['id'];
275: $idArtLang = (int) $_REQUEST['idartlang'];
276: $idCat = (string) $_REQUEST['idcat'];
277:
278: $art = new cApiArticleLanguage($idArtLang, true);
279: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
280: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
281:
282: $string = $linkEditor->generateArticleSelect($idCat);
283: break;
284:
285: case 'linkeditordirlist':
286: $id = (int) $_REQUEST['id'];
287: $idArtLang = (int) $_REQUEST['idartlang'];
288: $levelId = (string) $_REQUEST['level'];
289: $parentidcat = (string) $_REQUEST['parentidcat'];
290:
291: $art = new cApiArticleLanguage($idArtLang, true);
292: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
293: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
294:
295: $string = $linkEditor->getCategoryList($linkEditor->buildCategoryArray($levelId, $parentidcat));
296: break;
297:
298: case 'linkeditorimagelist':
299: $dirName = (string) $_REQUEST['dir'];
300: $id = (int) $_REQUEST['id'];
301: $idArtLang = (int) $_REQUEST['idartlang'];
302:
303: $art = new cApiArticleLanguage($idArtLang, true);
304: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
305: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
306:
307: $string = $linkEditor->getUploadFileSelect($dirName);
308: break;
309:
310: case 'generaljstranslations':
311: $translations = array();
312: $translations['Confirmation Required'] = i18n('Confirmation Required');
313: $translations['OK'] = i18n('OK');
314: $translations['Cancel'] = i18n('Cancel');
315: $string = json_encode($translations);
316: break;
317:
318: case 'logfilecontent':
319: $type = $_REQUEST['logfile'];
320: $numberOfLines = $_REQUEST['numberOfLines'];
321: $cfg = cRegistry::getConfig();
322: $filename = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['logs'] . $type;
323: $string = cFileHandler::read($filename);
324: $lines = file($filename);
325: $lines = array_splice($lines, $numberOfLines * -1);
326: $string = implode('', $lines);
327: break;
328:
329: case 'updatepluginorder':
330: if (cRegistry::getPerm()->have_perm()) {
331: $newOrder = cSecurity::toInteger($_POST['neworder']);
332: $pluginColl = new PimPluginCollection();
333: $pluginColl->select();
334: if ($newOrder <= 0 || $newOrder > $pluginColl->count()) {
335: $string = 'order must be > 0 and <= number of plugins';
336: break;
337: }
338:
339: $pluginId = cSecurity::toInteger($_POST['idplugin']);
340: $plugin = new PimPlugin($pluginId);
341: $plugin->updateExecOrder($newOrder);
342: $string = 'ok';
343: } else {
344: $string = 'Unknown Ajax Action';
345: }
346: break;
347:
348: case 'verify_module':
349:
350: $idmod = isset($_POST['idmod']) ? $_POST['idmod'] : NULL;
351: $inputType = isset($_POST['type']) ? $_POST['type'] : NULL;
352:
353:
354: $moduleCheck = getSystemProperty('system', 'modulecheck');
355: $moduleCheck = $moduleCheck == '' || $moduleCheck == 'true';
356:
357: $result = array(
358: 'state' => 'error',
359: 'message' => 'No cModuleHandler for ' . $idmod . ', or wrong code type: ' . $inputType
360: );
361:
362: if ($idmod && $inputType && $moduleCheck === true) {
363: $contenidoModuleHandler = new cModuleHandler($idmod);
364: switch ($inputType) {
365: case 'input':
366: $result = $contenidoModuleHandler->testInput();
367: break;
368: case 'output':
369: $result = $contenidoModuleHandler->testOutput();
370: break;
371: }
372:
373:
374: if ($result['state']) {
375: $result['state'] = 'ok';
376: $result['message'] = i18n("Module successfully compiled");
377: } else {
378: $result['state'] = 'error';
379: $result['message'] = $result['errorMessage'];
380: }
381: }
382:
383: $string = json_encode($result);
384: break;
385:
386: case 'authentication_fail':
387:
388: $result = array(
389: 'state' => 'error',
390: 'code' => 401,
391: 'message' => 'Unauthorized',
392: );
393: $string = json_encode($result);
394: break;
395:
396: default:
397:
398: $string = 'Unknown Ajax Action';
399: break;
400: }
401:
402: return $string;
403: }
404:
405: }
406: