setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']); if ($status == 0) doDefinition($lang['strviewupdated']); else doEdit($lang['strviewupdatedbad']); } /** * Function to allow editing of a view */ function doEdit($msg = '') { global $data, $misc; global $lang; $misc->printTrail('view'); $misc->printTitle($lang['stredit'],'pg.view.alter'); $misc->printMsg($msg); $viewdata = $data->getView($_REQUEST['view']); if ($viewdata->recordCount() > 0) { if (!isset($_POST['formDefinition'])) { $_POST['formDefinition'] = $viewdata->fields['vwdefinition']; $_POST['formComment'] = $viewdata->fields['relcomment']; } echo "
\n"; echo "\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; echo "\t\n\t\t\n"; echo "\t\t\n\t\n"; echo "
{$lang['strdefinition']}
{$lang['strcomment']}
\n"; echo "

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "

\n"; echo "
\n"; } else echo "

{$lang['strnodata']}

\n"; } /** * Allow the dumping of the data "in" a view * NOTE:: PostgreSQL doesn't currently support dumping the data in a view * so I have disabled the data related parts for now. In the future * we should allow it conditionally if it becomes supported. This is * a SMOP since it is based on pg_dump version not backend version. */ function doExport($msg = '') { global $data, $misc; global $lang; $misc->printTrail('view'); $misc->printTabs('view','export'); $misc->printMsg($msg); echo "
\n"; echo "\n"; echo "\n"; // Data only echo "\n"; // Structure only echo "\n"; echo "\n\n"; // Structure and data echo "\n"; echo "
{$lang['strformat']}{$lang['stroptions']}
\n"; echo "

{$lang['stroptions']}

\n"; echo "

\n"; echo "

\n"; echo "

\n"; echo $misc->form; echo "\n"; echo "\n"; echo "

\n"; echo "
\n"; } /** * Show definition for a view */ function doDefinition($msg = '') { global $data, $misc; global $lang; // Get view $vdata = $data->getView($_REQUEST['view']); $misc->printTrail('view'); $misc->printTabs('view','definition'); $misc->printMsg($msg); if ($vdata->recordCount() > 0) { // Show comment if any if ($vdata->fields['relcomment'] !== null) echo "

", $misc->printVal($vdata->fields['relcomment']), "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "
{$lang['strdefinition']}
", $misc->printVal($vdata->fields['vwdefinition']), "
\n"; } else echo "

{$lang['strnodata']}

\n"; $misc->printNavLinks(array ( 'alter' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'viewproperties.php', 'urlvars' => array ( 'action' => 'edit', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'] ) ) ), 'content' => $lang['stralter'] )), 'viewproperties-definition', get_defined_vars()); } /** * Displays a screen where they can alter a column in a view */ function doProperties($msg = '') { global $data, $misc; global $lang; if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1; switch ($_REQUEST['stage']) { case 1: global $lang; $misc->printTrail('column'); $misc->printTitle($lang['stralter'],'pg.column.alter'); $misc->printMsg($msg); echo "
\n"; // Output view header echo "\n"; echo ""; echo ""; $column = $data->getTableAttributes($_REQUEST['view'], $_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 "
{$lang['strname']}{$lang['strtype']}{$lang['strdefault']}{$lang['strcomment']}
", $misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), "
\n"; echo "

\n"; echo "\n"; echo $misc->form; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "

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

{$lang['strinvalidparam']}

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

\n"; echo "

\n"; echo "
\n"; } else echo "

{$lang['strnodata']}

\n"; } else{ global $data, $lang, $_reload_browser, $misc; // For databases that don't allow owner change if (!isset($_POST['owner'])) $_POST['owner'] = ''; if (!isset($_POST['newschema'])) $_POST['newschema'] = null; $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); if ($status == 0) { // If view has been renamed, need to change to the new name and // reload the browser frame. if ($_POST['view'] != $_POST['name']) { // Jump them to the new view name $_REQUEST['view'] = $_POST['name']; // Force a browser reload $_reload_browser = 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 $misc->setCurrentSchema($_POST['newschema']); $_reload_browser = true; } doDefault($lang['strviewaltered']); } else doAlter(true, $lang['strviewalteredbad']); } } function doTree () { global $misc, $data; $reqvars = $misc->getRequestVars('column'); $columns = $data->getTableAttributes($_REQUEST['view']); $attrs = array ( 'text' => field('attname'), 'action' => url('colproperties.php', $reqvars, array( 'view' => $_REQUEST['view'], 'column' => field('attname') ) ), 'icon' => 'Column', 'iconAction' => url('display.php', $reqvars, array( 'view' => $_REQUEST['view'], 'column' => field('attname'), 'query' => replace( 'SELECT "%column%", count(*) AS "count" FROM %view% GROUP BY "%column%" ORDER BY "%column%"', array ( '%column%' => field('attname'), '%view%' => $_REQUEST['view'] ) ) ) ), 'toolTip'=> field('comment') ); $misc->printTree($columns, $attrs, 'viewcolumns'); exit; } if ($action == 'tree') doTree(); /** * Show view definition and virtual columns */ function doDefault($msg = '') { global $data, $misc; global $lang; function attPre(&$rowdata) { global $data; $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); } $misc->printTrail('view'); $misc->printTabs('view','columns'); $misc->printMsg($msg); // Get view $vdata = $data->getView($_REQUEST['view']); // Get columns (using same method for getting a view) $attrs = $data->getTableAttributes($_REQUEST['view']); // Show comment if any if ($vdata->fields['relcomment'] !== null) echo "

", $misc->printVal($vdata->fields['relcomment']), "

\n"; $columns = array( 'column' => array( 'title' => $lang['strcolumn'], 'field' => field('attname'), 'url' => "colproperties.php?subject=column&{$misc->href}&view=".urlencode($_REQUEST['view'])."&", 'vars' => array('column' => 'attname'), ), 'type' => array( 'title' => $lang['strtype'], 'field' => field('+type'), ), 'default' => array( 'title' => $lang['strdefault'], 'field' => field('adsrc'), ), 'actions' => array( 'title' => $lang['stractions'], ), 'comment' => array( 'title' => $lang['strcomment'], 'field' => field('comment'), ), ); $actions = array( 'alter' => array( 'content' => $lang['stralter'], 'attr'=> array ( 'href' => array ( 'url' => 'viewproperties.php', 'urlvars' => array ( 'action' => 'properties', 'view' => $_REQUEST['view'], 'column' => field('attname') ) ) ) ), ); $misc->printTable($attrs, $columns, $actions, 'viewproperties-viewproperties', null, 'attPre'); echo "
\n"; $navlinks = array ( 'browse' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'display.php', 'urlvars' => array ( 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'], 'subject' => 'view', 'return' => 'view' ) ) ), 'content' => $lang['strbrowse'] ), 'select' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'views.php', 'urlvars' => array ( 'action' => 'confselectrows', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'] ) ) ), 'content' => $lang['strselect'] ), 'drop' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'views.php', 'urlvars' => array ( 'action' => 'confirm_drop', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'] ) ) ), 'content' => $lang['strdrop'] ), 'alter' => array ( 'attr'=> array ( 'href' => array ( 'url' => 'viewproperties.php', 'urlvars' => array ( 'action' => 'confirm_alter', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], 'view' => $_REQUEST['view'] ) ) ), 'content' => $lang['stralter'] ) ); $misc->printNavLinks($navlinks, 'viewproperties-viewproperties', get_defined_vars()); } $misc->printHeader($lang['strviews'] . ' - ' . $_REQUEST['view']); $misc->printBody(); switch ($action) { case 'save_edit': if (isset($_POST['cancel'])) doDefinition(); else doSaveEdit(); break; case 'edit': doEdit(); break; case 'export': doExport(); break; case 'definition': doDefinition(); break; case 'properties': if (isset($_POST['cancel'])) doDefault(); else doProperties(); break; case 'alter': if (isset($_POST['alter'])) doAlter(false); else doDefault(); break; case 'confirm_alter': doAlter(true); break; case 'drop': if (isset($_POST['drop'])) doDrop(false); else doDefault(); break; case 'confirm_drop': doDrop(true); break; default: doDefault(); break; } $misc->printFooter(); ?>