Rewritten
[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
47 // Needed include files
48 require("inc/config.php");
49
50 // Fix missing module to "index"
51 if (!REQUEST_ISSET_GET(('module'))) REQUEST_SET_GET('module', "index");
52
53 // Secure action/what if present
54 if (REQUEST_ISSET_GET(('action'))) $GLOBALS['action'] = secureString(REQUEST_GET('action'));
55 if (REQUEST_ISSET_GET(('what')))   $GLOBALS['what']   = secureString(REQUEST_GET('what'));
56
57 // Secure the module name (very important line!)
58 $GLOBALS['module'] = secureString(REQUEST_GET('module'));
59
60 // Check if logged in
61 if (IS_MEMBER()) {
62         // Is still logged in so we welcome him with his name
63         $result = SQL_QUERY_ESC("SELECT surname, family FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
64          array($GLOBALS['userid']), __FILE__, __LINE__);
65         if (SQL_NUMROWS($result) == 1) {
66                 // Load surname and family's name and build the username
67                 list($s, $f) = SQL_FETCHROW($result);
68                 $username = $s." ".$f;
69
70                 // Additionally admin?
71                 if (IS_ADMIN()) {
72                         // Add it
73                         $username .= " ({!_ADMIN_SHORT!})";
74                 } // END - if
75         } else {
76                 // Hmmm, logged in and no valid userid?
77                 $username = "<em>{!_UNKNOWN!}</em>";
78
79                 // Destroy session
80                 destroy_user_session();
81
82                 // Kill userid
83                 $GLOBALS['userid'] = 0;
84         }
85
86         // Free memory
87         SQL_FREERESULT($result);
88 } elseif (IS_ADMIN()) {
89         // Admin is there
90         $username = getMessage('_ADMIN');
91 } else {
92         // He's a guest, hello there... ;-)
93         $username = getMessage('_GUEST');
94 }
95
96 // The header file
97 LOAD_INC_ONCE("inc/header.php");
98
99 // Modules are by default not valid!
100 $MOD_VALID = false; $check = "failed";
101 if ((getConfig('maintenance') == "Y") && (!IS_ADMIN()) && ($GLOBALS['module'] != "admin")) {
102         // Maintain mode is active and you are no admin
103         addFatalMessage(getMessage('LANG_DOWN_MAINTAINCE'));
104 } elseif ((SQL_IS_LINK_UP()) && (getTotalFatalErrors() == 0)) {
105         // Construct module name
106         define('__MODULE', sprintf("inc/modules/%s.php", SQL_ESCAPE($GLOBALS['module'])));
107
108         // Did we found the module listed in allowed modules and are we successfully connected?
109         $check = CHECK_MODULE($GLOBALS['module']);
110         switch ($check)
111         {
112         case "admin_only":
113         case "mem_only":
114         case "done":
115                 // Does the module exists on local file system?
116                 if ((FILE_READABLE(constant('__MODULE'))) && (getTotalFatalErrors() == 0)) {
117                         // Module is valid, active and located on the local disc...
118                         $MOD_VALID = true;
119                 } elseif (!empty($URL)) {
120                         // An URL was specified so we load the de-referrer module
121                         LOAD_URL(DEREFERER($URL));
122                 } elseif (getTotalFatalErrors() == 0) {
123                         addFatalMessage(sprintf(getMessage('LANG_MOD_REG_404'), $GLOBALS['module']));
124                 }
125                 break;
126
127         case "404":
128                 addFatalMessage(sprintf(getMessage('LANG_MOD_REG_404'), $GLOBALS['module']));
129                 break;
130
131         case "locked":
132                 if (!FILE_READABLE(constant('__MODULE'))) {
133                         // Module does addionally not exists
134                         addFatalMessage(sprintf(getMessage('LANG_MOD_REG_404'), $GLOBALS['module']));
135                 } // END - if
136
137                 // Add fatal message
138                 addFatalMessage(sprintf(getMessage('LANG_MOD_REG_LOCKED'), $GLOBALS['module']));
139                 break;
140
141         default:
142                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown status %s return from module check. Module=%s", $check, $GLOBALS['module']));
143                 addFatalMessage(sprintf(getMessage('LANG_MOD_REG_UNKNOWN'), $check));
144                 break;
145         }
146 } elseif (getTotalFatalErrors() == 0) {
147         // MySQL problems!
148         addFatalMessage(getMessage('MYSQL_ERRORS'));
149 }
150
151 if (($MOD_VALID) && (defined('__MODULE'))) {
152         /////////////////////////////////////////////
153         // Main including line DO NOT REMOVE/EDIT! //
154         /////////////////////////////////////////////
155         //
156         // Everything is okay so we can load the module
157         LOAD_INC_ONCE(constant('__MODULE'));
158 } // END - if
159
160 // Next-to-end add the footer
161 LOAD_INC_ONCE("inc/footer.php");
162
163 //
164 ?>