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')))) $mysql = postRequestElement('mysql');
52 // Check if both passwords from SMTP are matching
53 if ((isGetRequestElementSet('page') && (getRequestElement('page') == 5))) {
54 // Okay, we have to check it
55 if (isPostRequestElementSet('smtp_user') && (!isPostRequestElementSet('smtp_host'))) {
57 addToInstallContent(getMessage('INSTALL_SMTP_HOSTNAME_EMPTY') . '<br />');
58 setRequestGetElement('page', 3);
61 if ((!isPostRequestElementSet('smtp_pass1')) && (isPostRequestElementSet('smtp_pass2'))) {
63 addToInstallContent(getMessage('INSTALL_SMTP_PASS1_EMPTY') . '<br />');
64 setRequestGetElement('page', 3);
67 if ((isPostRequestElementSet('smtp_pass1')) && (!isPostRequestElementSet('smtp_pass2'))) {
68 // Password repeat is empty
69 addToInstallContent(getMessage('INSTALL_SMTP_PASS2_EMPTY') . '<br />');
70 setRequestGetElement('page', 3);
73 if (postRequestElement('smtp_pass1') != postRequestElement('smtp_pass1')) {
74 // Passwords are not matching
75 addToInstallContent(getMessage('INSTALL_SMTP_PASS_MISMATCH') . '<br />');
76 setRequestGetElement('page', 3);
80 // Is MXChange installed or no admin registered so far?
81 if ((!isInstalled()) || (!isAdminRegistered())) {
82 // Output page for entered value
83 switch (getRequestElement('page')) {
84 case 'welcome': // Welcome to the installation!
85 addTemplateToInstallContent('install_welcome');
88 case '1': // Server path, base URL
90 addTemplateToInstallContent('install_page1');
93 case '2': // MySQL data (alone!)
94 if (empty($mysql['dbase'])) $mysql['dbase'] = 'your_database';
95 if (empty($mysql['login'])) $mysql['login'] = 'your_login';
96 if (empty($mysql['host'])) $mysql['host'] = 'localhost';
97 if (empty($mysql['prefix'])) $mysql['prefix'] = 'mxchange';
98 if (empty($mysql['type'])) $mysql['type'] = 'MyISAM';
99 if (getTotalFatalErrors() > 0) {
100 addToInstallContent('<span class="install_fatal">');
101 foreach (getFatalArray() as $key => $err) {
102 addToInstallContent('<strong>·</strong> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '<br />');
104 addToInstallContent('</span><br />');
106 $content['mysql_host'] = $mysql['host'];
107 $content['mysql_dbase'] = $mysql['dbase'];
108 $content['mysql_prefix'] = $mysql['prefix'];
109 $content['mysql_login'] = $mysql['login'];
110 $content['table_type'] = $mysql['type'];
111 $content['spath'] = postRequestElement('spath');
112 $content['burl'] = postRequestElement('burl');
113 $content['title'] = postRequestElement('title');
114 $content['slogan'] = postRequestElement('slogan');
115 $content['email'] = postRequestElement('email');
118 addTemplateToInstallContent('install_page2', false, $content);
123 $content['spath'] = postRequestElement('spath');
124 $content['burl'] = postRequestElement('burl');
125 $content['title'] = postRequestElement('title');
126 $content['slogan'] = postRequestElement('slogan');
127 $content['email'] = postRequestElement('email');
129 // Use default SMTP data
130 $smtpHost = getConfig('SMTP_HOSTNAME');
131 $smtpUser = getConfig('SMTP_USER');
132 $smtpPass1 = getConfig('SMTP_PASSWORD');
133 $smtpPass2 = getConfig('SMTP_PASSWORD');
135 // Overwrite it with the data from sent (failed) form
136 if (isPostRequestElementSet('smtp_host')) $smtpHost = postRequestElement('smtp_host');
137 if (isPostRequestElementSet('smtp_user')) $smtpUser = postRequestElement('smtp_user');
138 if (isPostRequestElementSet('smtp_pass')) {
139 $smtpPass1 = postRequestElement('smtp_pass');
140 $smtpPass2 = postRequestElement('smtp_pass');
144 $content['mysql_host'] = $mysql['host'];
145 $content['mysql_dbase'] = $mysql['dbase'];
146 $content['mysql_prefix'] = $mysql['prefix'];
147 $content['table_type'] = $mysql['type'];
148 $content['mysql_login'] = $mysql['login'];
149 $content['mysql_pass1'] = $mysql['pass1'];
150 $content['mysql_pass2'] = $mysql['pass2'];
152 // Set constants for SMTP data
153 $content['smtp_host'] = $smtpHost;
154 $content['smtp_user'] = $smtpUser;
155 $content['smtp_pass1'] = $smtpPass1;
156 $content['smtp_pass2'] = $smtpPass2;
159 addTemplateToInstallContent('install_page3', false, $content);
162 case '5': // Misc settings
164 $content['spath'] = postRequestElement('spath');
165 $content['burl'] = postRequestElement('burl');
166 $content['title'] = postRequestElement('title');
167 $content['slogan'] = postRequestElement('slogan');
168 $content['email'] = postRequestElement('email');
171 $content['mysql_host'] = $mysql['host'];
172 $content['mysql_dbase'] = $mysql['dbase'];
173 $content['mysql_prefix'] = $mysql['prefix'];
174 $content['mysql_login'] = $mysql['login'];
175 $content['table_type'] = $mysql['type'];
178 $content['smtp_host'] = postRequestElement('smtp_host');
179 $content['smtp_user'] = postRequestElement('smtp_user');
180 $content['smtp_pass'] = postRequestElement('smtp_pass1');
184 foreach ($mysql as $key => $value) {
185 $OUT .= " <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
187 $content['mysql_hidden'] = $OUT;
190 addTemplateToInstallContent('install_page5', false, $content);
193 case 'finalize': // Write captured data to files
194 if ((isPostRequestElementSet('finalize')) && (!isInstalled())) {
195 // You have submitted data then we have to reset the SQLs
198 // Connect to MySQL server
199 SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
200 if (SQL_IS_LINK_UP()) {
201 // Seems to work, also right database?
202 if (SQL_SELECT_DB($mysql['dbase'], __FILE__, __LINE__) === true) {
203 // Automatically run install.sql
204 if ((!isFileReadable(postRequestElement('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestElement('spath') . 'install/menu-'.getLanguage().'.sql'))) {
205 // Installation area not found!
206 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
209 if (getTotalFatalErrors() == 0) {
210 // Set type and prefix from POST data
211 setConfigEntry('_TABLE_TYPE' , postRequestElement('mysql', 'type'));
212 setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql', 'prefix'));
214 // Both exists so import them
215 foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
216 // Should be save here because file_exists() is there but we check it again. :)
217 $FQFN = postRequestElement('spath') . 'install/' . $dump . '.sql';
219 // Is the file readable?
220 if (isFileReadable($FQFN)) {
222 $fileContent = readFromFile($FQFN, true);
224 // Compile all config entries (we use a filter here, yes...)
225 $fileContent = FILTER_COMPILE_CONFIG($fileContent);
227 // Split it up against ";\n" and merge it into existing SQLs
228 mergeSqls(explode(";\n", $fileContent), 'install');
231 debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
234 //* DEBUG: */ die('<pre>'.print_r(getSqls(), true).'</pre>');
236 // Are some SQLs found?
237 if (countSqls() == 0) {
239 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
243 // Now run all queries through and try to keep out empty or comment queries
244 runFilterChain('run_sqls');
246 // Copy the config template and verify it
247 doInstallWriteLocalConfig();
252 if (getTotalFatalErrors() > 0) {
254 foreach (getFatalArray() as $value) {
255 $OUT .= " <li>" . $value . "</li>\n";
257 $content['fatal_errors'] = $OUT;
259 foreach ($mysql as $key => $value) {
260 $OUT .= " <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
262 $content['mysql_hidden'] = $OUT;
263 $content['spath'] = postRequestElement('spath');
264 $content['burl'] = postRequestElement('burl');
265 $content['title'] = postRequestElement('title');
266 $content['smtp_host'] = postRequestElement('smtp_host');
267 $content['smtp_user'] = postRequestElement('smtp_user');
268 $content['smtp_pass'] = postRequestElement('smtp_pass1');
271 addTemplateToInstallContent('install_fatal_errors', false, $content);
273 // Installation is done!
274 redirectToUrl('install.php?page=finished');
277 // Something goes wrong during installation! :-(
278 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
284 // Load template that we are finished
285 addTemplateToInstallContent('install_finished');
288 redirectToUrl('install.php');
293 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestElement('page')));
294 addTemplateToInstallContent('admin_settings_saved', "<div class=\"install_error\">{--WRONG_PAGE--}</div>");
298 // Already installed!
299 addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));