2 /************************************************************************
3 * MXChange v0.2.1 Start: 11/16/2003 *
4 * =============== Last change: 12/13/2004 *
6 * -------------------------------------------------------------------- *
7 * File : mysql-connect.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Connects to your database *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Verbindet zu Ihrer Datenbank *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Non-database functions
46 require('inc/functions.php');
49 require('inc/wrapper-functions.php');
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');
57 // Initialize the configuration
61 set_error_handler('__errorHandler');
63 // Disable block-mode by default
64 enableBlockMode(false);
72 // Set important header_sent
73 if (!isset($GLOBALS['header_sent'])) $GLOBALS['header_sent'] = 0;
75 // Init fatal messages
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');
83 // Load configuration file(s) here
84 loadIncludeOnce('inc/load_config.php');
86 // Load database layer here
87 loadIncludeOnce('inc/db/lib.php');
89 // Check for write-permission for config.php and inc directory
90 if (!isModuleSet()) setModule(REQUEST_GET('module'));
91 if (!isModuleSet()) setModule('index');
96 if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['password'])) && (!empty($GLOBALS['mysql']['dbase']))) {
98 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
100 // Is the link valid?
101 if (SQL_IS_LINK_UP()) {
102 // Enable exit on error
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']);
110 // Remove MySQL array from namespace
111 unset($GLOBALS['mysql']);
113 // Load configuration stuff
117 loadIncludeOnce('inc/session.php');
120 loadIncludeOnce('inc/versions.php');
122 // Loading patching system is required here...
123 loadIncludeOnce('inc/patch-system.php');
126 loadIncludeOnce('inc/check-reset.php');
128 // Load admin include file if he is admin
130 // Administrative functions
131 loadIncludeOnce('inc/modules/admin/admin-inc.php');
133 //* DEBUG: */ ADD_POINTS_REFSYSTEM('test', 36, 1000);
137 if ((getOutputMode() != 1) && (getOutputMode() != -1)) {
138 if (!isModuleSet()) setModule('empty');
139 if (!isWhatSet()) setWhat(getWhatFromModule(getModule()));
140 if (!isActionSet()) setAction(getModeAction(getModule(), getWhat()));
142 // Set action/what to empty
147 // Run the init filter chain
148 runFilterChain('init');
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
159 if (getConfig('index_home') != '') setWhatFromConfig('index_home');
161 // Anything else like begging link
166 // Update sending pool
167 if ((getOutputMode() != '1') && (getOutputMode() != '-1')) loadIncludeOnce('inc/pool-update.php'); // Sends out mails in configureable steps
169 // Check module for permissions
170 $checkModule = checkModulePermissions(getModule());
171 if ($checkModule != 'done') {
173 DEBUG_LOG(__FILE__, __LINE__, sprintf("Check of module %s results in unpexted value: %s",
179 // Shall we activate the exchange?
180 if (getConfig('activate_xchange') > 0) activateExchange();
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(), ''));
187 // Generate weak (!!!) code
188 define('RAND_NUMBER', mt_rand(1000000, 9999999));
192 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
195 // No link to database!
196 addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
199 // Maybe you forgot to enter your MySQL data?
200 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
203 ///////////////////////////////////////////////////
204 // Include neccessary functions for installation //
205 ///////////////////////////////////////////////////
207 // Default output is 'direct' for HTML output
208 setConfigEntry('OUTPUT_MODE', 'direct');
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');
216 // Set other missing variables
217 if (!isOutputModeSet()) setOutputMode('0');
219 // Include databases.php
220 loadIncludeOnce('inc/databases.php');
223 loadIncludeOnce('inc/session.php');
226 loadIncludeOnce('inc/versions.php');
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');
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'));
240 if (!isIncludeWriteable('dummy')) {
241 addFatalMessage(__FILE__, __LINE__, getMessage('DUMMY_IS_WRITE_PROTECTED'));
243 if (!isIncludeWriteable('.secret/dummy')) {
244 addFatalMessage(__FILE__, __LINE__, getMessage('SECRET_IS_WRITE_PROTECTED'));
248 // Run the init filter chain
249 runFilterChain('init');
251 // Load extension 'sql_patches'
252 LOAD_EXTENSION('sql_patches');
254 // Load configuration file(s) here
255 loadIncludeOnce('inc/load_config.php');
259 loadIncludeOnce('inc/session.php');
262 loadIncludeOnce('inc/versions.php');
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');