Merge remote-tracking branch 'origin/QA_4_4' into QA_4_4
[phpmyadmin.git] / prefs_manage.php
blob3eb10a36e78b40435d1459bc633304817a38c9a6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
6 * @package PhpMyAdmin
7 */
9 /**
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 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
22 PMA_userprefsPageInit($cf);
24 $error = '';
25 if (isset($_POST['submit_export'])
26 && filter_input(INPUT_POST, 'export_type') == 'text_file'
27 ) {
28 // export to JSON file
29 PMA_Response::getInstance()->disable();
30 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
31 PMA_downloadHeader($filename, 'application/json');
32 $settings = PMA_loadUserprefs();
33 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
34 exit;
35 } else if (isset($_POST['submit_get_json'])) {
36 $settings = PMA_loadUserprefs();
37 $response = PMA_Response::getInstance();
38 $response->addJSON('prefs', json_encode($settings['config_data']));
39 $response->addJSON('mtime', $settings['mtime']);
40 exit;
41 } else if (isset($_POST['submit_import'])) {
42 // load from JSON file
43 $json = '';
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'])
48 ) {
49 // read JSON from uploaded file
50 $open_basedir = @ini_get('open_basedir');
51 $file_to_unlink = '';
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"
56 // directory
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);
71 } else {
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');
83 } else {
84 // sanitize input values: treat them as though
85 // they came from HTTP POST request
86 $form_display = new FormDisplay($cf);
87 foreach ($forms as $formset_id => $formset) {
88 foreach ($formset as $form_name => $form) {
89 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
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);
97 $_POST_bak = $_POST;
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();
104 $_POST = $_POST_bak;
106 if (!$all_ok && isset($_POST['fix_errors'])) {
107 $form_display->fixErrors();
108 $all_ok = true;
110 if (!$all_ok) {
111 // mimic original form and post json in a hidden field
112 include 'libraries/user_preferences.inc.php';
113 $msg = PMA_Message::error(
114 __('Configuration contains incorrect data for some fields.')
116 $msg->display();
117 echo '<div class="config-form">';
118 $form_display->displayErrors();
119 echo '</div>';
120 echo '<form action="prefs_manage.php" method="post">';
121 echo PMA_URL_getHiddenInputs() . "\n";
122 echo '<input type="hidden" name="json" value="'
123 . htmlspecialchars($json) . '" />';
124 echo '<input type="hidden" name="fix_errors" value="1" />';
125 if (! empty($_POST['import_merge'])) {
126 echo '<input type="hidden" name="import_merge" value="1" />';
128 if ($return_url) {
129 echo '<input type="hidden" name="return_url" value="'
130 . htmlspecialchars($return_url) . '" />';
132 echo '<p>';
133 echo __('Do you want to import remaining settings?');
134 echo '</p>';
135 echo '<input type="submit" name="submit_import" value="'
136 . __('Yes') . '" />';
137 echo '<input type="submit" name="submit_ignore" value="'
138 . __('No') . '" />';
139 echo '</form>';
140 exit;
143 // check for ThemeDefault and fontsize
144 $params = array();
145 if (isset($config['ThemeDefault'])
146 && $_SESSION['PMA_Theme_Manager']->theme->getId() != $config['ThemeDefault']
147 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
149 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
150 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
152 if (isset($config['fontsize'])
153 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
155 $params['set_fontsize'] = $config['fontsize'];
157 if (isset($config['lang'])
158 && $config['lang'] != $GLOBALS['lang']
160 $params['lang'] = $config['lang'];
162 if (isset($config['collation_connection'])
163 && $config['collation_connection'] != $GLOBALS['collation_connection']
165 $params['collation_connection'] = $config['collation_connection'];
168 // save settings
169 $result = PMA_saveUserprefs($cf->getConfigArray());
170 if ($result === true) {
171 if ($return_url) {
172 $query = explode('&', parse_url($return_url, PHP_URL_QUERY));
173 $return_url = parse_url($return_url, PHP_URL_PATH);
175 /** @var PMA_String $pmaString */
176 $pmaString = $GLOBALS['PMA_String'];
178 foreach ($query as $q) {
179 $pos = /*overload*/mb_strpos($q, '=');
180 $k = /*overload*/mb_substr($q, 0, $pos);
181 if ($k == 'token') {
182 continue;
184 $params[$k] = /*overload*/mb_substr($q, $pos+1);
186 } else {
187 $return_url = 'prefs_manage.php';
189 // reload config
190 $GLOBALS['PMA_Config']->loadUserPreferences();
191 PMA_userprefsRedirect($return_url, $params);
192 exit;
193 } else {
194 $error = $result;
197 } else if (isset($_POST['submit_clear'])) {
198 $result = PMA_saveUserprefs(array());
199 if ($result === true) {
200 $params = array();
201 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
202 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
204 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
205 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
206 PMA_userprefsRedirect('prefs_manage.php', $params);
207 exit;
208 } else {
209 $error = $result;
211 exit;
214 $response = PMA_Response::getInstance();
215 $header = $response->getHeader();
216 $scripts = $header->getScripts();
217 $scripts->addFile('config.js');
219 require 'libraries/user_preferences.inc.php';
220 if ($error) {
221 if (!$error instanceof PMA_Message) {
222 $error = PMA_Message::error($error);
224 $error->display();
227 <script type="text/javascript">
228 <?php
229 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
231 </script>
232 <div id="maincontainer">
233 <div id="main_pane_left">
234 <div class="group">
235 <?php
236 echo '<h2>' . __('Import') . '</h2>'
237 . '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
238 . ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
239 . PMA_Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
240 . PMA_URL_getHiddenInputs()
241 . '<input type="hidden" name="json" value="" />'
242 . '<input type="radio" id="import_text_file" name="import_type"'
243 . ' value="text_file" checked="checked" />'
244 . '<label for="import_text_file">' . __('Import from file') . '</label>'
245 . '<div id="opts_import_text_file" class="prefsmanage_opts">'
246 . '<label for="input_import_file">' . __('Browse your computer:') . '</label>'
247 . '<input type="file" name="import_file" id="input_import_file" />'
248 . '</div>'
249 . '<input type="radio" id="import_local_storage" name="import_type"'
250 . ' value="local_storage" disabled="disabled" />'
251 . '<label for="import_local_storage">'
252 . __('Import from browser\'s storage') . '</label>'
253 . '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
254 . '<div class="localStorage-supported">'
255 . __('Settings will be imported from your browser\'s local storage.')
256 . '<br />'
257 . '<div class="localStorage-exists">'
258 . __('Saved on: @DATE@')
259 . '</div>'
260 . '<div class="localStorage-empty">';
261 PMA_Message::notice(__('You have no saved settings!'))->display();
262 echo '</div>'
263 . '</div>'
264 . '<div class="localStorage-unsupported">';
265 PMA_Message::notice(
266 __('This feature is not supported by your web browser')
267 )->display();
268 echo '</div>'
269 . '</div>'
270 . '<input type="checkbox" id="import_merge" name="import_merge" />'
271 . '<label for="import_merge">'
272 . __('Merge with current configuration') . '</label>'
273 . '<br /><br />'
274 . '<input type="submit" name="submit_import" value="'
275 . __('Go') . '" />'
276 . '</form>'
277 . '</div>';
278 if (file_exists('setup/index.php')) {
279 // show only if setup script is available, allows to disable this message
280 // by simply removing setup directory
282 <div class="group">
283 <h2><?php echo __('More settings') ?></h2>
284 <div class="group-cnt">
285 <?php
286 echo sprintf(
288 'You can set more settings by modifying config.inc.php, eg. '
289 . 'by using %sSetup script%s.'
290 ), '<a href="setup/index.php" target="_blank">', '</a>'
291 ) . PMA_Util::showDocu('setup', 'setup-script');
293 </div>
294 </div>
295 <?php
298 </div>
299 <div id="main_pane_right">
300 <div class="group">
301 <h2><?php echo __('Export'); ?></h2>
302 <div class="click-hide-message group-cnt" style="display:none">
303 <?php
304 PMA_Message::rawSuccess(
305 __('Configuration has been saved.')
306 )->display();
308 </div>
309 <form class="group-cnt prefs-form disableAjax" name="prefs_export"
310 action="prefs_manage.php" method="post">
311 <?php echo PMA_URL_getHiddenInputs(); ?>
312 <div style="padding-bottom:0.5em">
313 <input type="radio" id="export_text_file" name="export_type"
314 value="text_file" checked="checked" />
315 <label for="export_text_file">
316 <?php echo __('Save as file'); ?>
317 </label><br />
318 <input type="radio" id="export_local_storage" name="export_type"
319 value="local_storage" disabled="disabled" />
320 <label for="export_local_storage">
321 <?php echo __('Save to browser\'s storage'); ?></label>
322 </div>
323 <div id="opts_export_local_storage"
324 class="prefsmanage_opts disabled">
325 <span class="localStorage-supported">
326 <?php
327 echo __(
328 'Settings will be saved in your browser\'s local '
329 . 'storage.'
332 <div class="localStorage-exists">
334 <?php
335 echo __(
336 'Existing settings will be overwritten!'
339 </b>
340 </div>
341 </span>
342 <div class="localStorage-unsupported">
343 <?php
344 PMA_Message::notice(
345 __('This feature is not supported by your web browser')
346 )->display();
348 </div>
349 </div>
350 <br />
351 <?php
352 echo '<input type="submit" name="submit_export" value="' . __(
353 'Go'
354 ) . '" />';
356 </form>
357 </div>
358 <div class="group">
359 <h2><?php echo __('Reset'); ?></h2>
360 <form class="group-cnt prefs-form disableAjax" name="prefs_reset"
361 action="prefs_manage.php" method="post">
362 <?php
363 echo PMA_URL_getHiddenInputs() . __(
364 'You can reset all your settings and restore them to default '
365 . 'values.'
368 <br /><br />
369 <input type="submit" name="submit_clear"
370 value="<?php echo __('Reset'); ?>"/>
371 </form>
372 </div>
373 </div>
374 <br class="clearfloat" />
375 </div>