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