1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* sysPass |
4
|
|
|
* |
5
|
|
|
* @author nuxsmin |
6
|
|
|
* @link https://syspass.org |
7
|
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
8
|
|
|
* |
9
|
|
|
* This file is part of sysPass. |
10
|
|
|
* |
11
|
|
|
* sysPass is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* sysPass is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU General Public License |
22
|
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace SP\Modules\Web\Controllers; |
26
|
|
|
|
27
|
|
|
use SP\Core\Acl\Acl; |
28
|
|
|
use SP\Core\Events\Event; |
29
|
|
|
use SP\Core\Events\EventDispatcherInterface; |
30
|
|
|
use SP\Core\Language; |
31
|
|
|
use SP\Modules\Web\Controllers\Helpers\TabsHelper; |
32
|
|
|
use SP\Mvc\Controller\ExtensibleTabControllerInterface; |
33
|
|
|
use SP\Mvc\View\Components\DataTab; |
34
|
|
|
use SP\Mvc\View\Components\SelectItemAdapter; |
35
|
|
|
use SP\Mvc\View\Template; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class UserSettingsManagerController |
39
|
|
|
* |
40
|
|
|
* @package web\Controllers |
41
|
|
|
*/ |
42
|
|
|
final class UserSettingsManagerController extends ControllerBase implements ExtensibleTabControllerInterface |
43
|
|
|
{ |
44
|
|
|
/** |
45
|
|
|
* @var TabsHelper |
46
|
|
|
*/ |
47
|
|
|
protected $tabsHelper; |
48
|
|
|
|
49
|
|
|
public function indexAction() |
50
|
|
|
{ |
51
|
|
|
$this->getTabs(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns a tabbed grid with items |
56
|
|
|
*/ |
57
|
|
|
protected function getTabs() |
58
|
|
|
{ |
59
|
|
|
$this->tabsHelper = $this->dic->get(TabsHelper::class); |
60
|
|
|
|
61
|
|
|
$this->tabsHelper->addTab($this->getUserPreferences()); |
62
|
|
|
|
63
|
|
|
$this->eventDispatcher->notifyEvent('show.userSettings', new Event($this)); |
64
|
|
|
|
65
|
|
|
$this->tabsHelper->renderTabs(Acl::getActionRoute(Acl::USERSETTINGS), $this->request->analyzeInt('tabIndex', 0)); |
66
|
|
|
|
67
|
|
|
$this->view(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return DataTab |
72
|
|
|
*/ |
73
|
|
|
private function getUserPreferences() |
74
|
|
|
{ |
75
|
|
|
$template = clone $this->view; |
76
|
|
|
$template->setBase('usersettings'); |
77
|
|
|
$template->addTemplate('general'); |
78
|
|
|
|
79
|
|
|
$userData = $this->session->getUserData(); |
80
|
|
|
$userPreferences = $userData->getPreferences(); |
81
|
|
|
|
82
|
|
|
$template->assign('langs', SelectItemAdapter::factory(Language::getAvailableLanguages())->getItemsFromArraySelected([$userPreferences->getLang() ?: $this->configData->getSiteLang()])); |
83
|
|
|
$template->assign('themes', SelectItemAdapter::factory($this->theme->getThemesAvailable())->getItemsFromArraySelected([$userPreferences->getTheme() ?: $this->configData->getSiteTheme()])); |
84
|
|
|
$template->assign('chkAccountLink', $userPreferences->isAccountLink() ? 'checked="checked"' : ''); |
85
|
|
|
$template->assign('resultsPerPage', $userPreferences->getResultsPerPage() ?: $this->configData->getAccountCount()); |
86
|
|
|
$template->assign('chkSortViews', $userPreferences->isSortViews() ? 'checked="checked"' : ''); |
87
|
|
|
$template->assign('chkTopNavbar', $userPreferences->isTopNavbar() ? 'checked="checked"' : ''); |
88
|
|
|
$template->assign('chkOptionalActions', $userPreferences->isOptionalActions() ? 'checked="checked"' : ''); |
89
|
|
|
$template->assign('chkResultsAsCards', $userPreferences->isResultsAsCards() ? 'checked="checked"' : ''); |
90
|
|
|
$template->assign('route', 'userSettingsGeneral/save'); |
91
|
|
|
|
92
|
|
|
return new DataTab(__('Preferencias'), $template); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param DataTab $tab |
97
|
|
|
*/ |
98
|
|
|
public function addTab(DataTab $tab) |
99
|
|
|
{ |
100
|
|
|
$this->tabsHelper->addTab($tab); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return Template |
105
|
|
|
*/ |
106
|
|
|
public function getView(): Template |
107
|
|
|
{ |
108
|
|
|
return $this->view; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return void |
113
|
|
|
*/ |
114
|
|
|
public function displayView() |
115
|
|
|
{ |
116
|
|
|
$this->view(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return EventDispatcherInterface |
121
|
|
|
*/ |
122
|
|
|
public function getEventDispatcher(): EventDispatcherInterface |
123
|
|
|
{ |
124
|
|
|
return $this->eventDispatcher; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
129
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
130
|
|
|
* @throws \SP\Services\Auth\AuthException |
131
|
|
|
*/ |
132
|
|
|
protected function initialize() |
133
|
|
|
{ |
134
|
|
|
$this->checkLoggedIn(); |
135
|
|
|
} |
136
|
|
|
} |