* A class that implements the DB interface for Postgres
* Note: This class uses ADODB and returns RecordSets.
*
- * $Id: Postgres73.php,v 1.10 2002/12/27 16:28:01 chriskl Exp $
+ * $Id: Postgres73.php,v 1.11 2003/01/04 07:56:23 chriskl Exp $
*/
// @@@ THOUGHT: What about inherits? ie. use of ONLY???
function &getSchemas() {
if (!$this->_showSystem) $and = "AND nspname NOT LIKE 'pg_%'";
else $and = '';
- $sql = "SELECT nspname, nspowner FROM pg_namespace WHERE nspname = 'public'
+ $sql = "SELECT pn.nspname, pu.usename AS nspowner FROM pg_namespace pn, pg_user pu
+ WHERE pn.nspowner = pu.usesysid
+ AND nspname = 'public'
UNION ALL
- SELECT nspname, nspowner FROM pg_namespace WHERE nspname != 'public' {$and}ORDER BY nspname";
+ SELECT pn.nspname, pu.usename AS nspowner FROM pg_namespace pn, pg_user pu
+ WHERE pn.nspowner = pu.usesysid
+ AND nspname != 'public' {$and}ORDER BY nspname";
return $this->selectSet($sql);
}
* @return 0 success
*/
function createSchema($schemaname, $authorization = '') {
- $this->clean($schemaname);
- $this->clean($authorization);
+ $this->fieldClean($schemaname);
+ $this->fieldClean($authorization);
$sql = "CREATE SCHEMA \"{$schemaname}\"";
if ($authorization != '') $sql .= " AUTHORIZATION \"{$authorization}\"";
* @return 0 success
*/
function dropSchema($schemaname) {
- $this->clean($schemaname);
+ $this->fieldClean($schemaname);
$sql = "DROP SCHEMA \"{$schemaname}\"";
<?php
/**
- * List database controls
+ * Manage schemas within a database
*
- * $Id: database.php,v 1.6 2003/01/04 07:08:03 chriskl Exp $
+ * $Id: database.php,v 1.7 2003/01/04 07:56:23 chriskl Exp $
*/
// Include application functions
include_once('../conf/config.inc.php');
- $misc->printHeader();
-?>
+ $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
+ if (!isset($msg)) $msg = '';
+ $PHP_SELF = $_SERVER['PHP_SELF'];
+
+ /**
+ * Show confirmation of drop and perform actual drop
+ */
+ function doDrop($confirm) {
+ global $PHP_SELF, $data, $localData;
+ global $strDrop, $strConfDropSchema, $strSchemaDropped, $strSchemaDroppedBad;
-<h2><?php echo $appName ?> :: <?php echo $_GET['database'] ?></h2>
+ if ($confirm) {
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": ",
+ htmlspecialchars($_REQUEST['schema']), ": {$strDrop}</h2>\n";
+
+ echo "<p>", sprintf($strConfDropSchema, htmlspecialchars($_REQUEST['schema'])), "</p>\n";
+
+ echo "<form action=\"{$PHP_SELF}\" method=\"post\">\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"drop\">\n";
+ echo "<input type=\"hidden\" name=\"database\" value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=\"hidden\" name=\"schema\" value=\"", htmlspecialchars($_REQUEST['schema']), "\">\n";
+ echo "<input type=\"submit\" name=\"choice\" value=\"Yes\"> <input type=\"submit\" name=\"choice\" value=\"No\">\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $localData->dropSchema($_POST['schema']);
+ if ($status == 0)
+ doDefault($strSchemaDropped);
+ else
+ doDefault($strSchemaDroppedBad);
+ }
+
+ }
+
+ /**
+ * Displays a screen where they can enter a new schema
+ */
+ function doCreate($msg = '') {
+ global $data, $misc;
+ global $PHP_SELF, $strName, $strOwner, $strCreateSchema, $strShowAllSchemas;
+
+ if (!isset($_POST['formName'])) $_POST['formName'] = '';
+ if (!isset($_POST['formAuth'])) $_POST['formAuth'] = $_SESSION['webdbUsername'];
+
+ // Fetch all users from the database
+ $users = &$data->getUsers();
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$strCreateSchema}</h2>\n";
+ $misc->printMsg($msg);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<table width=\"100%\">\n";
+ echo "<tr><th class=\"data\">{$strName}</th><th class=\"data\">{$strOwner}</th></tr>\n";
+ echo "<tr><td class=\"data1\"><input name=\"formName\" size=\"{$data->_maxNameLen}\" maxlength=\"{$data->_maxNameLen}\" value=\"",
+ htmlspecialchars($_POST['formName']), "\"></td>\n";
+ echo "<td class=\"data1\"><select name=\"formAuth\">";
+ while (!$users->EOF) {
+ $uname = htmlspecialchars($users->f[$data->uFields['uname']]);
+ echo "<option value=\"{$uname}\"",
+ ($uname == $_POST['formAuth']) ? ' selected' : '', ">{$uname}</option>\n";
+ $users->moveNext();
+ }
+ echo "</select></td></tr>\n";
+ echo "</table>\n";
+ echo "<p>\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"save_create\">\n";
+ echo "<input type=\"hidden\" name=\"database\" value=\"", htmlspecialchars($_REQUEST['database']), "\">\n";
+ echo "<input type=\"submit\" value=\"Save\"> <input type=\"reset\">\n";
+ echo "</p>\n";
+ echo "</form>\n";
+
+ echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?database=",
+ urlencode($_REQUEST['database']), "\">{$strShowAllSchemas}</a></p>\n";
+ }
+
+ /**
+ * Actually creates the new schema in the database
+ */
+ function doSaveCreate() {
+ global $localData, $strSchemaNeedsName, $strSchemaCreated, $strSchemaCreatedBad;
+
+ // Check that they've given a name
+ if ($_POST['formName'] == '') doCreate($strSchemaNeedsName);
+ else {
+ $status = $localData->createSchema($_POST['formName'], $_POST['formAuth']);
+ if ($status == 0)
+ doDefault($strSchemaCreated);
+ else
+ doCreate($strSchemaCreatedBad);
+ }
+ }
+
+ /**
+ * Show default list of schemas in the server
+ */
+ function doDefault($msg = '') {
+ global $data, $localData, $misc;
+ global $PHP_SELF, $strName, $strOwner, $strSchemas, $strDrop, $strActions, $strCreateSchema, $strNoSchemas;
+
+ echo "<h2>", htmlspecialchars($_REQUEST['database']), ": {$strSchemas}</h2>\n";
+ $misc->printMsg($msg);
+
+ // Check that the DB actually supports schemas
+ if ($data->hasSchemas()) {
+ $schemas = &$localData->getSchemas();
+
+ if ($schemas->recordCount() > 0) {
+ echo "<table>\n";
+ echo "<tr><th class=data>{$strName}</th><th class=data>{$strOwner}</th><th class=data>{$strActions}</th>\n";
+ $i = 0;
+ while (!$schemas->EOF) {
+ $id = (($i % 2) == 0 ? '1' : '2');
+ echo "<tr><td class=data{$id}>", htmlspecialchars($schemas->f[$data->nspFields['nspname']]), "</td>\n";
+ echo "<td class=data{$id}>", htmlspecialchars($schemas->f[$data->nspFields['nspowner']]), "</td>\n";
+ echo "<td class=opbutton{$id}><a href=\"$PHP_SELF?action=confirm_drop&database=",
+ htmlspecialchars($_REQUEST['database']), "&schema=",
+ htmlspecialchars($schemas->f[$data->nspFields['nspname']]), "\">{$strDrop}</a></td>\n";
+ echo "</tr>\n";
+ $schemas->moveNext();
+ $i++;
+ }
+ echo "</table>\n";
+ }
+ else {
+ echo "<p>{$strNoSchemas}</p>\n";
+ }
+
+ echo "<p><a class=navlink href=\"$PHP_SELF?database=", urlencode($_REQUEST['database']),
+ "&action=create\">{$strCreateSchema}</a></p>\n";
+ } else {
+ // If the database does not support schemas...
+ echo "<p>{$strNoSchemas}</p>\n";
+ }
+ }
+
+ $misc->printHeader($strSchemas);
+
+ switch ($action) {
+ case 'save_create':
+ doSaveCreate();
+ break;
+ case 'create':
+ doCreate();
+ break;
+ case 'drop':
+ if ($_POST['choice'] == 'Yes') doDrop(false);
+ else doDefault();
+ break;
+ case 'confirm_drop':
+ doDrop(true);
+ break;
+ default:
+ doDefault();
+ break;
+ }
-<?php
$misc->printFooter();
+
?>