2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
8 use PhpMyAdmin\Config\ConfigFile
;
9 use PhpMyAdmin\Config\Forms\User\UserFormList
;
12 use PhpMyAdmin\Message
;
13 use PhpMyAdmin\Response
;
14 use PhpMyAdmin\Sanitize
;
15 use PhpMyAdmin\ThemeManager
;
17 use PhpMyAdmin\UserPreferences
;
21 * Gets some core libraries and displays a top message if required
23 require_once 'libraries/common.inc.php';
25 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
26 UserPreferences
::pageInit($cf);
27 $response = Response
::getInstance();
30 if (isset($_POST['submit_export'])
31 && isset($_POST['export_type'])
32 && $_POST['export_type'] == 'text_file'
34 // export to JSON file
36 $filename = 'phpMyAdmin-config-' . urlencode(Core
::getenv('HTTP_HOST')) . '.json';
37 Core
::downloadHeader($filename, 'application/json');
38 $settings = UserPreferences
::load();
39 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT
);
41 } elseif (isset($_POST['submit_export'])
42 && isset($_POST['export_type'])
43 && $_POST['export_type'] == 'php_file'
45 // export to JSON file
47 $filename = 'phpMyAdmin-config-' . urlencode(Core
::getenv('HTTP_HOST')) . '.php';
48 Core
::downloadHeader($filename, 'application/php');
49 $settings = UserPreferences
::load();
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";
57 } elseif (isset($_POST['submit_get_json'])) {
58 $settings = UserPreferences
::load();
59 $response->addJSON('prefs', json_encode($settings['config_data']));
60 $response->addJSON('mtime', $settings['mtime']);
62 } elseif (isset($_POST['submit_import'])) {
63 // load from JSON file
65 if (isset($_POST['import_type'])
66 && $_POST['import_type'] == 'text_file'
67 && isset($_FILES['import_file'])
68 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
69 && is_uploaded_file($_FILES['import_file']['tmp_name'])
71 $import_handle = new File($_FILES['import_file']['tmp_name']);
72 $import_handle->checkUploadedFile();
73 if ($import_handle->isError()) {
74 $error = $import_handle->getError();
76 // read JSON from uploaded file
77 $json = $import_handle->getRawContent();
80 // read from POST value (json)
81 $json = isset($_POST['json']) ?
$_POST['json'] : null;
84 // hide header message
85 $_SESSION['userprefs_autoload'] = true;
87 $config = json_decode($json, true);
88 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
89 if (! is_array($config)) {
90 if (! isset($error)) {
91 $error = __('Could not import configuration');
94 // sanitize input values: treat them as though
95 // they came from HTTP POST request
96 $form_display = new UserFormList($cf);
97 $new_config = $cf->getFlatDefaultConfig();
98 if (!empty($_POST['import_merge'])) {
99 $new_config = array_merge($new_config, $cf->getConfigArray());
101 $new_config = array_merge($new_config, $config);
103 foreach ($new_config as $k => $v) {
104 $_POST[str_replace('/', '-', $k)] = $v;
106 $cf->resetConfigData();
107 $all_ok = $form_display->process(true, false);
108 $all_ok = $all_ok && !$form_display->hasErrors();
111 if (!$all_ok && isset($_POST['fix_errors'])) {
112 $form_display->fixErrors();
116 // mimic original form and post json in a hidden field
117 include 'libraries/user_preferences.inc.php';
118 $msg = Message
::error(
119 __('Configuration contains incorrect data for some fields.')
122 echo '<div class="config-form">';
123 echo $form_display->displayErrors();
125 echo '<form action="prefs_manage.php" method="post">';
126 echo Url
::getHiddenInputs() , "\n";
127 echo '<input type="hidden" name="json" value="'
128 , htmlspecialchars($json) , '" />';
129 echo '<input type="hidden" name="fix_errors" value="1" />';
130 if (! empty($_POST['import_merge'])) {
131 echo '<input type="hidden" name="import_merge" value="1" />';
134 echo '<input type="hidden" name="return_url" value="'
135 , htmlspecialchars($return_url) , '" />';
138 echo __('Do you want to import remaining settings?');
140 echo '<input type="submit" name="submit_import" value="'
141 , __('Yes') , '" />';
142 echo '<input type="submit" name="submit_ignore" value="'
148 // check for ThemeDefault
150 $tmanager = ThemeManager
::getInstance();
151 if (isset($config['ThemeDefault'])
152 && $tmanager->theme
->getId() != $config['ThemeDefault']
153 && $tmanager->checkTheme($config['ThemeDefault'])
155 $tmanager->setActiveTheme($config['ThemeDefault']);
156 $tmanager->setThemeCookie();
158 if (isset($config['lang'])
159 && $config['lang'] != $GLOBALS['lang']
161 $params['lang'] = $config['lang'];
165 $result = UserPreferences
::save($cf->getConfigArray());
166 if ($result === true) {
168 $query = PhpMyAdmin\Util
::splitURLQuery($return_url);
169 $return_url = parse_url($return_url, PHP_URL_PATH
);
171 foreach ($query as $q) {
172 $pos = mb_strpos($q, '=');
173 $k = mb_substr($q, 0, $pos);
177 $params[$k] = mb_substr($q, $pos +
1);
180 $return_url = 'prefs_manage.php';
183 $GLOBALS['PMA_Config']->loadUserPreferences();
184 UserPreferences
::redirect($return_url, $params);
190 } elseif (isset($_POST['submit_clear'])) {
191 $result = UserPreferences
::save(array());
192 if ($result === true) {
194 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
195 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
196 UserPreferences
::redirect('prefs_manage.php', $params);
204 $response = Response
::getInstance();
205 $header = $response->getHeader();
206 $scripts = $header->getScripts();
207 $scripts->addFile('config.js');
209 require 'libraries/user_preferences.inc.php';
211 if (!$error instanceof Message
) {
212 $error = Message
::error($error);
217 <script type
="text/javascript">
219 Sanitize
::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
222 <div id
="maincontainer">
223 <div id
="main_pane_left">
226 echo '<h2>' , __('Import') , '</h2>'
227 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
228 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
229 , Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
230 , Url
::getHiddenInputs()
231 , '<input type="hidden" name="json" value="" />'
232 , '<input type="radio" id="import_text_file" name="import_type"'
233 , ' value="text_file" checked="checked" />'
234 , '<label for="import_text_file">' . __('Import from file') . '</label>'
235 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
236 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
237 , '<input type="file" name="import_file" id="input_import_file" />'
239 , '<input type="radio" id="import_local_storage" name="import_type"'
240 , ' value="local_storage" disabled="disabled" />'
241 , '<label for="import_local_storage">'
242 , __('Import from browser\'s storage') , '</label>'
243 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
244 , '<div class="localStorage-supported">'
245 , __('Settings will be imported from your browser\'s local storage.')
247 , '<div class="localStorage-exists">'
248 , __('Saved on: @DATE@')
250 , '<div class="localStorage-empty">';
251 Message
::notice(__('You have no saved settings!'))->display();
254 , '<div class="localStorage-unsupported">';
256 __('This feature is not supported by your web browser')
260 , '<input type="checkbox" id="import_merge" name="import_merge" />'
261 , '<label for="import_merge">'
262 , __('Merge with current configuration') . '</label>'
264 , '<input type="submit" name="submit_import" value="'
268 if (@file_exists
('setup/index.php') && ! @file_exists
(CONFIG_FILE
)) {
269 // show only if setup script is available, allows to disable this message
270 // by simply removing setup directory
271 // Also do not show in config exists (and setup would refuse to work)
274 <h2
><?php
echo __('More settings') ?
></h2
>
275 <div
class="group-cnt">
279 'You can set more settings by modifying config.inc.php, eg. '
280 . 'by using %sSetup script%s.'
281 ), '<a href="setup/index.php" target="_blank">', '</a>'
282 ) , PhpMyAdmin\Util
::showDocu('setup', 'setup-script');
290 <div id
="main_pane_right">
292 <h2
><?php
echo __('Export'); ?
></h2
>
293 <div
class="click-hide-message group-cnt hide">
296 __('Configuration has been saved.')
300 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
301 action
="prefs_manage.php" method
="post">
302 <?php
echo Url
::getHiddenInputs(); ?
>
303 <div style
="padding-bottom:0.5em">
304 <input type
="radio" id
="export_text_file" name
="export_type"
305 value
="text_file" checked
="checked" />
306 <label
for="export_text_file">
307 <?php
echo __('Save as file'); ?
>
309 <input type
="radio" id
="export_php_file" name
="export_type"
311 <label
for="export_php_file">
312 <?php
echo __('Save as PHP file'); ?
>
314 <input type
="radio" id
="export_local_storage" name
="export_type"
315 value
="local_storage" disabled
="disabled" />
316 <label
for="export_local_storage">
317 <?php
echo __('Save to browser\'s storage'); ?
></label
>
319 <div id
="opts_export_local_storage"
320 class="prefsmanage_opts disabled">
321 <span
class="localStorage-supported">
324 'Settings will be saved in your browser\'s local '
328 <div
class="localStorage-exists">
332 'Existing settings will be overwritten!'
338 <div
class="localStorage-unsupported">
341 __('This feature is not supported by your web browser')
348 echo '<input type="submit" name="submit_export" value="' , __(
355 <h2
><?php
echo __('Reset'); ?
></h2
>
356 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
357 action
="prefs_manage.php" method
="post">
359 echo Url
::getHiddenInputs() , __(
360 'You can reset all your settings and restore them to default '
365 <input type
="submit" name
="submit_clear"
366 value
="<?php echo __('Reset'); ?>"/>
370 <br
class="clearfloat" />
374 if ($response->isAjax()) {
375 $response->addJSON('_disableNaviSettings', true);
377 define('PMA_DISABLE_NAVI_SETTINGS', true);