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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 /************************************************************************
41 * YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION! *
42 ************************************************************************/
44 // Some security stuff...
45 if (!defined('__SECURITY')) {
49 // Load extension timezone
50 loadExtension('timezone', 'test');
53 setConfigEntry('timezone', 'Europe/Berlin');
56 FILTER_INIT_TIMEZONE();
59 $GLOBALS['install_mysql'] = array();
60 if ((isPostRequestParameterSet('mysql')) && (is_array(postRequestParameter('mysql')))) {
61 // Transfer 'mysql' array
62 $GLOBALS['install_mysql'] = postRequestParameter('mysql');
65 // Check if both passwords from SMTP are matching
66 if ((isGetRequestParameterSet('page') && (getRequestParameter('page') == 5))) {
67 // Okay, we have to check it
68 if (isPostRequestParameterSet('smtp_user') && (!isPostRequestParameterSet('smtp_host'))) {
70 addToInstallContent('<div class="para">{--INSTALL_SMTP_HOSTNAME_EMPTY--}</div>');
71 setGetRequestParameter('page', 3);
74 if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
76 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS1_EMPTY--}</div>');
77 setGetRequestParameter('page', 3);
80 if ((isPostRequestParameterSet('smtp_pass1')) && (!isPostRequestParameterSet('smtp_pass2'))) {
81 // Password repeat is empty
82 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS2_EMPTY--}</div>');
83 setGetRequestParameter('page', 3);
86 if (postRequestParameter('smtp_pass1') != postRequestParameter('smtp_pass1')) {
87 // Passwords are not matching
88 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS_MISMATCH--}</div>');
89 setGetRequestParameter('page', 3);
93 // Is the mailer installed or no admin registered so far?
94 if ((!isInstalled()) || (!isAdminRegistered())) {
95 // Output page for entered value
96 switch (getRequestParameter('page')) {
97 case 'welcome': // Welcome to the installation!
98 addTemplateToInstallContent('install_welcome');
101 case '1': // Server path, base URL
103 addTemplateToInstallContent('install_page1');
106 case '2': // MySQL data (alone!)
107 if (empty($GLOBALS['install_mysql']['dbase'])) $GLOBALS['install_mysql']['dbase'] = 'your_database';
108 if (empty($GLOBALS['install_mysql']['login'])) $GLOBALS['install_mysql']['login'] = 'your_login';
109 if (empty($GLOBALS['install_mysql']['host'])) $GLOBALS['install_mysql']['host'] = 'localhost';
110 if (empty($GLOBALS['install_mysql']['prefix'])) $GLOBALS['install_mysql']['prefix'] = 'mxchange';
111 if (empty($GLOBALS['install_mysql']['type'])) $GLOBALS['install_mysql']['type'] = 'MyISAM';
112 if (ifFatalErrorsDetected()) {
113 addToInstallContent('<div class="install_fatal"><ul>');
114 foreach (getFatalArray() as $key => $err) {
115 addToInstallContent('<li> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</li>');
117 addToInstallContent('</ol></div>');
120 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
121 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
122 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
123 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
124 $content['table_type'] = $GLOBALS['install_mysql']['type'];
125 $content['spath'] = postRequestParameter('spath');
126 $content['burl'] = postRequestParameter('burl');
127 $content['title'] = postRequestParameter('title');
128 $content['slogan'] = postRequestParameter('slogan');
129 $content['email'] = postRequestParameter('email');
132 addTemplateToInstallContent('install_page2', $content);
137 $content['spath'] = postRequestParameter('spath');
138 $content['burl'] = postRequestParameter('burl');
139 $content['title'] = postRequestParameter('title');
140 $content['slogan'] = postRequestParameter('slogan');
141 $content['email'] = postRequestParameter('email');
143 // Use default SMTP data
144 $smtpHost = '{?SMTP_HOSTNAME?}';
145 $smtpUser = '{?SMTP_USER?}';
146 $smtpPass1 = '{?SMTP_PASSWORD?}';
147 $smtpPass2 = '{?SMTP_PASSWORD?}';
149 // Overwrite it with the data from sent (failed) form
150 if (isPostRequestParameterSet('smtp_host')) $smtpHost = postRequestParameter('smtp_host');
151 if (isPostRequestParameterSet('smtp_user')) $smtpUser = postRequestParameter('smtp_user');
152 if (isPostRequestParameterSet('smtp_pass')) {
153 $smtpPass1 = postRequestParameter('smtp_pass');
154 $smtpPass2 = postRequestParameter('smtp_pass');
158 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
159 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
160 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
161 $content['table_type'] = $GLOBALS['install_mysql']['type'];
162 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
163 $content['mysql_pass1'] = $GLOBALS['install_mysql']['pass1'];
164 $content['mysql_pass2'] = $GLOBALS['install_mysql']['pass2'];
166 // Set constants for SMTP data
167 $content['smtp_host'] = $smtpHost;
168 $content['smtp_user'] = $smtpUser;
169 $content['smtp_pass1'] = $smtpPass1;
170 $content['smtp_pass2'] = $smtpPass2;
173 addTemplateToInstallContent('install_page3', $content);
176 case '5': // Misc settings
178 $content['spath'] = postRequestParameter('spath');
179 $content['burl'] = postRequestParameter('burl');
180 $content['title'] = postRequestParameter('title');
181 $content['slogan'] = postRequestParameter('slogan');
182 $content['email'] = postRequestParameter('email');
185 $content['smtp_host'] = postRequestParameter('smtp_host');
186 $content['smtp_user'] = postRequestParameter('smtp_user');
187 $content['smtp_pass'] = postRequestParameter('smtp_pass1');
191 foreach ($GLOBALS['install_mysql'] as $key => $value) {
192 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
194 $content['mysql_hidden'] = $OUT;
197 addTemplateToInstallContent('install_page5', $content);
200 case 'finalize': // Write captured data to files
201 if ((isPostRequestParameterSet('finalize')) && (!isInstalled())) {
202 // You have submitted data then we have to reset the SQLs
205 // Restore PHPs error handler to prevent ours to handle errors,
206 // e.g. failed connection attempts. We want to handle them on
208 restore_error_handler();
210 // Connect to MySQL 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(postRequestParameter('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestParameter('spath') . 'install/menu-'.getLanguage().'.sql'))) {
219 // Installation area not found!
220 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_MISSING_DUMPS--}');
224 // Any errors detected?
225 if (!ifFatalErrorsDetected()) {
226 // Set type and prefix from POST data
227 setConfigEntry('_TABLE_TYPE' , postRequestParameter('mysql', 'type'));
228 setConfigEntry('_MYSQL_PREFIX', postRequestParameter('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 = postRequestParameter('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'] = postRequestParameter('spath');
277 $content['burl'] = postRequestParameter('burl');
278 $content['title'] = postRequestParameter('title');
279 $content['smtp_host'] = postRequestParameter('smtp_host');
280 $content['smtp_user'] = postRequestParameter('smtp_user');
281 $content['smtp_pass'] = postRequestParameter('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", getRequestParameter('page')));
310 addTemplateToInstallContent('admin_settings_unsaved', '{--WRONG_PAGE--}');
314 // Already installed!
315 addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');