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: public function handle($action) {
32: $backendPath = cRegistry::getBackendPath();
33: $string = '';
34:
35: $frontendURL = cRegistry::getFrontendUrl();
36: $frontendPath = cRegistry::getFrontendPath();
37:
38: switch ($action) {
39:
40:
41: case 'artsel':
42: $name = (string) $_REQUEST['name'];
43: $value = (int) $_REQUEST['value'];
44: $idCat = (int) $_REQUEST['idcat'];
45: $string = buildArticleSelect($name, $idCat, $value);
46: break;
47:
48: case 'dirlist':
49: global $cfgClient, $client;
50:
51: $dirName = (string) $_REQUEST['dir'];
52: $fileListId = (int) $_REQUEST['id'];
53: $idArtLang = (int) $_REQUEST['idartlang'];
54:
55: $art = new cApiArticleLanguage($idArtLang, true);
56: $artReturn = $art->getContent('CMS_FILELIST', $fileListId);
57: $fileList = new cContentTypeFilelist($artReturn, $fileListId, array());
58:
59: $string = $fileList->generateDirectoryList($fileList->buildDirectoryList($cfgClient[$client]['upl']['path'] . $dirName));
60: break;
61:
62: case 'filelist':
63: $dirName = (string) $_REQUEST['dir'];
64: $fileListId = (int) $_REQUEST['id'];
65: $idArtLang = (int) $_REQUEST['idartlang'];
66:
67: $art = new cApiArticleLanguage($idArtLang, true);
68: $artReturn = $art->getContent('CMS_FILELIST', $fileListId);
69: $fileList = new cContentTypeFilelist($artReturn, $fileListId, array());
70:
71: $string = $fileList->generateFileSelect($dirName);
72: break;
73:
74: case 'inused_layout':
75:
76: global $cfg;
77: if ((int) $_REQUEST['id'] > 0) {
78: $layout = new cApiLayout((int) $_REQUEST['id']);
79: if ($layout->isInUse(true)) {
80: $template = new cTemplate();
81: $usedTemplates = $layout->getUsedTemplates();
82: if (count($usedTemplates) > 0) {
83: $response = '<br />';
84: foreach ($usedTemplates as $i => $usedTemplate) {
85: if ($i%2 == 0) {
86: $template->set('d', 'CLASS', 'grey');
87: } else {
88: $template->set('d', 'CLASS', 'white');
89: }
90: $template->set('d', 'NAME', $usedTemplate['tpl_name']);
91: $template->next();
92: }
93:
94: $string = '<div class="inuse_info" >' . $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_lay_mod'], true) . '</div>';
95: } else {
96: $string = i18n('No data found!');
97: }
98: }
99: }
100: break;
101:
102: case 'inused_module':
103:
104: global $cfg;
105: $module = new cApiModule();
106: if ((int) $_REQUEST['id'] > 0 && $module->moduleInUse((int) $_REQUEST['id'], true)) {
107: $template = new cTemplate();
108: $usedTemplates = $module->getUsedTemplates();
109: if (count($usedTemplates) > 0) {
110: foreach ($usedTemplates as $i => $usedTemplate) {
111: if ($i%2 == 0) {
112: $template->set('d', 'CLASS', 'grey');
113: } else {
114: $template->set('d', 'CLASS', 'white');
115: }
116:
117: $template->set('d', 'NAME', $usedTemplate['tpl_name']);
118: $template->next();
119: }
120:
121: $string = '<div class="inuse_info" >' . $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_lay_mod'], true) . '</div>';
122: } else {
123: $string = i18n('No data found!');
124: }
125: }
126: break;
127:
128: case 'inused_template':
129:
130: global $cfg;
131: cInclude('backend', 'includes/functions.tpl.php');
132:
133: if ((int) $_REQUEST['id'] > 0) {
134: $template = new cTemplate();
135: $template->reset();
136: $usedData = tplGetInUsedData((int) $_REQUEST['id']);
137:
138: if (isset($usedData['cat'])) {
139: $template->set('s', 'HEAD_TYPE', i18n('Category'));
140: foreach ($usedData['cat'] as $i => $cat) {
141: $template->set('d', 'ID', $cat['idcat']);
142: $template->set('d', 'LANG', $cat['lang']);
143: $template->set('d', 'NAME', $cat['name']);
144: $template->next();
145: }
146: $template->set('s', 'HEAD_ID', i18n('idcat'));
147: $template->set('s', 'HEAD_LANG', i18n('idlang'));
148: $template->set('s', 'HEAD_NAME', i18n('Name'));
149: $response = $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_tpl'], true);
150: }
151:
152: $template->reset();
153:
154: if (isset($usedData['art'])) {
155: $template->set('s', 'HEAD_TYPE', i18n('Article'));
156: foreach ($usedData['art'] as $i => $aArt) {
157: $template->set('d', 'ID', $aArt['idart']);
158: $template->set('d', 'LANG', $aArt['lang']);
159: $template->set('d', 'NAME', $aArt['title']);
160: $template->next();
161: }
162: $template->set('s', 'HEAD_ID', i18n('idart'));
163: $template->set('s', 'HEAD_LANG', i18n('idlang'));
164: $template->set('s', 'HEAD_NAME', i18n('Name'));
165: $response .= $template->generate($backendPath . $cfg['path']['templates'] . $cfg['templates']['inuse_tpl'], true);
166: }
167:
168: $string = '<div class="inuse_info" >' . $response . '</div>';
169: } else {
170: $string = i18n('No data found!');
171: }
172:
173: break;
174:
175: case 'scaleImage':
176: $filename_a = $_REQUEST['url'];
177: $filename = str_replace($frontendURL, $frontendPath, $filename_a);
178:
179:
180: $filetype = substr($filename, strlen($filename) - 4, 4);
181: switch (strtolower($filetype)) {
182: case '.gif':
183: $string = cApiImgScale($filename, 428, 210);
184: break;
185: case '.png':
186: $string = cApiImgScale($filename, 428, 210);
187: break;
188: case '.jpg':
189: $string = cApiImgScale($filename, 428, 210);
190: break;
191: case 'jpeg':
192: $string = cApiImgScale($filename, 428, 210);
193: break;
194: default:
195: $string = $filename_a;
196: break;
197: }
198:
199:
200: if ($string == '') {
201: $filename = str_replace($frontendPath,$frontendURL, $filename_a);
202: $string = $filename;
203: }
204: break;
205:
206: case 'imagelist':
207: global $cfg, $client, $lang, $cfgClient;
208:
209: $dirName = (string) $_REQUEST['dir'];
210: $imageId = (int) $_REQUEST['id'];
211: $idArtLang = (int) $_REQUEST['idartlang'];
212:
213: $art = new cApiArticleLanguage($idArtLang, true);
214: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
215: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
216:
217: $string = $image->generateFileSelect($dirName);
218: break;
219:
220: case 'loadImageMeta':
221: $imageId = (int) $_REQUEST['id'];
222: $idArtLang = (int) $_REQUEST['idartlang'];
223:
224: $art = new cApiArticleLanguage($idArtLang, true);
225: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
226: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
227:
228: $filename = (string) basename($_REQUEST['filename']);
229: $dirname = (string) dirname($_REQUEST['filename']);
230: if ($dirname != '.') {
231: $dirname .= '/';
232: } else {
233: $dirname = '';
234: }
235:
236: $string = $image->getImageMeta($filename, $dirname);
237: break;
238:
239: case 'upl_mkdir':
240: $imageId = (int) $_REQUEST['id'];
241: $idArtLang = (int) $_REQUEST['idartlang'];
242: $path = (string) $_REQUEST['path'];
243: $name = (string) $_REQUEST['foldername'];
244:
245: $art = new cApiArticleLanguage($idArtLang, true);
246: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
247: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
248:
249: $string = $image->uplmkdir($path, $name);
250: break;
251:
252: case 'upl_upload':
253: $imageId = (int) $_REQUEST['id'];
254: $idArtLang = (int) $_REQUEST['idartlang'];
255: $path = (string) $_REQUEST['path'];
256:
257: $art = new cApiArticleLanguage($idArtLang, true);
258: $artReturn = $art->getContent('CMS_IMGEDITOR', $imageId);
259: $image = new cContentTypeImgeditor($artReturn, $imageId, array());
260:
261: $string = $image->uplupload($path);
262: break;
263:
264: case 'linkeditorfilelist':
265: $id = (int) $_REQUEST['id'];
266: $idArtLang = (int) $_REQUEST['idartlang'];
267: $idCat = (string) $_REQUEST['idcat'];
268:
269: $art = new cApiArticleLanguage($idArtLang, true);
270: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
271: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
272:
273: $string = $linkEditor->generateArticleSelect($idCat);
274: break;
275:
276: case 'linkeditordirlist':
277: $id = (int) $_REQUEST['id'];
278: $idArtLang = (int) $_REQUEST['idartlang'];
279: $levelId = (string) $_REQUEST['level'];
280: $parentidcat = (string) $_REQUEST['parentidcat'];
281:
282: $art = new cApiArticleLanguage($idArtLang, true);
283: $artReturn = $art->getContent('CMS_LINKEDITOR', $id);
284: $linkEditor = new cContentTypeLinkeditor($artReturn, $id, array());
285:
286: $string = $linkEditor->getCategoryList($linkEditor->buildCategoryArray($levelId, $parentidcat));
287: break;
288:
289: case 'linkeditorimagelist':
290: $dirName = (string) $_REQUEST['dir'];
291: $id = (int) $_REQUEST['id'];
292: $idArtLang = (int) $_REQUEST['idartlang'];
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->getUploadFileSelect($dirName);
299: break;
300:
301: case 'generaljstranslations':
302: $translations = array();
303: $translations['Confirmation Required'] = i18n('Confirmation Required');
304: $translations['OK'] = i18n('OK');
305: $translations['Cancel'] = i18n('Cancel');
306: $string = json_encode($translations);
307: break;
308:
309: case 'logfilecontent':
310: $type = $_REQUEST['logfile'];
311: $numberOfLines = $_REQUEST['numberOfLines'];
312: $cfg = cRegistry::getConfig();
313: $filename = $cfg['path']['frontend'] . DS . $cfg['path']['logs'] . $type;
314: $string = cFileHandler::read($filename);
315: $lines = file($filename);
316: $lines = array_splice($lines, $numberOfLines * -1);
317: $string = implode('', $lines);
318: break;
319:
320: default:
321:
322: $string = 'Unknown Ajax Action';
323: break;
324: }
325:
326: return $string;
327: }
328:
329: }
330: