2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
10 * Gets some core libraries and displays a top message if required
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/user_preferences.lib.php';
14 require_once 'libraries/config/config_functions.lib.php';
15 require_once 'libraries/config/messages.inc.php';
16 require_once 'libraries/config/ConfigFile.class.php';
17 require_once 'libraries/config/Form.class.php';
18 require_once 'libraries/config/FormDisplay.class.php';
19 require 'libraries/config/user_preferences.forms.php';
21 PMA_userprefs_pageinit();
24 if (isset($_POST['submit_export']) && filter_input(INPUT_POST
, 'export_type') == 'text_file') {
25 // export to JSON file
26 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
27 PMA_download_header($filename, 'application/json');
28 $settings = PMA_load_userprefs();
29 echo json_encode($settings['config_data']);
31 } else if (isset($_POST['submit_get_json'])) {
32 $settings = PMA_load_userprefs();
33 header('Content-Type: application/json');
36 'prefs' => json_encode($settings['config_data']),
37 'mtime' => $settings['mtime']
41 } else if (isset($_POST['submit_import'])) {
42 // load from JSON file
44 if (filter_input(INPUT_POST
, 'import_type') == 'text_file'
45 && isset($_FILES['import_file'])
46 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
47 && is_uploaded_file($_FILES['import_file']['tmp_name'])
49 // read JSON from uploaded file
50 $open_basedir = @ini_get
('open_basedir');
52 $import_file = $_FILES['import_file']['tmp_name'];
54 // If we are on a server with open_basedir, we must move the file
55 // before opening it. The doc explains how to create the "./tmp"
57 if (!empty($open_basedir)) {
58 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : 'tmp/');
59 if (is_writable($tmp_subdir)) {
60 $import_file_new = tempnam($tmp_subdir, 'prefs');
61 if (move_uploaded_file($import_file, $import_file_new)) {
62 $import_file = $import_file_new;
63 $file_to_unlink = $import_file_new;
67 $json = file_get_contents($import_file);
68 if ($file_to_unlink) {
69 unlink($file_to_unlink);
72 // read from POST value (json)
73 $json = filter_input(INPUT_POST
, 'json');
76 // hide header message
77 $_SESSION['userprefs_autoload'] = true;
79 $config = json_decode($json, true);
80 $return_url = filter_input(INPUT_POST
, 'return_url');
81 if (! is_array($config)) {
82 $error = __('Could not import configuration');
84 // sanitize input values: treat them as though they came from HTTP POST request
85 $form_display = new FormDisplay();
86 foreach ($forms as $formset_id => $formset) {
87 foreach ($formset as $form_name => $form) {
88 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
91 $cf = ConfigFile
::getInstance();
92 $new_config = $cf->getFlatDefaultConfig();
93 if (!empty($_POST['import_merge'])) {
94 $new_config = array_merge($new_config, $cf->getConfigArray());
96 $new_config = array_merge($new_config, $config);
98 foreach ($new_config as $k => $v) {
99 $_POST[str_replace('/', '-', $k)] = $v;
101 $cf->resetConfigData();
102 $all_ok = $form_display->process(true, false);
103 $all_ok = $all_ok && !$form_display->hasErrors();
106 if (!$all_ok && isset($_POST['fix_errors'])) {
107 $form_display->fixErrors();
111 // mimic original form and post json in a hidden field
112 include 'libraries/header.inc.php';
113 include 'libraries/user_preferences.inc.php';
114 $msg = PMA_Message
::error(__('Configuration contains incorrect data for some fields.'));
116 echo '<div class="config-form">';
117 $form_display->displayErrors();
120 <form action
="prefs_manage.php" method
="post">
121 <?php
echo PMA_generate_common_hidden_inputs() . "\n"; ?
>
122 <input type
="hidden" name
="json" value
="<?php echo htmlspecialchars($json) ?>" />
123 <input type
="hidden" name
="fix_errors" value
="1" />
124 <?php
if (! empty($_POST['import_merge'])) { ?
>
125 <input type
="hidden" name
="import_merge" value
="1" />
127 <?php
if ($return_url) { ?
>
128 <input type
="hidden" name
="return_url" value
="<?php echo htmlspecialchars($return_url) ?>" />
130 <p
><?php
echo __('Do you want to import remaining settings?') ?
></p
>
131 <input type
="submit" name
="submit_import" value
="<?php echo __('Yes') ?>" />
132 <input type
="submit" name
="submit_ignore" value
="<?php echo __('No') ?>" />
135 include 'libraries/footer.inc.php';
139 // check for ThemeDefault and fontsize
141 if (isset($config['ThemeDefault'])
142 && $_SESSION['PMA_Theme_Manager']->theme
->getId() != $config['ThemeDefault']
143 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
145 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
146 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
147 $params['reload_left_frame'] = true;
149 if (isset($config['fontsize'])
150 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
152 $params['set_fontsize'] = $config['fontsize'];
153 $params['reload_left_frame'] = true;
155 if (isset($config['lang'])
156 && $config['lang'] != $GLOBALS['lang']
158 $params['lang'] = $config['lang'];
159 $params['reload_left_frame'] = true;
161 if (isset($config['collation_connection'])
162 && $config['collation_connection'] != $GLOBALS['collation_connection']
164 $params['collation_connection'] = $config['collation_connection'];
165 $params['reload_left_frame'] = true;
169 $old_settings = PMA_load_userprefs();
170 $result = PMA_save_userprefs($cf->getConfigArray());
171 if ($result === true) {
173 $query = explode('&', parse_url($return_url, PHP_URL_QUERY
));
174 $return_url = parse_url($return_url, PHP_URL_PATH
);
175 foreach ($query as $q) {
176 $pos = strpos($q, '=');
177 $k = substr($q, 0, $pos);
181 $params[$k] = substr($q, $pos+
1);
184 $return_url = 'prefs_manage.php';
187 $GLOBALS['PMA_Config']->loadUserPreferences();
188 PMA_userprefs_redirect($forms, $old_settings, $return_url, $params);
194 } else if (isset($_POST['submit_clear'])) {
195 $old_settings = PMA_load_userprefs();
196 $result = PMA_save_userprefs(array());
197 if ($result === true) {
199 if ($_SESSION['PMA_Theme_Manager']->theme
->getId() != 'original') {
200 $GLOBALS['PMA_Config']->removeCookie($_SESSION['PMA_Theme_Manager']->getThemeCookieName());
201 unset($_SESSION['PMA_Theme_Manager']);
202 unset($_SESSION['PMA_Theme']);
203 $params['reload_left_frame'] = true;
205 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
206 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
207 $params['reload_left_frame'] = true;
209 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
210 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
211 PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params);
219 $GLOBALS['js_include'][] = 'config.js';
220 require 'libraries/header.inc.php';
221 require 'libraries/user_preferences.inc.php';
223 if (!$error instanceof PMA_Message
) {
224 $error = PMA_Message
::error($error);
229 <script type
="text/javascript">
231 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
234 <div id
="maincontainer">
235 <div id
="main_pane_left">
237 <h2
><?php
echo __('Import') ?
></h2
>
238 <form
class="group-cnt prefs-form" name
="prefs_import" action
="prefs_manage.php" method
="post" enctype
="multipart/form-data">
240 echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
241 echo PMA_generate_common_hidden_inputs() . "\n";
243 <input type
="hidden" name
="json" value
="" />
244 <input type
="radio" id
="import_text_file" name
="import_type" value
="text_file" checked
="checked" />
245 <label
for="import_text_file"><?php
echo __('Import from file') ?
></label
>
246 <div id
="opts_import_text_file" class="prefsmanage_opts">
247 <label
for="input_import_file"><?php
echo __('Browse your computer:'); ?
></label
>
248 <input type
="file" name
="import_file" id
="input_import_file" />
250 <input type
="radio" id
="import_local_storage" name
="import_type" value
="local_storage" disabled
="disabled" />
251 <label
for="import_local_storage"><?php
echo __('Import from browser\'s storage') ?
></label
>
252 <div id
="opts_import_local_storage" class="prefsmanage_opts disabled">
253 <div
class="localStorage-supported">
254 <?php
echo __('Settings will be imported from your browser\'s local storage.') ?
>
256 <div
class="localStorage-exists">
257 <?php
echo __('Saved on: @DATE@') ?
>
259 <div
class="localStorage-empty">
260 <?php PMA_Message
::notice(__('You have no saved settings!'))->display() ?
>
263 <div
class="localStorage-unsupported">
264 <?php PMA_Message
::notice(__('This feature is not supported by your web browser'))->display() ?
>
268 <input type
="checkbox" id
="import_merge" name
="import_merge" />
269 <label
for="import_merge"><?php
echo __('Merge with current configuration') ?
></label
>
271 <input type
="submit" name
="submit_import" value
="<?php echo __('Go'); ?>" />
275 if (file_exists('setup/index.php')) {
276 // show only if setup script is available, allows to disable this message
277 // by simply removing setup directory
280 <h2
><?php
echo __('More settings') ?
></h2
>
281 <div
class="group-cnt">
283 echo sprintf(__('You can set more settings by modifying config.inc.php, eg. by using %sSetup script%s.'), '<a href="setup/index.php">', '</a>');
284 echo PMA_showDocu('setup_script');
292 <div id
="main_pane_right">
294 <h2
><?php
echo __('Export') ?
></h2
>
295 <div
class="click-hide-message group-cnt" style
="display:none">
297 $message = PMA_Message
::rawSuccess(__('Configuration has been saved'));
301 <form
class="group-cnt prefs-form" name
="prefs_export" action
="prefs_manage.php" method
="post">
302 <?php
echo PMA_generate_common_hidden_inputs() . "\n" ?
>
303 <div style
="padding-bottom:0.5em">
304 <input type
="radio" id
="export_text_file" name
="export_type" value
="text_file" checked
="checked" />
305 <label
for="export_text_file"><?php
echo __('Save as file') ?
></label
>
307 <input type
="radio" id
="export_local_storage" name
="export_type" value
="local_storage" disabled
="disabled" />
308 <label
for="export_local_storage"><?php
echo __('Save to browser\'s storage') ?
></label
>
310 <div id
="opts_export_local_storage" class="prefsmanage_opts disabled">
311 <span
class="localStorage-supported">
312 <?php
echo __('Settings will be saved in your browser\'s local storage.') ?
>
313 <span
class="localStorage-exists">
314 <br
/><b
><?php
echo __('Existing settings will be overwritten!') ?
></b
>
317 <div
class="localStorage-unsupported">
318 <?php PMA_Message
::notice(__('This feature is not supported by your web browser'))->display() ?
>
322 <input type
="submit" name
="submit_export" value
="<?php echo __('Go'); ?>" />
326 <h2
><?php
echo __('Reset') ?
></h2
>
327 <form
class="group-cnt prefs-form" name
="prefs_reset" action
="prefs_manage.php" method
="post">
328 <?php
echo PMA_generate_common_hidden_inputs() . "\n" ?
>
329 <?php
echo __('You can reset all your settings and restore them to default values.') ?
>
331 <input type
="submit" name
="submit_clear" value
="<?php echo __('Reset') ?>" />
336 <br
class="clearfloat" />
340 * Displays the footer
342 require 'libraries/footer.inc.php';