make-euros has replied me, now when you add request parameters only those from select...
[mailer.git] / inc / install-inc.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 08/29/2003 *
4  * ===================                          Last change: 11/11/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : install-inc.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for installation procedure             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer die Installationsroutine         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 /************************************************************************
40  *      YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION!        *
41  ************************************************************************/
42
43 // Some security stuff...
44 if (!defined('__SECURITY')) {
45         die();
46 } // END - if
47
48 // Init variables
49 $mysql = array();
50 if ((isPostRequestParameterSet('mysql')) && (is_array(postRequestParameter('mysql')))) {
51         // Transfer 'mysql' array
52         $mysql = postRequestParameter('mysql');
53 } // END - if
54
55 // Check if both passwords from SMTP are matching
56 if ((isGetRequestParameterSet('page') && (getRequestParameter('page') == 5))) {
57         // Okay, we have to check it
58         if (isPostRequestParameterSet('smtp_user') && (!isPostRequestParameterSet('smtp_host'))) {
59                 // Hostname not set
60                 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_HOSTNAME_EMPTY') . '</div>');
61                 setGetRequestParameter('page', 3);
62         } // END - if
63
64         if ((!isPostRequestParameterSet('smtp_pass1')) && (isPostRequestParameterSet('smtp_pass2'))) {
65                 // Password is empty
66                 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_PASS1_EMPTY') . '</div>');
67                 setGetRequestParameter('page', 3);
68         } // END - if
69
70         if ((isPostRequestParameterSet('smtp_pass1')) && (!isPostRequestParameterSet('smtp_pass2'))) {
71                 // Password repeat is empty
72                 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_PASS2_EMPTY') . '</div>');
73                 setGetRequestParameter('page', 3);
74         } // END - if
75
76         if (postRequestParameter('smtp_pass1') != postRequestParameter('smtp_pass1')) {
77                 // Passwords are not matching
78                 addToInstallContent('<div class="para">' . getMessage('INSTALL_SMTP_PASS_MISMATCH') . '</div>');
79                 setGetRequestParameter('page', 3);
80         } // END - if
81 } // END - if
82
83 // Is the mailer installed or no admin registered so far?
84 if ((!isInstalled()) || (!isAdminRegistered())) {
85         // Output page for entered value
86         switch (getRequestParameter('page')) {
87                 case 'welcome': // Welcome to the installation!
88                         addTemplateToInstallContent('install_welcome');
89                         break;
90
91                 case '1': // Server path, base URL
92                         // Load template
93                         addTemplateToInstallContent('install_page1');
94                         break;
95
96                 case '2': // MySQL data (alone!)
97                         if (empty($mysql['dbase']))  $mysql['dbase']  = 'your_database';
98                         if (empty($mysql['login']))  $mysql['login']  = 'your_login';
99                         if (empty($mysql['host']))   $mysql['host']   = 'localhost';
100                         if (empty($mysql['prefix'])) $mysql['prefix'] = 'mxchange';
101                         if (empty($mysql['type']))   $mysql['type']   = 'MyISAM';
102                         if (getTotalFatalErrors() > 0) {
103                                 addToInstallContent('<div class="install_fatal">');
104                                 foreach (getFatalArray() as $key => $err) {
105                                         addToInstallContent('<div class="para"><strong>&middot;</strong>&nbsp;{--FATAL_NO--}' . ($key + 1) . ':&nbsp;' . $err . '</div>');
106                                 }
107                                 addToInstallContent('</div>');
108                         }
109                         $content['mysql_host']   = $mysql['host'];
110                         $content['mysql_dbase']  = $mysql['dbase'];
111                         $content['mysql_prefix'] = $mysql['prefix'];
112                         $content['mysql_login']  = $mysql['login'];
113                         $content['table_type']   = $mysql['type'];
114                         $content['spath']        = postRequestParameter('spath');
115                         $content['burl']         = postRequestParameter('burl');
116                         $content['title']        = postRequestParameter('title');
117                         $content['slogan']       = postRequestParameter('slogan');
118                         $content['email']        = postRequestParameter('email');
119
120                         // Load template
121                         addTemplateToInstallContent('install_page2', $content);
122                         break;
123
124                 case '3':
125                         // Set more values
126                         $content['spath']      = postRequestParameter('spath');
127                         $content['burl']       = postRequestParameter('burl');
128                         $content['title']      = postRequestParameter('title');
129                         $content['slogan']     = postRequestParameter('slogan');
130                         $content['email']      = postRequestParameter('email');
131
132                         // Use default SMTP data
133                         $smtpHost  = getConfig('SMTP_HOSTNAME');
134                         $smtpUser  = getConfig('SMTP_USER');
135                         $smtpPass1 = getConfig('SMTP_PASSWORD');
136                         $smtpPass2 = getConfig('SMTP_PASSWORD');
137
138                         // Overwrite it with the data from sent (failed) form
139                         if (isPostRequestParameterSet('smtp_host')) $smtpHost = postRequestParameter('smtp_host');
140                         if (isPostRequestParameterSet('smtp_user')) $smtpUser = postRequestParameter('smtp_user');
141                         if (isPostRequestParameterSet('smtp_pass')) {
142                                 $smtpPass1 = postRequestParameter('smtp_pass');
143                                 $smtpPass2 = postRequestParameter('smtp_pass');
144                         } // END - if
145
146                         // MySQL settings
147                         $content['mysql_host']   = $mysql['host'];
148                         $content['mysql_dbase']  = $mysql['dbase'];
149                         $content['mysql_prefix'] = $mysql['prefix'];
150                         $content['table_type']   = $mysql['type'];
151                         $content['mysql_login']  = $mysql['login'];
152                         $content['mysql_pass1']  = $mysql['pass1'];
153                         $content['mysql_pass2']  = $mysql['pass2'];
154
155                         // Set constants for SMTP data
156                         $content['smtp_host']  = $smtpHost;
157                         $content['smtp_user']  = $smtpUser;
158                         $content['smtp_pass1'] = $smtpPass1;
159                         $content['smtp_pass2'] = $smtpPass2;
160
161                         // Load template
162                         addTemplateToInstallContent('install_page3', $content);
163                         break;
164
165                 case '5': // Misc settings
166                         // General settings
167                         $content['spath']  = postRequestParameter('spath');
168                         $content['burl']   = postRequestParameter('burl');
169                         $content['title']  = postRequestParameter('title');
170                         $content['slogan'] = postRequestParameter('slogan');
171                         $content['email']  = postRequestParameter('email');
172
173                         // SMTP settings
174                         $content['smtp_host'] = postRequestParameter('smtp_host');
175                         $content['smtp_user'] = postRequestParameter('smtp_user');
176                         $content['smtp_pass'] = postRequestParameter('smtp_pass1');
177
178                         // MySQL data
179                         $OUT = '';
180                         foreach ($mysql as $key => $value) {
181                                 $OUT .= "    <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
182                         } // END - foreach
183                         $content['mysql_hidden'] = $OUT;
184
185                         // Load template
186                         addTemplateToInstallContent('install_page5', $content);
187                         break;
188
189                 case 'finalize': // Write captured data to files
190                         if ((isPostRequestParameterSet('finalize')) && (!isInstalled())) {
191                                 // You have submitted data then we have to reset the SQLs
192                                 initSqls();
193
194                                 // Connect to MySQL server
195                                 SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
196                                 if (SQL_IS_LINK_UP()) {
197                                         // Seems to work, also right database?
198                                         if (SQL_SELECT_DB($mysql['dbase'], __FILE__, __LINE__) === true) {
199                                                 // Automatically run install.sql
200                                                 if ((!isFileReadable(postRequestParameter('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestParameter('spath') . 'install/menu-'.getLanguage().'.sql'))) {
201                                                         // Installation area not found!
202                                                         addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
203                                                 } // END - if
204
205                                                 if (getTotalFatalErrors() == '0') {
206                                                         // Set type and prefix from POST data
207                                                         setConfigEntry('_TABLE_TYPE'  , postRequestParameter('mysql', 'type'));
208                                                         setConfigEntry('_MYSQL_PREFIX', postRequestParameter('mysql', 'prefix'));
209
210                                                         // Both exists so import them
211                                                         foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
212                                                                 // Should be save here because file_exists() is there but we check it again. :)
213                                                                 $FQFN = postRequestParameter('spath') . 'install/' . $dump . '.sql';
214
215                                                                 // Is the file readable?
216                                                                 if (isFileReadable($FQFN)) {
217                                                                         // Read the file
218                                                                         $fileContent = readFromFile($FQFN, true);
219
220                                                                         // Split it up against ";\n" and merge it into existing SQLs
221                                                                         mergeSqls(explode(";\n", $fileContent), 'install');
222                                                                 } else {
223                                                                         // Not readable!
224                                                                         debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
225                                                                 }
226                                                         } // END - foreach
227                                                         //* DEBUG: */ die('<pre>'.print_r(getSqls(), true).'</pre>');
228
229                                                         // Are some SQLs found?
230                                                         if (countSqls() == '0') {
231                                                                 // Abort here
232                                                                 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
233                                                                 return;
234                                                         } // END - if
235
236                                                         // Now run all queries through and try to keep out empty or comment queries
237                                                         runFilterChain('run_sqls');
238
239                                                         // Copy the config template and verify it
240                                                         doInstallWriteLocalConfig();
241                                                 } // END - if
242                                         } // END - if
243                                 } // END - if
244
245                                 if (getTotalFatalErrors() > 0) {
246                                         $OUT = '';
247                                         foreach (getFatalArray() as $value) {
248                                                 $OUT .= '    <li>' . $value . '</li>';
249                                         } // END foreach
250                                         $content['fatal_errors'] = $OUT;
251                                         $OUT = '';
252                                         foreach ($mysql as $key => $value) {
253                                                 $OUT .= '    <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
254                                         } // END foreach
255                                         $content['mysql_hidden'] = $OUT;
256                                         $content['spath']      = postRequestParameter('spath');
257                                         $content['burl']       = postRequestParameter('burl');
258                                         $content['title']      = postRequestParameter('title');
259                                         $content['smtp_host']  = postRequestParameter('smtp_host');
260                                         $content['smtp_user']  = postRequestParameter('smtp_user');
261                                         $content['smtp_pass']  = postRequestParameter('smtp_pass1');
262
263                                         // Load template
264                                         addTemplateToInstallContent('install_fatal_errors', $content);
265                                 } else {
266                                         // Installation is done!
267                                         redirectToUrl('install.php?page=finished');
268                                 }
269                         } else {
270                                 // Something goes wrong during installation! :-(
271                                 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
272                         }
273                         break;
274
275                 case 'finished':
276                         if (isInstalled()) {
277                                 // Load template that we are finished
278                                 addTemplateToInstallContent('install_finished');
279                         } else {
280                                 // Not finished
281                                 redirectToUrl('install.php');
282                         }
283                         break;
284
285                 default:
286                         logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestParameter('page')));
287                         addTemplateToInstallContent('admin_settings_saved', '<div class="install_error">{--WRONG_PAGE--}</div>');
288                         break;
289         } // END - switch
290 } else {
291         // Already installed!
292         addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));
293 }
294
295 // [EOF]
296 ?>