2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/22/2009 *
4 * =================== Last change: 10/22/2009 *
6 * -------------------------------------------------------------------- *
7 * File : install-functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for installation procedure *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer die Installationsroutine *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isInstallationPhase())) {
44 function initInstaller () {
45 // Initialize installer group array
46 $GLOBALS['installer_groups'] = array(
48 'base_path' => 'base_data',
49 'base_url' => 'base_data',
50 'main_title' => 'base_data',
51 'slogan' => 'base_data',
52 'webmaster' => 'base_data',
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',
62 'smtp_host' => 'smtp_config',
63 'smtp_user' => 'smtp_config',
64 'smtp_password1' => 'smtp_config',
65 'smtp_password2' => 'smtp_config',
67 'output_mode' => 'other_config',
68 'warn_no_pass' => 'other_config',
69 'write_footer' => 'other_config',
70 'enable_backlink' => 'other_config',
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);
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.
83 if ($path != getPath()) {
84 changeDataInLocalConfigurationFile('SERVER-PATH', "setConfigEntry('PATH', '", "');", $path, 0);
86 if ($url != getUrl()) {
87 changeDataInLocalConfigurationFile('HOST-URL', "setConfigEntry('URL', '", "');", $url, 0);
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);
108 // Generate a long site-key and write it
109 changeDataInLocalConfigurationFile('SITE-KEY', "setConfigEntry('SITE_KEY', '", "');", generatePassword(50), 0);
111 // Script is now installed
112 return changeDataInLocalConfigurationFile('INSTALLED', "setConfigEntry('MAILER_INSTALLED', '", "');", 'Y', 0);
115 // Adds a given template with content to install output stream
116 function addTemplateToInstallContent ($template, $content = array()) {
118 $out = loadTemplate($template, TRUE, $content);
121 addToInstallContent($out);
124 // Add it to install content
125 function addToInstallContent ($out) {
127 if (!isset($GLOBALS['install_content'])) {
129 $GLOBALS['install_content'] = $out;
132 $GLOBALS['install_content'] .= $out;
136 // Somewhat getter for installer content
137 function getInstallerContent () {
139 if (isset($GLOBALS['install_content'])) {
141 $content = $GLOBALS['install_content'];
143 // Nothing found, this needs fixing
144 $content = displayMessage('{--INSTALLER_CONTENT_404--}', TRUE);
151 // Read a given SQL dump
152 function readSqlDump ($FQFN) {
154 $content = readFromFile($FQFN);
156 // Remove some unwanted chars
157 $content = str_replace(chr(13), '', $content);
158 $content = str_replace(PHP_EOL . PHP_EOL, PHP_EOL, $content);
160 // Return the content
164 // Generates the installer menu by simply loading another template
165 function generateInstallerMenu () {
166 // Load installer menu template
167 $OUT = loadTemplate('install_menu', TRUE);
169 // Return loaded content
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);
178 // Return loaded content
182 // Generate an option list for database types for given default value
183 function generateInstallerDatabaseTypeOptions () {
184 return generateOptions(
186 array('MyISAM', 'InnoDB'),
187 array('{--INSTALLER_TABLE_TYPE_MYISAM--}', '{--INSTALLER_TABLE_TYPE_INNODB--}'),
188 getSession('mysql_engine')
192 // Generate an option list for output mode types for given default value
193 function generateInstallerOutputModeOptions ($defaultValue) {
194 return generateOptions(
196 array('render', 'direct'),
197 array('{--INSTALLER_MODE_RENDER--}', '{--INSTALLER_MODE_DIRECT--}'),
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');
208 return $isAjaxInstaller;
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');
217 return $isPlainInstaller;
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)) {
225 reportBug(__FUNCTION__, __LINE__, 'failedFields[]=' . gettype($failedFields) . ' verification failed');
230 foreach ($failedFields as $key => $field) {
232 $out .= '<li>{--INSTALLER_FIELD_FAILED_' . strtoupper($field) . '--}</li>';
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';
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);
251 // All fine (CAREFULL!)
256 $isValid = (bool) call_user_func($callbackName, $value);
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);
266 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT!');
270 // Post-check on installer data
271 function doInstallerPostCheck ($currentTab, &$saveStatus) {
273 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - ENTERED!');
275 // Create the call-back function on 'tab'
276 $callbackName = 'isInstallerPost' . capitalizeUnderscoreString($currentTab) . 'Valid';
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);
287 // Init 'tab-specific error message'
288 $GLOBALS['installer_post_error'][$currentTab] = '';
289 $GLOBALS['installer_failed_fields'][$currentTab] = array();
292 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Calling function ' . $callbackName . ',currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status']);
295 $isValid = (bool) call_user_func($callbackName, $currentTab);
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] . '%}';
303 // Is there failed fields?
304 if (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0) {
306 $saveStatus['failed_fields'] = merge_array($saveStatus['failed_fields'], $GLOBALS['installer_failed_fields'][$currentTab]);
311 //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentTab=' . $currentTab . ',saveStatus[status]=' . $saveStatus['status'] . ' - EXIT!');
314 // Determines an installer group by given key
315 function determineInstallerGroupByKey ($key) {
317 if (!isset($GLOBALS['installer_groups'][$key])) {
319 logDebugMessage(__FUNCTION__, __LINE__, 'Cannot determine installer group, returning dummy group. key=' . $key);
321 // Return dummy group
326 return $GLOBALS['installer_groups'][$key];
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);
334 // Depending on the group, add it for later usage (to render the overview page)
335 $GLOBALS['installer_overview'][$group][$key] = $value;
338 //-----------------------------------------------------------------------------
339 // Template call-back functions
340 //-----------------------------------------------------------------------------
342 // ----------------- Extensions -----------------
344 // Generates (and returns) a table from all extensions
345 function generateInstallerExtensionTable () {
346 // Generate extension list
347 $extensions = loadAllExtensionsByTemplate();
349 // "Walk" through all
351 foreach ($extensions as $extension) {
352 // Remove prefix + suffix
353 $ext_name = substr(basename($extension), 4, -4);
355 // Is the extension not in development and not admintheme* ?
356 if ((loadExtension($ext_name, 'test', '0.0.0', TRUE)) && (isExtensionProductive($ext_name)) && (substr($ext_name, 0, 10) != 'admintheme')) {
357 // Default is not disabled
359 if ($ext_name == 'sql_patches') {
360 // Always keep this enabled
361 $disabled = ' disabled="disabled"';
364 // Initialize content array
366 'ext_name' => $ext_name,
367 'ext_version' => getExtensionVersion($ext_name),
368 'checked' => getExtensionSelectedFromSession($ext_name, 'extensions'),
369 'disabled' => $disabled,
370 'description' => loadTemplate('ext_' . $ext_name, TRUE),
374 $OUT .= loadTemplate('install_list_extensions_row', TRUE, $content);
378 // Load main template
379 return loadTemplate('install_list_extensions', TRUE, $OUT);
382 //-----------------------------------------------------------------------------
383 // Call-back functions to check validity
384 //-----------------------------------------------------------------------------
386 // ----------------- Base data -----------------
388 // Call-back function to check validity of 'base_path'
389 function isInstallerBasePathValid ($value) {
390 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
391 // Is it a directory and if some typical files could be found
393 // Is it a directory?
394 (isDirectory($value))
396 // Doesn't contain dots
397 (strpos($value, '..') === FALSE)
399 // Is there a trailing slash?
400 (substr($value, -1, 1) == '/')
402 // Is mysql-manager.php there?
403 (isFileReadable($value . 'inc/mysql-manager.php'))
405 // What about gen_sql_patches.php?
406 (isFileReadable($value . 'inc/gen_sql_patches.php'))
408 // And how about referral-functions.php?
409 (isFileReadable($value . 'inc/referral-functions.php'))
413 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
417 // Call-back function to check validity of 'base_url'
418 function isInstallerBaseUrlValid ($value) {
419 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
425 // Starts with http:// or https:// ?
426 ((substr($value, 0, 7) == 'http://') || (substr($value, 0, 8) == 'https://'))
428 // Has no trailing slash?
429 (substr($value, -1, 1) != '/')
431 // And total length is at least 6+8=14 chars long? (https://foo.ba)
432 (strlen($value) >= 14)
439 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
443 // Call-back function to checl validity of 'main_title'
444 function isInstallerMainTitleValid ($value) {
446 // @TODO Comparing with DEFAULT_MAIN_TITLE doesn't work
447 $isValid = ((strlen($value) >= 4) && ($value != getMessage('DEFAULT_MAIN_TITLE')));
453 // Call-back function to checl validity of 'slogan'
454 function isInstallerSloganValid ($value) {
456 $isValid = ((strlen($value) >= 4) && ($value != getMessage('DEFAULT_SLOGAN')));
462 // Call-back function to check validity of 'webmaster'
463 function isInstallerWebmasterValid ($value) {
464 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' - ENTERED!');
465 // Is it a valid email address?
467 // Is it a valid email address?
468 (isEmailValid($value))
470 // Or is there 'localhost/127.0.0.1' as hostname? Then don't check email address (e.g. you@localhost)
471 (in_array(detectServerName(), array('localhost', '127.0.0.1')))
473 // Is not default "email address"
474 $value != getMessage('DEFAULT_WEBMASTER')
478 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',isValid=' . intval($isValid) . ' - EXIT');
482 // ----------------- Database configuration -----------------
484 // Call-back function to check validity of 'mysql_host'
485 function isInstallerMysqlHostValid ($value) {
486 // This value must match a hostname or IP address
488 // Shall not be empty
489 (!empty($value)) && (
490 // Is localhost/127.0.0.1? (mostly the case)
491 (in_array($value, array('localhost', '127.0.0.1')))
493 // IP number match (this regex was taken from www.regexlib.com)
494 (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))
497 (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/', $value))
504 // Call-back function to check validity of 'mysql_engine'
505 function isInstallerMysqlEngineValid ($value) {
506 // This value must be 'MyISAM' or 'InnoDB'
507 $isValid = in_array($value, array('MyISAM', 'InnoDB'));
513 // Call-back function to check validity of 'mysql_dbase'
514 function isInstallerMysqlDbaseValid ($value) {
515 // This value must not be empty
516 $isValid = ((!empty($value)) && ($value != 'your_database'));
522 // Call-back function to check validity of 'mysql_login'
523 function isInstallerMysqlLoginValid ($value) {
524 // This value must not be empty
525 $isValid = ((!empty($value)) && ($value != 'your_login'));
531 // Call-back function to check validity of 'mysql_prefix'
532 function isInstallerMysqlPrefixValid ($value) {
533 // This value must not be empty
534 $isValid = !empty($value);
540 // ----------------- SMTP configuration -----------------
542 // ----------------- Other configuration -----------------
544 // ----------------- Extensions -----------------
546 // Call-back function to check 'sel' (array!)
547 function isInstallerSelValid ($value) {
548 // $value is not an array, is really bad.
549 if (!is_array($value)) {
551 reportBug(__FUNCTION__, __LINE__, 'sel,value[]=' . gettype($value) . '!=array');
554 // Add always missing ext-sql_patches
555 $value['sql_patches'] = '1';
560 // "Walk" through all extensions
561 foreach ($value as $ext_name => $sel) {
562 // Is this extension choosen?
569 $isValid = (($isValid) && (loadExtension($ext_name, 'test', '0.0.0', TRUE)));
572 // Remove 'sel' from POST data as it cannot be saved
573 unsetPostRequestElement('sel');
575 // Save it in session (sorry to do that here :( )
576 setSession('extensions', implode(':', array_keys($value)));
582 //-----------------------------------------------------------------------------
583 // Call-back functions to post-check validity
584 //-----------------------------------------------------------------------------
586 // Call-back function to check if base data is valid
587 function isInstallerPostBaseDataValid ($currentTab) {
588 // By default it is not valid
591 // Is the base path valid?
592 if (!isInstallerBasePathValid(postRequestElement('base_path'))) {
594 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_BASE_PATH_INVALID--}';
595 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'base_path');
597 } elseif (!isInstallerBaseUrlValid(postRequestElement('base_url'))) {
599 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_BASE_URL_INVALID--}';
600 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'base_url');
602 } elseif (strlen(postRequestElement('main_title')) < 3) {
604 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_MAIN_TITLE_INVALID--}';
605 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'main_title');
607 } elseif (strlen(postRequestElement('slogan')) < 3) {
609 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_SLOGAN_INVALID--}';
610 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'slogan');
612 } elseif (!isInstallerWebmasterValid(postRequestElement('webmaster'))) {
614 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_WEBMASTER_INVALID--}';
615 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'webmaster');
621 // Remember this tab in session
622 installTabOkay($currentTab);
629 // Call-back function to check if database configuration in POST is valid
630 function isInstallerPostDatabaseConfigValid ($currentTab) {
631 // By default nothing is valid
633 $engineValid = FALSE;
636 // Do both passwords match?
637 if ((!isPostRequestElementSet('mysql_password1')) && (isPostRequestElementSet('mysql_password2'))) {
638 // Password 1 not set
639 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD1_EMPTY--}';
640 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1');
642 } elseif ((isPostRequestElementSet('mysql_password1')) && (!isPostRequestElementSet('mysql_password2'))) {
643 // Password 2 not set
644 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORD2_EMPTY--}';
645 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password2');
647 } elseif (postRequestElement('mysql_password1') != postRequestElement('mysql_password2')) {
648 // Passwords mismatch
649 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_PASSWORDS_MISMATCH--}';
650 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_password1', 'mysql_password2');
654 // Remove any previous flag
655 unsetSqlLinkUp(__FUNCTION__, __LINE__);
657 // Try to connect to the database
658 sqlConnectToDatabase(postRequestElement('mysql_host'), postRequestElement('mysql_login'), postRequestElement('mysql_password1'), __FUNCTION__, __LINE__);
661 if (!isSqlLinkUp()) {
662 // Cannot connect to database
663 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_CONNECT_ERROR--}';
664 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_login', 'mysql_password1', 'mysql_password2');
668 // Then attempt to select the database
669 if (!sqlSelectDatabase(postRequestElement('mysql_dbase'), __FUNCTION__, __LINE__)) {
670 // Could not find database
671 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_SELECT_FAILED--}';
672 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
674 // Disconnect here, we don't need idle database connections laying around
675 sqlCloseLink(__FUNCTION__, __LINE__);
681 // Set database name and prefix
682 setConfigEntry('__DB_NAME' , postRequestElement('mysql_dbase'));
683 setConfigEntry('_MYSQL_PREFIX', postRequestElement('mysql_prefix'));
685 // Get an array of all supported engines
686 $engines = getArrayFromSupportedSqlEngines(postRequestElement('mysql_engine'));
689 if (!is_array($engines)) {
690 // Something bad happened
691 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINES_SQL_ERROR--}';
692 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
694 // Disconnect here, we don't need idle database connections laying around
695 sqlCloseLink(__FUNCTION__, __LINE__);
699 } elseif (count($engines) == 0) {
700 // No engine is active
701 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_NO_ENGINES_ACTIVE--}';
702 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
704 // Disconnect here, we don't need idle database connections laying around
705 sqlCloseLink(__FUNCTION__, __LINE__);
711 // Then check all, if the requested is working
712 foreach ($engines as $engineArray) {
713 // By default the selected engine is not valid
714 $engineValid = FALSE;
716 // Is the engine there?
717 if (strtolower($engineArray['Engine']) == strtolower(postRequestElement('mysql_engine'))) {
718 // Okay, engine is found
724 // So, is the engine found?
725 if ($engineValid === FALSE) {
726 // Requested engine is not active
727 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_ENGINE_UNSUPPORTED--}';
728 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
730 // Disconnect here, we don't need idle database connections laying around
731 sqlCloseLink(__FUNCTION__, __LINE__);
737 // Init some known tables
742 'admin_menu' => TRUE,
748 'extensions' => TRUE,
750 'guest_menu' => TRUE,
752 'max_receive' => TRUE,
754 'member_menu' => TRUE,
768 'task_system' => TRUE,
771 // So check if all tables are not there
772 foreach ($tables as $tableName => $isFound) {
774 $tables[$tableName] = ifSqlTableExists($tableName);
776 // Is it (hopefully not) there?
777 if ($tables[$tableName] === FALSE) {
778 // This does not exist
783 // Determine final status (simply compare both counts
784 $isValid = (count($tables) == $missingTables);
786 // Disconnect here, we don't need idle database connections laying around
787 sqlCloseLink(__FUNCTION__, __LINE__);
789 // If the status is true, disconnect the database
790 if ($isValid === FALSE) {
791 // Still something bad happened (e.g. tables found)
792 $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_IN_USE--}';
793 array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_dbase');
795 // Remember this tab in session
796 installTabOkay($currentTab);
803 // Store given tab in session
804 function installTabOkay ($currentTab) {
806 if (isSessionVariableSet('installer_okay')) {
807 // Is this tab already found?
808 if (strpos(getSession('installer_okay'), $currentTab) === FALSE) {
810 setSession('installer_okay', getSession('installer_okay') . ';' . $currentTab);
814 setSession('installer_okay', $currentTab);
818 // Checks whether at least the required tabs are completed
819 function isInstallationDataCompleted () {
822 (isSessionVariableSet('installer_okay')) &&
823 (strpos(getSession('installer_okay'), 'base_data') !== FALSE) &&
824 (strpos(getSession('installer_okay'), 'database_config') !== FALSE)
828 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCompleted=' . intval($isCompleted) . ',installer_okay=' . getSession('installer_okay'));
832 // Call-back function to check if enable_backlink is Y/N
833 function isInstallerEnableBacklinkValid ($currentTab) {
834 // Check and return it
835 return in_array($currentTab, array('Y', 'N'));
838 // Call-back function to check if warn_no_pass is Y/N
839 function isInstallerWarnNoPassValid ($currentTab) {
840 // Check and return it
841 return in_array($currentTab, array('Y', 'N'));
844 // Call-back function to check if write_footer is Y/N
845 function isInstallerWriteFooterValid ($currentTab) {
846 // Check and return it
847 return in_array($currentTab, array('Y', 'N'));
850 // Call-back function to check if output_mode is Y/N
851 function isInstallerOutputModeValid ($currentTab) {
852 // Check and return it
853 return in_array($currentTab, array('render', 'direct'));
856 // Wrapper to import given installation SQL dump
857 function importInstallSqlDump ($dumpName) {
859 importSqlDump('install', $dumpName, 'install');