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 Psr\Http\Message\ResponseInterface
;
18 use Psr\Http\Message\ServerRequestInterface
;
19 use TYPO3\CMS\Backend\Backend\Avatar\DefaultAvatarProvider
;
20 use TYPO3\CMS\Backend\Module\AbstractModule
;
21 use TYPO3\CMS\Backend\Module\ModuleLoader
;
22 use TYPO3\CMS\Backend\Template\Components\ButtonBar
;
23 use TYPO3\CMS\Backend\Utility\BackendUtility
;
24 use TYPO3\CMS\Core\Imaging\Icon
;
25 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
26 use TYPO3\CMS\Core\Database\DatabaseConnection
;
27 use TYPO3\CMS\Core\DataHandling\DataHandler
;
28 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory
;
29 use TYPO3\CMS\Core\Messaging\FlashMessage
;
30 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
;
31 use TYPO3\CMS\Core\Resource\ResourceFactory
;
32 use TYPO3\CMS\Core\Utility\GeneralUtility
;
35 * Script class for the Setup module
37 class SetupModuleController
extends AbstractModule
40 * Flag if password has not been updated
42 const PASSWORD_NOT_UPDATED
= 0;
45 * Flag if password has been updated
47 const PASSWORD_UPDATED
= 1;
50 * Flag if both new passwords do not match
52 const PASSWORD_NOT_THE_SAME
= 2;
55 * Flag if the current password given was not identical to the real
58 const PASSWORD_OLD_WRONG
= 3;
63 public $MOD_MENU = array();
68 public $MOD_SETTINGS = array();
71 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
86 * backend user object, set during simulate-user operation
88 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
95 public $languageUpdate;
100 protected $pagetreeNeedsRefresh = false
;
110 protected $tsFieldConf;
115 protected $saveData = false
;
120 protected $passwordIsUpdated = self
::PASSWORD_NOT_UPDATED
;
125 protected $passwordIsSubmitted = false
;
130 protected $setupIsUpdated = false
;
135 protected $tempDataIsCleared = false
;
140 protected $settingsAreResetToDefault = false
;
143 * Form protection instance
145 * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection
147 protected $formProtection;
152 protected $simulateSelector = '';
157 protected $simUser = '';
160 * The name of the module
164 protected $moduleName = 'user_setup';
169 protected $loadModules;
172 * Instantiate the form protection before a simulated user is initialized.
174 public function __construct()
176 parent
::__construct();
177 $this->formProtection
= FormProtectionFactory
::get();
181 * Getter for the form protection instance.
183 * @return \TYPO3\CMS\Core\FormProtection\BackendFormProtection
185 public function getFormProtection()
187 return $this->formProtection
;
191 * If settings are submitted to _POST[DATA], store them
192 * NOTICE: This method is called before the \TYPO3\CMS\Backend\Template\DocumentTemplate
193 * is included. See bottom of document.
195 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
197 public function storeIncomingData()
199 // First check if something is submitted in the data-array from POST vars
200 $d = GeneralUtility
::_POST('data');
201 $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
202 $beUser = $this->getBackendUser();
203 $beUserId = $beUser->user
['uid'];
205 $fieldList = $this->getFieldsFromShowItem();
206 if (is_array($d) && $this->formProtection
->validateToken((string)GeneralUtility
::_POST('formToken'), 'BE user setup', 'edit')) {
207 // UC hashed before applying changes
208 $save_before = md5(serialize($beUser->uc
));
209 // PUT SETTINGS into the ->uc array:
210 // Reload left frame when switching BE language
211 if (isset($d['lang']) && $d['lang'] != $beUser->uc
['lang']) {
212 $this->languageUpdate
= true
;
214 // Reload pagetree if the title length is changed
215 if (isset($d['titleLen']) && $d['titleLen'] !== $beUser->uc
['titleLen']) {
216 $this->pagetreeNeedsRefresh
= true
;
218 if ($d['setValuesToDefault']) {
219 // If every value should be default
221 $this->settingsAreResetToDefault
= true
;
222 } elseif ($d['clearSessionVars']) {
223 foreach ($beUser->uc
as $key => $value) {
224 if (!isset($columns[$key])) {
225 unset($beUser->uc
[$key]);
228 $this->tempDataIsCleared
= true
;
229 } elseif ($d['save']) {
230 // Save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
231 foreach ($columns as $field => $config) {
232 if (!in_array($field, $fieldList)) {
235 if ($config['table']) {
236 if ($config['table'] === 'be_users' && !in_array($field, array('password', 'password2', 'passwordCurrent', 'email', 'realName', 'admin', 'avatar'))) {
237 if (!isset($config['access']) ||
$this->checkAccess($config) && $beUser->user
[$field] !== $d['be_users'][$field]) {
238 if ($config['type'] === 'check') {
239 $fieldValue = isset($d['be_users'][$field]) ?
1 : 0;
241 $fieldValue = $d['be_users'][$field];
243 $storeRec['be_users'][$beUserId][$field] = $fieldValue;
244 $beUser->user
[$field] = $fieldValue;
248 if ($config['type'] === 'check') {
249 $beUser->uc
[$field] = isset($d[$field]) ?
1 : 0;
251 $beUser->uc
[$field] = htmlspecialchars($d[$field]);
254 // Personal data for the users be_user-record (email, name, password...)
255 // If email and name is changed, set it in the users record:
256 $be_user_data = $d['be_users'];
257 // Possibility to modify the transmitted values. Useful to do transformations, like RSA password decryption
258 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'])) {
259 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'] as $function) {
260 $params = array('be_user_data' => &$be_user_data);
261 GeneralUtility
::callUserFunction($function, $params, $this);
264 $this->passwordIsSubmitted
= (string)$be_user_data['password'] !== '';
265 $passwordIsConfirmed = $this->passwordIsSubmitted
&& $be_user_data['password'] === $be_user_data['password2'];
266 // Update the real name:
267 if ($be_user_data['realName'] !== $beUser->user
['realName']) {
268 $beUser->user
['realName'] = ($storeRec['be_users'][$beUserId]['realName'] = substr($be_user_data['realName'], 0, 80));
270 // Update the email address:
271 if ($be_user_data['email'] !== $beUser->user
['email']) {
272 $beUser->user
['email'] = ($storeRec['be_users'][$beUserId]['email'] = substr($be_user_data['email'], 0, 80));
274 // Update the password:
275 if ($passwordIsConfirmed) {
276 $currentPasswordHashed = $GLOBALS['BE_USER']->user
['password'];
277 $saltFactory = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory
::getSaltingInstance($currentPasswordHashed);
278 if ($saltFactory->checkPassword($be_user_data['passwordCurrent'], $currentPasswordHashed)) {
279 $this->passwordIsUpdated
= self
::PASSWORD_UPDATED
;
280 $storeRec['be_users'][$beUserId]['password'] = $be_user_data['password'];
282 $this->passwordIsUpdated
= self
::PASSWORD_OLD_WRONG
;
285 $this->passwordIsUpdated
= self
::PASSWORD_NOT_THE_SAME
;
288 $this->setAvatarFileUid($beUserId, $be_user_data['avatar'], $storeRec);
290 $this->saveData
= true
;
292 // Inserts the overriding values.
293 $beUser->overrideUC();
294 $save_after = md5(serialize($beUser->uc
));
295 // If something in the uc-array of the user has changed, we save the array...
296 if ($save_before != $save_after) {
297 $beUser->writeUC($beUser->uc
);
298 $beUser->writelog(254, 1, 0, 1, 'Personal settings changed', array());
299 $this->setupIsUpdated
= true
;
301 // If the temporary data has been cleared, lets make a log note about it
302 if ($this->tempDataIsCleared
) {
303 $beUser->writelog(254, 1, 0, 1, $this->getLanguageService()->getLL('tempDataClearedLog'), array());
305 // Persist data if something has changed:
306 if (!empty($storeRec) && $this->saveData
) {
307 // Make instance of TCE for storing the changes.
308 /** @var DataHandler $dataHandler */
309 $dataHandler = GeneralUtility
::makeInstance(DataHandler
::class);
310 $dataHandler->stripslashes_values
= false
;
311 // This is so the user can actually update his user record.
312 $isAdmin = $beUser->user
['admin'];
313 $beUser->user
['admin'] = 1;
314 $dataHandler->start($storeRec, array(), $beUser);
315 // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
316 $dataHandler->bypassWorkspaceRestrictions
= true
;
317 $dataHandler->process_datamap();
319 if ($this->passwordIsUpdated
=== self
::PASSWORD_NOT_UPDATED ||
count($storeRec['be_users'][$beUserId]) > 1) {
320 $this->setupIsUpdated
= true
;
322 // Restore admin status after processing
323 $beUser->user
['admin'] = $isAdmin;
328 /******************************
332 ******************************/
334 * Initializes the module for display of the settings form.
338 public function init()
340 $this->getLanguageService()->includeLLFile('EXT:setup/Resources/Private/Language/locallang.xlf');
342 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
343 $scriptUser = $this->getRealScriptUserObj();
345 $this->isAdmin
= $scriptUser->isAdmin();
346 // Getting the 'override' values as set might be set in User TSconfig
347 $this->overrideConf
= $this->getBackendUser()->getTSConfigProp('setup.override');
348 // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1)
349 $this->tsFieldConf
= $this->getBackendUser()->getTSConfigProp('setup.fields');
350 // id password is disabled, disable repeat of password too (password2)
351 if (isset($this->tsFieldConf
['password.']) && $this->tsFieldConf
['password.']['disabled']) {
352 $this->tsFieldConf
['password2.']['disabled'] = 1;
353 $this->tsFieldConf
['passwordCurrent.']['disabled'] = 1;
355 // Create instance of object for output of data
356 $this->doc
= GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate
::class);
357 $this->moduleTemplate
->setForm(
358 '<form action="' . BackendUtility
::getModuleUrl('user_setup') . '" method="post" name="usersetup" enctype="multipart/form-data">'
363 * Generate necessary JavaScript
367 protected function getJavaScript()
370 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'])) {
371 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'] as $function) {
373 $javaScript .= GeneralUtility
::callUserFunction($function, $params, $this);
380 * Generate the main settings form:
384 public function main()
386 if ($this->languageUpdate
) {
387 $this->moduleTemplate
->addJavaScriptCode('languageUpdate', '
388 if (top.refreshMenu) {
391 top.TYPO3ModuleMenu.refreshMenu();
395 if ($this->pagetreeNeedsRefresh
) {
396 BackendUtility
::setUpdateSignal('updatePageTree');
399 $this->moduleTemplate
->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/md5.js');
401 $this->content
.= '<div id="user-setup-wrapper">';
402 // Load available backend modules
403 $this->loadModules
= GeneralUtility
::makeInstance(ModuleLoader
::class);
404 $this->loadModules
->observeWorkspaces
= true
;
405 $this->loadModules
->load($GLOBALS['TBE_MODULES']);
406 $this->content
.= $this->doc
->header($this->getLanguageService()->getLL('UserSettings'));
407 // Show if setup was saved
408 if ($this->setupIsUpdated
&& !$this->tempDataIsCleared
&& !$this->settingsAreResetToDefault
) {
409 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('setupWasUpdated'), $this->getLanguageService()->getLL('UserSettings'));
410 $this->content
.= $flashMessage->render();
413 // Show if temporary data was cleared
414 if ($this->tempDataIsCleared
) {
415 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('tempDataClearedFlashMessage'), $this->getLanguageService()->getLL('tempDataCleared'));
416 $this->content
.= $flashMessage->render();
419 // Show if temporary data was cleared
420 if ($this->settingsAreResetToDefault
) {
421 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('settingsAreReset'), $this->getLanguageService()->getLL('resetConfiguration'));
422 $this->content
.= $flashMessage->render();
426 if ($this->setupIsUpdated ||
$this->settingsAreResetToDefault
) {
427 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('activateChanges'), '', FlashMessage
::INFO
);
428 $this->content
.= $flashMessage->render();
431 // If password is updated, output whether it failed or was OK.
432 if ($this->passwordIsSubmitted
) {
433 $flashMessage = null
;
434 switch ($this->passwordIsUpdated
) {
435 case self
::PASSWORD_OLD_WRONG
:
436 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('oldPassword_failed'), $this->getLanguageService()->getLL('newPassword'), FlashMessage
::ERROR
);
438 case self
::PASSWORD_NOT_THE_SAME
:
439 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('newPassword_failed'), $this->getLanguageService()->getLL('newPassword'), FlashMessage
::ERROR
);
441 case self
::PASSWORD_UPDATED
:
442 $flashMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $this->getLanguageService()->getLL('newPassword_ok'), $this->getLanguageService()->getLL('newPassword'));
446 $this->content
.= $flashMessage->render();
450 // Render user switch
451 $this->content
.= $this->renderSimulateUserSelectAndLabel();
453 // Render the menu items
454 $menuItems = $this->renderUserSetup();
455 $this->content
.= $this->doc
->getDynamicTabMenu($menuItems, 'user-setup', 1, false
, false
);
456 $formToken = $this->formProtection
->generateToken('BE user setup', 'edit');
457 $this->content
.= $this->doc
->section('', '<input type="hidden" name="simUser" value="' . $this->simUser
. '" />
458 <input type="hidden" name="formToken" value="' . $formToken . '" />
459 <input type="hidden" value="1" name="data[save]" />
460 <input type="hidden" name="data[setValuesToDefault]" value="0" id="setValuesToDefault" />
461 <input type="hidden" name="data[clearSessionVars]" value="0" id="clearSessionVars" />');
462 // End of wrapper div
463 $this->content
.= '</div>';
464 // Setting up the buttons and markers for docheader
466 // Build the <body> for the module
467 // Renders the module page
468 $this->moduleTemplate
->setContent($this->content
);
473 * Injects the request object for the current request or subrequest
474 * Simply calls main() and init() and writes the content to the response
476 * @param ServerRequestInterface $request the current request
477 * @param ResponseInterface $response
478 * @return ResponseInterface the response with the content
480 public function mainAction(ServerRequestInterface
$request, ResponseInterface
$response)
482 $GLOBALS['SOBE'] = $this;
483 $this->simulateUser();
484 $this->storeIncomingData();
488 $response->getBody()->write($this->moduleTemplate
->renderContent());
493 * Prints the content / ends page
496 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
498 public function printContent()
500 GeneralUtility
::logDeprecatedFunction();
505 * Create the panel of buttons for submitting the form or otherwise perform operations.
507 protected function getButtons()
509 $buttonBar = $this->moduleTemplate
->getDocHeaderComponent()->getButtonBar();
510 $cshButton = $buttonBar->makeHelpButton()
511 ->setModuleName('_MOD_user_setup')
513 $buttonBar->addButton($cshButton);
515 $saveButton = $buttonBar->makeInputButton()
516 ->setName('data[save]')
517 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', true
))
519 ->setShowLabelText(true
)
520 ->setIcon($this->moduleTemplate
->getIconFactory()->getIcon('actions-document-save', Icon
::SIZE_SMALL
));
522 $buttonBar->addButton($saveButton);
523 $shortcutButton = $buttonBar->makeShortcutButton()
524 ->setModuleName($this->moduleName
);
525 $buttonBar->addButton($shortcutButton);
528 /******************************
532 ******************************/
535 * renders the data for all tabs in the user setup and returns
536 * everything that is needed with tabs and dyntab menu
538 * @return array Ready to use for the dyntabmenu itemarray
540 protected function renderUserSetup()
546 $fieldArray = $this->getFieldsFromShowItem();
548 foreach ($fieldArray as $fieldName) {
550 if (substr($fieldName, 0, 8) === '--div--;') {
551 if ($firstTabLabel === '') {
553 $tabLabel = $this->getLabel(substr($fieldName, 8), '', false
);
554 $firstTabLabel = $tabLabel;
557 'label' => $tabLabel,
558 'content' => count($code) ?
implode(LF
, $code) : ''
560 $tabLabel = $this->getLabel(substr($fieldName, 8), '', false
);
565 $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
567 // Field my be disabled in setup.fields
568 if (isset($this->tsFieldConf
[$fieldName . '.']['disabled']) && $this->tsFieldConf
[$fieldName . '.']['disabled'] == 1) {
571 if (isset($config['access']) && !$this->checkAccess($config)) {
574 $label = $this->getLabel($config['label'], $fieldName);
575 $label = $this->getCSH($config['csh'] ?
: $fieldName, $label);
576 $type = $config['type'];
577 $class = $config['class'];
579 if ($type !== 'check') {
580 $class .= ' form-control';
583 $style = $config['style'];
585 $more .= ' class="' . $class . '"';
588 $more .= ' style="' . $style . '"';
590 if (isset($this->overrideConf
[$fieldName])) {
591 $more .= ' disabled="disabled"';
593 $value = $config['table'] === 'be_users' ?
$this->getBackendUser()->user
[$fieldName] : $this->getBackendUser()->uc
[$fieldName];
594 if (!$value && isset($config['default'])) {
595 $value = $config['default'];
598 if ($config['table'] === 'be_users') {
599 $dataAdd = '[be_users]';
606 $noAutocomplete = '';
607 if ($type === 'password') {
609 $noAutocomplete = 'autocomplete="off" ';
610 $more .= ' data-rsa-encryption=""';
612 $html = '<input id="field_' . $fieldName . '"
614 name="data' . $dataAdd . '[' . $fieldName . ']" ' .
616 'value="' . htmlspecialchars($value) . '" ' .
621 $html = $label . '<div class="checkbox"><label><input id="field_' . $fieldName . '"
623 name="data' . $dataAdd . '[' . $fieldName . ']"' .
624 ($value ?
' checked="checked"' : '') .
630 if ($config['itemsProcFunc']) {
631 $html = GeneralUtility
::callUserFunction($config['itemsProcFunc'], $config, $this, '');
633 $html = '<select id="field_' . $fieldName . '"
634 name="data' . $dataAdd . '[' . $fieldName . ']"' .
636 foreach ($config['items'] as $key => $optionLabel) {
637 $html .= '<option value="' . $key . '"' . ($value == $key ?
' selected="selected"' : '') . '>' . $this->getLabel($optionLabel, '', false
) . '</option>' . LF
;
639 $html .= '</select>';
643 $html = GeneralUtility
::callUserFunction($config['userFunc'], $config, $this, '');
646 if ($config['onClick']) {
647 $onClick = $config['onClick'];
648 if ($config['onClickLabels']) {
649 foreach ($config['onClickLabels'] as $key => $labelclick) {
650 $config['onClickLabels'][$key] = $this->getLabel($labelclick, '', false
);
652 $onClick = vsprintf($onClick, $config['onClickLabels']);
654 $html = '<br><input class="btn btn-default" type="button"
655 value="' . $this->getLabel($config['buttonlabel'], '', false
) . '"
656 onclick="' . $onClick . '" />';
660 // Get current avatar image
662 $avatarFileUid = $this->getAvatarFileUid($this->getBackendUser()->user
['uid']);
664 if ($avatarFileUid) {
665 $defaultAvatarProvider = GeneralUtility
::makeInstance(DefaultAvatarProvider
::class);
666 $avatarImage = $defaultAvatarProvider->getImage($this->getBackendUser()->user
, 32);
668 $icon = '<span class="avatar"><span class="avatar-image">' .
669 '<img src="' . htmlspecialchars($avatarImage->getUrl(true
)) . '"' .
670 ' width="' . (int)$avatarImage->getWidth() . '" ' .
671 'height="' . (int)$avatarImage->getHeight() . '" />' .
673 $html .= '<span class="pull-left" style="padding-right: 10px" id="image_' . htmlspecialchars($fieldName) . '">' . $icon . ' </span>';
676 $html .= '<input id="field_' . htmlspecialchars($fieldName) . '" type="hidden" ' .
677 'name="data' . $dataAdd . '[' . htmlspecialchars($fieldName) . ']"' . $more .
678 ' value="' . $avatarFileUid . '" />';
680 $html .= '<div class="btn-group">';
681 if ($avatarFileUid) {
682 $html .= '<a id="clear_button_' . htmlspecialchars($fieldName) . '" onclick="clearExistingImage(); return false;" class="btn btn-default"><span class="t3-icon fa t3-icon fa fa-remove"> </span></a>';
684 $html .= '<a id="add_button_' . htmlspecialchars($fieldName) . '" class="btn btn-default btn-add-avatar" onclick="openFileBrowser();return false;"><span class="t3-icon t3-icon-actions t3-icon-actions-insert t3-icon-insert-record"> </span></a>' .
687 $this->addAvatarButtonJs($fieldName);
693 $code[] = '<div class="form-section"><div class="form-group">' .
700 'label' => $tabLabel,
701 'content' => count($code) ?
implode(LF
, $code) : ''
706 /******************************
710 ******************************/
712 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
713 * Anyway: The REAL user is returned - the one logged in.
715 * @return BackendUserAuthentication The REAL user is returned - the one logged in.
717 protected function getRealScriptUserObj()
719 return is_object($this->OLD_BE_USER
) ?
$this->OLD_BE_USER
: $this->getBackendUser();
723 * Return a select with available languages
725 * @param array $params
727 * @return string Complete select as HTML string or warning box if something went wrong.
729 public function renderLanguageSelect($params)
731 $languageOptions = array();
732 // Compile the languages dropdown
733 $langDefault = $this->getLanguageService()->getLL('lang_default', true
);
734 $languageOptions[$langDefault] = '<option value=""' . ($this->getBackendUser()->uc
['lang'] === '' ?
' selected="selected"' : '') . '>' . $langDefault . '</option>';
735 // Traverse the number of languages
736 /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
737 $locales = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Localization\Locales
::class);
738 $languages = $locales->getLanguages();
739 foreach ($languages as $locale => $name) {
740 if ($locale !== 'default') {
741 $defaultName = isset($GLOBALS['LOCAL_LANG']['default']['lang_' . $locale]) ?
$GLOBALS['LOCAL_LANG']['default']['lang_' . $locale][0]['source'] : $name;
742 $localizedName = $this->getLanguageService()->getLL('lang_' . $locale, true
);
743 if ($localizedName === '') {
744 $localizedName = htmlspecialchars($name);
746 $localLabel = ' - [' . htmlspecialchars($defaultName) . ']';
747 $available = is_dir(PATH_typo3conf
. 'l10n/' . $locale);
749 $languageOptions[$defaultName] = '<option value="' . $locale . '"' . ($this->getBackendUser()->uc
['lang'] === $locale ?
' selected="selected"' : '') . '>' . $localizedName . $localLabel . '</option>';
753 ksort($languageOptions);
755 <select id="field_lang" name="data[lang]" class="form-control">' . implode('', $languageOptions) . '
757 if ($this->getBackendUser()->uc
['lang'] && !@is_dir
((PATH_typo3conf
. 'l10n/' . $this->getBackendUser()->uc
['lang']))) {
758 $languageUnavailableWarning = 'The selected language "' . $this->getLanguageService()->getLL(('lang_' . $this->getBackendUser()->uc
['lang']), true
) . '" is not available before the language files are installed.<br />' . ($this->getBackendUser()->isAdmin() ?
'You can use the Language module to easily download new language files.' : 'Please ask your system administrator to do this.');
759 $languageUnavailableMessage = GeneralUtility
::makeInstance(FlashMessage
::class, $languageUnavailableWarning, '', FlashMessage
::WARNING
);
760 $languageCode = $languageUnavailableMessage->render() . $languageCode;
762 return $languageCode;
766 * Returns a select with all modules for startup
768 * @param array $params
769 * @param SetupModuleController $pObj
771 * @return string Complete select as HTML string
773 public function renderStartModuleSelect($params, $pObj)
775 $startModuleSelect = '<option value="">' . $this->getLanguageService()->getLL('startModule.firstInMenu', true
) . '</option>';
776 foreach ($pObj->loadModules
->modules
as $mainMod => $modData) {
777 if (!empty($modData['sub']) && is_array($modData['sub'])) {
779 foreach ($modData['sub'] as $subData) {
780 $modName = $subData['name'];
781 $modules .= '<option value="' . htmlspecialchars($modName) . '"';
782 $modules .= $this->getBackendUser()->uc
['startModule'] === $modName ?
' selected="selected"' : '';
783 $modules .= '>' . $this->getLanguageService()->moduleLabels
['tabs'][$modName . '_tab'] . '</option>';
785 $groupLabel = $this->getLanguageService()->moduleLabels
['tabs'][$mainMod . '_tab'];
786 $startModuleSelect .= '<optgroup label="' . htmlspecialchars($groupLabel) . '">' . $modules . '</optgroup>';
789 return '<select id="field_startModule" name="data[startModule]" class="form-control">' . $startModuleSelect . '</select>';
793 * Will make the simulate-user selector if the logged in user is administrator.
794 * 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)
798 public function simulateUser()
800 // If admin, allow simulation of another user
802 $this->simulateSelector
= '';
803 unset($this->OLD_BE_USER
);
804 if ($this->getBackendUser()->isAdmin()) {
805 $this->simUser
= (int)GeneralUtility
::_GP('simUser');
806 // Make user-selector:
807 $db = $this->getDatabaseConnection();
808 $where = 'AND username NOT LIKE ' . $db->fullQuoteStr($db->escapeStrForLike('_cli_', 'be_users') . '%', 'be_users');
809 $where .= ' AND uid <> ' . (int)$this->getBackendUser()->user
['uid'] . BackendUtility
::BEenableFields('be_users');
810 $users = BackendUtility
::getUserNames('username,usergroup,usergroup_cached_list,uid,realName', $where);
812 foreach ($users as $rr) {
813 $label = htmlspecialchars(($rr['username'] . ($rr['realName'] ?
' (' . $rr['realName'] . ')' : '')));
814 $opt[] = '<option value="' . $rr['uid'] . '"' . ($this->simUser
== $rr['uid'] ?
' selected="selected"' : '') . '>' . $label . '</option>';
817 $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>';
820 // This can only be set if the previous code was executed.
821 if ($this->simUser
> 0) {
823 $this->OLD_BE_USER
= $this->getBackendUser();
824 unset($GLOBALS['BE_USER']);
826 // New backend user object
827 $BE_USER = GeneralUtility
::makeInstance(BackendUserAuthentication
::class);
828 $BE_USER->setBeUserByUid($this->simUser
);
829 $BE_USER->fetchGroupData();
830 $BE_USER->backendSetUC();
831 // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
832 $GLOBALS['BE_USER'] = $BE_USER;
837 * Render simulate user select and label
841 protected function renderSimulateUserSelectAndLabel()
843 if ($this->simulateSelector
=== '') {
848 '<label for="field_simulate" style="margin-right: 20px;">' .
849 $this->getLanguageService()->sL('LLL:EXT:setup/Resources/Private/Language/locallang.xlf:simulate') .
851 $this->simulateSelector
.
856 * Returns access check (currently only "admin" is supported)
858 * @param array $config Configuration of the field, access mode is defined in key 'access'
859 * @return bool Whether it is allowed to modify the given field
861 protected function checkAccess(array $config)
863 $access = $config['access'];
865 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access])) {
866 if (class_exists($access)) {
867 $accessObject = GeneralUtility
::makeInstance($access);
868 if (method_exists($accessObject, 'accessLevelCheck')) {
869 // Initialize vars. If method fails, $set will be set to FALSE
870 return $accessObject->accessLevelCheck($config);
873 } elseif ($access == 'admin') {
874 return $this->isAdmin
;
881 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
883 * @param string $str Locallang key
884 * @param string $key Alternative override-config key
885 * @param bool $addLabelTag Defines whether the string should be wrapped in a <label> tag.
886 * @param string $altLabelTagId Alternative id for use in "for" attribute of <label> tag. By default the $str key is used prepended with "field_".
887 * @return string HTML output.
889 protected function getLabel($str, $key = '', $addLabelTag = true
, $altLabelTagId = '')
891 if (substr($str, 0, 4) === 'LLL:') {
892 $out = $this->getLanguageService()->sL($str);
894 $out = htmlspecialchars($str);
896 if (isset($this->overrideConf
[$key ?
: $str])) {
897 $out = '<span style="color:#999999">' . $out . '</span>';
900 $out = '<label for="' . ($altLabelTagId ?
: 'field_' . $key) . '">' . $out . '</label>';
906 * Returns the CSH Icon for given string
908 * @param string $str Locallang key
909 * @param string $label The label to be used, that should be wrapped in help
910 * @return string HTML output.
912 protected function getCSH($str, $label)
914 $context = '_MOD_user_setup';
916 $strParts = explode(':', $str);
917 if (count($strParts) > 1) {
918 // Setting comes from another extension
919 $context = $strParts[0];
920 $field = $strParts[1];
921 } elseif (!GeneralUtility
::inList('language,simuser,reset', $str)) {
922 $field = 'option_' . $str;
924 return BackendUtility
::wrapInHelp($context, $field, $label);
928 * Returns array with fields defined in $GLOBALS['TYPO3_USER_SETTINGS']['showitem']
930 * @return array Array with fieldnames visible in form
932 protected function getFieldsFromShowItem()
934 return GeneralUtility
::trimExplode(',', $GLOBALS['TYPO3_USER_SETTINGS']['showitem'], true
);
940 * @param int $beUserId
943 protected function getAvatarFileUid($beUserId)
945 $file = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
947 'sys_file_reference',
948 'tablenames = \'be_users\' AND fieldname = \'avatar\' AND ' .
949 'table_local = \'sys_file\' AND uid_foreign = ' . (int)$beUserId .
950 BackendUtility
::BEenableFields('sys_file_reference') . BackendUtility
::deleteClause('sys_file_reference')
952 return $file ?
$file['uid_local'] : 0;
956 * Set avatar fileUid for backend user
958 * @param int $beUserId
959 * @param int $fileUid
960 * @param array $storeRec
962 protected function setAvatarFileUid($beUserId, $fileUid, array &$storeRec)
965 // Update is only needed when new fileUid is set
966 if ((int)$fileUid === $this->getAvatarFileUid($beUserId)) {
970 // Delete old file reference
971 $this->getDatabaseConnection()->exec_DELETEquery(
972 'sys_file_reference',
973 'tablenames = \'be_users\' AND fieldname = \'avatar\' AND ' .
974 'table_local = \'sys_file\' AND uid_foreign = ' . (int)$beUserId
977 // Create new reference
982 $file = ResourceFactory
::getInstance()->getFileObject($fileUid);
983 } catch (FileDoesNotExistException
$e) {
987 // Check if user is allowed to use the image (only when not in simulation mode)
988 if ($file && $this->simUser
=== 0 && !$file->getStorage()->checkFileActionPermission('read', $file)) {
992 // Check if extension is allowed
993 if ($file && GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) {
995 // Create new file reference
996 $storeRec['sys_file_reference']['NEW1234'] = array(
997 'uid_local' => $fileUid,
998 'uid_foreign' => $beUserId,
999 'tablenames' => 'be_users',
1000 'fieldname' => 'avatar',
1002 'table_local' => 'sys_file',
1004 $storeRec['be_users'][(int)$beUserId]['avatar'] = 'NEW1234';
1010 * Add JavaScript to for browse files button
1012 * @param string $fieldName
1014 protected function addAvatarButtonJs($fieldName)
1016 $this->moduleTemplate
->addJavaScriptCode('avatar-button', '
1019 function openFileBrowser() {
1020 var url = ' . GeneralUtility
::quoteJSvalue(BackendUtility
::getModuleUrl('wizard_element_browser', ['mode' => 'file', 'bparams' => '||||dummy|setFileUid'])) . ';
1021 browserWin = window.open(url,"Typo3WinBrowser","height=650,width=800,status=0,menubar=0,resizable=1,scrollbars=1");
1025 function clearExistingImage() {
1026 TYPO3.jQuery(\'#image_' . htmlspecialchars($fieldName) . '\').hide();
1027 TYPO3.jQuery(\'#clear_button_' . htmlspecialchars($fieldName) . '\').hide();
1028 TYPO3.jQuery(\'#field_' . htmlspecialchars($fieldName) . '\').val(\'\');
1031 function setFileUid(field, value, fileUid) {
1032 clearExistingImage();
1033 TYPO3.jQuery(\'#field_' . htmlspecialchars($fieldName) . '\').val(fileUid);
1034 TYPO3.jQuery(\'#add_button_' . htmlspecialchars($fieldName) . '\').removeClass(\'btn-default\').addClass(\'btn-info\');
1042 * Returns the current BE user.
1044 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1046 protected function getBackendUser()
1048 return $GLOBALS['BE_USER'];
1052 * Returns LanguageService
1054 * @return \TYPO3\CMS\Lang\LanguageService
1056 protected function getLanguageService()
1058 return $GLOBALS['LANG'];
1062 * @return DatabaseConnection
1064 protected function getDatabaseConnection()
1066 return $GLOBALS['TYPO3_DB'];