Reverted of changes in 1704, see ticket #160
[mailer.git] / inc / mysql-connect.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } // END - if
44
45 // Load more function libraries or includes
46 foreach (array('request-functions', 'session-functions', 'code-functions', 'language-functions', 'sql-functions', 'expression-functions', 'filter-functions','revision-functions', 'filters', 'mysql-manager', 'extensions-functions', 'handler') 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 // Init userid
64 initMemberId();
65
66 // Set important header_sent
67 if (!isset($GLOBALS['header_sent'])) $GLOBALS['header_sent'] = '0';
68
69 // Init fatal messages
70 initFatalMessages();
71
72 // Init message system
73 initMessages();
74
75 // Are we in installation phase?
76 if ((!isInstalling()) && (!isInstallationPhase())) {
77         // Load configuration file(s) here
78         loadIncludeOnce('inc/load_config.php');
79
80         // Load database layer here
81         loadIncludeOnce('inc/db/lib.php');
82
83         // CSS array
84         initExtensionCssFiles();
85
86         if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['password'])) && (!empty($GLOBALS['mysql']['dbase']))) {
87                 // Connect to DB
88                 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
89
90                 // Is the link valid?
91                 if (SQL_IS_LINK_UP()) {
92                         // Enable exit on error
93                         enableExitOnError();
94
95                         // Is it a valid resource?
96                         if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
97                                 // This is required for extension 'optimize' to work
98                                 setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
99
100                                 // Remove MySQL array from namespace
101                                 unset($GLOBALS['mysql']);
102
103                                 // Load cache
104                                 loadIncludeOnce('inc/load_cache.php');
105
106                                 // Check module for permissions
107                                 $checkModule = checkModulePermissions();
108
109                                 // Admin module should be accessable by guests to login
110                                 if ((getModule() == 'admin') && ($checkModule == 'admin_only')) {
111                                         // This is fine and can be ignored
112                                 } elseif ($checkModule != 'done') {
113                                         // Not fine!
114                                         logDebugMessage(__FILE__, __LINE__, sprintf("Check of module %s results in unexpected value: %s",
115                                                 getModule(),
116                                                 $checkModule
117                                         ));
118                                 }
119                         } else {
120                                 // Wrong database?
121                                 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
122                         }
123                 } else {
124                         // No link to database!
125                         addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
126                 }
127         } else {
128                 // Maybe you forgot to enter your MySQL data?
129                 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
130         }
131 } else {
132         ///////////////////////////////////////////////////
133         // Include neccessary functions for installation //
134         ///////////////////////////////////////////////////
135
136         // Default output is 'direct' for HTML output
137         setConfigEntry('OUTPUT_MODE', 'direct');
138
139         // This hack prevents a backtrace in CSS output
140         if (getOutputMode() == 1) {
141                 // Problem with config so set output mode
142                 setConfigEntry('OUTPUT_MODE', 'render');
143         } // END - if
144
145         // CFG: DATABASE-TYPE
146         setConfigEntry('_DB_TYPE', 'mysql3');
147
148         // Include more
149         foreach (array('inc/db/lib.php','inc/databases.php','inc/session.php','inc/versions.php','inc/install-functions.php','inc/load_config.php') as $inc) {
150                 // Load the include
151                 loadIncludeOnce($inc);
152         } // END - foreach
153
154         // Init filter system here
155         initFilterSystem();
156
157         // Are we installation routine?
158         if ((!isInstalling()) && (getOutputMode() != 1) && (getOutputMode() != -1)) {
159                 // You have to install first!
160                 redirectToUrl('install.php');
161         } // END - if
162
163         // Load cache
164         loadIncludeOnce('inc/load_cache.php');
165
166         // Run the init filter chain
167         runFilterChain('init');
168 }
169
170 // Handle fatal errors
171 runFilterChain('handle_fatal_errors');
172
173 // [EOF]
174 ?>