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
;
15 use PMA\libraries\ThemeManager
;
18 * Gets some core libraries and displays a top message if required
20 require_once 'libraries/common.inc.php';
21 require_once 'libraries/user_preferences.lib.php';
22 require_once 'libraries/config/config_functions.lib.php';
23 require_once 'libraries/config/messages.inc.php';
24 require 'libraries/config/user_preferences.forms.php';
26 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings
);
27 PMA_userprefsPageInit($cf);
30 if (isset($_POST['submit_export'])
31 && isset($_POST['export_type'])
32 && $_POST['export_type'] == 'text_file'
34 // export to JSON file
35 PMA\libraries\Response
::getInstance()->disable();
36 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
37 PMA_downloadHeader($filename, 'application/json');
38 $settings = PMA_loadUserprefs();
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
46 PMA\libraries\Response
::getInstance()->disable();
47 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.php';
48 PMA_downloadHeader($filename, 'application/php');
49 $settings = PMA_loadUserprefs();
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 } else if (isset($_POST['submit_get_json'])) {
58 $settings = PMA_loadUserprefs();
59 $response = PMA\libraries\Response
::getInstance();
60 $response->addJSON('prefs', json_encode($settings['config_data']));
61 $response->addJSON('mtime', $settings['mtime']);
63 } else if (isset($_POST['submit_import'])) {
64 // load from JSON file
66 if (isset($_POST['import_type'])
67 && $_POST['import_type'] == 'text_file'
68 && isset($_FILES['import_file'])
69 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
70 && is_uploaded_file($_FILES['import_file']['tmp_name'])
72 // read JSON from uploaded file
73 $open_basedir = @ini_get
('open_basedir');
75 $import_file = $_FILES['import_file']['tmp_name'];
77 // If we are on a server with open_basedir, we must move the file
78 // before opening it. The doc explains how to create the "./tmp"
80 if (!empty($open_basedir)) {
81 $tmp_subdir = (PMA_IS_WINDOWS ?
'.\\tmp\\' : 'tmp/');
82 if (@is_writable
($tmp_subdir)) {
83 $import_file_new = tempnam($tmp_subdir, 'prefs');
84 if (move_uploaded_file($import_file, $import_file_new)) {
85 $import_file = $import_file_new;
86 $file_to_unlink = $import_file_new;
90 $json = file_get_contents($import_file);
91 if ($file_to_unlink) {
92 unlink($file_to_unlink);
95 // read from POST value (json)
96 $json = isset($_POST['json']) ?
$_POST['json'] : null;
99 // hide header message
100 $_SESSION['userprefs_autoload'] = true;
102 $config = json_decode($json, true);
103 $return_url = isset($_POST['return_url']) ?
$_POST['return_url'] : null;
104 if (! is_array($config)) {
105 $error = __('Could not import configuration');
107 // sanitize input values: treat them as though
108 // they came from HTTP POST request
109 $form_display = new FormDisplay($cf);
110 foreach ($forms as $formset_id => $formset) {
111 foreach ($formset as $form_name => $form) {
112 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
115 $new_config = $cf->getFlatDefaultConfig();
116 if (!empty($_POST['import_merge'])) {
117 $new_config = array_merge($new_config, $cf->getConfigArray());
119 $new_config = array_merge($new_config, $config);
121 foreach ($new_config as $k => $v) {
122 $_POST[str_replace('/', '-', $k)] = $v;
124 $cf->resetConfigData();
125 $all_ok = $form_display->process(true, false);
126 $all_ok = $all_ok && !$form_display->hasErrors();
129 if (!$all_ok && isset($_POST['fix_errors'])) {
130 $form_display->fixErrors();
134 // mimic original form and post json in a hidden field
135 include 'libraries/user_preferences.inc.php';
136 $msg = Message
::error(
137 __('Configuration contains incorrect data for some fields.')
140 echo '<div class="config-form">';
141 echo $form_display->displayErrors();
143 echo '<form action="prefs_manage.php" method="post">';
144 echo URL
::getHiddenInputs() , "\n";
145 echo '<input type="hidden" name="json" value="'
146 , htmlspecialchars($json) , '" />';
147 echo '<input type="hidden" name="fix_errors" value="1" />';
148 if (! empty($_POST['import_merge'])) {
149 echo '<input type="hidden" name="import_merge" value="1" />';
152 echo '<input type="hidden" name="return_url" value="'
153 , htmlspecialchars($return_url) , '" />';
156 echo __('Do you want to import remaining settings?');
158 echo '<input type="submit" name="submit_import" value="'
159 , __('Yes') , '" />';
160 echo '<input type="submit" name="submit_ignore" value="'
166 // check for ThemeDefault and fontsize
168 $tmanager = ThemeManager
::getInstance();
169 if (isset($config['ThemeDefault'])
170 && $tmanager->theme
->getId() != $config['ThemeDefault']
171 && $tmanager->checkTheme($config['ThemeDefault'])
173 $tmanager->setActiveTheme($config['ThemeDefault']);
174 $tmanager->setThemeCookie();
176 if (isset($config['fontsize'])
177 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
179 $params['set_fontsize'] = $config['fontsize'];
181 if (isset($config['lang'])
182 && $config['lang'] != $GLOBALS['lang']
184 $params['lang'] = $config['lang'];
186 if (isset($config['collation_connection'])
187 && $config['collation_connection'] != $GLOBALS['collation_connection']
189 $params['collation_connection'] = $config['collation_connection'];
193 $result = PMA_saveUserprefs($cf->getConfigArray());
194 if ($result === true) {
196 $query = explode('&', parse_url($return_url, PHP_URL_QUERY
));
197 $return_url = parse_url($return_url, PHP_URL_PATH
);
199 foreach ($query as $q) {
200 $pos = mb_strpos($q, '=');
201 $k = mb_substr($q, 0, $pos);
205 $params[$k] = mb_substr($q, $pos +
1);
208 $return_url = 'prefs_manage.php';
211 $GLOBALS['PMA_Config']->loadUserPreferences();
212 PMA_userprefsRedirect($return_url, $params);
218 } else if (isset($_POST['submit_clear'])) {
219 $result = PMA_saveUserprefs(array());
220 if ($result === true) {
222 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
223 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
225 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
226 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
227 PMA_userprefsRedirect('prefs_manage.php', $params);
235 $response = Response
::getInstance();
236 $header = $response->getHeader();
237 $scripts = $header->getScripts();
238 $scripts->addFile('config.js');
240 require 'libraries/user_preferences.inc.php';
242 if (!$error instanceof Message
) {
243 $error = Message
::error($error);
248 <script type
="text/javascript">
250 Sanitize
::printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
253 <div id
="maincontainer">
254 <div id
="main_pane_left">
257 echo '<h2>' , __('Import') , '</h2>'
258 , '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
259 , ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
260 , Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
261 , URL
::getHiddenInputs()
262 , '<input type="hidden" name="json" value="" />'
263 , '<input type="radio" id="import_text_file" name="import_type"'
264 , ' value="text_file" checked="checked" />'
265 , '<label for="import_text_file">' . __('Import from file') . '</label>'
266 , '<div id="opts_import_text_file" class="prefsmanage_opts">'
267 , '<label for="input_import_file">' , __('Browse your computer:') , '</label>'
268 , '<input type="file" name="import_file" id="input_import_file" />'
270 , '<input type="radio" id="import_local_storage" name="import_type"'
271 , ' value="local_storage" disabled="disabled" />'
272 , '<label for="import_local_storage">'
273 , __('Import from browser\'s storage') , '</label>'
274 , '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
275 , '<div class="localStorage-supported">'
276 , __('Settings will be imported from your browser\'s local storage.')
278 , '<div class="localStorage-exists">'
279 , __('Saved on: @DATE@')
281 , '<div class="localStorage-empty">';
282 Message
::notice(__('You have no saved settings!'))->display();
285 , '<div class="localStorage-unsupported">';
287 __('This feature is not supported by your web browser')
291 , '<input type="checkbox" id="import_merge" name="import_merge" />'
292 , '<label for="import_merge">'
293 , __('Merge with current configuration') . '</label>'
295 , '<input type="submit" name="submit_import" value="'
299 if (file_exists('setup/index.php')) {
300 // show only if setup script is available, allows to disable this message
301 // by simply removing setup directory
304 <h2
><?php
echo __('More settings') ?
></h2
>
305 <div
class="group-cnt">
309 'You can set more settings by modifying config.inc.php, eg. '
310 . 'by using %sSetup script%s.'
311 ), '<a href="setup/index.php" target="_blank">', '</a>'
312 ) , PMA\libraries\Util
::showDocu('setup', 'setup-script');
320 <div id
="main_pane_right">
322 <h2
><?php
echo __('Export'); ?
></h2
>
323 <div
class="click-hide-message group-cnt" style
="display:none">
326 __('Configuration has been saved.')
330 <form
class="group-cnt prefs-form disableAjax" name
="prefs_export"
331 action
="prefs_manage.php" method
="post">
332 <?php
echo URL
::getHiddenInputs(); ?
>
333 <div style
="padding-bottom:0.5em">
334 <input type
="radio" id
="export_text_file" name
="export_type"
335 value
="text_file" checked
="checked" />
336 <label
for="export_text_file">
337 <?php
echo __('Save as file'); ?
>
339 <input type
="radio" id
="export_php_file" name
="export_type"
341 <label
for="export_php_file">
342 <?php
echo __('Save as PHP file'); ?
>
344 <input type
="radio" id
="export_local_storage" name
="export_type"
345 value
="local_storage" disabled
="disabled" />
346 <label
for="export_local_storage">
347 <?php
echo __('Save to browser\'s storage'); ?
></label
>
349 <div id
="opts_export_local_storage"
350 class="prefsmanage_opts disabled">
351 <span
class="localStorage-supported">
354 'Settings will be saved in your browser\'s local '
358 <div
class="localStorage-exists">
362 'Existing settings will be overwritten!'
368 <div
class="localStorage-unsupported">
371 __('This feature is not supported by your web browser')
378 echo '<input type="submit" name="submit_export" value="' , __(
385 <h2
><?php
echo __('Reset'); ?
></h2
>
386 <form
class="group-cnt prefs-form disableAjax" name
="prefs_reset"
387 action
="prefs_manage.php" method
="post">
389 echo URL
::getHiddenInputs() , __(
390 'You can reset all your settings and restore them to default '
395 <input type
="submit" name
="submit_clear"
396 value
="<?php echo __('Reset'); ?>"/>
400 <br
class="clearfloat" />
404 if ($response->isAjax()) {
405 $response->addJSON('_disableNaviSettings', true);
407 define('PMA_DISABLE_NAVI_SETTINGS', true);