/** * Loads user preferences and merges them with current config * must be called after control connection has been estabilished * * @uses $GLOBALS['cfg'] * @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() * @uses PMA_load_userprefs() * @return boolean */ function loadUserPreferences() { // index.php should load these settings, so that phpmyadmin.css.php // will have everything avaiable in session cache $server = isset($GLOBALS['server']) ? $GLOBALS['server'] : (!empty($GLOBALS['cfg']['ServerDefault']) ? $GLOBALS['cfg']['ServerDefault'] : 0); $cache_key = 'server_' . $server; if ($server > 0 && !defined('PMA_MINIMUM_COMMON')) { $config_mtime = max($this->default_source_mtime, $this->source_mtime); // cache user preferences, use database only when needed if (!isset($_SESSION['cache'][$cache_key]['userprefs']) || $_SESSION['cache'][$cache_key]['config_mtime'] < $config_mtime) { // load required libraries require_once './libraries/user_preferences.lib.php'; $prefs = PMA_load_userprefs(); $_SESSION['cache'][$cache_key]['userprefs'] = PMA_apply_userprefs($prefs['config_data']); $_SESSION['cache'][$cache_key]['userprefs_mtime'] = $prefs['mtime']; $_SESSION['cache'][$cache_key]['userprefs_type'] = $prefs['type']; $_SESSION['cache'][$cache_key]['config_mtime'] = $config_mtime; } } else { if ($server == 0 || !isset($_SESSION['cache'][$cache_key]['userprefs'])) { $this->set('user_preferences', false); return; } } $config_data = $_SESSION['cache'][$cache_key]['userprefs']; // type is 'db' or 'session' $this->set('user_preferences', $_SESSION['cache'][$cache_key]['userprefs_type']); $this->set('user_preferences_mtime', $_SESSION['cache'][$cache_key]['userprefs_mtime']); // backup some settings $org_fontsize = $this->settings['fontsize']; // load config array $this->settings = PMA_array_merge_recursive($this->settings, $config_data); $GLOBALS['cfg'] = PMA_array_merge_recursive($GLOBALS['cfg'], $config_data); if (defined('PMA_MINIMUM_COMMON')) { return; } // settings below start really working on next page load, but // changes are made only in index.php so everything is set when // in frames // save theme $tmanager = $_SESSION['PMA_Theme_Manager']; if ($tmanager->getThemeCookie() || isset($_REQUEST['set_theme'])) { 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'); } } else { // no cookie - read default from settings if ($this->settings['ThemeDefault'] != $tmanager->theme->getId() && $tmanager->checkTheme($this->settings['ThemeDefault'])) { $tmanager->setActiveTheme($this->settings['ThemeDefault']); $tmanager->setThemeCookie(); } } // 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']); } } }
continue; } $form_display->registerForm($form_name, $form, 1); } if (isset($_POST['revert'])) { // revert erroneous fields to their default values $form_display->fixErrors(); // redirect $url_params = array('form' => $form_param); PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'prefs_forms.php' . PMA_generate_common_url($url_params, '&')); exit; } $error = null; if ($form_display->process(false) && !$form_display->hasErrors()) { // save settings $old_settings = PMA_load_userprefs(); $result = PMA_save_userprefs(ConfigFile::getInstance()->getConfigArray()); if ($result === true) { // reload config $GLOBALS['PMA_Config']->loadUserPreferences(); $hash = ltrim(filter_input(INPUT_POST, 'tab_hash'), '#'); PMA_userprefs_redirect($forms, $old_settings, 'prefs_forms.php', array('form' => $form_param), $hash); exit; } else { $error = $result; } } // display forms $GLOBALS['js_include'][] = 'config.js'; require './libraries/header.inc.php'; require './libraries/user_preferences.inc.php';
/** * Updates one user preferences option (loads and saves to database). * * No validation is done! * * @uses PMA_load_userprefs() * @uses PMA_save_userprefs() * @param string $cfg_name * @param mixed $value * @return void */ function PMA_persist_option($path, $value, $default_value) { $prefs = PMA_load_userprefs(); if ($value === $default_value) { if (isset($prefs['config_data'][$path])) { unset($prefs['config_data'][$path]); } else { return; } } else { $prefs['config_data'][$path] = $value; } PMA_save_userprefs($prefs['config_data']); }