Refactured
[mailer.git] / 0.2.1 / modules.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 08/25/2003 *\r
4  * ===============                              Last change: 07/01/2005 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : modules.php                                      *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : Main loader file. Loads our needed stuff         *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : Hauptladedatei. L�dt alle ben�tigten Dateien     *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // APD call (if you have this apache extension and want to debug this script for us)\r
35 //apd_set_pprof_trace();\r
36 \r
37 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )\r
38 require_once ("inc/libs/security_functions.php");\r
39 \r
40 // Init "action" and "what"\r
41 global $what, $action;\r
42 $CSS = 0;\r
43 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";\r
44 $GLOBALS['userid'] = 0;\r
45 if (!empty($_GET['action'])) $GLOBALS['action'] = trim(strip_tags($_GET['action']));\r
46 if (!empty($_GET['what'])) $GLOBALS['what'] = trim(strip_tags($_GET['what']));\r
47 \r
48 // Secure the module name (very important line!)\r
49 $GLOBALS['module'] = htmlentities(strip_tags($_GET['module']), ENT_QUOTES);\r
50 \r
51 // Needed include files\r
52 require ("inc/config.php");\r
53 \r
54 // Check if logged in\r
55 if (IS_LOGGED_IN())\r
56 {\r
57         // Is still logged in so we welcome him with his name\r
58         $result = SQL_QUERY_ESC("SELECT surname, family FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",\r
59          array($GLOBALS['userid']), __FILE__, __LINE__);\r
60         if (SQL_NUMROWS($result) == 1)\r
61         {\r
62                 // Load surname and family's name and build the username\r
63                 list($s, $f) = SQL_FETCHROW($result);\r
64                 $username = $s." ".$f;\r
65 \r
66                 // Update only cookies and no login data!\r
67                 UPDATE_LOGIN_DATA(false);\r
68         }\r
69          else\r
70         {\r
71 \r
72                 // Hmmm, logged in and no valid cookies???\r
73                 $username = "<I>"._UNKNOWN."</I>";\r
74         }\r
75 \r
76         // Free memory\r
77         SQL_FREERESULT($result);\r
78 }\r
79  elseif (IS_ADMIN())\r
80 {\r
81         $username = _ADMIN;\r
82 }\r
83  else\r
84 {\r
85         // He's a guest, hello there... ;-)\r
86         $username = _GUEST;\r
87 }\r
88 \r
89 // The header file\r
90 include (PATH."inc/header.php");\r
91 \r
92 // Modules are by default not valid!\r
93 $MOD_VALID = false; $check = "failed";\r
94 if ((!empty($CONFIG['maintenance'])) && ($CONFIG['maintenance'] == "Y") && (!IS_ADMIN()) && ($GLOBALS['module'] != "admin"))\r
95 {\r
96         // Maintain mode is active and you are no admin\r
97         ADD_FATAL(LANG_DOWN_MAINTAINCE);\r
98 }\r
99  elseif (($link) && ($db) && (sizeof($FATAL) == 0))\r
100 {\r
101         // Did we found the module listed in allowed modules and are we successfully connected?\r
102         $check = CHECK_MODULE($GLOBALS['module']);\r
103         switch ($check)\r
104         {\r
105         case "admin_only":\r
106         case "mem_only":\r
107         case "done":\r
108                 // Construct module name\r
109                 define('__MODULE', sprintf(PATH."inc/modules/%s.php", $GLOBALS['module']));\r
110 \r
111                 // Does the module exists on local file system?\r
112                 if (((file_exists(__MODULE)) || (!empty($URL))) && (sizeof($FATAL) == 0))\r
113                 {\r
114                         // Module is valid, active and located on the local disc...\r
115                         $MOD_VALID = true;\r
116                 }\r
117                  elseif (!empty($URL))\r
118                 {\r
119                         // An URL was specified so we load the de-referrer module\r
120                         include (PATH."inc/loader.php");\r
121                 }\r
122                  elseif (sizeof($FATAL) == 0)\r
123                 {\r
124                         ADD_FATAL(LANG_MOD_REG_404_1.$GLOBALS['module'].LANG_MOD_REG_404_2);\r
125                 }\r
126                 break;\r
127 \r
128         case "404":\r
129                 ADD_FATAL(LLANG_MOD_REG_404_1.$GLOBALS['module'].LANG_MOD_REG_404_2);\r
130                 break;\r
131 \r
132         case "locked":\r
133                 if (!file_exists(PATH."inc/modules/".$GLOBALS['module'].".php"))\r
134                 {\r
135                         // Module does addionally not exists\r
136                         ADD_FATAL(LANG_MOD_REG_404_1.$GLOBALS['module'].LANG_MOD_REG_404_2);\r
137                 }\r
138                 ADD_FATAL(LANG_MOD_LOCKED_1.$GLOBALS['module'].LANG_MOD_LOCKED_2);\r
139                 break;\r
140 \r
141         default:\r
142                 ADD_FATAL(LANG_MOD_UNKNOWN_1.$check.LANG_MOD_UNKNOWN_2);\r
143                 break;\r
144         }\r
145 }\r
146  elseif (sizeof($FATAL) == 0)\r
147 {\r
148         // MySQL problems!\r
149         ADD_FATAL(MYSQL_ERRORS);\r
150 }\r
151 \r
152 if ($MOD_VALID)\r
153 {\r
154         /////////////////////////////////////////////\r
155         // Main including line DO NOT REMOVE/EDIT! //\r
156         /////////////////////////////////////////////\r
157         //\r
158         // Everything is okay so we can load the module\r
159         include (__MODULE);\r
160 }\r
161 \r
162 // Next-to-end add the footer\r
163 include (PATH."inc/footer.php");\r
164 \r
165 //\r
166 ?>\r