2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences management page
10 * Gets some core libraries and displays a top message if required
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/user_preferences.lib.php';
14 require_once 'libraries/config/config_functions.lib.php';
15 require_once 'libraries/config/messages.inc.php';
16 require_once 'libraries/config/ConfigFile.class.php';
17 require_once 'libraries/config/Form.class.php';
18 require_once 'libraries/config/FormDisplay.class.php';
19 require 'libraries/config/user_preferences.forms.php';
21 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
22 PMA_userprefsPageInit($cf);
25 if (isset($_POST['submit_export'])
26 && isset($_POST['export_type'])
27 && $_POST['export_type'] == 'text_file'
29 // export to JSON file
30 PMA_Response
::getInstance()->disable();
31 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
32 PMA_downloadHeader($filename, 'application/json');
33 $settings = PMA_loadUserprefs();
34 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT
);
36 } else if (isset($_POST['submit_get_json'])) {
37 $settings = PMA_loadUserprefs();
38 $response = PMA_Response
::getInstance();
39 $response->addJSON('prefs', json_encode($settings['config_data']));
40 $response->addJSON('mtime', $settings['mtime']);
42 } else if (isset($_POST['submit_import'])) {
43 // load from JSON file
45 if (isset($_POST['import_type'])
46 && $_POST['import_type'] == 'text_file'
47 && isset($_FILES['import_file'])
48 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
49 && is_uploaded_file($_FILES['import_file']['tmp_name'])
51 // read JSON from uploaded file
52 $open_basedir = @ini_get
('open_basedir');
54 $import_file = $_FILES['import_file']['tmp_name'];
56 // If we are on a server with open_basedir, we must move the file
57 // before opening it. The doc explains how to create the "./tmp"
59 if (!empty($open_basedir)) {
60 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : 'tmp/');
61 if (is_writable($tmp_subdir)) {
62 $import_file_new = tempnam($tmp_subdir, 'prefs');
63 if (move_uploaded_file($import_file, $import_file_new)) {
64 $import_file = $import_file_new;
65 $file_to_unlink = $import_file_new;
69 $json = file_get_contents($import_file);
70 if ($file_to_unlink) {
71 unlink($file_to_unlink);
74 // read from POST value (json)
75 $json = isset($_POST['json']) ?
$_POST['json'] : null;
78 // hide header message
79 $_SESSION['userprefs_autoload'] = true;
81 $config = json_decode($json, true);
82 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
83 if (! is_array($config)) {
84 $error = __('Could not import configuration');
86 // sanitize input values: treat them as though
87 // they came from HTTP POST request
88 $form_display = new FormDisplay($cf);
89 foreach ($forms as $formset_id => $formset) {
90 foreach ($formset as $form_name => $form) {
91 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
94 $new_config = $cf->getFlatDefaultConfig();
95 if (!empty($_POST['import_merge'])) {
96 $new_config = array_merge($new_config, $cf->getConfigArray());
98 $new_config = array_merge($new_config, $config);
100 foreach ($new_config as $k => $v) {
101 $_POST[str_replace('/', '-', $k)] = $v;
103 $cf->resetConfigData();
104 $all_ok = $form_display->process(true, false);
105 $all_ok = $all_ok && !$form_display->hasErrors();
108 if (!$all_ok && isset($_POST['fix_errors'])) {
109 $form_display->fixErrors();
113 // mimic original form and post json in a hidden field
114 include 'libraries/user_preferences.inc.php';
115 $msg = PMA_Message
::error(
116 __('Configuration contains incorrect data for some fields.')
119 echo '<div class="config-form">';
120 echo $form_display->displayErrors();
122 echo '<form action="prefs_manage.php" method="post">';
123 echo PMA_URL_getHiddenInputs() . "\n";
124 echo '<input type="hidden" name="json" value="'
125 . htmlspecialchars($json) . '" />';
126 echo '<input type="hidden" name="fix_errors" value="1" />';
127 if (! empty($_POST['import_merge'])) {
128 echo '<input type="hidden" name="import_merge" value="1" />';
131 echo '<input type="hidden" name="return_url" value="'
132 . htmlspecialchars($return_url) . '" />';
135 echo __('Do you want to import remaining settings?');
137 echo '<input type="submit" name="submit_import" value="'
138 . __('Yes') . '" />';
139 echo '<input type="submit" name="submit_ignore" value="'
145 // check for ThemeDefault and fontsize
147 if (isset($config['ThemeDefault'])
148 && $_SESSION['PMA_Theme_Manager']->theme
->getId() != $config['ThemeDefault']
149 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
151 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
152 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
154 if (isset($config['fontsize'])
155 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
157 $params['set_fontsize'] = $config['fontsize'];
159 if (isset($config['lang'])
160 && $config['lang'] != $GLOBALS['lang']
162 $params['lang'] = $config['lang'];
164 if (isset($config['collation_connection'])
165 && $config['collation_connection'] != $GLOBALS['collation_connection']
167 $params['collation_connection'] = $config['collation_connection'];
171 $result = PMA_saveUserprefs($cf->getConfigArray());
172 if ($result === true) {
174 $query = explode('&', parse_url($return_url, PHP_URL_QUERY
));
175 $return_url = parse_url($return_url, PHP_URL_PATH
);
177 /** @var PMA_String $pmaString */
178 $pmaString = $GLOBALS['PMA_String'];
180 foreach ($query as $q) {
181 $pos = /*overload*/mb_strpos($q, '=');
182 $k = /*overload*/mb_substr($q, 0, $pos);
186 $params[$k] = /*overload*/mb_substr($q, $pos +
1);
189 $return_url = 'prefs_manage.php';
192 $GLOBALS['PMA_Config']->loadUserPreferences();
193 PMA_userprefsRedirect($return_url, $params);
199 } else if (isset($_POST['submit_clear'])) {
200 $result = PMA_saveUserprefs(array());
201 if ($result === true) {
203 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
204 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
206 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
207 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
208 PMA_userprefsRedirect('prefs_manage.php', $params);
216 $response = PMA_Response
::getInstance();
217 $header = $response->getHeader();
218 $scripts = $header->getScripts();
219 $scripts->addFile('config.js');
221 require 'libraries/user_preferences.inc.php';
223 if (!$error instanceof PMA_Message
) {
224 $error = PMA_Message
::error($error);
229 <script type
="text/javascript">
231 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
234 <div id
="maincontainer">
235 <div id
="main_pane_left">
238 echo '<h2>' . __('Import') . '</h2>'
239 . '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
240 . ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
241 . PMA_Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
242 . PMA_URL_getHiddenInputs()
243 . '<input type="hidden" name="json" value="" />'
244 . '<input type="radio" id="import_text_file" name="import_type"'
245 . ' value="text_file" checked="checked" />'
246 . '<label for="import_text_file">' . __('Import from file') . '</label>'
247 . '<div id="opts_import_text_file" class="prefsmanage_opts">'
248 . '<label for="input_import_file">' . __('Browse your computer:') . '</label>'
249 . '<input type="file" name="import_file" id="input_import_file" />'
251 . '<input type="radio" id="import_local_storage" name="import_type"'
252 . ' value="local_storage" disabled="disabled" />'
253 . '<label for="import_local_storage">'
254 . __('Import from browser\'s storage') . '</label>'
255 . '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
256 . '<div class="localStorage-supported">'
257 . __('Settings will be imported from your browser\'s local storage.')
259 . '<div class="localStorage-exists">'
260 . __('Saved on: @DATE@')
262 . '<div class="localStorage-empty">';
263 PMA_Message
::notice(__('You have no saved settings!'))->display();
266 . '<div class="localStorage-unsupported">';
268 __('This feature is not supported by your web browser')
272 . '<input type="checkbox" id="import_merge" name="import_merge" />'
273 . '<label for="import_merge">'
274 . __('Merge with current configuration') . '</label>'
276 . '<input type="submit" name="submit_import" value="'
280 if (file_exists('setup/index.php')) {
281 // show only if setup script is available, allows to disable this message
282 // by simply removing setup directory
285 <h2
><?php
echo __('More settings') ?
></h2
>
286 <div
class="group-cnt">
290 'You can set more settings by modifying config.inc.php, eg. '
291 . 'by using %sSetup script%s.'
292 ), '<a href="setup/index.php" target="_blank">', '</a>'
293 ) . PMA_Util
::showDocu('setup', 'setup-script');
301 <div id
="main_pane_right">
303 <h2
><?php
echo __('Export'); ?
></h2
>
304 <div
class="click-hide-message group-cnt" style
="display:none">
306 PMA_Message
::rawSuccess(
307 __('Configuration has been saved.')
311 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
312 action
="prefs_manage.php" method
="post">
313 <?php
echo PMA_URL_getHiddenInputs(); ?
>
314 <div style
="padding-bottom:0.5em">
315 <input type
="radio" id
="export_text_file" name
="export_type"
316 value
="text_file" checked
="checked" />
317 <label
for="export_text_file">
318 <?php
echo __('Save as 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 PMA_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);