Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-04-20 19:14:41 +02:00
commit f87b74e214
2 changed files with 45 additions and 31 deletions

View File

@ -22,16 +22,20 @@ if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) {
$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)
$fav_instance_tables = $fav_instance->getTables();
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;
$favorite_tables[$user] = $fav_instance->getTables();
$ajax_response = PMA_Response::getInstance();
$ajax_response->addJSON(
@ -61,7 +65,7 @@ if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) {
}
} elseif (isset($_REQUEST['add_favorite'])) {
if (!$already_favorite) {
if (count($fav_instance->tables) == $GLOBALS['cfg']['NumFavoriteTables']) {
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" />'
@ -76,7 +80,7 @@ if ($GLOBALS['is_ajax_request'] && ! empty($_REQUEST['favorite_table'])) {
}
$favorite_tables[$user] = $fav_instance->tables;
$favorite_tables[$user] = $fav_instance->getTables();
$ajax_response = PMA_Response::getInstance();
$ajax_response->addJSON(
'changes',

View File

@ -33,10 +33,10 @@ class PMA_RecentFavoriteTable
/**
* Reference to session variable containing recently used or favorite tables.
*
* @access public
* @access private
* @var array
*/
public $tables;
private $_tables;
/**
* Defines type of action, Favorite or Recent table.
@ -44,7 +44,7 @@ class PMA_RecentFavoriteTable
* @access private
* @var string
*/
private $table_type;
private $_tableType;
/**
* PMA_RecentFavoriteTable instances.
@ -62,20 +62,20 @@ class PMA_RecentFavoriteTable
*/
private function __construct($type)
{
$this->table_type = $type;
$this->_tableType = $type;
if (strlen($GLOBALS['cfg']['Server']['pmadb'])
&& strlen($GLOBALS['cfg']['Server'][$this->table_type])
&& strlen($GLOBALS['cfg']['Server'][$this->_tableType])
) {
$this->_pmaTable
= PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . "."
. PMA_Util::backquote($GLOBALS['cfg']['Server'][$this->table_type]);
. PMA_Util::backquote($GLOBALS['cfg']['Server'][$this->_tableType]);
}
$server_id = $GLOBALS['server'];
if (! isset($_SESSION['tmpval'][$this->table_type . '_tables'][$server_id])) {
$_SESSION['tmpval'][$this->table_type . '_tables'][$server_id]
if (! isset($_SESSION['tmpval'][$this->_tableType . '_tables'][$server_id])) {
$_SESSION['tmpval'][$this->_tableType . '_tables'][$server_id]
= isset($this->_pmaTable) ? $this->getFromDb() : array();
}
$this->tables =& $_SESSION['tmpval'][$this->table_type . '_tables'][$server_id];
$this->_tables =& $_SESSION['tmpval'][$this->_tableType . '_tables'][$server_id];
}
/**
@ -93,6 +93,16 @@ class PMA_RecentFavoriteTable
return self::$_instances[$type];
}
/**
* Returns the recent/favorite tables array
*
* @return array
*/
public function getTables()
{
return $this->_tables;
}
/**
* Returns recently used tables or favorite from phpMyAdmin database.
*
@ -128,14 +138,14 @@ class PMA_RecentFavoriteTable
= " REPLACE INTO " . $this->_pmaTable . " (`username`, `tables`)" .
" VALUES ('" . $username . "', '"
. PMA_Util::sqlAddSlashes(
json_encode($this->tables)
json_encode($this->_tables)
) . "')";
$success = $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['controllink']);
if (! $success) {
$error_msg = '';
switch ($this->table_type) {
switch ($this->_tableType) {
case 'recent':
$error_msg = __('Could not save recent table!');
break;
@ -165,11 +175,11 @@ class PMA_RecentFavoriteTable
public function trim()
{
$max = max(
$GLOBALS['cfg']['Num' . ucfirst($this->table_type) . 'Tables'], 0
$GLOBALS['cfg']['Num' . ucfirst($this->_tableType) . 'Tables'], 0
);
$trimming_occurred = count($this->tables) > $max;
while (count($this->tables) > $max) {
array_pop($this->tables);
$trimming_occurred = count($this->_tables) > $max;
while (count($this->_tables) > $max) {
array_pop($this->_tables);
}
return $trimming_occurred;
}
@ -182,16 +192,16 @@ class PMA_RecentFavoriteTable
public function getHtmlList()
{
// Remove Recent/Favorite tables that don't exist.
foreach ($this->tables as $tbl) {
foreach ($this->_tables as $tbl) {
if (! $GLOBALS['dbi']->getColumns($tbl['db'], $tbl['table'])) {
$this->remove($tbl['db'], $tbl['table']);
}
}
$html = '';
if (count($this->tables)) {
if ($this->table_type == 'recent') {
foreach ($this->tables as $table) {
if (count($this->_tables)) {
if ($this->_tableType == 'recent') {
foreach ($this->_tables as $table) {
$html .= '<li>';
$html .= '<a href="sql.php?server=' . $GLOBALS['server']
. '&db=' . $table['db']
@ -201,7 +211,7 @@ class PMA_RecentFavoriteTable
$html .= '</li>';
}
} else {
foreach ($this->tables as $table) {
foreach ($this->_tables as $table) {
$html .= '<li>';
$html .= '<a class="ajax favorite_table_anchor"';
@ -228,7 +238,7 @@ class PMA_RecentFavoriteTable
}
} else {
$html .= '<li >'
. ($this->table_type == 'recent'
. ($this->_tableType == 'recent'
?__('There are no recent tables.')
:__('There are no favorite tables.'))
. '</li>';
@ -244,7 +254,7 @@ class PMA_RecentFavoriteTable
public function getHtml()
{
$html = '<div class="drop_list">';
if ($this->table_type == 'recent') {
if ($this->_tableType == 'recent') {
$html .= '<span title="' . __('Recent tables')
. '" class="drop_button">'
. __('Recent') . '</span><ul id="pma_recent_list">';
@ -278,9 +288,9 @@ class PMA_RecentFavoriteTable
$table_arr['table'] = $table;
// add only if this is new table
if (! isset($this->tables[0]) || $this->tables[0] != $table_arr) {
array_unshift($this->tables, $table_arr);
$this->tables = array_merge(array_unique($this->tables, SORT_REGULAR));
if (! isset($this->_tables[0]) || $this->_tables[0] != $table_arr) {
array_unshift($this->_tables, $table_arr);
$this->_tables = array_merge(array_unique($this->_tables, SORT_REGULAR));
$this->trim();
if (isset($this->_pmaTable)) {
return $this->saveToDb();
@ -302,9 +312,9 @@ class PMA_RecentFavoriteTable
$table_arr = array();
$table_arr['db'] = $db;
$table_arr['table'] = $table;
foreach ($this->tables as $key => $value) {
foreach ($this->_tables as $key => $value) {
if ($value['db'] == $db && $value['table'] == $table) {
unset($this->tables[$key]);
unset($this->_tables[$key]);
}
}
if (isset($this->_pmaTable)) {