/** * Add or remove favorite tables * * @param string $db current database * * @return void */ function PMA_addRemoveFavoriteTables($db) { $fav_instance = PMA_RecentFavoriteTable::getInstance('favorite'); if (isset($_REQUEST['favorite_tables'])) { $favorite_tables = json_decode($_REQUEST['favorite_tables'], true); } else { $favorite_tables = array(); } // Required to keep each user's preferences separate. $user = sha1($GLOBALS['cfg']['Server']['user']); // Request for Synchronization of favorite tables. if (isset($_REQUEST['sync_favorite_tables'])) { PMA_synchronizeFavoriteTables($fav_instance, $user, $favorite_tables); exit; } $changes = true; $msg = ''; $titles = PMA_Util::buildActionTitles(); $favorite_table = $_REQUEST['favorite_table']; $already_favorite = PMA_checkFavoriteTable($db, $favorite_table); if (isset($_REQUEST['remove_favorite'])) { if ($already_favorite) { // If already in favorite list, remove it. $fav_instance->remove($db, $favorite_table); } } elseif (isset($_REQUEST['add_favorite'])) { if (!$already_favorite) { if (count($fav_instance->getTables()) == $GLOBALS['cfg']['NumFavoriteTables']) { $changes = false; $msg = '<div class="error"><img src="themes/dot.gif" ' . 'title="" alt="" class="icon ic_s_error" />' . __("Favorite List is full!") . '</div>'; } else { // Otherwise add to favorite list. $fav_instance->add($db, $favorite_table); } } } $favorite_tables[$user] = $fav_instance->getTables(); $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('list', $fav_instance->getHtmlList()); $ajax_response->addJSON('anchor', PMA_getHtmlForFavoriteAnchor($db, array('TABLE_NAME' => $favorite_table), $titles)); } else { $ajax_response->addJSON('message', $msg); } }
/** * Get HTML for favorite anchor. * * @param string $db current database * @param string $current_table current table * @param array $titles titles * * @return $html_output */ function PMA_getHtmlForFavoriteAnchor($db, $current_table, $titles) { $html_output = '<a '; $html_output .= 'id="' . md5($current_table) . '_favorite_anchor" '; $html_output .= 'class="ajax favorite_table_anchor'; // Check if current table is already in favorite list. $already_favorite = PMA_checkFavoriteTable($db, $current_table); $fav_params = array('db' => $db, 'ajax_request' => true, 'favorite_table' => $current_table, ($already_favorite ? 'remove' : 'add') . '_favorite' => true); $fav_url = 'db_structure.php' . PMA_URL_getCommon($fav_params); $html_output .= '" '; $html_output .= 'href="' . $fav_url . '" title="' . ($already_favorite ? __("Remove from Favorites") : __("Add to Favorites")) . '" data-favtargets="' . md5($db . "." . $current_table) . '" >' . (!$already_favorite ? $titles['NoFavorite'] : $titles['Favorite']) . '</a>'; return $html_output; }
* I could have used the PHP ternary conditional operator but I find * the code easier to read without this operator. */ list($browse_table, $search_table, $browse_table_label, $empty_table, $tracking_icon) = PMA_getHtmlForActionLinks($current_table, $table_is_view, $tbl_url_query, $titles, $truename, $db_is_system_schema, $url_query); if (!$db_is_system_schema) { list($drop_query, $drop_message) = PMA_getTableDropQueryAndMessage($table_is_view, $current_table); } if ($num_columns > 0 && $num_tables > $num_columns && $row_count % $num_columns == 0) { $row_count = 1; $odd_row = true; $response->addHTML('</tr></tbody></table>'); $response->addHTML(PMA_tableHeader(false, $server_slave_status)); } list($do, $ignored) = PMA_getServerSlaveStatus($server_slave_status, $truename); // Handle favorite table list. ----START---- $already_favorite = PMA_checkFavoriteTable($db, $current_table['TABLE_NAME']); if (isset($_REQUEST['remove_favorite'])) { if ($already_favorite) { // If already in favorite list, remove it. $favorite_table = $_REQUEST['favorite_table']; $fav_instance->remove($db, $favorite_table); } } if (isset($_REQUEST['add_favorite'])) { if (!$already_favorite) { // Otherwise add to favorite list. $favorite_table = $_REQUEST['favorite_table']; $fav_instance->add($db, $favorite_table); } } // Handle favorite table list. ----ENDS----