Translated using Weblate (German)
[phpmyadmin.git] / prefs_manage.php
blob3dddc702ebd5566b05ed9e4757fd4057ada9171f
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Config\ConfigFile;
11 use PhpMyAdmin\Config\Forms\User\UserFormList;
12 use PhpMyAdmin\Core;
13 use PhpMyAdmin\File;
14 use PhpMyAdmin\Message;
15 use PhpMyAdmin\Response;
16 use PhpMyAdmin\Sanitize;
17 use PhpMyAdmin\ThemeManager;
18 use PhpMyAdmin\Url;
19 use PhpMyAdmin\UserPreferences;
20 use PhpMyAdmin\Util;
22 /**
23 * Gets some core libraries and displays a top message if required
25 require_once 'libraries/common.inc.php';
27 $userPreferences = new UserPreferences();
29 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
30 $userPreferences->pageInit($cf);
31 $response = Response::getInstance();
33 $error = '';
34 if (isset($_POST['submit_export'])
35 && isset($_POST['export_type'])
36 && $_POST['export_type'] == 'text_file'
37 ) {
38 // export to JSON file
39 $response->disable();
40 $filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.json';
41 Core::downloadHeader($filename, 'application/json');
42 $settings = $userPreferences->load();
43 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
44 exit;
45 } elseif (isset($_POST['submit_export'])
46 && isset($_POST['export_type'])
47 && $_POST['export_type'] == 'php_file'
48 ) {
49 // export to JSON file
50 $response->disable();
51 $filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.php';
52 Core::downloadHeader($filename, 'application/php');
53 $settings = $userPreferences->load();
54 echo '/* ' . __('phpMyAdmin configuration snippet') . " */\n\n";
55 echo '/* ' . __('Paste it to your config.inc.php') . " */\n\n";
56 foreach ($settings['config_data'] as $key => $val) {
57 echo '$cfg[\'' . str_replace('/', '\'][\'', $key) . '\'] = ';
58 echo var_export($val, true) . ";\n";
60 exit;
61 } elseif (isset($_POST['submit_get_json'])) {
62 $settings = $userPreferences->load();
63 $response->addJSON('prefs', json_encode($settings['config_data']));
64 $response->addJSON('mtime', $settings['mtime']);
65 exit;
66 } elseif (isset($_POST['submit_import'])) {
67 // load from JSON file
68 $json = '';
69 if (isset($_POST['import_type'])
70 && $_POST['import_type'] == 'text_file'
71 && isset($_FILES['import_file'])
72 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
73 && is_uploaded_file($_FILES['import_file']['tmp_name'])
74 ) {
75 $import_handle = new File($_FILES['import_file']['tmp_name']);
76 $import_handle->checkUploadedFile();
77 if ($import_handle->isError()) {
78 $error = $import_handle->getError();
79 } else {
80 // read JSON from uploaded file
81 $json = $import_handle->getRawContent();
83 } else {
84 // read from POST value (json)
85 $json = isset($_POST['json']) ? $_POST['json'] : null;
88 // hide header message
89 $_SESSION['userprefs_autoload'] = true;
91 $config = json_decode($json, true);
92 $return_url = isset($_POST['return_url']) ? $_POST['return_url'] : null;
93 if (! is_array($config)) {
94 if (! isset($error)) {
95 $error = __('Could not import configuration');
97 } else {
98 // sanitize input values: treat them as though
99 // they came from HTTP POST request
100 $form_display = new UserFormList($cf);
101 $new_config = $cf->getFlatDefaultConfig();
102 if (!empty($_POST['import_merge'])) {
103 $new_config = array_merge($new_config, $cf->getConfigArray());
105 $new_config = array_merge($new_config, $config);
106 $_POST_bak = $_POST;
107 foreach ($new_config as $k => $v) {
108 $_POST[str_replace('/', '-', $k)] = $v;
110 $cf->resetConfigData();
111 $all_ok = $form_display->process(true, false);
112 $all_ok = $all_ok && !$form_display->hasErrors();
113 $_POST = $_POST_bak;
115 if (!$all_ok && isset($_POST['fix_errors'])) {
116 $form_display->fixErrors();
117 $all_ok = true;
119 if (!$all_ok) {
120 // mimic original form and post json in a hidden field
121 include 'libraries/user_preferences.inc.php';
122 $msg = Message::error(
123 __('Configuration contains incorrect data for some fields.')
125 $msg->display();
126 echo '<div class="config-form">';
127 echo $form_display->displayErrors();
128 echo '</div>';
129 echo '<form action="prefs_manage.php" method="post">';
130 echo Url::getHiddenInputs() , "\n";
131 echo '<input type="hidden" name="json" value="'
132 , htmlspecialchars($json) , '" />';
133 echo '<input type="hidden" name="fix_errors" value="1" />';
134 if (! empty($_POST['import_merge'])) {
135 echo '<input type="hidden" name="import_merge" value="1" />';
137 if ($return_url) {
138 echo '<input type="hidden" name="return_url" value="'
139 , htmlspecialchars($return_url) , '" />';
141 echo '<p>';
142 echo __('Do you want to import remaining settings?');
143 echo '</p>';
144 echo '<input type="submit" name="submit_import" value="'
145 , __('Yes') , '" />';
146 echo '<input type="submit" name="submit_ignore" value="'
147 , __('No') , '" />';
148 echo '</form>';
149 exit;
152 // check for ThemeDefault
153 $params = [];
154 $tmanager = ThemeManager::getInstance();
155 if (isset($config['ThemeDefault'])
156 && $tmanager->theme->getId() != $config['ThemeDefault']
157 && $tmanager->checkTheme($config['ThemeDefault'])
159 $tmanager->setActiveTheme($config['ThemeDefault']);
160 $tmanager->setThemeCookie();
162 if (isset($config['lang'])
163 && $config['lang'] != $GLOBALS['lang']
165 $params['lang'] = $config['lang'];
168 // save settings
169 $result = $userPreferences->save($cf->getConfigArray());
170 if ($result === true) {
171 if ($return_url) {
172 $query = PhpMyAdmin\Util::splitURLQuery($return_url);
173 $return_url = parse_url($return_url, PHP_URL_PATH);
175 foreach ($query as $q) {
176 $pos = mb_strpos($q, '=');
177 $k = mb_substr($q, 0, $pos);
178 if ($k == 'token') {
179 continue;
181 $params[$k] = mb_substr($q, $pos + 1);
183 } else {
184 $return_url = 'prefs_manage.php';
186 // reload config
187 $GLOBALS['PMA_Config']->loadUserPreferences();
188 $userPreferences->redirect($return_url, $params);
189 exit;
190 } else {
191 $error = $result;
194 } elseif (isset($_POST['submit_clear'])) {
195 $result = $userPreferences->save([]);
196 if ($result === true) {
197 $params = [];
198 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
199 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
200 $userPreferences->redirect('prefs_manage.php', $params);
201 exit;
202 } else {
203 $error = $result;
205 exit;
208 $response = Response::getInstance();
209 $header = $response->getHeader();
210 $scripts = $header->getScripts();
211 $scripts->addFile('config.js');
213 require 'libraries/user_preferences.inc.php';
214 if ($error) {
215 if (!$error instanceof Message) {
216 $error = Message::error($error);
218 $error->display();
221 <script type="text/javascript">
222 <?php
223 Sanitize::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
225 </script>
226 <div id="maincontainer">
227 <div id="main_pane_left">
228 <div class="group">
229 <?php
230 echo '<h2>' , __('Import') , '</h2>'
231 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
232 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
233 , Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
234 , Url::getHiddenInputs()
235 , '<input type="hidden" name="json" value="" />'
236 , '<input type="radio" id="import_text_file" name="import_type"'
237 , ' value="text_file" checked="checked" />'
238 , '<label for="import_text_file">' . __('Import from file') . '</label>'
239 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
240 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
241 , '<input type="file" name="import_file" id="input_import_file" />'
242 , '</div>'
243 , '<input type="radio" id="import_local_storage" name="import_type"'
244 , ' value="local_storage" disabled="disabled" />'
245 , '<label for="import_local_storage">'
246 , __('Import from browser\'s storage') , '</label>'
247 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
248 , '<div class="localStorage-supported">'
249 , __('Settings will be imported from your browser\'s local storage.')
250 , '<br />'
251 , '<div class="localStorage-exists">'
252 , __('Saved on: @DATE@')
253 , '</div>'
254 , '<div class="localStorage-empty">';
255 Message::notice(__('You have no saved settings!'))->display();
256 echo '</div>'
257 , '</div>'
258 , '<div class="localStorage-unsupported">';
259 Message::notice(
260 __('This feature is not supported by your web browser')
261 )->display();
262 echo '</div>'
263 , '</div>'
264 , '<input type="checkbox" id="import_merge" name="import_merge" />'
265 , '<label for="import_merge">'
266 , __('Merge with current configuration') . '</label>'
267 , '<br /><br />'
268 , '<input type="submit" name="submit_import" value="'
269 , __('Go') . '" />'
270 , '</form>'
271 , '</div>';
272 if (@file_exists('setup/index.php') && ! @file_exists(CONFIG_FILE)) {
273 // show only if setup script is available, allows to disable this message
274 // by simply removing setup directory
275 // Also do not show in config exists (and setup would refuse to work)
277 <div class="group">
278 <h2><?php echo __('More settings') ?></h2>
279 <div class="group-cnt">
280 <?php
281 echo sprintf(
283 'You can set more settings by modifying config.inc.php, eg. '
284 . 'by using %sSetup script%s.'
286 '<a href="setup/index.php" target="_blank">',
287 '</a>'
288 ) , PhpMyAdmin\Util::showDocu('setup', 'setup-script');
290 </div>
291 </div>
292 <?php
295 </div>
296 <div id="main_pane_right">
297 <div class="group">
298 <h2><?php echo __('Export'); ?></h2>
299 <div class="click-hide-message group-cnt hide">
300 <?php
301 Message::rawSuccess(
302 __('Configuration has been saved.')
303 )->display();
305 </div>
306 <form class="group-cnt prefs-form disableAjax" name="prefs_export"
307 action="prefs_manage.php" method="post">
308 <?php echo Url::getHiddenInputs(); ?>
309 <div>
310 <input type="radio" id="export_text_file" name="export_type"
311 value="text_file" checked="checked" />
312 <label for="export_text_file">
313 <?php echo __('Save as file'); ?>
314 </label><br />
315 <input type="radio" id="export_php_file" name="export_type"
316 value="php_file" />
317 <label for="export_php_file">
318 <?php echo __('Save as PHP file'); ?>
319 </label><br />
320 <input type="radio" id="export_local_storage" name="export_type"
321 value="local_storage" disabled="disabled" />
322 <label for="export_local_storage">
323 <?php echo __('Save to browser\'s storage'); ?></label>
324 </div>
325 <div id="opts_export_local_storage"
326 class="prefsmanage_opts disabled">
327 <span class="localStorage-supported">
328 <?php
329 echo __(
330 'Settings will be saved in your browser\'s local '
331 . 'storage.'
334 <div class="localStorage-exists">
336 <?php
337 echo __(
338 'Existing settings will be overwritten!'
341 </b>
342 </div>
343 </span>
344 <div class="localStorage-unsupported">
345 <?php
346 Message::notice(
347 __('This feature is not supported by your web browser')
348 )->display();
350 </div>
351 </div>
352 <br />
353 <?php
354 echo '<input type="submit" name="submit_export" value="' , __(
355 'Go'
356 ) , '" />';
358 </form>
359 </div>
360 <div class="group">
361 <h2><?php echo __('Reset'); ?></h2>
362 <form class="group-cnt prefs-form disableAjax" name="prefs_reset"
363 action="prefs_manage.php" method="post">
364 <?php
365 echo Url::getHiddenInputs() , __(
366 'You can reset all your settings and restore them to default '
367 . 'values.'
370 <br /><br />
371 <input type="submit" name="submit_clear"
372 value="<?php echo __('Reset'); ?>"/>
373 </form>
374 </div>
375 </div>
376 <br class="clearfloat" />
377 </div>
379 <?php
380 if ($response->isAjax()) {
381 $response->addJSON('_disableNaviSettings', true);
382 } else {
383 define('PMA_DISABLE_NAVI_SETTINGS', true);