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: if ($path == '/') {
266: $path = '';
267: }
268:
269: $art = new cApiArticleLanguage($idArtLang, true);
270: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
271: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
272:
273: $string = $image->uplupload($path);
274: break;
275:
276: case 'linkeditorfilelist':
277: $id = (int) $_REQUEST['id'];
278: $idArtLang = (int) $_REQUEST['idartlang'];
279: $idCat = (string) $_REQUEST['idcat'];
280:
281: $art = new cApiArticleLanguage($idArtLang, true);
282: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
283: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
284:
285: $string = $linkEditor->generateArticleSelect($idCat);
286: break;
287:
288: case 'linkeditordirlist':
289: $id = (int) $_REQUEST['id'];
290: $idArtLang = (int) $_REQUEST['idartlang'];
291: $levelId = (string) $_REQUEST['level'];
292: $parentidcat = (string) $_REQUEST['parentidcat'];
293:
294: $art = new cApiArticleLanguage($idArtLang, true);
295: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
296: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
297:
298: $string = $linkEditor->getCategoryList($linkEditor->buildCategoryArray($levelId, $parentidcat));
299: break;
300:
301: case 'linkeditorimagelist':
302: $dirName = (string) $_REQUEST['dir'];
303: $id = (int) $_REQUEST['id'];
304: $idArtLang = (int) $_REQUEST['idartlang'];
305:
306: $art = new cApiArticleLanguage($idArtLang, true);
307: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
308: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
309:
310: $string = $linkEditor->getUploadFileSelect($dirName);
311: break;
312:
313: case 'generaljstranslations':
314: $translations = array();
315: $translations['Confirmation Required'] = i18n('Confirmation Required');
316: $translations['OK'] = i18n('OK');
317: $translations['Cancel'] = i18n('Cancel');
318: $string = json_encode($translations);
319: break;
320:
321: case 'logfilecontent':
322: $type = $_REQUEST['logfile'];
323: $numberOfLines = $_REQUEST['numberOfLines'];
324: $cfg = cRegistry::getConfig();
325: $filename = $cfg['path']['frontend'] . DIRECTORY_SEPARATOR . $cfg['path']['logs'] . $type;
326: $string = cFileHandler::read($filename);
327: $lines = file($filename);
328: $lines = array_splice($lines, $numberOfLines * -1);
329: $string = implode('', $lines);
330: break;
331:
332: case 'updatepluginorder':
333: if (cRegistry::getPerm()->have_perm()) {
334: $newOrder = cSecurity::toInteger($_POST['neworder']);
335: $pluginColl = new PimPluginCollection();
336: $pluginColl->select();
337: if ($newOrder <= 0 || $newOrder > $pluginColl->count()) {
338: $string = 'order must be > 0 and <= number of plugins';
339: break;
340: }
341:
342: $pluginId = cSecurity::toInteger($_POST['idplugin']);
343: $plugin = new PimPlugin($pluginId);
344: $plugin->updateExecOrder($newOrder);
345: $string = 'ok';
346: } else {
347: $string = 'Unknown Ajax Action';
348: }
349: break;
350:
351: case 'verify_module':
352:
353: $idmod = isset($_POST['idmod']) ? $_POST['idmod'] : NULL;
354: $inputType = isset($_POST['type']) ? $_POST['type'] : NULL;
355:
356:
357: $moduleCheck = getSystemProperty('system', 'modulecheck');
358: $moduleCheck = $moduleCheck == '' || $moduleCheck == 'true';
359:
360: $result = array(
361: 'state' => 'error',
362: 'message' => 'No cModuleHandler for ' . $idmod . ', or wrong code type: ' . $inputType
363: );
364:
365: if ($idmod && $inputType && $moduleCheck === true) {
366: $contenidoModuleHandler = new cModuleHandler($idmod);
367: switch ($inputType) {
368: case 'input':
369: $result = $contenidoModuleHandler->testInput();
370: break;
371: case 'output':
372: $result = $contenidoModuleHandler->testOutput();
373: break;
374: }
375:
376:
377: if ($result['state']) {
378: $result['state'] = 'ok';
379: $result['message'] = i18n("Module successfully compiled");
380: } else {
381: $result['state'] = 'error';
382: $result['message'] = $result['errorMessage'];
383: }
384: }
385:
386: $string = json_encode($result);
387: break;
388:
389: case 'authentication_fail':
390:
391: $result = array(
392: 'state' => 'error',
393: 'code' => 401,
394: 'message' => 'Unauthorized',
395: );
396: $string = json_encode($result);
397: break;
398:
399: default:
400:
401: $string = 'Unknown Ajax Action';
402: break;
403: }
404:
405: return $string;
406: }
407:
408: }
409: