diff --git a/libraries/user_preferences.inc.php b/libraries/user_preferences.inc.php index 00bc89747..e11b5e1c6 100644 --- a/libraries/user_preferences.inc.php +++ b/libraries/user_preferences.inc.php @@ -47,17 +47,8 @@ if (!empty($_GET['saved'])) { $message->display(); } -$forms_all_keys = PMA_read_userprefs_fieldnames($forms); -$cf = ConfigFile::getInstance(); -$cf->resetConfigData(); // start with a clean instance -$cf->setAllowedKeys($forms_all_keys); -$cf->setCfgUpdateReadMapping(array( - 'Server/hide_db' => 'Servers/1/hide_db', - 'Server/only_db' => 'Servers/1/only_db')); -$cf->updateWithGlobalConfig($GLOBALS['cfg']); - // todo: debug - remove -$arr = $cf->getConfigArray(); +$arr = ConfigFile::getInstance()->getConfigArray(); $arr2 = array(); foreach ($arr as $k => $v) { $arr2[] = "$k " . var_export($v, true); diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php index 6616963e8..dd26a3f95 100644 --- a/libraries/user_preferences.lib.php +++ b/libraries/user_preferences.lib.php @@ -6,6 +6,21 @@ * @package phpMyAdmin */ +/** + * Common initialization for user preferences modification pages + */ +function PMA_userprefs_pageinit() +{ + $forms_all_keys = PMA_read_userprefs_fieldnames($GLOBALS['forms']); + $cf = ConfigFile::getInstance(); + $cf->resetConfigData(); // start with a clean instance + $cf->setAllowedKeys($forms_all_keys); + $cf->setCfgUpdateReadMapping(array( + 'Server/hide_db' => 'Servers/1/hide_db', + 'Server/only_db' => 'Servers/1/only_db')); + $cf->updateWithGlobalConfig($GLOBALS['cfg']); +} + /** * Loads user preferences * diff --git a/prefs_forms.php b/prefs_forms.php index 280083237..63cdea502 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -18,11 +18,15 @@ require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require './libraries/config/user_preferences.forms.php'; -$GLOBALS['js_include'][] = 'config.js'; -require_once './libraries/header.inc.php'; -require_once './libraries/user_preferences.inc.php'; +PMA_userprefs_pageinit(); -// handle form display and processing +// handle form processing + +$form_param = filter_input(INPUT_GET, 'form'); +if (!isset($forms[$form_param])) { + $forms_keys = array_keys($forms); + $form_param = array_shift($forms_keys); +} $form_display = new FormDisplay(); foreach ($forms[$form_param] as $form_name => $form) { @@ -42,36 +46,36 @@ if (isset($_POST['revert'])) { . PMA_generate_common_url($url_params, '&')); exit; } -if (!$form_display->process(false)) { - // handle form view and failed POST - $form_display->display(true, true); -} else { - // check for form errors - if ($form_display->hasErrors()) { - // form has errors - ?> -
- - displayErrors(); ?> -
- display(true, true); + +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) { + $hash = ltrim(filter_input(INPUT_POST, 'tab_hash'), '#'); + PMA_userprefs_redirect($forms, $old_settings, 'prefs_forms.php', array( + 'form' => $form_param), $hash); + exit; } else { - // save settings - $old_settings = PMA_load_userprefs(); - $result = PMA_save_userprefs($cf->getConfigArray()); - if ($result === true) { - $hash = ltrim(filter_input(INPUT_POST, 'tab_hash'), '#'); - PMA_userprefs_redirect($forms, $old_settings, 'prefs_forms.php', array( - 'form' => $form_param), $hash); - exit; - } else { - $result->display(); - } - $form_display->display(true, true); + $error = $result; } } +// display forms +$GLOBALS['js_include'][] = 'config.js'; +require './libraries/header.inc.php'; +require './libraries/user_preferences.inc.php'; +if ($form_display->hasErrors()) { + // form has errors + ?> +
+ + displayErrors(); ?> +
+ display(true, true); + /** * Displays the footer */ diff --git a/prefs_manage.php b/prefs_manage.php index bcef4bef8..52a33f084 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -18,6 +18,8 @@ require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require './libraries/config/user_preferences.forms.php'; +PMA_userprefs_pageinit(); + $error = ''; if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == 'text_file') { // export to JSON file @@ -103,8 +105,8 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == } if (!$all_ok) { // mimic original form and post json in a hidden field - require_once './libraries/header.inc.php'; - require_once './libraries/user_preferences.inc.php'; + require './libraries/header.inc.php'; + require './libraries/user_preferences.inc.php'; $msg = PMA_Message::warning(__('Configuration contains incorrect data for some fields.')); $msg->display(); echo '
'; @@ -205,8 +207,8 @@ if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == } $GLOBALS['js_include'][] = 'config.js'; -require_once './libraries/header.inc.php'; -require_once './libraries/user_preferences.inc.php'; +require './libraries/header.inc.php'; +require './libraries/user_preferences.inc.php'; ?>