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')) {
50 $GLOBALS['install_mysql'] = array();
51 if ((isPostRequestParameterSet('mysql')) && (is_array(postRequestParameter('mysql')))) {
52 // Transfer 'mysql' array
53 $GLOBALS['install_mysql'] = postRequestParameter('mysql');
56 // Check if both passwords from SMTP are matching
57 if ((isGetRequestParameterSet('page') && (getRequestParameter('page') == 5))) {
58 // Okay, we have to check it
59 if (isPostRequestParameterSet('smtp_user') && (!isPostRequestParameterSet('smtp_host'))) {
61 addToInstallContent('<div class="para">{--INSTALL_SMTP_HOSTNAME_EMPTY--}</div>');
62 setGetRequestParameter('page', 3);
65 if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
67 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS1_EMPTY--}</div>');
68 setGetRequestParameter('page', 3);
71 if ((isPostRequestParameterSet('smtp_pass1')) && (!isPostRequestParameterSet('smtp_pass2'))) {
72 // Password repeat is empty
73 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS2_EMPTY--}</div>');
74 setGetRequestParameter('page', 3);
77 if (postRequestParameter('smtp_pass1') != postRequestParameter('smtp_pass1')) {
78 // Passwords are not matching
79 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS_MISMATCH--}</div>');
80 setGetRequestParameter('page', 3);
84 // Is the mailer installed or no admin registered so far?
85 if ((!isInstalled()) || (!isAdminRegistered())) {
86 // Output page for entered value
87 switch (getRequestParameter('page')) {
88 case 'welcome': // Welcome to the installation!
89 addTemplateToInstallContent('install_welcome');
92 case '1': // Server path, base URL
94 addTemplateToInstallContent('install_page1');
97 case '2': // MySQL data (alone!)
98 if (empty($GLOBALS['install_mysql']['dbase'])) $GLOBALS['install_mysql']['dbase'] = 'your_database';
99 if (empty($GLOBALS['install_mysql']['login'])) $GLOBALS['install_mysql']['login'] = 'your_login';
100 if (empty($GLOBALS['install_mysql']['host'])) $GLOBALS['install_mysql']['host'] = 'localhost';
101 if (empty($GLOBALS['install_mysql']['prefix'])) $GLOBALS['install_mysql']['prefix'] = 'mxchange';
102 if (empty($GLOBALS['install_mysql']['type'])) $GLOBALS['install_mysql']['type'] = 'MyISAM';
103 if (ifFatalErrorsDetected()) {
104 addToInstallContent('<div class="install_fatal">');
105 foreach (getFatalArray() as $key => $err) {
106 addToInstallContent('<div class="para"><strong>·</strong> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</div>');
108 addToInstallContent('</div>');
110 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
111 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
112 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
113 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
114 $content['table_type'] = $GLOBALS['install_mysql']['type'];
115 $content['spath'] = postRequestParameter('spath');
116 $content['burl'] = postRequestParameter('burl');
117 $content['title'] = postRequestParameter('title');
118 $content['slogan'] = postRequestParameter('slogan');
119 $content['email'] = postRequestParameter('email');
122 addTemplateToInstallContent('install_page2', $content);
127 $content['spath'] = postRequestParameter('spath');
128 $content['burl'] = postRequestParameter('burl');
129 $content['title'] = postRequestParameter('title');
130 $content['slogan'] = postRequestParameter('slogan');
131 $content['email'] = postRequestParameter('email');
133 // Use default SMTP data
134 $smtpHost = '{?SMTP_HOSTNAME?}';
135 $smtpUser = '{?SMTP_USER?}';
136 $smtpPass1 = '{?SMTP_PASSWORD?}';
137 $smtpPass2 = '{?SMTP_PASSWORD?}';
139 // Overwrite it with the data from sent (failed) form
140 if (isPostRequestParameterSet('smtp_host')) $smtpHost = postRequestParameter('smtp_host');
141 if (isPostRequestParameterSet('smtp_user')) $smtpUser = postRequestParameter('smtp_user');
142 if (isPostRequestParameterSet('smtp_pass')) {
143 $smtpPass1 = postRequestParameter('smtp_pass');
144 $smtpPass2 = postRequestParameter('smtp_pass');
148 $content['mysql_host'] = $GLOBALS['install_mysql']['host'];
149 $content['mysql_dbase'] = $GLOBALS['install_mysql']['dbase'];
150 $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
151 $content['table_type'] = $GLOBALS['install_mysql']['type'];
152 $content['mysql_login'] = $GLOBALS['install_mysql']['login'];
153 $content['mysql_pass1'] = $GLOBALS['install_mysql']['pass1'];
154 $content['mysql_pass2'] = $GLOBALS['install_mysql']['pass2'];
156 // Set constants for SMTP data
157 $content['smtp_host'] = $smtpHost;
158 $content['smtp_user'] = $smtpUser;
159 $content['smtp_pass1'] = $smtpPass1;
160 $content['smtp_pass2'] = $smtpPass2;
163 addTemplateToInstallContent('install_page3', $content);
166 case '5': // Misc settings
168 $content['spath'] = postRequestParameter('spath');
169 $content['burl'] = postRequestParameter('burl');
170 $content['title'] = postRequestParameter('title');
171 $content['slogan'] = postRequestParameter('slogan');
172 $content['email'] = postRequestParameter('email');
175 $content['smtp_host'] = postRequestParameter('smtp_host');
176 $content['smtp_user'] = postRequestParameter('smtp_user');
177 $content['smtp_pass'] = postRequestParameter('smtp_pass1');
181 foreach ($GLOBALS['install_mysql'] as $key => $value) {
182 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
184 $content['mysql_hidden'] = $OUT;
187 addTemplateToInstallContent('install_page5', $content);
190 case 'finalize': // Write captured data to files
191 if ((isPostRequestParameterSet('finalize')) && (!isInstalled())) {
192 // You have submitted data then we have to reset the SQLs
195 // Restore PHPs error handler to prevent ours to handle errors,
196 // e.g. failed connection attempts. We want to handle them on
198 restore_error_handler();
200 // Connect to MySQL server
201 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
204 if (SQL_IS_LINK_UP()) {
205 // Seems to work, also right database?
206 if (SQL_SELECT_DB($GLOBALS['install_mysql']['dbase'], __FILE__, __LINE__) === true) {
208 if ((!isFileReadable(postRequestParameter('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestParameter('spath') . 'install/menu-'.getLanguage().'.sql'))) {
209 // Installation area not found!
210 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_MISSING_DUMPS--}');
214 // Any errors detected?
215 if (!ifFatalErrorsDetected()) {
216 // Set type and prefix from POST data
217 setConfigEntry('_TABLE_TYPE' , postRequestParameter('mysql', 'type'));
218 setConfigEntry('_MYSQL_PREFIX', postRequestParameter('mysql', 'prefix'));
220 // Both exists so import them
221 foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
222 // Should be save here because file_exists() is there but we check it again. :)
223 $FQFN = postRequestParameter('spath') . 'install/' . $dump . '.sql';
225 // Is the file readable?
226 if (isFileReadable($FQFN)) {
228 $fileContent = readSqlDump($FQFN);
230 // Split it up against ";\n" and merge it into existing SQLs
231 mergeSqls(explode(";\n", $fileContent), 'install');
234 debug_report_bug(__FILE__, __LINE__, sprintf("SQL dump %s is not readable!", $dump));
237 //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
239 // Are some SQLs found?
240 if (countSqls() == 0) {
242 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_SQL_IMPORT_FAILED--}');
246 // Now run all queries through and try to keep out empty or comment queries
247 runFilterChain('run_sqls');
249 // Copy the config template and verify it
250 doInstallWriteLocalConfig();
255 if (ifFatalErrorsDetected()) {
257 foreach (getFatalArray() as $value) {
258 $OUT .= ' <li>' . $value . '</li>';
260 $content['fatal_errors'] = $OUT;
262 foreach ($GLOBALS['install_mysql'] as $key => $value) {
263 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
265 $content['mysql_hidden'] = $OUT;
266 $content['spath'] = postRequestParameter('spath');
267 $content['burl'] = postRequestParameter('burl');
268 $content['title'] = postRequestParameter('title');
269 $content['smtp_host'] = postRequestParameter('smtp_host');
270 $content['smtp_user'] = postRequestParameter('smtp_user');
271 $content['smtp_pass'] = postRequestParameter('smtp_pass1');
274 addTemplateToInstallContent('install_fatal_errors', $content);
276 // We have handled all fatal errors here
279 // Installation is done!
280 redirectToUrl('install.php?page=finished');
283 // Something goes wrong during installation! :-(
284 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_FINALIZER_FAILED--}');
290 // Load template that we are finished
291 addTemplateToInstallContent('install_finished');
294 redirectToUrl('install.php');
299 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestParameter('page')));
300 addTemplateToInstallContent('admin_settings_saved', '<div class="install_error">{--WRONG_PAGE--}</div>');
304 // Already installed!
305 addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');