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