2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
8 use PMA\libraries\config\ConfigFile
;
9 use PMA\libraries\config\FormDisplay
;
10 use PMA\libraries\Message
;
11 use PMA\libraries\Response
;
12 use PMA\libraries\PMA_String
;
13 use PMA\libraries\Util
;
16 * Gets some core libraries and displays a top message if required
18 require_once 'libraries/common.inc.php';
19 require_once 'libraries/user_preferences.lib.php';
20 require_once 'libraries/config/config_functions.lib.php';
21 require_once 'libraries/config/messages.inc.php';
22 require 'libraries/config/user_preferences.forms.php';
24 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
25 PMA_userprefsPageInit($cf);
28 if (isset($_POST['submit_export'])
29 && isset($_POST['export_type'])
30 && $_POST['export_type'] == 'text_file'
32 // export to JSON file
33 PMA\libraries\Response
::getInstance()->disable();
34 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
35 PMA_downloadHeader($filename, 'application/json');
36 $settings = PMA_loadUserprefs();
37 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT
);
39 } else if (isset($_POST['submit_get_json'])) {
40 $settings = PMA_loadUserprefs();
41 $response = PMA\libraries\Response
::getInstance();
42 $response->addJSON('prefs', json_encode($settings['config_data']));
43 $response->addJSON('mtime', $settings['mtime']);
45 } else if (isset($_POST['submit_import'])) {
46 // load from JSON file
48 if (isset($_POST['import_type'])
49 && $_POST['import_type'] == 'text_file'
50 && isset($_FILES['import_file'])
51 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
52 && is_uploaded_file($_FILES['import_file']['tmp_name'])
54 // read JSON from uploaded file
55 $open_basedir = @ini_get
('open_basedir');
57 $import_file = $_FILES['import_file']['tmp_name'];
59 // If we are on a server with open_basedir, we must move the file
60 // before opening it. The doc explains how to create the "./tmp"
62 if (!empty($open_basedir)) {
63 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : 'tmp/');
64 if (is_writable($tmp_subdir)) {
65 $import_file_new = tempnam($tmp_subdir, 'prefs');
66 if (move_uploaded_file($import_file, $import_file_new)) {
67 $import_file = $import_file_new;
68 $file_to_unlink = $import_file_new;
72 $json = file_get_contents($import_file);
73 if ($file_to_unlink) {
74 unlink($file_to_unlink);
77 // read from POST value (json)
78 $json = isset($_POST['json']) ?
$_POST['json'] : null;
81 // hide header message
82 $_SESSION['userprefs_autoload'] = true;
84 $config = json_decode($json, true);
85 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
86 if (! is_array($config)) {
87 $error = __('Could not import configuration');
89 // sanitize input values: treat them as though
90 // they came from HTTP POST request
91 $form_display = new FormDisplay($cf);
92 foreach ($forms as $formset_id => $formset) {
93 foreach ($formset as $form_name => $form) {
94 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
97 $new_config = $cf->getFlatDefaultConfig();
98 if (!empty($_POST['import_merge'])) {
99 $new_config = array_merge($new_config, $cf->getConfigArray());
101 $new_config = array_merge($new_config, $config);
103 foreach ($new_config as $k => $v) {
104 $_POST[str_replace('/', '-', $k)] = $v;
106 $cf->resetConfigData();
107 $all_ok = $form_display->process(true, false);
108 $all_ok = $all_ok && !$form_display->hasErrors();
111 if (!$all_ok && isset($_POST['fix_errors'])) {
112 $form_display->fixErrors();
116 // mimic original form and post json in a hidden field
117 include 'libraries/user_preferences.inc.php';
118 $msg = Message
::error(
119 __('Configuration contains incorrect data for some fields.')
122 echo '<div class="config-form">';
123 echo $form_display->displayErrors();
125 echo '<form action="prefs_manage.php" method="post">';
126 echo PMA_URL_getHiddenInputs() . "\n";
127 echo '<input type="hidden" name="json" value="'
128 . htmlspecialchars($json) . '" />';
129 echo '<input type="hidden" name="fix_errors" value="1" />';
130 if (! empty($_POST['import_merge'])) {
131 echo '<input type="hidden" name="import_merge" value="1" />';
134 echo '<input type="hidden" name="return_url" value="'
135 . htmlspecialchars($return_url) . '" />';
138 echo __('Do you want to import remaining settings?');
140 echo '<input type="submit" name="submit_import" value="'
141 . __('Yes') . '" />';
142 echo '<input type="submit" name="submit_ignore" value="'
148 // check for ThemeDefault and fontsize
150 if (isset($config['ThemeDefault'])
151 && $_SESSION['PMA_Theme_Manager']->theme
->getId() != $config['ThemeDefault']
152 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
154 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
155 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
157 if (isset($config['fontsize'])
158 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
160 $params['set_fontsize'] = $config['fontsize'];
162 if (isset($config['lang'])
163 && $config['lang'] != $GLOBALS['lang']
165 $params['lang'] = $config['lang'];
167 if (isset($config['collation_connection'])
168 && $config['collation_connection'] != $GLOBALS['collation_connection']
170 $params['collation_connection'] = $config['collation_connection'];
174 $result = PMA_saveUserprefs($cf->getConfigArray());
175 if ($result === true) {
177 $query = explode('&', parse_url($return_url, PHP_URL_QUERY
));
178 $return_url = parse_url($return_url, PHP_URL_PATH
);
180 /** @var String $pmaString */
181 $pmaString = $GLOBALS['PMA_String'];
183 foreach ($query as $q) {
184 $pos = /*overload*/mb_strpos($q, '=');
185 $k = /*overload*/mb_substr($q, 0, $pos);
189 $params[$k] = /*overload*/mb_substr($q, $pos +
1);
192 $return_url = 'prefs_manage.php';
195 $GLOBALS['PMA_Config']->loadUserPreferences();
196 PMA_userprefsRedirect($return_url, $params);
202 } else if (isset($_POST['submit_clear'])) {
203 $result = PMA_saveUserprefs(array());
204 if ($result === true) {
206 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
207 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
209 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
210 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
211 PMA_userprefsRedirect('prefs_manage.php', $params);
219 $response = Response
::getInstance();
220 $header = $response->getHeader();
221 $scripts = $header->getScripts();
222 $scripts->addFile('config.js');
224 require 'libraries/user_preferences.inc.php';
226 if (!$error instanceof Message
) {
227 $error = Message
::error($error);
232 <script type
="text/javascript">
234 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
237 <div id
="maincontainer">
238 <div id
="main_pane_left">
241 echo '<h2>' . __('Import') . '</h2>'
242 . '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
243 . ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
244 . Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
245 . PMA_URL_getHiddenInputs()
246 . '<input type="hidden" name="json" value="" />'
247 . '<input type="radio" id="import_text_file" name="import_type"'
248 . ' value="text_file" checked="checked" />'
249 . '<label for="import_text_file">' . __('Import from file') . '</label>'
250 . '<div id="opts_import_text_file" class="prefsmanage_opts">'
251 . '<label for="input_import_file">' . __('Browse your computer:') . '</label>'
252 . '<input type="file" name="import_file" id="input_import_file" />'
254 . '<input type="radio" id="import_local_storage" name="import_type"'
255 . ' value="local_storage" disabled="disabled" />'
256 . '<label for="import_local_storage">'
257 . __('Import from browser\'s storage') . '</label>'
258 . '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
259 . '<div class="localStorage-supported">'
260 . __('Settings will be imported from your browser\'s local storage.')
262 . '<div class="localStorage-exists">'
263 . __('Saved on: @DATE@')
265 . '<div class="localStorage-empty">';
266 Message
::notice(__('You have no saved settings!'))->display();
269 . '<div class="localStorage-unsupported">';
271 __('This feature is not supported by your web browser')
275 . '<input type="checkbox" id="import_merge" name="import_merge" />'
276 . '<label for="import_merge">'
277 . __('Merge with current configuration') . '</label>'
279 . '<input type="submit" name="submit_import" value="'
283 if (file_exists('setup/index.php')) {
284 // show only if setup script is available, allows to disable this message
285 // by simply removing setup directory
288 <h2
><?php
echo __('More settings') ?
></h2
>
289 <div
class="group-cnt">
293 'You can set more settings by modifying config.inc.php, eg. '
294 . 'by using %sSetup script%s.'
295 ), '<a href="setup/index.php" target="_blank">', '</a>'
296 ) . PMA\libraries\Util
::showDocu('setup', 'setup-script');
304 <div id
="main_pane_right">
306 <h2
><?php
echo __('Export'); ?
></h2
>
307 <div
class="click-hide-message group-cnt" style
="display:none">
310 __('Configuration has been saved.')
314 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
315 action
="prefs_manage.php" method
="post">
316 <?php
echo PMA_URL_getHiddenInputs(); ?
>
317 <div style
="padding-bottom:0.5em">
318 <input type
="radio" id
="export_text_file" name
="export_type"
319 value
="text_file" checked
="checked" />
320 <label
for="export_text_file">
321 <?php
echo __('Save as file'); ?
>
323 <input type
="radio" id
="export_local_storage" name
="export_type"
324 value
="local_storage" disabled
="disabled" />
325 <label
for="export_local_storage">
326 <?php
echo __('Save to browser\'s storage'); ?
></label
>
328 <div id
="opts_export_local_storage"
329 class="prefsmanage_opts disabled">
330 <span
class="localStorage-supported">
333 'Settings will be saved in your browser\'s local '
337 <div
class="localStorage-exists">
341 'Existing settings will be overwritten!'
347 <div
class="localStorage-unsupported">
350 __('This feature is not supported by your web browser')
357 echo '<input type="submit" name="submit_export" value="' . __(
364 <h2
><?php
echo __('Reset'); ?
></h2
>
365 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
366 action
="prefs_manage.php" method
="post">
368 echo PMA_URL_getHiddenInputs() . __(
369 'You can reset all your settings and restore them to default '
374 <input type
="submit" name
="submit_clear"
375 value
="<?php echo __('Reset'); ?>"/>
379 <br
class="clearfloat" />
383 if ($response->isAjax()) {
384 $response->addJSON('_disableNaviSettings', true);
386 define('PMA_DISABLE_NAVI_SETTINGS', true);