diff --git a/db_structure.php b/db_structure.php index ab46c50909..3ca9009753 100644 --- a/db_structure.php +++ b/db_structure.php @@ -18,11 +18,38 @@ require_once 'libraries/structure.lib.php'; // Add/Remove favorite tables using Ajax request. if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) { + $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite'); + $favorite_tables = json_decode($_REQUEST['favorite_tables'], true); + // Required to keep each user's preferences seperate. + $user = sha1($GLOBALS['cfg']['Server']['user']); + // Request for Synchronization of favorite tables. + if (isset($_REQUEST['sync_favorite_tables'])) { + if (empty($fav_instance->tables) + && isset($favorite_tables[$user])) { + foreach ($favorite_tables[$user] as $key => $value) { + $fav_instance->add($value['db'], $value['table']); + } + } + $favorite_tables[$user] = $fav_instance->tables; + + $ajax_response = PMA_Response::getInstance(); + $ajax_response->addJSON( + 'favorite_tables', + json_encode($favorite_tables) + ); + $ajax_response->addJSON( + 'options', + $fav_instance->getHtmlSelectOption() + ); + $server_id = $GLOBALS['server']; + // Set flag when localStorage and pmadb(if present) are in sync. + $_SESSION['tmpval']['favorites_synced'][$server_id] = true; + exit; + } global $db; $changes = true; $msg = ''; $titles = PMA_Util::buildActionTitles(); - $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite'); $favorite_table = $_REQUEST['favorite_table']; $already_favorite = PMA_checkFavoriteTable($db, $favorite_table); @@ -48,15 +75,24 @@ if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) { } + $favorite_tables[$user] = $fav_instance->tables; $ajax_response = PMA_Response::getInstance(); $ajax_response->addJSON( 'changes', $changes ); if ($changes) { + $ajax_response->addJSON( + 'user', + $user + ); + $ajax_response->addJSON( + 'favorite_tables', + json_encode($favorite_tables) + ); $ajax_response->addJSON( 'options', - PMA_RecentFavoriteTable::getInstance('favorite')->getHtmlSelectOption() + $fav_instance->getHtmlSelectOption() ); $ajax_response->addJSON( 'anchor', diff --git a/doc/faq.rst b/doc/faq.rst index 0fde66e8ce..d1d54d6d22 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -1929,8 +1929,13 @@ 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. +in your browser's local storage if you have not configured your +`phpMyAdmin Configuration Storage`. Otherwise these entries are stored in +`phpMyAdmin Configuration Storage`. + +IMPORTANT: In absence of `phpMyAdmin Configuration Storage`, your Favorite +tables may be different in different browsers based on your different +selections in them. 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 diff --git a/index.php b/index.php index 2f1cd8efb4..b106ff3885 100644 --- a/index.php +++ b/index.php @@ -117,6 +117,8 @@ if ($server > 0) { } echo '