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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 /************************************************************************
39 * YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION! *
40 ************************************************************************/
42 // Some security stuff...
43 if (!defined('__SECURITY')) {
47 // Load extension timezone
48 loadExtension('timezone', 'test');
51 setConfigEntry('timezone', 'Europe/Berlin');
54 FILTER_INIT_TIMEZONE(array());
57 $GLOBALS['install_mysql'] = array();
58 if ((isPostRequestElementSet('mysql')) && (is_array(postRequestElement('mysql')))) {
59 // Transfer 'mysql' array
60 $GLOBALS['install_mysql'] = postRequestElement('mysql');
63 // Check if both passwords from SMTP are matching
64 if ((isGetRequestElementSet('page') && (getRequestElement('page') == 5))) {
65 // Okay, we have to check it
66 if (isPostRequestElementSet('smtp_user') && (!isPostRequestElementSet('smtp_host'))) {
68 addToInstallContent('<div class="para">{--INSTALL_SMTP_HOSTNAME_EMPTY--}</div>');
69 setGetRequestElement('page', 3);
72 if ((!isPostRequestElementSet('smtp_pass1')) && (isPostRequestElementSet('smtp_pass2'))) {
74 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASSWORD1_EMPTY--}</div>');
75 setGetRequestElement('page', 3);
78 if ((isPostRequestElementSet('smtp_pass1')) && (!isPostRequestElementSet('smtp_pass2'))) {
79 // Password repeat is empty
80 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASSWORD2_EMPTY--}</div>');
81 setGetRequestElement('page', 3);
84 if (postRequestElement('smtp_pass1') != postRequestElement('smtp_pass1')) {
85 // Passwords are not matching
86 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS_MISMATCH--}</div>');
87 setGetRequestElement('page', 3);
91 // Is the mailer installed or no admin registered so far?
92 if ((!isInstalled()) || (!isAdminRegistered())) {
93 // Output page for entered value
94 switch (getRequestElement('page')) {
95 case 'welcome': // Welcome to the installation!
96 addTemplateToInstallContent('install_welcome');
99 case '1': // Server path, base URL
101 addTemplateToInstallContent('install_page1');
104 case '2': // Database login data
105 if (empty($GLOBALS['install_mysql']['dbase'])) $GLOBALS['install_mysql']['dbase'] = 'your_database';
106 if (empty($GLOBALS['install_mysql']['login'])) $GLOBALS['install_mysql']['login'] = 'your_login';
107 if (empty($GLOBALS['install_mysql']['host'])) $GLOBALS['install_mysql']['host'] = 'localhost';
108 if (empty($GLOBALS['install_mysql']['prefix'])) $GLOBALS['install_mysql']['prefix'] = 'mailer';
109 if (empty($GLOBALS['install_mysql']['type'])) $GLOBALS['install_mysql']['type'] = 'MyISAM';
110 if (ifFatalErrorsDetected()) {
111 addToInstallContent('<div class="install_fatal"><ul>');
112 foreach (getFatalArray() as $key => $err) {
113 addToInstallContent('<li> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</li>');
115 addToInstallContent('</ol></div>');
118 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
119 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
120 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
121 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
122 $content['table_type'] = $GLOBALS['install_mysql']['type'];
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');
130 addTemplateToInstallContent('install_page2', $content);
135 $content['spath'] = postRequestElement('spath');
136 $content['burl'] = postRequestElement('burl');
137 $content['title'] = postRequestElement('title');
138 $content['slogan'] = postRequestElement('slogan');
139 $content['email'] = postRequestElement('email');
141 // Use default SMTP data
142 $smtpHost = '{?SMTP_HOSTNAME?}';
143 $smtpUser = '{?SMTP_USER?}';
144 $smtpPass1 = '{?SMTP_PASSWORD?}';
145 $smtpPass2 = '{?SMTP_PASSWORD?}';
147 // Overwrite it with the data from sent (failed) form
148 if (isPostRequestElementSet('smtp_host')) $smtpHost = postRequestElement('smtp_host');
149 if (isPostRequestElementSet('smtp_user')) $smtpUser = postRequestElement('smtp_user');
150 if (isPostRequestElementSet('smtp_pass')) {
151 $smtpPass1 = postRequestElement('smtp_pass');
152 $smtpPass2 = postRequestElement('smtp_pass');
155 // Database login data
156 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
157 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
158 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
159 $content['table_type'] = $GLOBALS['install_mysql']['type'];
160 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
161 $content['mysql_pass1'] = $GLOBALS['install_mysql']['pass1'];
162 $content['mysql_pass2'] = $GLOBALS['install_mysql']['pass2'];
164 // Set constants for SMTP data
165 $content['smtp_host'] = $smtpHost;
166 $content['smtp_user'] = $smtpUser;
167 $content['smtp_pass1'] = $smtpPass1;
168 $content['smtp_pass2'] = $smtpPass2;
171 addTemplateToInstallContent('install_page3', $content);
174 case '5': // Misc settings
176 $content['spath'] = postRequestElement('spath');
177 $content['burl'] = postRequestElement('burl');
178 $content['title'] = postRequestElement('title');
179 $content['slogan'] = postRequestElement('slogan');
180 $content['email'] = postRequestElement('email');
183 $content['smtp_host'] = postRequestElement('smtp_host');
184 $content['smtp_user'] = postRequestElement('smtp_user');
185 $content['smtp_pass'] = postRequestElement('smtp_pass1');
187 // Database login data
189 foreach ($GLOBALS['install_mysql'] as $key => $value) {
190 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
192 $content['mysql_hidden'] = $OUT;
195 addTemplateToInstallContent('install_page5', $content);
198 case 'finalize': // Write captured data to files
199 if ((isPostRequestElementSet('finalize')) && (!isInstalled())) {
200 // You have submitted data then we have to reset the SQLs
204 * Restore PHPs error handler to prevent ours to handle errors,
205 * e.g. failed connection attempts. We want to handle them on
208 restore_error_handler();
210 // Connect to database server
211 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
214 if (SQL_IS_LINK_UP()) {
215 // Seems to work, also right database?
216 if (SQL_SELECT_DB($GLOBALS['install_mysql']['dbase'], __FILE__, __LINE__) === true) {
218 if ((!isFileReadable(postRequestElement('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestElement('spath') . 'install/menu-'.getLanguage().'.sql'))) {
219 // Installation area not found
220 debug_report_bug(__FILE__, __LINE__, 'SQL dumps not found. Please extract ALL files from the archive or checkout all files out from SVN.');
224 // Any errors detected?
225 if (!ifFatalErrorsDetected()) {
226 // Set type and prefix from POST data
227 setConfigEntry('_TABLE_TYPE' , postRequestElement('mysql', 'type'));
228 setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql', 'prefix'));
230 // Both exists so import them
231 foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
232 // Should be save here because file_exists() is there but we check it again. :)
233 $FQFN = postRequestElement('spath') . 'install/' . $dump . '.sql';
235 // Is the file readable?
236 if (isFileReadable($FQFN)) {
238 $fileContent = readSqlDump($FQFN);
240 // Split it up against ";\n" and merge it into existing SQLs
241 mergeSqls(explode(";\n", $fileContent), 'install');
244 debug_report_bug(__FILE__, __LINE__, sprintf("SQL dump %s is not readable!", $dump));
247 //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
249 // Are some SQLs found?
250 if (countSqls() == 0) {
252 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_SQL_IMPORT_FAILED--}');
256 // Now run all queries through and try to keep out empty or comment queries
257 runFilterChain('run_sqls');
259 // Copy the config template and verify it
260 doInstallWriteLocalConfig();
265 if (ifFatalErrorsDetected()) {
267 foreach (getFatalArray() as $value) {
268 $OUT .= ' <li>' . $value . '</li>';
270 $content['fatal_errors'] = $OUT;
272 foreach ($GLOBALS['install_mysql'] as $key => $value) {
273 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
275 $content['mysql_hidden'] = $OUT;
276 $content['spath'] = postRequestElement('spath');
277 $content['burl'] = postRequestElement('burl');
278 $content['title'] = postRequestElement('title');
279 $content['smtp_host'] = postRequestElement('smtp_host');
280 $content['smtp_user'] = postRequestElement('smtp_user');
281 $content['smtp_pass'] = postRequestElement('smtp_pass1');
284 addTemplateToInstallContent('install_fatal_errors', $content);
286 // We have handled all fatal errors here
289 // Installation is done!
290 redirectToUrl('install.php?page=finished');
293 // Something goes wrong during installation! :-(
294 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_FINALIZER_FAILED--}');
300 // Load template that we are finished
301 addTemplateToInstallContent('install_finished');
304 redirectToUrl('install.php');
309 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestElement('page')));
310 addTemplateToInstallContent('admin_settings_unsaved', '{--WRONG_PAGE--}');
314 // Already installed!
315 addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');