Translated using Weblate (Malayalam)
[phpmyadmin.git] / prefs_manage.php
blob326786ff2a23c278cc339d5c659abb929108855d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
6 * @package PhpMyAdmin
7 */
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\PMA_String;
13 use PMA\libraries\Util;
15 /**
16 * Gets some core libraries and displays a top message if required
18 require_once 'libraries/common.inc.php';
19 require_once 'libraries/user_preferences.lib.php';
20 require_once 'libraries/config/config_functions.lib.php';
21 require_once 'libraries/config/messages.inc.php';
22 require 'libraries/config/user_preferences.forms.php';
24 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
25 PMA_userprefsPageInit($cf);
27 $error = '';
28 if (isset($_POST['submit_export'])
29 && isset($_POST['export_type'])
30 && $_POST['export_type'] == 'text_file'
31 ) {
32 // export to JSON file
33 PMA\libraries\Response::getInstance()->disable();
34 $filename = 'phpMyAdmin-config-' . urlencode(PMA_getenv('HTTP_HOST')) . '.json';
35 PMA_downloadHeader($filename, 'application/json');
36 $settings = PMA_loadUserprefs();
37 echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
38 exit;
39 } else if (isset($_POST['submit_get_json'])) {
40 $settings = PMA_loadUserprefs();
41 $response = PMA\libraries\Response::getInstance();
42 $response->addJSON('prefs', json_encode($settings['config_data']));
43 $response->addJSON('mtime', $settings['mtime']);
44 exit;
45 } else if (isset($_POST['submit_import'])) {
46 // load from JSON file
47 $json = '';
48 if (isset($_POST['import_type'])
49 && $_POST['import_type'] == 'text_file'
50 && isset($_FILES['import_file'])
51 && $_FILES['import_file']['error'] == UPLOAD_ERR_OK
52 && is_uploaded_file($_FILES['import_file']['tmp_name'])
53 ) {
54 // read JSON from uploaded file
55 $open_basedir = @ini_get('open_basedir');
56 $file_to_unlink = '';
57 $import_file = $_FILES['import_file']['tmp_name'];
59 // If we are on a server with open_basedir, we must move the file
60 // before opening it. The doc explains how to create the "./tmp"
61 // directory
62 if (!empty($open_basedir)) {
63 $tmp_subdir = (PMA_IS_WINDOWS ? '.\\tmp\\' : 'tmp/');
64 if (is_writable($tmp_subdir)) {
65 $import_file_new = tempnam($tmp_subdir, 'prefs');
66 if (move_uploaded_file($import_file, $import_file_new)) {
67 $import_file = $import_file_new;
68 $file_to_unlink = $import_file_new;
72 $json = file_get_contents($import_file);
73 if ($file_to_unlink) {
74 unlink($file_to_unlink);
76 } else {
77 // read from POST value (json)
78 $json = isset($_POST['json']) ? $_POST['json'] : null;
81 // hide header message
82 $_SESSION['userprefs_autoload'] = true;
84 $config = json_decode($json, true);
85 $return_url = isset($_POST['return_url']) ? $_POST['return_url'] : null;
86 if (! is_array($config)) {
87 $error = __('Could not import configuration');
88 } else {
89 // sanitize input values: treat them as though
90 // they came from HTTP POST request
91 $form_display = new FormDisplay($cf);
92 foreach ($forms as $formset_id => $formset) {
93 foreach ($formset as $form_name => $form) {
94 $form_display->registerForm($formset_id . ': ' . $form_name, $form);
97 $new_config = $cf->getFlatDefaultConfig();
98 if (!empty($_POST['import_merge'])) {
99 $new_config = array_merge($new_config, $cf->getConfigArray());
101 $new_config = array_merge($new_config, $config);
102 $_POST_bak = $_POST;
103 foreach ($new_config as $k => $v) {
104 $_POST[str_replace('/', '-', $k)] = $v;
106 $cf->resetConfigData();
107 $all_ok = $form_display->process(true, false);
108 $all_ok = $all_ok && !$form_display->hasErrors();
109 $_POST = $_POST_bak;
111 if (!$all_ok && isset($_POST['fix_errors'])) {
112 $form_display->fixErrors();
113 $all_ok = true;
115 if (!$all_ok) {
116 // mimic original form and post json in a hidden field
117 include 'libraries/user_preferences.inc.php';
118 $msg = Message::error(
119 __('Configuration contains incorrect data for some fields.')
121 $msg->display();
122 echo '<div class="config-form">';
123 echo $form_display->displayErrors();
124 echo '</div>';
125 echo '<form action="prefs_manage.php" method="post">';
126 echo PMA_URL_getHiddenInputs() . "\n";
127 echo '<input type="hidden" name="json" value="'
128 . htmlspecialchars($json) . '" />';
129 echo '<input type="hidden" name="fix_errors" value="1" />';
130 if (! empty($_POST['import_merge'])) {
131 echo '<input type="hidden" name="import_merge" value="1" />';
133 if ($return_url) {
134 echo '<input type="hidden" name="return_url" value="'
135 . htmlspecialchars($return_url) . '" />';
137 echo '<p>';
138 echo __('Do you want to import remaining settings?');
139 echo '</p>';
140 echo '<input type="submit" name="submit_import" value="'
141 . __('Yes') . '" />';
142 echo '<input type="submit" name="submit_ignore" value="'
143 . __('No') . '" />';
144 echo '</form>';
145 exit;
148 // check for ThemeDefault and fontsize
149 $params = array();
150 if (isset($config['ThemeDefault'])
151 && $_SESSION['PMA_Theme_Manager']->theme->getId() != $config['ThemeDefault']
152 && $_SESSION['PMA_Theme_Manager']->checkTheme($config['ThemeDefault'])
154 $_SESSION['PMA_Theme_Manager']->setActiveTheme($config['ThemeDefault']);
155 $_SESSION['PMA_Theme_Manager']->setThemeCookie();
157 if (isset($config['fontsize'])
158 && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize')
160 $params['set_fontsize'] = $config['fontsize'];
162 if (isset($config['lang'])
163 && $config['lang'] != $GLOBALS['lang']
165 $params['lang'] = $config['lang'];
167 if (isset($config['collation_connection'])
168 && $config['collation_connection'] != $GLOBALS['collation_connection']
170 $params['collation_connection'] = $config['collation_connection'];
173 // save settings
174 $result = PMA_saveUserprefs($cf->getConfigArray());
175 if ($result === true) {
176 if ($return_url) {
177 $query = explode('&', parse_url($return_url, PHP_URL_QUERY));
178 $return_url = parse_url($return_url, PHP_URL_PATH);
180 /** @var String $pmaString */
181 $pmaString = $GLOBALS['PMA_String'];
183 foreach ($query as $q) {
184 $pos = /*overload*/mb_strpos($q, '=');
185 $k = /*overload*/mb_substr($q, 0, $pos);
186 if ($k == 'token') {
187 continue;
189 $params[$k] = /*overload*/mb_substr($q, $pos + 1);
191 } else {
192 $return_url = 'prefs_manage.php';
194 // reload config
195 $GLOBALS['PMA_Config']->loadUserPreferences();
196 PMA_userprefsRedirect($return_url, $params);
197 exit;
198 } else {
199 $error = $result;
202 } else if (isset($_POST['submit_clear'])) {
203 $result = PMA_saveUserprefs(array());
204 if ($result === true) {
205 $params = array();
206 if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') {
207 $GLOBALS['PMA_Config']->removeCookie('pma_fontsize');
209 $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection');
210 $GLOBALS['PMA_Config']->removeCookie('pma_lang');
211 PMA_userprefsRedirect('prefs_manage.php', $params);
212 exit;
213 } else {
214 $error = $result;
216 exit;
219 $response = Response::getInstance();
220 $header = $response->getHeader();
221 $scripts = $header->getScripts();
222 $scripts->addFile('config.js');
224 require 'libraries/user_preferences.inc.php';
225 if ($error) {
226 if (!$error instanceof Message) {
227 $error = Message::error($error);
229 $error->display();
232 <script type="text/javascript">
233 <?php
234 PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
236 </script>
237 <div id="maincontainer">
238 <div id="main_pane_left">
239 <div class="group">
240 <?php
241 echo '<h2>' . __('Import') . '</h2>'
242 . '<form class="group-cnt prefs-form disableAjax" name="prefs_import"'
243 . ' action="prefs_manage.php" method="post" enctype="multipart/form-data">'
244 . Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size'])
245 . PMA_URL_getHiddenInputs()
246 . '<input type="hidden" name="json" value="" />'
247 . '<input type="radio" id="import_text_file" name="import_type"'
248 . ' value="text_file" checked="checked" />'
249 . '<label for="import_text_file">' . __('Import from file') . '</label>'
250 . '<div id="opts_import_text_file" class="prefsmanage_opts">'
251 . '<label for="input_import_file">' . __('Browse your computer:') . '</label>'
252 . '<input type="file" name="import_file" id="input_import_file" />'
253 . '</div>'
254 . '<input type="radio" id="import_local_storage" name="import_type"'
255 . ' value="local_storage" disabled="disabled" />'
256 . '<label for="import_local_storage">'
257 . __('Import from browser\'s storage') . '</label>'
258 . '<div id="opts_import_local_storage" class="prefsmanage_opts disabled">'
259 . '<div class="localStorage-supported">'
260 . __('Settings will be imported from your browser\'s local storage.')
261 . '<br />'
262 . '<div class="localStorage-exists">'
263 . __('Saved on: @DATE@')
264 . '</div>'
265 . '<div class="localStorage-empty">';
266 Message::notice(__('You have no saved settings!'))->display();
267 echo '</div>'
268 . '</div>'
269 . '<div class="localStorage-unsupported">';
270 Message::notice(
271 __('This feature is not supported by your web browser')
272 )->display();
273 echo '</div>'
274 . '</div>'
275 . '<input type="checkbox" id="import_merge" name="import_merge" />'
276 . '<label for="import_merge">'
277 . __('Merge with current configuration') . '</label>'
278 . '<br /><br />'
279 . '<input type="submit" name="submit_import" value="'
280 . __('Go') . '" />'
281 . '</form>'
282 . '</div>';
283 if (file_exists('setup/index.php')) {
284 // show only if setup script is available, allows to disable this message
285 // by simply removing setup directory
287 <div class="group">
288 <h2><?php echo __('More settings') ?></h2>
289 <div class="group-cnt">
290 <?php
291 echo sprintf(
293 'You can set more settings by modifying config.inc.php, eg. '
294 . 'by using %sSetup script%s.'
295 ), '<a href="setup/index.php" target="_blank">', '</a>'
296 ) . PMA\libraries\Util::showDocu('setup', 'setup-script');
298 </div>
299 </div>
300 <?php
303 </div>
304 <div id="main_pane_right">
305 <div class="group">
306 <h2><?php echo __('Export'); ?></h2>
307 <div class="click-hide-message group-cnt" style="display:none">
308 <?php
309 Message::rawSuccess(
310 __('Configuration has been saved.')
311 )->display();
313 </div>
314 <form class="group-cnt prefs-form disableAjax" name="prefs_export"
315 action="prefs_manage.php" method="post">
316 <?php echo PMA_URL_getHiddenInputs(); ?>
317 <div style="padding-bottom:0.5em">
318 <input type="radio" id="export_text_file" name="export_type"
319 value="text_file" checked="checked" />
320 <label for="export_text_file">
321 <?php echo __('Save as file'); ?>
322 </label><br />
323 <input type="radio" id="export_local_storage" name="export_type"
324 value="local_storage" disabled="disabled" />
325 <label for="export_local_storage">
326 <?php echo __('Save to browser\'s storage'); ?></label>
327 </div>
328 <div id="opts_export_local_storage"
329 class="prefsmanage_opts disabled">
330 <span class="localStorage-supported">
331 <?php
332 echo __(
333 'Settings will be saved in your browser\'s local '
334 . 'storage.'
337 <div class="localStorage-exists">
339 <?php
340 echo __(
341 'Existing settings will be overwritten!'
344 </b>
345 </div>
346 </span>
347 <div class="localStorage-unsupported">
348 <?php
349 Message::notice(
350 __('This feature is not supported by your web browser')
351 )->display();
353 </div>
354 </div>
355 <br />
356 <?php
357 echo '<input type="submit" name="submit_export" value="' . __(
358 'Go'
359 ) . '" />';
361 </form>
362 </div>
363 <div class="group">
364 <h2><?php echo __('Reset'); ?></h2>
365 <form class="group-cnt prefs-form disableAjax" name="prefs_reset"
366 action="prefs_manage.php" method="post">
367 <?php
368 echo PMA_URL_getHiddenInputs() . __(
369 'You can reset all your settings and restore them to default '
370 . 'values.'
373 <br /><br />
374 <input type="submit" name="submit_clear"
375 value="<?php echo __('Reset'); ?>"/>
376 </form>
377 </div>
378 </div>
379 <br class="clearfloat" />
380 </div>
382 <?php
383 if ($response->isAjax()) {
384 $response->addJSON('_disableNaviSettings', true);
385 } else {
386 define('PMA_DISABLE_NAVI_SETTINGS', true);