';
+ } else {
+ // Otherwise add to favorite list.
+ $fav_instance->add($db, $favorite_table);
+ }
+ }
+ } else {
+
+ }
+
+ $ajax_response = PMA_Response::getInstance();
+ $ajax_response->addJSON(
+ 'changes',
+ $changes
+ );
+ if ($changes) {
+ $ajax_response->addJSON(
+ 'options',
+ PMA_RecentFavoriteTable::getInstance('favorite')->getHtmlSelectOption()
+ );
+ $ajax_response->addJSON(
+ 'anchor',
+ PMA_getHtmlForFavoriteAnchor($db, array('TABLE_NAME' => $favorite_table), $titles)
+ );
+ } else {
+ $ajax_response->addJSON(
+ 'message',
+ $msg
+ );
+ }
+ exit;
+}
+
$response = PMA_Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();
@@ -133,8 +188,8 @@ $overhead_size = (double) 0;
$hidden_fields = array();
$odd_row = true;
$sum_row_count_pre = '';
-// Instance of PMA_FavoriteTable class.
-$fav_instance = PMA_FavoriteTable::getInstance();
+// Instance of PMA_RecentFavoriteTable class.
+$fav_instance = PMA_RecentFavoriteTable::getInstance('favorite');
foreach ($tables as $keyname => $current_table) {
// Get valid statistics whatever is the table type
diff --git a/doc/faq.rst b/doc/faq.rst
index 2dde65d14b..0fde66e8ce 100644
--- a/doc/faq.rst
+++ b/doc/faq.rst
@@ -1920,6 +1920,28 @@ next to the column name, when the tooltip tells you to do so. This
will show you an input box with the column name. You may right-click
the column name within this input box to copy it to your clipboard.
+.. _faq6_34:
+
+6.34 How can I use the Favorite Tables feature?
+---------------------------------------------------------
+
+Favorite Tables feature is very much similar to Recent Tables feature.
+It allows you to add a shortcut for the frequently used tables of any
+database in the navigation panel . You can easily navigate to any table
+in the list by simply choosing it from the list. These tables are stored
+temporarily in your session if you have not configured your
+`phpMyAdmin Configuration Storage`. Otherwise these entries are permanent.
+
+To add a table to Favorite list simply click on the `Gray` star in front
+of a table name in the list of tables of a Database and wait until it
+turns to `Yellow`.
+To remove a table from list, simply click on the `Yellow` star and
+wait until it turns `Gray` again.
+
+Using :config:option:`$cfg['NumFavoriteTables']` in your :file:`config.inc.php`
+file, you can define the maximum number of favorite tables shown in the
+navigation panel. Its default value is `10`.
+
.. _faqproject:
phpMyAdmin project
diff --git a/index.php b/index.php
index 625b564fcd..2f1cd8efb4 100644
--- a/index.php
+++ b/index.php
@@ -56,12 +56,12 @@ if (! empty($_REQUEST['target'])
/**
* Check if it is an ajax request to reload the recent tables list.
*/
-require_once 'libraries/RecentTable.class.php';
+require_once 'libraries/RecentFavoriteTable.class.php';
if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['recent_table'])) {
$response = PMA_Response::getInstance();
$response->addJSON(
'options',
- PMA_RecentTable::getInstance()->getHtmlSelectOption()
+ PMA_RecentFavoriteTable::getInstance('recent')->getHtmlSelectOption()
);
exit;
}
diff --git a/js/db_structure.js b/js/db_structure.js
index 25161811fb..6d667dbe50 100644
--- a/js/db_structure.js
+++ b/js/db_structure.js
@@ -28,6 +28,7 @@ AJAX.registerTeardown('db_structure.js', function () {
$("a.drop_table_anchor.ajax").die('click');
$('a.drop_tracking_anchor.ajax').die('click');
$('#real_end_input').die('click');
+ $("a.favorite_table_anchor.ajax").die('click');
});
/**
@@ -396,4 +397,30 @@ AJAX.registerOnload('db_structure.js', function () {
);
});
+ // Add/Remove favorite table using Ajax.
+ $(".favorite_table_anchor").live("click", function (event) {
+ event.preventDefault();
+ var anchor_id = $(this).attr("id");
+ $.get(
+ $(this).attr('href'),
+ function (data) {
+ if (data.success === true) {
+ if (data.changes) {
+ $('#favoriteTable').html(data.options);
+ $('#' + anchor_id).parent().html(data.anchor);
+ PMA_tooltip(
+ $('#' + anchor_id),
+ 'a',
+ $('#' + anchor_id).attr("title")
+ );
+ } else {
+ PMA_ajaxShowMessage(data.message);
+ }
+ } else {
+ PMA_ajaxShowMessage(data.message);
+ }
+ }
+ );
+ });
+
}); // end $()
diff --git a/libraries/Header.class.php b/libraries/Header.class.php
index 14ae45dc24..991293cb40 100644
--- a/libraries/Header.class.php
+++ b/libraries/Header.class.php
@@ -10,8 +10,7 @@ if (! defined('PHPMYADMIN')) {
}
require_once 'libraries/Scripts.class.php';
-require_once 'libraries/RecentTable.class.php';
-require_once 'libraries/FavoriteTable.class.php';
+require_once 'libraries/RecentFavoriteTable.class.php';
require_once 'libraries/Menu.class.php';
require_once 'libraries/navigation/Navigation.class.php';
require_once 'libraries/url_generating.lib.php';
@@ -703,7 +702,7 @@ class PMA_Header
&& strlen($table)
&& $GLOBALS['cfg']['NumRecentTables'] > 0
) {
- $tmp_result = PMA_RecentTable::getInstance()->add($db, $table);
+ $tmp_result = PMA_RecentFavoriteTable::getInstance('recent')->add($db, $table);
if ($tmp_result === true) {
$params = array('ajax_request' => true, 'recent_table' => true);
$url = 'index.php' . PMA_URL_getCommon($params);
diff --git a/libraries/FavoriteTable.class.php b/libraries/RecentFavoriteTable.class.php
similarity index 64%
rename from libraries/FavoriteTable.class.php
rename to libraries/RecentFavoriteTable.class.php
index 4e445e8240..30b28c9b20 100644
--- a/libraries/FavoriteTable.class.php
+++ b/libraries/RecentFavoriteTable.class.php
@@ -1,7 +1,7 @@
table_type = $type;
if (strlen($GLOBALS['cfg']['Server']['pmadb'])
- && strlen($GLOBALS['cfg']['Server']['favorite'])
+ && strlen($GLOBALS['cfg']['Server'][$this->table_type])
) {
$this->_pmaTable
= PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "."
- . PMA_Util::backquote($GLOBALS['cfg']['Server']['favorite']);
+ . PMA_Util::backquote($GLOBALS['cfg']['Server'][$this->table_type]);
}
$server_id = $GLOBALS['server'];
- if (! isset($_SESSION['tmpval']['favorite_tables'][$server_id])) {
- $_SESSION['tmpval']['favorite_tables'][$server_id]
+ if (! isset($_SESSION['tmpval'][$this->table_type . '_tables'][$server_id])) {
+ $_SESSION['tmpval'][$this->table_type . '_tables'][$server_id]
= isset($this->_pmaTable) ? $this->getFromDb() : array();
}
- $this->tables =& $_SESSION['tmpval']['favorite_tables'][$server_id];
+ $this->tables =& $_SESSION['tmpval'][$this->table_type . '_tables'][$server_id];
}
/**
* Returns class instance.
*
- * @return PMA_FavoriteTable
+ * @return PMA_RecentFavoriteTable
*/
- public static function getInstance()
+ public static function getInstance($type)
{
if (is_null(self::$_instance)) {
- self::$_instance = new PMA_FavoriteTable();
+ self::$_instance = new PMA_RecentFavoriteTable($type);
+ } else {
+ if (self::$_instance->table_type != $type) {
+ self::$_instance = new PMA_RecentFavoriteTable($type);
+ }
}
return self::$_instance;
}
/**
- * Returns favorite tables from phpMyAdmin database.
+ * Returns recently used tables or favorite from phpMyAdmin database.
*
* @return array
*/
public function getFromDb()
{
- // Read from phpMyAdmin database, if favorite tables are not in session
+ // Read from phpMyAdmin database, if recent tables is not in session
$sql_query
= " SELECT `tables` FROM " . $this->_pmaTable .
" WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'";
@@ -100,7 +115,7 @@ class PMA_FavoriteTable
}
/**
- * Save favorite tables into phpMyAdmin database.
+ * Save recent/favorite tables into phpMyAdmin database.
*
* @return true|PMA_Message
*/
@@ -117,7 +132,17 @@ class PMA_FavoriteTable
$success = $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['controllink']);
if (! $success) {
- $message = PMA_Message::error(__('Could not save favorite table!'));
+ $error_msg = '';
+ switch ($this->table_type) {
+ case 'recent':
+ $error_msg = __('Could not save recent table!');
+ break;
+
+ case 'favorite':
+ $error_msg = __('Could not save favorite table!');
+ break;
+ }
+ $message = PMA_Message::error($error_msg);
$message->addMessage('