config.php *must* now be extended
[mailer.git] / modules.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/25/2003 *
4  * ===============                              Last change: 07/01/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : modules.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Main loader file. Loads our needed stuff         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Hauptladedatei. Laedt alle benoetigten Dateien   *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // XDEBUG call
35 //xdebug_start_trace();
36
37 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
38 require("inc/libs/security_functions.php");
39
40 // Init "action" and "what"
41 $GLOBALS['startTime'] = microtime(true);
42 $GLOBALS['output_mode'] = 0;
43 $GLOBALS['what']   = "";
44 $GLOBALS['action'] = "";
45 $GLOBALS['userid'] = 0;
46 $GLOBALS['module'] = "";
47
48 // Needed include files
49 require("inc/config.php");
50
51 // Fix missing module to "index"
52 if (!REQUEST_ISSET_GET(('module'))) REQUEST_SET_GET('module', "index");
53
54 // Check if logged in
55 if (IS_MEMBER()) {
56         // Is still logged in so we welcome him with his name
57         $result = SQL_QUERY_ESC("SELECT surname, family FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
58          array($GLOBALS['userid']), __FILE__, __LINE__);
59         if (SQL_NUMROWS($result) == 1) {
60                 // Load surname and family's name and build the username
61                 list($s, $f) = SQL_FETCHROW($result);
62                 $username = $s." ".$f;
63
64                 // Additionally admin?
65                 if (IS_ADMIN()) {
66                         // Add it
67                         $username .= " ({--_ADMIN_SHORT--})";
68                 } // END - if
69         } else {
70                 // Hmmm, logged in and no valid userid?
71                 $username = "<em>{--_UNKNOWN--}</em>";
72
73                 // Destroy session
74                 destroy_user_session();
75
76                 // Kill userid
77                 $GLOBALS['userid'] = 0;
78         }
79
80         // Free memory
81         SQL_FREERESULT($result);
82 } elseif (IS_ADMIN()) {
83         // Admin is there
84         $username = getMessage('_ADMIN');
85 } else {
86         // He's a guest, hello there... ;-)
87         $username = getMessage('_GUEST');
88 }
89
90 // The header file
91 LOAD_INC_ONCE("inc/header.php");
92
93 // Modules are by default not valid!
94 $MOD_VALID = false; $check = "failed";
95 if ((getConfig('maintenance') == "Y") && (!IS_ADMIN()) && ($GLOBALS['module'] != "admin")) {
96         // Maintain mode is active and you are no admin
97         addFatalMessage(__FILE__, __LINE__, getMessage('LANG_DOWN_MAINTAINCE'));
98 } elseif ((SQL_IS_LINK_UP()) && (getTotalFatalErrors() == 0)) {
99         // Construct module name
100         define('__MODULE', sprintf("inc/modules/%s.php", SQL_ESCAPE($GLOBALS['module'])));
101
102         // Did we found the module listed in allowed modules and are we successfully connected?
103         $check = checkModulePermissions($GLOBALS['module']);
104         switch ($check)
105         {
106         case "admin_only":
107         case "mem_only":
108         case "done":
109                 // Does the module exists on local file system?
110                 if ((FILE_READABLE(constant('__MODULE'))) && (getTotalFatalErrors() == 0)) {
111                         // Module is valid, active and located on the local disc...
112                         $MOD_VALID = true;
113                 } elseif (!empty($URL)) {
114                         // An URL was specified so we load the de-referrer module
115                         LOAD_URL(DEREFERER($URL));
116                 } elseif (getTotalFatalErrors() == 0) {
117                         addFatalMessage(__FILE__, __LINE__, sprintf(getMessage('LANG_MOD_REG_404'), $GLOBALS['module']));
118                 }
119                 break;
120
121         case "404":
122                 addFatalMessage(__FILE__, __LINE__, sprintf(getMessage('LANG_MOD_REG_404'), $GLOBALS['module']));
123                 break;
124
125         case "locked":
126                 if (!FILE_READABLE(constant('__MODULE'))) {
127                         // Module does addionally not exists
128                         addFatalMessage(__FILE__, __LINE__, sprintf(getMessage('LANG_MOD_REG_404'), $GLOBALS['module']));
129                 } // END - if
130
131                 // Add fatal message
132                 addFatalMessage(__FILE__, __LINE__, sprintf(getMessage('LANG_MOD_REG_LOCKED'), $GLOBALS['module']));
133                 break;
134
135         default:
136                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s return from module check. Module=%s", $check, $GLOBALS['module']));
137                 addFatalMessage(__FILE__, __LINE__, sprintf(getMessage('LANG_MOD_REG_UNKNOWN'), $check));
138                 break;
139         }
140 } elseif (getTotalFatalErrors() == 0) {
141         // MySQL problems!
142         addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_ERRORS'));
143 }
144
145 if (($MOD_VALID) && (defined('__MODULE'))) {
146         /////////////////////////////////////////////
147         // Main including line DO NOT REMOVE/EDIT! //
148         /////////////////////////////////////////////
149         //
150         // Everything is okay so we can load the module
151         LOAD_INC_ONCE(constant('__MODULE'));
152 } // END - if
153
154 // Next-to-end add the footer
155 LOAD_INC_ONCE("inc/footer.php");
156
157 //
158 ?>