From 175ffa5c4ea914bcffcf139902857b8d35ded5f6 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sun, 1 May 2011 22:58:47 +0700 Subject: [PATCH 01/80] Recently used tables (simple version, only works with LeftDefaultTablTable=tbl_structure.php) --- libraries/common.lib.php | 18 ++++++++++++++++++ navigation.php | 19 +++++++++++++++++++ tbl_structure.php | 1 + 3 files changed, 38 insertions(+) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 8be5c0e7e4..df434ea06a 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -3023,4 +3023,22 @@ function PMA_buildActionTitles() { $titles['Edit'] = PMA_getIcon('b_edit.png', __('Edit'), true); return $titles; } + +/** + * Add recently used tables + */ +function PMA_addRecentTable($table, $db) { + if (isset($_SESSION['tmp_user_values']['recent_tables'])) { + array_unshift($_SESSION['tmp_user_values']['recent_tables'], $db . '.' . $table); + $_SESSION['tmp_user_values']['recent_tables'] = array_unique($_SESSION['tmp_user_values']['recent_tables']); + while (count($_SESSION['tmp_user_values']['recent_tables']) > 5) { + array_pop($_SESSION['tmp_user_values']['recent_tables']); + } + } else { + $_SESSION['tmp_user_values']['recent_tables'] = array(); + array_unshift($_SESSION['tmp_user_values']['recent_tables'], $db . '.' . $table); + } + $GLOBALS['reload'] = true; + PMA_reloadNavigation(); +} ?> diff --git a/navigation.php b/navigation.php index 167c060d3d..47bcf1d597 100644 --- a/navigation.php +++ b/navigation.php @@ -179,6 +179,25 @@ require_once './libraries/header_http.inc.php'; +
+ +
+' . "\n"; +PMA_addRecentTable($table, $db); /** * Displays the footer From 4b7e65e6107706b9d9ea9b671f509935ed49f3f0 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 2 May 2011 10:09:05 +0700 Subject: [PATCH 02/80] Recently used tables (works, but only in temporary session variable) --- libraries/header.inc.php | 3 +++ tbl_structure.php | 1 - themes/original/css/theme_left.css.php | 10 ++++++++++ themes/pmahomme/css/theme_left.css.php | 12 +++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 807ec0af20..9e37e32033 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -151,6 +151,9 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { .'"' . htmlspecialchars($show_comment) .'"' . "\n"; } // end if + + // remember accessed table + PMA_addRecentTable($table, $db); } else { // no table selected, display database comment if present /** diff --git a/tbl_structure.php b/tbl_structure.php index 6286287a1f..73374d7a5e 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -934,7 +934,6 @@ if ($cfg['ShowStats']) { require './libraries/tbl_triggers.lib.php'; echo '
' . "\n"; -PMA_addRecentTable($table, $db); /** * Displays the footer diff --git a/themes/original/css/theme_left.css.php b/themes/original/css/theme_left.css.php index 50ffc3984e..f21bca27f0 100644 --- a/themes/original/css/theme_left.css.php +++ b/themes/original/css/theme_left.css.php @@ -83,6 +83,16 @@ div#pmalogo { background-color: ; padding:.3em; } + +div#recentTableList { + text-align: center; + margin-bottom: 0.5em; +} + +div#recentTableList select { + width: 100%; +} + div#pmalogo, div#leftframelinks, div#databaseList { diff --git a/themes/pmahomme/css/theme_left.css.php b/themes/pmahomme/css/theme_left.css.php index 467e70a255..e0a6393c5e 100644 --- a/themes/pmahomme/css/theme_left.css.php +++ b/themes/pmahomme/css/theme_left.css.php @@ -94,11 +94,21 @@ button { div#pmalogo { } + +div#recentTableList { + text-align: center; + margin: 20px 10px 0px 10px; +} + +div#recentTableList select { + width: 100%; +} + div#pmalogo, div#leftframelinks, div#databaseList { text-align: center; - margin: 20px 10px 0px 10px; + margin: 5px 10px 0px 10px; } ul#databaseList { From 21bceed4148081c50f0b2b03126717d41b65f10a Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sat, 7 May 2011 14:52:07 +0700 Subject: [PATCH 03/80] Recently used tables (now with configuration) --- libraries/common.lib.php | 33 ++++++++++++++------- libraries/config.default.php | 7 +++++ libraries/config/setup.forms.php | 3 +- libraries/config/user_preferences.forms.php | 3 +- libraries/header.inc.php | 2 +- navigation.php | 15 ++++++---- 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index df434ea06a..ca4eebefcd 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -3025,18 +3025,31 @@ function PMA_buildActionTitles() { } /** - * Add recently used tables + * Trim recent table according to the LeftRecentTable configuration */ -function PMA_addRecentTable($table, $db) { - if (isset($_SESSION['tmp_user_values']['recent_tables'])) { - array_unshift($_SESSION['tmp_user_values']['recent_tables'], $db . '.' . $table); - $_SESSION['tmp_user_values']['recent_tables'] = array_unique($_SESSION['tmp_user_values']['recent_tables']); - while (count($_SESSION['tmp_user_values']['recent_tables']) > 5) { - array_pop($_SESSION['tmp_user_values']['recent_tables']); - } +function PMA_trimRecentTable() { + while (count($_SESSION['tmp_user_values']['recent_tables']) > $GLOBALS['cfg']['LeftRecentTable']) { + array_pop($_SESSION['tmp_user_values']['recent_tables']); + } +} + +/** + * Add recently used tables + * + * @param string $db Database name where the table is located + * @param string $table Table name + * + * @uses PMA_trimRecentTable() + */ +function PMA_addRecentTable($db, $table) { + $recent_tables =& $_SESSION['tmp_user_values']['recent_tables']; + if (isset($recent_tables)) { + array_unshift($recent_tables, $db . '.' . $table); + $recent_tables = array_unique($recent_tables); + PMA_trimRecentTable(); } else { - $_SESSION['tmp_user_values']['recent_tables'] = array(); - array_unshift($_SESSION['tmp_user_values']['recent_tables'], $db . '.' . $table); + $recent_tables = array(); + array_unshift($recent_tables, $db . '.' . $table); } $GLOBALS['reload'] = true; PMA_reloadNavigation(); diff --git a/libraries/config.default.php b/libraries/config.default.php index 4ca31e78f5..9111aec89d 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -794,6 +794,13 @@ $cfg['LeftLogoLink'] = 'main.php'; */ $cfg['LeftLogoLinkWindow'] = 'main'; +/** + * number of recently used tables displayed in the navigation frame + * + * @global integer $cfg['LeftRecentTable'] + */ +$cfg['LeftRecentTable'] = 5; + /** * display a JavaScript table filter in the left frame * when more then x tables are present diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 5287aade93..acf477ea72 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -162,7 +162,8 @@ $forms['Left_frame']['Left_frame'] = array( 'LeftDisplayLogo', 'LeftLogoLink', 'LeftLogoLinkWindow', - 'LeftPointerEnable'); + 'LeftPointerEnable', + 'LeftRecentTable'); $forms['Left_frame']['Left_servers'] = array( 'LeftDisplayServers', 'DisplayServersList'); diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index d23eddafef..ffe036632f 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -77,7 +77,8 @@ $forms['Left_frame']['Left_frame'] = array( 'LeftDisplayLogo', 'LeftLogoLink', 'LeftLogoLinkWindow', - 'LeftPointerEnable'); + 'LeftPointerEnable', + 'LeftRecentTable'); $forms['Left_frame']['Left_databases'] = array( 'DisplayDatabasesList', 'LeftFrameDBTree', diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 9e37e32033..af9d4c6356 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -153,7 +153,7 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { } // end if // remember accessed table - PMA_addRecentTable($table, $db); + PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); } else { // no table selected, display database comment if present /** diff --git a/navigation.php b/navigation.php index 47bcf1d597..1c9bcd7cbb 100644 --- a/navigation.php +++ b/navigation.php @@ -180,19 +180,24 @@ require_once './libraries/header_http.inc.php';
- + ' . $table . ''; } ?> -
Date: Sun, 8 May 2011 02:42:38 +0700 Subject: [PATCH 04/80] Recently used tables (class, configuration, remember in pma database) --- config.sample.inc.php | 1 + libraries/RecentTable.class.php | 198 ++++++++++++++++++++++++++++++ libraries/common.lib.php | 31 ----- libraries/config.default.php | 7 ++ libraries/config/messages.inc.php | 2 + libraries/header.inc.php | 15 ++- libraries/relation.lib.php | 16 ++- navigation.php | 24 +--- 8 files changed, 237 insertions(+), 57 deletions(-) create mode 100644 libraries/RecentTable.class.php diff --git a/config.sample.inc.php b/config.sample.inc.php index 0ea16d5f76..95d3a1a911 100644 --- a/config.sample.inc.php +++ b/config.sample.inc.php @@ -52,6 +52,7 @@ $cfg['Servers'][$i]['AllowNoPassword'] = false; // $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages'; // $cfg['Servers'][$i]['column_info'] = 'pma_column_info'; // $cfg['Servers'][$i]['history'] = 'pma_history'; +// $cfg['Servers'][$i]['recent'] = 'pma_recent'; // $cfg['Servers'][$i]['tracking'] = 'pma_tracking'; // $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords'; // $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig'; diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php new file mode 100644 index 0000000000..12eb7f5112 --- /dev/null +++ b/libraries/RecentTable.class.php @@ -0,0 +1,198 @@ +pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) .".". + PMA_backquote($GLOBALS['cfg']['Server']['recent']); + } + if (!isset($_SESSION['tmp_user_values']['recent_tables'])) { + $_SESSION['tmp_user_values']['recent_tables'] = + isset($this->pma_table) ? $this->getFromDb() : array(); + } + $this->tables =& $_SESSION['tmp_user_values']['recent_tables']; + } + + /** + * Returns class instance. + * + * @return RecentTable + */ + public static function getInstance() + { + if (is_null(self::$_instance)) { + self::$_instance = new RecentTable(); + } + return self::$_instance; + } + + /** + * Returns recently used tables from phpMyAdmin database. + * + * @uses $pma_table + * @uses PMA_query_as_controluser() + * @uses PMA_DBI_fetch_array() + * @uses json_decode() + * + * @return array + */ + public function getFromDb() + { + // Read from phpMyAdmin database, if recent tables is not in session + $sql_query = + " SELECT `tables` FROM " . $this->pma_table . + " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'"; + + $row = PMA_DBI_fetch_array(PMA_query_as_controluser($sql_query)); + if (isset($row[0])) { + return json_decode($row[0]); + } else { + return array(); + } + } + + /** + * Save recent tables into phpMyAdmin database. + * + * @uses PMA_query_as_controluser() + * @uses PMA_DBI_fetch_value() + * @uses PMA_DBI_try_query() + * @uses json_decode() + * @uses PMA_Message + * + * @return true|PMA_Message + */ + public function saveToDb() + { + $username = $GLOBALS['cfg']['Server']['user']; + $sql_query = + " SELECT COUNT(*) FROM " . $this->pma_table . + " WHERE `username` = '" . $username . "'"; + + $exist = PMA_DBI_fetch_value(PMA_query_as_controluser($sql_query)); + if ($exist) { + $sql_query = + " UPDATE " . $this->pma_table . + " SET `tables` = '" . PMA_sqlAddslashes(json_encode($this->tables)) . "'" . + " WHERE `username` = '" . $username . "'"; + + $success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']); + } else { + $sql_query = + " INSERT INTO " . $this->pma_table . " (`username`, `tables`)" . + " VALUES ('" . $username . "', '" . PMA_sqlAddslashes(json_encode($this->tables)) . "')"; + + $success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']); + } + + if (!$success) { + $message = PMA_Message::error(__('Could not save configuration')); + $message->addMessage('

'); + $message->addMessage(PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink']))); + return $message; + } + return true; + } + + /** + * Trim recent table according to the LeftRecentTable configuration. + */ + public function trim() + { + while (count($this->tables) > $GLOBALS['cfg']['LeftRecentTable']) { + array_pop($this->tables); + } + } + + /** + * Return HTML code "select" for recently used tables. + * + * @return string + */ + public function getHtmlSelect() + { + $this->trim(); + + $html = ''; + + return $html; + } + + /** + * Add recently used tables. + * + * @param string $db Database name where the table is located + * @param string $table Table name + * + * @return true|PMA_Message True if success, PMA_Message if not + */ + public function add($db, $table) + { + $table_str = $db . '.' . $table; + + // add only if this is new table + if (!isset($this->tables[0]) || $this->tables[0] != $table_str) { + array_unshift($this->tables, $table_str); + $this->tables = array_unique($this->tables); + $this->trim(); + if (isset($this->pma_table)) { + return $this->saveToDb(); + } + } + return true; + } + +} +?> diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 4ff850b242..56618a180a 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -3023,35 +3023,4 @@ function PMA_buildActionTitles() { $titles['Edit'] = PMA_getIcon('b_edit.png', __('Edit'), true); return $titles; } - -/** - * Trim recent table according to the LeftRecentTable configuration - */ -function PMA_trimRecentTable() { - while (count($_SESSION['tmp_user_values']['recent_tables']) > $GLOBALS['cfg']['LeftRecentTable']) { - array_pop($_SESSION['tmp_user_values']['recent_tables']); - } -} - -/** - * Add recently used tables - * - * @param string $db Database name where the table is located - * @param string $table Table name - * - * @uses PMA_trimRecentTable() - */ -function PMA_addRecentTable($db, $table) { - $recent_tables =& $_SESSION['tmp_user_values']['recent_tables']; - if (isset($recent_tables)) { - array_unshift($recent_tables, $db . '.' . $table); - $recent_tables = array_unique($recent_tables); - PMA_trimRecentTable(); - } else { - $recent_tables = array(); - array_unshift($recent_tables, $db . '.' . $table); - } - $GLOBALS['reload'] = true; - PMA_reloadNavigation(); -} ?> diff --git a/libraries/config.default.php b/libraries/config.default.php index 9111aec89d..ae4018c5e2 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -338,6 +338,13 @@ $cfg['Servers'][$i]['history'] = ''; */ $cfg['Servers'][$i]['designer_coords'] = ''; +/** + * table to store recently used tables + * - leave blank for no "persistent" recently used tables + * SUGGESTED: 'pma_recent' + */ +$cfg['Servers'][$i]['recent'] = ''; + /** * table to store SQL tracking * - leave blank for no SQL tracking diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 9ebbfea8f6..47ccf7febf 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -282,6 +282,8 @@ $strConfigLeftLogoLinkWindow_desc = __('Open the linked page in the main window $strConfigLeftLogoLinkWindow_name = __('Logo link target'); $strConfigLeftPointerEnable_desc = __('Highlight server under the mouse cursor'); $strConfigLeftPointerEnable_name = __('Enable highlighting'); +$strConfigLeftRecentTable_desc = __('Maximum number of recently used tables; set 0 to disable'); +$strConfigLeftRecentTable_name = __('Recently used tables'); $strConfigLightTabs_desc = __('Use less graphically intense tabs'); $strConfigLightTabs_name = __('Light tabs'); $strConfigLimitChars_desc = __('Maximum number of characters shown in any non-numeric column on browse view'); diff --git a/libraries/header.inc.php b/libraries/header.inc.php index af9d4c6356..b581070e6c 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -8,10 +8,8 @@ if (! defined('PHPMYADMIN')) { exit; } -/** - * - */ require_once './libraries/common.inc.php'; +require_once './libraries/RecentTable.class.php'; /** @@ -152,8 +150,15 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { .'"' . "\n"; } // end if - // remember accessed table - PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); + // add recently used table and reload the navigation + $result = RecentTable::getInstance()->add($GLOBALS['db'], $GLOBALS['table']); + if ($result === true) { + $GLOBALS['reload'] = true; + PMA_reloadNavigation(); + } else { + $error = $result; + $error->display(); + } } else { // no table selected, display database comment if present /** diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 9588853f94..1236275dd9 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -138,6 +138,10 @@ function PMA_printRelationsParamDiagnostic($cfgRelation) PMA_printDiagMessageForFeature(__('Designer'), 'designerwork', $messages); + PMA_printDiagMessageForParameter('recent', isset($cfgRelation['recent']), $messages, 'recent'); + + PMA_printDiagMessageForFeature(__('Recently used tables'), 'recentwork', $messages); + PMA_printDiagMessageForParameter('tracking', isset($cfgRelation['tracking']), $messages, 'tracking'); PMA_printDiagMessageForFeature(__('Tracking'), 'trackingwork', $messages); @@ -220,6 +224,7 @@ function PMA__getRelationsParam() $cfgRelation['commwork'] = false; $cfgRelation['mimework'] = false; $cfgRelation['historywork'] = false; + $cfgRelation['recentwork'] = false; $cfgRelation['trackingwork'] = false; $cfgRelation['designerwork'] = false; $cfgRelation['userconfigwork'] = false; @@ -271,6 +276,8 @@ function PMA__getRelationsParam() $cfgRelation['pdf_pages'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['history']) { $cfgRelation['history'] = $curr_table[0]; + } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['recent']) { + $cfgRelation['recent'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['tracking']) { $cfgRelation['tracking'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['userconfig']) { @@ -325,6 +332,10 @@ function PMA__getRelationsParam() $cfgRelation['historywork'] = true; } + if (isset($cfgRelation['recent'])) { + $cfgRelation['recentwork'] = true; + } + if (isset($cfgRelation['tracking'])) { $cfgRelation['trackingwork'] = true; } @@ -346,8 +357,9 @@ function PMA__getRelationsParam() if ($cfgRelation['relwork'] && $cfgRelation['displaywork'] && $cfgRelation['pdfwork'] && $cfgRelation['commwork'] && $cfgRelation['mimework'] && $cfgRelation['historywork'] - && $cfgRelation['trackingwork'] && $cfgRelation['userconfigwork'] - && $cfgRelation['bookmarkwork'] && $cfgRelation['designerwork']) { + && $cfgRelation['recentwork'] && $cfgRelation['trackingwork'] + && $cfgRelation['userconfigwork'] && $cfgRelation['bookmarkwork'] + && $cfgRelation['designerwork']) { $cfgRelation['allworks'] = true; } diff --git a/navigation.php b/navigation.php index 86f360a5af..2bff387795 100644 --- a/navigation.php +++ b/navigation.php @@ -180,27 +180,13 @@ require_once './libraries/header_http.inc.php'; -
- -
-tables)) { + echo '
'; + echo RecentTable::getInstance()->getHtmlSelect(); + echo '
'; } if (! $GLOBALS['server']) { From d5421a41f9491edeebfde55c49823ada7f5dabed Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sun, 8 May 2011 03:11:09 +0700 Subject: [PATCH 05/80] Recently used tables (add SQL in scripts/create_tables.sql) --- scripts/create_tables.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/create_tables.sql b/scripts/create_tables.sql index 1efdaadfde..2d6cb56886 100644 --- a/scripts/create_tables.sql +++ b/scripts/create_tables.sql @@ -105,6 +105,18 @@ CREATE TABLE IF NOT EXISTS `pma_pdf_pages` ( -- -------------------------------------------------------- +-- +-- Table structure for table `pma_recent` +-- + +CREATE TABLE IF NOT EXISTS `pma_recent` ( + `username` varchar(64) COLLATE utf8_bin NOT NULL, + `tables` blob NOT NULL, + PRIMARY KEY (`username`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- -------------------------------------------------------- + -- -- Table structure for table `pma_relation` -- From 04bbe91b52ca660d0743d0bc644823e8960fffb0 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sun, 8 May 2011 22:40:46 +0700 Subject: [PATCH 06/80] Recently used tables (fix bug & add pma_recent in /setup) --- libraries/RecentTable.class.php | 29 ++++++----------------------- libraries/config/messages.inc.php | 2 ++ libraries/config/setup.forms.php | 1 + libraries/header.inc.php | 6 +++--- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index 12eb7f5112..d9faf59c44 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -12,7 +12,6 @@ require_once './libraries/Message.class.php'; * * @TODO Add documentation about configuration LeftRecentTable * @TODO Add documentation about table pma_recent (#recent) in Documentation.html - * @TODO Add SQL script to generate pma_recent table * * @package phpMyAdmin */ @@ -48,7 +47,7 @@ class RecentTable $this->pma_table = PMA_backquote($GLOBALS['cfg']['Server']['pmadb']) .".". PMA_backquote($GLOBALS['cfg']['Server']['recent']); } - if (!isset($_SESSION['tmp_user_values']['recent_tables'])) { + if (! isset($_SESSION['tmp_user_values']['recent_tables'])) { $_SESSION['tmp_user_values']['recent_tables'] = isset($this->pma_table) ? $this->getFromDb() : array(); } @@ -96,8 +95,6 @@ class RecentTable /** * Save recent tables into phpMyAdmin database. * - * @uses PMA_query_as_controluser() - * @uses PMA_DBI_fetch_value() * @uses PMA_DBI_try_query() * @uses json_decode() * @uses PMA_Message @@ -108,27 +105,13 @@ class RecentTable { $username = $GLOBALS['cfg']['Server']['user']; $sql_query = - " SELECT COUNT(*) FROM " . $this->pma_table . - " WHERE `username` = '" . $username . "'"; + " REPLACE INTO " . $this->pma_table . " (`username`, `tables`)" . + " VALUES ('" . $username . "', '" . PMA_sqlAddslashes(json_encode($this->tables)) . "')"; - $exist = PMA_DBI_fetch_value(PMA_query_as_controluser($sql_query)); - if ($exist) { - $sql_query = - " UPDATE " . $this->pma_table . - " SET `tables` = '" . PMA_sqlAddslashes(json_encode($this->tables)) . "'" . - " WHERE `username` = '" . $username . "'"; - - $success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']); - } else { - $sql_query = - " INSERT INTO " . $this->pma_table . " (`username`, `tables`)" . - " VALUES ('" . $username . "', '" . PMA_sqlAddslashes(json_encode($this->tables)) . "')"; - - $success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']); - } + $success = PMA_DBI_try_query($sql_query, $GLOBALS['controllink']); if (!$success) { - $message = PMA_Message::error(__('Could not save configuration')); + $message = PMA_Message::error(__('Could not save recent table')); $message->addMessage('

'); $message->addMessage(PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink']))); return $message; @@ -183,7 +166,7 @@ class RecentTable $table_str = $db . '.' . $table; // add only if this is new table - if (!isset($this->tables[0]) || $this->tables[0] != $table_str) { + if (! isset($this->tables[0]) || $this->tables[0] != $table_str) { array_unshift($this->tables, $table_str); $this->tables = array_unique($this->tables); $this->trim(); diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 47ccf7febf..6d3f121f7b 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -402,6 +402,8 @@ $strConfigServers_pmadb_desc = __('Database used for relations, bookmarks, and P $strConfigServers_pmadb_name = __('Database name'); $strConfigServers_port_desc = __('Port on which MySQL server is listening, leave empty for default'); $strConfigServers_port_name = __('Server port'); +$strConfigServers_recent_desc = __('Leave blank for no "persistent" recently used tables across sessions, suggested: [kbd]pma_recent[/kbd]'); +$strConfigServers_recent_name = __('Recently used table'); $strConfigServers_relation_desc = __('Leave blank for no [a@http://wiki.phpmyadmin.net/pma/relation]relation-links[/a] support, suggested: [kbd]pma_relation[/kbd]'); $strConfigServers_relation_name = __('Relation table'); $strConfigServers_ShowDatabasesCommand_desc = __('SQL command to fetch available databases'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index acf477ea72..7269823d2d 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -73,6 +73,7 @@ $forms['Servers']['Server_pmadb'] = array('Servers' => array(1 => array( 'table_info' => 'pma_table_info', 'column_info' => 'pma_column_info', 'history' => 'pma_history', + 'recent' => 'pma_recent', 'tracking' => 'pma_tracking', 'table_coords' => 'pma_table_coords', 'pdf_pages' => 'pma_pdf_pages', diff --git a/libraries/header.inc.php b/libraries/header.inc.php index b581070e6c..3d10821782 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -151,12 +151,12 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { } // end if // add recently used table and reload the navigation - $result = RecentTable::getInstance()->add($GLOBALS['db'], $GLOBALS['table']); - if ($result === true) { + $tmp_result = RecentTable::getInstance()->add($GLOBALS['db'], $GLOBALS['table']); + if ($tmp_result === true) { $GLOBALS['reload'] = true; PMA_reloadNavigation(); } else { - $error = $result; + $error = $tmp_result; $error->display(); } } else { From ed646a067f057ba8e133a06c3224a7ab9f98a1c1 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Mon, 9 May 2011 20:35:08 +0700 Subject: [PATCH 07/80] Added array_merge (RecentTable.class.php) to ensure the keys are continuous --- libraries/RecentTable.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index d9faf59c44..387879e7a2 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -168,7 +168,7 @@ class RecentTable // add only if this is new table if (! isset($this->tables[0]) || $this->tables[0] != $table_str) { array_unshift($this->tables, $table_str); - $this->tables = array_unique($this->tables); + $this->tables = array_merge(array_unique($this->tables)); $this->trim(); if (isset($this->pma_table)) { return $this->saveToDb(); From c468705538f034e06447b85123063cdcfffc1b59 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 10 May 2011 01:55:02 +0700 Subject: [PATCH 08/80] Add PMA_addRecentTable function, jQuery for recent tables 'onchange' event --- Documentation.html | 25 +++++++++++++++++++++++++ js/navigation.js | 10 ++++++++++ libraries/RecentTable.class.php | 17 +++++++---------- libraries/header.inc.php | 26 ++++++++++++++++++-------- navigation.php | 2 +- 5 files changed, 61 insertions(+), 19 deletions(-) diff --git a/Documentation.html b/Documentation.html index cee6a4211e..55bc56d0c1 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1054,6 +1054,27 @@ ALTER TABLE `pma_column_comments` +
+ $cfg['Servers'][$i]['recent'] string +
+
+ Since release ??? you can show recently used tables in the left navigation frame. + It helps you to jump across table directly, without the need to select the database, + and then select the table. Using + $cfg['LeftRecentTable'] + you can configure the maximum number of recent tables shown.

+ + Without configuring the storage, you can still access the recently used tables, + but it will disappear after you logout.

+ + To allow the usage of this functionality: + +
    +
  • set up pmadb and the phpMyAdmin configuration storage
  • +
  • put the table name in $cfg['Servers'][$i]['recent'] (e.g. 'pma_recent')
  • +
+
+
$cfg['Servers'][$i]['tracking'] string
@@ -1467,6 +1488,10 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE
Defines how many sublevels should be displayed when splitting up tables by the above separator.
+
$cfg['LeftRecentTable'] integer
+
The maximum number of recently used tables shown in the left navigation + frame. Set this to 0 (zero) to disable the recent tables.
+
$cfg['ShowTooltip'] boolean
Defines whether to display table comment as tool-tip in left frame or not.
diff --git a/js/navigation.js b/js/navigation.js index ed6dcb1049..9403ade8d4 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -177,4 +177,14 @@ $(document).ready(function(){ $('#clear_fast_filter').click(clear_fast_filter); $('#fast_filter').focus(function (evt) {evt.target.select();}); $('#fast_filter').keyup(function (evt) {fast_filter(evt.target.value);}); + + /* Jump to recent table */ + $('#recentTable').change(function() { + if (this.value != '') { + var arr = this.value.split('.'); + window.parent.setDb(arr[0]); + window.parent.setTable(arr[1]); + window.parent.refreshMain($('#LeftDefaultTabTable')[0].value); + } + }); }); diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index 387879e7a2..635b659a02 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -10,8 +10,7 @@ require_once './libraries/Message.class.php'; /** * Handles the recently used tables. * - * @TODO Add documentation about configuration LeftRecentTable - * @TODO Add documentation about table pma_recent (#recent) in Documentation.html + * @TODO Change the release version in table pma_recent (#recent in Documentation.html) * * @package phpMyAdmin */ @@ -124,7 +123,8 @@ class RecentTable */ public function trim() { - while (count($this->tables) > $GLOBALS['cfg']['LeftRecentTable']) { + $max = max($GLOBALS['cfg']['LeftRecentTable'], 0); + while (count($this->tables) > $max) { array_pop($this->tables); } } @@ -137,13 +137,10 @@ class RecentTable public function getHtmlSelect() { $this->trim(); - - $html = ''; + $html .= ''; diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 3b4384326f..6549cb67fd 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -168,7 +168,9 @@ if (isset($GLOBALS['is_ajax_request']) && !$GLOBALS['is_ajax_request']) { } // end if // add recently used table and reload the navigation - PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); + if ($GLOBALS['cfg']['LeftRecentTable'] > 0) { + PMA_addRecentTable($GLOBALS['db'], $GLOBALS['table']); + } } else { // no table selected, display database comment if present /** From b8c654d748c7de1fde1c388743c734a6a6b30d9c Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 10 May 2011 09:56:24 +0700 Subject: [PATCH 10/80] Updated target release 3.5.0 for 'recent' feature in Documentation.html --- Documentation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation.html b/Documentation.html index 55bc56d0c1..d9afdde79a 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1058,7 +1058,7 @@ ALTER TABLE `pma_column_comments` $cfg['Servers'][$i]['recent'] string
- Since release ??? you can show recently used tables in the left navigation frame. + Since release 3.5.0 you can show recently used tables in the left navigation frame. It helps you to jump across table directly, without the need to select the database, and then select the table. Using $cfg['LeftRecentTable'] From 6e4abf02d6af2a32fc9ebff6410a3603dc50ba4b Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 10 May 2011 16:18:18 +0700 Subject: [PATCH 11/80] Validation (non-negative number) for LeftRecentTable --- libraries/config.values.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/config.values.php b/libraries/config.values.php index b5190370a4..d884e59a01 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -159,6 +159,7 @@ $cfg_db['_validators'] = array( 'Import/skip_queries' => 'validate_non_negative_number', 'InsertRows' => 'validate_positive_number', 'LeftFrameTableLevel' => 'validate_positive_number', + 'LeftRecentTable' => 'validate_non_negative_number', 'LimitChars' => 'validate_positive_number', 'LoginCookieValidity' => 'validate_positive_number', 'LoginCookieStore' => 'validate_non_negative_number', From 4ab5d6aded69bd4ce43777326cc225324cbbd39a Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Tue, 10 May 2011 20:42:48 +0700 Subject: [PATCH 12/80] Update documentation and string for the pma_recent --- Documentation.html | 4 +++- libraries/relation.lib.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation.html b/Documentation.html index d9afdde79a..019b15d8a8 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1062,7 +1062,9 @@ ALTER TABLE `pma_column_comments` It helps you to jump across table directly, without the need to select the database, and then select the table. Using $cfg['LeftRecentTable'] - you can configure the maximum number of recent tables shown.

+ you can configure the maximum number of recent tables shown. When you select a table + from the list, it will jump to the page specified in + $cfg['LeftDefaultTabTable'].

Without configuring the storage, you can still access the recently used tables, but it will disappear after you logout.

diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 1236275dd9..e45a8752ca 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -140,7 +140,7 @@ function PMA_printRelationsParamDiagnostic($cfgRelation) PMA_printDiagMessageForParameter('recent', isset($cfgRelation['recent']), $messages, 'recent'); - PMA_printDiagMessageForFeature(__('Recently used tables'), 'recentwork', $messages); + PMA_printDiagMessageForFeature(__('Persistent recently used tables'), 'recentwork', $messages); PMA_printDiagMessageForParameter('tracking', isset($cfgRelation['tracking']), $messages, 'tracking'); From fadd8994ccc41f1a7bc74509428a50a89d8789ac Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Wed, 11 May 2011 11:27:47 +0700 Subject: [PATCH 13/80] Documentation for cfg_LeftRecentTable updated --- Documentation.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation.html b/Documentation.html index 019b15d8a8..624616596e 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1492,7 +1492,7 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE
$cfg['LeftRecentTable'] integer
The maximum number of recently used tables shown in the left navigation - frame. Set this to 0 (zero) to disable the recent tables.
+ frame. Set this to 0 (zero) to disable the listing of recent tables.
$cfg['ShowTooltip'] boolean
Defines whether to display table comment as tool-tip in left frame or From 963d77e3bef98f6f8624dd5ee28b92405ad77149 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sat, 14 May 2011 02:46:15 +0700 Subject: [PATCH 14/80] Ajaxification of recent tables list --- js/navigation.js | 13 +++++++++++++ libraries/RecentTable.class.php | 21 ++++++++++++++++----- libraries/header.inc.php | 5 +++-- navigation.php | 18 ++++++++++++++---- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/js/navigation.js b/js/navigation.js index 9403ade8d4..cb7ffac568 100644 --- a/js/navigation.js +++ b/js/navigation.js @@ -165,6 +165,19 @@ function clear_fast_filter() { elm.focus(); } +/** + * Reloads the recent tables list. + */ +function PMA_reloadRecentTable() { + $.get('navigation.php', + { 'token' : window.parent.token, 'ajax_request' : true, 'recent_table' : true }, + function (data) { + if (data.success == true) { + $('#recentTable').html(data.options); + } + }); +} + /* Performed on load */ $(document).ready(function(){ /* Display filter */ diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index 91a6e2a180..9252601754 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -134,7 +134,21 @@ class RecentTable } /** - * Return HTML code "select" for recently used tables. + * Return options for HTML select. + * + * @return string + */ + public function getHtmlSelectOption() + { + $html = ''; + foreach ($this->tables as $table) { + $html .= ''; + } + return $html; + } + + /** + * Return HTML select. * * @return string */ @@ -148,10 +162,7 @@ class RecentTable $html = ''; $html .= ''; return $html; diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 3a84e2ec31..05d272effb 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -21,8 +21,9 @@ require_once './libraries/RecentTable.class.php'; function PMA_addRecentTable($db, $table) { $tmp_result = RecentTable::getInstance()->add($db, $table); if ($tmp_result === true) { - $GLOBALS['reload'] = true; - PMA_reloadNavigation(); + echo ''; } else { $error = $tmp_result; $error->display(); diff --git a/navigation.php b/navigation.php index 6c39e52073..f498a91dc5 100644 --- a/navigation.php +++ b/navigation.php @@ -53,6 +53,16 @@ function PMA_exitNavigationFrame() exit; } +require_once './libraries/common.lib.php'; +require_once './libraries/RecentTable.class.php'; + +/** + * Check if it is an ajax request to reload the recent tables list. + */ +if ($GLOBALS['is_ajax_request'] && $_REQUEST['recent_table']) { + PMA_ajaxResponse('', true, array('options' => RecentTable::getInstance()->getHtmlSelectOption()) ); +} + // keep the offset of the db list in session before closing it if (! isset($_SESSION['tmp_user_values']['navi_limit_offset'])) { $_SESSION['tmp_user_values']['navi_limit_offset'] = 0; @@ -180,12 +190,12 @@ require_once './libraries/header_http.inc.php'; 0) && count(RecentTable::getInstance()->tables)) { +if ($GLOBALS['cfg']['LeftRecentTable'] > 0) { echo '
'; - echo RecentTable::getInstance()->getHtmlSelect(); + if (count(RecentTable::getInstance()->tables)) { + echo RecentTable::getInstance()->getHtmlSelect(); + } echo '
'; } From 456640c457d62ff0e0a0d7965cca4aa0135aed93 Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sat, 14 May 2011 12:21:49 +0700 Subject: [PATCH 15/80] Some fix for ajaxification --- libraries/RecentTable.class.php | 8 ++++++-- navigation.php | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index 9252601754..add2876b87 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -141,8 +141,12 @@ class RecentTable public function getHtmlSelectOption() { $html = ''; - foreach ($this->tables as $table) { - $html .= ''; + if (count($this->tables)) { + foreach ($this->tables as $table) { + $html .= ''; + } + } else { + $html .= ''; } return $html; } diff --git a/navigation.php b/navigation.php index f498a91dc5..2c6f58d132 100644 --- a/navigation.php +++ b/navigation.php @@ -193,9 +193,7 @@ require './libraries/navigation_header.inc.php'; // display recently used tables if ($GLOBALS['cfg']['LeftRecentTable'] > 0) { echo '
'; - if (count(RecentTable::getInstance()->tables)) { - echo RecentTable::getInstance()->getHtmlSelect(); - } + echo RecentTable::getInstance()->getHtmlSelect(); echo '
'; } From 5dee868bfff80abfb7aea70d1d41a083117fd2ba Mon Sep 17 00:00:00 2001 From: Aris Feryanto Date: Sat, 14 May 2011 12:34:13 +0700 Subject: [PATCH 16/80] Move recent tables trimming to correct place --- libraries/RecentTable.class.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index add2876b87..ebe93f5fd7 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -140,6 +140,11 @@ class RecentTable */ public function getHtmlSelectOption() { + // trim and save, in case where the configuration is changed + if ($this->trim() && isset($this->pma_table)) { + $this->saveToDb(); + } + $html = ''; if (count($this->tables)) { foreach ($this->tables as $table) { @@ -158,11 +163,6 @@ class RecentTable */ public function getHtmlSelect() { - // trim and save, in case where the configuration is changed - if ($this->trim() && isset($this->pma_table)) { - $this->saveToDb(); - } - $html = ''; $html .= '