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 * -------------------------------------------------------------------- *
14 * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009) $ *
15 * $Tag:: 0.2.1-FINAL $ *
16 * $Author:: stelzi $ *
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 // CFG: DEBUG-SQL (if enabled and DEBUG_MODE is enabled all SQL queries will be logged to debug.log)
46 define('DEBUG_SQL', false);
48 // Non-database functions
49 require("inc/functions.php");
51 // Load more function libraries or includes
52 foreach (array('request-functions', 'session-functions', 'config-functions', 'filters', 'mysql-manager', 'extensions', 'db/lib', 'handler', 'hooks') as $lib) {
53 // Load special functions
54 LOAD_INC_ONCE(sprintf("inc/%s.php", $lib));
58 set_error_handler('__errorHandler');
60 // Register shutdown hook
61 register_shutdown_function('__SHUTDOWN_HOOK');
63 // Check if the user setups his MySQL stuff...
64 if ((empty($MySQL['login'])) && (!defined('mxchange_installing')) && (!REQUEST_ISSET_GET(('installing'))) && (isInstalled())) {
65 // No login entered and outside installation mode
66 OUTPUT_HTML("<strong>{--LANG_WARNING--}:</strong> ");
68 // You have changed my configuration file!
69 mxchange_die("{--DIE_CONFIG_CHANGED_YOU--}");
71 // Please run the installation script (maybe again)
72 mxchange_die("{--DIE_RUN_INSTALL_MYSQL--}");
74 } elseif ((!isInstalling()) && (!REQUEST_ISSET_GET(('installing'))) && (empty($MySQL['password'])) && (isBooleanConstantAndTrue('warn_no_pass'))) {
75 // No database password entered!!!
76 OUTPUT_HTML("<div>{--LANG_WARNING--}:</div> {--WARN_NULL_PASSWORD--}");
79 // Set dummy config array
82 // Set important header_sent
83 $GLOBALS['header_sent'] = 0;
85 // Init fatal messages
88 // Check if this file is writeable or read-only and warn the user
89 if ((!isInstalling()) && (isInstalled())) {
90 // Check for write-permission for config.php and inc directory
91 if (empty($GLOBALS['module'])) $GLOBALS['module'] = REQUEST_GET('module');
92 if (empty($GLOBALS['module'])) $GLOBALS['module'] = "index";
97 if ((!empty($MySQL['host'])) && (!empty($MySQL['login'])) && (!empty($MySQL['password'])) && (!empty($MySQL['dbase']))) {
99 SQL_CONNECT($MySQL['host'], $MySQL['login'], $MySQL['password'], __FILE__, __LINE__);
101 // Is the link valid?
102 if (SQL_IS_LINK_UP()) {
103 // Is it a valid resource?
104 if (SQL_SELECT_DB($MySQL['dbase'], __FILE__, __LINE__) === true) {
105 // This is required for extension 'optimize' to work
106 define('__DB_NAME', $MySQL['dbase']);
108 // Remove MySQL array from namespace
111 // Load configuration stuff
115 LOAD_INC_ONCE("inc/session.php");
117 // Load "databases" aka static arrays
118 LOAD_INC_ONCE("inc/databases.php");
120 // Loading patching system is required here...
121 LOAD_INC_ONCE("inc/patch-system.php"); // Initialize patch system
124 LOAD_INC_ONCE("inc/check-reset.php");
126 // Load admin include file if he is admin
128 // Administrative functions
129 LOAD_INC_ONCE("inc/modules/admin/admin-inc.php");
131 //* DEBUG: */ ADD_POINTS_REFSYSTEM("test", 36, 1000);
135 if (($GLOBALS['output_mode'] != 1) && ($GLOBALS['output_mode'] != -1)) {
136 if (empty($GLOBALS['module'])) $GLOBALS['module'] = "empty";
137 if (empty($GLOBALS['what'])) $GLOBALS['what'] = GET_WHAT($GLOBALS['module']);
138 if (empty($GLOBALS['action'])) $GLOBALS['action'] = GET_ACTION($GLOBALS['module'], $GLOBALS['what']);
140 // Set action/what to empty
141 $GLOBALS['action'] = "";
142 $GLOBALS['what'] = "";
145 // Run the init filter chain
146 runFilterChain('init');
148 // Set default 'what' value
149 //* DEBUG: */ OUTPUT_HTML("-".$GLOBALS['module']."/".$GLOBALS['what']."-<br />");
150 if ((empty($GLOBALS['what'])) && (empty($GLOBALS['action'])) && ($GLOBALS['output_mode'] != 1) && ($GLOBALS['output_mode'] != -1)) {
151 if ($GLOBALS['module'] == "admin") {
152 // Set 'action' value to 'login' in admin menu
153 $GLOBALS['action'] = GET_ACTION($GLOBALS['module'], $GLOBALS['what']);
154 } elseif (($GLOBALS['module'] == "index") || ($GLOBALS['module'] == "login")) {
155 // Set 'what' value to 'welcome' in guest and member menu
156 $GLOBALS['what'] = "welcome";
157 if (getConfig('index_home') != "") $GLOBALS['what'] = getConfig('index_home');
159 // Anything else like begging link
160 $GLOBALS['what'] = "";
164 // Update sending pool
165 if (($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) LOAD_INC_ONCE("inc/pool-update.php"); // Sends out mails in configureable steps
167 // Load all active extension including language files when not upgrading.
168 // Check module for testing and count one click
169 $dummy = checkModulePermissions($GLOBALS['module']);
170 if ($dummy == "done") countModuleHit($GLOBALS['module']);
173 // Shall we activate the exchange?
174 if (getConfig('activate_xchange') > 0) activateExchange();
176 // Is the extension sql_patches installed and at least 0.3.6?
177 if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
178 // Generate random number
179 if (isset($GLOBALS['userid'])) {
180 define('RAND_NUMBER', generateRandomCodde(10, mt_rand(10000,32766), $GLOBALS['userid'], ""));
182 define('RAND_NUMBER', generateRandomCodde(10, mt_rand(10000,32766), 0, ""));
185 // Generate weak (!!!) code
186 define('RAND_NUMBER', mt_rand(1000000, 9999999));
190 addFatalMessage(__FILE__, __LINE__, getMessage('WRONG_DB_SELECTED'));
193 // No link to database!
194 addFatalMessage(__FILE__, __LINE__, getMessage('NO_DB_LINK'));
197 // Maybe you forgot to enter your MySQL data?
198 addFatalMessage(__FILE__, __LINE__, getMessage('MYSQL_DATA_MISSING'));
201 ///////////////////////////////////////////////////
202 // Include neccessary functions for installation //
203 ///////////////////////////////////////////////////
205 // Set other missing variables
206 if (!isset($GLOBALS['output_mode'])) $GLOBALS['output_mode'] = "0";
209 LOAD_INC_ONCE("inc/session.php");
211 // Include databases.php
212 LOAD_INC_ONCE("inc/databases.php");
214 // Check if we are in installation routine
215 if ((basename($_SERVER['PHP_SELF']) != "install.php") && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != -1)) {
216 // Redirect to the installation system
217 LOAD_URL("install.php");
220 // Double-check installation mode
221 if ((!isInstalled()) || (!isAdminRegistered())) {
222 // Check for file permissions
223 if (!IS_INC_WRITEABLE("config")) {
224 addFatalMessage(__FILE__, __LINE__, getMessage('CONFIG_IS_WRITE_PROTECTED'));
226 if (!IS_INC_WRITEABLE("dummy")) {
227 addFatalMessage(__FILE__, __LINE__, getMessage('DUMMY_IS_WRITE_PROTECTED'));
229 if (!IS_INC_WRITEABLE(".secret/dummy")) {
230 addFatalMessage(__FILE__, __LINE__, getMessage('SECRET_IS_WRITE_PROTECTED'));
234 // Run the init filter chain
235 runFilterChain('init');
237 // Load extension 'sql_patches'
238 LOAD_EXTENSION("sql_patches");
241 if ((getTotalFatalErrors() > 0) && (isInstalled()) && (!defined('mxchange_installing')) && ($GLOBALS['output_mode'] != "1")) {
242 // One or more fatal error(s) occur during connect...
243 LOAD_INC_ONCE("inc/header.php");
244 LOAD_INC_ONCE("inc/fatal_errors.php");
245 LOAD_INC_ONCE("inc/footer.php");