Translated using Weblate (Slovenian)
[phpmyadmin.git] / prefs_manage.php
blobbb03a628ee4749cc541d8999c75ab893e2585f21
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
6 * @package PhpMyAdmin
7 */
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\Util;
13 use PMA\libraries\URL;
14 use PMA\libraries\Sanitize;
16 /**
17 * Gets some core libraries and displays a top message if required
19 require_once 'libraries/common.inc.php';
20 require_once 'libraries/user_preferences.lib.php';
21 require_once 'libraries/config/config_functions.lib.php';
22 require_once 'libraries/config/messages.inc.php';
23 require 'libraries/config/user_preferences.forms.php';
25 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
26 PMA_userprefsPageInit($cf);
28 $error = '';
29 if (isset($_POST['submit_export'])
30 && isset($_POST['export_type'])
31 && $_POST['export_type'] == 'text_file'
32 ) {
33 // export to JSON file
34 PMA\libraries\Response::getInstance()->disable();
35 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
36 PMA_downloadHeader($filename, 'application/json');
37 $settings = PMA_loadUserprefs();
38 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
39 exit;
40 } else if (isset($_POST['submit_get_json'])) {
41 $settings = PMA_loadUserprefs();
42 $response = PMA\libraries\Response::getInstance();
43 $response->addJSON('prefs', json_encode($settings['config_data']));
44 $response->addJSON('mtime', $settings['mtime']);
45 exit;
46 } else if (isset($_POST['submit_import'])) {
47 // load from JSON file
48 $json = '';
49 if (isset($_POST['import_type'])
50 && $_POST['import_type'] == 'text_file'
51 && isset($_FILES['import_file'])
52 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
53 && is_uploaded_file($_FILES['import_file']['tmp_name'])
54 ) {
55 // read JSON from uploaded file
56 $open_basedir = @ini_get('open_basedir');
57 $file_to_unlink = '';
58 $import_file = $_FILES['import_file']['tmp_name'];
60 // If we are on a server with open_basedir, we must move the file
61 // before opening it. The doc explains how to create the "./tmp"
62 // directory
63 if (!empty($open_basedir)) {
64 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : 'tmp/');
65 if (@is_writable($tmp_subdir)) {
66 $import_file_new = tempnam($tmp_subdir, 'prefs');
67 if (move_uploaded_file($import_file, $import_file_new)) {
68 $import_file = $import_file_new;
69 $file_to_unlink = $import_file_new;
73 $json = file_get_contents($import_file);
74 if ($file_to_unlink) {
75 unlink($file_to_unlink);
77 } else {
78 // read from POST value (json)
79 $json = isset($_POST['json']) ? $_POST['json'] : null;
82 // hide header message
83 $_SESSION['userprefs_autoload'] = true;
85 $config = json_decode($json, true);
86 $return_url = isset($_POST['return_url']) ? $_POST['return_url'] : null;
87 if (! is_array($config)) {
88 $error = __('Could not import configuration');
89 } else {
90 // sanitize input values: treat them as though
91 // they came from HTTP POST request
92 $form_display = new FormDisplay($cf);
93 foreach ($forms as $formset_id => $formset) {
94 foreach ($formset as $form_name => $form) {
95 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
98 $new_config = $cf->getFlatDefaultConfig();
99 if (!empty($_POST['import_merge'])) {
100 $new_config = array_merge($new_config, $cf->getConfigArray());
102 $new_config = array_merge($new_config, $config);
103 $_POST_bak = $_POST;
104 foreach ($new_config as $k => $v) {
105 $_POST[str_replace('/', '-', $k)] = $v;
107 $cf->resetConfigData();
108 $all_ok = $form_display->process(true, false);
109 $all_ok = $all_ok && !$form_display->hasErrors();
110 $_POST = $_POST_bak;
112 if (!$all_ok && isset($_POST['fix_errors'])) {
113 $form_display->fixErrors();
114 $all_ok = true;
116 if (!$all_ok) {
117 // mimic original form and post json in a hidden field
118 include 'libraries/user_preferences.inc.php';
119 $msg = Message::error(
120 __('Configuration contains incorrect data for some fields.')
122 $msg->display();
123 echo '<div class="config-form">';
124 echo $form_display->displayErrors();
125 echo '</div>';
126 echo '<form action="prefs_manage.php" method="post">';
127 echo URL::getHiddenInputs() , "\n";
128 echo '<input type="hidden" name="json" value="'
129 , htmlspecialchars($json) , '" />';
130 echo '<input type="hidden" name="fix_errors" value="1" />';
131 if (! empty($_POST['import_merge'])) {
132 echo '<input type="hidden" name="import_merge" value="1" />';
134 if ($return_url) {
135 echo '<input type="hidden" name="return_url" value="'
136 , htmlspecialchars($return_url) , '" />';
138 echo '<p>';
139 echo __('Do you want to import remaining settings?');
140 echo '</p>';
141 echo '<input type="submit" name="submit_import" value="'
142 , __('Yes') , '" />';
143 echo '<input type="submit" name="submit_ignore" value="'
144 , __('No') , '" />';
145 echo '</form>';
146 exit;
149 // check for ThemeDefault and fontsize
150 $params = array();
151 if (isset($config['ThemeDefault'])
152 && $_SESSION['PMA_Theme_Manager']->theme->getId() != $config['ThemeDefault']
153 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
155 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
156 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
158 if (isset($config['fontsize'])
159 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
161 $params['set_fontsize'] = $config['fontsize'];
163 if (isset($config['lang'])
164 && $config['lang'] != $GLOBALS['lang']
166 $params['lang'] = $config['lang'];
168 if (isset($config['collation_connection'])
169 && $config['collation_connection'] != $GLOBALS['collation_connection']
171 $params['collation_connection'] = $config['collation_connection'];
174 // save settings
175 $result = PMA_saveUserprefs($cf->getConfigArray());
176 if ($result === true) {
177 if ($return_url) {
178 $query = explode('&', parse_url($return_url, PHP_URL_QUERY));
179 $return_url = parse_url($return_url, PHP_URL_PATH);
181 foreach ($query as $q) {
182 $pos = mb_strpos($q, '=');
183 $k = mb_substr($q, 0, $pos);
184 if ($k == 'token') {
185 continue;
187 $params[$k] = mb_substr($q, $pos + 1);
189 } else {
190 $return_url = 'prefs_manage.php';
192 // reload config
193 $GLOBALS['PMA_Config']->loadUserPreferences();
194 PMA_userprefsRedirect($return_url, $params);
195 exit;
196 } else {
197 $error = $result;
200 } else if (isset($_POST['submit_clear'])) {
201 $result = PMA_saveUserprefs(array());
202 if ($result === true) {
203 $params = array();
204 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
205 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
207 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
208 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
209 PMA_userprefsRedirect('prefs_manage.php', $params);
210 exit;
211 } else {
212 $error = $result;
214 exit;
217 $response = Response::getInstance();
218 $header = $response->getHeader();
219 $scripts = $header->getScripts();
220 $scripts->addFile('config.js');
222 require 'libraries/user_preferences.inc.php';
223 if ($error) {
224 if (!$error instanceof Message) {
225 $error = Message::error($error);
227 $error->display();
230 <script type="text/javascript">
231 <?php
232 Sanitize::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
234 </script>
235 <div id="maincontainer">
236 <div id="main_pane_left">
237 <div class="group">
238 <?php
239 echo '<h2>' , __('Import') , '</h2>'
240 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
241 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
242 , Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
243 , URL::getHiddenInputs()
244 , '<input type="hidden" name="json" value="" />'
245 , '<input type="radio" id="import_text_file" name="import_type"'
246 , ' value="text_file" checked="checked" />'
247 , '<label for="import_text_file">' . __('Import from file') . '</label>'
248 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
249 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
250 , '<input type="file" name="import_file" id="input_import_file" />'
251 , '</div>'
252 , '<input type="radio" id="import_local_storage" name="import_type"'
253 , ' value="local_storage" disabled="disabled" />'
254 , '<label for="import_local_storage">'
255 , __('Import from browser\'s storage') , '</label>'
256 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
257 , '<div class="localStorage-supported">'
258 , __('Settings will be imported from your browser\'s local storage.')
259 , '<br />'
260 , '<div class="localStorage-exists">'
261 , __('Saved on: @DATE@')
262 , '</div>'
263 , '<div class="localStorage-empty">';
264 Message::notice(__('You have no saved settings!'))->display();
265 echo '</div>'
266 , '</div>'
267 , '<div class="localStorage-unsupported">';
268 Message::notice(
269 __('This feature is not supported by your web browser')
270 )->display();
271 echo '</div>'
272 , '</div>'
273 , '<input type="checkbox" id="import_merge" name="import_merge" />'
274 , '<label for="import_merge">'
275 , __('Merge with current configuration') . '</label>'
276 , '<br /><br />'
277 , '<input type="submit" name="submit_import" value="'
278 , __('Go') . '" />'
279 , '</form>'
280 , '</div>';
281 if (file_exists('setup/index.php')) {
282 // show only if setup script is available, allows to disable this message
283 // by simply removing setup directory
285 <div class="group">
286 <h2><?php echo __('More settings') ?></h2>
287 <div class="group-cnt">
288 <?php
289 echo sprintf(
291 'You can set more settings by modifying config.inc.php, eg. '
292 . 'by using %sSetup script%s.'
293 ), '<a href="setup/index.php" target="_blank">', '</a>'
294 ) , PMA\libraries\Util::showDocu('setup', 'setup-script');
296 </div>
297 </div>
298 <?php
301 </div>
302 <div id="main_pane_right">
303 <div class="group">
304 <h2><?php echo __('Export'); ?></h2>
305 <div class="click-hide-message group-cnt" style="display:none">
306 <?php
307 Message::rawSuccess(
308 __('Configuration has been saved.')
309 )->display();
311 </div>
312 <form class="group-cnt prefs-form disableAjax" name="prefs_export"
313 action="prefs_manage.php" method="post">
314 <?php echo URL::getHiddenInputs(); ?>
315 <div style="padding-bottom:0.5em">
316 <input type="radio" id="export_text_file" name="export_type"
317 value="text_file" checked="checked" />
318 <label for="export_text_file">
319 <?php echo __('Save as file'); ?>
320 </label><br />
321 <input type="radio" id="export_local_storage" name="export_type"
322 value="local_storage" disabled="disabled" />
323 <label for="export_local_storage">
324 <?php echo __('Save to browser\'s storage'); ?></label>
325 </div>
326 <div id="opts_export_local_storage"
327 class="prefsmanage_opts disabled">
328 <span class="localStorage-supported">
329 <?php
330 echo __(
331 'Settings will be saved in your browser\'s local '
332 . 'storage.'
335 <div class="localStorage-exists">
337 <?php
338 echo __(
339 'Existing settings will be overwritten!'
342 </b>
343 </div>
344 </span>
345 <div class="localStorage-unsupported">
346 <?php
347 Message::notice(
348 __('This feature is not supported by your web browser')
349 )->display();
351 </div>
352 </div>
353 <br />
354 <?php
355 echo '<input type="submit" name="submit_export" value="' , __(
356 'Go'
357 ) , '" />';
359 </form>
360 </div>
361 <div class="group">
362 <h2><?php echo __('Reset'); ?></h2>
363 <form class="group-cnt prefs-form disableAjax" name="prefs_reset"
364 action="prefs_manage.php" method="post">
365 <?php
366 echo URL::getHiddenInputs() , __(
367 'You can reset all your settings and restore them to default '
368 . 'values.'
371 <br /><br />
372 <input type="submit" name="submit_clear"
373 value="<?php echo __('Reset'); ?>"/>
374 </form>
375 </div>
376 </div>
377 <br class="clearfloat" />
378 </div>
380 <?php
381 if ($response->isAjax()) {
382 $response->addJSON('_disableNaviSettings', true);
383 } else {
384 define('PMA_DISABLE_NAVI_SETTINGS', true);