2 /************************************************************************
3 * MXChange v0.2.1 Start: 08/29/2003 *
4 * =============== Last change: 11/11/2004 *
6 * -------------------------------------------------------------------- *
7 * File : install-inc.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for installation procedure *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer die Installationsroutine *
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 - 2009 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 /************************************************************************
40 * YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION! *
41 ************************************************************************/
43 // Some security stuff...
44 if (!defined('__SECURITY')) {
50 if ((isPostRequestElementSet('mysql')) && (is_array(postRequestElement('mysql')))) {
51 // Transfer 'mysql' array
52 $mysql = postRequestElement('mysql');
55 // Check if both passwords from SMTP are matching
56 if ((isGetRequestElementSet('page') && (getRequestElement('page') == 5))) {
57 // Okay, we have to check it
58 if (isPostRequestElementSet('smtp_user') && (!isPostRequestElementSet('smtp_host'))) {
60 addToInstallContent(getMessage('INSTALL_SMTP_HOSTNAME_EMPTY') . '<br />');
61 setRequestGetElement('page', 3);
64 if ((!isPostRequestElementSet('smtp_pass1')) && (isPostRequestElementSet('smtp_pass2'))) {
66 addToInstallContent(getMessage('INSTALL_SMTP_PASS1_EMPTY') . '<br />');
67 setRequestGetElement('page', 3);
70 if ((isPostRequestElementSet('smtp_pass1')) && (!isPostRequestElementSet('smtp_pass2'))) {
71 // Password repeat is empty
72 addToInstallContent(getMessage('INSTALL_SMTP_PASS2_EMPTY') . '<br />');
73 setRequestGetElement('page', 3);
76 if (postRequestElement('smtp_pass1') != postRequestElement('smtp_pass1')) {
77 // Passwords are not matching
78 addToInstallContent(getMessage('INSTALL_SMTP_PASS_MISMATCH') . '<br />');
79 setRequestGetElement('page', 3);
83 // Is MXChange installed or no admin registered so far?
84 if ((!isInstalled()) || (!isAdminRegistered())) {
85 // Output page for entered value
86 switch (getRequestElement('page')) {
87 case 'welcome': // Welcome to the installation!
88 addTemplateToInstallContent('install_welcome');
91 case 1: // Server path, base URL
93 addTemplateToInstallContent('install_page1');
96 case 2: // MySQL data (alone!)
97 if (empty($mysql['dbase'])) $mysql['dbase'] = 'your_database';
98 if (empty($mysql['login'])) $mysql['login'] = 'your_login';
99 if (empty($mysql['host'])) $mysql['host'] = 'localhost';
100 if (empty($mysql['prefix'])) $mysql['prefix'] = 'mxchange';
101 if (empty($mysql['type'])) $mysql['type'] = 'MyISAM';
102 if (getTotalFatalErrors() > 0) {
103 addToInstallContent('<span class="install_fatal">');
104 foreach (getFatalArray() as $key => $err) {
105 addToInstallContent('<strong>·</strong> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '<br />');
107 addToInstallContent('</span><br />');
109 $content['mysql_host'] = $mysql['host'];
110 $content['mysql_dbase'] = $mysql['dbase'];
111 $content['mysql_prefix'] = $mysql['prefix'];
112 $content['mysql_login'] = $mysql['login'];
113 $content['table_type'] = $mysql['type'];
114 $content['spath'] = postRequestElement('spath');
115 $content['burl'] = postRequestElement('burl');
116 $content['title'] = postRequestElement('title');
117 $content['slogan'] = postRequestElement('slogan');
118 $content['email'] = postRequestElement('email');
121 addTemplateToInstallContent('install_page2', $content);
126 $content['spath'] = postRequestElement('spath');
127 $content['burl'] = postRequestElement('burl');
128 $content['title'] = postRequestElement('title');
129 $content['slogan'] = postRequestElement('slogan');
130 $content['email'] = postRequestElement('email');
132 // Use default SMTP data
133 $smtpHost = getConfig('SMTP_HOSTNAME');
134 $smtpUser = getConfig('SMTP_USER');
135 $smtpPass1 = getConfig('SMTP_PASSWORD');
136 $smtpPass2 = getConfig('SMTP_PASSWORD');
138 // Overwrite it with the data from sent (failed) form
139 if (isPostRequestElementSet('smtp_host')) $smtpHost = postRequestElement('smtp_host');
140 if (isPostRequestElementSet('smtp_user')) $smtpUser = postRequestElement('smtp_user');
141 if (isPostRequestElementSet('smtp_pass')) {
142 $smtpPass1 = postRequestElement('smtp_pass');
143 $smtpPass2 = postRequestElement('smtp_pass');
147 $content['mysql_host'] = $mysql['host'];
148 $content['mysql_dbase'] = $mysql['dbase'];
149 $content['mysql_prefix'] = $mysql['prefix'];
150 $content['table_type'] = $mysql['type'];
151 $content['mysql_login'] = $mysql['login'];
152 $content['mysql_pass1'] = $mysql['pass1'];
153 $content['mysql_pass2'] = $mysql['pass2'];
155 // Set constants for SMTP data
156 $content['smtp_host'] = $smtpHost;
157 $content['smtp_user'] = $smtpUser;
158 $content['smtp_pass1'] = $smtpPass1;
159 $content['smtp_pass2'] = $smtpPass2;
162 addTemplateToInstallContent('install_page3', $content);
165 case 5: // Misc settings
167 $content['spath'] = postRequestElement('spath');
168 $content['burl'] = postRequestElement('burl');
169 $content['title'] = postRequestElement('title');
170 $content['slogan'] = postRequestElement('slogan');
171 $content['email'] = postRequestElement('email');
174 $content['smtp_host'] = postRequestElement('smtp_host');
175 $content['smtp_user'] = postRequestElement('smtp_user');
176 $content['smtp_pass'] = postRequestElement('smtp_pass1');
180 foreach ($mysql as $key => $value) {
181 $OUT .= " <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
183 $content['mysql_hidden'] = $OUT;
186 addTemplateToInstallContent('install_page5', $content);
189 case 'finalize': // Write captured data to files
190 if ((isPostRequestElementSet('finalize')) && (!isInstalled())) {
191 // You have submitted data then we have to reset the SQLs
194 // Connect to MySQL server
195 SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
196 if (SQL_IS_LINK_UP()) {
197 // Seems to work, also right database?
198 if (SQL_SELECT_DB($mysql['dbase'], __FILE__, __LINE__) === true) {
199 // Automatically run install.sql
200 if ((!isFileReadable(postRequestElement('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestElement('spath') . 'install/menu-'.getLanguage().'.sql'))) {
201 // Installation area not found!
202 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
205 if (getTotalFatalErrors() == 0) {
206 // Set type and prefix from POST data
207 setConfigEntry('_TABLE_TYPE' , postRequestElement('mysql', 'type'));
208 setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql', 'prefix'));
210 // Both exists so import them
211 foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
212 // Should be save here because file_exists() is there but we check it again. :)
213 $FQFN = postRequestElement('spath') . 'install/' . $dump . '.sql';
215 // Is the file readable?
216 if (isFileReadable($FQFN)) {
218 $fileContent = readFromFile($FQFN, true);
220 // Compile all config entries (we use a filter here, yes...)
221 $fileContent = FILTER_COMPILE_CONFIG($fileContent);
223 // Split it up against ";\n" and merge it into existing SQLs
224 mergeSqls(explode(";\n", $fileContent), 'install');
227 debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
230 //* DEBUG: */ die('<pre>'.print_r(getSqls(), true).'</pre>');
232 // Are some SQLs found?
233 if (countSqls() == 0) {
235 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
239 // Now run all queries through and try to keep out empty or comment queries
240 runFilterChain('run_sqls');
242 // Copy the config template and verify it
243 doInstallWriteLocalConfig();
248 if (getTotalFatalErrors() > 0) {
250 foreach (getFatalArray() as $value) {
251 $OUT .= " <li>" . $value . "</li>\n";
253 $content['fatal_errors'] = $OUT;
255 foreach ($mysql as $key => $value) {
256 $OUT .= " <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
258 $content['mysql_hidden'] = $OUT;
259 $content['spath'] = postRequestElement('spath');
260 $content['burl'] = postRequestElement('burl');
261 $content['title'] = postRequestElement('title');
262 $content['smtp_host'] = postRequestElement('smtp_host');
263 $content['smtp_user'] = postRequestElement('smtp_user');
264 $content['smtp_pass'] = postRequestElement('smtp_pass1');
267 addTemplateToInstallContent('install_fatal_errors', $content);
269 // Installation is done!
270 redirectToUrl('install.php?page=finished');
273 // Something goes wrong during installation! :-(
274 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
280 // Load template that we are finished
281 addTemplateToInstallContent('install_finished');
284 redirectToUrl('install.php');
289 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestElement('page')));
290 addTemplateToInstallContent('admin_settings_saved', "<div class=\"install_error\">{--WRONG_PAGE--}</div>");
294 // Already installed!
295 addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));