From c4fe7a386efdc972fb1dcd0dae2353e3fbbff5ae Mon Sep 17 00:00:00 2001 From: chriskl Date: Wed, 23 Apr 2003 08:19:03 +0000 Subject: [PATCH] allow select on views --- HISTORY | 1 + views.php | 173 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 132 insertions(+), 42 deletions(-) diff --git a/HISTORY b/HISTORY index 57bafdab..0e77c478 100644 --- a/HISTORY +++ b/HISTORY @@ -7,6 +7,7 @@ Version 3.0.0-dev-4 * Sort on a column when browsing a table * Slovak translation * Reload browser after create/drop of database, schemas and tables +* Select on views Version 3.0.0-dev-3 ------------------- diff --git a/views.php b/views.php index 37551284..1a4aaa69 100644 --- a/views.php +++ b/views.php @@ -3,7 +3,7 @@ /** * Manage views in a database * - * $Id: views.php,v 1.8 2003/04/04 03:59:36 chriskl Exp $ + * $Id: views.php,v 1.9 2003/04/23 08:19:03 chriskl Exp $ */ // Include application functions @@ -12,6 +12,89 @@ $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : ''; if (!isset($msg)) $msg = ''; $PHP_SELF = $_SERVER['PHP_SELF']; + + /** + * Ask for select parameters and perform select + */ + function doSelectRows($confirm, $msg = '') { + global $localData, $database, $misc; + global $lang; + global $PHP_SELF; + + if ($confirm) { + echo "

", htmlspecialchars($_REQUEST['database']), ": {$lang['strviews']}: ", htmlspecialchars($_REQUEST['view']), ": {$lang['strselect']}

\n"; + $misc->printMsg($msg); + + $attrs = &$localData->getTableAttributes($_REQUEST['view']); + + echo "
\n"; + if ($attrs->recordCount() > 0) { + echo "\n"; + + // Output table header + echo ""; + echo ""; + echo ""; + + $i = 0; + while (!$attrs->EOF) { + $attrs->f['attnotnull'] = $localData->phpBool($attrs->f['attnotnull']); + // Set up default value if there isn't one already + if (!isset($_REQUEST['values'][$attrs->f['attname']])) + $_REQUEST['values'][$attrs->f['attname']] = null; + // Continue drawing row + $id = (($i % 2) == 0 ? '1' : '2'); + echo "\n"; + echo ""; + echo ""; + echo ""; + echo ""; + else + echo " "; + echo ""; + echo "\n"; + $i++; + $attrs->moveNext(); + } + echo "
{$lang['strshow']}{$lang['strfield']}{$lang['strtype']}{$lang['strnull']}{$lang['strvalue']}
"; + echo "f['attname']), "]\"", + isset($_REQUEST['show'][$attrs->f['attname']]) ? ' checked="checked"' : '', " />", htmlspecialchars($attrs->f['attname']), "", htmlspecialchars($attrs->f['type']), ""; + // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS) + if (!$attrs->f['attnotnull']) + echo "f['attname']}]\"", + isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " />", $localData->printField("values[{$attrs->f['attname']}]", + $_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "

\n"; + } + else echo "

{$lang['strinvalidparam']}

\n"; + + echo "

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

\n"; + echo "
\n"; + } + else { + if (!isset($_POST['show'])) $_POST['show'] = array(); + if (!isset($_POST['values'])) $_POST['values'] = array(); + if (!isset($_POST['nulls'])) $_POST['nulls'] = array(); + + if (sizeof($_POST['show']) == 0) + doSelectRows(true, $lang['strselectneedscol']); + else { + // Generate query SQL + $query = $localData->getSelectSQL($_REQUEST['view'], array_keys($_POST['show']), + $_POST['values'], array_keys($_POST['nulls'])); + $_REQUEST['query'] = $query; + $_REQUEST['return_url'] = "views.php?action=confselectrows&{$misc->href}&view={$_REQUEST['view']}"; + $_REQUEST['return_desc'] = $lang['strback']; + + include('display.php'); + exit; + } + } + +} /** * Function to save after editing a view @@ -40,23 +123,23 @@ if ($viewdata->recordCount() > 0) { echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; echo "
{$lang['strname']}
", htmlspecialchars($viewdata->f[$data->vwFields['vwname']]), "
{$lang['strdefinition']}
\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; echo $misc->form; - echo " \n"; + echo " \n"; echo "
\n"; } else echo "

{$lang['strnodata']}

\n"; - echo "

href}\">{$lang['strshowallviews']} |\n"; - echo "href}&view=", + echo "

href}\">{$lang['strshowallviews']} |\n"; + echo "href}&view=", urlencode($_REQUEST['view']), "\">{$lang['strproperties']}

\n"; } @@ -73,17 +156,17 @@ $viewdata = &$localData->getView($_REQUEST['view']); if ($viewdata->recordCount() > 0) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo "
{$lang['strname']}
", htmlspecialchars($viewdata->f[$data->vwFields['vwname']]), "
{$lang['strdefinition']}
", nl2br(htmlspecialchars($viewdata->f[$data->vwFields['vwdef']])), "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "
{$lang['strname']}
", htmlspecialchars($viewdata->f[$data->vwFields['vwname']]), "
{$lang['strdefinition']}
", nl2br(htmlspecialchars($viewdata->f[$data->vwFields['vwdef']])), "
\n"; } else echo "

{$lang['strnodata']}

\n"; - echo "

href}\">{$lang['strshowallviews']} |\n"; - echo "href}&view=", + echo "

href}\">{$lang['strshowallviews']} |\n"; + echo "href}&view=", urlencode($_REQUEST['view']), "\">{$lang['stredit']}

\n"; } @@ -99,10 +182,10 @@ echo "

", sprintf($lang['strconfdropview'], htmlspecialchars($_REQUEST['view'])), "

\n"; echo "
\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; echo $misc->form; - echo " \n"; + echo " \n"; echo "
\n"; } else { @@ -128,21 +211,21 @@ echo "

", htmlspecialchars($_REQUEST['database']), ": {$lang['strviews']}: {$lang['strcreateview']}

\n"; $misc->printMsg($msg); - echo "
\n"; - echo "\n"; - echo "\n"; - echo "
{$lang['strname']}
_maxNameLen} maxlength={$data->_maxNameLen} value=\"", + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; - echo "\n"; - echo "\n"; echo "
{$lang['strname']}
_maxNameLen}\" value=\"", htmlspecialchars($_POST['formView']), "\">
{$lang['strdefinition']}
\n"; - echo "\n"; + echo "\n"; echo $misc->form; - echo " \n"; + echo " \n"; echo "\n"; - echo "

href}\">{$lang['strshowallviews']}

\n"; + echo "

href}\">{$lang['strshowallviews']}

\n"; } /** @@ -177,7 +260,8 @@ if ($views->recordCount() > 0) { echo "\n"; - echo "\n"; + echo ""; + echo "\n"; $i = 0; while (!$views->EOF) { // @@@@@@@@@ FIX THIS!!!!! @@ -185,14 +269,14 @@ $count = urlencode("SELECT COUNT(*) AS total FROM \"{$views->f[$data->vwFields['vwname']]}\""); $return_url = urlencode("views.php?{$misc->href}"); $id = (($i % 2) == 0 ? '1' : '2'); - echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; $views->moveNext(); @@ -204,7 +288,7 @@ echo "

{$lang['strnoviews']}

\n"; } - echo "

href}\">{$lang['strcreateview']}

\n"; + echo "

href}\">{$lang['strcreateview']}

\n"; } @@ -212,6 +296,13 @@ $misc->printBody(); switch ($action) { + case 'selectrows': + if (!isset($_POST['cancel'])) doSelectRows(false); + else doDefault(); + break; + case 'confselectrows': + doSelectRows(true); + break; case 'save_create': doSaveCreate(); break; @@ -219,7 +310,7 @@ doCreate(); break; case 'drop': - if ($_POST['choice'] == "{$lang['stryes']}") doDrop(false); + if (isset($_POST['yes'])) doDrop(false); else doDefault(); break; case 'confirm_drop': @@ -234,8 +325,6 @@ case 'properties': doProperties(); break; - case 'browse': - // @@ Not yet implemented default: doDefault(); break; -- 2.39.5
{$lang['strview']}{$lang['strowner']}{$lang['stractions']}
{$lang['strview']}{$lang['strowner']}{$lang['stractions']}
", htmlspecialchars($views->f[$data->vwFields['vwname']]), "", htmlspecialchars($views->f[$data->vwFields['vwowner']]), "href}&query={$query}&count={$count}&return_url={$return_url}&return_desc=", + echo "
", htmlspecialchars($views->f[$data->vwFields['vwname']]), "", htmlspecialchars($views->f[$data->vwFields['vwowner']]), "href}&query={$query}&count={$count}&return_url={$return_url}&return_desc=", urlencode($lang['strback']), "\">{$lang['strbrowse']}{$lang['strselect']}href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strproperties']}href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strdrop']}href}&object=", urlencode($views->f[$data->vwFields['vwname']]), + echo "href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strselect']}href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strproperties']}href}&view=", urlencode($views->f[$data->vwFields['vwname']]), "\">{$lang['strdrop']}href}&object=", urlencode($views->f[$data->vwFields['vwname']]), "&type=view\">{$lang['strprivileges']}