Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 336 lines (323 sloc) 14.748 kB
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
5 *
e56949f @nijel Use package name PhpMyAdmin
nijel authored
6 * @package PhpMyAdmin
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
7 */
8
9 /**
10 * Gets some core libraries and displays a top message if required
11 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
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';
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
20
279724d @Crack bugfix: user preferences don't work correctly without output buffering
Crack authored
21 PMA_userprefs_pageinit();
22
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
23 $error = '';
24 if (isset($_POST['submit_export']) && filter_input(INPUT_POST, 'export_type') == 'text_file') {
25 // export to JSON file
26 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
5b568db @nijel Use new function for download headers
nijel authored
27 PMA_download_header($filename, 'application/json');
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
28 $settings = PMA_load_userprefs();
29 echo json_encode($settings['config_data']);
30 return;
5717683 @Crack basic import/export for localStorage, needs to be polished
Crack authored
31 } else if (isset($_POST['submit_get_json'])) {
32 $settings = PMA_load_userprefs();
33 header('Content-Type: application/json');
3137cc2 @Crack add date information when importing from localStorage
Crack authored
34 echo json_encode(array(
35 'prefs' => json_encode($settings['config_data']),
36 'mtime' => $settings['mtime']));
5717683 @Crack basic import/export for localStorage, needs to be polished
Crack authored
37 return;
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
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'];
49
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)) {
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
54 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : 'tmp/');
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
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;
60 }
61 }
62 }
63 $json = file_get_contents($import_file);
64 if ($file_to_unlink) {
65 unlink($file_to_unlink);
66 }
67 } else {
68 // read from POST value (json)
69 $json = filter_input(INPUT_POST, 'json');
70 }
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
71
72 // hide header message
73 $_SESSION['userprefs_autoload'] = true;
74
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
75 $config = json_decode($json, true);
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
76 $return_url = filter_input(INPUT_POST, 'return_url');
e6211f0 @lem9 Other replacements for easier reading
lem9 authored
77 if (! is_array($config)) {
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
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);
85 }
86 }
87 $cf = ConfigFile::getInstance();
9d4c540 @Crack fix import merge
Crack authored
88 $new_config = $cf->getFlatDefaultConfig();
89 if (!empty($_POST['import_merge'])) {
90 $new_config = array_merge($new_config, $cf->getConfigArray());
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
91 }
9d4c540 @Crack fix import merge
Crack authored
92 $new_config = array_merge($new_config, $config);
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
93 $_POST_bak = $_POST;
9d4c540 @Crack fix import merge
Crack authored
94 foreach ($new_config as $k => $v) {
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
95 $_POST[str_replace('/', '-', $k)] = $v;
96 }
9d4c540 @Crack fix import merge
Crack authored
97 $cf->resetConfigData();
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
98 $all_ok = $form_display->process(true, false);
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
99 $all_ok = $all_ok && !$form_display->hasErrors();
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
100 $_POST = $_POST_bak;
101
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
102 if (!$all_ok && isset($_POST['fix_errors'])) {
103 $form_display->fixErrors();
104 $all_ok = true;
105 }
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
106 if (!$all_ok) {
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
107 // mimic original form and post json in a hidden field
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
108 include 'libraries/header.inc.php';
109 include 'libraries/user_preferences.inc.php';
b2b1953 @lem9 Start to replace warning level with error level
lem9 authored
110 $msg = PMA_Message::error(__('Configuration contains incorrect data for some fields.'));
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
111 $msg->display();
112 echo '<div class="config-form">';
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
113 $form_display->displayErrors();
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
114 echo '</div>';
115 ?>
116 <form action="prefs_manage.php" method="post">
117 <?php echo PMA_generate_common_hidden_inputs() . "\n"; ?>
118 <input type="hidden" name="json" value="<?php echo htmlspecialchars($json) ?>" />
119 <input type="hidden" name="fix_errors" value="1" />
120 <?php if (!empty($_POST['import_merge'])): ?>
121 <input type="hidden" name="import_merge" value="1" />
122 <?php endif; ?>
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
123 <?php if ($return_url): ?>
124 <input type="hidden" name="return_url" value="<?php echo htmlspecialchars($return_url) ?>" />
125 <?php endif; ?>
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
126 <p><?php echo __('Do you want to import remaining settings?') ?></p>
127 <input type="submit" name="submit_import" value="<?php echo __('Yes') ?>" />
128 <input type="submit" name="submit_ignore" value="<?php echo __('No') ?>" />
129 </form>
130 <?php
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
131 include 'libraries/footer.inc.php';
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
132 return;
133 }
134
135 // check for ThemeDefault and fontsize
136 $params = array();
137 if (isset($config['ThemeDefault'])
c67340d @Crack save lang and collation_connection to user preferences
Crack authored
138 && $_SESSION['PMA_Theme_Manager']->theme->getId() != $config['ThemeDefault']
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
139 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])) {
140 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
141 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
142 $params['reload_left_frame'] = true;
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
143 }
c67340d @Crack save lang and collation_connection to user preferences
Crack authored
144 if (isset($config['fontsize'])
145 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')) {
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
146 $params['set_fontsize'] = $config['fontsize'];
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
147 $params['reload_left_frame'] = true;
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
148 }
c67340d @Crack save lang and collation_connection to user preferences
Crack authored
149 if (isset($config['lang'])
150 && $config['lang'] != $GLOBALS['lang']) {
151 $params['lang'] = $config['lang'];
152 $params['reload_left_frame'] = true;
153 }
154 if (isset($config['collation_connection'])
155 && $config['collation_connection'] != $GLOBALS['collation_connection']) {
156 $params['collation_connection'] = $config['collation_connection'];
157 $params['reload_left_frame'] = true;
158 }
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
159
160 // save settings
161 $old_settings = PMA_load_userprefs();
162 $result = PMA_save_userprefs($cf->getConfigArray());
163 if ($result === true) {
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
164 if ($return_url) {
165 $query = explode('&', parse_url($return_url, PHP_URL_QUERY));
166 $return_url = parse_url($return_url, PHP_URL_PATH);
167 foreach ($query as $q) {
168 $pos = strpos($q, '=');
169 $k = substr($q, 0, $pos);
170 if ($k == 'token') {
171 continue;
172 }
173 $params[$k] = substr($q, $pos+1);
174 }
175 } else {
176 $return_url = 'prefs_manage.php';
177 }
a6b34a5 @Crack fix generation of theme unique value
Crack authored
178 // reload config
179 $GLOBALS['PMA_Config']->loadUserPreferences();
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
180 PMA_userprefs_redirect($forms, $old_settings, $return_url, $params);
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
181 exit;
182 } else {
183 $error = $result;
184 }
185 }
186 } else if (isset($_POST['submit_clear'])) {
187 $old_settings = PMA_load_userprefs();
188 $result = PMA_save_userprefs(array());
189 if ($result === true) {
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
190 $params = array();
191 if ($_SESSION['PMA_Theme_Manager']->theme->getId() != 'original') {
192 $GLOBALS['PMA_Config']->removeCookie($_SESSION['PMA_Theme_Manager']->getThemeCookieName());
193 unset($_SESSION['PMA_Theme_Manager']);
194 unset($_SESSION['PMA_Theme']);
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
195 $params['reload_left_frame'] = true;
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
196 }
197 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
198 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
7a5fd62 @Crack allow users to easily work with preferences stored in session (when p…
Crack authored
199 $params['reload_left_frame'] = true;
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
200 }
c67340d @Crack save lang and collation_connection to user preferences
Crack authored
201 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
202 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
e7dd9a7 @Crack allow to partially import broken configs - show message with error li…
Crack authored
203 PMA_userprefs_redirect($forms, $old_settings, 'prefs_manage.php', $params);
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
204 exit;
205 } else {
206 $error = $result;
207 }
208 exit;
209 }
210
211 $GLOBALS['js_include'][] = 'config.js';
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
212 require 'libraries/header.inc.php';
213 require 'libraries/user_preferences.inc.php';
98cbab0 @Crack second part of error message display changes
Crack authored
214 if ($error) {
215 if (!$error instanceof PMA_Message) {
216 $error = PMA_Message::error($error);
217 }
218 $error->display();
219 }
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
220 ?>
5717683 @Crack basic import/export for localStorage, needs to be polished
Crack authored
221 <script type="text/javascript">
222 <?php
51c9fcc @nijel Use same format string as in other places.
nijel authored
223 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
5717683 @Crack basic import/export for localStorage, needs to be polished
Crack authored
224 ?>
225 </script>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
226 <div id="maincontainer">
227 <div id="main_pane_left">
228 <div class="group">
229 <h2><?php echo __('Import') ?></h2>
230 <form class="group-cnt prefs-form" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data">
5717683 @Crack basic import/export for localStorage, needs to be polished
Crack authored
231 <?php
232 echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n";
233 echo PMA_generate_common_hidden_inputs() . "\n";
234 ?>
235 <input type="hidden" name="json" value="" />
7399ce3 @Crack a few changes on preferences manage page
Crack authored
236 <input type="radio" id="import_text_file" name="import_type" value="text_file" checked="checked" />
237 <label for="import_text_file"><?php echo __('Import from file') ?></label>
b3ae73f @Crack ui fixes
Crack authored
238 <div id="opts_import_text_file" class="prefsmanage_opts">
4441512 @lem9 Use newest message
lem9 authored
239 <label for="input_import_file"><?php echo __('Browse your computer:'); ?></label>
b3ae73f @Crack ui fixes
Crack authored
240 <input type="file" name="import_file" id="input_import_file" />
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
241 </div>
7399ce3 @Crack a few changes on preferences manage page
Crack authored
242 <input type="radio" id="import_local_storage" name="import_type" value="local_storage" disabled="disabled" />
243 <label for="import_local_storage"><?php echo __('Import from browser\'s storage') ?></label>
244 <div id="opts_import_local_storage" class="prefsmanage_opts disabled">
b3ae73f @Crack ui fixes
Crack authored
245 <div class="localStorage-supported">
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
246 <?php echo __('Settings will be imported from your browser\'s local storage.') ?>
b3ae73f @Crack ui fixes
Crack authored
247 <br />
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
248 <div class="localStorage-exists">
51c9fcc @nijel Use same format string as in other places.
nijel authored
249 <?php echo __('Saved on: @DATE@') ?>
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
250 </div>
251 <div class="localStorage-empty">
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
252 <?php PMA_Message::notice(__('You have no saved settings!'))->display() ?>
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
253 </div>
b3ae73f @Crack ui fixes
Crack authored
254 </div>
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
255 <div class="localStorage-unsupported">
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
256 <?php PMA_Message::notice(__('This feature is not supported by your web browser'))->display() ?>
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
257 </div>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
258 </div>
7399ce3 @Crack a few changes on preferences manage page
Crack authored
259
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
260 <input type="checkbox" id="import_merge" name="import_merge" />
261 <label for="import_merge"><?php echo __('Merge with current configuration') ?></label>
262 <br /><br />
263 <input type="submit" name="submit_import" value="<?php echo __('Go'); ?>" />
264 </form>
265 </div>
f7c3ea1 @Crack info about setup script in "manage your settings", it seems many peop…
Crack authored
266 <?php
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
267 if (file_exists('setup/index.php')) {
f7c3ea1 @Crack info about setup script in "manage your settings", it seems many peop…
Crack authored
268 // show only if setup script is available, allows to disable this message
269 // by simply removing setup directory
270 ?>
271 <div class="group">
272 <h2><?php echo __('More settings') ?></h2>
273 <div class="group-cnt">
274 <?php
275 echo sprintf(__('You can set more settings by modifying config.inc.php, eg. by using %sSetup script%s.'), '<a href="setup/index.php">', '</a>');
276 echo PMA_showDocu('setup_script');
277 ?>
278 </div>
279 </div>
280 <?php
281 }
282 ?>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
283 </div>
284 <div id="main_pane_right">
285 <div class="group">
286 <h2><?php echo __('Export') ?></h2>
625b9ed @Crack show message when preferences are saved to localStorage
Crack authored
287 <div class="click-hide-message group-cnt" style="display:none">
288 <?php
289 $message = PMA_Message::rawSuccess(__('Configuration has been saved'));
290 $message->display();
291 ?>
292 </div>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
293 <form class="group-cnt prefs-form" name="prefs_export" action="prefs_manage.php" method="post">
294 <?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
295 <div style="padding-bottom:0.5em">
296 <input type="radio" id="export_text_file" name="export_type" value="text_file" checked="checked" />
297 <label for="export_text_file"><?php echo __('Save as file') ?></label>
298 <br />
299 <input type="radio" id="export_local_storage" name="export_type" value="local_storage" disabled="disabled" />
300 <label for="export_local_storage"><?php echo __('Save to browser\'s storage') ?></label>
301 </div>
7399ce3 @Crack a few changes on preferences manage page
Crack authored
302 <div id="opts_export_local_storage" class="prefsmanage_opts disabled">
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
303 <span class="localStorage-supported">
304 <?php echo __('Settings will be saved in your browser\'s local storage.') ?>
305 <span class="localStorage-exists">
7399ce3 @Crack a few changes on preferences manage page
Crack authored
306 <br /><b><?php echo __('Existing settings will be overwritten!') ?></b>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
307 </span>
308 </span>
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
309 <div class="localStorage-unsupported">
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
310 <?php PMA_Message::notice(__('This feature is not supported by your web browser'))->display() ?>
5b09d0f Cleanup HTML5 validity issues
Jo Michael authored
311 </div>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
312 </div>
313 <br />
314 <input type="submit" name="submit_export" value="<?php echo __('Go'); ?>" />
315 </form>
316 </div>
317 <div class="group">
318 <h2><?php echo __('Reset') ?></h2>
5717683 @Crack basic import/export for localStorage, needs to be polished
Crack authored
319 <form class="group-cnt prefs-form" name="prefs_reset" action="prefs_manage.php" method="post">
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
320 <?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
59a84ae @nijel Add missing dot.
nijel authored
321 <?php echo __('You can reset all your settings and restore them to default values.') ?>
104ac11 @Crack import and export for user preferences (currently JSON file only)
Crack authored
322 <br /><br />
323 <input type="submit" name="submit_clear" value="<?php echo __('Reset') ?>" />
324 </form>
325
326 </div>
327 </div>
328 <br class="clearfloat" />
329 </div>
330 <?php
331 /**
332 * Displays the footer
333 */
b2fd866 Leading ./ paths for includes can be omitted, part 2
Jo Michael authored
334 require 'libraries/footer.inc.php';
51c9fcc @nijel Use same format string as in other places.
nijel authored
335 ?>
Something went wrong with that request. Please try again.