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"; } 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"; } /** * 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 "{$lang['strdefinition']} |
---|
", $misc->printVal($vdata->fields['vwdefinition']), " |
{$lang['strnodata']}
\n"; echo "href}&view=", urlencode($_REQUEST['view']), "\">{$lang['stralter']}
\n"; } /** * 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"; 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"; } 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->printTreeXML($columns, $attrs); 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'), ), '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( 'title' => $lang['stralter'], 'url' => "viewproperties.php?action=properties&{$misc->href}&view=".urlencode($_REQUEST['view'])."&", 'vars' => array('column' => 'attname'), ), ); $misc->printTable($attrs, $columns, $actions, null, 'attPre'); echo "