[BUGFIX] Only show download location as configured
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / Controller / BackendUserController.php
1 <?php
2 namespace TYPO3\CMS\Beuser\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Felix Kopp <felix-source@phorax.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * 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 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * Backend module user administration controller
30 *
31 * @author Felix Kopp <felix-source@phorax.com>
32 * @package TYPO3
33 * @subpackage beuser
34 */
35 class BackendUserController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
36
37 /**
38 * @var \TYPO3\CMS\Beuser\Domain\Model\ModuleData
39 */
40 protected $moduleData;
41
42 /**
43 * @var \TYPO3\CMS\Beuser\Service\ModuleDataStorageService
44 * @inject
45 */
46 protected $moduleDataStorageService;
47
48 /**
49 * @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserRepository
50 * @inject
51 */
52 protected $backendUserRepository;
53
54 /**
55 * @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserGroupRepository
56 * @inject
57 */
58 protected $backendUserGroupRepository;
59
60 /**
61 * @var \TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
62 * @inject
63 */
64 protected $backendUserSessionRepository;
65
66 /**
67 * Load and persist module data
68 *
69 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request
70 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response
71 * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
72 * @return void
73 */
74 public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
75 $this->moduleData = $this->moduleDataStorageService->loadModuleData();
76 // We "finally" persist the module data.
77 try {
78 parent::processRequest($request, $response);
79 $this->moduleDataStorageService->persistModuleData($this->moduleData);
80 } catch (\CMS\Extbase\Mvc\Exception\StopActionException $e) {
81 $this->moduleDataStorageService->persistModuleData($this->moduleData);
82 throw $e;
83 }
84 }
85
86 /**
87 * Initialize actions
88 *
89 * @throws \RuntimeException
90 * @return void
91 */
92 public function initializeAction() {
93 // @TODO: Extbase backend modules relies on frontend TypoScript for view, persistence
94 // and settings. Thus, we need a TypoScript root template, that then loads the
95 // ext_typoscript_setup.txt file of this module. This is nasty, but can not be
96 // circumvented until there is a better solution in extbase.
97 // For now we throw an exception if no settings are detected.
98 if (empty($this->settings)) {
99 throw new \RuntimeException('No settings detected. This module can not work then. This usually happens if there is no frontend TypoScript template with root flag set. ' . 'Please create a frontend page with a TypoScript root template.', 1344375003);
100 }
101 }
102
103 /**
104 * Displays all BackendUsers
105 * - Switch session to different user
106 *
107 * @param \TYPO3\CMS\Beuser\Domain\Model\Demand $demand
108 * @return void
109 */
110 public function indexAction(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand = NULL) {
111 if ($demand === NULL) {
112 $demand = $this->moduleData->getDemand();
113 } else {
114 $this->moduleData->setDemand($demand);
115 }
116 // Switch user permanently or only until logout
117 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SwitchUser')) {
118 $this->switchUser(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SwitchUser'), \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('switchBackUser'));
119 }
120 $compareUserList = $this->moduleData->getCompareUserList();
121 $this->view->assign('demand', $demand);
122 $this->view->assign('returnUrl', 'mod.php?M=tools_BeuserTxBeuser');
123 $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
124 $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
125 $this->view->assign('backendUsers', $this->backendUserRepository->findDemanded($demand));
126 $this->view->assign('backendUserGroups', array_merge(array(''), $this->backendUserGroupRepository->findAll()->toArray()));
127 $this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
128 }
129
130 /**
131 * Views all currently logged in BackendUsers and their sessions
132 *
133 * @return void
134 */
135 public function onlineAction() {
136 $onlineUsersAndSessions = array();
137 $onlineUsers = $this->backendUserRepository->findOnline();
138 foreach ($onlineUsers as $onlineUser) {
139 $onlineUsersAndSessions[] = array(
140 'backendUser' => $onlineUser,
141 'sessions' => $this->backendUserSessionRepository->findByBackendUser($onlineUser)
142 );
143 }
144 $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
145 $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
146 $this->view->assign('onlineUsersAndSessions', $onlineUsersAndSessions);
147 $this->view->assign('currentSessionId', $GLOBALS['BE_USER']->user['ses_id']);
148 }
149
150 /**
151 * Compare backend users from demand
152 *
153 * @return void
154 */
155 public function compareAction() {
156 $compareUserList = $this->moduleData->getCompareUserList();
157 $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
158 $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
159 $this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
160 }
161
162 /**
163 * Attaches one backend user to the compare list
164 *
165 * @param integer $uid
166 * @retun void
167 */
168 public function addToCompareListAction($uid) {
169 $this->moduleData->attachUidCompareUser($uid);
170 $this->forward('index');
171 }
172
173 /**
174 * Removes given backend user to the compare list
175 *
176 * @param integer $uid
177 * @retun void
178 */
179 public function removeFromCompareListAction($uid) {
180 $this->moduleData->detachUidCompareUser($uid);
181 $this->forward('index');
182 }
183
184 /**
185 * Terminate BackendUser session and logout corresponding client
186 * Redirects to onlineAction with message
187 *
188 * @param \TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser
189 * @param string $sessionId
190 * @return void
191 */
192 protected function terminateBackendUserSessionAction(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser, $sessionId) {
193 $GLOBALS['TYPO3_DB']->exec_DELETEquery('be_sessions', 'ses_userid = "' . intval($backendUser->getUid()) . '" AND ses_id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($sessionId, 'be_sessions') . ' LIMIT 1');
194 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
195 $message = 'Session successfully terminated.';
196 $this->flashMessageContainer->add($message, '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
197 }
198 $this->forward('online');
199 }
200
201 /**
202 * Switches to a given user (SU-mode) and then redirects to the start page of the backend to refresh the navigation etc.
203 *
204 * @param array $switchUser BE-user record that will be switched to
205 * @param boolean $switchBack
206 * @return void
207 */
208 protected function switchUser($switchUser, $switchBack = FALSE) {
209 $targetUser = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $switchUser);
210 if (is_array($targetUser) && $GLOBALS['BE_USER']->isAdmin()) {
211 $updateData['ses_userid'] = $targetUser['uid'];
212 // User switchback or replace current session?
213 if ($switchBack) {
214 $updateData['ses_backuserid'] = intval($GLOBALS['BE_USER']->user['uid']);
215 }
216 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_sessions', 'ses_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') . ' AND ses_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions') . ' AND ses_userid=' . intval($GLOBALS['BE_USER']->user['uid']), $updateData);
217 $redirectUrl = $GLOBALS['BACK_PATH'] . 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
218 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
219 }
220 }
221
222 }
223
224
225 ?>