From 8f7dc900627fdeefe86917cb5328454c622a51d0 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Mon, 12 May 2003 18:28:46 +0000 Subject: [PATCH] Patch #725839 (Netsted display of tables) --- ChangeLog | 2 + config.inc.php3 | 4 + left.php3 | 347 ++++++++++++++++++++++++++++--- libraries/common.lib.php3 | 8 +- libraries/config_import.lib.php3 | 8 + 5 files changed, 336 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index c58f69737..aac5f4042 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,8 @@ $Source$ in the small frame. * footer.inc.php3: Only update db/table variables if the query was correct. Fixes #735970. + * left.php3, config.inc.php3, libraries/config_import.lib.php3, libraries/ + common.lib.php3: Patch #725839 (Nested display of tables) 2003-05-12 Michal Cihar * index.php3: Better fix for #736003. diff --git a/config.inc.php3 b/config.inc.php3 index a0749cf9d..6c4c1157c 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -197,6 +197,10 @@ $cfg['UseDbSearch'] = TRUE; // whether to enable the "database searc // Left frame setup $cfg['LeftFrameLight'] = TRUE; // use a select-based menu and display only the // current tables in the left frame. +$cfg['LeftFrameTableSeparator']= '__'; // Which string will be used to generate table prefixes + // to split tables into multiple categories +$cfg['LeftFrameTableLevel'] = '1'; // How many sublevels should be displayed when splitting + // up tables by the above Separator $cfg['ShowTooltip'] = TRUE; // display table comment as tooltip in left frame $cfg['ShowTooltipAliasDB'] = FALSE; // if ShowToolTip is enabled, this defines that table/db comments $cfg['ShowTooltipAliasTB'] = FALSE; // are shown (in the left menu and db_details_structure) instead of diff --git a/left.php3 b/left.php3 index 7498e020f..ba7c7164f 100755 --- a/left.php3 +++ b/left.php3 @@ -33,6 +33,189 @@ include('./libraries/bookmark.lib.php3'); require('./libraries/relation.lib.php3'); $cfgRelation = PMA_getRelationsParam(); +function PMA_reduceNest($_table) { + + if ($GLOBALS['cfg']['LeftFrameTableLevel'] > 0) { + $max = $GLOBALS['cfg']['LeftFrameTableLevel']; + $temp_table = $_table; + $new_table = array(); + $last_index = 0; + for ($ti = 0; $ti < $max; $ti++) { + if (isset($temp_table[$ti])) { + $new_table[$ti] = $temp_table[$ti]; + unset($temp_table[$ti]); + $last_index = $ti; + } + } + + $_table = $new_table; + } + + return $_table; +} + +function PMA_indent($spaces) { + $string = ''; + for ($i = 0; $i <= $spaces; $i++) { + $string .= ' '; + } + + return $string; +} + +/* DEBUGGING ONLY - REMOVE WHEN PATCH ACCEPTED +$path = ''; +$functioncalls = ''; + +function functioncalls($name, $args, $array) { + $GLOBALS['functioncalls'] .= $name . "\n------------------------\n"; + foreach($array AS $xkey => $key) { + $defvals = explode(':' , $key); + $key=$defvals[0]; + + $val = (isset($args[$xkey]) ? $args[$xkey] : $defvals[1]); + if (is_array($val)) { + $GLOBALS['functioncalls'] .= $key . "\n"; + foreach($val AS $skey => $sval) { + if (!is_array($val)) { + $GLOBALS['functioncalls'] .= "\t" . $skey . "\n\t\t" . stripslashes(var_export($sval)) . "\n"; + } else { + $GLOBALS['functioncalls'] .= "\t" . $skey . "\n\t\t[ARRAY]\n"; + } + } + } else { + $GLOBALS['functioncalls'] .= $key . "\n\t" . stripslashes(var_export($val, true)) . "\n"; + } + } + + $GLOBALS['functioncalls'] .= "\n\n"; + + return true; +} +*/ + +function PMA_nestedSetHeaderParent($baseid, $key, $keyhistory, $indent, $indent_level, $val, $childout = true) { +/* DEBUGGING ONLY - REMOVE WHEN PATCH ACCEPTED + $args = func_get_args(); + functioncalls('PMA_nestedSetHeaderParent', $args, array('baseid', 'key','keyhistory','indent','indent_level','val','childout:true')); +*/ + + $name = $key; + $id = eregi_replace('[^a-z0-9]*', '', $baseid . $keyhistory . $key) . $indent; + + $on_mouse = (($GLOBALS['cfg']['LeftPointerColor'] == '') ? '' : ' onmouseover="if (isDOM || isIE4) {hilightBase(\'el' . $id . '\', \'' . $GLOBALS['cfg']['LeftPointerColor'] . '\')}" onmouseout="if (isDOM || isIE4) {hilightBase(\'el' . $id . '\', \'' . $GLOBALS['cfg']['LeftBgColor'] . '\')}"'); + + $countarray = $val; + if (count($countarray) == 2 && isset($countarray['pma_name']) && isset($countarray['pma_list_item'])) { + $counter = count($countarray['pma_name']); + } else { + unset($countarray['pma_name']); + if (count($countarray) > 1) { + unset($countarray['pma_list_item']); + } + $counter = count($countarray); + } + + echo "\n"; + echo PMA_indent($indent * 5) . '
' . "\n"; + echo PMA_indent($indent * 6) . ''; + echo '+' . "\n"; + echo PMA_indent($indent * 6) . '' . htmlspecialchars($name) . '  (' . $counter . ')' . "\n"; + echo PMA_indent($indent * 5) . '
' . "\n"; + echo "\n"; + + if ($childout) { + echo PMA_indent($indent * 5) . '
' . "\n"; + } +} + +function PMA_nestedSetHeader($baseid, $tablestack, $keyhistory, $indent, $indent_level, $headerOut, $firstGroup = false, $firstGroupClose = true) { +/* DEBUGGING ONLY - REMOVE WHEN PATCH ACCEPTED + $args = func_get_args(); + functioncalls('PMA_nestedSetHeader', $args, array('baseid', 'tablestack','keyhistory','indent','indent_level','headerOut','firstGroup:false')); +*/ + if ($firstGroup) { + PMA_nestedSetHeaderParent($baseid, $firstGroup, $keyhistory, $indent, $indent_level, $tablestack); + $indent++; + } + + while(list($key, $val) = each($tablestack)) { + if ($key != 'pma_name' && $key != 'pma_list_item') { + if ($headerOut) { + PMA_nestedSetHeaderParent($baseid, $key, $keyhistory, $indent, $indent_level, $val); + } + + if (isset($val['pma_name']) && isset($val['pma_list_item']) && count($val) == 2) { + PMA_nestedSet($baseid, $val, $key, $keyhistory . $key, false, ($indent + 1)); + } else { + PMA_nestedSet($baseid, $val, $key, $keyhistory . $key, true, ($indent + 1)); + } + + if ($headerOut) { + echo PMA_indent($indent * 5) . '
' . "\n"; + } + } + } + + if ($firstGroup && $firstGroupClose) { + echo PMA_indent($indent * 4) . '' . "\n"; + } elseif ($firstGroup) { + echo PMA_indent($indent * 4) . '' . "\n"; + } +} + +function PMA_nestedSet($baseid, $tablestack, $key = '__protected__', $keyhistory = '', $headerOut = false, $indent = 1) { +/* DEBUGGING ONLY - REMOVE WHEN PATCH ACCEPTED + $args = func_get_args(); + functioncalls('PMA_nestedSet', $args, array('baseid', 'tablestack', 'key:__protected__', 'keyhistory:\'\'', 'headerOut:false', 'indent:1')); +*/ + + if ($keyhistory == '' && $key != '__protected__') { + $keyhistory = $key; + } + + $indent_level = 9; + + if (isset($tablestack) + && isset($tablestack['pma_name']) + && isset($tablestack['pma_list_item'])) { + + if (count($tablestack) > 1 && !empty($key) && isset($tablestack['pma_name']) && isset($tablestack['pma_list_item']) && $indent == 1) { + PMA_nestedSetHeader($baseid, $tablestack, $keyhistory, ($indent+1), $indent_level, $headerOut, $key, false); + $divClose = true; + $extra_indent = 1; + } else { + PMA_nestedSetHeader($baseid, $tablestack, $keyhistory, $indent, $indent_level, $headerOut); + $divClose = false; + $extra_indent = 0; + } + + $on_mouse = (($GLOBALS['cfg']['LeftPointerColor'] == '') ? '' : ' onmouseover="if (isDOM || isIE4) {hilightBase(\'el' . $keyhistory . $key . '\', \'' . $GLOBALS['cfg']['LeftPointerColor'] . '\')}" onmouseout="if (isDOM || isIE4) {hilightBase(\'el' . $keyhistory . $key . '\', \'' . $GLOBALS['cfg']['LeftBgColor'] . '\')}"'); + + $loops = 0; + while(list($tkey, $tval) = each($tablestack['pma_name'])) { + + echo PMA_indent($indent * 5) . ''; + $items = explode("\n", $tablestack['pma_list_item'][$tkey]); + while(list($ikey, $ival) = each($items)) { + echo "\n"; + echo PMA_indent(($indent * 5)) . $ival; + } + echo "\n"; + + $loops++; + } + + if ($divClose) { + echo PMA_indent($indent * 5) . ''; + } + + } elseif (is_array($tablestack)) { + PMA_nestedSetHeader($baseid, $tablestack, $keyhistory, (($key == '__protected__' && $indent == 1 )? ($indent-1) : ($indent + 1)), $indent_level, $headerOut, (($key == '__protected__' && $indent == 1) || ($indent > 1) ? false : $key)); + } + + return true; +} /** * Get the list and number of available databases. * Skipped if no server selected: in this case no database should be displayed @@ -81,7 +264,7 @@ if (isset($lightm_db) && !empty($lightm_db)) { 1 && !$cfg['LeftFrameLight']) { +if (($num_dbs > 1 || !empty($cfg['LeftFrameTableSeparator'])) && !$cfg['LeftFrameLight']) { echo "\n"; ?> @@ -260,9 +443,9 @@ if ($num_dbs > 1) {
> - - 1) { ? htmlspecialchars($tooltip[$table]) : ''; - echo "\n"; - $book_sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'', 'label'); - ?> - - - <?php echo $strBrowse . ': ' . $url_title; ?>  - -
- '; + $list_item .= '' . $strBrowse . ': ' . $url_title . ''; + $list_item .= ' ' . "\n"; + $list_item .= ''; + $list_item .= ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
' . "\n"; + + // garvin: Check whether to display nested sets + if (!empty($cfg['LeftFrameTableSeparator'])) { + $_table = explode($cfg['LeftFrameTableSeparator'], $table); + if (is_array($_table)) { + reset($_table); + while(list($key, $val) = each($_table)) { + if ($val == '') { + $_table[$key] = '__protected__'; + } + } + + unset($_table[count($_table)-1]); + $_table = PMA_reduceNest($_table); + + $eval_string = '$tablestack[\'' . implode('\'][\'', $_table) . '\'][\'pma_name\'][] = \'' . $table . '\';'; + $eval_string .= '$tablestack[\'' . implode('\'][\'', $_table) . '\'][\'pma_list_item\'][] = \'' . $list_item . '\';'; + eval($eval_string); + } else { + $tablestack['__protected__']['pma_name'][] = $table; + $tablestack['__protected__']['pma_list_item'][] = $list_item; + } + } else { + $tablestack['__protected__']['pma_name'][] = $table; + $tablestack['__protected__']['pma_list_item'][] = $list_item; + } } // end for $t (tables list) - echo "\n"; + + PMA_nestedSet($j, $tablestack); ?>
" href="' . "\n"; - $table_list .= ' ' . $strBrowse . ': ' . $url_title . ' ' . "\n"; + $table_list .= ' ' . $strBrowse . ': ' . $url_title . ' ' . "\n"; if (PMA_USR_BROWSER_AGENT == 'IE') { - $table_list .= ' ' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
' . "\n"; + $table_list .= ' ' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
' . "\n"; } else { - $table_list .= ' ' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
' . "\n"; + $table_list .= ' ' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
' . "\n"; } } // end for $t (tables list) @@ -421,38 +627,121 @@ else if ($num_dbs == 1) { } } + // Displays the database name - echo "\n"; - ?> + if (!$cfg['LeftFrameLight']) { + $on_mouse = (($cfg['LeftPointerColor'] == '') ? '' : ' onmouseover="if (isDOM || isIE4) {hilightBase(\'el2\', \'' . $cfg['LeftPointerColor'] . '\')}" onmouseout="if (isDOM || isIE4) {hilightBase(\'el2\', \'' . $cfg['LeftBgColor'] . '\')}"'); + + echo "\n"; + echo '
'; + + if (!empty($num_tables)) { + echo "\n"; + ?> + + + + + - + + + ' . htmlspecialchars($db_tooltip) . '' : htmlspecialchars($db)); ?>  () +
+ +
> +
- - - <?php echo $strBrowse . ': ' . htmlspecialchars($table); ?>  + + <?php echo $strBrowse . ': ' . $url_title; ?> 
'; + $list_item .= '' . $strBrowse . ': ' . $url_title . ''; + $list_item .= ' ' . "\n"; + $list_item .= ''; + $list_item .= ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
'; + + // garvin: Check whether to display nested sets + if (!empty($cfg['LeftFrameTableSeparator'])) { + $_table = explode($cfg['LeftFrameTableSeparator'], $table); + if (is_array($_table)) { + reset($_table); + while(list($key, $val) = each($_table)) { + if ($val == '') { + $_table[$key] = '__protected__'; + } + } + unset($_table[count($_table)-1]); + $_table = PMA_reduceNest($_table); + + $eval_string = '$tablestack[\'' . implode('\'][\'', $_table) . '\'][\'pma_name\'][] = \'' . $table . '\';'; + $eval_string .= '$tablestack[\'' . implode('\'][\'', $_table) . '\'][\'pma_list_item\'][] = \'' . $list_item . '\';'; + eval($eval_string); + } else { + $tablestack['__protected__']['pma_name'][] = $table; + $tablestack['__protected__']['pma_list_item'][] = $list_item; + } + } else { + $tablestack['__protected__']['pma_name'][] = $table; + $tablestack['__protected__']['pma_list_item'][] = $list_item; + } + } } // end for $j (tables list) - echo "\n"; - ?> + + if (!$cfg['LeftFrameLight']) { + PMA_nestedSet('1', $tablestack); + ?>
- + + '; + } + + echo "\n"; } // end if ($num_dbs == 1) diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index 764373889..ed493f276 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -138,7 +138,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} * Includes compatibility code for older config.inc.php3 revisions * if necessary */ - if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 174) { + if (!isset($cfg['FileRevision']) || (int) substr($cfg['FileRevision'], 13, 3) < 175) { include('./libraries/config_import.lib.php3'); } @@ -1809,13 +1809,13 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} * Fulfills todo-item http://sourceforge.net/tracker/index.php?func=detail&aid=544361&group_id=23067&atid=377411 * * @param string The string - * @param string The seperator (defaults to "
\n") + * @param string The Separator (defaults to "
\n") * * @access public * @author Garvin Hicking * @return string The flipped string */ - function PMA_flipstring($string, $seperator = "
\n") { + function PMA_flipstring($string, $Separator = "
\n") { $format_string = ''; $charbuff = false; @@ -1841,7 +1841,7 @@ h1 {font-family: sans-serif; font-size: large; font-weight: bold} } if ($append && ($i != strlen($string))) { - $format_string .= $seperator; + $format_string .= $Separator; } } diff --git a/libraries/config_import.lib.php3 b/libraries/config_import.lib.php3 index 3a512445f..f43cdccd7 100644 --- a/libraries/config_import.lib.php3 +++ b/libraries/config_import.lib.php3 @@ -265,6 +265,14 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) { } } + if (!isset($cfg['LeftFrameTableSeparator'])) { + $cfg['LeftFrameTableSeparator'] = '__'; + } + + if (!isset($cfg['LeftFrameTableLevel'])) { + $cfg['LeftFrameTableLevel'] = '1'; + } + if (!isset($cfg['LightTabs'])) { $cfg['LightTabs'] = FALSE; }