2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
8 use PhpMyAdmin\Config\ConfigFile
;
9 use PhpMyAdmin\Config\FormDisplay
;
12 use PhpMyAdmin\Message
;
13 use PhpMyAdmin\Response
;
16 use PhpMyAdmin\Sanitize
;
17 use PhpMyAdmin\ThemeManager
;
20 * Gets some core libraries and displays a top message if required
22 require_once 'libraries/common.inc.php';
23 require_once 'libraries/user_preferences.lib.php';
24 require_once 'libraries/config/config_functions.lib.php';
25 require_once 'libraries/config/messages.inc.php';
26 require 'libraries/config/user_preferences.forms.php';
28 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
29 PMA_userprefsPageInit($cf);
30 $response = Response
::getInstance();
33 if (isset($_POST['submit_export'])
34 && isset($_POST['export_type'])
35 && $_POST['export_type'] == 'text_file'
37 // export to JSON file
39 $filename = 'phpMyAdmin-config-' . urlencode(Core
::getenv('HTTP_HOST')) . '.json';
40 Core
::downloadHeader($filename, 'application/json');
41 $settings = PMA_loadUserprefs();
42 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT
);
44 } elseif (isset($_POST['submit_export'])
45 && isset($_POST['export_type'])
46 && $_POST['export_type'] == 'php_file'
48 // export to JSON file
50 $filename = 'phpMyAdmin-config-' . urlencode(Core
::getenv('HTTP_HOST')) . '.php';
51 Core
::downloadHeader($filename, 'application/php');
52 $settings = PMA_loadUserprefs();
53 echo '/* ' . _('phpMyAdmin configuration snippet') . " */\n\n";
54 echo '/* ' . _('Paste it to your config.inc.php') . " */\n\n";
55 foreach ($settings['config_data'] as $key => $val) {
56 echo '$cfg[\'' . str_replace('/', '\'][\'', $key) . '\'] = ';
57 echo var_export($val, true) . ";\n";
60 } else if (isset($_POST['submit_get_json'])) {
61 $settings = PMA_loadUserprefs();
62 $response->addJSON('prefs', json_encode($settings['config_data']));
63 $response->addJSON('mtime', $settings['mtime']);
65 } else if (isset($_POST['submit_import'])) {
66 // load from JSON file
68 if (isset($_POST['import_type'])
69 && $_POST['import_type'] == 'text_file'
70 && isset($_FILES['import_file'])
71 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
72 && is_uploaded_file($_FILES['import_file']['tmp_name'])
74 $import_handle = new File($_FILES['import_file']['tmp_name']);
75 $import_handle->checkUploadedFile();
76 if ($import_handle->isError()) {
77 $error = $import_handle->getError();
79 // read JSON from uploaded file
80 $json = $import_handle->getRawContent();
83 // read from POST value (json)
84 $json = isset($_POST['json']) ?
$_POST['json'] : null;
87 // hide header message
88 $_SESSION['userprefs_autoload'] = true;
90 $config = json_decode($json, true);
91 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
92 if (! is_array($config)) {
93 if (! isset($error)) {
94 $error = __('Could not import configuration');
97 // sanitize input values: treat them as though
98 // they came from HTTP POST request
99 $form_display = new FormDisplay($cf);
100 foreach ($forms as $formset_id => $formset) {
101 foreach ($formset as $form_name => $form) {
102 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
105 $new_config = $cf->getFlatDefaultConfig();
106 if (!empty($_POST['import_merge'])) {
107 $new_config = array_merge($new_config, $cf->getConfigArray());
109 $new_config = array_merge($new_config, $config);
111 foreach ($new_config as $k => $v) {
112 $_POST[str_replace('/', '-', $k)] = $v;
114 $cf->resetConfigData();
115 $all_ok = $form_display->process(true, false);
116 $all_ok = $all_ok && !$form_display->hasErrors();
119 if (!$all_ok && isset($_POST['fix_errors'])) {
120 $form_display->fixErrors();
124 // mimic original form and post json in a hidden field
125 include 'libraries/user_preferences.inc.php';
126 $msg = Message
::error(
127 __('Configuration contains incorrect data for some fields.')
130 echo '<div class="config-form">';
131 echo $form_display->displayErrors();
133 echo '<form action="prefs_manage.php" method="post">';
134 echo Url
::getHiddenInputs() , "\n";
135 echo '<input type="hidden" name="json" value="'
136 , htmlspecialchars($json) , '" />';
137 echo '<input type="hidden" name="fix_errors" value="1" />';
138 if (! empty($_POST['import_merge'])) {
139 echo '<input type="hidden" name="import_merge" value="1" />';
142 echo '<input type="hidden" name="return_url" value="'
143 , htmlspecialchars($return_url) , '" />';
146 echo __('Do you want to import remaining settings?');
148 echo '<input type="submit" name="submit_import" value="'
149 , __('Yes') , '" />';
150 echo '<input type="submit" name="submit_ignore" value="'
156 // check for ThemeDefault and fontsize
158 $tmanager = ThemeManager
::getInstance();
159 if (isset($config['ThemeDefault'])
160 && $tmanager->theme
->getId() != $config['ThemeDefault']
161 && $tmanager->checkTheme($config['ThemeDefault'])
163 $tmanager->setActiveTheme($config['ThemeDefault']);
164 $tmanager->setThemeCookie();
166 if (isset($config['fontsize'])
167 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
169 $params['set_fontsize'] = $config['fontsize'];
171 if (isset($config['lang'])
172 && $config['lang'] != $GLOBALS['lang']
174 $params['lang'] = $config['lang'];
176 if (isset($config['collation_connection'])
177 && $config['collation_connection'] != $GLOBALS['collation_connection']
179 $params['collation_connection'] = $config['collation_connection'];
183 $result = PMA_saveUserprefs($cf->getConfigArray());
184 if ($result === true) {
186 $query = PhpMyAdmin\Util
::splitURLQuery($return_url);
187 $return_url = parse_url($return_url, PHP_URL_PATH
);
189 foreach ($query as $q) {
190 $pos = mb_strpos($q, '=');
191 $k = mb_substr($q, 0, $pos);
195 $params[$k] = mb_substr($q, $pos +
1);
198 $return_url = 'prefs_manage.php';
201 $GLOBALS['PMA_Config']->loadUserPreferences();
202 PMA_userprefsRedirect($return_url, $params);
208 } else if (isset($_POST['submit_clear'])) {
209 $result = PMA_saveUserprefs(array());
210 if ($result === true) {
212 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
213 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
215 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
216 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
217 PMA_userprefsRedirect('prefs_manage.php', $params);
225 $response = Response
::getInstance();
226 $header = $response->getHeader();
227 $scripts = $header->getScripts();
228 $scripts->addFile('config.js');
230 require 'libraries/user_preferences.inc.php';
232 if (!$error instanceof Message
) {
233 $error = Message
::error($error);
238 <script type
="text/javascript">
240 Sanitize
::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
243 <div id
="maincontainer">
244 <div id
="main_pane_left">
247 echo '<h2>' , __('Import') , '</h2>'
248 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
249 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
250 , Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
251 , Url
::getHiddenInputs()
252 , '<input type="hidden" name="json" value="" />'
253 , '<input type="radio" id="import_text_file" name="import_type"'
254 , ' value="text_file" checked="checked" />'
255 , '<label for="import_text_file">' . __('Import from file') . '</label>'
256 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
257 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
258 , '<input type="file" name="import_file" id="input_import_file" />'
260 , '<input type="radio" id="import_local_storage" name="import_type"'
261 , ' value="local_storage" disabled="disabled" />'
262 , '<label for="import_local_storage">'
263 , __('Import from browser\'s storage') , '</label>'
264 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
265 , '<div class="localStorage-supported">'
266 , __('Settings will be imported from your browser\'s local storage.')
268 , '<div class="localStorage-exists">'
269 , __('Saved on: @DATE@')
271 , '<div class="localStorage-empty">';
272 Message
::notice(__('You have no saved settings!'))->display();
275 , '<div class="localStorage-unsupported">';
277 __('This feature is not supported by your web browser')
281 , '<input type="checkbox" id="import_merge" name="import_merge" />'
282 , '<label for="import_merge">'
283 , __('Merge with current configuration') . '</label>'
285 , '<input type="submit" name="submit_import" value="'
289 if (@file_exists
('setup/index.php') && ! @file_exists
(CONFIG_FILE
)) {
290 // show only if setup script is available, allows to disable this message
291 // by simply removing setup directory
292 // Also do not show in config exists (and setup would refuse to work)
295 <h2
><?php
echo __('More settings') ?
></h2
>
296 <div
class="group-cnt">
300 'You can set more settings by modifying config.inc.php, eg. '
301 . 'by using %sSetup script%s.'
302 ), '<a href="setup/index.php" target="_blank">', '</a>'
303 ) , PhpMyAdmin\Util
::showDocu('setup', 'setup-script');
311 <div id
="main_pane_right">
313 <h2
><?php
echo __('Export'); ?
></h2
>
314 <div
class="click-hide-message group-cnt hide">
317 __('Configuration has been saved.')
321 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
322 action
="prefs_manage.php" method
="post">
323 <?php
echo Url
::getHiddenInputs(); ?
>
324 <div style
="padding-bottom:0.5em">
325 <input type
="radio" id
="export_text_file" name
="export_type"
326 value
="text_file" checked
="checked" />
327 <label
for="export_text_file">
328 <?php
echo __('Save as file'); ?
>
330 <input type
="radio" id
="export_php_file" name
="export_type"
332 <label
for="export_php_file">
333 <?php
echo __('Save as PHP file'); ?
>
335 <input type
="radio" id
="export_local_storage" name
="export_type"
336 value
="local_storage" disabled
="disabled" />
337 <label
for="export_local_storage">
338 <?php
echo __('Save to browser\'s storage'); ?
></label
>
340 <div id
="opts_export_local_storage"
341 class="prefsmanage_opts disabled">
342 <span
class="localStorage-supported">
345 'Settings will be saved in your browser\'s local '
349 <div
class="localStorage-exists">
353 'Existing settings will be overwritten!'
359 <div
class="localStorage-unsupported">
362 __('This feature is not supported by your web browser')
369 echo '<input type="submit" name="submit_export" value="' , __(
376 <h2
><?php
echo __('Reset'); ?
></h2
>
377 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
378 action
="prefs_manage.php" method
="post">
380 echo Url
::getHiddenInputs() , __(
381 'You can reset all your settings and restore them to default '
386 <input type
="submit" name
="submit_clear"
387 value
="<?php echo __('Reset'); ?>"/>
391 <br
class="clearfloat" />
395 if ($response->isAjax()) {
396 $response->addJSON('_disableNaviSettings', true);
398 define('PMA_DISABLE_NAVI_SETTINGS', true);