User preferences:
- add icons to category tabs - user overrides were unavailable in CSS files - apply saved configuration immediately after save, reload navigation frame if it's affected - disabled overrides marked in user preferences forms
This commit is contained in:
@@ -413,31 +413,38 @@ class PMA_Config
|
||||
* loads user preferences and merges them with current config
|
||||
* must be called after control connection has been estabilished
|
||||
*
|
||||
* @uses PMA_array_merge_recursive
|
||||
* @uses PMA_backquote()
|
||||
* @uses PMA_DBI_fetch_value
|
||||
* @uses PMA_getRelationsParam()
|
||||
* @uses PMA_sqlAddslashes()
|
||||
* @uses $GLOBALS['cfg']
|
||||
* @uses $GLOBALS['controllink']
|
||||
* @uses $_SESSION['cache']['config_mtime']
|
||||
* @uses $_SESSION['cache']['userprefs']
|
||||
* @uses $_SESSION['cache']['userprefs_mtime']
|
||||
* @uses PMA_apply_userprefs()
|
||||
* @uses PMA_array_merge_recursive()
|
||||
* @uses PMA_load_userprefs()
|
||||
* @return boolean
|
||||
*/
|
||||
function loadUserPreferences()
|
||||
{
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
if (!$cfgRelation['userconfigwork']) {
|
||||
return false;
|
||||
// index.php should load these settings, so that phpmyadmin.css.php
|
||||
// will have everything avaiable in session cache
|
||||
if (!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']['userprefs'])
|
||||
|| $_SESSION['cache']['config_mtime'] < $config_mtime) {
|
||||
require_once './libraries/user_preferences.lib.php';
|
||||
require_once './libraries/config/config_functions.lib.php';
|
||||
$prefs = PMA_load_userprefs();
|
||||
$_SESSION['cache']['userprefs'] = PMA_apply_userprefs($prefs['config_data']);
|
||||
$_SESSION['cache']['userprefs_mtime'] = $prefs['mtime'];
|
||||
$_SESSION['cache']['config_mtime'] = $config_mtime;
|
||||
}
|
||||
} else if (!isset($_SESSION['cache']['userprefs'])) {
|
||||
return;
|
||||
}
|
||||
$query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']);
|
||||
$query = '
|
||||
SELECT `config_data`
|
||||
FROM ' . $query_table . '
|
||||
WHERE `username` = \'' . PMA_sqlAddslashes($cfgRelation['user']) . '\'';
|
||||
$config_data = PMA_DBI_fetch_value($query, 0, 0, $GLOBALS['controllink']);
|
||||
$config_data = $_SESSION['cache']['userprefs'];
|
||||
if (!$config_data) {
|
||||
return false;
|
||||
}
|
||||
$config_data = unserialize($config_data);
|
||||
$this->settings = PMA_array_merge_recursive($this->settings, $config_data);
|
||||
$GLOBALS['cfg'] = PMA_array_merge_recursive($GLOBALS['cfg'], $config_data);
|
||||
$this->set('user_preferences_loaded', true);
|
||||
@@ -572,6 +579,7 @@ class PMA_Config
|
||||
$fontsize +
|
||||
$this->source_mtime +
|
||||
$this->default_source_mtime +
|
||||
(isset($_SESSION['cache']['userprefs_mtime']) ? $_SESSION['cache']['userprefs_mtime'] : 0) +
|
||||
$_SESSION['PMA_Theme']->mtime_info +
|
||||
$_SESSION['PMA_Theme']->filesize_info)
|
||||
. (isset($_SESSION['tmp_user_values']['custom_color']) ? substr($_SESSION['tmp_user_values']['custom_color'],1,6) : '');
|
||||
|
@@ -954,9 +954,6 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
||||
|
||||
} // end server connecting
|
||||
|
||||
// load user preferences
|
||||
$GLOBALS['PMA_Config']->loadUserPreferences();
|
||||
|
||||
/**
|
||||
* check if profiling was requested and remember it
|
||||
* (note: when $cfg['ServerDefault'] = 0, constant is not defined)
|
||||
@@ -978,6 +975,9 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
||||
}
|
||||
} // end if !defined('PMA_MINIMUM_COMMON')
|
||||
|
||||
// load user preferences
|
||||
$GLOBALS['PMA_Config']->loadUserPreferences();
|
||||
|
||||
// remove sensitive values from session
|
||||
$GLOBALS['PMA_Config']->set('blowfish_secret', '');
|
||||
$GLOBALS['PMA_Config']->set('Servers', '');
|
||||
|
@@ -167,7 +167,8 @@ class ConfigFile
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens multidimensional array, changes indices to paths (eg. 'key/subkey')
|
||||
* Flattens multidimensional array, changes indices to paths (eg. 'key/subkey').
|
||||
* Used as array_walk() callback.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $key
|
||||
@@ -385,18 +386,20 @@ class ConfigFile
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns configuration array
|
||||
* Returns configuration array (flat format)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigArray()
|
||||
{
|
||||
$c = $_SESSION[$this->id];
|
||||
$this->_flattenArrayResult = array();
|
||||
array_walk($_SESSION[$this->id], array($this, '_flattenArray'), '');
|
||||
$c = $this->_flattenArrayResult;
|
||||
$this->_flattenArrayResult = null;
|
||||
|
||||
$persistKeys = array_diff(array_keys($this->persistKeys), array_keys($c));
|
||||
foreach ($persistKeys as $k) {
|
||||
if (strpos($k, '/') === false) {
|
||||
$c[$k] = $this->getDefault($k);
|
||||
}
|
||||
$c[$k] = $this->getDefault($k);
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
@@ -139,6 +139,9 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
|
||||
<?php if (!empty($opts['wiki'])){ ?><a href="<?php echo $opts['wiki'] ?>" target="wiki"><img class="icon" src="<?php echo $img_path ?>b_info.png" width="11" height="11" alt="Wiki" title="Wiki" /></a><?php } ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if (!$is_setup_script && isset($opts['userprefs_allow']) && !$opts['userprefs_allow']): ?>
|
||||
<span class="disabled-notice" title="<?php echo __('This setting is disabled, it will not be applied to your configuration') ?>"><?php echo __('Disabled') ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($description)) { ?><small><?php echo $description ?></small><?php } ?>
|
||||
|
||||
</th>
|
||||
|
@@ -59,7 +59,6 @@ $forms['Left_frame']['Left_databases'] = array(
|
||||
'DisplayDatabasesList',
|
||||
'LeftFrameDBTree',
|
||||
'LeftFrameDBSeparator',
|
||||
'LeftFrameTableLevel',
|
||||
'ShowTooltipAliasDB');
|
||||
$forms['Left_frame']['Left_tables'] = array(
|
||||
'LeftDefaultTabTable',
|
||||
|
@@ -6,9 +6,57 @@
|
||||
* @package phpMyAdmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Loads user preferences
|
||||
*
|
||||
* Returns false or an array:
|
||||
* * config_data - path => value pairs
|
||||
* * mtime - last modification time
|
||||
*
|
||||
* @uses PMA_array_merge_recursive
|
||||
* @uses PMA_backquote()
|
||||
* @uses PMA_DBI_fetch_single_row()
|
||||
* @uses PMA_getRelationsParam()
|
||||
* @uses PMA_sqlAddslashes()
|
||||
* @uses $GLOBALS['controllink']
|
||||
* @return false|array
|
||||
*/
|
||||
function PMA_load_userprefs()
|
||||
{
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
if (!$cfgRelation['userconfigwork']) {
|
||||
return false;
|
||||
}
|
||||
$query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']);
|
||||
$query = '
|
||||
SELECT `config_data`, UNIX_TIMESTAMP(`timevalue`) ts
|
||||
FROM ' . $query_table . '
|
||||
WHERE `username` = \'' . PMA_sqlAddslashes($cfgRelation['user']) . '\'';
|
||||
$row = PMA_DBI_fetch_single_row($query, 'ASSOC', $GLOBALS['controllink']);
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
$config_data = unserialize($row['config_data']);
|
||||
return array(
|
||||
'config_data' => $config_data,
|
||||
'mtime' => $row['ts']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves user preferences
|
||||
*
|
||||
* @uses $GLOBALS['controllink']
|
||||
* @uses $_SESSION['cache']['userprefs']
|
||||
* @uses ConfigFile::getConfigArray()
|
||||
* @uses ConfigFile::getInstance()
|
||||
* @uses PMA_backquote()
|
||||
* @uses PMA_DBI_fetch_value
|
||||
* @uses PMA_DBI_getError()
|
||||
* @uses PMA_DBI_try_query()
|
||||
* @uses PMA_Message::addMessage()
|
||||
* @uses PMA_Message::error()
|
||||
* @uses PMA_Message::rawError()
|
||||
* @uses PMA_sqlAddslashes()
|
||||
* @uses PMA_getRelationsParam()
|
||||
* @return true|PMA_Message
|
||||
*/
|
||||
@@ -37,6 +85,9 @@ function PMA_save_userprefs()
|
||||
VALUES (\'' . PMA_sqlAddslashes($cfgRelation['user']) . '\',
|
||||
\'' . PMA_sqlAddslashes($config_data) . '\')';
|
||||
}
|
||||
if (isset($_SESSION['cache']['userprefs'])) {
|
||||
unset($_SESSION['cache']['userprefs']);
|
||||
}
|
||||
if (!PMA_DBI_try_query($query, $GLOBALS['controllink'])) {
|
||||
$message = PMA_Message::error(__('Could not save configuration'));
|
||||
$message->addMessage('<br /><br />');
|
||||
@@ -45,4 +96,27 @@ function PMA_save_userprefs()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user preferences array filtered by $cfg['UserprefsDisallow']
|
||||
* (blacklist) and keys from user preferences form (whitelist)
|
||||
*
|
||||
* @uses PMA_array_write()
|
||||
* @uses PMA_read_userprefs_fieldnames()
|
||||
* @param array $config_data path => value pairs
|
||||
* @return array
|
||||
*/
|
||||
function PMA_apply_userprefs(array $config_data)
|
||||
{
|
||||
$cfg = array();
|
||||
$blacklist = array_flip($GLOBALS['cfg']['UserprefsDisallow']);
|
||||
$whitelist = array_flip(PMA_read_userprefs_fieldnames());
|
||||
foreach ($config_data as $path => $value) {
|
||||
if (!isset($whitelist[$path]) || isset($blacklist[$path])) {
|
||||
continue;
|
||||
}
|
||||
PMA_array_write($path, $cfg, $value);
|
||||
}
|
||||
return $cfg;
|
||||
}
|
||||
?>
|
@@ -1309,10 +1309,17 @@ table#serverconnection_trg_local {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.config-form fieldset .doc {
|
||||
.config-form fieldset .doc, .config-form fieldset .disabled-notice {
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
.config-form fieldset .disabled-notice {
|
||||
font-size: 80%;
|
||||
text-transform: uppercase;
|
||||
color: #E00;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.config-form fieldset td {
|
||||
padding-top: 0.3em;
|
||||
padding-bottom: 0.3em;
|
||||
|
@@ -29,17 +29,39 @@ if (!isset($forms[$form_param])) {
|
||||
$forms_keys = array_keys($forms);
|
||||
$form_param = array_shift($forms_keys);
|
||||
}
|
||||
$tabs_icons = array(
|
||||
'Features' => 'b_tblops.png',
|
||||
'Sql_queries' => 'b_sql.png',
|
||||
'Left_frame' => 'b_select.png',
|
||||
'Main_frame' => 'b_props.png',
|
||||
'Import' => 'b_import.png',
|
||||
'Export' => 'b_export.png');
|
||||
foreach (array_keys($forms) as $formset) {
|
||||
$tabs[] = array(
|
||||
'link' => 'user_preferences.php',
|
||||
'text' => PMA_ifSetOr($GLOBALS['strSetupForm_' . $formset], $formset), // TODO: remove ifSetOr
|
||||
'icon' => $tabs_icons[$formset],
|
||||
'active' => $formset == $form_param,
|
||||
'url_params' => array('form' => $formset)
|
||||
);
|
||||
'url_params' => array('form' => $formset));
|
||||
}
|
||||
|
||||
echo PMA_generate_html_tabs($tabs, array());
|
||||
|
||||
// show "configuration saved" message and reload navigation frame if needed
|
||||
if (!empty($_GET['saved'])) {
|
||||
$message = PMA_Message::rawSuccess(__('Configuration has been saved'));
|
||||
$message->display();
|
||||
if (isset($_GET['refresh_left_frame']) && $_GET['refresh_left_frame'] == '1') {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
if (window.parent && window.parent.frame_navigation) {
|
||||
window.parent.frame_navigation.location.reload();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
// handle form display and processing
|
||||
|
||||
$forms_all_keys = PMA_read_userprefs_fieldnames($forms);
|
||||
@@ -54,7 +76,10 @@ foreach ($arr as $k => $v) {
|
||||
$arr2[] = "<b>$k</b> " . var_export($v, true);
|
||||
}
|
||||
$arr2 = implode(', ', $arr2);
|
||||
$msg = !empty($arr2) ? PMA_Message::notice('Debug: ' . $arr2) : PMA_Message::notice('no settings');
|
||||
$arr2 .= '<br />Blacklist: ' . (empty($cfg['UserprefsDisallow'])
|
||||
? '<i>empty</i>'
|
||||
: implode(', ', $cfg['UserprefsDisallow']));
|
||||
$msg = PMA_Message::notice('Debug: ' . $arr2);
|
||||
$msg->display();
|
||||
|
||||
$form_display = new FormDisplay();
|
||||
@@ -87,15 +112,30 @@ if (!$form_display->process(false)) {
|
||||
$form_display->display(true, true);
|
||||
} else {
|
||||
// save settings
|
||||
$old_settings = PMA_load_userprefs();
|
||||
$result = PMA_save_userprefs();
|
||||
if ($result === true) {
|
||||
$message = PMA_Message::rawSuccess(__('Configuration has been saved'));
|
||||
$message->display();
|
||||
// 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_servers'], $forms['Left_frame']['Left_databases']);
|
||||
$diff = array_intersect($check_keys, $diff_keys);
|
||||
$refresh_left_frame = !empty($diff);
|
||||
|
||||
// redirect
|
||||
//$url_params = array('form' => $form_param);
|
||||
//PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'user_preferences.php'
|
||||
// . PMA_generate_common_url($url_params, '&'));
|
||||
//exit;
|
||||
$url_params = array(
|
||||
'form' => $form_param,
|
||||
'saved' => 1,
|
||||
'refresh_left_frame' => $refresh_left_frame);
|
||||
PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'user_preferences.php'
|
||||
. PMA_generate_common_url($url_params, '&'));
|
||||
exit;
|
||||
} else {
|
||||
$result->display();
|
||||
}
|
||||
|
Reference in New Issue
Block a user