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">' . getMessage('INSTALL_SMTP_HOSTNAME_EMPTY') . '</div>');
62 setGetRequestParameter('page', 3);
65 if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
67 addToInstallContent('<div class="para">' . getMessage('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">' . getMessage('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">' . getMessage('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 = getConfig('SMTP_HOSTNAME');
135 $smtpUser = getConfig('SMTP_USER');
136 $smtpPass1 = getConfig('SMTP_PASSWORD');
137 $smtpPass2 = getConfig('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 . "\" />\n";
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 // Connect to MySQL server
196 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
199 if (SQL_IS_LINK_UP()) {
200 // Seems to work, also right database?
201 if (SQL_SELECT_DB($GLOBALS['install_mysql']['dbase'], __FILE__, __LINE__) === true) {
203 if ((!isFileReadable(postRequestParameter('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestParameter('spath') . 'install/menu-'.getLanguage().'.sql'))) {
204 // Installation area not found!
205 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
209 // Any errors detected?
210 if (!ifFatalErrorsDetected()) {
211 // Set type and prefix from POST data
212 setConfigEntry('_TABLE_TYPE' , postRequestParameter('mysql', 'type'));
213 setConfigEntry('_MYSQL_PREFIX', postRequestParameter('mysql', 'prefix'));
215 // Both exists so import them
216 foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
217 // Should be save here because file_exists() is there but we check it again. :)
218 $FQFN = postRequestParameter('spath') . 'install/' . $dump . '.sql';
220 // Is the file readable?
221 if (isFileReadable($FQFN)) {
223 $fileContent = readSqlDump($FQFN);
225 // Split it up against ";\n" and merge it into existing SQLs
226 mergeSqls(explode(";\n", $fileContent), 'install');
229 debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
232 //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
234 // Are some SQLs found?
235 if (countSqls() == 0) {
237 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
241 // Now run all queries through and try to keep out empty or comment queries
242 runFilterChain('run_sqls');
244 // Copy the config template and verify it
245 doInstallWriteLocalConfig();
250 if (ifFatalErrorsDetected()) {
252 foreach (getFatalArray() as $value) {
253 $OUT .= ' <li>' . $value . '</li>';
255 $content['fatal_errors'] = $OUT;
257 foreach ($GLOBALS['install_mysql'] as $key => $value) {
258 $OUT .= ' <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
260 $content['mysql_hidden'] = $OUT;
261 $content['spath'] = postRequestParameter('spath');
262 $content['burl'] = postRequestParameter('burl');
263 $content['title'] = postRequestParameter('title');
264 $content['smtp_host'] = postRequestParameter('smtp_host');
265 $content['smtp_user'] = postRequestParameter('smtp_user');
266 $content['smtp_pass'] = postRequestParameter('smtp_pass1');
269 addTemplateToInstallContent('install_fatal_errors', $content);
271 // Installation is done!
272 redirectToUrl('install.php?page=finished');
275 // Something goes wrong during installation! :-(
276 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
282 // Load template that we are finished
283 addTemplateToInstallContent('install_finished');
286 redirectToUrl('install.php');
291 logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestParameter('page')));
292 addTemplateToInstallContent('admin_settings_saved', '<div class="install_error">{--WRONG_PAGE--}</div>');
296 // Already installed!
297 addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));