2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 ((isPostRequestParameterSet('mysql')) && (is_array(postRequestParameter('mysql')))) {
51 // Transfer 'mysql' array
52 $mysql = postRequestParameter('mysql');
55 // Check if both passwords from SMTP are matching
56 if ((isGetRequestParameterSet('page') && (getRequestParameter('page') == 5))) {
57 // Okay, we have to check it
58 if (isPostRequestParameterSet('smtp_user') && (!isPostRequestParameterSet('smtp_host'))) {
60 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_HOSTNAME_EMPTY') . '</div>');
61 setGetRequestParameter('page', 3);
64 if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
66 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_PASS1_EMPTY') . '</div>');
67 setGetRequestParameter('page', 3);
70 if ((isPostRequestParameterSet('smtp_pass1')) && (!isPostRequestParameterSet('smtp_pass2'))) {
71 // Password repeat is empty
72 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_PASS2_EMPTY') . '</div>');
73 setGetRequestParameter('page', 3);
76 if (postRequestParameter('smtp_pass1') != postRequestParameter('smtp_pass1')) {
77 // Passwords are not matching
78 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_PASS_MISMATCH') . '</div>');
79 setGetRequestParameter('page', 3);
83 // Is the mailer installed or no admin registered so far?
84 if ((!isInstalled()) || (!isAdminRegistered())) {
85 // Output page for entered value
86 switch (getRequestParameter('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('<div class="install_fatal">');
104 foreach (getFatalArray() as $key => $err) {
105 addToInstallContent('<div class="para"><strong>·</strong> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</div>');
107 addToInstallContent('</div>');
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'] = postRequestParameter('spath');
115 $content['burl'] = postRequestParameter('burl');
116 $content['title'] = postRequestParameter('title');
117 $content['slogan'] = postRequestParameter('slogan');
118 $content['email'] = postRequestParameter('email');
121 addTemplateToInstallContent('install_page2', $content);
126 $content['spath'] = postRequestParameter('spath');
127 $content['burl'] = postRequestParameter('burl');
128 $content['title'] = postRequestParameter('title');
129 $content['slogan'] = postRequestParameter('slogan');
130 $content['email'] = postRequestParameter('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 (isPostRequestParameterSet('smtp_host')) $smtpHost = postRequestParameter('smtp_host');
140 if (isPostRequestParameterSet('smtp_user')) $smtpUser = postRequestParameter('smtp_user');
141 if (isPostRequestParameterSet('smtp_pass')) {
142 $smtpPass1 = postRequestParameter('smtp_pass');
143 $smtpPass2 = postRequestParameter('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'] = postRequestParameter('spath');
168 $content['burl'] = postRequestParameter('burl');
169 $content['title'] = postRequestParameter('title');
170 $content['slogan'] = postRequestParameter('slogan');
171 $content['email'] = postRequestParameter('email');
174 $content['smtp_host'] = postRequestParameter('smtp_host');
175 $content['smtp_user'] = postRequestParameter('smtp_user');
176 $content['smtp_pass'] = postRequestParameter('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 ((isPostRequestParameterSet('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(postRequestParameter('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestParameter('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' , postRequestParameter('mysql', 'type'));
208 setConfigEntry('_MYSQL_PREFIX', postRequestParameter('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 = postRequestParameter('spath') . 'install/' . $dump . '.sql';
215 // Is the file readable?
216 if (isFileReadable($FQFN)) {
218 $fileContent = readFromFile($FQFN, true);
220 // Split it up against ";\n" and merge it into existing SQLs
221 mergeSqls(explode(";\n", $fileContent), 'install');
224 debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
227 //* DEBUG: */ die('<pre>'.print_r(getSqls(), true).'</pre>');
229 // Are some SQLs found?
230 if (countSqls() == '0') {
232 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
236 // Now run all queries through and try to keep out empty or comment queries
237 runFilterChain('run_sqls');
239 // Copy the config template and verify it
240 doInstallWriteLocalConfig();
245 if (getTotalFatalErrors() > 0) {
247 foreach (getFatalArray() as $value) {
248 $OUT .= ' <li>' . $value . '</li>';
250 $content['fatal_errors'] = $OUT;
252 foreach ($mysql as $key => $value) {
253 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
255 $content['mysql_hidden'] = $OUT;
256 $content['spath'] = postRequestParameter('spath');
257 $content['burl'] = postRequestParameter('burl');
258 $content['title'] = postRequestParameter('title');
259 $content['smtp_host'] = postRequestParameter('smtp_host');
260 $content['smtp_user'] = postRequestParameter('smtp_user');
261 $content['smtp_pass'] = postRequestParameter('smtp_pass1');
264 addTemplateToInstallContent('install_fatal_errors', $content);
266 // Installation is done!
267 redirectToUrl('install.php?page=finished');
270 // Something goes wrong during installation! :-(
271 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
277 // Load template that we are finished
278 addTemplateToInstallContent('install_finished');
281 redirectToUrl('install.php');
286 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestParameter('page')));
287 addTemplateToInstallContent('admin_settings_saved', '<div class="install_error">{--WRONG_PAGE--}</div>');
291 // Already installed!
292 addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));