2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
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
;
15 * Gets some core libraries and displays a top message if required
17 require_once 'libraries/common.inc.php';
18 require_once 'libraries/user_preferences.lib.php';
19 require_once 'libraries/config/config_functions.lib.php';
20 require_once 'libraries/config/messages.inc.php';
21 require 'libraries/config/user_preferences.forms.php';
23 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
24 PMA_userprefsPageInit($cf);
27 if (isset($_POST['submit_export'])
28 && isset($_POST['export_type'])
29 && $_POST['export_type'] == 'text_file'
31 // export to JSON file
32 PMA\libraries\Response
::getInstance()->disable();
33 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
34 PMA_downloadHeader($filename, 'application/json');
35 $settings = PMA_loadUserprefs();
36 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT
);
38 } else if (isset($_POST['submit_get_json'])) {
39 $settings = PMA_loadUserprefs();
40 $response = PMA\libraries\Response
::getInstance();
41 $response->addJSON('prefs', json_encode($settings['config_data']));
42 $response->addJSON('mtime', $settings['mtime']);
44 } else if (isset($_POST['submit_import'])) {
45 // load from JSON file
47 if (isset($_POST['import_type'])
48 && $_POST['import_type'] == 'text_file'
49 && isset($_FILES['import_file'])
50 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
51 && is_uploaded_file($_FILES['import_file']['tmp_name'])
53 // read JSON from uploaded file
54 $open_basedir = @ini_get
('open_basedir');
56 $import_file = $_FILES['import_file']['tmp_name'];
58 // If we are on a server with open_basedir, we must move the file
59 // before opening it. The doc explains how to create the "./tmp"
61 if (!empty($open_basedir)) {
62 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : 'tmp/');
63 if (is_writable($tmp_subdir)) {
64 $import_file_new = tempnam($tmp_subdir, 'prefs');
65 if (move_uploaded_file($import_file, $import_file_new)) {
66 $import_file = $import_file_new;
67 $file_to_unlink = $import_file_new;
71 $json = file_get_contents($import_file);
72 if ($file_to_unlink) {
73 unlink($file_to_unlink);
76 // read from POST value (json)
77 $json = isset($_POST['json']) ?
$_POST['json'] : null;
80 // hide header message
81 $_SESSION['userprefs_autoload'] = true;
83 $config = json_decode($json, true);
84 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
85 if (! is_array($config)) {
86 $error = __('Could not import configuration');
88 // sanitize input values: treat them as though
89 // they came from HTTP POST request
90 $form_display = new FormDisplay($cf);
91 foreach ($forms as $formset_id => $formset) {
92 foreach ($formset as $form_name => $form) {
93 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
96 $new_config = $cf->getFlatDefaultConfig();
97 if (!empty($_POST['import_merge'])) {
98 $new_config = array_merge($new_config, $cf->getConfigArray());
100 $new_config = array_merge($new_config, $config);
102 foreach ($new_config as $k => $v) {
103 $_POST[str_replace('/', '-', $k)] = $v;
105 $cf->resetConfigData();
106 $all_ok = $form_display->process(true, false);
107 $all_ok = $all_ok && !$form_display->hasErrors();
110 if (!$all_ok && isset($_POST['fix_errors'])) {
111 $form_display->fixErrors();
115 // mimic original form and post json in a hidden field
116 include 'libraries/user_preferences.inc.php';
117 $msg = Message
::error(
118 __('Configuration contains incorrect data for some fields.')
121 echo '<div class="config-form">';
122 echo $form_display->displayErrors();
124 echo '<form action="prefs_manage.php" method="post">';
125 echo PMA_URL_getHiddenInputs() , "\n";
126 echo '<input type="hidden" name="json" value="'
127 , htmlspecialchars($json) , '" />';
128 echo '<input type="hidden" name="fix_errors" value="1" />';
129 if (! empty($_POST['import_merge'])) {
130 echo '<input type="hidden" name="import_merge" value="1" />';
133 echo '<input type="hidden" name="return_url" value="'
134 , htmlspecialchars($return_url) , '" />';
137 echo __('Do you want to import remaining settings?');
139 echo '<input type="submit" name="submit_import" value="'
140 , __('Yes') , '" />';
141 echo '<input type="submit" name="submit_ignore" value="'
147 // check for ThemeDefault and fontsize
149 if (isset($config['ThemeDefault'])
150 && $_SESSION['PMA_Theme_Manager']->theme
->getId() != $config['ThemeDefault']
151 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
153 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
154 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
156 if (isset($config['fontsize'])
157 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
159 $params['set_fontsize'] = $config['fontsize'];
161 if (isset($config['lang'])
162 && $config['lang'] != $GLOBALS['lang']
164 $params['lang'] = $config['lang'];
166 if (isset($config['collation_connection'])
167 && $config['collation_connection'] != $GLOBALS['collation_connection']
169 $params['collation_connection'] = $config['collation_connection'];
173 $result = PMA_saveUserprefs($cf->getConfigArray());
174 if ($result === true) {
176 $query = explode('&', parse_url($return_url, PHP_URL_QUERY
));
177 $return_url = parse_url($return_url, PHP_URL_PATH
);
179 foreach ($query as $q) {
180 $pos = mb_strpos($q, '=');
181 $k = mb_substr($q, 0, $pos);
185 $params[$k] = mb_substr($q, $pos +
1);
188 $return_url = 'prefs_manage.php';
191 $GLOBALS['PMA_Config']->loadUserPreferences();
192 PMA_userprefsRedirect($return_url, $params);
198 } else if (isset($_POST['submit_clear'])) {
199 $result = PMA_saveUserprefs(array());
200 if ($result === true) {
202 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
203 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
205 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
206 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
207 PMA_userprefsRedirect('prefs_manage.php', $params);
215 $response = Response
::getInstance();
216 $header = $response->getHeader();
217 $scripts = $header->getScripts();
218 $scripts->addFile('config.js');
220 require 'libraries/user_preferences.inc.php';
222 if (!$error instanceof Message
) {
223 $error = Message
::error($error);
228 <script type
="text/javascript">
230 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
233 <div id
="maincontainer">
234 <div id
="main_pane_left">
237 echo '<h2>' , __('Import') , '</h2>'
238 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
239 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
240 , Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
241 , PMA_URL_getHiddenInputs()
242 , '<input type="hidden" name="json" value="" />'
243 , '<input type="radio" id="import_text_file" name="import_type"'
244 , ' value="text_file" checked="checked" />'
245 , '<label for="import_text_file">' . __('Import from file') . '</label>'
246 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
247 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
248 , '<input type="file" name="import_file" id="input_import_file" />'
250 , '<input type="radio" id="import_local_storage" name="import_type"'
251 , ' value="local_storage" disabled="disabled" />'
252 , '<label for="import_local_storage">'
253 , __('Import from browser\'s storage') , '</label>'
254 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
255 , '<div class="localStorage-supported">'
256 , __('Settings will be imported from your browser\'s local storage.')
258 , '<div class="localStorage-exists">'
259 , __('Saved on: @DATE@')
261 , '<div class="localStorage-empty">';
262 Message
::notice(__('You have no saved settings!'))->display();
265 , '<div class="localStorage-unsupported">';
267 __('This feature is not supported by your web browser')
271 , '<input type="checkbox" id="import_merge" name="import_merge" />'
272 , '<label for="import_merge">'
273 , __('Merge with current configuration') . '</label>'
275 , '<input type="submit" name="submit_import" value="'
279 if (file_exists('setup/index.php')) {
280 // show only if setup script is available, allows to disable this message
281 // by simply removing setup directory
284 <h2
><?php
echo __('More settings') ?
></h2
>
285 <div
class="group-cnt">
289 'You can set more settings by modifying config.inc.php, eg. '
290 . 'by using %sSetup script%s.'
291 ), '<a href="setup/index.php" target="_blank">', '</a>'
292 ) , PMA\libraries\Util
::showDocu('setup', 'setup-script');
300 <div id
="main_pane_right">
302 <h2
><?php
echo __('Export'); ?
></h2
>
303 <div
class="click-hide-message group-cnt" style
="display:none">
306 __('Configuration has been saved.')
310 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
311 action
="prefs_manage.php" method
="post">
312 <?php
echo PMA_URL_getHiddenInputs(); ?
>
313 <div style
="padding-bottom:0.5em">
314 <input type
="radio" id
="export_text_file" name
="export_type"
315 value
="text_file" checked
="checked" />
316 <label
for="export_text_file">
317 <?php
echo __('Save as file'); ?
>
319 <input type
="radio" id
="export_local_storage" name
="export_type"
320 value
="local_storage" disabled
="disabled" />
321 <label
for="export_local_storage">
322 <?php
echo __('Save to browser\'s storage'); ?
></label
>
324 <div id
="opts_export_local_storage"
325 class="prefsmanage_opts disabled">
326 <span
class="localStorage-supported">
329 'Settings will be saved in your browser\'s local '
333 <div
class="localStorage-exists">
337 'Existing settings will be overwritten!'
343 <div
class="localStorage-unsupported">
346 __('This feature is not supported by your web browser')
353 echo '<input type="submit" name="submit_export" value="' , __(
360 <h2
><?php
echo __('Reset'); ?
></h2
>
361 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
362 action
="prefs_manage.php" method
="post">
364 echo PMA_URL_getHiddenInputs() , __(
365 'You can reset all your settings and restore them to default '
370 <input type
="submit" name
="submit_clear"
371 value
="<?php echo __('Reset'); ?>"/>
375 <br
class="clearfloat" />
379 if ($response->isAjax()) {
380 $response->addJSON('_disableNaviSettings', true);
382 define('PMA_DISABLE_NAVI_SETTINGS', true);