]> dev.renevier.net Git - syp.git/blobdiff - inc/html/install.php
postgresql support
[syp.git] / inc / html / install.php
index 4b2d02cb3673dca4cc1a1a53d096015f807cce6b..7bab8efd67b21eed0fa9c9f52be97d38583ea4b5 100644 (file)
 
     function create_install_form () {
         if (isset ($_POST ["db_form_submit"])) {
+            $type = $_POST ["db_type"];
             $host = $_POST ["db_host"];
             $name = $_POST ["db_name"];
             $user = $_POST ["db_user"];
             $prefix = $_POST ["db_prefix"];
             $title = $_POST ["site_title"];
         } else {
+            $type = "mysql";
             $host = "localhost";
             $user = "syp";
             $name = "syp";
         print '<form method="post" action="' . $_SERVER ["REQUEST_URI"] .  '"><fieldset>' . "\n";
         print '<legend>' . trans ("SYP configuration") . '</legend>' . "\n";
 
+        $drivers = array();
+        $handle = opendir("./inc/db");
+        if (!$handle) {
+            par_error_and_leave (trans ('Could not list <code>inc/db</code> directory'));
+        }
+        while (false !== ($file = readdir($handle))) {
+            if ($file == "." or $file == "..") {
+                continue;
+            }
+            $driver_name = substr($file,0,strrpos($file,'.'));
+            if ($driver_name == "anydb") {
+                continue;
+            }
+            array_push ($drivers, $driver_name);
+        }
+        closedir($handle);
+
+
+        print '<div><label for="db_type" title="' .
+              trans ("You can specify a database backend. Mysql is the most available for standard web hosting services.") .
+              '">' . trans ("database backend:") . '</label>' . "\n" .
+              '<select id="db_type" name="db_type">'. "\n";
+        foreach ($drivers as $driver) {
+            if ($driver == $type) {
+                print '<option name="' . $driver . '" selected="true">' . $driver . '</option>' . "\n";
+            } else {
+                print '<option name="' . $driver . '">' . $driver . '</option>' . "\n";
+            }
+        }
+        print "</select>" . "\n";
+
         print '<div><label for="db_host" title="' .
               trans ("address of the database server (example: localhost, db.myhost.com or 192.168.0.15).") .
               '">' . trans ("database server hostname:") . '</label>' . "\n" .
            }
         }
 
+        define (DBTYPE, _unquote ($_POST ["db_type"]));
         define (DBHOST, _unquote ($_POST ["db_host"]));
         define (DBNAME, _unquote ($_POST ["db_name"]));
         define (DBUSER, _unquote ($_POST ["db_user"]));
         leave ();
     }
 
-    require_once ("./inc/db/mysql.php");
+    if (!include_once ("./inc/db/" . DBTYPE . ".php")) {
+        par_error_and_leave (trans("Unkown backend: ", DBTYPE));
+    }
     require_once ("./inc/utils.php");
 
     try {
         if ($handle) {
             while (!feof ($handle)) {
                 $line = fgets ($handle, 4096);
-                foreach (array ("DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
+                foreach (array ("DBTYPE", "DBHOST", "DBNAME", "DBUSER", "DBPWD", "DBPREFIX", "SITETITLE") as $value) {
                     $pattern = "(define\s+\(\s*\"$value\"\s*,\s*\")[^\"]*(\"\s*\)\s*;)";
                     if (preg_match( "/$pattern/", $line, $match )) {
                         $line = $match[1] . addslashes (constant ($value)) . $match[2];