+// Load the currently set module
+function loadModule () {
+ // By default all modules are invalid
+ $isModuleValid = FALSE;
+
+ // Construct module name
+ $GLOBALS['module_inc'] = sprintf("inc/modules/%s.php", getModule());
+
+ // Check module permission (again)
+ $moduleState = checkModulePermissions();
+
+ // Which permission/error state do we have?
+ switch ($moduleState) {
+ case 'cache_miss': // The cache is gone
+ case 'admin_only': // Admin-only access
+ case 'mem_only': // Member-only access
+ case 'done': // All fine!
+ // Does the module exists on local file system?
+ if ((isIncludeReadable($GLOBALS['module_inc'])) && (!ifFatalErrorsDetected())) {
+ // Module is valid, active and located on the local disk...
+ $isModuleValid = TRUE;
+ } elseif (!ifFatalErrorsDetected()) {
+ // Set HTTP status
+ setHttpStatus('404');
+
+ // Module not found
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_404--}');
+
+ // Set module to error module (non-existent!)
+ setModule('error');
+ }
+ break;
+
+ case '404':
+ // Set HTTP status
+ setHttpStatus('404');
+
+ // Add fatal message
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_404--}');
+ break;
+
+ case 'locked':
+ // Set HTTP status
+ setHttpStatus('403 Forbidden');
+
+ if (!isIncludeReadable($GLOBALS['module_inc'])) {
+ // Set HTTP status again
+ setHttpStatus('404 Not Found');
+
+ // Module does addionally not exists
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_LOCKED_404--}');
+ } // END - if
+
+ // Add fatal message
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MODULE_REGISTRY_IS_LOCKED--}');
+ break;
+
+ default:
+ // Unknown module status
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s return from module check. Module=%s", $moduleState, getModule()));
+ addFatalMessage(__FUNCTION__, __LINE__, '{%message,UNKNOWN_MODULE_STATUS=' . $moduleState . '%}');
+ break;
+ } // END - switch
+
+ // Return status
+ return $isModuleValid;
+}
+
+// Include module
+function doIncludeModule () {
+ // Set content type
+ setContentType('text/html');
+
+ // The header file
+ loadIncludeOnce('inc/header.php');
+
+ // Modules are by default not valid!
+ $isModuleValid = FALSE;
+
+ // By default NULL is used
+ $GLOBALS['module_inc'] = NULL;
+
+ // Is the maintenance mode active or goes all well?
+ if ((isExtensionActive('maintenance')) && (isMaintenanceEnabled()) && (!isAdmin()) && (getModule() != 'admin')) {
+ // Maintain mode is active and you are no admin
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MAILER_DOWN_FOR_MAINTENANCE--}');
+ } elseif ((SQL_IS_LINK_UP()) && (!ifFatalErrorsDetected())) {
+ // Do the small "load module" call
+ $isModuleValid = loadModule();
+ } elseif (!ifFatalErrorsDetected()) {
+ // SQL problems detected
+ addFatalMessage(__FUNCTION__, __LINE__, '{--MYSQL_ERRORS--}');
+ }
+
+ // Is the module valid?
+ if (($isModuleValid === TRUE) && (!is_null($GLOBALS['module_inc']))) {
+ // Run pre-filter
+ runFilterChain('pre_module_load');
+
+ // Everything is okay so we can load the module
+ loadIncludeOnce($GLOBALS['module_inc']);
+
+ // Run post-filter
+ runFilterChain('post_module_load');
+ } // END - if
+
+ // Add the footer (this will call doShutdown())
+ loadIncludeOnce('inc/footer.php');
+}
+