aa55cdabe20c87a650527a9cd0ecd9b207a89949
[mailer.git] / 0.2.1 / 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 // APD call (if you have this apache extension and want to debug this script for us)
35 //apd_set_pprof_trace();
36
37 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
38 require_once ("inc/libs/security_functions.php");
39
40 // Init "action" and "what"
41 global $what, $action;
42 $CSS = 0;
43 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
44 $GLOBALS['userid'] = 0;
45 if (!empty($_GET['action'])) $GLOBALS['action'] = secureString($_GET['action']);
46 if (!empty($_GET['what'])) $GLOBALS['what'] = secureString($_GET['what']);
47
48 // Secure the module name (very important line!)
49 $GLOBALS['module'] = htmlentities(strip_tags($_GET['module']), ENT_QUOTES);
50
51 // Needed include files
52 require ("inc/config.php");
53
54 // Check if logged in
55 if (IS_LOGGED_IN())
56 {
57         // Is still logged in so we welcome him with his name
58         $result = SQL_QUERY_ESC("SELECT surname, family FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
59          array($GLOBALS['userid']), __FILE__, __LINE__);
60         if (SQL_NUMROWS($result) == 1)
61         {
62                 // Load surname and family's name and build the username
63                 list($s, $f) = SQL_FETCHROW($result);
64                 $username = $s." ".$f;
65
66                 // Update only cookies and no login data!
67                 UPDATE_LOGIN_DATA(false);
68         }
69          else
70         {
71
72                 // Hmmm, logged in and no valid cookies???
73                 $username = "<I>"._UNKNOWN."</I>";
74         }
75
76         // Free memory
77         SQL_FREERESULT($result);
78 }
79  elseif (IS_ADMIN())
80 {
81         $username = _ADMIN;
82 }
83  else
84 {
85         // He's a guest, hello there... ;-)
86         $username = _GUEST;
87 }
88
89 // The header file
90 include (PATH."inc/header.php");
91
92 // Modules are by default not valid!
93 $MOD_VALID = false; $check = "failed";
94 if ((!empty($CONFIG['maintenance'])) && ($CONFIG['maintenance'] == "Y") && (!IS_ADMIN()) && ($GLOBALS['module'] != "admin"))
95 {
96         // Maintain mode is active and you are no admin
97         ADD_FATAL(LANG_DOWN_MAINTAINCE);
98 }
99  elseif (($link) && ($db) && (sizeof($FATAL) == 0))
100 {
101         // Did we found the module listed in allowed modules and are we successfully connected?
102         $check = CHECK_MODULE($GLOBALS['module']);
103         switch ($check)
104         {
105         case "admin_only":
106         case "mem_only":
107         case "done":
108                 // Construct module name
109                 define('__MODULE', sprintf(PATH."inc/modules/%s.php", $GLOBALS['module']));
110
111                 // Does the module exists on local file system?
112                 if (((file_exists(__MODULE)) || (!empty($URL))) && (sizeof($FATAL) == 0))
113                 {
114                         // Module is valid, active and located on the local disc...
115                         $MOD_VALID = true;
116                 }
117                  elseif (!empty($URL))
118                 {
119                         // An URL was specified so we load the de-referrer module
120                         include (PATH."inc/loader.php");
121                 }
122                  elseif (sizeof($FATAL) == 0)
123                 {
124                         ADD_FATAL(LANG_MOD_REG_404_1.$GLOBALS['module'].LANG_MOD_REG_404_2);
125                 }
126                 break;
127
128         case "404":
129                 ADD_FATAL(LANG_MOD_REG_404_1.$GLOBALS['module'].LANG_MOD_REG_404_2);
130                 break;
131
132         case "locked":
133                 if (!file_exists(PATH."inc/modules/".$GLOBALS['module'].".php"))
134                 {
135                         // Module does addionally not exists
136                         ADD_FATAL(LANG_MOD_REG_404_1.$GLOBALS['module'].LANG_MOD_REG_404_2);
137                 }
138                 ADD_FATAL(LANG_MOD_LOCKED_1.$GLOBALS['module'].LANG_MOD_LOCKED_2);
139                 break;
140
141         default:
142                 ADD_FATAL(LANG_MOD_UNKNOWN_1.$check.LANG_MOD_UNKNOWN_2);
143                 break;
144         }
145 }
146  elseif (sizeof($FATAL) == 0)
147 {
148         // MySQL problems!
149         ADD_FATAL(MYSQL_ERRORS);
150 }
151
152 if ($MOD_VALID)
153 {
154         /////////////////////////////////////////////
155         // Main including line DO NOT REMOVE/EDIT! //
156         /////////////////////////////////////////////
157         //
158         // Everything is okay so we can load the module
159         include (__MODULE);
160 }
161
162 // Next-to-end add the footer
163 include (PATH."inc/footer.php");
164
165 //
166 ?>