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