3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Controllers\Preferences
;
8 use PhpMyAdmin\Config\ConfigFile
;
9 use PhpMyAdmin\Config\Forms\User\MainForm
;
10 use PhpMyAdmin\ConfigStorage\Relation
;
11 use PhpMyAdmin\Controllers\AbstractController
;
12 use PhpMyAdmin\ResponseRenderer
;
13 use PhpMyAdmin\Routing
;
14 use PhpMyAdmin\Template
;
15 use PhpMyAdmin\TwoFactor
;
17 use PhpMyAdmin\UserPreferences
;
22 class MainPanelController
extends AbstractController
24 /** @var UserPreferences */
25 private $userPreferences;
33 public function __construct(
34 ResponseRenderer
$response,
36 UserPreferences
$userPreferences,
40 parent
::__construct($response, $template);
41 $this->userPreferences
= $userPreferences;
42 $this->relation
= $relation;
43 $this->config
= $config;
46 public function __invoke(): void
48 $route = Routing
::getCurrentRoute();
50 $GLOBALS['cf'] = new ConfigFile($this->config
->baseSettings
);
51 $this->userPreferences
->pageInit($GLOBALS['cf']);
53 $formDisplay = new MainForm($GLOBALS['cf'], 1);
55 if (isset($_POST['revert'])) {
56 // revert erroneous fields to their default values
57 $formDisplay->fixErrors();
58 $this->redirect('/preferences/main-panel');
63 $GLOBALS['error'] = null;
64 if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
66 $twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
68 $result = $this->userPreferences
->save($GLOBALS['cf']->getConfigArray());
69 // save back the 2FA setting only
71 if ($result === true) {
73 $this->config
->loadUserPreferences();
74 $GLOBALS['tabHash'] = $_POST['tab_hash'] ??
null;
75 $GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
76 $this->userPreferences
->redirect('index.php?route=/preferences/main-panel', null, $GLOBALS['hash']);
81 $GLOBALS['error'] = $result;
84 $this->addScriptFiles(['config.js']);
86 $relationParameters = $this->relation
->getRelationParameters();
88 $this->render('preferences/header', [
90 'is_saved' => ! empty($_GET['saved']),
91 'has_config_storage' => $relationParameters->userPreferencesFeature
!== null,
94 if ($formDisplay->hasErrors()) {
95 $formErrors = $formDisplay->displayErrors();
98 $this->render('preferences/forms/main', [
99 'error' => $GLOBALS['error'] ?
$GLOBALS['error']->getDisplay() : '',
100 'has_errors' => $formDisplay->hasErrors(),
101 'errors' => $formErrors ??
null,
102 'form' => $formDisplay->getDisplay(
104 Url
::getFromRoute('/preferences/main-panel'),
105 ['server' => $GLOBALS['server']]
109 if ($this->response
->isAjax()) {
110 $this->response
->addJSON('disableNaviSettings', true);
112 define('PMA_DISABLE_NAVI_SETTINGS', true);