add missing @uses comments
[phpmyadmin.git] / prefs_manage.php
blob37b448b6656ce3efcc72ef600b1e14ec5b736b57
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
6 * @package phpMyAdmin
7 */
9 /**
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 $error = '';
22 if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == 'text_file') {
23 // export to JSON file
24 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
25 header('Content-Type: application/json');
26 header('Content-Disposition: attachment; filename="' . $filename . '"');
27 header('Expires: ' . date(DATE_RFC1123));
28 $settings = PMA_load_userprefs();
29 echo json_encode($settings['config_data']);
30 return;
31 } else if (isset($_POST['submit_get_json'])) {
32 $settings = PMA_load_userprefs();
33 header('Content-Type: application/json');
34 echo json_encode(array(
35 'prefs' => json_encode($settings['config_data']),
36 'mtime' => $settings['mtime']));
37 return;
38 } else if (isset($_POST['submit_import'])) {
39 // load from JSON file
40 $json = '';
41 if (filter_input(INPUT_POST, 'import_type') == 'text_file'
42 && isset($_FILES['import_file'])
43 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
44 && is_uploaded_file($_FILES['import_file']['tmp_name'])) {
45 // read JSON from uploaded file
46 $open_basedir = @ini_get('open_basedir');
47 $file_to_unlink = '';
48 $import_file = $_FILES['import_file']['tmp_name'];
50 // If we are on a server with open_basedir, we must move the file
51 // before opening it. The doc explains how to create the "./tmp"
52 // directory
53 if (!empty($open_basedir)) {
54 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : './tmp/');
55 if (is_writable($tmp_subdir)) {
56 $import_file_new = tempnam($tmp_subdir, 'prefs');
57 if (move_uploaded_file($import_file, $import_file_new)) {
58 $import_file = $import_file_new;
59 $file_to_unlink = $import_file_new;
63 $json = file_get_contents($import_file);
64 if ($file_to_unlink) {
65 unlink($file_to_unlink);
67 } else {
68 // read from POST value (json)
69 $json = filter_input(INPUT_POST, 'json');
72 // hide header message
73 $_SESSION['userprefs_autoload'] = true;
75 $config = json_decode($json, true);
76 $return_url = filter_input(INPUT_POST, 'return_url');
77 if (!is_array($config)) {
78 $error = __('Could not import configuration');
79 } else {
80 // sanitize input values: treat them as though they came from HTTP POST request
81 $form_display = new FormDisplay();
82 foreach ($forms as $formset_id => $formset) {
83 foreach ($formset as $form_name => $form) {
84 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
87 $cf = ConfigFile::getInstance();
88 if (empty($_POST['import_merge'])) {
89 $cf->resetConfigData();
91 $_POST_bak = $_POST;
92 foreach ($cf->getFlatDefaultConfig() as $k => $v) {
93 $_POST[str_replace('/', '-', $k)] = $v;
95 $_POST = array_merge($_POST, $config);
96 $all_ok = $form_display->process(true, false);
97 $all_ok = $all_ok && !$form_display->hasErrors();
98 $_POST = $_POST_bak;
100 if (!$all_ok && isset($_POST['fix_errors'])) {
101 $form_display->fixErrors();
102 $all_ok = true;
104 if (!$all_ok) {
105 // mimic original form and post json in a hidden field
106 require_once './libraries/header.inc.php';
107 require_once './libraries/user_preferences.inc.php';
108 $msg = PMA_Message::warning(__('Configuration contains incorrect data for some fields.'));
109 $msg->display();
110 echo '<div class="config-form">';
111 $form_display->displayErrors();
112 echo '</div>';
114 <form action="prefs_manage.php" method="post">
115 <?php echo PMA_generate_common_hidden_inputs() . "\n"; ?>
116 <input type="hidden" name="json" value="<?php echo htmlspecialchars($json) ?>" />
117 <input type="hidden" name="fix_errors" value="1" />
118 <?php if (!empty($_POST['import_merge'])): ?>
119 <input type="hidden" name="import_merge" value="1" />
120 <?php endif; ?>
121 <?php if ($return_url): ?>
122 <input type="hidden" name="return_url" value="<?php echo htmlspecialchars($return_url) ?>" />
123 <?php endif; ?>
124 <p><?php echo __('Do you want to import remaining settings?') ?></p>
125 <input type="submit" name="submit_import" value="<?php echo __('Yes') ?>" />
126 <input type="submit" name="submit_ignore" value="<?php echo __('No') ?>" />
127 </form>
128 <?php
129 require_once './libraries/footer.inc.php';
130 return;
133 // check for ThemeDefault and fontsize
134 $params = array();
135 if (isset($config['ThemeDefault'])
136 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])) {
137 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
138 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
139 $params['reload_left_frame'] = true;
141 if (isset($config['fontsize'])) {
142 $params['set_fontsize'] = $config['fontsize'];
143 $params['reload_left_frame'] = true;
146 // save settings
147 $old_settings = PMA_load_userprefs();
148 $result = PMA_save_userprefs($cf->getConfigArray());
149 if ($result === true) {
150 if ($return_url) {
151 $query = explode('&', parse_url($return_url, PHP_URL_QUERY));
152 $return_url = parse_url($return_url, PHP_URL_PATH);
153 foreach ($query as $q) {
154 $pos = strpos($q, '=');
155 $k = substr($q, 0, $pos);
156 if ($k == 'token') {
157 continue;
159 $params[$k] = substr($q, $pos+1);
161 } else {
162 $return_url = 'prefs_manage.php';
164 PMA_userprefs_redirect($forms, $old_settings, $return_url, $params);
165 exit;
166 } else {
167 $error = $result;
170 } else if (isset($_POST['submit_clear'])) {
171 $old_settings = PMA_load_userprefs();
172 $result = PMA_save_userprefs(array());
173 if ($result === true) {
174 $params = array();
175 if ($_SESSION['PMA_Theme_Manager']->theme->getId() != 'original') {
176 $GLOBALS['PMA_Config']->removeCookie($_SESSION['PMA_Theme_Manager']->getThemeCookieName());
177 unset($_SESSION['PMA_Theme_Manager']);
178 unset($_SESSION['PMA_Theme']);
179 $params['reload_left_frame'] = true;
181 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
182 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
183 $params['reload_left_frame'] = true;
185 PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params);
186 exit;
187 } else {
188 $error = $result;
190 exit;
193 $GLOBALS['js_include'][] = 'config.js';
194 require_once './libraries/header.inc.php';
195 require_once './libraries/user_preferences.inc.php';
197 <script type="text/javascript">
198 <?php
199 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: __DATE__'));
201 </script>
202 <div id="maincontainer">
203 <div id="main_pane_left">
204 <div class="group">
205 <h2><?php echo __('Import') ?></h2>
206 <form class="group-cnt prefs-form" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data">
207 <?php
208 echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
209 echo PMA_generate_common_hidden_inputs() . "\n";
211 <input type="hidden" name="json" value="" />
212 <div>
213 <input type="radio" id="import_text_file" name="import_type" value="text_file" checked="checked" />
214 <label for="import_text_file"><?php echo __('Import from text file') ?></label>
215 <br />
216 <input type="radio" id="import_local_storage" name="import_type" value="local_storage" disabled="disabled" />
217 <label for="import_local_storage"><?php echo __('Import from browser\'s storage') ?></label>
218 </div>
219 <div id="opts_import_text_file" class="prefsmanage_opts">
220 <label for="input_import_file"><?php echo __('Location of the text file'); ?></label>
221 <input type="file" name="import_file" id="input_import_file" />
222 </div>
223 <div id="opts_import_local_storage" class="prefsmanage_opts" style="display:none">
224 <div class="localStorage-supported">
225 <?php echo __('Settings will be imported from your browser\'s local storage.') ?>
226 <br />
227 <span class="localStorage-exists">
228 <?php echo __('Saved on: __DATE__') ?>
229 </span>
230 <span class="localStorage-empty">
231 <?php PMA_Message::notice(__('You have no saved settings!'))->display() ?>
232 </span>
233 </div>
234 <span class="localStorage-unsupported">
235 <?php PMA_Message::notice(__('This feature is not supported by your web browser'))->display() ?>
236 </span>
237 </div>
238 <input type="checkbox" id="import_merge" name="import_merge" />
239 <label for="import_merge"><?php echo __('Merge with current configuration') ?></label>
240 <br /><br />
241 <input type="submit" name="submit_import" value="<?php echo __('Go'); ?>" />
242 </form>
243 </div>
244 </div>
245 <div id="main_pane_right">
246 <div class="group">
247 <h2><?php echo __('Export') ?></h2>
248 <div class="click-hide-message group-cnt" style="display:none">
249 <?php
250 $message = PMA_Message::rawSuccess(__('Configuration has been saved'));
251 $message->display();
253 </div>
254 <form class="group-cnt prefs-form" name="prefs_export" action="prefs_manage.php" method="post">
255 <?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
256 <div style="padding-bottom:0.5em">
257 <input type="radio" id="export_text_file" name="export_type" value="text_file" checked="checked" />
258 <label for="export_text_file"><?php echo __('Save as file') ?></label>
259 <br />
260 <input type="radio" id="export_local_storage" name="export_type" value="local_storage" disabled="disabled" />
261 <label for="export_local_storage"><?php echo __('Save to browser\'s storage') ?></label>
262 </div>
263 <div id="opts_export_local_storage" class="prefsmanage_opts" style="display:none">
264 <span class="localStorage-supported">
265 <?php echo __('Settings will be saved in your browser\'s local storage.') ?>
266 <span class="localStorage-exists">
267 <b><?php PMA_Message::notice(__('Existing settings will be overridden!'))->display() ?></b>
268 </span>
269 </span>
270 <span class="localStorage-unsupported">
271 <?php PMA_Message::notice(__('This feature is not supported by your web browser'))->display() ?>
272 </span>
273 </div>
274 <br />
275 <input type="submit" name="submit_export" value="<?php echo __('Go'); ?>" />
276 </form>
277 </div>
278 <div class="group">
279 <h2><?php echo __('Reset') ?></h2>
280 <form class="group-cnt prefs-form" name="prefs_reset" action="prefs_manage.php" method="post">
281 <?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
282 <?php echo __('You can reset all your settings and restore them to default values') ?>
283 <br /><br />
284 <input type="submit" name="submit_clear" value="<?php echo __('Reset') ?>" />
285 </form>
287 </div>
288 </div>
289 <br class="clearfloat" />
290 </div>
291 <?php
293 * Displays the footer
295 require_once './libraries/footer.inc.php';