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', 'db/lib', 'handler', 'hooks') as $lib) {
53 // Load special functions
54 loadIncludeOnce('inc/' . $lib . '.php');
58 set_error_handler('__errorHandler');
66 // Set important header_sent
67 $GLOBALS['header_sent'] = 0;
69 // Init fatal messages
72 // Check if this file is writeable or read-only and warn the user
73 if ((!isInstalling()) && (isInstalled())) {
74 // Load "databases" aka static arrays
75 loadIncludeOnce('inc/databases.php');
77 // Load configuration file(s) here
78 loadIncludeOnce('inc/load_config.php');
80 // Check for write-permission for config.php and inc directory
81 if (!isModuleSet()) setModule(REQUEST_GET('module'));
82 if (!isModuleSet()) setModule('index');
87 if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['password'])) && (!empty($GLOBALS['mysql']['dbase']))) {
89 SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
92 if (SQL_IS_LINK_UP()) {
93 // Enable exit on error
96 // Is it a valid resource?
97 if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === true) {
98 // This is required for extension 'optimize' to work
99 define('__DB_NAME', $GLOBALS['mysql']['dbase']);
101 // Remove MySQL array from namespace
102 unset($GLOBALS['mysql']);
104 // Load configuration stuff
108 loadIncludeOnce('inc/session.php');
111 loadIncludeOnce('inc/versions.php');
113 // Loading patching system is required here...
114 loadIncludeOnce('inc/patch-system.php');
117 loadIncludeOnce('inc/check-reset.php');
119 // Load admin include file if he is admin
121 // Administrative functions
122 loadIncludeOnce('inc/modules/admin/admin-inc.php');
124 //* DEBUG: */ ADD_POINTS_REFSYSTEM('test', 36, 1000);
128 if ((getOutputMode() != 1) && (getOutputMode() != -1)) {
129 if (!isModuleSet()) setModule('empty');
130 if (!isWhatSet()) setWhat(getWhatFromModule(getModule()));
131 if (!isActionSet()) setAction(getModeAction(getModule(), getWhat()));
133 // Set action/what to empty
138 // Run the init filter chain
139 runFilterChain('init');
141 // Set default 'what' value
142 //* DEBUG: */ OUTPUT_HTML('-'.getModule().'/'.getWhat()."-<br />");
143 if ((!isWhatSet()) && (!isActionSet()) && (getOutputMode() != 1) && (getOutputMode() != -1)) {
144 if (getModule() == 'admin') {
145 // Set 'action' value to 'login' in admin menu
146 setAction(getModeAction(getModule(), getWhat()));
147 } elseif ((getModule() == 'index') || (getModule() == 'login')) {
148 // Set 'what' value to 'welcome' in guest and member menu
150 if (getConfig('index_home') != '') setWhatFromConfig('index_home');
152 // Anything else like begging link
157 // Update sending pool
158 if ((getOutputMode() != '1') && (getOutputMode() != '-1')) loadIncludeOnce('inc/pool-update.php'); // Sends out mails in configureable steps
160 // Load all active extension including language files when not upgrading.
161 // Check module for testing and count one click
162 if (checkModulePermissions(getModule()) == 'done') countModuleHit(getModule());
164 // Shall we activate the exchange?
165 if (getConfig('activate_xchange') > 0) activateExchange();
167 // Is the extension sql_patches installed and at least 0.3.6?
168 if (GET_EXT_VERSION('sql_patches') >= '0.3.6') {
169 // Generate random number
170 define('RAND_NUMBER', generateRandomCode(10, mt_rand(10000,32766), getUserId(), ''));
172 // Generate weak (!!!) code
173 define('RAND_NUMBER', mt_rand(1000000, 9999999));
177 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
180 // No link to database!
181 addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
184 // Maybe you forgot to enter your MySQL data?
185 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
188 ///////////////////////////////////////////////////
189 // Include neccessary functions for installation //
190 ///////////////////////////////////////////////////
192 // Default output is 'direct' for HTML output
193 setConfigEntry('OUTPUT_MODE', 'direct');
195 // This hack prevents a backtrace in CSS output
196 if (getOutputMode() == '1') {
197 // Problem with config so set output mode
198 setConfigEntry('OUTPUT_MODE', 'render');
201 // Set other missing variables
202 if (!isOutputModeSet()) setOutputMode('0');
204 // Include databases.php
205 loadIncludeOnce('inc/databases.php');
208 loadIncludeOnce('inc/session.php');
211 loadIncludeOnce('inc/versions.php');
213 // Check if we are in installation routine
214 if ((!isInstalling()) && (getOutputMode() != '1') && (getOutputMode() != -1)) {
215 // Redirect to the installation system
216 redirectToUrl('install.php');
219 // Double-check installation mode
220 if ((!isInstalled()) || (!isAdminRegistered())) {
221 // Check for file permissions
222 if (!isIncludeWriteable('config')) {
223 addFatalMessage(__FILE__, __LINE__, getMessage('CONFIG_IS_WRITE_PROTECTED'));
225 if (!isIncludeWriteable('dummy')) {
226 addFatalMessage(__FILE__, __LINE__, getMessage('DUMMY_IS_WRITE_PROTECTED'));
228 if (!isIncludeWriteable('.secret/dummy')) {
229 addFatalMessage(__FILE__, __LINE__, getMessage('SECRET_IS_WRITE_PROTECTED'));
233 // Run the init filter chain
234 runFilterChain('init');
236 // Load extension 'sql_patches'
237 LOAD_EXTENSION('sql_patches');
239 // Load configuration file(s) here
240 loadIncludeOnce('inc/load_config.php');
244 loadIncludeOnce('inc/session.php');
247 loadIncludeOnce('inc/versions.php');
249 if ((getTotalFatalErrors() > 0) && (isInstalled()) && (!isInstalling()) && (getOutputMode() != '1')) {
250 // One or more fatal error(s) occur during connect...
251 loadIncludeOnce('inc/header.php');
252 loadIncludeOnce('inc/fatal_errors.php');
253 loadIncludeOnce('inc/footer.php');