API functions renamed:
[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 // Enable HTML templates by default
76 enableTemplateHtml();
77
78 // Are we in installation phase?
79 if ((!isInstalling()) && (!isInstallationPhase())) {
80         // Load configuration file(s) here
81         loadIncludeOnce('inc/load_config.php');
82
83         // Load database layer here
84         loadIncludeOnce('inc/db/lib.php');
85
86         // CSS array
87         initExtensionCssFiles();
88
89         if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['dbase']))) {
90                 // Connect to DB
91                 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
92
93                 // Is the link valid?
94                 if (SQL_IS_LINK_UP()) {
95                         // Enable exit on error
96                         enableExitOnError();
97
98                         // Is it a valid resource?
99                         if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
100                                 // This is required for extension 'optimize' to work
101                                 setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
102
103                                 // Remove MySQL array from namespace
104                                 unset($GLOBALS['mysql']);
105
106                                 // Load cache
107                                 loadIncludeOnce('inc/load_cache.php');
108
109                                 // Check module for permissions
110                                 $checkModule = checkModulePermissions();
111
112                                 // Admin module should be accessable by guests to login
113                                 if ((getModule() == 'admin') && ($checkModule == 'admin_only')) {
114                                         // This is fine and can be ignored
115                                 } elseif ($checkModule != 'done') {
116                                         // Not fine!
117                                         logDebugMessage(__FILE__, __LINE__, sprintf("Check of module %s results in unexpected value: %s",
118                                                 getModule(),
119                                                 $checkModule
120                                         ));
121                                 }
122                         } else {
123                                 // Wrong database?
124                                 addFatalMessage(__FILE__, __LINE__, '{--WRONG_DB_SELECTED--}');
125                         }
126                 } else {
127                         // No link to database!
128                         addFatalMessage(__FILE__, __LINE__, '{--NO_DB_LINK--}');
129                 }
130         } else {
131                 // Maybe you forgot to enter your MySQL data?
132                 addFatalMessage(__FILE__, __LINE__, '{--MYSQL_DATA_MISSING--}');
133         }
134 } else {
135         ///////////////////////////////////////////////////
136         // Include neccessary functions for installation //
137         ///////////////////////////////////////////////////
138
139         // Default output is 'direct' for HTML output
140         setConfigEntry('OUTPUT_MODE', 'direct');
141
142         // This hack prevents a backtrace in CSS output
143         if (getScriptOutputMode() == 1) {
144                 // Problem with config so set output mode
145                 setConfigEntry('OUTPUT_MODE', 'render');
146         } // END - if
147
148         // CFG: DATABASE-TYPE
149         setConfigEntry('_DB_TYPE', 'mysql3');
150
151         // Include more
152         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) {
153                 // Load the include
154                 loadIncludeOnce($inc);
155         } // END - foreach
156
157         // Load cache
158         loadIncludeOnce('inc/load_cache.php');
159
160         // Run the init filter chain
161         runFilterChain('init');
162
163         // Are we installation routine?
164         if ((!isInstalling()) && (getScriptOutputMode() != 1) && (getScriptOutputMode() != -1)) {
165                 // You have to install first!
166                 redirectToUrl('install.php');
167         } // END - if
168 }
169
170 // Handle fatal errors
171 runFilterChain('handle_fatal_errors');
172
173 // [EOF]
174 ?>