Fixes for broken installation routine
[mailer.git] / inc / install-inc.php
index d2fb295a77c7c02fc72edc60713ca5a9048b37d4..9d68191e9ef1de86caa3a3931a935162339fd058 100644 (file)
@@ -17,6 +17,8 @@
  * Needs to be in all Files and every File needs "svn propset           *
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
+ * @TODO Rewrite all constants in this include file                     *
+ * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
@@ -84,14 +86,12 @@ if ((!isInstalled()) || (!isAdminRegistered())) {
        define('__BURL_ACTION', constant('URL'));
 
        // Output page for entered value
-       switch (REQUEST_GET('page'))
-       {
+       switch (REQUEST_GET('page')) {
                case 'welcome': // Welcome to the installation!
                        LOAD_TEMPLATE('install_welcome');
                        break;
 
                case '1': // Server path, base URL
-                       // @Profi-Concept: Hab meine Meinung doch geaendert! :-)
                        // Load template
                        LOAD_TEMPLATE('install_page1');
                        break;
@@ -260,7 +260,7 @@ if ((!isInstalled()) || (!isAdminRegistered())) {
                        break;
 
                case 'finalize': // Write captured data to files
-                       if ((REQUEST_ISSET_POST(('finalize'))) && (!isInstalled())) {
+                       if ((REQUEST_ISSET_POST('finalize')) && (!isInstalled())) {
                                // You have submitted data then we have to reset the SQLs
                                INIT_SQLS();
 
@@ -270,7 +270,12 @@ if ((!isInstalled()) || (!isAdminRegistered())) {
                                        // Seems to work, also right database?
                                        if (SQL_SELECT_DB($mysql['dbase'], __FILE__, __LINE__) === true) {
                                                // Automatically run install.sql
-                                               if ((isFileReadable(REQUEST_POST('spath') . 'install/tables.sql')) && (isFileReadable(REQUEST_POST('spath') . 'install/menu-'.getLanguage().'.sql'))) {
+                                               if ((!isFileReadable(REQUEST_POST('spath') . 'install/tables.sql')) || (!isFileReadable(REQUEST_POST('spath') . 'install/menu-'.getLanguage().'.sql'))) {
+                                                       // Installation area not found!
+                                                       addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
+                                               } // END - if
+
+                                               if (getTotalFatalErrors() == 0) {
                                                        // Both exists so import them
                                                        foreach (array('tables', 'menu-'.getLanguage()) as $dump) {
                                                                // Should be save here because file_exists() is there but we check it again. :)
@@ -337,22 +342,19 @@ if ((!isInstalled()) || (!isAdminRegistered())) {
 
                                                        // Script is now installed
                                                        changeDataInFile(REQUEST_POST('spath') . 'inc/cache/config-local.php', "INSTALLED", "setConfigEntry('MXCHANGE_INSTALLED', \"", "\");", 'Y', 0);
-                                               } else {
-                                                       // Installation area not found!
-                                                       addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
-                                               }
+                                               } // END - if
                                        } // END - if
                                } // END - if
 
                                if (getTotalFatalErrors() > 0) {
                                        $OUT = '';
                                        foreach (getFatalArray() as $value) {
-                                               $OUT .= "    <li>".$value."</li>\n";
+                                               $OUT .= "    <li>" . $value . "</li>\n";
                                        } // END foreach
                                        define('__FATAL_ERROR_LI', $OUT);
                                        $OUT = '';
                                        foreach ($mysql as $key => $value) {
-                                               $OUT .= "    <input type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\" />\n";
+                                               $OUT .= "    <input type=\"hidden\" name=\"mysql[" . $key . "]\" value=\"" . $value . "\" />\n";
                                        } // END foreach
                                        define('__MYSQL_DATA'   , $OUT);
                                        define('__SPATH_VALUE'  , REQUEST_POST('spath'));
@@ -366,11 +368,8 @@ if ((!isInstalled()) || (!isAdminRegistered())) {
                                        LOAD_TEMPLATE('install_fatal_errors');
                                } else {
                                        // Installation is done!
-                                       redirectToUrl('install.php?page=finalize');
+                                       redirectToUrl('install.php?page=finished');
                                }
-                       } elseif (isInstalled()) {
-                               // Redirection after writing data... :-)
-                               LOAD_TEMPLATE('install_finished');
                        } else {
                                // Something goes wrong during installation! :-(
                                addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
@@ -378,6 +377,16 @@ if ((!isInstalled()) || (!isAdminRegistered())) {
                        }
                        break;
 
+               case 'finished':
+                       if (isInstalled()) {
+                               // Load template that we are finished
+                               LOAD_TEMPLATE('install_finished');
+                       } else {
+                               // Not finished
+                               redirectToUrl('install.php');
+                       }
+                       break;
+
                default:
                        DEBUG_LOG(__FILE__, __LINE__, sprintf("Wrong page %s detected", REQUEST_GET('page')));
                        OUTPUT_HTML("    <div class=\"install_error\">{--WRONG_PAGE--}</div>");