Mailer project continued (heavy refactoring):
[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) {
76         // Copy the config template and verify it
77         copyFileVerified(postRequestElement('spath') . 'inc/config-local.php.dist', postRequestElement('spath') . getCachePath() . 'config-local.php', 0644);
78
79         // Ok, all done. So we can write the config data to the php files
80         // Do only write these if they differ from auto-detected values
81         if (postRequestElement('spath') != getPath()) changeDataInLocalConfigurationFile('SERVER-PATH', "setConfigEntry('PATH', '", "');", postRequestElement('spath'), 0);
82         if (postRequestElement('burl')  != getUrl())  changeDataInLocalConfigurationFile('HOST-URL', "setConfigEntry('URL', '", "');", postRequestElement('burl'), 0);
83
84         // Write more data
85         changeDataInLocalConfigurationFile('MAIN-TITLE', "setConfigEntry('MAIN_TITLE', '", "');", postRequestElement('title'), 0);
86         changeDataInLocalConfigurationFile('SLOGAN', "setConfigEntry('SLOGAN', '", "');", postRequestElement('slogan'), 0);
87         changeDataInLocalConfigurationFile('WEBMASTER', "setConfigEntry('WEBMASTER', '", "');", postRequestElement('email'), 0);
88         changeDataInLocalConfigurationFile('NULLPASS-WARNING', "setConfigEntry('WARN_NO_PASS', '", "');", postRequestElement('warn_no_pass'), 0);
89         changeDataInLocalConfigurationFile('WRITE-FOOTER', "setConfigEntry('WRITE_FOOTER', '", "');", postRequestElement('wfooter'), 0);
90         changeDataInLocalConfigurationFile('BACKLINK', "setConfigEntry('ENABLE_BACKLINK', '", "');", postRequestElement('blink'), 0);
91         // @TODO DEACTIVATED: changeDataInLocalConfigurationFile('OUTPUT-MODE', "setConfigEntry('OUTPUT_MODE', '", "');", postRequestElement('omode'), 0);
92         changeDataInLocalConfigurationFile('MYSQL-HOST', "      'host'     => '", "',", postRequestElement('mysql','host'), 0);
93         changeDataInLocalConfigurationFile('MYSQL-DBASE', "     'dbase'    => '", "',", postRequestElement('mysql','dbase'), 0);
94         changeDataInLocalConfigurationFile('MYSQL-LOGIN', "     'login'    => '", "',", postRequestElement('mysql','login'), 0);
95         changeDataInLocalConfigurationFile('MYSQL-PASSWORD', "  'password' => '", "',", postRequestElement('mysql','pass1'), 0);
96         changeDataInLocalConfigurationFile('MYSQL-PREFIX', "setConfigEntry('_MYSQL_PREFIX', '", "');", postRequestElement('mysql','prefix'), 0);
97         changeDataInLocalConfigurationFile('TABLE-TYPE', "setConfigEntry('_TABLE_TYPE', '", "');", postRequestElement('mysql','type'), 0);
98         changeDataInLocalConfigurationFile('SMTP-HOSTNAME', "setConfigEntry('SMTP_HOSTNAME', '", "');", postRequestElement('smtp_host'), 0);
99         changeDataInLocalConfigurationFile('SMTP-USER', "setConfigEntry('SMTP_USER', '", "');", postRequestElement('smtp_user'), 0);
100         changeDataInLocalConfigurationFile('SMTP-PASSWORD', "setConfigEntry('SMTP_PASSWORD', '", "');", postRequestElement('smtp_pass1'), 0);
101
102         // Generate a long site-key and write it
103         changeDataInLocalConfigurationFile('SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", generatePassword(50), 0);
104
105         // Script is now installed
106         changeDataInLocalConfigurationFile('INSTALLED', "setConfigEntry('MXCHANGE_INSTALLED', '", "');", 'Y', 0);
107 }
108
109 // Adds a given template with content to install output stream
110 function addTemplateToInstallContent ($template, $content = array()) {
111         // Load the template
112         $out = loadTemplate($template, TRUE, $content);
113
114         // Add it to output
115         addToInstallContent($out);
116 }
117
118 // Add it to install content
119 function addToInstallContent ($out) {
120         // Set or add it...
121         if (!isset($GLOBALS['install_content'])) {
122                 // Set it
123                 $GLOBALS['install_content'] = $out;
124         } else {
125                 // Add it
126                 $GLOBALS['install_content'] .= $out;
127         } // END - if
128 }
129
130 // Somewhat getter for installer content
131 function getInstallerContent () {
132         // Is it here?
133         if (isset($GLOBALS['install_content'])) {
134                 // Yes, then use it
135                 $content = $GLOBALS['install_content'];
136         } else {
137                 // Nothing found, this needs fixing
138                 $content = displayMessage('{--INSTALLER_CONTENT_404--}', TRUE);
139         }
140
141         // Return content
142         return $content;
143 }
144
145 // Read a given SQL dump
146 function readSqlDump ($FQFN) {
147         // Load the file
148         $content = readFromFile($FQFN);
149
150         // Remove some unwanted chars
151         $content = str_replace(chr(13), '', $content);
152         $content = str_replace(PHP_EOL . PHP_EOL, PHP_EOL, $content);
153
154         // Return the content
155         return $content;
156 }
157
158 // Generates the installer menu by simply loading another template
159 function generateInstallerMenu () {
160         // Load installer menu template
161         $OUT = loadTemplate('install_menu', TRUE);
162
163         // Return loaded content
164         return $OUT;
165 }
166
167 // Generate the install footer navigation by simply loading another template
168 function generateInstallerFooterNavigation () {
169         // Load installer menu template
170         $OUT = loadTemplate('install_footer', TRUE);
171
172         // Return loaded content
173         return $OUT;
174 }
175
176 // Generate an option list for database types for given default value
177 function generateInstallerDatabaseTypeOptions () {
178         return generateOptions(
179                 '/ARRAY/',
180                 array('MyISAM', 'InnoDB'),
181                 array('{--INSTALLER_TABLE_TYPE_MYISAM--}', '{--INSTALLER_TABLE_TYPE_INNODB--}'),
182                 getSession('mysql_engine')
183         );
184 }
185
186 // Generate an option list for output mode types for given default value
187 function generateInstallerOutputModeOptions ($defaultValue) {
188         return generateOptions(
189                 '/ARRAY/',
190                 array('render', 'direct'),
191                 array('{--INSTALLER_MODE_RENDER--}', '{--INSTALLER_MODE_DIRECT--}'),
192                 $defaultValue
193         );
194 }
195
196 // Checks whether we have an AJAX-enabled installer which defaults to red pill
197 function isAjaxInstaller () {
198         // Get the session data and compare it against 'ajax'
199         $isAjaxInstaller = (getSession('installer') == 'ajax');
200
201         // Return it
202         return $isAjaxInstaller;
203 }
204
205 // Checks whether we have an plain installer which defaults to red pill
206 function isPlainInstaller () {
207         // Get the session data and compare it against 'plain'
208         $isPlainInstaller = (getSession('installer') == 'plain');
209
210         // Return it
211         return $isPlainInstaller;
212 }
213
214 // Checks given key/value pair if it is valid by a call-back
215 function isInstallerDataValid (&$saveStatus, $key, $value) {
216         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ' - ENTERED!');
217         // Generate call-back function based on given key
218         $callbackName = 'isInstaller' . capitalizeUnderscoreString($key) . 'Valid';
219
220         // Is the function there?
221         if (!function_exists($callbackName)) {
222                 // Not found, which is not bad, but it means this data is always valid
223                 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', key=' . $key . ', value=' . $value);
224
225                 // All fine (CAREFULL!)
226                 return TRUE;
227         } // END - if
228
229         // Then call it back
230         $isValid = (bool) call_user_func($callbackName, $value);
231
232         // Is it not valid?
233         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid));
234         if ($isValid === FALSE) {
235                 // Then add it to saveStatus
236                 array_push($saveStatus['failed_fields'], $key);
237         } // END - if
238
239         // Return status
240         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT!');
241         return $isValid;
242 }
243
244 // Post-check on installer data
245 function doInstallerPostCheck ($currentTab, &$saveStatus) {
246         // Debug message
247         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - ENTERED!');
248
249         // Create the call-back function on 'tab'
250         $callbackName = 'isInstallerPost' . capitalizeUnderscoreString($currentTab) . 'Valid';
251
252         // Is the function there?
253         if (!function_exists($callbackName)) {
254                 // Not found, which is not bad, but it means the post-check won't be run
255                 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', currentTab=' . $currentTab);
256
257                 // Abort here
258                 return;
259         } // END - if
260
261         // Init 'tab-specific error message'
262         $GLOBALS['installer_post_error'][$currentTab]    = '';
263         $GLOBALS['installer_failed_fields'][$currentTab] = array();
264
265         // Debug message
266         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Calling function ' . $callbackName . ',currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status']);
267
268         // Then call it back
269         $isValid = (bool) call_user_func($callbackName, $currentTab);
270
271         // Is it not valid?
272         if (($isValid === FALSE) || (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0)) {
273                 // Then change status and message
274                 $saveStatus['status']  = 'failed';
275                 $saveStatus['message'] = '{%message,INSTALLER_POST_CHECK_' . strtoupper($currentTab) . '_FAILED=' . $GLOBALS['installer_post_error'][$currentTab] . '%}';
276
277                 // Is there failed fields?
278                 if (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0) {
279                         // Then merge both
280                         $saveStatus['failed_fields'] = merge_array($saveStatus['failed_fields'], $GLOBALS['installer_failed_fields'][$currentTab]);
281                 } // END - if
282         } // END - if
283
284         // Debug message
285         //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - EXIT!');
286 }
287
288 // Determines an installer group by given key
289 function determineInstallerGroupByKey ($key) {
290         // Try to look it up
291         if (!isset($GLOBALS['installer_groups'][$key])) {
292                 // Log missing entry
293                 logDebugMessage(__FUNCTION__, __LINE__, 'Cannot determine installer group, returning dummy group. key=' . $key);
294
295                 // Return dummy group
296                 return 'dummy';
297         } // END - if
298
299         // Return it
300         return $GLOBALS['installer_groups'][$key];
301 }
302
303 // Adds given key/value pair to an overview group
304 function addKeyValueToInstallerOverviewGroup ($key, $value) {
305         // First determine the group by given key
306         $group = determineInstallerGroupByKey($key);
307
308         // Depending on the group, add it for later usage (to render the overview page)
309         $GLOBALS['installer_overview'][$group][$key] = $value;
310 }
311
312 //-----------------------------------------------------------------------------
313 //                   Call-back functions to check validity
314 //-----------------------------------------------------------------------------
315
316 // ----------------- Base data -----------------
317
318 // Call-back function to check validity of 'base_path'
319 function isInstallerBasePathValid ($value) {
320         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
321         // Is it a directory and if some typical files could be found
322         $isValid = (
323                 // Is it a directory?
324                 (isDirectory($value))
325         &&
326                 // Is there a trailing slash?
327                 (substr($value, -1, 1) == '/')
328         &&
329                 // Is mysql-manager.php there?
330                 (isFileReadable($value . 'inc/mysql-manager.php'))
331         &&
332                 // What about gen_sql_patches.php?
333                 (isFileReadable($value . 'inc/gen_sql_patches.php'))
334         );
335
336         // Return it
337         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
338         return $isValid;
339 }
340
341 // Call-back function to check validity of 'base_url'
342 function isInstallerBaseUrlValid ($value) {
343         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
344         // Is it same as URL
345         $isValid = (
346                 // Same as URL?
347                 ($value == getUrl())
348         || (
349                 // Starts with http:// or https:// ?
350                 ((substr($value, 0, 7) == 'http://') || (substr($value, 0, 8) == 'https://'))
351         &&
352                 // Has no trailing slash?
353                 (substr($value, -1, 1) != '/')
354         &&
355                 // And total length is at least 6+8=14 chars long? (https://foo.ba)
356                 (strlen($value) >= 14)
357         &&
358                 // Is the URL valid?
359                 (isUrlValid($value))
360         ));
361
362         // Return it
363         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
364         return $isValid;
365 }
366
367 // Call-back function to check validity of 'webmaster'
368 function isInstallerWebmasterValid ($value) {
369         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
370         // Is it a valid email address?
371         $isValid = (
372                 // Is it a valid email address?
373                 (isEmailValid($value))
374         ||
375                 // Or is there 'localhost/127.0.0.1' as hostname? Then don't check email address (e.g. you@localhost)
376                 (in_array(detectServerName(), array('localhost', '127.0.0.1')))
377         );
378
379         // Return it
380         //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
381         return $isValid;
382 }
383
384 // ----------------- Database configuration -----------------
385
386 // Call-back function to check validity of 'mysql_host'
387 function isInstallerMysqlHostValid ($value) {
388         // This value must match a hostname or IP address
389         $isValid = (
390                 // Is localhost/127.0.0.1? (mostly the case)
391                 (in_array($value, array('localhost', '127.0.0.1')))
392         ||
393                 // IP number match (this regex was taken from www.regexlib.com)
394                 (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))
395         ||
396                 // Host name match
397                 (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $value))
398         );
399
400         // Return it
401         return $isValid;
402 }
403
404 // Call-back function to check validity of 'mysql_engine'
405 function isInstallerMysqlTypeValid ($value) {
406         // This value must be 'MyISAM' or 'InnoDB'
407         $isValid = in_array($value, array('MyISAM', 'InnoDB'));
408
409         // Return it
410         return $isValid;
411 }
412
413 // ----------------- SMTP configuration -----------------
414
415 // ----------------- Other configuration -----------------
416
417 //-----------------------------------------------------------------------------
418 //                 Call-back functions to post-check validity
419 //-----------------------------------------------------------------------------
420
421 // Call-back function to check if database configuration in POST is valid
422 function isInstallerPostDatabaseConfigValid ($currentTab) {
423         // By default nothing is valid
424         $isValid       = FALSE;
425         $engineValid   = FALSE;
426         $missingTables = 0;
427
428         // Do both passwords match?
429         if ((!isPostRequestElementSet('mysql_password1')) && (isPostRequestElementSet('mysql_password2'))) {
430                 // Password 1 not set
431                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD1_EMPTY--}';
432                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1');
433                 return FALSE;
434         } elseif ((isPostRequestElementSet('mysql_password1')) && (!isPostRequestElementSet('mysql_password2'))) {
435                 // Password 2 not set
436                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD2_EMPTY--}';
437                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password2');
438                 return FALSE;
439         } elseif (postRequestElement('mysql_password1') != postRequestElement('mysql_password2')) {
440                 // Passwords mismatch
441                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORDS_MISMATCH--}';
442                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1', 'mysql_password2');
443                 return FALSE;
444         } // END - if
445
446         // Try to connect to the database
447         $linkResource = SQL_CONNECT(postRequestElement('mysql_host'), postRequestElement('mysql_login'), postRequestElement('mysql_password1'), __FUNCTION__, __LINE__);
448
449         // Is the link up
450         if (!is_resource($linkResource)) {
451                 // Cannot connect to database
452                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_CONNECT_ERROR--}';
453                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_login', 'mysql_password1', 'mysql_password2');
454                 return FALSE;
455         } // END - if
456
457         // Then attempt to select the database
458         if (!SQL_SELECT_DB(postRequestElement('mysql_dbase'), __FUNCTION__, __LINE__)) {
459                 // Could not find database
460                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_SELECT_FAILED--}';
461                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
462
463                 // Disconnect here, we don't need idle database connections laying around
464                 SQL_CLOSE(__FUNCTION__, __LINE__);
465
466                 // Abort here
467                 return FALSE;
468         } // END - if
469
470         // Set database name and prefix
471         setConfigEntry('__DB_NAME'    , postRequestElement('mysql_dbase'));
472         setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql_prefix'));
473
474         // Get an array of all supported engines
475         $engines = getArrayFromSupportedSqlEngines(postRequestElement('mysql_engine'));
476
477         // Is this an array?
478         if (!is_array($engines)) {
479                 // Something bad happened
480                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINES_SQL_ERROR--}';
481                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
482
483                 // Disconnect here, we don't need idle database connections laying around
484                 SQL_CLOSE(__FUNCTION__, __LINE__);
485
486                 // Abort here
487                 return FALSE;
488         } elseif (count($engines) == 0) {
489                 // No engine is active
490                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_NO_ENGINES_ACTIVE--}';
491                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
492
493                 // Disconnect here, we don't need idle database connections laying around
494                 SQL_CLOSE(__FUNCTION__, __LINE__);
495
496                 // Abort here
497                 return FALSE;
498         }
499
500         // Then check all, if the requested is working
501         foreach ($engines as $engineArray) {
502                 // By default the selected engine is not valid
503                 $engineValid = FALSE;
504
505                 // Is the engine there?
506                 if (strtolower($engineArray['Engine']) == strtolower(postRequestElement('mysql_engine'))) {
507                         // Okay, engine is found
508                         $engineValid = TRUE;
509                         break;
510                 } // END - if
511         } // END - foreach
512
513         // So, is the engine found?
514         if ($engineValid === FALSE) {
515                 // Requested engine is not active
516                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINE_UNSUPPORTED--}';
517                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
518
519                 // Disconnect here, we don't need idle database connections laying around
520                 SQL_CLOSE(__FUNCTION__, __LINE__);
521
522                 // Abort here
523                 return FALSE;
524         } // END - if
525
526         // Init some known tables
527         $tables = array(
528                 // Admins
529                 'admins'      => TRUE,
530                 // Admin menu
531                 'admin_menu'  => TRUE,
532                 // Categories
533                 'cats'        => TRUE,
534                 // Configuration
535                 'config'      => TRUE,
536                 // Extensions
537                 'extensions'  => TRUE,
538                 // Guest menu
539                 'guest_menu'  => TRUE,
540                 // Max receive
541                 'max_receive' => TRUE,
542                 // Member menu
543                 'member_menu' => TRUE,
544                 // Module registry
545                 'mod_reg'     => TRUE,
546                 // Payments
547                 'payments'    => TRUE,
548                 // Sending pool
549                 'pool'        => TRUE,
550                 // Referral banner
551                 'refbanner'   => TRUE,
552                 // Referral levels
553                 'refdepths'   => TRUE,
554                 // Referral system
555                 'refsystem'   => TRUE,
556                 // Task system
557                 'task_system' => TRUE,
558         );
559
560         // So check if all tables are not there
561         foreach ($tables as $tableName => $isFound) {
562                 // Check it out
563                 $tables[$tableName] = ifSqlTableExists($tableName);
564
565                 // Is it (hopefully not) there?
566                 if ($tables[$tableName] === FALSE) {
567                         // This does not exist
568                         $missingTables++;
569                 } // END - if
570         } // END - foreach
571
572         // Determine final status (simply compare both counts
573         $isValid = (count($tables) == $missingTables);
574
575         // Disconnect here, we don't need idle database connections laying around
576         SQL_CLOSE(__FUNCTION__, __LINE__);
577
578         // If the status is true, disconnect the database
579         if ($isValid === FALSE) {
580                 // Still something bad happened (e.g. tables found)
581                 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_IN_USE--}';
582                 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
583         } // END - if
584
585         // Return status
586         return $isValid;
587 }
588
589 // Call-back function to check if enable_backlink is Y/N
590 function isInstallerEnableBacklinkValid ($currentTab) {
591         // Check and return it
592         return in_array($currentTab, array('Y', 'N'));
593 }
594
595 // Call-back function to check if warn_no_pass is Y/N
596 function isInstallerWarnNoPassValid ($currentTab) {
597         // Check and return it
598         return in_array($currentTab, array('Y', 'N'));
599 }
600
601 // Call-back function to check if write_footer is Y/N
602 function isInstallerWriteFooterValid ($currentTab) {
603         // Check and return it
604         return in_array($currentTab, array('Y', 'N'));
605 }
606
607 // Call-back function to check if output_mode is Y/N
608 function isInstallerOutputModeValid ($currentTab) {
609         // Check and return it
610         return in_array($currentTab, array('render', 'direct'));
611 }
612
613 // [EOF]
614 ?>