* 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
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
* 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';
$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.';
-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