NULL, ); // Init call-back debug information $GLOBALS['ajax_callback_function'] = NULL; // Set content type (mostly JSON) setContentType('application/json'); // By default nothing is found/valid setHttpStatus('204 No Content'); // Set username setUsername('{--USERNAME_AJAX--}'); // In installation phase load ajax_installer.php if (isInstaller()) { // Load it loadIncludeOnce('inc/ajax/ajax_installer.php'); } // END - if } // Setter for AJAX reply content function setAjaxReplyContent ($content) { // Log message //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'content()=' . strlen($content)); // Set it, but with URL encoding $GLOBALS['ajax_reply']['reply_content'] = urlencode(doFinalCompilation($content, FALSE)); } /** * Checks whether the AJAX access level was valid. This function doesn't need * caching in $GLOBALS[__FUNCTION__] because it will be called only once. */ function isValidAjaxRequestLevel () { // By default nothing is valid $isValid = FALSE; // Switch on the 'level' value switch (postRequestElement('level')) { case 'install': // Installation phase level // Simply check for it $isValid = isInstaller(); break; case 'admin': // Admin area // Load admin includes loadIncludeOnce('inc/modules/admin/admin-inc.php'); loadIncludeOnce('inc/ajax/ajax_admin.php'); // Determine correct 'what' value $what = determineWhat(); // Get action value $action = getActionFromModuleWhat('admin', $what); // Check condition $isValid = ((isAdmin()) && (isAdminAllowedAccessMenu($action, $what))); break; default: // Unsupported level (please report this!) logDebugMessage(__FUNCTION__, __LINE__, 'Unsupported AJAX request access level ' . postRequestElement('level') . ' detected. Please report this, it means this part is not finished.'); break; } // END - switch // Return validation result return $isValid; } // Processes the AJAX request by generating a call-back on given 'level' value function processAjaxRequest () { // Generate the call-back function name $callbackName = 'doAjaxProcess' . capitalizeUnderscoreString(postRequestElement('level')); // Is the call-back function there? if (!function_exists($callbackName)) { // This shall not happen reportBug(__FUNCTION__, __LINE__, 'AJAX call-back ' . $callbackName . ' does not exist.'); } // END - if // Call the function call_user_func($callbackName); } // Send AJAX content function sendAjaxContent ($forceOutput = FALSE) { // Is the status fine or template not found (404)? if ((isAjaxHttpStatusAccepted()) || ($forceOutput === TRUE)) { // Then output the JSON outputHtml(encodeJson($GLOBALS['ajax_reply'])); } // END - if } // Checks whether the HTTP status is accepted function isAjaxHttpStatusAccepted () { // Is it accepted? $isAccepted = in_array(strtoupper(getHttpStatus()), array('200 OK', '404 NOT FOUND')); // Return it return $isAccepted; } // [EOF] ?>