allow users to easily work with preferences stored in session (when pmadb is disabled): after logging in, user is presented with a message asking whether settings from localStorage should be loaded

This commit is contained in:
Crack
2010-07-14 21:28:24 +02:00
parent 60285cd665
commit 7a5fd62810
7 changed files with 107 additions and 18 deletions

View File

@@ -631,6 +631,7 @@ $(function() {
// //
$(function() { $(function() {
offerPrefsAutoimport();
var radios = $('#import_local_storage, #export_local_storage'); var radios = $('#import_local_storage, #export_local_storage');
if (!radios.length) { if (!radios.length) {
return; return;
@@ -747,6 +748,32 @@ function formatDate(d)
+ ':' + (d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes()); + ':' + (d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes());
} }
/**
* Prepares message which informs that localStorage preferences are available and can be imported
*/
function offerPrefsAutoimport()
{
var has_config = (window.localStorage || false) && (window.localStorage['config'] || false);
var cnt = $('#prefs_autoload');
if (!cnt.length || !has_config) {
return;
}
cnt.find('a').click(function(e) {
e.stopPropagation();
var a = $(this);
if (a.attr('href') == '#no') {
cnt.remove();
$.post('main.php', {
token: cnt.find('input[name=token]').val(),
prefs_autoload: 'hide'});
return;
}
cnt.find('input[name=json]').val(window.localStorage['config']);
cnt.find('form').submit();
});
cnt.show();
}
// //
// END: User preferences import/export // END: User preferences import/export
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@@ -119,7 +119,15 @@ if (window.parent.refreshNavigation) {
window.parent.refreshNavigation(); window.parent.refreshNavigation();
} }
<?php <?php
} else if (isset($_GET['reload_left_frame']) && $_GET['reload_left_frame'] == '1') {
// reload left frame (used by user preferences)
?>
if (window.parent && window.parent.frame_navigation) {
window.parent.frame_navigation.location.reload();
}
<?php
} }
?> ?>
// set current db, table and sql query in the querywindow // set current db, table and sql query in the querywindow
if (window.parent.reload_querywindow) { if (window.parent.reload_querywindow) {

View File

@@ -22,6 +22,14 @@ if (empty($GLOBALS['is_header_sent'])) {
require_once './libraries/ob.lib.php'; require_once './libraries/ob.lib.php';
PMA_outBufferPre(); PMA_outBufferPre();
// if database storage for user preferences is transient, offer to load
// exported settings from localStorage (detection will be done in JavaScript)
$userprefs_offer_import = $GLOBALS['PMA_Config']->get('user_preferences') == 'session'
&& !isset($_SESSION['userprefs_autoload']);
if ($userprefs_offer_import) {
$GLOBALS['js_include'][] = 'config.js';
}
// For re-usability, moved http-headers and stylesheets // For re-usability, moved http-headers and stylesheets
// to a seperate file. It can now be included by header.inc.php, // to a seperate file. It can now be included by header.inc.php,
// querywindow.php. // querywindow.php.
@@ -59,6 +67,12 @@ if (empty($GLOBALS['is_header_sent'])) {
PMA_Message::notice(__('Cookies must be enabled past this point.'))->display(); PMA_Message::notice(__('Cookies must be enabled past this point.'))->display();
} }
// offer to load user preferences from localStorage
if ($userprefs_offer_import) {
require_once './libraries/user_preferences.lib.php';
PMA_userprefs_autoload_header();
}
if (!defined('PMA_DISPLAY_HEADING')) { if (!defined('PMA_DISPLAY_HEADING')) {
define('PMA_DISPLAY_HEADING', 1); define('PMA_DISPLAY_HEADING', 1);
} }

View File

@@ -45,15 +45,6 @@ echo '</ul>';
if (!empty($_GET['saved'])) { if (!empty($_GET['saved'])) {
$message = PMA_Message::rawSuccess(__('Configuration has been saved')); $message = PMA_Message::rawSuccess(__('Configuration has been saved'));
$message->display(); $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
}
} }
$forms_all_keys = PMA_read_userprefs_fieldnames($forms); $forms_all_keys = PMA_read_userprefs_fieldnames($forms);

View File

@@ -221,17 +221,40 @@ function PMA_userprefs_redirect(array $forms, array $old_settings, $file_name, $
$check_keys = array_merge($check_keys, $forms['Left_frame']['Left_frame'], $check_keys = array_merge($check_keys, $forms['Left_frame']['Left_frame'],
$forms['Left_frame']['Left_databases']); $forms['Left_frame']['Left_databases']);
$diff = array_intersect($check_keys, $diff_keys); $diff = array_intersect($check_keys, $diff_keys);
$refresh_left_frame = !empty($diff) $reload_left_frame = !empty($diff)
|| (isset($params['refresh_left_frame']) && $params['refresh_left_frame']); || (isset($params['reload_left_frame']) && $params['reload_left_frame']);
// redirect // redirect
$url_params = array( $url_params = array(
'saved' => 1, 'saved' => 1,
'refresh_left_frame' => $refresh_left_frame); 'reload_left_frame' => $reload_left_frame);
if (is_array($params)) { if (is_array($params)) {
$url_params = array_merge($params, $url_params); $url_params = array_merge($params, $url_params);
} }
PMA_sendHeaderLocation($GLOBALS['cfg']['PmaAbsoluteUri'] . $file_name PMA_sendHeaderLocation($GLOBALS['cfg']['PmaAbsoluteUri'] . $file_name
. PMA_generate_common_url($url_params, '&')); . PMA_generate_common_url($url_params, '&'));
} }
function PMA_userprefs_autoload_header()
{
if (isset($_REQUEST['prefs_autoload']) && $_REQUEST['prefs_autoload'] == 'hide') {
$_SESSION['userprefs_autoload'] = true;
exit;
}
$script_name = basename(basename($GLOBALS['PMA_PHP_SELF']));
$return_url = $script_name . '?' . http_build_query($_GET, '', '&');
?>
<div id="prefs_autoload" class="notice" style="display:none">
<form action="prefs_manage.php" method="post">
<?php echo PMA_generate_common_hidden_inputs() . "\n"; ?>
<input type="hidden" name="json" value="" />
<input type="hidden" name="submit_import" value="1" />
<input type="hidden" name="return_url" value="<?php echo htmlspecialchars($return_url) ?>" />
<?php echo __('Your browser has phpMyAdmin configuration for this domain. Would you like to import it for current session?') ?>
<br />
<a href="#yes"><?php echo __('Yes') ?></a> / <a href="#no"><?php echo __('No') ?></a>
</form>
</div>
<?php
}
?> ?>

View File

@@ -68,7 +68,12 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
// read from POST value (json) // read from POST value (json)
$json = filter_input(INPUT_POST, 'json'); $json = filter_input(INPUT_POST, 'json');
} }
// hide header message
$_SESSION['userprefs_autoload'] = true;
$config = json_decode($json, true); $config = json_decode($json, true);
$return_url = filter_input(INPUT_POST, 'return_url');
if (!is_array($config)) { if (!is_array($config)) {
$error = __('Could not import configuration'); $error = __('Could not import configuration');
} else { } else {
@@ -113,6 +118,9 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
<?php if (!empty($_POST['import_merge'])): ?> <?php if (!empty($_POST['import_merge'])): ?>
<input type="hidden" name="import_merge" value="1" /> <input type="hidden" name="import_merge" value="1" />
<?php endif; ?> <?php endif; ?>
<?php if ($return_url): ?>
<input type="hidden" name="return_url" value="<?php echo htmlspecialchars($return_url) ?>" />
<?php endif; ?>
<p><?php echo __('Do you want to import remaining settings?') ?></p> <p><?php echo __('Do you want to import remaining settings?') ?></p>
<input type="submit" name="submit_import" value="<?php echo __('Yes') ?>" /> <input type="submit" name="submit_import" value="<?php echo __('Yes') ?>" />
<input type="submit" name="submit_ignore" value="<?php echo __('No') ?>" /> <input type="submit" name="submit_ignore" value="<?php echo __('No') ?>" />
@@ -128,18 +136,32 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
&& $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])) { && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])) {
$_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']); $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
$_SESSION['PMA_Theme_Manager']->setThemeCookie(); $_SESSION['PMA_Theme_Manager']->setThemeCookie();
$params['refresh_left_frame'] = true; $params['reload_left_frame'] = true;
} }
if (isset($config['fontsize'])) { if (isset($config['fontsize'])) {
$params['set_fontsize'] = $config['fontsize']; $params['set_fontsize'] = $config['fontsize'];
$params['refresh_left_frame'] = true; $params['reload_left_frame'] = true;
} }
// save settings // save settings
$old_settings = PMA_load_userprefs(); $old_settings = PMA_load_userprefs();
$result = PMA_save_userprefs($cf->getConfigArray()); $result = PMA_save_userprefs($cf->getConfigArray());
if ($result === true) { if ($result === true) {
PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params); if ($return_url) {
$query = explode('&', parse_url($return_url, PHP_URL_QUERY));
$return_url = parse_url($return_url, PHP_URL_PATH);
foreach ($query as $q) {
$pos = strpos($q, '=');
$k = substr($q, 0, $pos);
if ($k == 'token') {
continue;
}
$params[$k] = substr($q, $pos+1);
}
} else {
$return_url = 'prefs_manage.php';
}
PMA_userprefs_redirect($forms, $old_settings, $return_url, $params);
exit; exit;
} else { } else {
$error = $result; $error = $result;
@@ -154,11 +176,11 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') ==
$GLOBALS['PMA_Config']->removeCookie($_SESSION['PMA_Theme_Manager']->getThemeCookieName()); $GLOBALS['PMA_Config']->removeCookie($_SESSION['PMA_Theme_Manager']->getThemeCookieName());
unset($_SESSION['PMA_Theme_Manager']); unset($_SESSION['PMA_Theme_Manager']);
unset($_SESSION['PMA_Theme']); unset($_SESSION['PMA_Theme']);
$params['refresh_left_frame'] = true; $params['reload_left_frame'] = true;
} }
if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') { if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
$GLOBALS['PMA_Config']->removeCookie('pma_fontsize'); $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
$params['refresh_left_frame'] = true; $params['reload_left_frame'] = true;
} }
PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params); PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params);
exit; exit;

View File

@@ -1441,4 +1441,8 @@ fieldset .group-field th {
.prefsmanage_opts { .prefsmanage_opts {
margin-<?php echo $left; ?>: 2em; margin-<?php echo $left; ?>: 2em;
} }
#prefs_autoload {
margin-bottom: 0.5em;
}