Several more constants rewritten to getConfig()
[mailer.git] / inc / mysql-connect.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/16/2003 *
4  * ===============                              Last change: 12/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : mysql-connect.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Connects to your database                        *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Verbindet zu Ihrer Datenbank                     *
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 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Load more function libraries or includes
46 foreach (array('functions', 'request-functions', 'session-functions', 'code-functions', 'inc-functions', 'language-functions', 'filters', 'mysql-manager', 'extensions', 'handler', 'hooks') as $lib) {
47         // Load special functions
48         loadIncludeOnce('inc/' . $lib . '.php');
49 } // END - foreach
50
51 // Set error handler
52 set_error_handler('__errorHandler');
53
54 // Disable block-mode by default
55 enableBlockMode(false);
56
57 // Init error handler
58 initErrorHandler();
59
60 // Init request
61 initRequest();
62
63 // Set important header_sent
64 if (!isset($GLOBALS['header_sent'])) $GLOBALS['header_sent'] = 0;
65
66 // Init fatal messages
67 initFatalMessages();
68
69 // Check if this file is writeable or read-only and warn the user
70 if ((!isInstalling()) && (isInstalled())) {
71         // Load "databases" aka static arrays
72         loadIncludeOnce('inc/databases.php');
73
74         // Load configuration file(s) here
75         loadIncludeOnce('inc/load_config.php');
76
77         // Load database layer here
78         loadIncludeOnce('inc/db/lib.php');
79
80         // Check for write-permission for config.php and inc directory
81         if (!isModuleSet()) setModule(REQUEST_GET('module'));
82         if (!isModuleSet()) setModule('index');
83
84         // CSS array
85         EXT_INIT_CSS_FILES();
86
87         if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['password'])) && (!empty($GLOBALS['mysql']['dbase']))) {
88                 // Connect to DB
89                 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
90
91                 // Is the link valid?
92                 if (SQL_IS_LINK_UP()) {
93                         // Enable exit on error
94                         enableExitOnError();
95
96                         // Is it a valid resource?
97                         if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
98                                 // This is required for extension 'optimize' to work
99                                 define('__DB_NAME', $GLOBALS['mysql']['dbase']);
100
101                                 // Remove MySQL array from namespace
102                                 unset($GLOBALS['mysql']);
103
104                                 // Load configuration stuff
105                                 loadConfiguration();
106
107                                 // Init session
108                                 loadIncludeOnce('inc/session.php');
109
110                                 // Load versions
111                                 loadIncludeOnce('inc/versions.php');
112
113                                 // Loading patching system is required here...
114                                 loadIncludeOnce('inc/patch-system.php');
115
116                                 // Run daily reset
117                                 loadIncludeOnce('inc/check-reset.php');
118
119                                 // Load admin include file if he is admin
120                                 if (IS_ADMIN()) {
121                                         // Administrative functions
122                                         loadIncludeOnce('inc/modules/admin/admin-inc.php');
123                                 } // END - if
124                                 //* DEBUG: */ ADD_POINTS_REFSYSTEM('test', 36, 1000);
125                                 //* DEBUG: */ die();
126
127                                 // Get all values
128                                 if ((getOutputMode() != 1) && (getOutputMode() != -1)) {
129                                         if (!isModuleSet())  setModule('empty');
130                                         if (!isWhatSet())    setWhat(getWhatFromModule(getModule()));
131                                         if (!isActionSet())  setAction(getModeAction(getModule(), getWhat()));
132                                 } else {
133                                         // Set action/what to empty
134                                         setAction('');
135                                         setWhat('');
136                                 }
137
138                                 // Run the init filter chain
139                                 runFilterChain('init');
140
141                                 // Set default 'what' value
142                                 //* DEBUG: */ OUTPUT_HTML('-'.getModule().'/'.getWhat()."-<br />");
143                                 if ((!isWhatSet()) && (!isActionSet()) && (getOutputMode() != 1) && (getOutputMode() != -1)) {
144                                         if (getModule() == 'admin') {
145                                                 // Set 'action' value to 'login' in admin menu
146                                                 setAction(getModeAction(getModule(), getWhat()));
147                                         } elseif ((getModule() == 'index') || (getModule() == 'login')) {
148                                                 // Set 'what' value to 'welcome' in guest and member menu
149                                                 setWhat('welcome');
150                                                 if (getConfig('index_home') != '') setWhatFromConfig('index_home');
151                                         } else {
152                                                 // Anything else like begging link
153                                                 setWhat('');
154                                         }
155                                 } // END - if
156
157                                 // Update sending pool
158                                 if ((getOutputMode() != '1') && (getOutputMode() != '-1')) loadIncludeOnce('inc/pool-update.php'); // Sends out mails in configureable steps
159
160                                 // Check module for permissions
161                                 $checkModule = checkModulePermissions(getModule());
162                                 if ($checkModule != 'done') {
163                                         // Not fine!
164                                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Check of module %s results in unpexted value: %s",
165                                                 getModule(),
166                                                 $checkModule
167                                         ));
168                                 } // END - if
169
170                                 // Shall we activate the exchange?
171                                 if (getConfig('activate_xchange') > 0) activateExchange();
172
173                                 // Is the extension sql_patches installed and at least 0.3.6?
174                                 if (GET_EXT_VERSION('sql_patches') >= '0.3.6') {
175                                         // Generate random number
176                                         setConfigEntry('RAND_NUMBER', generateRandomCode(10, mt_rand(10000, 32766), getUserId(), ''));
177                                 } else {
178                                         // Generate weak (!!!) code
179                                         setConfigEntry('RAND_NUMBER', mt_rand(1000000, 9999999));
180                                 }
181                         } else {
182                                 // Wrong database?
183                                 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
184                         }
185                 } else {
186                         // No link to database!
187                         addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
188                 }
189         } else {
190                 // Maybe you forgot to enter your MySQL data?
191                 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
192         }
193 } else {
194         ///////////////////////////////////////////////////
195         // Include neccessary functions for installation //
196         ///////////////////////////////////////////////////
197
198         // Default output is 'direct' for HTML output
199         setConfigEntry('OUTPUT_MODE', 'direct');
200
201         // This hack prevents a backtrace in CSS output
202         if (getOutputMode() == '1') {
203                 // Problem with config so set output mode
204                 setConfigEntry('OUTPUT_MODE', 'render');
205         } // END - if
206
207         // Set other missing variables
208         if (!isOutputModeSet()) setOutputMode('0');
209
210         // Include databases.php
211         loadIncludeOnce('inc/databases.php');
212
213         // Init session
214         loadIncludeOnce('inc/session.php');
215
216         // Load versions
217         loadIncludeOnce('inc/versions.php');
218
219         // Check if we are in installation routine
220         if ((!isInstalling()) && (getOutputMode() != '1') && (getOutputMode() != -1)) {
221                 // Redirect to the installation system
222                 redirectToUrl('install.php');
223         } // END - if
224
225         // Double-check installation mode
226         if ((!isInstalled()) || (!isAdminRegistered())) {
227                 // Check for file permissions
228                 if (!isIncludeWriteable('config')) {
229                         addFatalMessage(__FILE__, __LINE__, getMessage('CONFIG_IS_WRITE_PROTECTED'));
230                 } // END - if
231                 if (!isIncludeWriteable('dummy')) {
232                         addFatalMessage(__FILE__, __LINE__, getMessage('DUMMY_IS_WRITE_PROTECTED'));
233                 } // END - if
234                 if (!isIncludeWriteable('.secret/dummy')) {
235                         addFatalMessage(__FILE__, __LINE__, getMessage('SECRET_IS_WRITE_PROTECTED'));
236                 } // END - if
237         } // END - if
238
239         // Run the init filter chain
240         runFilterChain('init');
241
242         // Load extension 'sql_patches'
243         LOAD_EXTENSION('sql_patches');
244
245         // Load configuration file(s) here
246         loadIncludeOnce('inc/load_config.php');
247 }
248
249 // Init session
250 loadIncludeOnce('inc/session.php');
251
252 // Load versions
253 loadIncludeOnce('inc/versions.php');
254
255 if ((getTotalFatalErrors() > 0) && (isInstalled()) && (!isInstalling()) && (getOutputMode() != '1')) {
256         // One or more fatal error(s) occur during connect...
257         loadIncludeOnce('inc/header.php');
258         loadIncludeOnce('inc/fatal_errors.php');
259         loadIncludeOnce('inc/footer.php');
260 } // END - if
261
262 //
263 ?>