printTrail('database');
$misc->printTitle($lang['stralter'], 'pg.database.alter');
echo "
\n";
}
else {
if (!isset($_POST['owner'])) $_POST['owner'] = '';
if (!isset($_POST['dbcomment'])) $_POST['dbcomment'] = '';
if ($data->alterDatabase($_POST['oldname'], $_POST['newname'], $_POST['owner'], $_POST['dbcomment']) == 0) {
$_reload_browser = true;
doDefault($lang['strdatabasealtered']);
}
else
doDefault($lang['strdatabasealteredbad']);
}
}
/**
* Show confirmation of drop and perform actual drop
*/
function doDrop($confirm) {
global $data, $misc;
global $lang, $_reload_drop_database;
if (empty($_REQUEST['dropdatabase']) && empty($_REQUEST['ma'])) {
doDefault($lang['strspecifydatabasetodrop']);
exit();
}
if ($confirm) {
$misc->printTrail('database');
$misc->printTitle($lang['strdrop'], 'pg.database.drop');
echo "\n";
} // END confirm
else {
//If multi drop
if (is_array($_REQUEST['dropdatabase'])) {
$msg = '';
foreach($_REQUEST['dropdatabase'] as $d) {
$status = $data->dropDatabase($d);
if ($status == 0)
$msg.= sprintf('%s: %s
', htmlentities($d, ENT_QUOTES, 'UTF-8'), $lang['strdatabasedropped']);
else {
doDefault(sprintf('%s%s: %s
', $msg, htmlentities($d, ENT_QUOTES, 'UTF-8'), $lang['strdatabasedroppedbad']));
return;
}
}// Everything went fine, back to Default page...
$_reload_drop_database = true;
doDefault($msg);
} else {
$status = $data->dropDatabase($_POST['dropdatabase']);
if ($status == 0) {
$_reload_drop_database = true;
doDefault($lang['strdatabasedropped']);
}
else
doDefault($lang['strdatabasedroppedbad']);
}
}//END DROP
}// END FUNCTION
/**
* Displays a screen where they can enter a new database
*/
function doCreate($msg = '') {
global $data, $misc;
global $lang;
$misc->printTrail('server');
$misc->printTitle($lang['strcreatedatabase'], 'pg.database.create');
$misc->printMsg($msg);
if (!isset($_POST['formName'])) $_POST['formName'] = '';
// Default encoding is that in language file
if (!isset($_POST['formEncoding'])) {
$_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 "\n";
}
/**
* Actually creates the new view in the database
*/
function doSaveCreate() {
global $data, $lang, $_reload_browser;
// Default tablespace to null if it isn't set
if (!isset($_POST['formSpc'])) $_POST['formSpc'] = null;
// Default comment to blank if it isn't set
if (!isset($_POST['formComment'])) $_POST['formComment'] = null;
// Default collate to blank if it isn't set
if (!isset($_POST['formCollate'])) $_POST['formCollate'] = null;
// Default ctype to blank if it isn't set
if (!isset($_POST['formCType'])) $_POST['formCType'] = null;
// 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'], $_POST['formTemplate'], $_POST['formCollate'], $_POST['formCType']);
if ($status == 0) {
$_reload_browser = true;
doDefault($lang['strdatabasecreated']);
}
else
doCreate($lang['strdatabasecreatedbad']);
}
}
/**
* Displays options for cluster download
*/
function doExport($msg = '') {
global $data, $misc;
global $lang;
$misc->printTrail('server');
$misc->printTabs('server','export');
$misc->printMsg($msg);
echo "\n";
}
/**
* Show default list of databases in the server
*/
function doDefault($msg = '') {
global $data, $conf, $misc;
global $lang;
$misc->printTrail('server');
$misc->printTabs('server','databases');
$misc->printMsg($msg);
$databases = $data->getDatabases();
$columns = array(
'database' => array(
'title' => $lang['strdatabase'],
'field' => field('datname'),
'url' => "redirect.php?subject=database&{$misc->href}&",
'vars' => array('database' => 'datname'),
),
'owner' => array(
'title' => $lang['strowner'],
'field' => field('datowner'),
),
'encoding' => array(
'title' => $lang['strencoding'],
'field' => field('datencoding'),
),
'lc_collate' => array(
'title' => $lang['strcollation'],
'field' => field('datcollate'),
),
'lc_ctype' => array(
'title' => $lang['strctype'],
'field' => field('datctype'),
),
'tablespace' => array(
'title' => $lang['strtablespace'],
'field' => field('tablespace'),
),
'dbsize' => array(
'title' => $lang['strsize'],
'field' => field('dbsize'),
'type' => 'prettysize',
),
'actions' => array(
'title' => $lang['stractions'],
),
'comment' => array(
'title' => $lang['strcomment'],
'field' => field('datcomment'),
),
);
$actions = array(
'multiactions' => array(
'keycols' => array('database' => 'datname'),
'url' => 'all_db.php',
'default' => null,
),
'drop' => array(
'content' => $lang['strdrop'],
'attr'=> array (
'href' => array (
'url' => 'all_db.php',
'urlvars' => array (
'subject' => 'database',
'action' => 'confirm_drop',
'dropdatabase' => field('datname')
)
)
),
'multiaction' => 'confirm_drop',
),
'privileges' => array(
'content' => $lang['strprivileges'],
'attr'=> array (
'href' => array (
'url' => 'privileges.php',
'urlvars' => array (
'subject' => 'database',
'database' => field('datname')
)
)
)
)
);
if ($data->hasAlterDatabase() ) {
$actions['alter'] = array(
'content' => $lang['stralter'],
'attr'=> array (
'href' => array (
'url' => 'all_db.php',
'urlvars' => array (
'subject' => 'database',
'action' => 'confirm_alter',
'alterdatabase' => field('datname')
)
)
)
);
}
if (!$data->hasTablespaces()) unset($columns['tablespace']);
if (!$data->hasServerAdminFuncs()) unset($columns['dbsize']);
if (!$data->hasDatabaseCollation()) unset($columns['lc_collate'], $columns['lc_ctype']);
if (!isset($data->privlist['database'])) unset($actions['privileges']);
$misc->printTable($databases, $columns, $actions, 'all_db-databases', $lang['strnodatabases']);
$navlinks = array (
'create' => array (
'attr'=> array (
'href' => array (
'url' => 'all_db.php',
'urlvars' => array (
'action' => 'create',
'server' => $_REQUEST['server']
)
)
),
'content' => $lang['strcreatedatabase']
)
);
$misc->printNavLinks($navlinks, 'all_db-databases', get_defined_vars());
}
function doTree() {
global $misc, $data, $lang;
$databases = $data->getDatabases();
$reqvars = $misc->getRequestVars('database');
$attrs = array(
'text' => field('datname'),
'icon' => 'Database',
'toolTip'=> field('datcomment'),
'action' => url('redirect.php',
$reqvars,
array('database' => field('datname'))
),
'branch' => url('database.php',
$reqvars,
array(
'action' => 'tree',
'database' => field('datname')
)
),
);
$misc->printTree($databases, $attrs, 'databases');
exit;
}
if ($action == 'tree') doTree();
$misc->printHeader($lang['strdatabases']);
$misc->printBody();
switch ($action) {
case 'export':
doExport();
break;
case 'save_create':
if (isset($_POST['cancel'])) doDefault();
else doSaveCreate();
break;
case 'create':
doCreate();
break;
case 'drop':
if (isset($_REQUEST['drop'])) doDrop(false);
else doDefault();
break;
case 'confirm_drop':
doDrop(true);
break;
case 'alter':
if (isset($_POST['oldname']) && isset($_POST['newname']) && !isset($_POST['cancel']) ) doAlter(false);
else doDefault();
break;
case 'confirm_alter':
doAlter(true);
break;
default:
doDefault();
break;
}
$misc->printFooter();
?>