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