[geeklog-cvs] geeklog: Moved dropdown for database selection to a function tha...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Jan 24 14:23:36 EST 2010


changeset 7616:28a46c314666
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/28a46c314666
user: Dirk Haun <dirk at haun-online.de>
date: Sun Jan 24 17:46:20 2010 +0100
description:
Moved dropdown for database selection to a function that checks which databases are actually supported

diffstat:

 public_html/admin/install/index.php       |  24 ++++++------
 public_html/admin/install/lib-install.php |  54 +++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 12 deletions(-)

diffs (117 lines):

diff -r 06de17bdb77d -r 28a46c314666 public_html/admin/install/index.php
--- a/public_html/admin/install/index.php	Sun Jan 24 13:16:46 2010 +0100
+++ b/public_html/admin/install/index.php	Sun Jan 24 17:46:20 2010 +0100
@@ -77,28 +77,26 @@
         // go back because they entered incorrect database information.
         $site_name = (isset($_POST['site_name'])) ? str_replace('\\', '', $_POST['site_name']) : $LANG_INSTALL[29];
         $site_slogan = (isset($_POST['site_slogan'])) ? str_replace('\\', '', $_POST['site_slogan']) : $LANG_INSTALL[30];
-        $mysql_innodb_selected = '';
-        $mysql_selected = '';
-        $mssql_selected = '';
+        $db_selected = '';
         if (isset($_POST['db_type'])) {
             switch ($_POST['db_type']) {
                 case 'mysql-innodb':
-                    $mysql_innodb_selected = ' selected="selected"';
+                    $db_selected = 'mysql-innodb';
                     break;
                 case 'mssql':
-                    $mssql_selected = ' selected="selected"';
+                    $db_selected = 'mssql';
                     break;
                 default:
-                    $mysql_selected = ' selected="selected"';
+                    $db_selected = 'mysql';
                     break;
             }
         } else {
             switch ($_DB_dbms) {
                 case 'mssql':
-                    $mssql_selected = ' selected="selected"';
+                    $db_selected = 'mssql';
                     break;
                 default:
-                    $mysql_selected = ' selected="selected"';
+                    $db_selected = 'mysql';
                     break;
             }
         }
@@ -157,10 +155,12 @@
 
             <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[32] . ' ' . INST_helpLink('site_name') . '</label> <input type="text" name="site_name" value="' . htmlspecialchars($site_name) . '" size="40"' . XHTML . '></p>
             <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[33] . ' ' . INST_helpLink('site_slogan') . '</label> <input type="text" name="site_slogan" value="' . htmlspecialchars($site_slogan) . '" size="40"' . XHTML . '></p>
-            <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[34] . ' ' . INST_helpLink('db_type') . '</label> <select name="db_type">
-                <option value="mysql"' . $mysql_selected . '>' . $LANG_INSTALL[35] . '</option>
-                ' . ($install_type == 'install' ? '<option value="mysql-innodb"' . $mysql_innodb_selected . '>' . $LANG_INSTALL[36] . '</option>' : '') . '
-                <option value="mssql"' . $mssql_selected . '>' . $LANG_INSTALL[37] . '</option></select> ' . '</p>
+            <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[34] . ' ' . INST_helpLink('db_type') . '</label> <select name="db_type">'
+
+            . INST_listOfSupportedDBs($gl_path, $db_selected,
+                    ($install_type == 'install' ? true : false)) .
+
+           '</select> ' . '</p>
             <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[39] . ' ' . INST_helpLink('db_host') . '</label> <input type="text" name="db_host" value="'. htmlspecialchars($db_host) .'" size="20"' . XHTML . '></p>
             <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[40] . ' ' . INST_helpLink('db_name') . '</label> <input type="text" name="db_name" value="'. htmlspecialchars($db_name) . '" size="20"' . XHTML . '></p>
             <p><label class="' . $form_label_dir . '">' . $LANG_INSTALL[41] . ' ' . INST_helpLink('db_user') . '</label> <input type="text" name="db_user" value="' . htmlspecialchars($db_user) . '" size="20"' . XHTML . '></p>
diff -r 06de17bdb77d -r 28a46c314666 public_html/admin/install/lib-install.php
--- a/public_html/admin/install/lib-install.php	Sun Jan 24 13:16:46 2010 +0100
+++ b/public_html/admin/install/lib-install.php	Sun Jan 24 17:46:20 2010 +0100
@@ -1195,4 +1195,58 @@
     return $path;
 }
 
+/**
+* Prepare a dropdown list of all available databases
+*
+* Checks which driver classes and "tableanddata" files are actually present,
+* so that unwanted dbs can be removed (still requires special code all over the
+* place so you can't simply drop in new files to add support for new dbs).
+*
+* @param    string  $gl_path            base Geeklog install path
+* @param    string  $selected_dbtype    currently selected db type
+* @param    boolean $list_innodb        whether to list InnoDB option
+*
+*/
+function INST_listOfSupportedDBs($gl_path, $selected_dbtype, $list_innodb = false)
+{
+    global $LANG_INSTALL;
+
+    $retval = '';
+
+    $dbs = array();
+
+    if (file_exists($gl_path . '/sql/mysql_tableanddata.php') &&
+            file_exists($gl_path . '/system/databases/mysql.class.php')) {
+        $dbs['mysql'] = $LANG_INSTALL[35];
+
+        // may not be needed as a separate option, e.g. for upgrades
+        if ($list_innodb) {
+            $dbs['mysql-innodb'] = $LANG_INSTALL[36];
+        }
+    }
+
+    if (file_exists($gl_path . '/sql/mssql_tableanddata.php') &&
+            file_exists($gl_path . '/system/databases/mssql.class.php')) {
+        $dbs['mssql'] = $LANG_INSTALL[37];
+    }
+
+    // later: PostgreSQL
+    /*
+    if (file_exists($gl_path . '/sql/pgsql_tableanddata.php') &&
+            file_exists($gl_path . '/system/databases/pgsql.class.php')) {
+        $dbs['pgsql'] = $LANG_INSTALL[360];
+    }
+    */
+
+    foreach ($dbs as $dbname => $optiontext) {
+        $retval .= '<option value="' . $dbname . '"';
+        if ($dbname == $selected_dbtype) {
+            $retval .= ' selected="selected"';
+        }
+        $retval .= '>' . $optiontext . '</option>' . LB;
+    }
+
+    return $retval;
+}
+
 ?>



More information about the geeklog-cvs mailing list