]> git.mxchange.org Git - mailer.git/blob - inc/install-inc.php
Extension ext-network continued:
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 /************************************************************************
39  *      YOU MAY ALSO WANT TO REMOVE THIS FILE AFTER INSTALLTION!        *
40  ************************************************************************/
41
42 // Some security stuff...
43 if (!defined('__SECURITY')) {
44         die();
45 } // END - if
46
47 // Load extension timezone
48 loadExtension('timezone', 'test');
49
50 // Set config entry
51 setConfigEntry('timezone', 'Europe/Berlin');
52
53 // And init timezone
54 FILTER_INIT_TIMEZONE(array());
55
56 // Init variables
57 $GLOBALS['install_mysql'] = array();
58 if ((isPostRequestElementSet('mysql')) && (is_array(postRequestElement('mysql')))) {
59         // Transfer 'mysql' array
60         $GLOBALS['install_mysql'] = postRequestElement('mysql');
61 } // END - if
62
63 // Check if both passwords from SMTP are matching
64 if ((isGetRequestElementSet('page') && (getRequestElement('page') == 5))) {
65         // Okay, we have to check it
66         if (isPostRequestElementSet('smtp_user') && (!isPostRequestElementSet('smtp_host'))) {
67                 // Hostname not set
68                 addToInstallContent('<div class="para">{--INSTALL_SMTP_HOSTNAME_EMPTY--}</div>');
69                 setGetRequestElement('page', 3);
70         } // END - if
71
72         if ((!isPostRequestElementSet('smtp_pass1')) && (isPostRequestElementSet('smtp_pass2'))) {
73                 // Password is empty
74                 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASSWORD1_EMPTY--}</div>');
75                 setGetRequestElement('page', 3);
76         } // END - if
77
78         if ((isPostRequestElementSet('smtp_pass1')) && (!isPostRequestElementSet('smtp_pass2'))) {
79                 // Password repeat is empty
80                 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASSWORD2_EMPTY--}</div>');
81                 setGetRequestElement('page', 3);
82         } // END - if
83
84         if (postRequestElement('smtp_pass1') != postRequestElement('smtp_pass1')) {
85                 // Passwords are not matching
86                 addToInstallContent('<div class="para">{--INSTALL_SMTP_PASS_MISMATCH--}</div>');
87                 setGetRequestElement('page', 3);
88         } // END - if
89 } // END - if
90
91 // Is the mailer installed or no admin registered so far?
92 if ((!isInstalled()) || (!isAdminRegistered())) {
93         // Output page for entered value
94         switch (getRequestElement('page')) {
95                 case 'welcome': // Welcome to the installation!
96                         addTemplateToInstallContent('install_welcome');
97                         break;
98
99                 case '1': // Server path, base URL
100                         // Load template
101                         addTemplateToInstallContent('install_page1');
102                         break;
103
104                 case '2': // Database login data
105                         if (empty($GLOBALS['install_mysql']['dbase']))  $GLOBALS['install_mysql']['dbase']  = 'your_database';
106                         if (empty($GLOBALS['install_mysql']['login']))  $GLOBALS['install_mysql']['login']  = 'your_login';
107                         if (empty($GLOBALS['install_mysql']['host']))   $GLOBALS['install_mysql']['host']   = 'localhost';
108                         if (empty($GLOBALS['install_mysql']['prefix'])) $GLOBALS['install_mysql']['prefix'] = 'mailer';
109                         if (empty($GLOBALS['install_mysql']['type']))   $GLOBALS['install_mysql']['type']   = 'MyISAM';
110                         if (ifFatalErrorsDetected()) {
111                                 addToInstallContent('<div class="install_fatal"><ul>');
112                                 foreach (getFatalArray() as $key => $err) {
113                                         addToInstallContent('<li> {--FATAL_NO--}' . ($key + 1) . ': ' . $err . '</li>');
114                                 } // END - foreach
115                                 addToInstallContent('</ol></div>');
116                         } // END - if
117
118                         $content['mysql_host']   = $GLOBALS['install_mysql']['host'];
119                         $content['mysql_dbase']  = $GLOBALS['install_mysql']['dbase'];
120                         $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
121                         $content['mysql_login']  = $GLOBALS['install_mysql']['login'];
122                         $content['table_type']   = $GLOBALS['install_mysql']['type'];
123                         $content['spath']        = postRequestElement('spath');
124                         $content['burl']         = postRequestElement('burl');
125                         $content['title']        = postRequestElement('title');
126                         $content['slogan']       = postRequestElement('slogan');
127                         $content['email']        = postRequestElement('email');
128
129                         // Load template
130                         addTemplateToInstallContent('install_page2', $content);
131                         break;
132
133                 case '3':
134                         // Set more values
135                         $content['spath']      = postRequestElement('spath');
136                         $content['burl']       = postRequestElement('burl');
137                         $content['title']      = postRequestElement('title');
138                         $content['slogan']     = postRequestElement('slogan');
139                         $content['email']      = postRequestElement('email');
140
141                         // Use default SMTP data
142                         $smtpHost  = '{?SMTP_HOSTNAME?}';
143                         $smtpUser  = '{?SMTP_USER?}';
144                         $smtpPass1 = '{?SMTP_PASSWORD?}';
145                         $smtpPass2 = '{?SMTP_PASSWORD?}';
146
147                         // Overwrite it with the data from sent (failed) form
148                         if (isPostRequestElementSet('smtp_host')) $smtpHost = postRequestElement('smtp_host');
149                         if (isPostRequestElementSet('smtp_user')) $smtpUser = postRequestElement('smtp_user');
150                         if (isPostRequestElementSet('smtp_pass')) {
151                                 $smtpPass1 = postRequestElement('smtp_pass');
152                                 $smtpPass2 = postRequestElement('smtp_pass');
153                         } // END - if
154
155                         // Database login data
156                         $content['mysql_host']   = $GLOBALS['install_mysql']['host'];
157                         $content['mysql_dbase']  = $GLOBALS['install_mysql']['dbase'];
158                         $content['mysql_prefix'] = $GLOBALS['install_mysql']['prefix'];
159                         $content['table_type']   = $GLOBALS['install_mysql']['type'];
160                         $content['mysql_login']  = $GLOBALS['install_mysql']['login'];
161                         $content['mysql_pass1']  = $GLOBALS['install_mysql']['pass1'];
162                         $content['mysql_pass2']  = $GLOBALS['install_mysql']['pass2'];
163
164                         // Set constants for SMTP data
165                         $content['smtp_host']  = $smtpHost;
166                         $content['smtp_user']  = $smtpUser;
167                         $content['smtp_pass1'] = $smtpPass1;
168                         $content['smtp_pass2'] = $smtpPass2;
169
170                         // Load template
171                         addTemplateToInstallContent('install_page3', $content);
172                         break;
173
174                 case '5': // Misc settings
175                         // General settings
176                         $content['spath']  = postRequestElement('spath');
177                         $content['burl']   = postRequestElement('burl');
178                         $content['title']  = postRequestElement('title');
179                         $content['slogan'] = postRequestElement('slogan');
180                         $content['email']  = postRequestElement('email');
181
182                         // SMTP settings
183                         $content['smtp_host'] = postRequestElement('smtp_host');
184                         $content['smtp_user'] = postRequestElement('smtp_user');
185                         $content['smtp_pass'] = postRequestElement('smtp_pass1');
186
187                         // Database login data
188                         $OUT = '';
189                         foreach ($GLOBALS['install_mysql'] as $key => $value) {
190                                 $OUT .= '    <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
191                         } // END - foreach
192                         $content['mysql_hidden'] = $OUT;
193
194                         // Load template
195                         addTemplateToInstallContent('install_page5', $content);
196                         break;
197
198                 case 'finalize': // Write captured data to files
199                         if ((isPostRequestElementSet('finalize')) && (!isInstalled())) {
200                                 // You have submitted data then we have to reset the SQLs
201                                 initSqls();
202
203                                 /*
204                                  * Restore PHPs error handler to prevent ours to handle errors,
205                                  * e.g. failed connection attempts. We want to handle them on
206                                  * our own.
207                                  */
208                                 restore_error_handler();
209
210                                 // Connect to database server
211                                 SQL_CONNECT($GLOBALS['install_mysql']['host'], $GLOBALS['install_mysql']['login'], $GLOBALS['install_mysql']['pass1'], __FILE__, __LINE__);
212
213                                 // Is the link up?
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) {
217                                                 // Check for dumps
218                                                 if ((!isFileReadable(postRequestElement('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestElement('spath') . 'install/menu-'.getLanguage().'.sql'))) {
219                                                         // Installation area not found
220                                                         debug_report_bug(__FILE__, __LINE__, 'SQL dumps not found. Please extract ALL files from the archive or checkout all files out from SVN.');
221                                                         return;
222                                                 } // END - if
223
224                                                 // Any errors detected?
225                                                 if (!ifFatalErrorsDetected()) {
226                                                         // Set type and prefix from POST data
227                                                         setConfigEntry('_TABLE_TYPE'  , postRequestElement('mysql', 'type'));
228                                                         setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql', 'prefix'));
229
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 = postRequestElement('spath') . 'install/' . $dump . '.sql';
234
235                                                                 // Is the file readable?
236                                                                 if (isFileReadable($FQFN)) {
237                                                                         // Read the file
238                                                                         $fileContent = readSqlDump($FQFN);
239
240                                                                         // Split it up against ";\n" and merge it into existing SQLs
241                                                                         mergeSqls(explode(";\n", $fileContent), 'install');
242                                                                 } else {
243                                                                         // Not readable!
244                                                                         debug_report_bug(__FILE__, __LINE__, sprintf("SQL dump %s is not readable!", $dump));
245                                                                 }
246                                                         } // END - foreach
247                                                         //* DEBUG: */ die(__FUNCTION__.'['.__LINE__.']:'<pre>'.print_r(getSqls(), true).'</pre>');
248
249                                                         // Are some SQLs found?
250                                                         if (countSqls() == 0) {
251                                                                 // Abort here
252                                                                 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_SQL_IMPORT_FAILED--}');
253                                                                 return;
254                                                         } // END - if
255
256                                                         // Now run all queries through and try to keep out empty or comment queries
257                                                         runFilterChain('run_sqls');
258
259                                                         // Copy the config template and verify it
260                                                         doInstallWriteLocalConfig();
261                                                 } // END - if
262                                         } // END - if
263                                 } // END - if
264
265                                 if (ifFatalErrorsDetected()) {
266                                         $OUT = '';
267                                         foreach (getFatalArray() as $value) {
268                                                 $OUT .= '    <li>' . $value . '</li>';
269                                         } // END foreach
270                                         $content['fatal_errors'] = $OUT;
271                                         $OUT = '';
272                                         foreach ($GLOBALS['install_mysql'] as $key => $value) {
273                                                 $OUT .= '    <input type="hidden" name="mysql[' . $key . ']" value="' . $value . '" />';
274                                         } // END foreach
275                                         $content['mysql_hidden'] = $OUT;
276                                         $content['spath']      = postRequestElement('spath');
277                                         $content['burl']       = postRequestElement('burl');
278                                         $content['title']      = postRequestElement('title');
279                                         $content['smtp_host']  = postRequestElement('smtp_host');
280                                         $content['smtp_user']  = postRequestElement('smtp_user');
281                                         $content['smtp_pass']  = postRequestElement('smtp_pass1');
282
283                                         // Load template
284                                         addTemplateToInstallContent('install_fatal_errors', $content);
285
286                                         // We have handled all fatal errors here
287                                         initFatalMessages();
288                                 } else {
289                                         // Installation is done!
290                                         redirectToUrl('install.php?page=finished');
291                                 }
292                         } else {
293                                 // Something goes wrong during installation! :-(
294                                 addFatalMessage(__FILE__, __LINE__, '{--INSTALL_FINALIZER_FAILED--}');
295                         }
296                         break;
297
298                 case 'finished':
299                         if (isInstalled()) {
300                                 // Load template that we are finished
301                                 addTemplateToInstallContent('install_finished');
302                         } else {
303                                 // Not finished
304                                 redirectToUrl('install.php');
305                         }
306                         break;
307
308                 default:
309                         logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestElement('page')));
310                         addTemplateToInstallContent('admin_settings_unsaved', '{--WRONG_PAGE--}');
311                         break;
312         } // END - switch
313 } else {
314         // Already installed!
315         addFatalMessage(__FILE__, __LINE__, '{--ALREADY_INSTALLED--}');
316 }
317
318 // [EOF]
319 ?>