action) { return $this->doTree(); } $footer_template = 'footer.twig'; $header_template = 'header.twig'; ob_start(); $this->printFooter(true, $footer_template); switch ($this->action) { case 'save_edit': if (isset($_POST['cancel'])) { $this->doDefinition(); } else { $this->doSaveEdit(); } break; case 'edit': $footer_template = 'header_sqledit.twig'; $footer_template = 'footer_sqledit.twig'; $this->doEdit(); break; case 'export': $this->doExport(); break; case 'definition': $this->doDefinition(); break; case 'properties': if (isset($_POST['cancel'])) { $this->doDefault(); } else { $this->doProperties(); } break; case 'alter': if (isset($_POST['alter'])) { $this->doAlter(false); } else { $this->doDefault(); } break; case 'confirm_alter': $this->doAlter(true); break; /*case 'drop': if (isset($_POST['drop'])) { $this->doDrop(false); } else { $this->doDefault(); } break; case 'confirm_drop': $this->doDrop(true); break;*/ default: $this->doDefault(); break; } $output = ob_get_clean(); $this->printHeader($this->headerTitle('', '', $_REQUEST[$this->subject]), null, true, $header_template); $this->printBody(); echo $output; $this->printFooter(true, $footer_template); } /** * Function to save after editing a view. */ public function doSaveEdit() { $data = $this->misc->getDatabaseAccessor(); $status = $data->setView($_POST[$this->subject], $_POST['formDefinition'], $_POST['formComment']); if (0 == $status) { $this->doDefinition($this->lang['strviewupdated']); } else { $this->doEdit($this->lang['strviewupdatedbad']); } } /** * Function to allow editing of a view. * * @param mixed $msg */ public function doEdit($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail($this->subject); $this->printTitle($this->lang['stredit'], 'pg.view.alter'); $this->printMsg($msg); $viewdata = $data->getView($_REQUEST[$this->subject]); $this->printHeader($this->headerTitle(), null, true, 'header_sqledit.twig'); if ($viewdata->recordCount() > 0) { if (!isset($_POST['formDefinition'])) { $_POST['formDefinition'] = $viewdata->fields['vwdefinition']; $_POST['formComment'] = $viewdata->fields['relcomment']; } $variables = (object) [ 'subfolder' => \SUBFOLDER.'/src/views/viewproperties', 'formDefinition' => htmlspecialchars($_POST['formDefinition']), 'formComment' => htmlspecialchars($_POST['formComment']), 'subject' => htmlspecialchars($_REQUEST[$this->subject]), ]; $edition_area = <<
{$this->lang['strdefinition']}
{$this->lang['strcomment']}

{$this->misc->form}

EOT; echo $edition_area; } else { echo "

{$this->lang['strnodata']}

".PHP_EOL; } } /** * Displays a screen where they can alter a column in a view. * * @param mixed $msg */ public function doProperties($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_REQUEST, 'stage', 1); switch ($_REQUEST['stage']) { case 1: $this->printTrail('column'); $this->printTitle($this->lang['stralter'], 'pg.column.alter'); $this->printMsg($msg); echo '
'.PHP_EOL; // Output view header echo ''.PHP_EOL; echo ""; echo ""; $column = $data->getTableAttributes($_REQUEST[$this->subject], $_REQUEST['column']); if (!isset($_REQUEST['default'])) { $_REQUEST['field'] = $column->fields['attname']; $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->fields['adsrc']; $_REQUEST['comment'] = $column->fields['comment']; } echo ''; echo ''; echo ''; echo ''; echo '
{$this->lang['strname']}{$this->lang['strtype']}{$this->lang['strdefault']}{$this->lang['strcomment']}
', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '
'.PHP_EOL; echo '

'.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo ''.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo "lang['stralter']}\" />".PHP_EOL; echo "lang['strcancel']}\" />

".PHP_EOL; echo '
'.PHP_EOL; break; case 2: // Check inputs if ('' == trim($_REQUEST['field'])) { $_REQUEST['stage'] = 1; $this->doProperties($this->lang['strcolneedsname']); return; } // Alter the view column list($status, $sql) = $data->alterColumn( $_REQUEST[$this->subject], $_REQUEST['column'], $_REQUEST['field'], false, false, $_REQUEST['default'], $_REQUEST['olddefault'], '', '', '', '', $_REQUEST['comment'] ); if (0 == $status) { $this->doDefault($this->lang['strcolumnaltered']); } else { $_REQUEST['stage'] = 1; $this->doProperties($this->lang['strcolumnalteredbad']); return; } break; default: echo "

{$this->lang['strinvalidparam']}

".PHP_EOL; } } public function doAlter($confirm = false, $msg = '') { $data = $this->misc->getDatabaseAccessor(); if ($confirm) { $this->printTrail($this->subject); $this->printTitle($this->lang['stralter'], 'pg.view.alter'); $this->printMsg($msg); // Fetch view info $view = $data->getView($_REQUEST[$this->subject]); if ($view->recordCount() > 0) { $this->coalesceArr($_POST, 'name', $view->fields['relname']); $this->coalesceArr($_POST, 'owner', $view->fields['relowner']); $this->coalesceArr($_POST, 'newschema', $view->fields['nspname']); $this->coalesceArr($_POST, 'comment', $view->fields['relcomment']); echo '
'.PHP_EOL; echo ''.PHP_EOL; echo "".PHP_EOL; echo ''.PHP_EOL; if ($data->isSuperUser()) { // Fetch all users $users = $data->getUsers(); echo "".PHP_EOL; echo ''.PHP_EOL; } if ($data->hasAlterTableSchema()) { $schemas = $data->getSchemas(); echo "".PHP_EOL; echo ''.PHP_EOL; } echo "".PHP_EOL; echo ''.PHP_EOL; echo '
{$this->lang['strname']}'; echo "_maxNameLen}\" value=\"", htmlspecialchars($_POST['name']), '" />
{$this->lang['strowner']}
{$this->lang['strschema']}
{$this->lang['strcomment']}'; echo '
'.PHP_EOL; echo ''.PHP_EOL; echo ''.PHP_EOL; echo $this->misc->form; echo "

lang['stralter']}\" />".PHP_EOL; echo "lang['strcancel']}\" />

".PHP_EOL; echo '
'.PHP_EOL; } else { echo "

{$this->lang['strnodata']}

".PHP_EOL; } } else { // For databases that don't allow owner change $this->coalesceArr($_POST, 'owner', ''); $this->coalesceArr($_POST, 'newschema', null); $status = $data->alterView($_POST[$this->subject], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); if (0 == $status) { // If view has been renamed, need to change to the new name and // reload the browser frame. if ($_POST[$this->subject] != $_POST['name']) { // Jump them to the new view name $_REQUEST[$this->subject] = $_POST['name']; // Force a browser reload $this->misc->setReloadBrowser(true); } // If schema has changed, need to change to the new schema and reload the browser 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->doDefault($this->lang['strviewaltered']); } else { $this->doAlter(true, $this->lang['strviewalteredbad']); } } } }