Translated using Weblate (Turkish)
[phpmyadmin.git] / prefs_forms.php
blob7ac9261411f850c76ef0368aea480fc3ed91b0cd
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\Relation;
15 use PhpMyAdmin\Response;
16 use PhpMyAdmin\Template;
17 use PhpMyAdmin\TwoFactor;
18 use PhpMyAdmin\Url;
19 use PhpMyAdmin\UserPreferences;
20 use PhpMyAdmin\UserPreferencesHeader;
22 if (! defined('ROOT_PATH')) {
23 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
26 /**
27 * Gets some core libraries and displays a top message if required
29 require_once ROOT_PATH . 'libraries/common.inc.php';
31 /** @var Template $template */
32 $template = $containerBuilder->get('template');
33 $userPreferences = new UserPreferences();
35 $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
36 $userPreferences->pageInit($cf);
38 // handle form processing
40 $form_param = isset($_GET['form']) ? $_GET['form'] : null;
41 $form_class = UserFormList::get($form_param);
42 if ($form_class === null) {
43 Core::fatalError(__('Incorrect form specified!'));
46 /** @var BaseForm $form_display */
47 $form_display = new $form_class($cf, 1);
49 if (isset($_POST['revert'])) {
50 // revert erroneous fields to their default values
51 $form_display->fixErrors();
52 // redirect
53 $url_params = ['form' => $form_param];
54 Core::sendHeaderLocation(
55 './prefs_forms.php'
56 . Url::getCommonRaw($url_params)
58 exit;
61 $error = null;
62 if ($form_display->process(false) && ! $form_display->hasErrors()) {
63 // Load 2FA settings
64 $twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
65 // save settings
66 $result = $userPreferences->save($cf->getConfigArray());
67 // save back the 2FA setting only
68 $twoFactor->save();
69 if ($result === true) {
70 // reload config
71 $GLOBALS['PMA_Config']->loadUserPreferences();
72 $tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null;
73 $hash = ltrim($tabHash, '#');
74 $userPreferences->redirect(
75 'prefs_forms.php',
76 ['form' => $form_param],
77 $hash
79 exit;
80 } else {
81 $error = $result;
85 // display forms
86 $response = Response::getInstance();
87 $header = $response->getHeader();
88 $scripts = $header->getScripts();
89 $scripts->addFile('config.js');
91 /** @var Relation $relation */
92 $relation = $containerBuilder->get('relation');
93 echo UserPreferencesHeader::getContent($template, $relation);
95 if ($form_display->hasErrors()) {
96 $formErrors = $form_display->displayErrors();
99 echo $template->render('preferences/forms/main', [
100 'error' => $error ? $error->getDisplay() : '',
101 'has_errors' => $form_display->hasErrors(),
102 'errors' => $formErrors ?? null,
103 'form' => $form_display->getDisplay(true, true, true, 'prefs_forms.php?form=' . $form_param, [
104 'server' => $GLOBALS['server'],
108 if ($response->isAjax()) {
109 $response->addJSON('disableNaviSettings', true);
110 } else {
111 define('PMA_DISABLE_NAVI_SETTINGS', true);