2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * User preferences page
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config\ConfigFile
;
11 use PhpMyAdmin\Config\Forms\BaseForm
;
12 use PhpMyAdmin\Config\Forms\User\UserFormList
;
14 use PhpMyAdmin\Relation
;
15 use PhpMyAdmin\Response
;
16 use PhpMyAdmin\Template
;
17 use PhpMyAdmin\TwoFactor
;
19 use PhpMyAdmin\UserPreferences
;
20 use PhpMyAdmin\UserPreferencesHeader
;
22 if (! defined('ROOT_PATH')) {
23 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
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();
53 $url_params = ['form' => $form_param];
54 Core
::sendHeaderLocation(
56 . Url
::getCommonRaw($url_params)
62 if ($form_display->process(false) && ! $form_display->hasErrors()) {
64 $twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
66 $result = $userPreferences->save($cf->getConfigArray());
67 // save back the 2FA setting only
69 if ($result === true) {
71 $GLOBALS['PMA_Config']->loadUserPreferences();
72 $tabHash = isset($_POST['tab_hash']) ?
$_POST['tab_hash'] : null;
73 $hash = ltrim($tabHash, '#');
74 $userPreferences->redirect(
76 ['form' => $form_param],
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);
111 define('PMA_DISABLE_NAVI_SETTINGS', true);