Skip to content

Commit

Permalink
save lang and collation_connection to user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrp committed Jul 19, 2010
1 parent 8c28b69 commit c67340d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 26 deletions.
51 changes: 39 additions & 12 deletions libraries/Config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,11 @@ function load($source = null)
* must be called after control connection has been estabilished
*
* @uses $GLOBALS['cfg']
* @uses $_SESSION['cache']['config_mtime']
* @uses $_SESSION['cache']['userprefs']
* @uses $_SESSION['cache']['userprefs_mtime']
* @uses $GLOBALS['collation_connection']
* @uses $GLOBALS['lang']
* @uses $_SESSION['cache']['server_$server']['config_mtime']
* @uses $_SESSION['cache']['server_$server']['userprefs']
* @uses $_SESSION['cache']['server_$server']['userprefs_mtime']
* @uses $_SESSION['PMA_Theme_Manager']
* @uses PMA_apply_userprefs()
* @uses PMA_array_merge_recursive()
Expand Down Expand Up @@ -472,14 +474,11 @@ function loadUserPreferences()
// changes are made only in index.php so everything is set when
// in frames

// load/save theme
// theme cookie exists only if we are using non-default theme
// save theme
$tmanager = $_SESSION['PMA_Theme_Manager'];

// save new theme
if ($tmanager->getThemeCookie() || isset($_REQUEST['set_theme'])) {
if (!isset($config_data['ThemeDefault'])
|| $config_data['ThemeDefault'] != $tmanager->theme->getId()) {
if ((!isset($config_data['ThemeDefault']) && $tmanager->theme->getId() != 'original')
|| isset($config_data['ThemeDefault']) && $config_data['ThemeDefault'] != $tmanager->theme->getId()) {
// new theme was set in common.inc.php
$this->setUserValue(null, 'ThemeDefault', $tmanager->theme->getId(), 'original');
}
Expand All @@ -492,9 +491,37 @@ function loadUserPreferences()
}
}

// save new font size
if (!isset($config_data['fontsize']) || $org_fontsize != $config_data['fontsize']) {
$this->setUserValue('pma_fontsize', 'fontsize', $org_fontsize, '82%');
// save font size
if ((!isset($config_data['fontsize']) && $org_fontsize != '82%')
|| isset($config_data['fontsize']) && $org_fontsize != $config_data['fontsize']) {
$this->setUserValue(null, 'fontsize', $org_fontsize, '82%');
}

// save language
if (isset($_COOKIE['pma_lang']) || isset($_POST['lang'])) {
if ((!isset($config_data['lang']) && $GLOBALS['lang'] != 'en')
|| isset($config_data['lang']) && $GLOBALS['lang'] != $config_data['lang']) {
$this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
}
} else {
// read language from settings
if (isset($config_data['lang']) && PMA_langSet($config_data['lang'])) {
$this->setCookie('pma_lang', $GLOBALS['lang']);
}
}

// save connection collation
if (isset($_COOKIE['pma_collation_connection']) || isset($_POST['collation_connection'])) {
if ((!isset($config_data['collation_connection']) && $GLOBALS['collation_connection'] != 'utf8_general_ci')
|| isset($config_data['collation_connection']) && $GLOBALS['collation_connection'] != $config_data['collation_connection']) {
$this->setUserValue(null, 'collation_connection', $GLOBALS['collation_connection'], 'utf8_general_ci');
}
} else {
// read collation from settings
if (isset($config_data['collation_connection'])) {
$GLOBALS['collation_connection'] = $config_data['collation_connection'];
$this->setCookie('pma_collation_connection', $GLOBALS['collation_connection']);
}
}
}

Expand Down
31 changes: 18 additions & 13 deletions libraries/user_preferences.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ function PMA_apply_userprefs(array $config_data)
$cfg = array();
$blacklist = array_flip($GLOBALS['cfg']['UserprefsDisallow']);
$whitelist = array_flip(PMA_read_userprefs_fieldnames());
// whitelist some additional fields which are custom handled
$whitelist['ThemeDefault'] = true;
$whitelist['fontsize'] = true;
$whitelist['lang'] = true;
$whitelist['collation_connection'] = true;
foreach ($config_data as $path => $value) {
if (!isset($whitelist[$path]) || isset($blacklist[$path])) {
continue;
Expand Down Expand Up @@ -210,19 +213,21 @@ function PMA_persist_option($path, $value, $default_value)
*/
function PMA_userprefs_redirect(array $forms, array $old_settings, $file_name, $params = null)
{
// compute differences and check whether left frame should be refreshed
$old_settings = isset($old_settings['config_data'])
? $old_settings['config_data']
: array();
$new_settings = ConfigFile::getInstance()->getConfigArray();
$diff_keys = array_keys(array_diff_assoc($old_settings, $new_settings)
+ array_diff_assoc($new_settings, $old_settings));
$check_keys = array('NaturalOrder', 'MainPageIconic', 'DefaultTabDatabase');
$check_keys = array_merge($check_keys, $forms['Left_frame']['Left_frame'],
$forms['Left_frame']['Left_databases']);
$diff = array_intersect($check_keys, $diff_keys);
$reload_left_frame = !empty($diff)
|| (isset($params['reload_left_frame']) && $params['reload_left_frame']);
$reload_left_frame = isset($params['reload_left_frame']) && $params['reload_left_frame'];
if (!$reload_left_frame) {
// compute differences and check whether left frame should be refreshed
$old_settings = isset($old_settings['config_data'])
? $old_settings['config_data']
: array();
$new_settings = ConfigFile::getInstance()->getConfigArray();
$diff_keys = array_keys(array_diff_assoc($old_settings, $new_settings)
+ array_diff_assoc($new_settings, $old_settings));
$check_keys = array('NaturalOrder', 'MainPageIconic', 'DefaultTabDatabase');
$check_keys = array_merge($check_keys, $forms['Left_frame']['Left_frame'],
$forms['Left_frame']['Left_databases']);
$diff = array_intersect($check_keys, $diff_keys);
$reload_left_frame = !empty($diff);
}

// redirect
$url_params = array(
Expand Down
16 changes: 15 additions & 1 deletion prefs_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,27 @@
// check for ThemeDefault and fontsize
$params = array();
if (isset($config['ThemeDefault'])
&& $_SESSION['PMA_Theme_Manager']->theme->getId() != $config['ThemeDefault']
&& $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])) {
$_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
$_SESSION['PMA_Theme_Manager']->setThemeCookie();
$params['reload_left_frame'] = true;
}
if (isset($config['fontsize'])) {
if (isset($config['fontsize'])
&& $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')) {
$params['set_fontsize'] = $config['fontsize'];
$params['reload_left_frame'] = true;
}
if (isset($config['lang'])
&& $config['lang'] != $GLOBALS['lang']) {
$params['lang'] = $config['lang'];
$params['reload_left_frame'] = true;
}
if (isset($config['collation_connection'])
&& $config['collation_connection'] != $GLOBALS['collation_connection']) {
$params['collation_connection'] = $config['collation_connection'];
$params['reload_left_frame'] = true;
}

// save settings
$old_settings = PMA_load_userprefs();
Expand Down Expand Up @@ -182,6 +194,8 @@
$GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
$params['reload_left_frame'] = true;
}
$GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
$GLOBALS['PMA_Config']->removeCookie('pma_lang');
PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params);
exit;
} else {
Expand Down

0 comments on commit c67340d

Please sign in to comment.