action) { return $this->doTree(); } if ('subtree' == $this->action) { return $this->doSubTree(); } if (isset($_POST['cancel'])) { $this->action = ''; } $header_template = 'header.twig'; ob_start(); switch ($this->action) { case 'create': if (isset($_POST['create'])) { $this->doSaveCreate(); } else { $this->doCreate(); } break; case 'alter': if (isset($_POST['alter'])) { $this->doSaveAlter(); } else { $this->doAlter(); } break; case 'drop': if (isset($_POST['drop'])) { $this->doDrop(false); } else { $this->doDrop(true); } break; case 'export': $this->doExport(); break; default: $header_template = 'header_datatables.twig'; $this->doDefault(); break; } $output = ob_get_clean(); $this->printHeader($this->headerTitle(), null, true, $header_template); $this->printBody(); echo $output; return $this->printFooter(); } /** * Show default list of schemas in the database. * * @param mixed $msg */ public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('database'); $this->printTabs('database', 'schemas'); $this->printMsg($msg); // Check that the DB actually supports schemas $schemas = $data->getSchemas(); $destination = $this->container->utils->getDestinationWithLastTab('schema'); $columns = [ 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('nspname'), 'url' => \SUBFOLDER."{$destination}&", 'vars' => ['schema' => 'nspname'], ], 'owner' => [ 'title' => $this->lang['strowner'], 'field' => Decorator::field('nspowner'), ], 'schema_size' => [ 'title' => $this->lang['strsize'], 'field' => Decorator::field('schema_size'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('nspcomment'), ], ]; $actions = [ 'multiactions' => [ 'keycols' => ['nsp' => 'nspname'], 'url' => 'schemas', ], 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => 'schemas', 'urlvars' => [ 'action' => 'drop', 'nsp' => Decorator::field('nspname'), ], ], ], 'multiaction' => 'drop', ], 'privileges' => [ 'content' => $this->lang['strprivileges'], 'attr' => [ 'href' => [ 'url' => 'privileges', 'urlvars' => [ 'subject' => 'schema', 'schema' => Decorator::field('nspname'), ], ], ], ], 'alter' => [ 'content' => $this->lang['stralter'], 'attr' => [ 'href' => [ 'url' => 'schemas', 'urlvars' => [ 'action' => 'alter', 'schema' => Decorator::field('nspname'), ], ], ], ], ]; if (!$data->hasAlterSchema()) { unset($actions['alter']); } echo $this->printTable($schemas, $columns, $actions, 'schemas-schemas', $this->lang['strnoschemas']); $this->printNavLinks(['create' => [ 'attr' => [ 'href' => [ 'url' => 'schemas', 'urlvars' => [ 'action' => 'create', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], ], ], ], 'content' => $this->lang['strcreateschema'], ]], 'schemas-schemas', get_defined_vars()); } /** * Generate XML for the browser tree. */ public function doTree() { $data = $this->misc->getDatabaseAccessor(); $schemas = $data->getSchemas(); $reqvars = $this->misc->getRequestVars('schema'); //$this->prtrace($reqvars); $attrs = [ 'text' => Decorator::field('nspname'), 'icon' => 'Schema', 'toolTip' => Decorator::field('nspcomment'), 'action' => Decorator::redirecturl( 'redirect', $reqvars, [ 'subject' => 'schema', 'schema' => Decorator::field('nspname'), ] ), 'branch' => Decorator::url( 'schemas', $reqvars, [ 'action' => 'subtree', 'schema' => Decorator::field('nspname'), ] ), ]; return $this->printTree($schemas, $attrs, 'schemas'); } public function doSubTree() { $tabs = $this->misc->getNavTabs('schema'); $items = $this->adjustTabsForTree($tabs); $reqvars = $this->misc->getRequestVars('schema'); //$this->prtrace($reqvars); $attrs = [ 'text' => Decorator::field('title'), 'icon' => Decorator::field('icon'), 'action' => Decorator::actionurl( Decorator::field('url'), $reqvars, Decorator::field('urlvars', []) ), 'branch' => Decorator::url( Decorator::field('url'), $reqvars, Decorator::field('urlvars'), ['action' => 'tree'] ), ]; return $this->printTree($items, $attrs, 'schema'); } /** * Displays a screen where they can enter a new schema. * * @param mixed $msg */ public function doCreate($msg = '') { $data = $this->misc->getDatabaseAccessor(); $server_info = $this->misc->getServerInfo(); $this->coalesceArr($_POST, 'formName', ''); $this->coalesceArr($_POST, 'formAuth', $server_info['username']); $this->coalesceArr($_POST, 'formSpc', ''); $this->coalesceArr($_POST, 'formComment', ''); // Fetch all users from the database $users = $data->getUsers(); $this->printTrail('database'); $this->printTitle($this->lang['strcreateschema'], 'pg.schema.create'); $this->printMsg($msg); echo '
'.PHP_EOL; } /** * Actually creates the new schema in the database. */ public function doSaveCreate() { $data = $this->misc->getDatabaseAccessor(); // Check that they've given a name if ('' == $_POST['formName']) { $this->doCreate($this->lang['strschemaneedsname']); } else { $status = $data->createSchema($_POST['formName'], $_POST['formAuth'], $_POST['formComment']); if (0 == $status) { $this->misc->setReloadBrowser(true); $this->doDefault($this->lang['strschemacreated']); } else { $this->doCreate($this->lang['strschemacreatedbad']); } } } /** * Display a form to permit editing schema properies. * TODO: permit changing owner. * * @param mixed $msg */ public function doAlter($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('schema'); $this->printTitle($this->lang['stralter'], 'pg.schema.alter'); $this->printMsg($msg); $schema = $data->getSchemaByName($_REQUEST['schema']); if ($schema->recordCount() > 0) { $this->coalesceArr($_POST, 'comment', $schema->fields['nspcomment']); $this->coalesceArr($_POST, 'schema', $_REQUEST['schema']); $this->coalesceArr($_POST, 'name', $_REQUEST['schema']); $this->coalesceArr($_POST, 'owner', $schema->fields['ownername']); echo ''.PHP_EOL; } else { echo "{$this->lang['strnodata']}
".PHP_EOL; } } /** * Save the form submission containing changes to a schema. * * @param mixed $msg */ public function doSaveAlter() { $data = $this->misc->getDatabaseAccessor(); $status = $data->updateSchema($_POST['schema'], $_POST['comment'], $_POST['name'], $_POST['owner']); if (0 == $status) { $this->misc->setReloadBrowser(true); $this->doDefault($this->lang['strschemaaltered']); } else { $this->doAlter($this->lang['strschemaalteredbad']); } } /** * Show confirmation of drop and perform actual drop. * * @param mixed $confirm */ public function doDrop($confirm) { $data = $this->misc->getDatabaseAccessor(); if (empty($_REQUEST['nsp']) && empty($_REQUEST['ma'])) { return $this->doDefault($this->lang['strspecifyschematodrop']); } if ($confirm) { $this->printTrail('schema'); $this->printTitle($this->lang['strdrop'], 'pg.schema.drop'); echo ''.PHP_EOL; } else { if (is_array($_POST['nsp'])) { $msg = ''; $status = $data->beginTransaction(); if (0 == $status) { foreach ($_POST['nsp'] as $s) { $status = $data->dropSchema($s, isset($_POST['cascade'])); if (0 == $status) { $msg .= sprintf('%s: %s