view all databases, drop and create databases. drop has probs
authorchriskl <chriskl>
Thu, 7 Nov 2002 09:39:49 +0000 (09:39 +0000)
committerchriskl <chriskl>
Thu, 7 Nov 2002 09:39:49 +0000 (09:39 +0000)
classes/database/Postgres.php
classes/database/Postgres71.php
lang/english.php
public_html/all_db.php

index f34f0945ad08d05edbb802d09040069805b1654e..fb0a97bc64852007a945074584bd99ae8449d4a9 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres\r
  * Note: This class uses ADODB and returns RecordSets.\r
  *\r
- * $Id: Postgres.php,v 1.19 2002/10/10 18:13:00 xzilla Exp $\r
+ * $Id: Postgres.php,v 1.20 2002/11/07 09:39:49 chriskl Exp $\r
  */\r
 \r
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???\r
@@ -148,14 +148,26 @@ class Postgres extends BaseDB {
                return $this->selectRow($sql);\r
        }\r
 \r
+       /**\r
+        * Creates a database\r
+        * @param $database The name of the database to create\r
+        * @return 0 success\r
+        */\r
+       function createDatabase($database) {\r
+               $this->clean($database);\r
+               $sql = "CREATE DATABASE \"{$database}\"";\r
+               return $this->execute($sql);\r
+       }\r
+\r
        /**\r
         * Drops a database\r
-        * @param $database The name of the database to retrieve\r
+        * @param $database The name of the database to drop\r
         * @return 0 success\r
         */\r
        function dropDatabase($database) {\r
                $this->clean($database);\r
                $sql = "DROP DATABASE \"{$database}\"";\r
+               return $this->execute($sql);\r
        }\r
 \r
        // Table functions\r
index 4dd091b85c35cc365bb4a0a8c9b99f78400f1ab1..5611087807355ae26ddb87af5c33140fb0e749d1 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres71.php,v 1.16 2002/09/23 06:18:55 chriskl Exp $
+ * $Id: Postgres71.php,v 1.17 2002/11/07 09:39:49 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -49,16 +49,6 @@ class Postgres71 extends Postgres {
                return $this->selectRow($sql);
        }
 
-       /**
-        * Drops a database
-        * @param $database The name of the database to retrieve
-        * @return 0 success
-        */
-       function dropDatabase($database) {
-               $this->clean($database);
-               $sql = "DROP DATABASE \"{$database}\"";
-       }
-
        // Table functions
 
        /**
index 38ee606c8ec241902a30bb2df4e9f26d6b2b1046..79a465ff167b7f0bd113c4dd104af707410117dd 100755 (executable)
@@ -4,7 +4,7 @@
         * Language template file for WebDB.  Use this to base language
         * files.
         *
-        * $Id: english.php,v 1.12 2002/11/05 21:07:39 xzilla Exp $
+        * $Id: english.php,v 1.13 2002/11/07 09:39:49 chriskl Exp $
         */
 
        $appLang = 'english';
@@ -43,6 +43,8 @@
        $strNext = 'Next';
        $strFailed = 'Failed';
        $strNotLoaded = 'You have not compiled proper database support into your PHP installation.';
+       $strCreate = 'Create';
+       $strComment = 'Comment';
        
        // Users
        $strUsername = 'Username';
        $strExpires = 'Expires';        
        $strNoUsers = 'No users found.';
        
+       // Databases
+       $strDatabase = 'Database';
+       $strDatabases = 'Databases';
+       $strNoDatabases = 'No Databases found.';
+       $strDatabaseNeedsName = 'You must give a name for your database.';
+       
        // Views
        $strViewNeedsName = 'You must give a name for your view.';
        $strViewNeedsDef = 'You must give a definition for your view.';
index a5cf9a3f514a797c96c3350f7dda8ec123be2b3d..af104c25a9d24c346ea25afbe16f556108c3ed4b 100644 (file)
@@ -1 +1,147 @@
-this is just a placeholder. we want to display database name, owner, encoding and give option to create new databases
+<?php\r
+\r
+       /**\r
+        * Manage databases within a server\r
+        *\r
+        * $Id: all_db.php,v 1.2 2002/11/07 09:39:49 chriskl Exp $\r
+        */\r
+\r
+       // Include application functions\r
+       include_once('../conf/config.inc.php');\r
+       \r
+       $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';\r
+       if (!isset($msg)) $msg = '';\r
+       $PHP_SELF = $_SERVER['PHP_SELF'];\r
+\r
+       /**\r
+        * Show confirmation of drop and perform actual drop\r
+        */\r
+       function doDrop($confirm) {\r
+               global $data, $database;\r
+               global $PHP_SELF;\r
+\r
+               if ($confirm) { \r
+                       echo "<h2>Databases: ", htmlspecialchars($_REQUEST['database']), ": Drop</h2>\n";\r
+                       \r
+                       echo "<p>Are you sure you want to drop the database \"", htmlspecialchars($_REQUEST['database']), "\"?</p>\n";\r
+                       \r
+                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";\r
+                       echo "<input type=hidden name=action value=drop>\n";\r
+                       echo "<input type=hidden name=database value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";\r
+                       echo "<input type=submit name=choice value=\"Yes\"> <input type=submit name=choice value=\"No\">\n";\r
+                       echo "</form>\n";\r
+               }\r
+               else {\r
+                       $status = $data->dropDatabase($_POST['database']);\r
+                       if ($status == 0)\r
+                               doDefault('Database dropped.');\r
+                       else\r
+                               doDefault('Database drop failed.');\r
+               }\r
+               \r
+       }\r
+       \r
+       /**\r
+        * Displays a screen where they can enter a new database\r
+        */\r
+       function doCreate($msg = '') {\r
+               global $data, $misc;\r
+               global $PHP_SELF, $strName;\r
+               \r
+               if (!isset($_POST['formName'])) $_POST['formName'] = '';\r
+               \r
+               echo "<h2>Databases: Create Database</h2>\n";\r
+               $misc->printMsg($msg);\r
+               \r
+               echo "<form action=\"$PHP_SELF\" method=post>\n";\r
+               echo "<table width=100%>\n";\r
+               echo "<tr><th class=data>{$strName}</th></tr>\n";\r
+               echo "<tr><td class=data1><input name=formName size={$data->_maxNameLen} maxlength={$data->_maxNameLen} value=\"", \r
+                       htmlspecialchars($_POST['formName']), "\"></td></tr>\n";\r
+               echo "</table>\n";\r
+               echo "<input type=hidden name=action value=save_create>\n";\r
+               echo "<input type=submit value=Save> <input type=reset>\n";\r
+               echo "</form>\n";\r
+               \r
+               echo "<p><a class=navlink href=\"$PHP_SELF\">Show All Databases</a></p>\n";\r
+       }\r
+       \r
+       /**\r
+        * Actually creates the new view in the database\r
+        */\r
+       function doSaveCreate() {\r
+               global $data, $strDatabaseNeedsName;\r
+               \r
+               // Check that they've given a name and a definition\r
+               if ($_POST['formName'] == '') doCreate($strDatabaseNeedsName);\r
+               else {           \r
+                       $status = $data->createDatabase($_POST['formName']);\r
+                       if ($status == 0)\r
+                               doDefault('Database created.');\r
+                       else\r
+                               doCreate('Database creation failed.');\r
+               }\r
+       }       \r
+\r
+       /**\r
+        * Show default list of databases in the server\r
+        */\r
+       function doDefault($msg = '') {\r
+               global $data, $misc;\r
+               global $PHP_SELF, $strDatabase, $strDatabases, $strComment, $strActions, $strNoDatabases, $strCreate;\r
+               \r
+               echo "<h2>{$strDatabases}</h2>\n";\r
+               $misc->printMsg($msg);\r
+               \r
+               $databases = &$data->getDatabases();\r
+               \r
+               if ($databases->recordCount() > 0) {\r
+                       echo "<table>\n";\r
+                       echo "<tr><th class=data>{$strDatabase}</th><th class=data>{$strComment}</th><th class=data>{$strActions}</th>\n";\r
+                       $i = 0;\r
+                       while (!$databases->EOF) {\r
+                               $id = (($i % 2) == 0 ? '1' : '2');\r
+                               echo "<tr><td class=data{$id}>", htmlspecialchars($databases->f[$data->dbFields['dbname']]), "</td>\n";\r
+                               echo "<td class=data{$id}>", htmlspecialchars($databases->f[$data->dbFields['dbcomment']]), "</td>\n";\r
+                               echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=", \r
+                                       htmlspecialchars($databases->f[$data->dbFields['dbname']]), "\">Drop</a></td>\n";\r
+                               echo "</tr>\n";\r
+                               $databases->moveNext();\r
+                               $i++;\r
+                       }\r
+                       echo "</table>\n";\r
+               }\r
+               else {\r
+                       echo "<p>{$strNoDatabases}</p>\n";\r
+               }\r
+               \r
+               echo "<p><a class=navlink href=\"$PHP_SELF?action=create\">{$strCreate} {$strDatabase}</a></p>\n";\r
+\r
+       }\r
+\r
+       echo "<html>\n";\r
+       echo "<body>\n";\r
+       \r
+       switch ($action) {\r
+               case 'save_create':\r
+                       doSaveCreate();\r
+                       break;\r
+               case 'create':\r
+                       doCreate();\r
+                       break;\r
+               case 'drop':\r
+                       if ($_POST['choice'] == 'Yes') doDrop(false);\r
+                       else doDefault();\r
+                       break;\r
+               case 'confirm_drop':\r
+                       doDrop(true);\r
+                       break;                  \r
+               default:\r
+                       doDefault();\r
+                       break;\r
+       }       \r
+\r
+       echo "</body>\n";\r
+       echo "</html>\n";\r
+       \r
+?>\r