bugfix: user preferences don't work correctly without output buffering

This commit is contained in:
Crack
2010-08-01 22:52:15 +02:00
parent 9a73307003
commit 279724d6f8
4 changed files with 56 additions and 44 deletions

View File

@@ -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[] = "<b>$k</b> " . var_export($v, true);

View File

@@ -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
*

View File

@@ -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,11 +46,25 @@ 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);
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 {
// check for form errors
$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
?>
@@ -55,22 +73,8 @@ if (!$form_display->process(false)) {
<?php $form_display->displayErrors(); ?>
</div>
<?php
$form_display->display(true, true);
} 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);
}
}
/**
* Displays the footer

View File

@@ -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 '<div class="config-form">';
@@ -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';
?>
<script type="text/javascript">
<?php