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 - 2012 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 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isInstallationPhase())) {
43 // Load extension timezone
44 loadExtension('timezone', 'test');
47 setConfigEntry('timezone', 'Europe/Berlin');
50 FILTER_INIT_TIMEZONE(array());
53 $GLOBALS['install_mysql'] = array();
54 if ((isPostRequestElementSet('mysql')) && (ifPostContainsSelections('mysql'))) {
55 // Transfer 'mysql' array
56 $GLOBALS['install_mysql'] = postRequestElement('mysql');
59 // Check if both passwords from SMTP are matching
60 if ((isGetRequestElementSet('install_page') && (getRequestElement('install_page') == 5))) {
61 // Okay, we have to check it
62 if (isPostRequestElementSet('smtp_user') && (!isPostRequestElementSet('smtp_host'))) {
64 addToInstallContent('<div class="para">{--INSTALLER_SMTP_HOSTNAME_EMPTY--}</div>');
65 setGetRequestElement('install_page', 3);
68 if ((!isPostRequestElementSet('smtp_pass1')) && (isPostRequestElementSet('smtp_pass2'))) {
70 addToInstallContent('<div class="para">{--INSTALLER_SMTP_PASSWORD1_EMPTY--}</div>');
71 setGetRequestElement('install_page', 3);
74 if ((isPostRequestElementSet('smtp_pass1')) && (!isPostRequestElementSet('smtp_pass2'))) {
75 // Password repeat is empty
76 addToInstallContent('<div class="para">{--INSTALLER_SMTP_PASSWORD2_EMPTY--}</div>');
77 setGetRequestElement('install_page', 3);
80 if (postRequestElement('smtp_pass1') != postRequestElement('smtp_pass1')) {
81 // Passwords are not matching
82 addToInstallContent('<div class="para">{--INSTALLER_SMTP_PASS_MISMATCH--}</div>');
83 setGetRequestElement('install_page', 3);
87 // Is the mailer installed or no admin registered so far?
88 if ((!isInstalled()) || (!isAdminRegistered())) {
89 // Output page for entered value
90 switch (getRequestElement('install_page')) {
91 case 'welcome': // Welcome to the installation!
92 addTemplateToInstallContent('install_welcome');
95 case '1': // Server path, base URL
97 addTemplateToInstallContent('install_page1');
100 case '2': // Database login data
101 if (empty($GLOBALS['install_mysql']['dbase'])) $GLOBALS['install_mysql']['dbase'] = 'your_database';
102 if (empty($GLOBALS['install_mysql']['login'])) $GLOBALS['install_mysql']['login'] = 'your_login';
103 if (empty($GLOBALS['install_mysql']['host'])) $GLOBALS['install_mysql']['host'] = 'localhost';
104 if (empty($GLOBALS['install_mysql']['prefix'])) $GLOBALS['install_mysql']['prefix'] = 'mailer';
105 if (empty($GLOBALS['install_mysql']['type'])) $GLOBALS['install_mysql']['type'] = 'MyISAM';
106 if (ifFatalErrorsDetected()) {
107 addToInstallContent('<div class="install_fatal"><ul>');
108 foreach (getFatalArray() as $key => $err) {
109 addToInstallContent('<li> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</li>');
111 addToInstallContent('</ol></div>');
114 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
115 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
116 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
117 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
118 $content['table_type'] = $GLOBALS['install_mysql']['type'];
119 $content['spath'] = postRequestElement('spath');
120 $content['burl'] = postRequestElement('burl');
121 $content['title'] = postRequestElement('title');
122 $content['slogan'] = postRequestElement('slogan');
123 $content['email'] = postRequestElement('email');
126 addTemplateToInstallContent('install_page2', $content);
131 $content['spath'] = postRequestElement('spath');
132 $content['burl'] = postRequestElement('burl');
133 $content['title'] = postRequestElement('title');
134 $content['slogan'] = postRequestElement('slogan');
135 $content['email'] = postRequestElement('email');
137 // Use default SMTP data
138 $smtpHost = '{?SMTP_HOSTNAME?}';
139 $smtpUser = '{?SMTP_USER?}';
140 $smtpPass1 = '{?SMTP_PASSWORD?}';
141 $smtpPass2 = '{?SMTP_PASSWORD?}';
143 // Overwrite it with the data from sent (failed) form
144 if (isPostRequestElementSet('smtp_host')) $smtpHost = postRequestElement('smtp_host');
145 if (isPostRequestElementSet('smtp_user')) $smtpUser = postRequestElement('smtp_user');
146 if (isPostRequestElementSet('smtp_pass')) {
147 $smtpPass1 = postRequestElement('smtp_pass');
148 $smtpPass2 = postRequestElement('smtp_pass');
151 // Database login data
152 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
153 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
154 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
155 $content['table_type'] = $GLOBALS['install_mysql']['type'];
156 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
157 $content['mysql_pass1'] = $GLOBALS['install_mysql']['pass1'];
158 $content['mysql_pass2'] = $GLOBALS['install_mysql']['pass2'];
160 // Set constants for SMTP data
161 $content['smtp_host'] = $smtpHost;
162 $content['smtp_user'] = $smtpUser;
163 $content['smtp_pass1'] = $smtpPass1;
164 $content['smtp_pass2'] = $smtpPass2;
167 addTemplateToInstallContent('install_page3', $content);
170 case '5': // Misc settings
172 $content['spath'] = postRequestElement('spath');
173 $content['burl'] = postRequestElement('burl');
174 $content['title'] = postRequestElement('title');
175 $content['slogan'] = postRequestElement('slogan');
176 $content['email'] = postRequestElement('email');
179 $content['smtp_host'] = postRequestElement('smtp_host');
180 $content['smtp_user'] = postRequestElement('smtp_user');
181 $content['smtp_pass'] = postRequestElement('smtp_pass1');
183 // Database login data
185 foreach ($GLOBALS['install_mysql'] as $key => $value) {
186 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
188 $content['mysql_hidden'] = $OUT;
191 addTemplateToInstallContent('install_page5', $content);
194 case 'finalize': // Write captured data to files
195 if ((isPostRequestElementSet('finalize')) && (!isInstalled())) {
196 // You have submitted data then we have to reset the SQLs
200 * Restore PHPs error handler to prevent ours to handle errors,
201 * e.g. failed connection attempts. We want to handle them on
204 restore_error_handler();
206 // Connect to database server
207 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
210 if (SQL_IS_LINK_UP()) {
211 // Seems to work, also right database?
212 if (SQL_SELECT_DB($GLOBALS['install_mysql']['dbase'], __FILE__, __LINE__) === true) {
214 if ((!isFileReadable(postRequestElement('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestElement('spath') . 'install/menu-'.getLanguage().'.sql'))) {
215 // Installation area not found
216 reportBug(__FILE__, __LINE__, 'SQL dumps not found. Please extract ALL files from the archive or checkout all files out from SVN.');
220 // Any errors detected?
221 if (!ifFatalErrorsDetected()) {
222 // Set type, prefix from POST data and database name for later queries
223 setConfigEntry('_TABLE_TYPE' , postRequestElement('mysql', 'type'));
224 setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql', 'prefix'));
225 setConfigEntry('__DB_NAME' , $GLOBALS['install_mysql']['dbase']);
227 // Both exists so import them
228 foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
229 // Should be save here because file_exists() is there but we check it again. :)
230 $FQFN = postRequestElement('spath') . 'install/' . $dump . '.sql';
232 // Is the file readable?
233 if (isFileReadable($FQFN)) {
235 $fileContent = readSqlDump($FQFN);
237 // Split it up against ";\n" and merge it into existing SQLs
238 mergeSqls(explode(";\n", $fileContent), 'install');
241 reportBug(__FILE__, __LINE__, sprintf("SQL dump %s is not readable.", $dump));
244 //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
246 // Are some SQLs found?
247 if (countSqls() == 0) {
249 addFatalMessage(__FILE__, __LINE__, '{--INSTALLER_SQL_IMPORT_FAILED--}');
253 // Now run all queries through
254 runFilterChain('run_sqls');
256 // Copy the config template and verify it
257 doInstallWriteLocalConfigurationFile(postRequestElement('spath'));
262 // Are some fatal errors there?
263 if (ifFatalErrorsDetected()) {
265 foreach (getFatalArray() as $value) {
266 $OUT .= ' <li>' . $value . '</li>';
268 $content['fatal_errors'] = $OUT;
270 foreach ($GLOBALS['install_mysql'] as $key => $value) {
271 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
273 $content['mysql_hidden'] = $OUT;
274 $content['spath'] = postRequestElement('spath');
275 $content['burl'] = postRequestElement('burl');
276 $content['title'] = postRequestElement('title');
277 $content['smtp_host'] = postRequestElement('smtp_host');
278 $content['smtp_user'] = postRequestElement('smtp_user');
279 $content['smtp_pass'] = postRequestElement('smtp_pass1');
282 addTemplateToInstallContent('install_fatal_errors', $content);
284 // We have handled all fatal errors here
287 // Register ext-sql_patches
288 if ((registerExtension('sql_patches', NULL)) && (registerExtension('task', NULL))) {
289 // Installation is done!
290 redirectToUrl('install.php?install_page=finished');
292 // Something goes wrong on registration of ext-sql_patches
293 addFatalMessage(__FILE__, __LINE__, '{--INSTALLER_FINALIZER_CANNOT_REGISTER_SQL_PATCHES--}');
297 // Something goes wrong during installation! :-(
298 addFatalMessage(__FILE__, __LINE__, '{--INSTALLER_FINALIZER_FAILED--}');
304 // Load template that we are finished
305 addTemplateToInstallContent('install_finished');
308 redirectToUrl('install.php');
313 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong install_page=%s detected", getRequestElement('install_page')));
314 addTemplateToInstallContent('admin_settings_unsaved', '{--WRONG_PAGE--}');
318 // Already installed!
319 addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');