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