Translated using Weblate (German)
[phpmyadmin.git] / prefs_forms.php
blobe8f5f4cf47e8635dc21d78833e84c347f0ac0874
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences page
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Config\ConfigFile;
11 use PhpMyAdmin\Config\Forms\BaseForm;
12 use PhpMyAdmin\Config\Forms\User\UserFormList;
13 use PhpMyAdmin\Core;
14 use PhpMyAdmin\Response;
15 use PhpMyAdmin\Template;
16 use PhpMyAdmin\Url;
17 use PhpMyAdmin\UserPreferences;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
23 /**
24 * Gets some core libraries and displays a top message if required
26 require_once ROOT_PATH . 'libraries/common.inc.php';
28 $template = new Template();
29 $userPreferences = new UserPreferences();
31 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
32 $userPreferences->pageInit($cf);
34 // handle form processing
36 $form_param = isset($_GET['form']) ? $_GET['form'] : null;
37 $form_class = UserFormList::get($form_param);
38 if (is_null($form_class)) {
39 Core::fatalError(__('Incorrect form specified!'));
42 /** @var BaseForm $form_display */
43 $form_display = new $form_class($cf, 1);
45 if (isset($_POST['revert'])) {
46 // revert erroneous fields to their default values
47 $form_display->fixErrors();
48 // redirect
49 $url_params = ['form' => $form_param];
50 Core::sendHeaderLocation(
51 './prefs_forms.php'
52 . Url::getCommonRaw($url_params)
54 exit;
57 $error = null;
58 if ($form_display->process(false) && ! $form_display->hasErrors()) {
59 // save settings
60 $result = $userPreferences->save($cf->getConfigArray());
61 if ($result === true) {
62 // reload config
63 $GLOBALS['PMA_Config']->loadUserPreferences();
64 $tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null;
65 $hash = ltrim($tabHash, '#');
66 $userPreferences->redirect(
67 'prefs_forms.php',
68 ['form' => $form_param],
69 $hash
71 exit;
72 } else {
73 $error = $result;
77 // display forms
78 $response = Response::getInstance();
79 $header = $response->getHeader();
80 $scripts = $header->getScripts();
81 $scripts->addFile('config.js');
83 require ROOT_PATH . 'libraries/user_preferences.inc.php';
85 if ($form_display->hasErrors()) {
86 $formErrors = $form_display->displayErrors();
89 echo $template->render('preferences/forms/main', [
90 'error' => $error ? $error->getDisplay() : '',
91 'has_errors' => $form_display->hasErrors(),
92 'errors' => $formErrors ?? null,
93 'form' => $form_display->getDisplay(true, true),
94 ]);
96 if ($response->isAjax()) {
97 $response->addJSON('_disableNaviSettings', true);
98 } else {
99 define('PMA_DISABLE_NAVI_SETTINGS', true);