Mailer used in many places, we still need a good 'selling' title
[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  * 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         die();
42 } // END - if
43
44 // Load more function libraries or includes
45 foreach (array('functions', 'request-functions', 'session-functions', 'code-functions', 'language-functions', 'sql-functions', 'filter-functions', 'filters', 'mysql-manager', 'extensions-functions', 'handler') as $lib) {
46         // Load special functions
47         loadIncludeOnce('inc/' . $lib . '.php');
48 } // END - foreach
49
50 // Set error handler
51 set_error_handler('__errorHandler');
52
53 // Disable block-mode by default
54 enableBlockMode(false);
55
56 // Init error handler
57 initErrorHandler();
58
59 // Init request
60 initRequest();
61
62 // Init userid
63 initMemberId();
64
65 // Set important header_sent
66 if (!isset($GLOBALS['header_sent'])) $GLOBALS['header_sent'] = '0';
67
68 // Init fatal messages
69 initFatalMessages();
70
71 // Init message system
72 initMessages();
73
74 // Check if this file is writeable or read-only and warn the user
75 if (!isInstalling()) {
76         // Load configuration file(s) here
77         loadIncludeOnce('inc/load_config.php');
78
79         // Load database layer here
80         loadIncludeOnce('inc/db/lib.php');
81
82         // CSS array
83         initExtensionCssFiles();
84
85         if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['password'])) && (!empty($GLOBALS['mysql']['dbase']))) {
86                 // Connect to DB
87                 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
88
89                 // Is the link valid?
90                 if (SQL_IS_LINK_UP()) {
91                         // Enable exit on error
92                         enableExitOnError();
93
94                         // Is it a valid resource?
95                         if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
96                                 // This is required for extension 'optimize' to work
97                                 setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
98
99                                 // Remove MySQL array from namespace
100                                 unset($GLOBALS['mysql']);
101
102                                 // Load cache
103                                 loadIncludeOnce('inc/load_cache.php');
104
105                                 // Init filter system
106                                 initFilterSystem();
107
108                                 // Run the init filter chain
109                                 runFilterChain('init');
110
111                                 // Check module for permissions
112                                 $checkModule = checkModulePermissions();
113
114                                 // Admin module should be accessable by guests to login
115                                 if ((getModule() == 'admin') && ($checkModule == 'admin_only')) {
116                                         // This is fine and can be ignored
117                                 } elseif ($checkModule != 'done') {
118                                         // Not fine!
119                                         logDebugMessage(__FILE__, __LINE__, sprintf("Check of module %s results in unexpected value: %s",
120                                                 getModule(),
121                                                 $checkModule
122                                         ));
123                                 }
124                         } else {
125                                 // Wrong database?
126                                 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
127                         }
128                 } else {
129                         // No link to database!
130                         addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
131                 }
132         } else {
133                 // Maybe you forgot to enter your MySQL data?
134                 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
135         }
136 } else {
137         ///////////////////////////////////////////////////
138         // Include neccessary functions for installation //
139         ///////////////////////////////////////////////////
140
141         // Default output is 'direct' for HTML output
142         setConfigEntry('OUTPUT_MODE', 'direct');
143
144         // This hack prevents a backtrace in CSS output
145         if (getOutputMode() == 1) {
146                 // Problem with config so set output mode
147                 setConfigEntry('OUTPUT_MODE', 'render');
148         } // END - if
149
150         // CFG: DATABASE-TYPE
151         setConfigEntry('_DB_TYPE', 'mysql3');
152
153         // Include more
154         foreach (array('inc/databases.php','inc/versions.php','inc/db/lib.php','inc/session.php','inc/install-functions.php','inc/load_config.php') as $inc) {
155                 // Load the include
156                 loadIncludeOnce($inc);
157         } // END - foreach
158
159         // Load config
160         loadIncludeOnce('inc/load_config.php');
161
162         // Are we installation routine?
163         if ((!isInstalling()) && (getOutputMode() != 1) && (getOutputMode() != -1)) {
164                 // You have to install first!
165                 redirectToUrl('install.php');
166         } // END - if
167
168         // Init filter system here
169         initFilterSystem();
170
171         // Load cache
172         loadIncludeOnce('inc/load_cache.php');
173
174         // Run the init filter chain
175         runFilterChain('init');
176 }
177
178 // Handle fatal errors
179 runFilterChain('handle_fatal_errors');
180
181 // [EOF]
182 ?>