e09f2dffa9ffce61c412081c06c18a6616a324ac
[mailer.git] / inc / ajax / ajax_admin.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/24/2012 *
4  * ===================                          Last change: 06/24/2012 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ajax_admin.php                                   *
8  * -------------------------------------------------------------------- *
9  * Short description : AJAX library for admin menu                      *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : AJAX-Bibliothek fuer Adminmenu                   *
12  * -------------------------------------------------------------------- *
13  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
14  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
15  * For more information visit: http://mxchange.org                      *
16  *                                                                      *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or    *
20  * (at your option) any later version.                                  *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
35         die();
36 } elseif ((!isAjaxOutputMode()) || (!isAdmin())) {
37         header('HTTP/1.1 403 Forbidden');
38         die(json_encode(array('reply_content' => 'Access forbidden'), JSON_FORCE_OBJECT));
39 } // END - if
40
41 // "Generates" admin content by loading a message template
42 function generateAdminContent () {
43         // Return it
44         return displayMessage('{--ADMIN_AJAX_MENU_IS_LOADING--}', TRUE);
45 }
46
47 // Processes AJAX requests for admin menu
48 function doAjaxProcessAdmin () {
49         // 'do' must always be set and isAdmin must be true
50         if (!isAdmin()) {
51                 // This shall not happen
52                 reportBug(__FUNCTION__, __LINE__, 'This AJAX request handler was called outside the admin menu.');
53         } elseif (!isPostRequestElementSet('do')) {
54                 // This shall not happen
55                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "do" which is fatal.');
56         } // END - if
57
58         // Again we do a call-back, so generate a function name depending on 'do'
59         $callbackName = 'doAjaxAdmin' . capitalizeUnderscoreString(postRequestElement('do'));
60         $GLOBALS['ajax_callback_function'] = $callbackName;
61
62         // Is the call-back function there?
63         if (!function_exists($callbackName)) {
64                 // This shall not happen
65                 reportBug(__FUNCTION__, __LINE__, 'AJAX call-back ' . $callbackName . ' does not exist.');
66         } // END - if
67
68         // Call the function
69         call_user_func($callbackName);
70
71         // Send AJAX content
72         sendAjaxContent();
73 }
74
75 // Processes admin AJAX calls for content-requests
76 function doAjaxAdminRequestContent () {
77         // 'tab' must be there
78         if (!isPostRequestElementSet('tab')) {
79                 // This shall not happen
80                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "tab" which is fatal.');
81         } // END - if
82
83         // Construct call-back name for value-preset
84         $callbackName = 'doAjaxPrepareAdmin' . capitalizeUnderscoreString(postRequestElement('tab'));
85
86         // Is the function there?
87         if (function_exists($callbackName)) {
88                 // Call it for setting values in session
89                 call_user_func($callbackName);
90         } else {
91                 // Log missing functions
92                 logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' does not exist.');
93         }
94
95         // Is the HTTP status still the same? (204 No Content)
96         if (getHttpStatus() == '204 No Content') {
97                 // We use the current access level 'install' as prefix and construct a template name
98                 setAjaxReplyContent(loadTemplate('admin_area_' . trim(postRequestElement('tab')), TRUE));
99
100                 // Has the template been loaded?
101                 if (isset($GLOBALS['template_content']['html']['admin_page_' . trim(postRequestElement('tab'))])) {
102                         // All okay if we reach this point
103                         setHttpStatus('200 OK');
104                 } else {
105                         // Set 404 error
106                         setHttpStatus('404 Not Found');
107                 }
108         } // END - if
109 }
110
111 // [EOF]
112 ?>