]> git.mxchange.org Git - mailer.git/blob - inc/install-inc.php
Now with more feedback if no payout types are found
[mailer.git] / inc / install-inc.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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 ((isPostRequestElementSet('mysql')) && (is_array(postRequestElement('mysql')))) {
51         // Transfer 'mysql' array
52         $mysql = postRequestElement('mysql');
53 } // END - if
54
55 // Check if both passwords from SMTP are matching
56 if ((isGetRequestElementSet('page') && (getRequestElement('page') == 5))) {
57         // Okay, we have to check it
58         if (isPostRequestElementSet('smtp_user') && (!isPostRequestElementSet('smtp_host'))) {
59                 // Hostname not set
60                 addToInstallContent(getMessage('INSTALL_SMTP_HOSTNAME_EMPTY') . '<br />');
61                 setRequestGetElement('page', 3);
62         } // END - if
63
64         if ((!isPostRequestElementSet('smtp_pass1')) && (isPostRequestElementSet('smtp_pass2'))) {
65                 // Password is empty
66                 addToInstallContent(getMessage('INSTALL_SMTP_PASS1_EMPTY') . '<br />');
67                 setRequestGetElement('page', 3);
68         } // END - if
69
70         if ((isPostRequestElementSet('smtp_pass1')) && (!isPostRequestElementSet('smtp_pass2'))) {
71                 // Password repeat is empty
72                 addToInstallContent(getMessage('INSTALL_SMTP_PASS2_EMPTY') . '<br />');
73                 setRequestGetElement('page', 3);
74         } // END - if
75
76         if (postRequestElement('smtp_pass1') != postRequestElement('smtp_pass1')) {
77                 // Passwords are not matching
78                 addToInstallContent(getMessage('INSTALL_SMTP_PASS_MISMATCH') . '<br />');
79                 setRequestGetElement('page', 3);
80         } // END - if
81 } // END - if
82
83 // Is MXChange installed or no admin registered so far?
84 if ((!isInstalled()) || (!isAdminRegistered())) {
85         // Output page for entered value
86         switch (getRequestElement('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('<span class="install_fatal">');
104                                 foreach (getFatalArray() as $key => $err) {
105                                         addToInstallContent('<strong>&middot;</strong>&nbsp;{--FATAL_NO--}' . ($key + 1) . ':&nbsp;' . $err . '<br />');
106                                 }
107                                 addToInstallContent('</span><br />');
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']        = postRequestElement('spath');
115                         $content['burl']         = postRequestElement('burl');
116                         $content['title']        = postRequestElement('title');
117                         $content['slogan']       = postRequestElement('slogan');
118                         $content['email']        = postRequestElement('email');
119
120                         // Load template
121                         addTemplateToInstallContent('install_page2', $content);
122                         break;
123
124                 case 3:
125                         // Set more values
126                         $content['spath']      = postRequestElement('spath');
127                         $content['burl']       = postRequestElement('burl');
128                         $content['title']      = postRequestElement('title');
129                         $content['slogan']     = postRequestElement('slogan');
130                         $content['email']      = postRequestElement('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 (isPostRequestElementSet('smtp_host')) $smtpHost = postRequestElement('smtp_host');
140                         if (isPostRequestElementSet('smtp_user')) $smtpUser = postRequestElement('smtp_user');
141                         if (isPostRequestElementSet('smtp_pass')) {
142                                 $smtpPass1 = postRequestElement('smtp_pass');
143                                 $smtpPass2 = postRequestElement('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']  = postRequestElement('spath');
168                         $content['burl']   = postRequestElement('burl');
169                         $content['title']  = postRequestElement('title');
170                         $content['slogan'] = postRequestElement('slogan');
171                         $content['email']  = postRequestElement('email');
172
173                         // SMTP settings
174                         $content['smtp_host'] = postRequestElement('smtp_host');
175                         $content['smtp_user'] = postRequestElement('smtp_user');
176                         $content['smtp_pass'] = postRequestElement('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 ((isPostRequestElementSet('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(postRequestElement('spath') . 'install/tables.sql')) || (!isFileReadable(postRequestElement('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'  , postRequestElement('mysql', 'type'));
208                                                         setConfigEntry('_MYSQL_PREFIX', postRequestElement('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 = postRequestElement('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                                                                         // Compile all config entries (we use a filter here, yes...)
221                                                                         $fileContent = FILTER_COMPILE_CONFIG($fileContent);
222
223                                                                         // Split it up against ";\n" and merge it into existing SQLs
224                                                                         mergeSqls(explode(";\n", $fileContent), 'install');
225                                                                 } else {
226                                                                         // Not readable!
227                                                                         debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
228                                                                 }
229                                                         } // END - foreach
230                                                         //* DEBUG: */ die('<pre>'.print_r(getSqls(), true).'</pre>');
231
232                                                         // Are some SQLs found?
233                                                         if (countSqls() == 0) {
234                                                                 // Abort here
235                                                                 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
236                                                                 return;
237                                                         } // END - if
238
239                                                         // Now run all queries through and try to keep out empty or comment queries
240                                                         runFilterChain('run_sqls');
241
242                                                         // Copy the config template and verify it
243                                                         doInstallWriteLocalConfig();
244                                                 } // END - if
245                                         } // END - if
246                                 } // END - if
247
248                                 if (getTotalFatalErrors() > 0) {
249                                         $OUT = '';
250                                         foreach (getFatalArray() as $value) {
251                                                 $OUT .= "    <li>" . $value . "</li>\n";
252                                         } // END foreach
253                                         $content['fatal_errors'] = $OUT;
254                                         $OUT = '';
255                                         foreach ($mysql as $key => $value) {
256                                                 $OUT .= "    <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
257                                         } // END foreach
258                                         $content['mysql_hidden'] = $OUT;
259                                         $content['spath']      = postRequestElement('spath');
260                                         $content['burl']       = postRequestElement('burl');
261                                         $content['title']      = postRequestElement('title');
262                                         $content['smtp_host']  = postRequestElement('smtp_host');
263                                         $content['smtp_user']  = postRequestElement('smtp_user');
264                                         $content['smtp_pass']  = postRequestElement('smtp_pass1');
265
266                                         // Load template
267                                         addTemplateToInstallContent('install_fatal_errors', $content);
268                                 } else {
269                                         // Installation is done!
270                                         redirectToUrl('install.php?page=finished');
271                                 }
272                         } else {
273                                 // Something goes wrong during installation! :-(
274                                 addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
275                         }
276                         break;
277
278                 case 'finished':
279                         if (isInstalled()) {
280                                 // Load template that we are finished
281                                 addTemplateToInstallContent('install_finished');
282                         } else {
283                                 // Not finished
284                                 redirectToUrl('install.php');
285                         }
286                         break;
287
288                 default:
289                         logDebugMessage(__FILE__, __LINE__, sprintf("Wrong page %s detected", getRequestElement('page')));
290                         addTemplateToInstallContent('admin_settings_saved', "<div class=\"install_error\">{--WRONG_PAGE--}</div>");
291                         break;
292         } // END - switch
293 } else {
294         // Already installed!
295         addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));
296 }
297
298 // [EOF]
299 ?>