2 namespace TYPO3\CMS\Setup\Controller
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * Script class for the Setup module
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
25 class SetupModuleController
{
30 public $MCONF = array();
35 public $MOD_MENU = array();
40 public $MOD_SETTINGS = array();
43 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
58 * backend user object, set during simulate-user operation
60 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
67 public $languageUpdate;
72 protected $pagetreeNeedsRefresh = FALSE;
82 protected $tsFieldConf;
87 protected $saveData = FALSE;
92 protected $passwordIsUpdated = FALSE;
97 protected $passwordIsSubmitted = FALSE;
102 protected $setupIsUpdated = FALSE;
107 protected $tempDataIsCleared = FALSE;
112 protected $settingsAreResetToDefault = FALSE;
115 * Form protection instance
117 * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection
119 protected $formProtection;
124 protected $simulateSelector = '';
129 protected $simUser = '';
132 * Instantiate the form protection before a simulated user is initialized.
134 public function __construct() {
135 $this->formProtection
= \TYPO3\CMS\Core\FormProtection\FormProtectionFactory
::get();
139 * Getter for the form protection instance.
141 * @return \TYPO3\CMS\Core\FormProtection\BackendFormProtection
143 public function getFormProtection() {
144 return $this->formProtection
;
148 * If settings are submitted to _POST[DATA], store them
149 * NOTICE: This method is called before the \TYPO3\CMS\Backend\Template\DocumentTemplate
150 * is included. See bottom of document.
152 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
154 public function storeIncomingData() {
155 // First check if something is submitted in the data-array from POST vars
156 $d = GeneralUtility
::_POST('data');
157 $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
158 $beUserId = $GLOBALS['BE_USER']->user
['uid'];
160 $fieldList = $this->getFieldsFromShowItem();
161 if (is_array($d) && $this->formProtection
->validateToken((string)GeneralUtility
::_POST('formToken'), 'BE user setup', 'edit')) {
162 // UC hashed before applying changes
163 $save_before = md5(serialize($GLOBALS['BE_USER']->uc
));
164 // PUT SETTINGS into the ->uc array:
165 // Reload left frame when switching BE language
166 if (isset($d['lang']) && $d['lang'] != $GLOBALS['BE_USER']->uc
['lang']) {
167 $this->languageUpdate
= TRUE;
169 // Reload pagetree if the title length is changed
170 if (isset($d['titleLen']) && $d['titleLen'] !== $GLOBALS['BE_USER']->uc
['titleLen']) {
171 $this->pagetreeNeedsRefresh
= TRUE;
173 if ($d['setValuesToDefault']) {
174 // If every value should be default
175 $GLOBALS['BE_USER']->resetUC();
176 $this->settingsAreResetToDefault
= TRUE;
177 } elseif ($d['clearSessionVars']) {
178 foreach ($GLOBALS['BE_USER']->uc
as $key => $value) {
179 if (!isset($columns[$key])) {
180 unset($GLOBALS['BE_USER']->uc
[$key]);
183 $this->tempDataIsCleared
= TRUE;
184 } elseif ($d['save']) {
185 // Save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
186 foreach ($columns as $field => $config) {
187 if (!in_array($field, $fieldList)) {
190 if ($config['table']) {
191 if ($config['table'] === 'be_users' && !in_array($field, array('password', 'password2', 'email', 'realName', 'admin'))) {
192 if (!isset($config['access']) ||
$this->checkAccess($config) && $GLOBALS['BE_USER']->user
[$field] !== $d['be_users'][$field]) {
193 if ($config['type'] === 'check') {
194 $fieldValue = isset($d['be_users'][$field]) ?
1 : 0;
196 $fieldValue = $d['be_users'][$field];
198 $storeRec['be_users'][$beUserId][$field] = $fieldValue;
199 $GLOBALS['BE_USER']->user
[$field] = $fieldValue;
203 if ($config['type'] === 'check') {
204 $GLOBALS['BE_USER']->uc
[$field] = isset($d[$field]) ?
1 : 0;
206 $GLOBALS['BE_USER']->uc
[$field] = htmlspecialchars($d[$field]);
209 // Personal data for the users be_user-record (email, name, password...)
210 // If email and name is changed, set it in the users record:
211 $be_user_data = $d['be_users'];
212 // Possibility to modify the transmitted values. Useful to do transformations, like RSA password decryption
213 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'])) {
214 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'] as $function) {
215 $params = array('be_user_data' => &$be_user_data);
216 GeneralUtility
::callUserFunction($function, $params, $this);
219 $this->passwordIsSubmitted
= strlen($be_user_data['password']) > 0;
220 $passwordIsConfirmed = $this->passwordIsSubmitted
&& $be_user_data['password'] === $be_user_data['password2'];
221 // Update the real name:
222 if ($be_user_data['realName'] !== $GLOBALS['BE_USER']->user
['realName']) {
223 $GLOBALS['BE_USER']->user
['realName'] = ($storeRec['be_users'][$beUserId]['realName'] = substr($be_user_data['realName'], 0, 80));
225 // Update the email address:
226 if ($be_user_data['email'] !== $GLOBALS['BE_USER']->user
['email']) {
227 $GLOBALS['BE_USER']->user
['email'] = ($storeRec['be_users'][$beUserId]['email'] = substr($be_user_data['email'], 0, 80));
229 // Update the password:
230 if ($passwordIsConfirmed) {
231 $storeRec['be_users'][$beUserId]['password'] = $be_user_data['password2'];
232 $this->passwordIsUpdated
= TRUE;
234 $this->saveData
= TRUE;
236 // Inserts the overriding values.
237 $GLOBALS['BE_USER']->overrideUC();
238 $save_after = md5(serialize($GLOBALS['BE_USER']->uc
));
239 // If something in the uc-array of the user has changed, we save the array...
240 if ($save_before != $save_after) {
241 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc
);
242 $GLOBALS['BE_USER']->writelog(254, 1, 0, 1, 'Personal settings changed', array());
243 $this->setupIsUpdated
= TRUE;
245 // If the temporary data has been cleared, lets make a log note about it
246 if ($this->tempDataIsCleared
) {
247 $GLOBALS['BE_USER']->writelog(254, 1, 0, 1, $GLOBALS['LANG']->getLL('tempDataClearedLog'), array());
249 // Persist data if something has changed:
250 if (count($storeRec) && $this->saveData
) {
251 // Make instance of TCE for storing the changes.
252 $tce = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler
::class);
253 $tce->stripslashes_values
= 0;
254 $tce->start($storeRec, array(), $GLOBALS['BE_USER']);
255 // This is so the user can actually update his user record.
257 // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
258 $tce->bypassWorkspaceRestrictions
= TRUE;
259 $tce->process_datamap();
261 if (!$this->passwordIsUpdated ||
count($storeRec['be_users'][$beUserId]) > 1) {
262 $this->setupIsUpdated
= TRUE;
268 /******************************
272 ******************************/
274 * Initializes the module for display of the settings form.
278 public function init() {
279 $GLOBALS['LANG']->includeLLFile('EXT:setup/mod/locallang.xlf');
280 $this->MCONF
= $GLOBALS['MCONF'];
281 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
282 $scriptUser = $this->getRealScriptUserObj();
283 // ... and checking module access for the logged in user.
284 $scriptUser->modAccess($this->MCONF
, 1);
285 $this->isAdmin
= $scriptUser->isAdmin();
286 // Getting the 'override' values as set might be set in User TSconfig
287 $this->overrideConf
= $GLOBALS['BE_USER']->getTSConfigProp('setup.override');
288 // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1)
289 $this->tsFieldConf
= $GLOBALS['BE_USER']->getTSConfigProp('setup.fields');
290 // id password is disabled, disable repeat of password too (password2)
291 if (isset($this->tsFieldConf
['password.']) && $this->tsFieldConf
['password.']['disabled']) {
292 $this->tsFieldConf
['password2.']['disabled'] = 1;
294 // Create instance of object for output of data
295 $this->doc
= GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate
::class);
296 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
297 $this->doc
->setModuleTemplate('EXT:setup/Resources/Private/Templates/setup.html');
298 $this->doc
->form
= '<form action="' . BackendUtility
::getModuleUrl('user_setup') . '" method="post" name="usersetup" enctype="application/x-www-form-urlencoded">';
299 $this->doc
->addStyleSheet('module', 'sysext/setup/Resources/Public/Styles/styles.css');
300 $this->doc
->JScode
.= $this->getJavaScript();
304 * Generate necessary JavaScript
308 protected function getJavaScript() {
310 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'])) {
311 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'] as $function) {
313 $javaScript .= GeneralUtility
::callUserFunction($function, $params, $this);
320 * Generate the main settings form:
324 public function main() {
325 if ($this->languageUpdate
) {
326 $this->doc
->JScodeArray
['languageUpdate'] .= '
327 if (top.refreshMenu) {
330 top.TYPO3ModuleMenu.refreshMenu();
334 if ($this->pagetreeNeedsRefresh
) {
335 BackendUtility
::setUpdateSignal('updatePageTree');
338 $this->doc
->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/md5.js');
340 $this->content
.= '<div id="user-setup-wrapper">';
341 // Load available backend modules
342 $this->loadModules
= GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Module\ModuleLoader
::class);
343 $this->loadModules
->observeWorkspaces
= TRUE;
344 $this->loadModules
->load($GLOBALS['TBE_MODULES']);
345 $this->content
.= $this->doc
->header($GLOBALS['LANG']->getLL('UserSettings'));
346 // Show if setup was saved
347 if ($this->setupIsUpdated
&& !$this->tempDataIsCleared
&& !$this->settingsAreResetToDefault
) {
348 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('setupWasUpdated'), $GLOBALS['LANG']->getLL('UserSettings'));
349 $this->content
.= $flashMessage->render();
351 // Show if temporary data was cleared
352 if ($this->tempDataIsCleared
) {
353 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('tempDataClearedFlashMessage'), $GLOBALS['LANG']->getLL('tempDataCleared'));
354 $this->content
.= $flashMessage->render();
356 // Show if temporary data was cleared
357 if ($this->settingsAreResetToDefault
) {
358 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('settingsAreReset'), $GLOBALS['LANG']->getLL('resetConfiguration'));
359 $this->content
.= $flashMessage->render();
362 if ($this->setupIsUpdated ||
$this->settingsAreResetToDefault
) {
363 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('activateChanges'), '', \TYPO3\CMS\Core\Messaging\FlashMessage
::INFO
);
364 $this->content
.= $flashMessage->render();
366 // If password is updated, output whether it failed or was OK.
367 if ($this->passwordIsSubmitted
) {
368 if ($this->passwordIsUpdated
) {
369 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('newPassword_ok'), $GLOBALS['LANG']->getLL('newPassword'));
371 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $GLOBALS['LANG']->getLL('newPassword_failed'), $GLOBALS['LANG']->getLL('newPassword'), \TYPO3\CMS\Core\Messaging\FlashMessage
::ERROR
);
373 $this->content
.= $flashMessage->render();
376 // Render user switch
377 $this->content
.= $this->renderSimulateUserSelectAndLabel();
379 // Render the menu items
380 $menuItems = $this->renderUserSetup();
381 $this->content
.= $this->doc
->getDynTabMenu($menuItems, 'user-setup', FALSE, FALSE, 1, FALSE, 1, 1);
382 $formToken = $this->formProtection
->generateToken('BE user setup', 'edit');
383 $this->content
.= $this->doc
->section('', '<input type="hidden" name="simUser" value="' . $this->simUser
. '" />
384 <input type="hidden" name="formToken" value="' . $formToken . '" />
385 <input type="hidden" value="1" name="data[save]" />
386 <input type="hidden" name="data[setValuesToDefault]" value="0" id="setValuesToDefault" />
387 <input type="hidden" name="data[clearSessionVars]" value="0" id="clearSessionVars" />');
388 // End of wrapper div
389 $this->content
.= '</div>';
390 // Setting up the buttons and markers for docheader
391 $docHeaderButtons = $this->getButtons();
392 $markers['CSH'] = $docHeaderButtons['csh'];
393 $markers['CONTENT'] = $this->content
;
394 // Build the <body> for the module
395 $this->content
= $this->doc
->moduleBody($this->pageinfo
, $docHeaderButtons, $markers);
396 // Renders the module page
397 $this->content
= $this->doc
->render($GLOBALS['LANG']->getLL('UserSettings'), $this->content
);
401 * Prints the content / ends page
405 public function printContent() {
410 * Create the panel of buttons for submitting the form or otherwise perform operations.
412 * @return array All available buttons as an assoc. array
414 protected function getButtons() {
420 $buttons['csh'] = BackendUtility
::cshItem('_MOD_user_setup', '');
421 $buttons['save'] = \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('actions-document-save', array('html' => '<input type="image" name="data[save]" class="c-inputButton" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" />'));
422 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
423 $buttons['shortcut'] = $this->doc
->makeShortcutIcon('', '', $this->MCONF
['name']);
428 /******************************
432 ******************************/
435 * renders the data for all tabs in the user setup and returns
436 * everything that is needed with tabs and dyntab menu
438 * @return array Ready to use for the dyntabmenu itemarray
440 protected function renderUserSetup() {
445 $fieldArray = $this->getFieldsFromShowItem();
447 foreach ($fieldArray as $fieldName) {
449 if (substr($fieldName, 0, 8) === '--div--;') {
450 if ($firstTabLabel === '') {
452 $tabLabel = $this->getLabel(substr($fieldName, 8), '', FALSE);
453 $firstTabLabel = $tabLabel;
456 'label' => $tabLabel,
457 'content' => count($code) ?
implode(LF
, $code) : ''
459 $tabLabel = $this->getLabel(substr($fieldName, 8), '', FALSE);
465 $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
467 // Field my be disabled in setup.fields
468 if (isset($this->tsFieldConf
[$fieldName . '.']['disabled']) && $this->tsFieldConf
[$fieldName . '.']['disabled'] == 1) {
471 if (isset($config['access']) && !$this->checkAccess($config)) {
474 $label = $this->getLabel($config['label'], $fieldName);
475 $label = $this->getCSH($config['csh'] ?
: $fieldName, $label);
476 $type = $config['type'];
477 $class = $config['class'];
479 if ($type !== 'check') {
480 $class .= ' form-control';
483 $style = $config['style'];
485 $more .= ' class="' . $class . '"';
488 $more .= ' style="' . $style . '"';
490 if (isset($this->overrideConf
[$fieldName])) {
491 $more .= ' disabled="disabled"';
493 $value = $config['table'] === 'be_users' ?
$GLOBALS['BE_USER']->user
[$fieldName] : $GLOBALS['BE_USER']->uc
[$fieldName];
494 if (!$value && isset($config['default'])) {
495 $value = $config['default'];
498 if ($config['table'] === 'be_users') {
499 $dataAdd = '[be_users]';
506 $noAutocomplete = '';
507 if ($type === 'password') {
509 $noAutocomplete = 'autocomplete="off" ';
511 $html = '<input id="field_' . $fieldName . '"
513 name="data' . $dataAdd . '[' . $fieldName . ']" ' .
515 'value="' . htmlspecialchars($value) . '" ' .
521 $html = $label . '<div class="checkbox"><label><input id="field_' . $fieldName . '"
523 name="data' . $dataAdd . '[' . $fieldName . ']"' .
524 ($value ?
' checked="checked"' : '') .
531 if ($config['itemsProcFunc']) {
532 $html = GeneralUtility
::callUserFunction($config['itemsProcFunc'], $config, $this, '');
534 $html = '<select id="field_' . $fieldName . '"
535 name="data' . $dataAdd . '[' . $fieldName . ']"' .
537 foreach ($config['items'] as $key => $optionLabel) {
538 $html .= '<option value="' . $key . '"' . ($value == $key ?
' selected="selected"' : '') . '>' . $this->getLabel($optionLabel, '', FALSE) . '</option>' . LF
;
540 $html .= '</select>';
545 $html = GeneralUtility
::callUserFunction($config['userFunc'], $config, $this, '');
549 if ($config['onClick']) {
550 $onClick = $config['onClick'];
551 if ($config['onClickLabels']) {
552 foreach ($config['onClickLabels'] as $key => $labelclick) {
553 $config['onClickLabels'][$key] = $this->getLabel($labelclick, '', FALSE);
555 $onClick = vsprintf($onClick, $config['onClickLabels']);
557 $html = '<br><input type="button"
558 value="' . $this->getLabel($config['buttonlabel'], '', FALSE) . '"
559 onclick="' . $onClick . '" />';
567 $code[] = '<div class="form-group">' .
574 'label' => $tabLabel,
575 'content' => count($code) ?
implode(LF
, $code) : ''
580 /******************************
584 ******************************/
586 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
587 * Anyway: The REAL user is returned - the one logged in.
589 * @return object The REAL user is returned - the one logged in.
591 protected function getRealScriptUserObj() {
592 return is_object($this->OLD_BE_USER
) ?
$this->OLD_BE_USER
: $GLOBALS['BE_USER'];
596 * Return a select with available languages
598 * @return string Complete select as HTML string or warning box if something went wrong.
600 public function renderLanguageSelect($params, $pObj) {
601 $languageOptions = array();
602 // Compile the languages dropdown
603 $langDefault = $GLOBALS['LANG']->getLL('lang_default', TRUE);
604 $languageOptions[$langDefault] = '<option value=""' . ($GLOBALS['BE_USER']->uc
['lang'] === '' ?
' selected="selected"' : '') . '>' . $langDefault . '</option>';
605 // Traverse the number of languages
606 /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
607 $locales = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Localization\Locales
::class);
608 $languages = $locales->getLanguages();
609 foreach ($languages as $locale => $name) {
610 if ($locale !== 'default') {
611 $defaultName = isset($GLOBALS['LOCAL_LANG']['default']['lang_' . $locale]) ?
$GLOBALS['LOCAL_LANG']['default']['lang_' . $locale][0]['source'] : $name;
612 $localizedName = $GLOBALS['LANG']->getLL('lang_' . $locale, TRUE);
613 if ($localizedName === '') {
614 $localizedName = htmlspecialchars($name);
616 $localLabel = ' - [' . htmlspecialchars($defaultName) . ']';
617 $available = is_dir(PATH_typo3conf
. 'l10n/' . $locale) ?
TRUE : FALSE;
619 $languageOptions[$defaultName] = '<option value="' . $locale . '"' . ($GLOBALS['BE_USER']->uc
['lang'] === $locale ?
' selected="selected"' : '') . '>' . $localizedName . $localLabel . '</option>';
623 ksort($languageOptions);
625 <select id="field_lang" name="data[lang]" class="form-control">' . implode('', $languageOptions) . '
627 if ($GLOBALS['BE_USER']->uc
['lang'] && !@is_dir
((PATH_typo3conf
. 'l10n/' . $GLOBALS['BE_USER']->uc
['lang']))) {
628 $languageUnavailableWarning = 'The selected language "' . $GLOBALS['LANG']->getLL(('lang_' . $GLOBALS['BE_USER']->uc
['lang']), TRUE) . '" is not available before the language pack is installed.<br />' . ($GLOBALS['BE_USER']->isAdmin() ?
'You can use the Extension Manager to easily download and install new language packs.' : 'Please ask your system administrator to do this.');
629 $languageUnavailableMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, $languageUnavailableWarning, '', \TYPO3\CMS\Core\Messaging\FlashMessage
::WARNING
);
630 $languageCode = $languageUnavailableMessage->render() . $languageCode;
632 return $languageCode;
636 * Returns a select with all modules for startup
638 * @return string Complete select as HTML string
640 public function renderStartModuleSelect($params, $pObj) {
641 // Start module select
642 if (empty($GLOBALS['BE_USER']->uc
['startModule'])) {
643 $GLOBALS['BE_USER']->uc
['startModule'] = $GLOBALS['BE_USER']->uc_default
['startModule'];
645 $startModuleSelect = '<option value=""></option>';
646 foreach ($pObj->loadModules
->modules
as $mainMod => $modData) {
647 if (isset($modData['sub']) && is_array($modData['sub'])) {
648 $startModuleSelect .= '<option disabled="disabled">' . $GLOBALS['LANG']->moduleLabels
['tabs'][($mainMod . '_tab')] . '</option>';
649 foreach ($modData['sub'] as $subKey => $subData) {
650 $modName = $subData['name'];
651 $startModuleSelect .= '<option value="' . $modName . '"' . ($GLOBALS['BE_USER']->uc
['startModule'] == $modName ?
' selected="selected"' : '') . '>';
652 $startModuleSelect .= ' - ' . $GLOBALS['LANG']->moduleLabels
['tabs'][($modName . '_tab')] . '</option>';
656 return '<select id="field_startModule" name="data[startModule]" class="form-control">' . $startModuleSelect . '</select>';
660 * Will make the simulate-user selector if the logged in user is administrator.
661 * It will also set the GLOBAL(!) BE_USER to the simulated user selected if any (and set $this->OLD_BE_USER to logged in user)
665 public function simulateUser() {
666 // If admin, allow simulation of another user
668 $this->simulateSelector
= '';
669 unset($this->OLD_BE_USER
);
670 if ($GLOBALS['BE_USER']->isAdmin()) {
671 $this->simUser
= (int)GeneralUtility
::_GP('simUser');
672 // Make user-selector:
673 $users = BackendUtility
::getUserNames('username,usergroup,usergroup_cached_list,uid,realName', BackendUtility
::BEenableFields('be_users'));
675 foreach ($users as $rr) {
676 if ($rr['uid'] != $GLOBALS['BE_USER']->user
['uid']) {
677 $label = htmlspecialchars(($rr['username'] . ($rr['realName'] ?
' (' . $rr['realName'] . ')' : '')));
678 $opt[] = '<option value="' . $rr['uid'] . '"' . ($this->simUser
== $rr['uid'] ?
' selected="selected"' : '') . '>' . $label . '</option>';
682 $this->simulateSelector
= '<select id="field_simulate" name="simulateUser" onchange="window.location.href=' . GeneralUtility
::quoteJSvalue(BackendUtility
::getModuleUrl('user_setup') . '&simUser=') . '+this.options[this.selectedIndex].value;"><option></option>' . implode('', $opt) . '</select>';
685 // This can only be set if the previous code was executed.
686 if ($this->simUser
> 0) {
688 $this->OLD_BE_USER
= $GLOBALS['BE_USER'];
689 unset($GLOBALS['BE_USER']);
691 // New backend user object
692 $BE_USER = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication
::class);
693 $BE_USER->OS
= TYPO3_OS
;
694 $BE_USER->setBeUserByUid($this->simUser
);
695 $BE_USER->fetchGroupData();
696 $BE_USER->backendSetUC();
697 // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
698 $GLOBALS['BE_USER'] = $BE_USER;
703 * Render simulate user select and label
707 protected function renderSimulateUserSelectAndLabel() {
708 if ($this->simulateSelector
=== '') {
713 '<label for="field_simulate" style="margin-right: 20px;">' .
714 $GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xlf:simulate') .
716 $this->simulateSelector
.
721 * Returns access check (currently only "admin" is supported)
723 * @param array $config Configuration of the field, access mode is defined in key 'access'
724 * @return bool Whether it is allowed to modify the given field
726 protected function checkAccess(array $config) {
727 $access = $config['access'];
729 $accessObject = GeneralUtility
::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access] . ':&' . $access);
730 if (is_object($accessObject) && method_exists($accessObject, 'accessLevelCheck')) {
731 // Initialize vars. If method fails, $set will be set to FALSE
732 return $accessObject->accessLevelCheck($config);
733 } elseif ($access == 'admin') {
734 return $this->isAdmin
;
741 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
743 * @param string $str Locallang key
744 * @param string $key Alternative override-config key
745 * @param bool $addLabelTag Defines whether the string should be wrapped in a <label> tag.
746 * @param string $altLabelTagId Alternative id for use in "for" attribute of <label> tag. By default the $str key is used prepended with "field_".
747 * @return string HTML output.
749 protected function getLabel($str, $key = '', $addLabelTag = TRUE, $altLabelTagId = '') {
750 if (substr($str, 0, 4) === 'LLL:') {
751 $out = $GLOBALS['LANG']->sL($str);
753 $out = htmlspecialchars($str);
755 if (isset($this->overrideConf
[$key ?
: $str])) {
756 $out = '<span style="color:#999999">' . $out . '</span>';
759 $out = '<label for="' . ($altLabelTagId ?
: 'field_' . $key) . '">' . $out . '</label>';
765 * Returns the CSH Icon for given string
767 * @param string $str Locallang key
768 * @param string $label The label to be used, that should be wrapped in help
769 * @return string HTML output.
771 protected function getCSH($str, $label) {
772 $context = '_MOD_user_setup';
774 $strParts = explode(':', $str);
775 if (count($strParts) > 1) {
776 // Setting comes from another extension
777 $context = $strParts[0];
778 $field = $strParts[1];
779 } elseif (!GeneralUtility
::inList('language,simuser,reset', $str)) {
780 $field = 'option_' . $str;
782 return BackendUtility
::wrapInHelp($context, $field, $label);
786 * Returns array with fields defined in $GLOBALS['TYPO3_USER_SETTINGS']['showitem']
788 * @return array Array with fieldnames visible in form
790 protected function getFieldsFromShowItem() {
791 $fieldList = $GLOBALS['TYPO3_USER_SETTINGS']['showitem'];
792 // Disable fields depended on settings
793 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
794 $fieldList = GeneralUtility
::rmFromList('edit_RTE', $fieldList);
796 $fieldArray = GeneralUtility
::trimExplode(',', $fieldList, TRUE);