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
;
13 use PMA\libraries\URL
;
14 use PMA\libraries\Sanitize
;
17 * Gets some core libraries and displays a top message if required
19 require_once 'libraries/common.inc.php';
20 require_once 'libraries/user_preferences.lib.php';
21 require_once 'libraries/config/config_functions.lib.php';
22 require_once 'libraries/config/messages.inc.php';
23 require 'libraries/config/user_preferences.forms.php';
25 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
26 PMA_userprefsPageInit($cf);
29 if (isset($_POST['submit_export'])
30 && isset($_POST['export_type'])
31 && $_POST['export_type'] == 'text_file'
33 // export to JSON file
34 PMA\libraries\Response
::getInstance()->disable();
35 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
36 PMA_downloadHeader($filename, 'application/json');
37 $settings = PMA_loadUserprefs();
38 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT
);
40 } else if (isset($_POST['submit_get_json'])) {
41 $settings = PMA_loadUserprefs();
42 $response = PMA\libraries\Response
::getInstance();
43 $response->addJSON('prefs', json_encode($settings['config_data']));
44 $response->addJSON('mtime', $settings['mtime']);
46 } else if (isset($_POST['submit_import'])) {
47 // load from JSON file
49 if (isset($_POST['import_type'])
50 && $_POST['import_type'] == 'text_file'
51 && isset($_FILES['import_file'])
52 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
53 && is_uploaded_file($_FILES['import_file']['tmp_name'])
55 // read JSON from uploaded file
56 $open_basedir = @ini_get
('open_basedir');
58 $import_file = $_FILES['import_file']['tmp_name'];
60 // If we are on a server with open_basedir, we must move the file
61 // before opening it. The doc explains how to create the "./tmp"
63 if (!empty($open_basedir)) {
64 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : 'tmp/');
65 if (@is_writable
($tmp_subdir)) {
66 $import_file_new = tempnam($tmp_subdir, 'prefs');
67 if (move_uploaded_file($import_file, $import_file_new)) {
68 $import_file = $import_file_new;
69 $file_to_unlink = $import_file_new;
73 $json = file_get_contents($import_file);
74 if ($file_to_unlink) {
75 unlink($file_to_unlink);
78 // read from POST value (json)
79 $json = isset($_POST['json']) ?
$_POST['json'] : null;
82 // hide header message
83 $_SESSION['userprefs_autoload'] = true;
85 $config = json_decode($json, true);
86 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
87 if (! is_array($config)) {
88 $error = __('Could not import configuration');
90 // sanitize input values: treat them as though
91 // they came from HTTP POST request
92 $form_display = new FormDisplay($cf);
93 foreach ($forms as $formset_id => $formset) {
94 foreach ($formset as $form_name => $form) {
95 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
98 $new_config = $cf->getFlatDefaultConfig();
99 if (!empty($_POST['import_merge'])) {
100 $new_config = array_merge($new_config, $cf->getConfigArray());
102 $new_config = array_merge($new_config, $config);
104 foreach ($new_config as $k => $v) {
105 $_POST[str_replace('/', '-', $k)] = $v;
107 $cf->resetConfigData();
108 $all_ok = $form_display->process(true, false);
109 $all_ok = $all_ok && !$form_display->hasErrors();
112 if (!$all_ok && isset($_POST['fix_errors'])) {
113 $form_display->fixErrors();
117 // mimic original form and post json in a hidden field
118 include 'libraries/user_preferences.inc.php';
119 $msg = Message
::error(
120 __('Configuration contains incorrect data for some fields.')
123 echo '<div class="config-form">';
124 echo $form_display->displayErrors();
126 echo '<form action="prefs_manage.php" method="post">';
127 echo URL
::getHiddenInputs() , "\n";
128 echo '<input type="hidden" name="json" value="'
129 , htmlspecialchars($json) , '" />';
130 echo '<input type="hidden" name="fix_errors" value="1" />';
131 if (! empty($_POST['import_merge'])) {
132 echo '<input type="hidden" name="import_merge" value="1" />';
135 echo '<input type="hidden" name="return_url" value="'
136 , htmlspecialchars($return_url) , '" />';
139 echo __('Do you want to import remaining settings?');
141 echo '<input type="submit" name="submit_import" value="'
142 , __('Yes') , '" />';
143 echo '<input type="submit" name="submit_ignore" value="'
149 // check for ThemeDefault and fontsize
151 if (isset($config['ThemeDefault'])
152 && $_SESSION['PMA_Theme_Manager']->theme
->getId() != $config['ThemeDefault']
153 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
155 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
156 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
158 if (isset($config['fontsize'])
159 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
161 $params['set_fontsize'] = $config['fontsize'];
163 if (isset($config['lang'])
164 && $config['lang'] != $GLOBALS['lang']
166 $params['lang'] = $config['lang'];
168 if (isset($config['collation_connection'])
169 && $config['collation_connection'] != $GLOBALS['collation_connection']
171 $params['collation_connection'] = $config['collation_connection'];
175 $result = PMA_saveUserprefs($cf->getConfigArray());
176 if ($result === true) {
178 $query = explode('&', parse_url($return_url, PHP_URL_QUERY
));
179 $return_url = parse_url($return_url, PHP_URL_PATH
);
181 foreach ($query as $q) {
182 $pos = mb_strpos($q, '=');
183 $k = mb_substr($q, 0, $pos);
187 $params[$k] = mb_substr($q, $pos +
1);
190 $return_url = 'prefs_manage.php';
193 $GLOBALS['PMA_Config']->loadUserPreferences();
194 PMA_userprefsRedirect($return_url, $params);
200 } else if (isset($_POST['submit_clear'])) {
201 $result = PMA_saveUserprefs(array());
202 if ($result === true) {
204 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
205 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
207 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
208 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
209 PMA_userprefsRedirect('prefs_manage.php', $params);
217 $response = Response
::getInstance();
218 $header = $response->getHeader();
219 $scripts = $header->getScripts();
220 $scripts->addFile('config.js');
222 require 'libraries/user_preferences.inc.php';
224 if (!$error instanceof Message
) {
225 $error = Message
::error($error);
230 <script type
="text/javascript">
232 Sanitize
::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
235 <div id
="maincontainer">
236 <div id
="main_pane_left">
239 echo '<h2>' , __('Import') , '</h2>'
240 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
241 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
242 , Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
243 , URL
::getHiddenInputs()
244 , '<input type="hidden" name="json" value="" />'
245 , '<input type="radio" id="import_text_file" name="import_type"'
246 , ' value="text_file" checked="checked" />'
247 , '<label for="import_text_file">' . __('Import from file') . '</label>'
248 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
249 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
250 , '<input type="file" name="import_file" id="input_import_file" />'
252 , '<input type="radio" id="import_local_storage" name="import_type"'
253 , ' value="local_storage" disabled="disabled" />'
254 , '<label for="import_local_storage">'
255 , __('Import from browser\'s storage') , '</label>'
256 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
257 , '<div class="localStorage-supported">'
258 , __('Settings will be imported from your browser\'s local storage.')
260 , '<div class="localStorage-exists">'
261 , __('Saved on: @DATE@')
263 , '<div class="localStorage-empty">';
264 Message
::notice(__('You have no saved settings!'))->display();
267 , '<div class="localStorage-unsupported">';
269 __('This feature is not supported by your web browser')
273 , '<input type="checkbox" id="import_merge" name="import_merge" />'
274 , '<label for="import_merge">'
275 , __('Merge with current configuration') . '</label>'
277 , '<input type="submit" name="submit_import" value="'
281 if (file_exists('setup/index.php')) {
282 // show only if setup script is available, allows to disable this message
283 // by simply removing setup directory
286 <h2
><?php
echo __('More settings') ?
></h2
>
287 <div
class="group-cnt">
291 'You can set more settings by modifying config.inc.php, eg. '
292 . 'by using %sSetup script%s.'
293 ), '<a href="setup/index.php" target="_blank">', '</a>'
294 ) , PMA\libraries\Util
::showDocu('setup', 'setup-script');
302 <div id
="main_pane_right">
304 <h2
><?php
echo __('Export'); ?
></h2
>
305 <div
class="click-hide-message group-cnt" style
="display:none">
308 __('Configuration has been saved.')
312 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
313 action
="prefs_manage.php" method
="post">
314 <?php
echo URL
::getHiddenInputs(); ?
>
315 <div style
="padding-bottom:0.5em">
316 <input type
="radio" id
="export_text_file" name
="export_type"
317 value
="text_file" checked
="checked" />
318 <label
for="export_text_file">
319 <?php
echo __('Save as file'); ?
>
321 <input type
="radio" id
="export_local_storage" name
="export_type"
322 value
="local_storage" disabled
="disabled" />
323 <label
for="export_local_storage">
324 <?php
echo __('Save to browser\'s storage'); ?
></label
>
326 <div id
="opts_export_local_storage"
327 class="prefsmanage_opts disabled">
328 <span
class="localStorage-supported">
331 'Settings will be saved in your browser\'s local '
335 <div
class="localStorage-exists">
339 'Existing settings will be overwritten!'
345 <div
class="localStorage-unsupported">
348 __('This feature is not supported by your web browser')
355 echo '<input type="submit" name="submit_export" value="' , __(
362 <h2
><?php
echo __('Reset'); ?
></h2
>
363 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
364 action
="prefs_manage.php" method
="post">
366 echo URL
::getHiddenInputs() , __(
367 'You can reset all your settings and restore them to default '
372 <input type
="submit" name
="submit_clear"
373 value
="<?php echo __('Reset'); ?>"/>
377 <br
class="clearfloat" />
381 if ($response->isAjax()) {
382 $response->addJSON('_disableNaviSettings', true);
384 define('PMA_DISABLE_NAVI_SETTINGS', true);