From 820ad9c0cd54dd9076a573a0476acdbb4113d4a1 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Mon, 24 Feb 2003 16:39:15 +0000 Subject: [PATCH] Display and enter DB/table comments for navigation, stored in pma comments table. May be displayed as Alias-Tooltips in left frame. [#650064] --- db_details_structure.php3 | 77 ++++++++++++++++++++++++++++- left.php3 | 67 +++++++++++++++++++------ libraries/relation.lib.php3 | 98 ++++++++++++++++++++++++++++++++++++- 3 files changed, 224 insertions(+), 18 deletions(-) diff --git a/db_details_structure.php3 b/db_details_structure.php3 index a0bf159dd..76a9af658 100644 --- a/db_details_structure.php3 +++ b/db_details_structure.php3 @@ -31,7 +31,12 @@ if (empty($is_info)) { require('./libraries/relation.lib.php3'); $cfgRelation = PMA_getRelationsParam(); - +/** + * Check if comments were updated + */ +if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') { + PMA_SetComment($db, '', '(db_comment)', $comment); +} /** * Displays the tables list @@ -48,6 +53,34 @@ if ($num_tables == 0) { // 2. Shows table informations on mysql >= 3.23.03 - staybyte - 11 June 2001 else if (PMA_MYSQL_INT_VERSION >= 32303) { + + // Get additional information about tables for tooltip + if ($cfg['ShowTooltip']) { + $tooltip_truename = array(); + $tooltip_aliasname = array(); + + $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); + while ($tmp = PMA_mysql_fetch_array($result)) { + $tooltip_truename[$tmp['Name']] = ($cfg['ShowTooltipAliasTB'] ? (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') : $tmp['Name']); + $tooltip_aliasname[$tmp['Name']] = ($cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '')); + } // end while + } // end if + + if ($cfgRelation['commwork']) { + $comment = PMA_getComments($db); + + /** + * Displays table comment + */ + if (is_array($comment)) { + ?> + +

+ +

+
@@ -75,6 +108,13 @@ else if (PMA_MYSQL_INT_VERSION >= 32303) { $table_encoded = urlencode($table); $table_name = htmlspecialchars($table); + $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$table])) + ? str_replace('"', '"', $tooltip_aliasname[$table]) + : htmlspecialchars($sts_data['Name']); + $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$table])) + ? str_replace('"', '"', $tooltip_truename[$table]) + : htmlspecialchars($sts_data['Name']); + // Sets parameters for links $tbl_url_query = $url_query . '&table=' . $table_encoded; $bgcolor = ($i++ % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; @@ -85,7 +125,7 @@ else if (PMA_MYSQL_INT_VERSION >= 32303) { /> -     +     = 32303) { // 3. Shows tables list mysql < 3.23.03 else { + if ($cfgRelation['commwork']) { + $comment = PMA_getComments($db); + + /** + * Displays table comment + */ + if (is_array($comment)) { + ?> + +

+ +

+ @@ -428,6 +484,23 @@ if ($num_tables > 0) { + + + +
  • + + + + + + +
  • + + diff --git a/left.php3 b/left.php3 index a6c7ea110..6186c6eff 100755 --- a/left.php3 +++ b/left.php3 @@ -25,6 +25,8 @@ if ($cfg['OBGzip']) { } } +require('./libraries/relation.lib.php3'); +$cfgRelation = PMA_getRelationsParam(); /** * Get the list and number of available databases. @@ -224,18 +226,31 @@ if ($num_dbs > 1) { $num_tables_disp = '-'; } - // Get additional infomation about tables for tooltip + // Get additional information about tables for tooltip if ($cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303 && $num_tables && (!$cfg['LeftFrameLight'] || $selected_db == $j)) { $tooltip = array(); + $tooltip_name = array(); $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); while ($tmp = PMA_mysql_fetch_array($result)) { + $tooltip_name[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : ''); + $tmp['Comment'] = ($cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment']); + $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')'; } // end while } // end if + // garvin: Get comments from PMA comments table + $db_tooltip = ''; + if ($cfg['ShowTooltip'] && $cfgRelation['commwork']) { + $tmp_db_tooltip = PMA_getComments($db); + if (is_array($tmp_db_tooltip)) { + $db_tooltip = implode(' ', $tmp_db_tooltip); + } + } + // No light mode -> displays the expandible/collapsible db list if ($cfg['LeftFrameLight'] == FALSE) { @@ -259,8 +274,8 @@ if ($num_dbs > 1) { } echo "\n"; ?> - -   () + + ' . htmlspecialchars($db_tooltip) . '' : htmlspecialchars($db)); ?>  ()
    > @@ -269,16 +284,20 @@ if ($num_dbs > 1) { // Displays the list of tables from the current database for ($t = 0; $t < $num_tables; $t++) { $table = PMA_mysql_tablename($tables, $t); + $alias = (!empty($tooltip_name) && isset($tooltip_name[$table])) + ? htmlspecialchars($tooltip_name[$table]) + : ''; $url_title = (!empty($tooltip) && isset($tooltip[$table])) ? htmlspecialchars($tooltip[$table]) : ''; + echo "\n"; ?> - - <?php echo $strBrowse . ': ' . htmlspecialchars($table); ?>  + + <?php echo $strBrowse . ': ' . $url_title; ?>  -
    +
    1) { $url_title = (!empty($tooltip) && isset($tooltip[$table])) ? str_replace('"', '"', $tooltip[$table]) : ''; + $alias = (!empty($tooltip_name) && isset($tooltip_name[$table])) + ? str_replace('"', '"', $tooltip_name[$table]) + : ''; + $table_list .= ' ' . "\n"; - $table_list .= ' ' . $strBrowse . ': ' . $table . ' ' . "\n"; + $table_list .= ' ' . $strBrowse . ': ' . $url_title . ' ' . "\n"; if (PMA_USR_BROWSER_AGENT == 'IE') { - $table_list .= ' ' . htmlspecialchars($table) . '
    ' . "\n"; + $table_list .= ' ' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
    ' . "\n"; } else { - $table_list .= ' ' . htmlspecialchars($table) . '
    ' . "\n"; + $table_list .= ' ' . ($alias != '' && $cfg['ShowTooltipAliasTB'] ? $alias : htmlspecialchars($table)) . '
    ' . "\n"; } } // end for $t (tables list) @@ -318,15 +341,15 @@ if ($num_dbs > 1) { $selected = ' selected="selected"'; $table_list_header .= ' ' . "\n"; - $table_list_header .= ' ' . htmlspecialchars($db) . '  
    ' . "\n\n"; + $table_list_header .= ' ' . ($db_tooltip != '' && $cfg['ShowTooltipAliasTB'] ? htmlspecialchars($db_tooltip) : htmlspecialchars($db)) . '  
    ' . "\n\n"; } else { $selected = ''; } // end if... else... if (!empty($num_tables)) { - echo ' ' . "\n"; + echo ' ' . "\n"; } else { - echo ' ' . "\n"; + echo ' ' . "\n"; } // end if... else... } // end if (light mode) @@ -392,25 +415,41 @@ else if ($num_dbs == 1) { if ($cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303 && $num_tables) { $tooltip = array(); + $tooltip_name = array(); $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); while ($tmp = PMA_mysql_fetch_array($result)) { + $tooltip_name[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : ''); + $tmp['Comment'] = ($cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment']); + $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')'; } // end while } // end if + // garvin: Get comments from PMA comments table + $db_tooltip = ''; + if ($cfg['ShowTooltip'] && $cfgRelation['commwork']) { + $tmp_db_tooltip = PMA_getComments($db); + if (is_array($tmp_db_tooltip)) { + $db_tooltip = implode(' ', $tmp_db_tooltip); + } + } + // Displays the database name echo "\n"; ?>
    -   () +   ()
    <?php echo $strBrowse . ': ' . htmlspecialchars($table); ?>  -
    +
    */ - function PMA_getComments($db, $table) { + function PMA_getComments($db, $table = '') { global $cfgRelation; + if ($table != '') { $com_qry = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_comments']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; $com_rs = PMA_query_as_cu($com_qry); + } else { + $com_qry = 'SELECT comment FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'\'' + . ' AND column_name = \'(db_comment)\''; + $com_rs = PMA_query_as_cu($com_qry); + } + $i = 0; while ($row = @PMA_mysql_fetch_array($com_rs)) { - $col = $row['column_name']; + $i++; + $col = ($table != '' ? $row['column_name'] : $i); + + if (strlen($row['comment']) > 0) { $comment[$col] = $row['comment']; + } + } // end while if (isset($comment) && is_array($comment)) { @@ -313,5 +327,85 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){ return FALSE; } } // end of the 'PMA_getComments()' function + + /** + * Adds/removes slashes if required + * + * @param string the string to slash + * + * @return string the slashed string + * + * @access public + */ + function PMA_handleSlashes($val) { + return (get_magic_quotes_gpc() ? str_replace('\\"', '"', $val) : PMA_sqlAddslashes($val)); + } // end of the "PMA_handleSlashes()" function + + /** + * Set a single comment to a certain value. + * + * @param string the name of the db + * @param string the name of the table + * @param string the name of the column + * @param string the value of the column + * @param string (optional) if a column is renamed, this is the name of the former key which will get deleted + * + * @return boolean true, if comment-query was made. + * + * @global array the list of relations settings + * + * @access public + */ + function PMA_setComment($db, $table, $key, $value, $removekey = '') { + global $cfgRelation; + + if ($removekey != '' AND $removekey != $key) { + $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' + . ' AND column_name = \'' . PMA_handleSlashes($removekey) . '\''; + $rmv_rs = PMA_query_as_cu($remove_query); + unset($rmv_query); + } + + $test_qry = 'SELECT ' . PMA_backquote('comment') . ', mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' + . ' AND column_name = \'' . PMA_handleSlashes($key) . '\''; + $test_rs = PMA_query_as_cu($test_qry); + + if ($test_rs && mysql_num_rows($test_rs) > 0) { + $row = @PMA_mysql_fetch_array($test_rs); + + if (strlen($value) > 0 || strlen($row['mimetype']) > 0 || strlen($row['transformation']) > 0 || strlen($row['transformation_options']) > 0) { + $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_comments']) + . ' SET ' . PMA_backquote('comment') . ' = \'' . PMA_handleSlashes($value) . '\'' + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' + . ' AND column_name = \'' . PMA_handleSlashes($key) . '\''; + } else { + $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_comments']) + . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' + . ' AND table_name = \'' . PMA_sqlAddslashes($table) . '\'' + . ' AND column_name = \'' . PMA_handleSlashes($key) . '\''; + } + } else if (strlen($value) > 0) { + $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_comments']) + . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') ' + . ' VALUES(' + . '\'' . PMA_sqlAddslashes($db) . '\',' + . '\'' . PMA_sqlAddslashes($table) . '\',' + . '\'' . PMA_handleSlashes($key) . '\',' + . '\'' . PMA_handleSlashes($value) . '\')'; + } + + if (isset($upd_query)){ + $upd_rs = PMA_query_as_cu($upd_query); + unset($upd_query); + return true; + } else { + return false; + } + } // end of 'PMA_setComment()' function } // $__PMA_RELATION_LIB__ ?>