Some unneccessary parts removed because we have isInstalling() now
[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:: 856                                                    $ *
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 // Non-database functions
46 require("inc/functions.php");
47
48 // Load more function libraries or includes
49 foreach (array('request-functions', 'session-functions', 'config-functions', 'code-functions', 'filters', 'mysql-manager', 'extensions', 'db/lib', 'handler', 'hooks') as $lib) {
50         // Load special functions
51         LOAD_INC_ONCE(sprintf("inc/%s.php", $lib));
52 } // END - foreach
53
54 // Set error handler
55 set_error_handler('__errorHandler');
56
57 // Check if the user setups his MySQL stuff...
58 if ((empty($MySQL['login'])) && (!isInstalling()) && (!REQUEST_ISSET_GET('installing')) && (isInstalled())) {
59         // No login entered and outside installation mode
60         OUTPUT_HTML("<strong>{--LANG_WARNING--}:</strong> ");
61         if (isInstalled()) {
62                 // You have changed my configuration file!
63                 mxchange_die("{--DIE_CONFIG_CHANGED_YOU--}");
64         } else {
65                 // Please run the installation script (maybe again)
66                 mxchange_die("{--DIE_RUN_INSTALL_MYSQL--}");
67         }
68 } elseif ((!isInstalling()) && (empty($MySQL['password'])) && (isBooleanConstantAndTrue('warn_no_pass'))) {
69         // No database password entered!!!
70         OUTPUT_HTML("<div>{--LANG_WARNING--}:</div> {--WARN_NULL_PASSWORD--}");
71 }
72
73 // Set dummy config array
74 initConfig();
75
76 // Set important header_sent
77 $GLOBALS['header_sent'] = 0;
78
79 // Init fatal messages
80 initFatalMessages();
81
82 // Check if this file is writeable or read-only and warn the user
83 if ((!isInstalling()) && (isInstalled())) {
84         // Check for write-permission for config.php and inc directory
85         if (empty($GLOBALS['module'])) $GLOBALS['module'] = REQUEST_GET('module');
86         if (empty($GLOBALS['module'])) $GLOBALS['module'] = "index";
87
88         // CSS array
89         EXT_INIT_CSS_FILES();
90
91         if ((!empty($MySQL['host'])) && (!empty($MySQL['login'])) && (!empty($MySQL['password'])) && (!empty($MySQL['dbase']))) {
92                 // Connect to DB
93                 SQL_CONNECT($MySQL['host'], $MySQL['login'], $MySQL['password'], __FILE__, __LINE__);
94
95                 // Is the link valid?
96                 if (SQL_IS_LINK_UP()) {
97                         // Is it a valid resource?
98                         if (SQL_SELECT_DB($MySQL['dbase'], __FILE__, __LINE__) === true) {
99                                 // This is required for extension 'optimize' to work
100                                 define('__DB_NAME', $MySQL['dbase']);
101
102                                 // Remove MySQL array from namespace
103                                 unset($MySQL);
104
105                                 // Load configuration stuff
106                                 loadConfiguration();
107
108                                 // Init session
109                                 LOAD_INC_ONCE("inc/session.php");
110
111                                 // Load "databases" aka static arrays
112                                 LOAD_INC_ONCE("inc/databases.php");
113
114                                 // Loading patching system is required here...
115                                 LOAD_INC_ONCE("inc/patch-system.php"); // Initialize patch system
116
117                                 // Run daily reset
118                                 LOAD_INC_ONCE("inc/check-reset.php");
119
120                                 // Load admin include file if he is admin
121                                 if (IS_ADMIN()) {
122                                         // Administrative functions
123                                         LOAD_INC_ONCE("inc/modules/admin/admin-inc.php");
124                                 } // END - if
125                                 //* DEBUG: */ ADD_POINTS_REFSYSTEM("test", 36, 1000);
126                                 //* DEBUG: */ die();
127
128                                 // Get all values
129                                 if (($GLOBALS['output_mode'] != 1) && ($GLOBALS['output_mode'] != -1)) {
130                                         if (empty($GLOBALS['module']))  $GLOBALS['module'] = "empty";
131                                         if (empty($GLOBALS['what']))    $GLOBALS['what']   = GET_WHAT($GLOBALS['module']);
132                                         if (empty($GLOBALS['action']))  $GLOBALS['action'] = GET_ACTION($GLOBALS['module'], $GLOBALS['what']);
133                                 } else {
134                                         // Set action/what to empty
135                                         $GLOBALS['action'] = "";
136                                         $GLOBALS['what']   = "";
137                                 }
138
139                                 // Run the init filter chain
140                                 runFilterChain('init');
141
142                                 // Set default 'what' value
143                                 //* DEBUG: */ OUTPUT_HTML("-".$GLOBALS['module']."/".$GLOBALS['what']."-<br />");
144                                 if ((empty($GLOBALS['what'])) && (empty($GLOBALS['action'])) && ($GLOBALS['output_mode'] != 1) && ($GLOBALS['output_mode'] != -1)) {
145                                         if ($GLOBALS['module'] == "admin") {
146                                                 // Set 'action' value to 'login' in admin menu
147                                                 $GLOBALS['action'] = GET_ACTION($GLOBALS['module'], $GLOBALS['what']);
148                                         } elseif (($GLOBALS['module'] == "index") || ($GLOBALS['module'] == "login")) {
149                                                 // Set 'what' value to 'welcome' in guest and member menu
150                                                 $GLOBALS['what'] = "welcome";
151                                                 if (getConfig('index_home') != "") $GLOBALS['what'] = getConfig('index_home');
152                                         } else {
153                                                 // Anything else like begging link
154                                                 $GLOBALS['what'] = "";
155                                         }
156                                 } // END - if
157
158                                 // Update sending pool
159                                 if (($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) LOAD_INC_ONCE("inc/pool-update.php"); // Sends out mails in configureable steps
160
161                                 // Load all active extension including language files when not upgrading.
162                                 // Check module for testing and count one click
163                                 if (checkModulePermissions($GLOBALS['module']) == "done") countModuleHit($GLOBALS['module']);
164
165                                 // Shall we activate the exchange?
166                                 if (getConfig('activate_xchange') > 0) activateExchange();
167
168                                 // Is the extension sql_patches installed and at least 0.3.6?
169                                 if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
170                                         // Generate random number
171                                         define('RAND_NUMBER', generateRandomCodde(10, mt_rand(10000,32766), getUserId(), ""));
172                                 } else {
173                                         // Generate weak (!!!) code
174                                         define('RAND_NUMBER', mt_rand(1000000, 9999999));
175                                 }
176                         } else {
177                                 // Wrong database?
178                                 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
179                         }
180                 } else {
181                         // No link to database!
182                         addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
183                 }
184         } else {
185                 // Maybe you forgot to enter your MySQL data?
186                 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
187         }
188 } else {
189         ///////////////////////////////////////////////////
190         // Include neccessary functions for installation //
191         ///////////////////////////////////////////////////
192
193         // Set other missing variables
194         if (!isset($GLOBALS['output_mode'])) $GLOBALS['output_mode'] = "0";
195
196         // Init session
197         LOAD_INC_ONCE("inc/session.php");
198
199         // Include databases.php
200         LOAD_INC_ONCE("inc/databases.php");
201
202         // Check if we are in installation routine
203         if ((!isInstalling()) && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != -1)) {
204                 // Redirect to the installation system
205                 LOAD_URL("install.php");
206         } // END - if
207
208         // Double-check installation mode
209         if ((!isInstalled()) || (!isAdminRegistered())) {
210                 // Check for file permissions
211                 if (!IS_INC_WRITEABLE("config")) {
212                         addFatalMessage(__FILE__, __LINE__, getMessage('CONFIG_IS_WRITE_PROTECTED'));
213                 } // END - if
214                 if (!IS_INC_WRITEABLE("dummy")) {
215                         addFatalMessage(__FILE__, __LINE__, getMessage('DUMMY_IS_WRITE_PROTECTED'));
216                 } // END - if
217                 if (!IS_INC_WRITEABLE(".secret/dummy")) {
218                         addFatalMessage(__FILE__, __LINE__, getMessage('SECRET_IS_WRITE_PROTECTED'));
219                 } // END - if
220         } // END - if
221
222         // Run the init filter chain
223         runFilterChain('init');
224
225         // Load extension 'sql_patches'
226         LOAD_EXTENSION("sql_patches");
227 }
228
229 if ((getTotalFatalErrors() > 0) && (isInstalled()) && (!isInstalling()) && ($GLOBALS['output_mode'] != "1")) {
230         // One or more fatal error(s) occur during connect...
231         LOAD_INC_ONCE("inc/header.php");
232         LOAD_INC_ONCE("inc/fatal_errors.php");
233         LOAD_INC_ONCE("inc/footer.php");
234 } // END - if
235
236 //
237 ?>