From 1d8f25f8ec5cfd5a70102d56124f8dfd695c46c7 Mon Sep 17 00:00:00 2001 From: chriskl Date: Thu, 15 May 2003 09:48:39 +0000 Subject: [PATCH] heaps of fixes to table browser. (added features as well - naughty of me). Display nulls as NULL in italics, trim long values to 50 characters by default, sort ascending and descending by field, add no wrapping --- classes/Misc.php | 5 ++-- classes/database/Postgres.php | 14 ++++++++--- conf/config.inc.php-dist | 5 +++- lang/english.php | 5 +++- lang/recoded/english.php | 5 +++- tables.php | 47 ++++++++++++++++++++++++++++------- 6 files changed, 63 insertions(+), 18 deletions(-) diff --git a/classes/Misc.php b/classes/Misc.php index 4ecd0d9d..9e890ccc 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -2,7 +2,7 @@ /** * Class to hold various commonly used functions * - * $Id: Misc.php,v 1.31 2003/05/08 14:15:57 chriskl Exp $ + * $Id: Misc.php,v 1.32 2003/05/15 09:48:40 chriskl Exp $ */ class Misc { @@ -47,7 +47,8 @@ function printVal($str) { // If the string contains at least one instance of >1 space in a row, then // substitute all spaces for  s - if (strstr($str, ' ')) + if ($str === null) return 'NULL'; + elseif (strstr($str, ' ')) return nl2br(str_replace(' ', ' ', htmlspecialchars($str))); else return nl2br(htmlspecialchars($str)); diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index cc4aa522..0cf27dd8 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres.php,v 1.103 2003/05/15 08:59:48 chriskl Exp $ + * $Id: Postgres.php,v 1.104 2003/05/15 09:48:40 chriskl Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -666,6 +666,7 @@ class Postgres extends BaseDB { * Returns a recordset of all columns in a relation. Supports paging. * @param $relation The name of a relation * @param $sortkey Field over which to sort. '' for no sort. + * @param $sortdir 'asc' or 'desc' * @param $page The page of the relation to retrieve * @param $page_size The number of rows per page * @param &$max_pages (return-by-ref) The max number of pages in the relation @@ -674,7 +675,7 @@ class Postgres extends BaseDB { * @return -2 counting error * @return -3 page or page_size invalid */ - function &browseRelation($relation, $sortkey, $page, $page_size, &$max_pages) { + function &browseRelation($relation, $sortkey, $sortdir, $page, $page_size, &$max_pages) { $oldrelation = $relation; $this->fieldClean($relation); @@ -706,6 +707,11 @@ class Postgres extends BaseDB { if ($sortkey != '') { $this->fieldClean($sortkey); $orderby = " ORDER BY \"{$sortkey}\""; + // Add sort order + if ($sortdir == 'desc') + $orderby .= ' DESC'; + else + $orderby .= ' ASC'; } else $orderby = ''; @@ -716,9 +722,9 @@ class Postgres extends BaseDB { // Actually retrieve the rows, with offset and limit if ($hasID) - $rs = $this->selectSet("SELECT \"{$this->id}\",* FROM \"{$relation}\" {$orderby}LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size); + $rs = $this->selectSet("SELECT \"{$this->id}\",* FROM \"{$relation}\" {$orderby} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size); else - $rs = $this->selectSet("SELECT * FROM \"{$relation}\" {$orderby}LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size); + $rs = $this->selectSet("SELECT * FROM \"{$relation}\" {$orderby} LIMIT {$page_size} OFFSET " . ($page - 1) * $page_size); $status = $this->endTransaction(); if ($status != 0) { diff --git a/conf/config.inc.php-dist b/conf/config.inc.php-dist index f96ff505..674d94a3 100644 --- a/conf/config.inc.php-dist +++ b/conf/config.inc.php-dist @@ -4,7 +4,7 @@ * Central phpPgAdmin configuration. As a user you may modify the * settings here for your particular configuration. * - * $Id: config.inc.php-dist,v 1.20 2003/05/08 15:14:15 chriskl Exp $ + * $Id: config.inc.php-dist,v 1.21 2003/05/15 09:48:41 chriskl Exp $ */ // An example server. Create as many of these as you wish, @@ -52,6 +52,9 @@ // Max rows to show on a page when browsing record sets $conf['max_rows'] = 30; + // Max chars of each field to display by default in browse mode + $conf['max_chars'] = 50; + // Send XHTML headers? Unless debugging, it's best to leave this off $conf['use_xhtml'] = false; diff --git a/lang/english.php b/lang/english.php index 2e2f087b..0cb435c1 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.77 2003/05/10 13:15:42 chriskl Exp $ + * $Id: english.php,v 1.78 2003/05/15 09:48:41 chriskl Exp $ */ // Language and character set @@ -84,6 +84,9 @@ $lang['strdata'] = 'Data'; $lang['strconfirm'] = 'Confirm'; $lang['strexpression'] = 'Expression'; + $lang['strellipsis'] = '...'; + $lang['strexpand'] = 'Expand'; + $lang['strcollapse'] = 'Collapse'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 246b8666..ba7b7061 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.29 2003/05/10 13:15:43 chriskl Exp $ + * $Id: english.php,v 1.30 2003/05/15 09:48:42 chriskl Exp $ */ // Language and character set @@ -84,6 +84,9 @@ $lang['strdata'] = 'Data'; $lang['strconfirm'] = 'Confirm'; $lang['strexpression'] = 'Expression'; + $lang['strellipsis'] = '...'; + $lang['strexpand'] = 'Expand'; + $lang['strcollapse'] = 'Collapse'; // Error handling $lang['strnoframes'] = 'You need a frames-enabled browser to use this application.'; diff --git a/tables.php b/tables.php index eb5e517a..f6e11bc5 100644 --- a/tables.php +++ b/tables.php @@ -3,7 +3,7 @@ /** * List tables in a database * - * $Id: tables.php,v 1.21 2003/05/15 03:35:08 chriskl Exp $ + * $Id: tables.php,v 1.22 2003/05/15 09:48:39 chriskl Exp $ */ // Include application functions @@ -454,6 +454,8 @@ echo $misc->form; echo "\n"; echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "

\n"; echo "

\n"; @@ -491,6 +493,8 @@ echo $misc->form; echo "\n"; echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "\n"; @@ -518,9 +522,12 @@ if (!isset($_REQUEST['page'])) $_REQUEST['page'] = 1; if (!isset($_REQUEST['sortkey'])) $_REQUEST['sortkey'] = ''; + if (!isset($_REQUEST['sortdir'])) $_REQUEST['sortdir'] = ''; + if (!isset($_REQUEST['strings'])) $_REQUEST['strings'] = 'collapsed'; // Retrieve page from table. $max_pages is returned by reference. - $rs = &$localData->browseRelation($_REQUEST['table'], $_REQUEST['sortkey'], $_REQUEST['page'], $conf['max_rows'], $max_pages); + $rs = &$localData->browseRelation($_REQUEST['table'], $_REQUEST['sortkey'], $_REQUEST['sortdir'], + $_REQUEST['page'], $conf['max_rows'], $max_pages); // Fetch unique row identifier, if there is one $key = $localData->getRowIdentifier($_REQUEST['table']); @@ -528,7 +535,8 @@ if (is_object($rs) && $rs->recordCount() > 0) { // Show page navigation $misc->printPages($_REQUEST['page'], $max_pages, "{$PHP_SELF}?action=browse&page=%s&{$misc->href}&sortkey=" . - urlencode($_REQUEST['sortkey']) . "&table=" . urlencode($_REQUEST['table'])); + urlencode($_REQUEST['sortkey']) . "&sortdir=" . urlencode($_REQUEST['sortdir']) . + "&strings=" . urlencode($_REQUEST['strings']) . "&table=" . urlencode($_REQUEST['table'])); echo "\n"; // @@ CHECK THAT KEY ACTUALLY IS IN THE RESULT SET... @@ -539,7 +547,11 @@ reset($rs->f); while(list($k, ) = each($rs->f)) { if ($k == $localData->id && !$conf['show_oids']) continue; - echo "\n"; } @@ -563,17 +575,25 @@ echo "\n\n"; } else { echo "\n"; echo "\n"; } } while(list($k, $v) = each($rs->f)) { if ($k == $localData->id && !$conf['show_oids']) continue; - elseif ($v == '') echo ""; - else echo ""; + elseif ($v !== null && $v == '') echo ""; + else { + // Trim strings if over length + if ($_REQUEST['strings'] == 'collapsed' && strlen($v) > $conf['max_chars']) { + $v = substr($v, 0, $conf['max_chars'] - 1) . $lang['strellipsis']; + } + echo ""; + } } echo "\n"; $rs->moveNext(); @@ -584,7 +604,16 @@ } else echo "

{$lang['strnodata']}

\n"; - echo "

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

\n"; + echo "

href}\">{$lang['strshowalltables']} |\n"; + if ($_REQUEST['strings'] == 'expanded') + echo "href}&sortkey=", + urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), "&table=", urlencode($_REQUEST['table']), + "&strings=collapsed&page=", $_REQUEST['page'], "&{$key_str}\">{$lang['strcollapse']}

\n"; + else + echo "href}&sortkey=", + urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), "&table=", urlencode($_REQUEST['table']), + "&strings=expanded&page=", $_REQUEST['page'], "&{$key_str}\">{$lang['strexpand']}

\n"; + } /** -- 2.39.5
href}&sortkey=", urlencode($k), "&table=", + echo "href}&sortkey=", urlencode($k), "&sortdir="; + // Sort direction opposite to current direction, unless it's currently '' + echo ($_REQUEST['sortdir'] == 'asc' && $_REQUEST['sortkey'] == $k) ? 'desc' : 'asc'; + echo "&strings=", urlencode($_REQUEST['strings']), "&table=", urlencode($_REQUEST['table']), "\">", $misc->printVal($k), "  href}&sortkey=", - urlencode($_REQUEST['sortkey']), "&table=", urlencode($_REQUEST['table']), + urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), + "&table=", urlencode($_REQUEST['table']), "&strings=", urlencode($_REQUEST['strings']), "&page=", $_REQUEST['page'], "&{$key_str}\">{$lang['stredit']}href}&sortkey=", - urlencode($_REQUEST['sortkey']), "&table=", urlencode($_REQUEST['table']), + urlencode($_REQUEST['sortkey']), "&sortdir=", urlencode($_REQUEST['sortdir']), + "&table=", urlencode($_REQUEST['table']), "&strings=", urlencode($_REQUEST['strings']), "&page=", $_REQUEST['page'], "&{$key_str}\">{$lang['strdelete']} ", $misc->printVal($v), " ", $misc->printVal($v), "