]> git.mxchange.org Git - mailer.git/blob - inc/install-functions.php
ef8ae8debbb85321c92c052fea8a83a3ca0f6156
[mailer.git] / inc / install-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/22/2009 *
4  * ===================                          Last change: 10/22/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : install-functions.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 - 2012 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 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isInstallationPhase())) {
40         die();
41 } // END - if
42
43 // Init installer
44 function initInstaller () {
45         // Initialize installer group array
46         $GLOBALS['installer_groups'] = array(
47                 // base_data
48                 'base_path'       => 'base_data',
49                 'base_url'        => 'base_data',
50                 'main_title'      => 'base_data',
51                 'slogan'          => 'base_data',
52                 'webmaster'       => 'base_data',
53                 // database_config
54                 'mysql_host'      => 'database_config',
55                 'mysql_dbase'     => 'database_config',
56                 'mysql_prefix'    => 'database_config',
57                 'mysql_engine'    => 'database_config',
58                 'mysql_login'     => 'database_config',
59                 'mysql_password1' => 'database_config',
60                 'mysql_password2' => 'database_config',
61                 // smtp_config
62                 'smtp_host'       => 'smtp_config',
63                 'smtp_user'       => 'smtp_config',
64                 'smtp_password1'  => 'smtp_config',
65                 'smtp_password2'  => 'smtp_config',
66                 // other_config
67                 'output_mode'     => 'other_config',
68                 'warn_no_pass'    => 'other_config',
69                 'write_footer'    => 'other_config',
70                 'enable_backlink' => 'other_config',
71         );
72 }
73
74 // Write the local config-local.php file from "template"
75 function doInstallWriteLocalConfigurationFile ($path, $url, $title, $slogan, $email, $noPassword, $writeFooter, $backLink, $databaseHost, $databaseName, $databaseLogin, $databasePassword, $databasePrefix, $databaseType, $smtpHost, $smtpUser, $smtpPassword) {
76         // Copy the config template and verify it
77         copyFileVerified($path . 'inc/config-local.php.dist', $path . getCachePath() . 'config-local.php', 0644);
78
79         /*
80          * Ok, all done. So we can write the config data to the php files. Do only
81          * write these if they differ from auto-detected values.
82          */
83         if ($path != getPath()) {
84                 changeDataInLocalConfigurationFile('SERVER-PATH', "setConfigEntry('PATH', '", "');", $path, 0);
85         } // END - if
86         if ($url != getUrl()) {
87                 changeDataInLocalConfigurationFile('HOST-URL', "setConfigEntry('URL', '", "');", $url, 0);
88         } // END - if
89
90         // Write more data
91         changeDataInLocalConfigurationFile('MAIN-TITLE', "setConfigEntry('MAIN_TITLE', '", "');", $title, 0);
92         changeDataInLocalConfigurationFile('SLOGAN', "setConfigEntry('SLOGAN', '", "');", $slogan, 0);
93         changeDataInLocalConfigurationFile('WEBMASTER', "setConfigEntry('WEBMASTER', '", "');", $email, 0);
94         changeDataInLocalConfigurationFile('NULLPASS-WARNING', "setConfigEntry('WARN_NO_PASS', '", "');", $noPassword, 0);
95         changeDataInLocalConfigurationFile('WRITE-FOOTER', "setConfigEntry('WRITE_FOOTER', '", "');", $writeFooter, 0);
96         changeDataInLocalConfigurationFile('BACKLINK', "setConfigEntry('ENABLE_BACKLINK', '", "');", $backLink, 0);
97         // @TODO DEACTIVATED: changeDataInLocalConfigurationFile('OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestElement('omode'), 0);
98         changeDataInLocalConfigurationFile('MYSQL-HOST', "      'host'     => '", "',", $databaseHost, 0);
99         changeDataInLocalConfigurationFile('MYSQL-DBASE', "     'dbase'    => '", "',", $databaseName, 0);
100         changeDataInLocalConfigurationFile('MYSQL-LOGIN', "     'login'    => '", "',", $databaseLogin, 0);
101         changeDataInLocalConfigurationFile('MYSQL-PASSWORD', "  'password' => '", "',", $databasePassword, 0);
102         changeDataInLocalConfigurationFile('MYSQL-PREFIX', "setConfigEntry('_MYSQL_PREFIX', '", "');", $databasePrefix, 0);
103         changeDataInLocalConfigurationFile('TABLE-TYPE', "setConfigEntry('_TABLE_TYPE', '", "');", $databaseType, 0);
104         changeDataInLocalConfigurationFile('SMTP-HOSTNAME', "setConfigEntry('SMTP_HOSTNAME', '", "');", $smtpHost, 0);
105         changeDataInLocalConfigurationFile('SMTP-USER', "setConfigEntry('SMTP_USER', '", "');", $smtpUser, 0);
106         changeDataInLocalConfigurationFile('SMTP-PASSWORD', "setConfigEntry('SMTP_PASSWORD', '", "');", $smtpPassword, 0);
107
108         // Generate a long site-key and write it
109         changeDataInLocalConfigurationFile('SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", generatePassword(50), 0);
110
111         // Script is now installed
112         changeDataInLocalConfigurationFile('INSTALLED', "setConfigEntry('MAILER_INSTALLED', '", "');", 'Y', 0);
113 }
114
115 // Adds a given template with content to install output stream
116 function addTemplateToInstallContent ($template, $content = array()) {
117         // Load the template
118         $out = loadTemplate($template, TRUE, $content);
119
120         // Add it to output
121         addToInstallContent($out);
122 }
123
124 // Add it to install content
125 function addToInstallContent ($out) {
126         // Set or add it...
127         if (!isset($GLOBALS['install_content'])) {
128                 // Set it
129                 $GLOBALS['install_content'] = $out;
130         } else {
131                 // Add it
132                 $GLOBALS['install_content'] .= $out;
133         } // END - if
134 }
135
136 // Somewhat getter for installer content
137 function getInstallerContent () {
138         // Is it here?
139         if (isset($GLOBALS['install_content'])) {
140                 // Yes, then use it
141                 $content = $GLOBALS['install_content'];
142         } else {
143                 // Nothing found, this needs fixing
144                 $content = displayMessage('{--INSTALLER_CONTENT_404--}', TRUE);
145         }
146
147         // Return content
148         return $content;
149 }
150
151 // Read a given SQL dump
152 function readSqlDump ($FQFN) {
153         // Load the file
154         $content = readFromFile($FQFN);
155
156         // Remove some unwanted chars
157         $content = str_replace(chr(13), '', $content);
158         $content = str_replace(PHP_EOL . PHP_EOL, PHP_EOL, $content);
159
160         // Return the content
161         return $content;
162 }
163
164 // Generates the installer menu by simply loading another template
165 function generateInstallerMenu () {
166         // Load installer menu template
167         $OUT = loadTemplate('install_menu', TRUE);
168
169         // Return loaded content
170         return $OUT;
171 }
172
173 // Generate the install footer navigation by simply loading another template
174 function generateInstallerFooterNavigation () {
175         // Load installer menu template
176         $OUT = loadTemplate('install_footer', TRUE);
177
178         // Return loaded content
179         return $OUT;
180 }
181
182 // Generate an option list for database types for given default value
183 function generateInstallerDatabaseTypeOptions () {
184         return generateOptions(
185                 '/ARRAY/',
186                 array('MyISAM', 'InnoDB'),
187                 array('{--INSTALLER_TABLE_TYPE_MYISAM--}', '{--INSTALLER_TABLE_TYPE_INNODB--}'),
188                 getSession('mysql_engine')
189         );
190 }
191
192 // Generate an option list for output mode types for given default value
193 function generateInstallerOutputModeOptions ($defaultValue) {
194         return generateOptions(
195                 '/ARRAY/',
196                 array('render', 'direct'),
197                 array('{--INSTALLER_MODE_RENDER--}', '{--INSTALLER_MODE_DIRECT--}'),
198                 $defaultValue
199         );
200 }
201
202 // Checks whether we have an AJAX-enabled installer which defaults to red pill
203 function isAjaxInstaller () {
204         // Get the session data and compare it against 'ajax'
205         $isAjaxInstaller = (getSession('installer') == 'ajax');
206
207         // Return it
208         return $isAjaxInstaller;
209 }
210
211 // Checks whether we have an plain installer which defaults to red pill
212 function isPlainInstaller () {
213         // Get the session data and compare it against 'plain'
214         $isPlainInstaller = (getSession('installer') == 'plain');
215
216         // Return it
217         return $isPlainInstaller;
218 }
219
220 // Handle all given failed fields
221 function handleInstallerFailedFields ($failedFields) {
222         // Don't do anything with no array or no entries
223         if ((!is_array($failedFields)) || (count($failedFields) == 0)) {
224                 // Abort here
225                 reportBug(__FUNCTION__, __LINE__, 'failedFields[]=' . gettype($failedFields) . ' verification failed');
226         } // END - if
227
228         // Handle all
229         $out = '<ol>';
230         foreach ($failedFields as $key => $field) {
231                 // "Translate" it
232                 $out .= '<li>{--INSTALLER_FIELD_FAILED_' . strtoupper($field) . '--}</li>';
233         } // END - foreach
234         $out .= '</ol>';
235
236         // Return it
237         return $out;
238 }
239
240 // Checks given key/value pair if it is valid by a call-back
241 function isInstallerDataValid (&$saveStatus, $key, $value) {
242         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ' - ENTERED!');
243         // Generate call-back function based on given key
244         $callbackName = 'isInstaller' . capitalizeUnderscoreString($key) . 'Valid';
245
246         // Is the function there?
247         if (!function_exists($callbackName)) {
248                 // Not found, which is not bad, but it means this data is always valid
249                 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', key=' . $key . ', value=' . $value);
250
251                 // All fine (CAREFULL!)
252                 return TRUE;
253         } // END - if
254
255         // Then call it back
256         $isValid = (bool) call_user_func($callbackName, trim($value));
257
258         // Is it not valid?
259         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid));
260         if ($isValid === FALSE) {
261                 // Then add it to saveStatus
262                 array_push($saveStatus['failed_fields'], $key);
263         } // END - if
264
265         // Return status
266         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT!');
267         return $isValid;
268 }
269
270 // Post-check on installer data
271 function doInstallerPostCheck ($currentTab, &$saveStatus) {
272         // Debug message
273         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - ENTERED!');
274
275         // Create the call-back function on 'tab'
276         $callbackName = 'isInstallerPost' . capitalizeUnderscoreString($currentTab) . 'Valid';
277
278         // Is the function there?
279         if (!function_exists($callbackName)) {
280                 // Not found, which is not bad, but it means the post-check won't be run
281                 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', currentTab=' . $currentTab);
282
283                 // Abort here
284                 return;
285         } // END - if
286
287         // Init 'tab-specific error message'
288         $GLOBALS['installer_post_error'][$currentTab]    = '';
289         $GLOBALS['installer_failed_fields'][$currentTab] = array();
290
291         // Debug message
292         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Calling function ' . $callbackName . ',currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status']);
293
294         // Then call it back
295         $isValid = (bool) call_user_func($callbackName, $currentTab);
296
297         // Is it not valid?
298         if (($isValid === FALSE) || (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0)) {
299                 // Then change status and message
300                 $saveStatus['status']  = 'failed';
301                 $saveStatus['message'] = '{%message,INSTALLER_POST_CHECK_' . strtoupper($currentTab) . '_FAILED=' . $GLOBALS['installer_post_error'][$currentTab] . '%}';
302
303                 // Is there failed fields?
304                 if (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0) {
305                         // Then merge both
306                         $saveStatus['failed_fields'] = merge_array($saveStatus['failed_fields'], $GLOBALS['installer_failed_fields'][$currentTab]);
307                 } // END - if
308         } // END - if
309
310         // Debug message
311         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - EXIT!');
312 }
313
314 // Determines an installer group by given key
315 function determineInstallerGroupByKey ($key) {
316         // Try to look it up
317         if (!isset($GLOBALS['installer_groups'][$key])) {
318                 // Log missing entry
319                 logDebugMessage(__FUNCTION__, __LINE__, 'Cannot determine installer group, returning dummy group. key=' . $key);
320
321                 // Return dummy group
322                 return 'dummy';
323         } // END - if
324
325         // Return it
326         return $GLOBALS['installer_groups'][$key];
327 }
328
329 // Adds given key/value pair to an overview group
330 function addKeyValueToInstallerOverviewGroup ($key, $value) {
331         // First determine the group by given key
332         $group = determineInstallerGroupByKey($key);
333
334         // Depending on the group, add it for later usage (to render the overview page)
335         $GLOBALS['installer_overview'][$group][$key] = $value;
336 }
337
338 //-----------------------------------------------------------------------------
339 //                   Call-back functions to check validity
340 //-----------------------------------------------------------------------------
341
342 // ----------------- Base data -----------------
343
344 // Call-back function to check validity of 'base_path'
345 function isInstallerBasePathValid ($value) {
346         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
347         // Is it a directory and if some typical files could be found
348         $isValid = (
349                 // Is it a directory?
350                 (isDirectory($value))
351         &&
352                 // Doesn't contain dots
353                 (strpos($value, '..') === FALSE)
354         &&
355                 // Is there a trailing slash?
356                 (substr($value, -1, 1) == '/')
357         &&
358                 // Is mysql-manager.php there?
359                 (isFileReadable($value . 'inc/mysql-manager.php'))
360         &&
361                 // What about gen_sql_patches.php?
362                 (isFileReadable($value . 'inc/gen_sql_patches.php'))
363         &&
364                 // And how about referral-functions.php?
365                 (isFileReadable($value . 'inc/referral-functions.php'))
366         );
367
368         // Return it
369         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
370         return $isValid;
371 }
372
373 // Call-back function to check validity of 'base_url'
374 function isInstallerBaseUrlValid ($value) {
375         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
376         // Is it same as URL
377         $isValid = (
378                 // Same as URL?
379                 ($value == getUrl())
380         || (
381                 // Starts with http:// or https:// ?
382                 ((substr($value, 0, 7) == 'http://') || (substr($value, 0, 8) == 'https://'))
383         &&
384                 // Has no trailing slash?
385                 (substr($value, -1, 1) != '/')
386         &&
387                 // And total length is at least 6+8=14 chars long? (https://foo.ba)
388                 (strlen($value) >= 14)
389         &&
390                 // Is the URL valid?
391                 (isUrlValid($value))
392         ));
393
394         // Return it
395         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
396         return $isValid;
397 }
398
399 // Call-back function to checl validity of 'main_title'
400 function isInstallerMainTitleValid ($value) {
401         // Is it valid?
402         // @TODO Comparing with DEFAULT_MAIN_TITLE doesn't work
403         $isValid = ((strlen($value) >= 4) && ($value != getMessage('DEFAULT_MAIN_TITLE')));
404
405         // Return it
406         return $isValid;
407 }
408
409 // Call-back function to checl validity of 'slogan'
410 function isInstallerSloganValid ($value) {
411         // Is it valid?
412         $isValid = ((strlen($value) >= 4) && ($value != getMessage('DEFAULT_SLOGAN')));
413
414         // Return it
415         return $isValid;
416 }
417
418 // Call-back function to check validity of 'webmaster'
419 function isInstallerWebmasterValid ($value) {
420         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
421         // Is it a valid email address?
422         $isValid = ((
423                 // Is it a valid email address?
424                 (isEmailValid($value))
425         ||
426                 // Or is there 'localhost/127.0.0.1' as hostname? Then don't check email address (e.g. you@localhost)
427                 (in_array(detectServerName(), array('localhost', '127.0.0.1')))
428         ) && (
429                 // Is not default "email address"
430                 $value != getMessage('DEFAULT_WEBMASTER')
431         ));
432
433         // Return it
434         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
435         return $isValid;
436 }
437
438 // ----------------- Database configuration -----------------
439
440 // Call-back function to check validity of 'mysql_host'
441 function isInstallerMysqlHostValid ($value) {
442         // This value must match a hostname or IP address
443         $isValid = (
444                 // Shall not be empty
445                 (!empty($value)) && (
446                 // Is localhost/127.0.0.1? (mostly the case)
447                 (in_array($value, array('localhost', '127.0.0.1')))
448         ||
449                 // IP number match (this regex was taken from www.regexlib.com)
450                 (preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]))/', $value))
451         ||
452                 // Host name match
453                 (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $value))
454         ));
455
456         // Return it
457         return $isValid;
458 }
459
460 // Call-back function to check validity of 'mysql_engine'
461 function isInstallerMysqlEngineValid ($value) {
462         // This value must be 'MyISAM' or 'InnoDB'
463         $isValid = in_array($value, array('MyISAM', 'InnoDB'));
464
465         // Return it
466         return $isValid;
467 }
468
469 // Call-back function to check validity of 'mysql_dbase'
470 function isInstallerMysqlDbaseValid ($value) {
471         // This value must not be empty
472         $isValid = ((!empty($value)) && ($value != 'your_database'));
473
474         // Return it
475         return $isValid;
476 }
477
478 // Call-back function to check validity of 'mysql_login'
479 function isInstallerMysqlLoginValid ($value) {
480         // This value must not be empty
481         $isValid = ((!empty($value)) && ($value != 'your_login'));
482
483         // Return it
484         return $isValid;
485 }
486
487 // Call-back function to check validity of 'mysql_prefix'
488 function isInstallerMysqlPrefixValid ($value) {
489         // This value must not be empty
490         $isValid = !empty($value);
491
492         // Return it
493         return $isValid;
494 }
495
496 // ----------------- SMTP configuration -----------------
497
498 // ----------------- Other configuration -----------------
499
500 //-----------------------------------------------------------------------------
501 //                 Call-back functions to post-check validity
502 //-----------------------------------------------------------------------------
503
504 // Call-back function to check if base data is valid
505 function isInstallerPostBaseDataValid ($currentTab) {
506         // By default it is not valid
507         $isValid = FALSE;
508
509         // Is the base path valid?
510         if (!isInstallerBasePathValid(postRequestElement('base_path'))) {
511                 // Then mark it
512                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_BASE_PATH_INVALID--}';
513                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'base_path');
514                 return FALSE;
515         } elseif (!isInstallerBaseUrlValid(postRequestElement('base_url'))) {
516                 // Then mark it
517                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_BASE_URL_INVALID--}';
518                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'base_url');
519                 return FALSE;
520         } elseif (strlen(postRequestElement('main_title')) < 3) {
521                 // To short
522                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_MAIN_TITLE_INVALID--}';
523                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'main_title');
524                 return FALSE;
525         } elseif (strlen(postRequestElement('slogan')) < 3) {
526                 // To short
527                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_SLOGAN_INVALID--}';
528                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'slogan');
529                 return FALSE;
530         } elseif (!isInstallerWebmasterValid(postRequestElement('webmaster'))) {
531                 // Then mark it
532                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_WEBMASTER_INVALID--}';
533                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'webmaster');
534                 return FALSE;
535         } else {
536                 // All fine
537                 $isValid = TRUE;
538
539                 // Remember this tab in session
540                 installTabOkay($currentTab);
541         }
542
543         // Return it
544         return $isValid;
545 }
546
547 // Call-back function to check if database configuration in POST is valid
548 function isInstallerPostDatabaseConfigValid ($currentTab) {
549         // By default nothing is valid
550         $isValid       = FALSE;
551         $engineValid   = FALSE;
552         $missingTables = 0;
553
554         // Do both passwords match?
555         if ((!isPostRequestElementSet('mysql_password1')) && (isPostRequestElementSet('mysql_password2'))) {
556                 // Password 1 not set
557                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD1_EMPTY--}';
558                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1');
559                 return FALSE;
560         } elseif ((isPostRequestElementSet('mysql_password1')) && (!isPostRequestElementSet('mysql_password2'))) {
561                 // Password 2 not set
562                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD2_EMPTY--}';
563                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password2');
564                 return FALSE;
565         } elseif (postRequestElement('mysql_password1') != postRequestElement('mysql_password2')) {
566                 // Passwords mismatch
567                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORDS_MISMATCH--}';
568                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1', 'mysql_password2');
569                 return FALSE;
570         } // END - if
571
572         // Try to connect to the database
573         $linkResource = SQL_CONNECT(postRequestElement('mysql_host'), postRequestElement('mysql_login'), postRequestElement('mysql_password1'), __FUNCTION__, __LINE__);
574
575         // Is the link up
576         if (!is_resource($linkResource)) {
577                 // Cannot connect to database
578                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_CONNECT_ERROR--}';
579                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_login', 'mysql_password1', 'mysql_password2');
580                 return FALSE;
581         } // END - if
582
583         // Then attempt to select the database
584         if (!SQL_SELECT_DB(postRequestElement('mysql_dbase'), __FUNCTION__, __LINE__)) {
585                 // Could not find database
586                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_SELECT_FAILED--}';
587                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
588
589                 // Disconnect here, we don't need idle database connections laying around
590                 SQL_CLOSE(__FUNCTION__, __LINE__);
591
592                 // Abort here
593                 return FALSE;
594         } // END - if
595
596         // Set database name and prefix
597         setConfigEntry('__DB_NAME'    , postRequestElement('mysql_dbase'));
598         setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql_prefix'));
599
600         // Get an array of all supported engines
601         $engines = getArrayFromSupportedSqlEngines(postRequestElement('mysql_engine'));
602
603         // Is this an array?
604         if (!is_array($engines)) {
605                 // Something bad happened
606                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINES_SQL_ERROR--}';
607                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
608
609                 // Disconnect here, we don't need idle database connections laying around
610                 SQL_CLOSE(__FUNCTION__, __LINE__);
611
612                 // Abort here
613                 return FALSE;
614         } elseif (count($engines) == 0) {
615                 // No engine is active
616                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_NO_ENGINES_ACTIVE--}';
617                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
618
619                 // Disconnect here, we don't need idle database connections laying around
620                 SQL_CLOSE(__FUNCTION__, __LINE__);
621
622                 // Abort here
623                 return FALSE;
624         }
625
626         // Then check all, if the requested is working
627         foreach ($engines as $engineArray) {
628                 // By default the selected engine is not valid
629                 $engineValid = FALSE;
630
631                 // Is the engine there?
632                 if (strtolower($engineArray['Engine']) == strtolower(postRequestElement('mysql_engine'))) {
633                         // Okay, engine is found
634                         $engineValid = TRUE;
635                         break;
636                 } // END - if
637         } // END - foreach
638
639         // So, is the engine found?
640         if ($engineValid === FALSE) {
641                 // Requested engine is not active
642                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINE_UNSUPPORTED--}';
643                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
644
645                 // Disconnect here, we don't need idle database connections laying around
646                 SQL_CLOSE(__FUNCTION__, __LINE__);
647
648                 // Abort here
649                 return FALSE;
650         } // END - if
651
652         // Init some known tables
653         $tables = array(
654                 // Admins
655                 'admins'      => TRUE,
656                 // Admin menu
657                 'admin_menu'  => TRUE,
658                 // Categories
659                 'cats'        => TRUE,
660                 // Configuration
661                 'config'      => TRUE,
662                 // Extensions
663                 'extensions'  => TRUE,
664                 // Guest menu
665                 'guest_menu'  => TRUE,
666                 // Max receive
667                 'max_receive' => TRUE,
668                 // Member menu
669                 'member_menu' => TRUE,
670                 // Module registry
671                 'mod_reg'     => TRUE,
672                 // Payments
673                 'payments'    => TRUE,
674                 // Sending pool
675                 'pool'        => TRUE,
676                 // Referral banner
677                 'refbanner'   => TRUE,
678                 // Referral levels
679                 'refdepths'   => TRUE,
680                 // Referral system
681                 'refsystem'   => TRUE,
682                 // Task system
683                 'task_system' => TRUE,
684         );
685
686         // So check if all tables are not there
687         foreach ($tables as $tableName => $isFound) {
688                 // Check it out
689                 $tables[$tableName] = ifSqlTableExists($tableName);
690
691                 // Is it (hopefully not) there?
692                 if ($tables[$tableName] === FALSE) {
693                         // This does not exist
694                         $missingTables++;
695                 } // END - if
696         } // END - foreach
697
698         // Determine final status (simply compare both counts
699         $isValid = (count($tables) == $missingTables);
700
701         // Disconnect here, we don't need idle database connections laying around
702         SQL_CLOSE(__FUNCTION__, __LINE__);
703
704         // If the status is true, disconnect the database
705         if ($isValid === FALSE) {
706                 // Still something bad happened (e.g. tables found)
707                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_IN_USE--}';
708                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
709         } else {
710                 // Remember this tab in session
711                 installTabOkay($currentTab);
712         }
713
714         // Return status
715         return $isValid;
716 }
717
718 // Store given tab in session
719 function installTabOkay ($currentTab) {
720         // Is it set?
721         if (isSessionVariableSet('installer_okay')) {
722                 // Is this tab already found?
723                 if (strpos(getSession('installer_okay'), $currentTab) === FALSE) {
724                         // Then extend it
725                         setSession('installer_okay', getSession('installer_okay') . ';' . $currentTab);
726                 } // END - if
727         } else {
728                 // Initially set it
729                 setSession('installer_okay', $currentTab);
730         }
731 }
732
733 // Checks whether at least the required tabs are completed
734 function isInstallationDataCompleted () {
735         // Check both
736         $isCompleted = (
737                 (isSessionVariableSet('installer_okay')) &&
738                 (strpos(getSession('installer_okay'), 'base_data') !== FALSE) &&
739                 (strpos(getSession('installer_okay'), 'database_config') !== FALSE)
740         );
741
742         // Return it
743         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCompleted=' . intval($isCompleted) . ',installer_okay=' . getSession('installer_okay'));
744         return $isCompleted;
745 }
746
747 // Call-back function to check if enable_backlink is Y/N
748 function isInstallerEnableBacklinkValid ($currentTab) {
749         // Check and return it
750         return in_array($currentTab, array('Y', 'N'));
751 }
752
753 // Call-back function to check if warn_no_pass is Y/N
754 function isInstallerWarnNoPassValid ($currentTab) {
755         // Check and return it
756         return in_array($currentTab, array('Y', 'N'));
757 }
758
759 // Call-back function to check if write_footer is Y/N
760 function isInstallerWriteFooterValid ($currentTab) {
761         // Check and return it
762         return in_array($currentTab, array('Y', 'N'));
763 }
764
765 // Call-back function to check if output_mode is Y/N
766 function isInstallerOutputModeValid ($currentTab) {
767         // Check and return it
768         return in_array($currentTab, array('render', 'direct'));
769 }
770
771 // Wrapper to import given installation SQL dump
772 function importInstallSqlDump ($dumpName) {
773         // Import the file
774         importSqlDump('install', $dumpName, 'install');
775 }
776
777 // [EOF]
778 ?>