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