From 4d878ae9419cd24cc8701909cb93f51802dc8017 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 27 Feb 2003 13:01:08 +0000 Subject: [PATCH] See Changelog: Lightweight tabs, DB-based SQL history, tabbed querywindow. Have fun, surely needs some debugging. :) --- ChangeLog | 7 +++ config.inc.php3 | 17 +++-- db_details_links.php3 | 20 ++++-- index.php3 | 7 +++ libraries/common.lib.php3 | 41 +++++++----- libraries/config_import.lib.php3 | 36 +++++++++++ libraries/relation.lib.php3 | 91 ++++++++++++++++++++++++++- querywindow.php3 | 104 +++++++++++++++++++++++++------ tbl_properties_links.php3 | 24 ++++--- tbl_query_box.php3 | 97 ++++++++++++++++++---------- 10 files changed, 356 insertions(+), 88 deletions(-) diff --git a/ChangeLog b/ChangeLog index 692253858..0af409091 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,13 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-02-27 Garvin Hicking + * libraries/common.lib.php3, tbl_properties_links.php3, db_details_links.php3, + querywindow.php3: Integrated Manuzhais patch for Lightweight Tabs. + * querywindow.php3, tbl_query_box.php3, config.inc.php3, header.inc.php3, index.php3, + libraries/config_import.lib.php3: Added (optional) DB-based SQL-history with + purging on login, made querywindow tabbed, improved Querywindow-compatibility. + 2003-02-26 Garvin Hicking * lang/german-*: better grammar. ;) * libraries/display_tbl.lib.php3: Fixed transformation-link variable diff --git a/config.inc.php3 b/config.inc.php3 index a3de2e5d0..89f3d802d 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -183,6 +183,7 @@ $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['LightTabs'] = FALSE; // use lightweight, graphically less intense menu-tabs $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 @@ -373,8 +374,8 @@ $cfg['ModifyDeleteAtRight'] = FALSE; // show edit/delete links on right s // (or at the bottom with vertical browse) $cfg['DefaultDisplay'] = 'horizontal'; // default display direction // (horizontal|vertical|horizontalflipped) -$cfg['HeaderFlipType'] = 'css'; // table-header rotation via faking or css? (css|fake) -$cfg['ShowBrowseComments'] = TRUE; // shows stored relation-comments in 'browse' mode. +$cfg['HeaderFlipType'] = 'css'; // table-header rotation via faking or css? (css|fake) +$cfg['ShowBrowseComments'] = TRUE; // shows stored relation-comments in 'browse' mode. $cfg['ShowPropertyComments']= TRUE; // shows stored relation-comments in 'table property' mode. $cfg['RepeatCells'] = 100; // repeat header names every X cells? (0 = deactivate) @@ -382,9 +383,15 @@ $cfg['QueryFrame'] = TRUE; // displays a new frame where a link $cfg['QueryFrameJS'] = TRUE; // whether to use JavaScript functions for opening a new window for SQL commands. // if set to 'false', the target of the querybox is always the right frame. $cfg['QueryFrameDebug'] = FALSE; // display JS debugging link (DEVELOPERS only) -$cfg['QueryWindowWidth'] = 750; // Width of Query window -$cfg['QueryWindowHeight'] = 300; // Height of Query window - +$cfg['QueryWindowWidth'] = 750; // Width of Query window +$cfg['QueryWindowHeight'] = 300; // Height of Query window +$cfg['QueryHistoryDB'] = FALSE; // Set to TRUE if you want DB-based query history. + // If FALSE, this utilizes JS-routines to display + // query history (lost by window close) +$cfg['QueryWindowDefTab'] = 'sql'; // which tab to display in the querywindow on startup + // (sql|files|history|full) +$cfg['QueryHistoryMax'] = 25; // When using DB-based query history, how many entries + // should be kept? $cfg['BrowseMIME'] = TRUE; // Use MIME-Types (stored in column comments table) for /** diff --git a/db_details_links.php3 b/db_details_links.php3 index 802cfaa9f..008bd0ac7 100644 --- a/db_details_links.php3 +++ b/db_details_links.php3 @@ -58,11 +58,15 @@ else { /** * Displays tab links */ -?> - + +if ($cfg['LightTabs']) { + echo ' '; +} else { + echo '
- - '; +} + echo PMA_printTab($strStructure, 'db_details_structure.php3', $url_query); echo PMA_printTab($strSQL, 'db_details.php3', $url_query . '&db_query_force=1'); echo PMA_printTab($strExport, $lnk3, $arg3); @@ -79,8 +83,12 @@ if ($lnk5) { echo PMA_printTab($strDrop, $lnk5, $arg5, $att5); } // end if echo "\n"; + +if (!$cfg['LightTabs']) { + echo '
 
'; +} else { + echo '
'; +} ?> - -
diff --git a/index.php3 b/index.php3 index 1888d067e..3b4877b7a 100755 --- a/index.php3 +++ b/index.php3 @@ -41,6 +41,13 @@ if (isset($lightm_db)) { $url_query = PMA_generate_common_url(isset($db) ? $db : ''); header('Content-Type: text/html; charset=' . $GLOBALS['charset']); + +require('./libraries/relation.lib.php3'); +$cfgRelation = PMA_getRelationsParam(); + +if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) { + PMA_purgeHistory($cfg['Server']['user']); +} ?> diff --git a/libraries/common.lib.php3 b/libraries/common.lib.php3 index 5a7847d8a..8e4051f43 100644 --- a/libraries/common.lib.php3 +++ b/libraries/common.lib.php3 @@ -1542,16 +1542,18 @@ if (typeof(document.getElementById) != 'undefined' * @param string main link file, e.g. "test.php3" * @param string link arguments * @param string link attributes + * @param string include '?' even though no attributes are set. Can be set empty, should be '?'. + * @param boolean force display TAB as active * * @return string two table cells, the first beeing a separator, the second the tab itself * * @access public */ - function PMA_printTab($text, $link, $args = '', $attr = '') { - global $PHP_SELF; + function PMA_printTab($text, $link, $args = '', $attr = '', $sep = '?', $active = false) { + global $PHP_SELF, $cfg; global $db_details_links_count_tabs; - if (basename($PHP_SELF) == $link + if ((basename($PHP_SELF) == $link || $active) && ($text != $GLOBALS['strEmpty'] && $text != $GLOBALS['strDrop'])) { $bgcolor = 'silver'; } else { @@ -1563,19 +1565,30 @@ if (typeof(document.getElementById) != 'undefined' $attr = ' ' . $attr; } - $out = "\n" . ' ' - . '' - . "\n" . ' '; - if (strlen($link) > 0) { - $out .= '' - . '' . $text . ''; + if ($cfg['LightTabs']) { + $out = ''; + if (strlen($link) > 0) { + $out .= '' + . '' . $text . ''; + } else { + $out .= '' . $text . ''; + } + $out = '[ ' . $out . ' ]   '; } else { - $out .= '' . $text . ''; + $out = "\n" . ' ' + . '' + . "\n" . ' '; + if (strlen($link) > 0) { + $out .= '' + . '' . $text . ''; + } else { + $out .= '' . $text . ''; + } + $out .= "\n" . ' ' + . '' + . "\n" . ' ' + . ' '; } - $out .= "\n" . ' ' - . '' - . "\n" . ' ' - . ' '; return $out; } // end of the 'PMA_printTab()' function diff --git a/libraries/config_import.lib.php3 b/libraries/config_import.lib.php3 index 07b949d23..a7d136209 100644 --- a/libraries/config_import.lib.php3 +++ b/libraries/config_import.lib.php3 @@ -228,6 +228,15 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) { $cfg['LeftFrameLight'] = TRUE; } } + + if (!isset($cfg['LightTabs'])) { + if (isset($cfgLightTabs)) { + $cfg['LightTabs'] = $cfgLightTabs; + unset($cfgLightTabs); + } else { + $cfg['LightTabs'] = FALSE; + } + } if (!isset($cfg['ShowTooltip'])) { if (isset($cfgShowTooltip)) { @@ -698,6 +707,33 @@ if (!defined('PMA_CONFIG_IMPORT_LIB_INCLUDED')) { } } + if (!isset($cfg['QueryHistoryMax'])) { + if (isset($cfgQueryHistoryMax)) { + $cfg['QueryHistoryMax'] = $cfgQueryHistoryMax; + unset($cfgQueryHistoryMax); + } else { + $cfg['QueryHistoryMax'] = 25; + } + } + + if (!isset($cfg['QueryHistoryDB'])) { + if (isset($cfgQueryHistoryDB)) { + $cfg['QueryHistoryDB'] = $cfgQueryHistoryDB; + unset($cfgQueryHistoryDB); + } else { + $cfg['QueryHistoryDB'] = FALSE; + } + } + + if (!isset($cfg['QueryWindowDefTab'])) { + if (isset($cfgQueryWindowDefTab)) { + $cfg['QueryWindowDefTab'] = $cfgQueryWindowDefTab; + unset($cfgQueryWindowDefTab); + } else { + $cfg['QueryWindowDefTab'] = 'sql'; + } + } + if (!isset($cfg['BrowseMIME'])) { if (isset($cfgBrowseMIME)) { $cfg['BrowseMIME'] = $cfgBrowseMIME; diff --git a/libraries/relation.lib.php3 b/libraries/relation.lib.php3 index 414e81864..22373ee5a 100644 --- a/libraries/relation.lib.php3 +++ b/libraries/relation.lib.php3 @@ -364,7 +364,7 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){ $col = ($table != '' ? $row['column_name'] : $i); if (strlen($row['comment']) > 0) { - $comment[$col] = $row['comment']; + $comment[$col] = $row['comment']; } } // end while @@ -395,8 +395,8 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){ * @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 + * @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. * @@ -455,5 +455,90 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){ return false; } } // end of 'PMA_setComment()' function + +/** + * Set a SQL history entry + * + * @param string the name of the db + * @param string the name of the table + * @param string the username + * @param string the sql query + * + * @return boolean true + * + * @access public + */ + function PMA_setHistory($db, $table, $username, $sqlquery) { + global $cfgRelation; + + $hist_rs = PMA_query_as_cu('INSERT INTO ' . PMA_backquote($cfgRelation['history']) . ' (' + . PMA_backquote('username') . ',' + . PMA_backquote('db') . ',' + . PMA_backquote('table') . ',' + . PMA_backquote('timevalue') . ',' + . PMA_backquote('sqlquery') + . ') VALUES (' + . '\'' . PMA_sqlAddslashes($username) . '\',' + . '\'' . PMA_sqlAddslashes($db) . '\',' + . '\'' . PMA_sqlAddslashes($table) . '\',' + . 'NOW(),' + . '\'' . PMA_handleSlashes($sqlquery) . '\')'); + return true; + } // end of 'PMA_setHistory()' function + +/** + * Gets a SQL history entry + * + * @param string the username + * + * @return array list of history items + * + * @access public + */ + function PMA_getHistory($username) { + global $cfgRelation; + + $hist_rs = PMA_query_as_cu('SELECT ' + . PMA_backquote('db') . ',' + . PMA_backquote('table') . ',' + . PMA_backquote('sqlquery') + . ' FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE username = \'' . PMA_handleSlashes($username) . '\' ORDER BY timevalue DESC'); + + $history = array(); + + while ($row = @PMA_mysql_fetch_array($hist_rs)) { + $history[] = $row; + } + + return $history; + + } // end of 'PMA_getHistory()' function + +/** + * Set a SQL history entry + * + * @param string the name of the db + * @param string the name of the table + * @param string the username + * @param string the sql query + * + * @return boolean true + * + * @access public + */ + function PMA_purgeHistory($username) { + global $cfgRelation, $cfg; + + $purge_rs = PMA_query_as_cu('SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE username = \'' . PMA_handleSlashes($username) . '\' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1'); + $i = 0; + $row = @PMA_mysql_fetch_array($purge_rs); + + if (is_array($row) && $row[0] > 0) { + $maxtime = $row[0]; + $remove_rs = PMA_query_as_cu('DELETE FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE timevalue <= ' . $maxtime); + } + + return true; + } // end of 'PMA_purgeHistory()' function } // $__PMA_RELATION_LIB__ ?> diff --git a/querywindow.php3 b/querywindow.php3 index f8abf6820..6ec71ccad 100644 --- a/querywindow.php3 +++ b/querywindow.php3 @@ -52,7 +52,6 @@ header('Pragma: no-cache'); // HTTP/1.0 // Define the charset to be used header('Content-Type: text/html; charset=' . $charset); - /** * Displays the frame */ @@ -77,6 +76,21 @@ PMA_setFontSizes(); .child {font-family: ; font-size: ; color: #333399; text-decoration: none} .item, .item:active, .item:hover, .tblItem, .tblItem:active {font-size: ; color: #333399; text-decoration: none} .tblItem:hover {color: #FF0000; text-decoration: underline} + td.tab { + border-top: 1px solid #999; + border-right: 1px solid #666; + border-left: 1px solid #999; + border-bottom: none; + border-radius: 2px; + -moz-border-radius: 2px; + } + table.tabs { + border-top: none; + border-right: none; + border-left: none; + border-bottom: 1px solid #666; + } + //--> @@ -105,6 +119,12 @@ function query_auto_commit() { document.sqlform.submit(); } +function query_tab_commit(tab) { + document.querywindow.querydisplay_tab.value = tab; + document.querywindow.submit(); + return false; +} + // js form validation stuff var errorMsg0 = ''; var errorMsg1 = ''; @@ -118,6 +138,31 @@ var confirmMsg = '"> + + +  '; +} +echo "\n"; +echo PMA_printTab($strSQL, '#', '', 'onClick="javascript:query_tab_commit(\'sql\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'sql' ? TRUE : FALSE)); +echo PMA_printTab($strImportFiles, '#', '', 'onClick="javascript:query_tab_commit(\'files\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'files' ? TRUE : FALSE)); +echo PMA_printTab($strQuerySQLHistory, '#', '', 'onClick="javascript:query_tab_commit(\'history\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'history' ? TRUE : FALSE)); +echo PMA_printTab($strAll, '#', '', 'onClick="javascript:query_tab_commit(\'full\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'full' ? TRUE : FALSE)); + +if (!$cfg['LightTabs']) { + echo ''; +} else { + echo '
'; +} + +?> +
+ '; $input_query_history[] = ''; $input_query_history[] = ''; - $sql_history[] = '
  • [' . htmlspecialchars($query_history_latest_db) . '] ' . urldecode($query_history_latest) . '
  • ' . "\n"; + $sql_history[] = '
  • [' . htmlspecialchars($query_history_latest_db) . '] ' . urldecode($query_history_latest) . '
  • ' . "\n"; $sql_query = urldecode($query_history_latest); $db = $query_history_latest_db; @@ -140,21 +189,38 @@ if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) { $dup_sql[$query_history_latest] = true; } - if (isset($query_history) && is_array($query_history)) { - $current_index = count($query_history); - @reset($query_history); - while(list($query_no, $query_sql) = each($query_history)) { - if (!isset($dup_sql[$query_sql])) { + if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) { - $input_query_history[] = ''; - $input_query_history[] = ''; - $input_query_history[] = ''; - - $sql_history[] = '
  • [' . htmlspecialchars($query_history_db[$query_no]) . '] ' . urldecode($query_sql) . '
  • ' . "\n"; - $dup_sql[$query_sql] = true; + $temp_history = PMA_getHistory($cfg['Server']['user']); + if (is_array($temp_history) && count($temp_history) > 0) { + @reset($temp_history); + while(@list($history_nr, $history_array) = @each($temp_history)) { + if (!isset($dup_sql[$history_array['sqlquery']])) { + $sql_history[] = '
  • [' . htmlspecialchars($history_array['db']) . '] ' . urldecode($history_array['sqlquery']) . '
  • ' . "\n"; + $dup_sql[$history_array['sqlquery']] = true; + } } } - } + + } else { + + if (isset($query_history) && is_array($query_history)) { + $current_index = count($query_history); + @reset($query_history); + while(list($query_no, $query_sql) = each($query_history)) { + if (!isset($dup_sql[$query_sql])) { + + $input_query_history[] = ''; + $input_query_history[] = ''; + $input_query_history[] = ''; + + $sql_history[] = '
  • [' . htmlspecialchars($query_history_db[$query_no]) . '] ' . urldecode($query_sql) . '
  • ' . "\n"; + $dup_sql[$query_sql] = true; + } // end if check if this item exists + } // end while print history + } // end if history exists + + } // end if DB-based history } $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : ''); @@ -163,6 +229,7 @@ if (!isset($goto)) { } require './libraries/bookmark.lib.php3'; +$is_inside_querywindow = TRUE; require './tbl_query_box.php3'; // Hidden forms and query frame interaction stuff @@ -175,10 +242,10 @@ if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) { 0) { + if (isset($sql_history) && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full') && is_array($sql_history) && count($sql_history) > 0) { ?>
  • -
      ' . implode('', $sql_history) . '
    '; ?>
    +
      ' . implode('', $sql_history) . '
    '; ?>
  • - - + + @@ -200,6 +267,7 @@ if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) { + - + +if ($cfg['LightTabs']) { + echo ' '; +} else { + echo '
    - - '; +} + echo PMA_printTab($strStructure, 'tbl_properties_structure.php3', $url_query); echo PMA_printTab($strBrowse, $lnk2, $arg2); echo PMA_printTab($strSQL, 'tbl_properties.php3', $url_query); @@ -72,8 +76,12 @@ if (PMA_MYSQL_INT_VERSION >= 32322) { echo PMA_printTab($strEmpty, $lnk6, $arg6, $att6); echo PMA_printTab($strDrop, 'sql.php3', $arg7, $att7); echo "\n"; -?> - -
     
    -
    + +if (!$cfg['LightTabs']) { + echo ''; +} else { + echo '
    '; +} + +?>
    diff --git a/tbl_query_box.php3 b/tbl_query_box.php3 index e9e25d7a7..c9b6084e0 100755 --- a/tbl_query_box.php3 +++ b/tbl_query_box.php3 @@ -81,9 +81,6 @@ if ($cfg['QueryFrame'] && (!$cfg['QueryFrameJS'] || ($cfg['QueryFrameJS'] && !$d } ?> - -
  • -
    onsubmit="return checkSqlQuery(this)" name="sqlform"> @@ -92,14 +89,22 @@ if ($cfg['QueryFrame'] && (!$cfg['QueryFrameJS'] || ($cfg['QueryFrameJS'] && !$d + + + +
  • + @@ -112,9 +117,17 @@ for ($i = 0 ; $i < $fields_cnt; $i++) {
    + + +' . $strOr . ' ' . $strLocationTextfile . ' :
    ' . "\n"; +if ($is_upload && (!isset($is_inside_querywindow) || + (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'full')))) { + echo ' ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') || !isset($is_inside_querywindow) ? '' . $strOr . '' : '') . ' ' . $strLocationTextfile . ' :
    ' . "\n"; ?>

    @@ -166,37 +179,53 @@ if (function_exists('PMA_set_enc_form')) { } // Bookmark Support -if ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table']) { - if (($bookmark_list = PMA_listBookmarks($db, $cfg['Bookmark'])) && count($bookmark_list) > 0) { - echo " $strOr $strBookmarkQuery :
    \n"; - echo '
    ' . "\n"; - echo ' ' . "\n"; + echo ' ' . "\n"; + while (list($key, $value) = each($bookmark_list)) { + echo ' ' . "\n"; + } + echo ' ' . "\n"; + echo ' ' . "\n"; + echo '  ' . "\n"; + echo '  ' . "\n"; + echo '
    ' . "\n"; + echo '
    ' . "\n"; + $bookmark_go = TRUE; } - echo ' ' . "\n"; - echo ' ' . "\n"; - echo '  ' . "\n"; - echo '  ' . "\n"; - echo '
    ' . "\n"; - echo '
    ' . "\n"; } } + +if (!isset($is_inside_querywindow) || (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' || $querydisplay_tab == 'sql' || $querydisplay_tab == 'full' || ($querydisplay_tab == 'history' && $bookmark_go)))) { ?> -
  • - - -
  • -
    -
  • - + +

    +
  • +
    >
    +
  • + + \ No newline at end of file