add option for specifying the template database during database creation. prompted...
authorRobert Treat <robert@robert-treats-macbook.local>
Fri, 3 Jul 2009 23:14:28 +0000 (19:14 -0400)
committerRobert Treat <robert@robert-treats-macbook.local>
Fri, 3 Jul 2009 23:14:28 +0000 (19:14 -0400)
all_db.php
classes/database/Postgres.php
lang/english.php
lang/recoded/english.php

index bb79cf95aa6021c02826f34e3611fb6537401fbc..a5f511f48def39dcc837cc2602569a05a18d6ac7 100644 (file)
                        else
                                $_POST['formEncoding'] = '';
                }
+               if (!isset($_POST['formTemplate'])) $_POST['formTemplate'] = 'template1';
                if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
                if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
 
+               // Fetch a list of databases in the cluster
+               $templatedbs = $data->getDatabases(false);
+
                // Fetch all tablespaces from the database
                if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces();
 
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
                echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
                        htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
+
+               echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strtemplatedb']}</th>\n";
+               echo "\t\t<td class=\"data1\">\n";
+               echo "\t\t\t<select name=\"formTemplate\">\n";
+                       // Always offer template0 and template1 
+                       echo "\t\t\t\t<option value=\"template0\"",
+                               ($_POST['formTemplate'] == 'template0') ? ' selected="selected"' : '', ">template0</option>\n";
+                       echo "\t\t\t\t<option value=\"template1\"",
+                               ($_POST['formTemplate'] == 'template1') ? ' selected="selected"' : '', ">template1</option>\n";
+                       while (!$templatedbs->EOF) {
+                               $dbname = htmlspecialchars($templatedbs->fields['datname']);
+                               if ($dbname != 'template1') { 
+                                       // filter out for $conf[show_system] users so we dont get duplicates 
+                                       echo "\t\t\t\t<option value=\"{$dbname}\"",
+                                               ($dbname == $_POST['formTemplate']) ? ' selected="selected"' : '', ">{$dbname}</option>\n";
+                               }
+                               $templatedbs->moveNext();
+                       }
+               echo "\t\t\t</select>\n";
+               echo "\t\t</td>\n\t</tr>\n";
+
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strencoding']}</th>\n";
                echo "\t\t<td class=\"data1\">\n";
                echo "\t\t\t<select name=\"formEncoding\">\n";
                // Check that they've given a name and a definition
                if ($_POST['formName'] == '') doCreate($lang['strdatabaseneedsname']);
                else {
-                       $status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc'], $_POST['formComment']);
+                       $status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc'], $_POST['formComment'], $_POST['formTemplate']);
                        if ($status == 0) {
                                $_reload_browser = true;
                                doDefault($lang['strdatabasecreated']);
index f17d9de2103df898a117f79a1b241eaa7d18547c..80c0e078645f8fb15e93500b8885e4c236330880 100755 (executable)
@@ -545,17 +545,16 @@ class Postgres extends ADODB_base {
         * @return -1 tablespace error
         * @return -2 comment error
         */
-       function createDatabase($database, $encoding, $tablespace = '', $comment = '') {
+       function createDatabase($database, $encoding, $tablespace = '', $comment = '', $template = 'template1') {
                $this->fieldClean($database);
                $this->clean($encoding);
                $this->fieldClean($tablespace);
                $this->fieldClean($comment);
+               $this->fieldClean($template);
 
-               if ($encoding == '') {
-                       $sql = "CREATE DATABASE \"{$database}\"";
-               } else {
-                       $sql = "CREATE DATABASE \"{$database}\" WITH ENCODING='{$encoding}'";
-               }
+               $sql = "CREATE DATABASE \"{$database}\" WITH TEMPLATE=\"{$template}\"";
+
+               if ($encoding != '') $sql .= " ENCODING='{$encoding}'";
 
                if ($tablespace != '' && $this->hasTablespaces()) $sql .= " TABLESPACE \"{$tablespace}\"";
 
index 3c558b37efc2c2fad4cc6d3223a9dae072167855..015787101bd52d026d7591488f0a2352b7a6a4a0 100644 (file)
        $lang['strdatabasealtered'] = 'Database altered.';
        $lang['strdatabasealteredbad'] = 'Database alter failed.';
        $lang['strspecifydatabasetodrop'] = 'You must specify at least one database to drop.';
+       $lang['strtemplatedb'] = 'Template';
 
        // Views
        $lang['strview'] = 'View';
index 77e8f30d41a868424ad7ed3f342f783aaa22d8ea..d3c9020176b7bdedbbffc7cf366c6e8ce8187284 100644 (file)
        $lang['strdatabasealtered'] = 'Database altered.';
        $lang['strdatabasealteredbad'] = 'Database alter failed.';
        $lang['strspecifydatabasetodrop'] = 'You must specify at least one database to drop.';
+       $lang['strtemplatedb'] = 'Template';
 
        // Views
        $lang['strview'] = 'View';