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