action) { return $this->doTree(); } // Print header $this->printHeader(); $this->printBody(); switch ($this->action) { case 'create': $this->doCreateSequence(); break; case 'save_create_sequence': if (isset($_POST['create'])) { $this->doSaveCreateSequence(); } else { $this->doDefault(); } break; case 'properties': $this->doProperties(); break; case 'drop': if (isset($_POST['drop'])) { $this->doDrop(false); } else { $this->doDefault(); } break; case 'confirm_drop': $this->doDrop(true); break; case 'restart': $this->doRestart(); break; case 'reset': $this->doReset(); break; case 'nextval': $this->doNextval(); break; case 'setval': if (isset($_POST['setval'])) { $this->doSaveSetval(); } else { $this->doDefault(); } break; case 'confirm_setval': $this->doSetval(); break; case 'alter': if (isset($_POST['alter'])) { $this->doSaveAlter(); } else { $this->doDefault(); } break; case 'confirm_alter': $this->doAlter(); break; default: $this->doDefault(); break; } // Print footer return $this->printFooter(); } /** * Display list of all sequences in the database/schema. * * @param mixed $msg */ public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('schema'); $this->printTabs('schema', 'sequences'); $this->printMsg($msg); // Get all sequences $sequences = $data->getSequences(); $columns = [ 'sequence' => [ 'title' => $this->lang['strsequence'], 'field' => Decorator::field('seqname'), 'url' => "sequences?action=properties&{$this->misc->href}&", 'vars' => ['sequence' => 'seqname'], ], 'owner' => [ 'title' => $this->lang['strowner'], 'field' => Decorator::field('seqowner'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('seqcomment'), ], ]; $actions = [ 'multiactions' => [ 'keycols' => ['sequence' => 'seqname'], 'url' => 'sequences', ], 'alter' => [ 'content' => $this->lang['stralter'], 'attr' => [ 'href' => [ 'url' => 'sequences', 'urlvars' => [ 'action' => 'confirm_alter', 'subject' => 'sequence', 'sequence' => Decorator::field('seqname'), ], ], ], ], 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => 'sequences', 'urlvars' => [ 'action' => 'confirm_drop', 'sequence' => Decorator::field('seqname'), ], ], ], 'multiaction' => 'confirm_drop', ], 'privileges' => [ 'content' => $this->lang['strprivileges'], 'attr' => [ 'href' => [ 'url' => 'privileges', 'urlvars' => [ 'subject' => 'sequence', 'sequence' => Decorator::field('seqname'), ], ], ], ], ]; echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $this->lang['strnosequences']); $this->printNavLinks(['create' => [ 'attr' => [ 'href' => [ 'url' => 'sequences', 'urlvars' => [ 'action' => 'create', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strcreatesequence'], ]], 'sequences-sequences', get_defined_vars()); } /** * Generate XML for the browser tree. */ public function doTree() { $data = $this->misc->getDatabaseAccessor(); $sequences = $data->getSequences(); $reqvars = $this->misc->getRequestVars('sequence'); $attrs = [ 'text' => Decorator::field('seqname'), 'icon' => 'Sequence', 'toolTip' => Decorator::field('seqcomment'), 'action' => Decorator::actionurl( 'sequences', $reqvars, [ 'action' => 'properties', 'sequence' => Decorator::field('seqname'), ] ), ]; return $this->printTree($sequences, $attrs, 'sequences'); } /** * Display the properties of a sequence. * * @param mixed $msg */ public function doProperties($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('sequence'); $this->printTitle($this->lang['strproperties'], 'pg.sequence'); $this->printMsg($msg); // Fetch the sequence information $sequence = $data->getSequence($_REQUEST['sequence']); if (is_object($sequence) && $sequence->recordCount() > 0) { $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); $sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']); // Show comment if any if (null !== $sequence->fields['seqcomment']) { echo '
', $this->misc->printVal($sequence->fields['seqcomment']), '
'.PHP_EOL; } echo '{$this->lang['strname']} | "; if ($data->hasAlterSequenceStart()) { echo "{$this->lang['strstartvalue']} | "; } echo "{$this->lang['strlastvalue']} | "; echo "{$this->lang['strincrementby']} | "; echo "{$this->lang['strmaxvalue']} | "; echo "{$this->lang['strminvalue']} | "; echo "{$this->lang['strcachevalue']} | "; echo "{$this->lang['strlogcount']} | "; echo "{$this->lang['strcancycle']} | "; echo "{$this->lang['striscalled']} |
---|---|---|---|---|---|---|---|---|---|
', $this->misc->printVal($sequence->fields['seqname']), ' | '; if ($data->hasAlterSequenceStart()) { echo '', $this->misc->printVal($sequence->fields['start_value']), ' | '; } echo '', $this->misc->printVal($sequence->fields['last_value']), ' | '; echo '', $this->misc->printVal($sequence->fields['increment_by']), ' | '; echo '', $this->misc->printVal($sequence->fields['max_value']), ' | '; echo '', $this->misc->printVal($sequence->fields['min_value']), ' | '; echo '', $this->misc->printVal($sequence->fields['cache_value']), ' | '; echo '', $this->misc->printVal($sequence->fields['log_cnt']), ' | '; echo '', ($sequence->fields['is_cycled'] ? $this->lang['stryes'] : $this->lang['strno']), ' | '; echo '', ($sequence->fields['is_called'] ? $this->lang['stryes'] : $this->lang['strno']), ' | '; echo '
{$this->lang['strnodata']}
".PHP_EOL; } } /** * Drop a sequence. * * @param mixed $confirm * @param mixed $msg */ public function doDrop($confirm, $msg = '') { $data = $this->misc->getDatabaseAccessor(); if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) { return $this->doDefault($this->lang['strspecifysequencetodrop']); } if ($confirm) { $this->printTrail('sequence'); $this->printTitle($this->lang['strdrop'], 'pg.sequence.drop'); $this->printMsg($msg); echo ''.PHP_EOL; } else { if (is_array($_POST['sequence'])) { $msg = ''; $status = $data->beginTransaction(); if (0 == $status) { foreach ($_POST['sequence'] as $s) { $status = $data->dropSequence($s, isset($_POST['cascade'])); if (0 == $status) { $msg .= sprintf('%s: %s{$this->lang['strnodata']}
".PHP_EOL; } } /** * Function to save after altering a sequence. */ public function doSaveAlter() { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_POST, 'owner', null); $this->coalesceArr($_POST, 'newschema', null); $this->coalesceArr($_POST, 'formIncrement', null); $this->coalesceArr($_POST, 'formMinValue', null); $this->coalesceArr($_POST, 'formMaxValue', null); $this->coalesceArr($_POST, 'formStartValue', null); $this->coalesceArr($_POST, 'formRestartValue', null); $this->coalesceArr($_POST, 'formCacheValue', null); $this->coalesceArr($_POST, 'formCycledValue', null); $status = $data->alterSequence( $_POST['sequence'], $_POST['name'], $_POST['comment'], $_POST['owner'], $_POST['newschema'], $_POST['formIncrement'], $_POST['formMinValue'], $_POST['formMaxValue'], $_POST['formRestartValue'], $_POST['formCacheValue'], isset($_POST['formCycledValue']), $_POST['formStartValue'] ); if (0 == $status) { if ($_POST['sequence'] != $_POST['name']) { // Jump them to the new view name $_REQUEST['sequence'] = $_POST['name']; // Force a browser reload $this->misc->setReloadBrowser(true); } if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { // Jump them to the new sequence schema $this->misc->setCurrentSchema($_POST['newschema']); $this->misc->setReloadBrowser(true); } $this->doProperties($this->lang['strsequencealtered']); } else { $this->doProperties($this->lang['strsequencealteredbad']); } } /** * Function to allow altering of a sequence. * * @param mixed $msg */ public function doAlter($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('sequence'); $this->printTitle($this->lang['stralter'], 'pg.sequence.alter'); $this->printMsg($msg); // Fetch the sequence information $sequence = $data->getSequence($_REQUEST['sequence']); if (is_object($sequence) && $sequence->recordCount() > 0) { $this->coalesceArr($_POST, 'name', $_REQUEST['sequence']); $this->coalesceArr($_POST, 'comment', $sequence->fields['seqcomment']); $this->coalesceArr($_POST, 'owner', $sequence->fields['seqowner']); $this->coalesceArr($_POST, 'newschema', $sequence->fields['nspname']); // Handle Checkbox Value $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']); if ($sequence->fields['is_cycled']) { $_POST['formCycledValue'] = 'on'; } echo ''.PHP_EOL; } else { echo "{$this->lang['strnodata']}
".PHP_EOL; } } }