Prefix in install script is the same as in runtime scripts
[mailer.git] / inc / install-inc.php
index a6fbd91f2b21ac8c7951b2bc015e29537ec90989..7312a401f0d158b32cc1d9f13280d854d08b9738 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Funktionen fuer die Installationsroutine         *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
@@ -42,7 +47,7 @@ if (!defined('__SECURITY')) {
 }
 
 // Init variables
-$mysql = "";
+$mysql = array();
 if ((REQUEST_ISSET_POST(('mysql'))) && (is_array(REQUEST_POST('mysql')))) $mysql = REQUEST_POST('mysql');
 
 // Check if both passwords from SMTP are matching
@@ -74,7 +79,7 @@ if ((REQUEST_ISSET_GET(('page')) && (REQUEST_GET('page') == 5))) {
 } // END - if
 
 // Is MXChange installed or no admin registered so far?
-if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndTrue('admin_registered')))
+if ((!isInstalled()) || (!isAdminRegistered()))
 {
        // Set URL for FORM actions
        define('__BURL_ACTION', constant('URL'));
@@ -96,10 +101,11 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                if (empty($mysql['dbase']))  $mysql['dbase']  = "your_database";
                if (empty($mysql['login']))  $mysql['login']  = "your_login";
                if (empty($mysql['host']))   $mysql['host']   = "localhost";
-               if (empty($mysql['prefix'])) $mysql['prefix'] = "mxchange_";
+               if (empty($mysql['prefix'])) $mysql['prefix'] = "mxchange";
+               if (empty($mysql['type']))   $mysql['type']   = "MyISAM";
                if (getTotalFatalErrors() > 0) {
                        OUTPUT_HTML("<span class=\"install_fatal\">");
-                       foreach ($FATAL as $key => $err) {
+                       foreach (getFatalArray() as $key => $err) {
                                OUTPUT_HTML("  <strong>&middot;</strong>&nbsp;{--FATAL_NO--}".($key + 1).":&nbsp;".$err."<br />");
                        }
                        OUTPUT_HTML("</span><br />");
@@ -107,6 +113,7 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                define('__MYSQL_HOST'  , $mysql['host']);
                define('__MYSQL_DBASE' , $mysql['dbase']);
                define('__MYSQL_PREFIX', $mysql['prefix']);
+               define('__TABLE_TYPE'  , $mysql['type']);
                define('__MYSQL_LOGIN' , $mysql['login']);
                define('__SPATH_VALUE' , REQUEST_POST('spath'));
                define('__BURL_VALUE'  , REQUEST_POST('burl'));
@@ -140,6 +147,7 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                define('__MYSQL_HOST'   , $mysql['host']);
                define('__MYSQL_DBASE'  , $mysql['dbase']);
                define('__MYSQL_PREFIX' , $mysql['prefix']);
+               define('__TABLE_TYPE'   , $mysql['type']);
                define('__MYSQL_LOGIN'  , $mysql['login']);
                define('__MYSQL_PASS1'  , $mysql['pass1']);
                define('__MYSQL_PASS2'  , $mysql['pass2']);
@@ -166,6 +174,7 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                define('__MYSQL_HOST'   , $mysql['host']);
                define('__MYSQL_DBASE'  , $mysql['dbase']);
                define('__MYSQL_PREFIX' , $mysql['prefix']);
+               define('__TABLE_TYPE'   , $mysql['type']);
                define('__MYSQL_LOGIN'  , $mysql['login']);
 
                // SMTP settings
@@ -245,9 +254,9 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
 <tr>
   <td colspan=\"2\" align=\"center\">");
                foreach ($mysql as $key => $value) {
-                       OUTPUT_HTML("    <input type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\">");
+                       OUTPUT_HTML("    <input type=\"hidden\" name=\"mysql[".$key."]\" value=\"".$value."\" />");
                }
-               OUTPUT_HTML("    <input type=\"hidden\" name=\"spath\" value=\"{!__SPATH_VALUE!}\">
+               OUTPUT_HTML("    <input type=\"hidden\" name=\"spath\" value=\"{!__SPATH_VALUE!}\" />
     <input type=\"hidden\" name=\"burl\" value=\"{!__BURL_VALUE!}\" />
     <input type=\"hidden\" name=\"title\" value=\"{!__TITLE_VALUE!}\" />
     <input type=\"hidden\" name=\"slogan\" value=\"{!__SLOGAN_VALUE!}\" />
@@ -264,9 +273,9 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                break;
 
        case "finalize": // Write captured data to files
-               if ((REQUEST_ISSET_POST(('finalize'))) && (!isBooleanConstantAndTrue('mxchange_installed'))) {
-                       // You have submitted data then we have to reset the fatal messages
-                       $SQLs = array();
+               if ((REQUEST_ISSET_POST(('finalize'))) && (!isInstalled())) {
+                       // You have submitted data then we have to reset the SQLs
+                       INIT_SQLS();
 
                        // Connect to MySQL server
                        SQL_CONNECT($mysql['host'], $mysql['login'], $mysql['pass1'], __FILE__, __LINE__);
@@ -276,15 +285,25 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                                        // Automatically run install.sql
                                        if ((FILE_READABLE(REQUEST_POST('spath')."install/tables.sql")) && (FILE_READABLE(REQUEST_POST('spath')."install/menu-".GET_LANGUAGE().".sql"))) {
                                                // Both exists so import them
-                                               foreach (array("tables.sql", "menu-".GET_LANGUAGE().".sql") as $dump) {
+                                               foreach (array("tables", "menu-".GET_LANGUAGE()) as $dump) {
                                                        // Should be save here because file_exists() is there but we check it again. :)
-                                                       $FQFN = secureString(REQUEST_POST('spath')) . "install/" . $dump;
+                                                       $FQFN = REQUEST_POST('spath') . "install/" . $dump . ".sql";
                                                        if (FILE_READABLE($FQFN)) {
                                                                // Read the file
-                                                               $SQLs = READ_FILE($FQFN, true);
+                                                               $fileContent = READ_FILE($FQFN, true);
+
+                                                               // Replace the {!prefix!} with actual one
+                                                               while (strpos($fileContent, "{!prefix!}") !== false) {
+                                                                       $fileContent = str_replace("{!prefix!}", $mysql['prefix'], $fileContent);
+                                                               } // END - while
+
+                                                               // Replace the {!type!} with actual one
+                                                               while (strpos($fileContent, "{!type!}") !== false) {
+                                                                       $fileContent = str_replace("{!type!}", $mysql['type'], $fileContent);
+                                                               } // END - while
 
                                                                // And split it up against ;\n ...
-                                                               $SQLs = merge_array($SQLs, explode(";\n", $sql));
+                                                               SET_SQLS(merge_array(GET_SQLS(), explode(";\n", $fileContent)));
                                                        } else {
                                                                // Not readable!
                                                                debug_report_bug(sprintf("SQL dump %s is not readable!", $dump));
@@ -292,23 +311,14 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                                                } // END - foreach
 
                                                // Are some SQLs found?
-                                               if (count($SQLs) == 0) {
+                                               if (COUNT_SQLS() == 0) {
                                                        // Abort here
-                                                       addFatalMessage(getMessage('INSTALL_SQL_IMPORT_FAILED'));
+                                                       addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_SQL_IMPORT_FAILED'));
                                                        return;
                                                } // END - if
 
                                                // Now run all queries through and try to keep out empty or comment queries
-                                               foreach ($SQLs as $sql) {
-                                                       // Trim spaces away
-                                                       $sql = trim($sql);
-
-                                                       // Is this query not empty and not a comment?
-                                                       if ((!empty($sql)) && (substr($sql, 0, 2) != "--") && (substr($sql, 0, 1) != "#")) {
-                                                               // Then run it!
-                                                               SQL_QUERY($sql, __FILE__, __LINE__);
-                                                       } // END - if
-                                               } // END - foreach
+                                               runFilterChain('run_sqls');
 
                                                // Ok, all done. So we can write the config data to the php files
                                                if (REQUEST_POST('spath') != constant('PATH')) changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SERVER-PATH", "define('PATH', \"", "\");", REQUEST_POST('spath'), 0);
@@ -325,20 +335,21 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-LOGIN", "       'login'    => \"", "\",", $mysql['login'], 0);
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-PASSWORD", "    'password' => \"", "\",", $mysql['pass1'], 0);
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "MYSQL-PREFIX", "define('_MYSQL_PREFIX', \"", "\");", $mysql['prefix'], 0);
+                                               changeDataInFile(REQUEST_POST('spath')."inc/config.php", "TABLE-TYPE", "define('_TABLE_TYPE', \"", "\");", $mysql['type'], 0);
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SMTP-HOSTNAME", "define('SMTP_HOSTNAME', \"", "\");", REQUEST_POST('smtp_host'), 0);
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SMTP-USER", "define('SMTP_USER', \"", "\");", REQUEST_POST('smtp_user'), 0);
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "SMTP-PASSWORD", "define('SMTP_PASSWORD', \"", "\");", REQUEST_POST('smtp_pass1'), 0);
                                                changeDataInFile(REQUEST_POST('spath')."inc/config.php", "INSTALLED", "define('mxchange_installed', ", ");", "true", 0);
                                        } else {
                                                // Installation area not found!
-                                               addFatalMessage(getMessage('INSTALL_MISSING_DUMPS'));
+                                               addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_MISSING_DUMPS'));
                                        }
                                } // END - if
                        } // END - if
 
                        if (getTotalFatalErrors() > 0) {
                                $OUT = "";
-                               foreach ($FATAL as $value) {
+                               foreach (getFatalArray() as $value) {
                                        $OUT .= "    <li>".$value."</li>\n";
                                } // END foreach
                                define('__FATAL_ERROR_LI', $OUT);
@@ -360,12 +371,12 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
                                // Installation is done!
                                LOAD_URL("install.php?page=finalize");
                        }
-               } elseif (isBooleanConstantAndTrue('mxchange_installed')) {
+               } elseif (isInstalled()) {
                        // Redirection after writing data... :-)
                        LOAD_TEMPLATE("install_finished");
                } else {
                        // Something goes wrong during installation! :-(
-                       addFatalMessage(getMessage('INSTALL_FINALIZER_FAILED'));
+                       addFatalMessage(__FILE__, __LINE__, getMessage('INSTALL_FINALIZER_FAILED'));
                        LOAD_INC("inc/fatal_errors.php");
                }
                break;
@@ -377,7 +388,7 @@ if ((!isBooleanConstantAndTrue('mxchange_installed')) || (!isBooleanConstantAndT
        }
 } else {
        // Already installed!
-       addFatalMessage(getMessage('ALREADY_INSTALLED'));
+       addFatalMessage(__FILE__, __LINE__, getMessage('ALREADY_INSTALLED'));
 }
 
 //