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