2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config\ConfigFile
;
11 use PhpMyAdmin\Config\Forms\User\UserFormList
;
14 use PhpMyAdmin\Message
;
15 use PhpMyAdmin\Response
;
16 use PhpMyAdmin\Sanitize
;
17 use PhpMyAdmin\ThemeManager
;
19 use PhpMyAdmin\UserPreferences
;
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();
34 if (isset($_POST['submit_export'])
35 && isset($_POST['export_type'])
36 && $_POST['export_type'] == 'text_file'
38 // export to JSON file
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
);
45 } elseif (isset($_POST['submit_export'])
46 && isset($_POST['export_type'])
47 && $_POST['export_type'] == 'php_file'
49 // export to JSON file
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";
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']);
66 } elseif (isset($_POST['submit_import'])) {
67 // load from JSON file
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'])
75 $import_handle = new File($_FILES['import_file']['tmp_name']);
76 $import_handle->checkUploadedFile();
77 if ($import_handle->isError()) {
78 $error = $import_handle->getError();
80 // read JSON from uploaded file
81 $json = $import_handle->getRawContent();
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');
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);
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();
115 if (!$all_ok && isset($_POST['fix_errors'])) {
116 $form_display->fixErrors();
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.')
126 echo '<div class="config-form">';
127 echo $form_display->displayErrors();
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" />';
138 echo '<input type="hidden" name="return_url" value="'
139 , htmlspecialchars($return_url) , '" />';
142 echo __('Do you want to import remaining settings?');
144 echo '<input type="submit" name="submit_import" value="'
145 , __('Yes') , '" />';
146 echo '<input type="submit" name="submit_ignore" value="'
152 // check for ThemeDefault
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'];
169 $result = $userPreferences->save($cf->getConfigArray());
170 if ($result === true) {
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);
181 $params[$k] = mb_substr($q, $pos +
1);
184 $return_url = 'prefs_manage.php';
187 $GLOBALS['PMA_Config']->loadUserPreferences();
188 $userPreferences->redirect($return_url, $params);
194 } elseif (isset($_POST['submit_clear'])) {
195 $result = $userPreferences->save([]);
196 if ($result === true) {
198 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
199 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
200 $userPreferences->redirect('prefs_manage.php', $params);
208 $response = Response
::getInstance();
209 $header = $response->getHeader();
210 $scripts = $header->getScripts();
211 $scripts->addFile('config.js');
213 require 'libraries/user_preferences.inc.php';
215 if (!$error instanceof Message
) {
216 $error = Message
::error($error);
221 <script type
="text/javascript">
223 Sanitize
::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
226 <div id
="maincontainer">
227 <div id
="main_pane_left">
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" />'
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.')
251 , '<div class="localStorage-exists">'
252 , __('Saved on: @DATE@')
254 , '<div class="localStorage-empty">';
255 Message
::notice(__('You have no saved settings!'))->display();
258 , '<div class="localStorage-unsupported">';
260 __('This feature is not supported by your web browser')
264 , '<input type="checkbox" id="import_merge" name="import_merge" />'
265 , '<label for="import_merge">'
266 , __('Merge with current configuration') . '</label>'
268 , '<input type="submit" name="submit_import" value="'
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)
278 <h2
><?php
echo __('More settings') ?
></h2
>
279 <div
class="group-cnt">
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">',
288 ) , PhpMyAdmin\Util
::showDocu('setup', 'setup-script');
296 <div id
="main_pane_right">
298 <h2
><?php
echo __('Export'); ?
></h2
>
299 <div
class="click-hide-message group-cnt hide">
302 __('Configuration has been saved.')
306 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
307 action
="prefs_manage.php" method
="post">
308 <?php
echo Url
::getHiddenInputs(); ?
>
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'); ?
>
315 <input type
="radio" id
="export_php_file" name
="export_type"
317 <label
for="export_php_file">
318 <?php
echo __('Save as PHP file'); ?
>
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
>
325 <div id
="opts_export_local_storage"
326 class="prefsmanage_opts disabled">
327 <span
class="localStorage-supported">
330 'Settings will be saved in your browser\'s local '
334 <div
class="localStorage-exists">
338 'Existing settings will be overwritten!'
344 <div
class="localStorage-unsupported">
347 __('This feature is not supported by your web browser')
354 echo '<input type="submit" name="submit_export" value="' , __(
361 <h2
><?php
echo __('Reset'); ?
></h2
>
362 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
363 action
="prefs_manage.php" method
="post">
365 echo Url
::getHiddenInputs() , __(
366 'You can reset all your settings and restore them to default '
371 <input type
="submit" name
="submit_clear"
372 value
="<?php echo __('Reset'); ?>"/>
376 <br
class="clearfloat" />
380 if ($response->isAjax()) {
381 $response->addJSON('_disableNaviSettings', true);
383 define('PMA_DISABLE_NAVI_SETTINGS', true);