Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / prefs_manage.php
blobe85ab3d3c1b486db8e8eefd7f5229c297f9858a3
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 PMA_userprefsPageInit();
23 $error = '';
24 if (isset($_POST['submit_export'])
25 && filter_input(INPUT_POST, 'export_type') == 'text_file'
26 ) {
27 // export to JSON file
28 PMA_Response::getInstance()->disable();
29 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
30 PMA_downloadHeader($filename, 'application/json');
31 $settings = PMA_loadUserprefs();
32 echo json_encode($settings['config_data']);
33 exit;
34 } else if (isset($_POST['submit_get_json'])) {
35 $settings = PMA_loadUserprefs();
36 $response = PMA_Response::getInstance();
37 $response->addJSON('prefs', json_encode($settings['config_data']));
38 $response->addJSON('mtime', $settings['mtime']);
39 exit;
40 } else if (isset($_POST['submit_import'])) {
41 // load from JSON file
42 $json = '';
43 if (filter_input(INPUT_POST, 'import_type') == 'text_file'
44 && isset($_FILES['import_file'])
45 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
46 && is_uploaded_file($_FILES['import_file']['tmp_name'])
47 ) {
48 // read JSON from uploaded file
49 $open_basedir = @ini_get('open_basedir');
50 $file_to_unlink = '';
51 $import_file = $_FILES['import_file']['tmp_name'];
53 // If we are on a server with open_basedir, we must move the file
54 // before opening it. The doc explains how to create the "./tmp"
55 // directory
56 if (!empty($open_basedir)) {
57 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : 'tmp/');
58 if (is_writable($tmp_subdir)) {
59 $import_file_new = tempnam($tmp_subdir, 'prefs');
60 if (move_uploaded_file($import_file, $import_file_new)) {
61 $import_file = $import_file_new;
62 $file_to_unlink = $import_file_new;
66 $json = file_get_contents($import_file);
67 if ($file_to_unlink) {
68 unlink($file_to_unlink);
70 } else {
71 // read from POST value (json)
72 $json = filter_input(INPUT_POST, 'json');
75 // hide header message
76 $_SESSION['userprefs_autoload'] = true;
78 $config = json_decode($json, true);
79 $return_url = filter_input(INPUT_POST, 'return_url');
80 if (! is_array($config)) {
81 $error = __('Could not import configuration');
82 } else {
83 // sanitize input values: treat them as though
84 // they came from HTTP POST request
85 $form_display = new FormDisplay();
86 foreach ($forms as $formset_id => $formset) {
87 foreach ($formset as $form_name => $form) {
88 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
91 $cf = ConfigFile::getInstance();
92 $new_config = $cf->getFlatDefaultConfig();
93 if (!empty($_POST['import_merge'])) {
94 $new_config = array_merge($new_config, $cf->getConfigArray());
96 $new_config = array_merge($new_config, $config);
97 $_POST_bak = $_POST;
98 foreach ($new_config as $k => $v) {
99 $_POST[str_replace('/', '-', $k)] = $v;
101 $cf->resetConfigData();
102 $all_ok = $form_display->process(true, false);
103 $all_ok = $all_ok && !$form_display->hasErrors();
104 $_POST = $_POST_bak;
106 if (!$all_ok && isset($_POST['fix_errors'])) {
107 $form_display->fixErrors();
108 $all_ok = true;
110 if (!$all_ok) {
111 // mimic original form and post json in a hidden field
112 include 'libraries/user_preferences.inc.php';
113 $msg = PMA_Message::error(__('Configuration contains incorrect data for some fields.'));
114 $msg->display();
115 echo '<div class="config-form">';
116 $form_display->displayErrors();
117 echo '</div>';
119 <form action="prefs_manage.php" method="post">
120 <?php echo PMA_generate_common_hidden_inputs() . "\n"; ?>
121 <input type="hidden" name="json" value="<?php echo htmlspecialchars($json) ?>" />
122 <input type="hidden" name="fix_errors" value="1" />
123 <?php if (! empty($_POST['import_merge'])) { ?>
124 <input type="hidden" name="import_merge" value="1" />
125 <?php } ?>
126 <?php if ($return_url) { ?>
127 <input type="hidden" name="return_url" value="<?php echo htmlspecialchars($return_url) ?>" />
128 <?php } ?>
129 <p><?php echo __('Do you want to import remaining settings?') ?></p>
130 <input type="submit" name="submit_import" value="<?php echo __('Yes') ?>" />
131 <input type="submit" name="submit_ignore" value="<?php echo __('No') ?>" />
132 </form>
133 <?php
134 exit;
137 // check for ThemeDefault and fontsize
138 $params = array();
139 if (isset($config['ThemeDefault'])
140 && $_SESSION['PMA_Theme_Manager']->theme->getId() != $config['ThemeDefault']
141 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
143 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
144 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
146 if (isset($config['fontsize'])
147 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
149 $params['set_fontsize'] = $config['fontsize'];
151 if (isset($config['lang'])
152 && $config['lang'] != $GLOBALS['lang']
154 $params['lang'] = $config['lang'];
156 if (isset($config['collation_connection'])
157 && $config['collation_connection'] != $GLOBALS['collation_connection']
159 $params['collation_connection'] = $config['collation_connection'];
162 // save settings
163 $result = PMA_saveUserprefs($cf->getConfigArray());
164 if ($result === true) {
165 if ($return_url) {
166 $query = explode('&', parse_url($return_url, PHP_URL_QUERY));
167 $return_url = parse_url($return_url, PHP_URL_PATH);
168 foreach ($query as $q) {
169 $pos = strpos($q, '=');
170 $k = substr($q, 0, $pos);
171 if ($k == 'token') {
172 continue;
174 $params[$k] = substr($q, $pos+1);
176 } else {
177 $return_url = 'prefs_manage.php';
179 // reload config
180 $GLOBALS['PMA_Config']->loadUserPreferences();
181 PMA_userprefsRedirect($return_url, $params);
182 exit;
183 } else {
184 $error = $result;
187 } else if (isset($_POST['submit_clear'])) {
188 $result = PMA_saveUserprefs(array());
189 if ($result === true) {
190 $params = array();
191 if ($_SESSION['PMA_Theme_Manager']->theme->getId() != 'original') {
192 $GLOBALS['PMA_Config']->removeCookie(
193 $_SESSION['PMA_Theme_Manager']->getThemeCookieName()
195 unset($_SESSION['PMA_Theme_Manager']);
196 unset($_SESSION['PMA_Theme']);
198 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
199 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
201 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
202 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
203 PMA_userprefsRedirect('prefs_manage.php', $params);
204 exit;
205 } else {
206 $error = $result;
208 exit;
211 $response = PMA_Response::getInstance();
212 $header = $response->getHeader();
213 $scripts = $header->getScripts();
214 $scripts->addFile('config.js');
216 require 'libraries/user_preferences.inc.php';
217 if ($error) {
218 if (!$error instanceof PMA_Message) {
219 $error = PMA_Message::error($error);
221 $error->display();
224 <script type="text/javascript">
225 <?php
226 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
228 </script>
229 <div id="maincontainer">
230 <div id="main_pane_left">
231 <div class="group">
232 <h2><?php echo __('Import') ?></h2>
233 <form class="group-cnt prefs-form disableAjax" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data">
234 <?php
235 echo PMA_Util::generateHiddenMaxFileSize($max_upload_size) . "\n";
236 echo PMA_generate_common_hidden_inputs() . "\n";
238 <input type="hidden" name="json" value="" />
239 <input type="radio" id="import_text_file" name="import_type" value="text_file" checked="checked" />
240 <label for="import_text_file"><?php echo __('Import from file') ?></label>
241 <div id="opts_import_text_file" class="prefsmanage_opts">
242 <label for="input_import_file"><?php echo __('Browse your computer:'); ?></label>
243 <input type="file" name="import_file" id="input_import_file" />
244 </div>
245 <input type="radio" id="import_local_storage" name="import_type" value="local_storage" disabled="disabled" />
246 <label for="import_local_storage"><?php echo __('Import from browser\'s storage') ?></label>
247 <div id="opts_import_local_storage" class="prefsmanage_opts disabled">
248 <div class="localStorage-supported">
249 <?php echo __('Settings will be imported from your browser\'s local storage.') ?>
250 <br />
251 <div class="localStorage-exists">
252 <?php echo __('Saved on: @DATE@') ?>
253 </div>
254 <div class="localStorage-empty">
255 <?php PMA_Message::notice(__('You have no saved settings!'))->display() ?>
256 </div>
257 </div>
258 <div class="localStorage-unsupported">
259 <?php PMA_Message::notice(__('This feature is not supported by your web browser'))->display() ?>
260 </div>
261 </div>
263 <input type="checkbox" id="import_merge" name="import_merge" />
264 <label for="import_merge"><?php echo __('Merge with current configuration') ?></label>
265 <br /><br />
266 <input type="submit" name="submit_import" value="<?php echo __('Go'); ?>" />
267 </form>
268 </div>
269 <?php
270 if (file_exists('setup/index.php')) {
271 // show only if setup script is available, allows to disable this message
272 // by simply removing setup directory
274 <div class="group">
275 <h2><?php echo __('More settings') ?></h2>
276 <div class="group-cnt">
277 <?php
278 echo sprintf(__('You can set more settings by modifying config.inc.php, eg. by using %sSetup script%s.'), '<a href="setup/index.php" target="_blank">', '</a>');
279 echo PMA_Util::showDocu('setup', 'setup-script');
281 </div>
282 </div>
283 <?php
286 </div>
287 <div id="main_pane_right">
288 <div class="group">
289 <h2><?php echo __('Export') ?></h2>
290 <div class="click-hide-message group-cnt" style="display:none">
291 <?php
292 PMA_Message::rawSuccess(__('Configuration has been saved'))->display();
294 </div>
295 <form class="group-cnt prefs-form disableAjax" name="prefs_export" action="prefs_manage.php" method="post">
296 <?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
297 <div style="padding-bottom:0.5em">
298 <input type="radio" id="export_text_file" name="export_type" value="text_file" checked="checked" />
299 <label for="export_text_file"><?php echo __('Save as file') ?></label>
300 <br />
301 <input type="radio" id="export_local_storage" name="export_type" value="local_storage" disabled="disabled" />
302 <label for="export_local_storage"><?php echo __('Save to browser\'s storage') ?></label>
303 </div>
304 <div id="opts_export_local_storage" class="prefsmanage_opts disabled">
305 <span class="localStorage-supported">
306 <?php echo __('Settings will be saved in your browser\'s local storage.') ?>
307 <span class="localStorage-exists">
308 <br /><b><?php echo __('Existing settings will be overwritten!') ?></b>
309 </span>
310 </span>
311 <div class="localStorage-unsupported">
312 <?php PMA_Message::notice(__('This feature is not supported by your web browser'))->display() ?>
313 </div>
314 </div>
315 <br />
316 <input type="submit" name="submit_export" value="<?php echo __('Go'); ?>" />
317 </form>
318 </div>
319 <div class="group">
320 <h2><?php echo __('Reset') ?></h2>
321 <form class="group-cnt prefs-form disableAjax" name="prefs_reset" action="prefs_manage.php" method="post">
322 <?php echo PMA_generate_common_hidden_inputs() . "\n" ?>
323 <?php echo __('You can reset all your settings and restore them to default values.') ?>
324 <br /><br />
325 <input type="submit" name="submit_clear" value="<?php echo __('Reset') ?>" />
326 </form>
328 </div>
329 </div>
330 <br class="clearfloat" />
331 </div>