From 7a5fd6281078b234c665e64cea968641c4aceec0 Mon Sep 17 00:00:00 2001 From: Crack Date: Wed, 14 Jul 2010 21:28:24 +0200 Subject: [PATCH] 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 --- js/config.js | 27 +++++++++++++++++++++ libraries/footer.inc.php | 8 +++++++ libraries/header.inc.php | 14 +++++++++++ libraries/user_preferences.inc.php | 9 ------- libraries/user_preferences.lib.php | 29 +++++++++++++++++++--- prefs_manage.php | 32 +++++++++++++++++++++---- themes/original/css/theme_right.css.php | 6 ++++- 7 files changed, 107 insertions(+), 18 deletions(-) diff --git a/js/config.js b/js/config.js index 612425bf9..421a0aca3 100644 --- a/js/config.js +++ b/js/config.js @@ -631,6 +631,7 @@ $(function() { // $(function() { + offerPrefsAutoimport(); var radios = $('#import_local_storage, #export_local_storage'); if (!radios.length) { return; @@ -747,6 +748,32 @@ function formatDate(d) + ':' + (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 // ------------------------------------------------------------------ \ No newline at end of file diff --git a/libraries/footer.inc.php b/libraries/footer.inc.php index 2a3cb28f2..a27fa37a8 100644 --- a/libraries/footer.inc.php +++ b/libraries/footer.inc.php @@ -119,7 +119,15 @@ if (window.parent.refreshNavigation) { window.parent.refreshNavigation(); } + if (window.parent && window.parent.frame_navigation) { + window.parent.frame_navigation.location.reload(); + } + // set current db, table and sql query in the querywindow if (window.parent.reload_querywindow) { diff --git a/libraries/header.inc.php b/libraries/header.inc.php index 8273d5022..9101c0e33 100644 --- a/libraries/header.inc.php +++ b/libraries/header.inc.php @@ -22,6 +22,14 @@ if (empty($GLOBALS['is_header_sent'])) { require_once './libraries/ob.lib.php'; 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 // to a seperate file. It can now be included by header.inc.php, // querywindow.php. @@ -59,6 +67,12 @@ if (empty($GLOBALS['is_header_sent'])) { 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')) { define('PMA_DISPLAY_HEADING', 1); } diff --git a/libraries/user_preferences.inc.php b/libraries/user_preferences.inc.php index 101f39199..da2b35e51 100644 --- a/libraries/user_preferences.inc.php +++ b/libraries/user_preferences.inc.php @@ -45,15 +45,6 @@ echo ''; 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') { -?> - - 1, - 'refresh_left_frame' => $refresh_left_frame); + 'reload_left_frame' => $reload_left_frame); if (is_array($params)) { $url_params = array_merge($params, $url_params); } PMA_sendHeaderLocation($GLOBALS['cfg']['PmaAbsoluteUri'] . $file_name . 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, '', '&'); + ?> + + \ No newline at end of file diff --git a/prefs_manage.php b/prefs_manage.php index 5355b7f90..37b448b66 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -68,7 +68,12 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == // read from POST value (json) $json = filter_input(INPUT_POST, 'json'); } + + // hide header message + $_SESSION['userprefs_autoload'] = true; + $config = json_decode($json, true); + $return_url = filter_input(INPUT_POST, 'return_url'); if (!is_array($config)) { $error = __('Could not import configuration'); } else { @@ -113,6 +118,9 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == + + +

@@ -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']->setActiveTheme($config['ThemeDefault']); $_SESSION['PMA_Theme_Manager']->setThemeCookie(); - $params['refresh_left_frame'] = true; + $params['reload_left_frame'] = true; } if (isset($config['fontsize'])) { $params['set_fontsize'] = $config['fontsize']; - $params['refresh_left_frame'] = true; + $params['reload_left_frame'] = true; } // save settings $old_settings = PMA_load_userprefs(); $result = PMA_save_userprefs($cf->getConfigArray()); 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; } else { $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()); unset($_SESSION['PMA_Theme_Manager']); unset($_SESSION['PMA_Theme']); - $params['refresh_left_frame'] = true; + $params['reload_left_frame'] = true; } if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') { $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); exit; diff --git a/themes/original/css/theme_right.css.php b/themes/original/css/theme_right.css.php index 329ea80d7..028dd57dc 100644 --- a/themes/original/css/theme_right.css.php +++ b/themes/original/css/theme_right.css.php @@ -1441,4 +1441,8 @@ fieldset .group-field th { .prefsmanage_opts { margin-: 2em; -} \ No newline at end of file +} + +#prefs_autoload { + margin-bottom: 0.5em; +}