[BUGFIX] EXT: setup — Increase Spacing
[Packages/TYPO3.CMS.git] / typo3 / sysext / setup / Classes / Controller / SetupModuleController.php
1 <?php
2 namespace TYPO3\CMS\Setup\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.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 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Module: User configuration
31 *
32 * This module lets users viev and change their individual settings
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36 /**
37 * Script class for the Setup module
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 */
41 class SetupModuleController {
42
43 // Internal variables:
44 /**
45 * @todo Define visibility
46 */
47 public $MCONF = array();
48
49 /**
50 * @todo Define visibility
51 */
52 public $MOD_MENU = array();
53
54 /**
55 * @todo Define visibility
56 */
57 public $MOD_SETTINGS = array();
58
59 /**
60 * document template object
61 *
62 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
63 * @todo Define visibility
64 */
65 public $doc;
66
67 /**
68 * @todo Define visibility
69 */
70 public $content;
71
72 /**
73 * @todo Define visibility
74 */
75 public $overrideConf;
76
77 /**
78 * backend user object, set during simulate-user operation
79 *
80 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
81 * @todo Define visibility
82 */
83 public $OLD_BE_USER;
84
85 /**
86 * @todo Define visibility
87 */
88 public $languageUpdate;
89
90 protected $pagetreeNeedsRefresh = FALSE;
91
92 protected $isAdmin;
93
94 protected $dividers2tabs;
95
96 protected $tsFieldConf;
97
98 protected $saveData = FALSE;
99
100 protected $passwordIsUpdated = FALSE;
101
102 protected $passwordIsSubmitted = FALSE;
103
104 protected $setupIsUpdated = FALSE;
105
106 protected $tempDataIsCleared = FALSE;
107
108 protected $settingsAreResetToDefault = FALSE;
109
110 /**
111 * Form protection instance
112 *
113 * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection
114 */
115 protected $formProtection;
116
117 /******************************
118 *
119 * Saving data
120 *
121 ******************************/
122 /**
123 * Instanciate the form protection before a simulated user is initialized.
124 */
125 public function __construct() {
126 $this->formProtection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get();
127 }
128
129 /**
130 * Getter for the form protection instance.
131 *
132 * @return \TYPO3\CMS\Core\FormProtection\BackendFormProtection
133 */
134 public function getFormProtection() {
135 return $this->formProtection;
136 }
137
138 /**
139 * If settings are submitted to _POST[DATA], store them
140 * NOTICE: This method is called before the \TYPO3\CMS\Backend\Template\DocumentTemplate
141 * is included. See bottom of document.
142 *
143 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
144 */
145 public function storeIncomingData() {
146 // First check if something is submitted in the data-array from POST vars
147 $d = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('data');
148 $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
149 $beUserId = $GLOBALS['BE_USER']->user['uid'];
150 $storeRec = array();
151 $fieldList = $this->getFieldsFromShowItem();
152 if (is_array($d) && $this->formProtection->validateToken((string) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('formToken'), 'BE user setup', 'edit')) {
153 // UC hashed before applying changes
154 $save_before = md5(serialize($GLOBALS['BE_USER']->uc));
155 // PUT SETTINGS into the ->uc array:
156 // Reload left frame when switching BE language
157 if (isset($d['lang']) && $d['lang'] != $GLOBALS['BE_USER']->uc['lang']) {
158 $this->languageUpdate = TRUE;
159 }
160 // Reload pagetree if the title length is changed
161 if (isset($d['titleLen']) && $d['titleLen'] !== $GLOBALS['BE_USER']->uc['titleLen']) {
162 $this->pagetreeNeedsRefresh = TRUE;
163 }
164 if ($d['setValuesToDefault']) {
165 // If every value should be default
166 $GLOBALS['BE_USER']->resetUC();
167 $this->settingsAreResetToDefault = TRUE;
168 } elseif ($d['clearSessionVars']) {
169 foreach ($GLOBALS['BE_USER']->uc as $key => $value) {
170 if (!isset($columns[$key])) {
171 unset($GLOBALS['BE_USER']->uc[$key]);
172 }
173 }
174 $this->tempDataIsCleared = TRUE;
175 } elseif ($d['save']) {
176 // Save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
177 foreach ($columns as $field => $config) {
178 if (!in_array($field, $fieldList)) {
179 continue;
180 }
181 if ($config['table']) {
182 if ($config['table'] == 'be_users' && !in_array($field, array('password', 'password2', 'email', 'realName', 'admin'))) {
183 if (!isset($config['access']) || $this->checkAccess($config) && $GLOBALS['BE_USER']->user[$field] !== $d['be_users'][$field]) {
184 $storeRec['be_users'][$beUserId][$field] = $d['be_users'][$field];
185 $GLOBALS['BE_USER']->user[$field] = $d['be_users'][$field];
186 }
187 }
188 }
189 if ($config['type'] == 'check') {
190 $GLOBALS['BE_USER']->uc[$field] = isset($d[$field]) ? 1 : 0;
191 } else {
192 $GLOBALS['BE_USER']->uc[$field] = htmlspecialchars($d[$field]);
193 }
194 }
195 // Personal data for the users be_user-record (email, name, password...)
196 // If email and name is changed, set it in the users record:
197 $be_user_data = $d['be_users'];
198 // Possibility to modify the transmitted values. Useful to do transformations, like RSA password decryption
199 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'])) {
200 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'] as $function) {
201 $params = array('be_user_data' => &$be_user_data);
202 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($function, $params, $this);
203 }
204 }
205 $this->passwordIsSubmitted = strlen($be_user_data['password']) > 0;
206 $passwordIsConfirmed = $this->passwordIsSubmitted && $be_user_data['password'] === $be_user_data['password2'];
207 // Update the real name:
208 if ($be_user_data['realName'] !== $GLOBALS['BE_USER']->user['realName']) {
209 $GLOBALS['BE_USER']->user['realName'] = ($storeRec['be_users'][$beUserId]['realName'] = substr($be_user_data['realName'], 0, 80));
210 }
211 // Update the email address:
212 if ($be_user_data['email'] !== $GLOBALS['BE_USER']->user['email']) {
213 $GLOBALS['BE_USER']->user['email'] = ($storeRec['be_users'][$beUserId]['email'] = substr($be_user_data['email'], 0, 80));
214 }
215 // Update the password:
216 if ($passwordIsConfirmed) {
217 $storeRec['be_users'][$beUserId]['password'] = $be_user_data['password2'];
218 $this->passwordIsUpdated = TRUE;
219 }
220 $this->saveData = TRUE;
221 }
222 // Inserts the overriding values.
223 $GLOBALS['BE_USER']->overrideUC();
224 $save_after = md5(serialize($GLOBALS['BE_USER']->uc));
225 // If something in the uc-array of the user has changed, we save the array...
226 if ($save_before != $save_after) {
227 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
228 $GLOBALS['BE_USER']->writelog(254, 1, 0, 1, 'Personal settings changed', array());
229 $this->setupIsUpdated = TRUE;
230 }
231 // If the temporary data has been cleared, lets make a log note about it
232 if ($this->tempDataIsCleared) {
233 $GLOBALS['BE_USER']->writelog(254, 1, 0, 1, $GLOBALS['LANG']->getLL('tempDataClearedLog'), array());
234 }
235 // Persist data if something has changed:
236 if (count($storeRec) && $this->saveData) {
237 // Make instance of TCE for storing the changes.
238 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
239 $tce->stripslashes_values = 0;
240 $tce->start($storeRec, array(), $GLOBALS['BE_USER']);
241 // This is so the user can actually update his user record.
242 $tce->admin = 1;
243 // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
244 $tce->bypassWorkspaceRestrictions = TRUE;
245 $tce->process_datamap();
246 unset($tce);
247 if (!$this->passwordIsUpdated || count($storeRec['be_users'][$beUserId]) > 1) {
248 $this->setupIsUpdated = TRUE;
249 }
250 }
251 }
252 }
253
254 /******************************
255 *
256 * Rendering module
257 *
258 ******************************/
259 /**
260 * Initializes the module for display of the settings form.
261 *
262 * @return void
263 * @todo Define visibility
264 */
265 public function init() {
266 $this->MCONF = $GLOBALS['MCONF'];
267 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
268 $scriptUser = $this->getRealScriptUserObj();
269 // ... and checking module access for the logged in user.
270 $scriptUser->modAccess($this->MCONF, 1);
271 $this->isAdmin = $scriptUser->isAdmin();
272 // Getting the 'override' values as set might be set in User TSconfig
273 $this->overrideConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.override');
274 // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1)
275 $this->tsFieldConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.fields');
276 // id password is disabled, disable repeat of password too (password2)
277 if (isset($this->tsFieldConf['password.']) && $this->tsFieldConf['password.']['disabled']) {
278 $this->tsFieldConf['password2.']['disabled'] = 1;
279 }
280 // Create instance of object for output of data
281 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
282 $this->doc->backPath = $GLOBALS['BACK_PATH'];
283 $this->doc->setModuleTemplate('EXT:setup/Resources/Private/Templates/setup.html');
284 $this->doc->form = '<form action="' . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('user_setup') . '" method="post" name="usersetup" enctype="application/x-www-form-urlencoded">';
285 $this->doc->tableLayout = array(
286 'defRow' => array(
287 '0' => array('<td class="td-label">', '</td>'),
288 'defCol' => array('<td valign="top">', '</td>')
289 )
290 );
291 $this->doc->table_TR = '<tr>';
292 $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2" class="typo3-usersettings">';
293 $this->doc->JScode .= $this->getJavaScript();
294 }
295
296 /**
297 * Generate necessary JavaScript
298 *
299 * @return string
300 */
301 protected function getJavaScript() {
302 $javaScript = '';
303 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'])) {
304 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'] as $function) {
305 $params = array();
306 $javaScript .= \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($function, $params, $this);
307 }
308 }
309 return $javaScript;
310 }
311
312 /**
313 * Generate the main settings formular:
314 *
315 * @return void
316 * @todo Define visibility
317 */
318 public function main() {
319 global $LANG;
320 if ($this->languageUpdate) {
321 $this->doc->JScodeArray['languageUpdate'] .= '
322 if (top.refreshMenu) {
323 top.refreshMenu();
324 } else {
325 top.TYPO3ModuleMenu.refreshMenu();
326 }
327 ';
328 }
329 if ($this->pagetreeNeedsRefresh) {
330 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
331 }
332 // Start page:
333 $this->doc->loadJavascriptLib('md5.js');
334 // Use a wrapper div
335 $this->content .= '<div id="user-setup-wrapper">';
336 // Load available backend modules
337 $this->loadModules = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
338 $this->loadModules->observeWorkspaces = TRUE;
339 $this->loadModules->load($GLOBALS['TBE_MODULES']);
340 $this->content .= $this->doc->header($LANG->getLL('UserSettings'));
341 // Show if setup was saved
342 if ($this->setupIsUpdated && !$this->tempDataIsCleared && !$this->settingsAreResetToDefault) {
343 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('setupWasUpdated'), $LANG->getLL('UserSettings'));
344 $this->content .= $flashMessage->render();
345 }
346 // Show if temporary data was cleared
347 if ($this->tempDataIsCleared) {
348 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('tempDataClearedFlashMessage'), $LANG->getLL('tempDataCleared'));
349 $this->content .= $flashMessage->render();
350 }
351 // Show if temporary data was cleared
352 if ($this->settingsAreResetToDefault) {
353 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('settingsAreReset'), $LANG->getLL('resetConfiguration'));
354 $this->content .= $flashMessage->render();
355 }
356 // Notice
357 if ($this->setupIsUpdated || $this->settingsAreResetToDefault) {
358 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('activateChanges'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
359 $this->content .= $flashMessage->render();
360 }
361 // If password is updated, output whether it failed or was OK.
362 if ($this->passwordIsSubmitted) {
363 if ($this->passwordIsUpdated) {
364 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('newPassword_ok'), $LANG->getLL('newPassword'));
365 } else {
366 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $LANG->getLL('newPassword_failed'), $LANG->getLL('newPassword'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
367 }
368 $this->content .= $flashMessage->render();
369 }
370 // Render the menu items
371 $menuItems = $this->renderUserSetup();
372 $this->content .= $this->doc->getDynTabMenu($menuItems, 'user-setup', FALSE, FALSE, 1, FALSE, 1, $this->dividers2tabs);
373 $formToken = $this->formProtection->generateToken('BE user setup', 'edit');
374 $this->content .= $this->doc->section('', '<input type="hidden" name="simUser" value="' . $this->simUser . '" />
375 <input type="hidden" name="formToken" value="' . $formToken . '" />
376 <input type="hidden" value="1" name="data[save]" />
377 <input type="hidden" name="data[setValuesToDefault]" value="0" id="setValuesToDefault" />
378 <input type="hidden" name="data[clearSessionVars]" value="0" id="clearSessionVars" />');
379 // End of wrapper div
380 $this->content .= '</div>';
381 // Setting up the buttons and markers for docheader
382 $docHeaderButtons = $this->getButtons();
383 $markers['CSH'] = $docHeaderButtons['csh'];
384 $markers['CONTENT'] = $this->content;
385 // Build the <body> for the module
386 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
387 // Renders the module page
388 $this->content = $this->doc->render($LANG->getLL('UserSettings'), $this->content);
389 }
390
391 /**
392 * Prints the content / ends page
393 *
394 * @return void
395 * @todo Define visibility
396 */
397 public function printContent() {
398 echo $this->content;
399 }
400
401 /**
402 * Create the panel of buttons for submitting the form or otherwise perform operations.
403 *
404 * @return array All available buttons as an assoc. array
405 */
406 protected function getButtons() {
407 $buttons = array(
408 'csh' => '',
409 'save' => '',
410 'shortcut' => ''
411 );
412 $buttons['csh'] = \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'], '|', TRUE);
413 $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', 1) . '" />'));
414 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
415 $buttons['shortcut'] = $this->doc->makeShortcutIcon('', '', $this->MCONF['name']);
416 }
417 return $buttons;
418 }
419
420 /******************************
421 *
422 * Render module
423 *
424 ******************************/
425 /**
426 * renders the data for all tabs in the user setup and returns
427 * everything that is needed with tabs and dyntab menu
428 *
429 * @return array Ready to use for the dyntabmenu itemarray
430 */
431 protected function renderUserSetup() {
432 $result = array();
433 $firstTabLabel = '';
434 $code = array();
435 $i = 0;
436 $fieldArray = $this->getFieldsFromShowItem();
437 $this->dividers2tabs = isset($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) ? intval($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) : 0;
438 $tabLabel = '';
439 foreach ($fieldArray as $fieldName) {
440 $more = '';
441 if (substr($fieldName, 0, 8) == '--div--;') {
442 if ($firstTabLabel == '') {
443 // First tab
444 $tabLabel = $this->getLabel(substr($fieldName, 8), '', FALSE);
445 $firstTabLabel = $tabLabel;
446 } else {
447 if ($this->dividers2tabs) {
448 $result[] = array(
449 'label' => $tabLabel,
450 'content' => count($code) ? $this->doc->table($code) : ''
451 );
452 $tabLabel = $this->getLabel(substr($fieldName, 8), '', FALSE);
453 $i = 0;
454 $code = array();
455 }
456 }
457 continue;
458 }
459 $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
460 // Field my be disabled in setup.fields
461 if (isset($this->tsFieldConf[$fieldName . '.']['disabled']) && $this->tsFieldConf[$fieldName . '.']['disabled'] == 1) {
462 continue;
463 }
464 if (isset($config['access']) && !$this->checkAccess($config)) {
465 continue;
466 }
467 $label = $this->getLabel($config['label'], $fieldName);
468 $label = $this->getCSH($config['csh'] ? $config['csh'] : $fieldName, $label);
469 $type = $config['type'];
470 $eval = $config['eval'];
471 $class = $config['class'];
472 $style = $config['style'];
473 if ($class) {
474 $more .= ' class="' . $class . '"';
475 }
476 if ($style) {
477 $more .= ' style="' . $style . '"';
478 }
479 if ($this->overrideConf[$fieldName]) {
480 $more .= ' disabled="disabled"';
481 }
482 $value = $config['table'] == 'be_users' ? $GLOBALS['BE_USER']->user[$fieldName] : $GLOBALS['BE_USER']->uc[$fieldName];
483 if (!$value && isset($config['default'])) {
484 $value = $config['default'];
485 }
486 switch ($type) {
487 case 'text':
488
489 case 'password':
490 $dataAdd = '';
491 if ($config['table'] == 'be_users') {
492 $dataAdd = '[be_users]';
493 }
494 if ($eval == 'md5') {
495 $more .= ' onchange="this.value=this.value?MD5(this.value):\'\';"';
496 }
497 if ($type == 'password') {
498 $value = '';
499 }
500 $noAutocomplete = $type == 'password' ? 'autocomplete="off" ' : '';
501 $html = '<input id="field_' . $fieldName . '"
502 type="' . $type . '"
503 name="data' . $dataAdd . '[' . $fieldName . ']" ' . $noAutocomplete . 'value="' . htmlspecialchars($value) . '" ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . $more . ' />';
504 break;
505 case 'check':
506 if (!$class) {
507 $more .= ' class="check"';
508 }
509 $html = '<input id="field_' . $fieldName . '"
510 type="checkbox"
511 name="data[' . $fieldName . ']"' . ($value ? ' checked="checked"' : '') . $more . ' />';
512 break;
513 case 'select':
514 if (!$class) {
515 $more .= ' class="select"';
516 }
517 if ($config['itemsProcFunc']) {
518 $html = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($config['itemsProcFunc'], $config, $this, '');
519 } else {
520 $html = '<select ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' id="field_' . $fieldName . '" name="data[' . $fieldName . ']"' . $more . '>' . LF;
521 foreach ($config['items'] as $key => $optionLabel) {
522 $html .= '<option value="' . $key . '"' . ($value == $key ? ' selected="selected"' : '') . '>' . $this->getLabel($optionLabel, '', FALSE) . '</option>' . LF;
523 }
524 $html .= '</select>';
525 }
526 break;
527 case 'user':
528 $html = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($config['userFunc'], $config, $this, '');
529 break;
530 case 'button':
531 if ($config['onClick']) {
532 $onClick = $config['onClick'];
533 if ($config['onClickLabels']) {
534 foreach ($config['onClickLabels'] as $key => $labelclick) {
535 $config['onClickLabels'][$key] = $this->getLabel($labelclick, '', FALSE);
536 }
537 $onClick = vsprintf($onClick, $config['onClickLabels']);
538 }
539 $html = '<input ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' type="button" value="' . $this->getLabel($config['buttonlabel'], '', FALSE) . '" onclick="' . $onClick . '" />';
540 }
541 break;
542 default:
543 $html = '';
544 }
545 $code[$i][1] = $label;
546 $code[$i++][2] = $html;
547 }
548 if ($this->dividers2tabs == 0) {
549 $tabLabel = $firstTabLabel;
550 }
551 $result[] = array(
552 'label' => $tabLabel,
553 'content' => count($code) ? $this->doc->table($code) : ''
554 );
555 return $result;
556 }
557
558 /******************************
559 *
560 * Helper functions
561 *
562 ******************************/
563 /**
564 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
565 * Anyway: The REAL user is returned - the one logged in.
566 *
567 * @return object The REAL user is returned - the one logged in.
568 */
569 protected function getRealScriptUserObj() {
570 return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
571 }
572
573 /**
574 * Return a select with available languages
575 *
576 * @return string Complete select as HTML string or warning box if something went wrong.
577 */
578 public function renderLanguageSelect($params, $pObj) {
579 $languageOptions = array();
580 // Compile the languages dropdown
581 $langDefault = $GLOBALS['LANG']->getLL('lang_default', 1);
582 $languageOptions[$langDefault] = '<option value=""' . ($GLOBALS['BE_USER']->uc['lang'] === '' ? ' selected="selected"' : '') . '>' . $langDefault . '</option>';
583 // Traverse the number of languages
584 /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
585 $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Locales');
586 $languages = $locales->getLanguages();
587 foreach ($languages as $locale => $name) {
588 if ($locale !== 'default') {
589 $defaultName = isset($GLOBALS['LOCAL_LANG']['default']['lang_' . $locale]) ? $GLOBALS['LOCAL_LANG']['default']['lang_' . $locale][0]['source'] : $name;
590 $localizedName = $GLOBALS['LANG']->getLL('lang_' . $locale, TRUE);
591 if ($localizedName === '') {
592 $localizedName = htmlspecialchars($name);
593 }
594 $localLabel = ' - [' . htmlspecialchars($defaultName) . ']';
595 $available = is_dir(PATH_typo3conf . 'l10n/' . $locale) ? TRUE : FALSE;
596 if ($available) {
597 $languageOptions[$defaultName] = '<option value="' . $locale . '"' . ($GLOBALS['BE_USER']->uc['lang'] === $locale ? ' selected="selected"' : '') . '>' . $localizedName . $localLabel . '</option>';
598 }
599 }
600 }
601 ksort($languageOptions);
602 $languageCode = '
603 <select ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' id="field_lang" name="data[lang]" class="select">' . implode('', $languageOptions) . '
604 </select>';
605 if ($GLOBALS['BE_USER']->uc['lang'] && !@is_dir((PATH_typo3conf . 'l10n/' . $GLOBALS['BE_USER']->uc['lang']))) {
606 $languageUnavailableWarning = 'The selected language "' . $GLOBALS['LANG']->getLL(('lang_' . $GLOBALS['BE_USER']->uc['lang']), 1) . '" 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.');
607 $languageUnavailableMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $languageUnavailableWarning, '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
608 $languageCode = $languageUnavailableMessage->render() . $languageCode;
609 }
610 return $languageCode;
611 }
612
613 /**
614 * Returns a select with all modules for startup
615 *
616 * @return string Complete select as HTML string
617 */
618 public function renderStartModuleSelect($params, $pObj) {
619 // Start module select
620 if (empty($GLOBALS['BE_USER']->uc['startModule'])) {
621 $GLOBALS['BE_USER']->uc['startModule'] = $GLOBALS['BE_USER']->uc_default['startModule'];
622 }
623 $startModuleSelect = '<option value=""></option>';
624 foreach ($pObj->loadModules->modules as $mainMod => $modData) {
625 if (isset($modData['sub']) && is_array($modData['sub'])) {
626 $startModuleSelect .= '<option disabled="disabled">' . $GLOBALS['LANG']->moduleLabels['tabs'][($mainMod . '_tab')] . '</option>';
627 foreach ($modData['sub'] as $subKey => $subData) {
628 $modName = $subData['name'];
629 $startModuleSelect .= '<option value="' . $modName . '"' . ($GLOBALS['BE_USER']->uc['startModule'] == $modName ? ' selected="selected"' : '') . '>';
630 $startModuleSelect .= ' - ' . $GLOBALS['LANG']->moduleLabels['tabs'][($modName . '_tab')] . '</option>';
631 }
632 }
633 }
634 return '<select ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . 'id="field_startModule" name="data[startModule]" class="select">' . $startModuleSelect . '</select>';
635 }
636
637 /**
638 * Will make the simulate-user selector if the logged in user is administrator.
639 * 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)
640 *
641 * @return void
642 */
643 public function simulateUser() {
644 // If admin, allow simulation of another user
645 $this->simUser = 0;
646 $this->simulateSelector = '';
647 unset($this->OLD_BE_USER);
648 if ($GLOBALS['BE_USER']->isAdmin()) {
649 $this->simUser = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('simUser'));
650 // Make user-selector:
651 $users = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames('username,usergroup,usergroup_cached_list,uid,realName', \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('be_users'));
652 $opt = array();
653 foreach ($users as $rr) {
654 if ($rr['uid'] != $GLOBALS['BE_USER']->user['uid']) {
655 $opt[] = '<option value="' . $rr['uid'] . '"' . ($this->simUser == $rr['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars(($rr['username'] . ' (' . $rr['realName'] . ')')) . '</option>';
656 }
657 }
658 if (count($opt)) {
659 $this->simulateSelector = '<select ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' id="field_simulate" name="simulateUser" onchange="window.location.href=\'' . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('user_setup') . '&simUser=\'+this.options[this.selectedIndex].value;"><option></option>' . implode('', $opt) . '</select>';
660 }
661 }
662 // This can only be set if the previous code was executed.
663 if ($this->simUser > 0) {
664 // Save old user...
665 $this->OLD_BE_USER = $GLOBALS['BE_USER'];
666 unset($GLOBALS['BE_USER']);
667 // Unset current
668 // New backend user object
669 $BE_USER = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
670 $BE_USER->OS = TYPO3_OS;
671 $BE_USER->setBeUserByUid($this->simUser);
672 $BE_USER->fetchGroupData();
673 $BE_USER->backendSetUC();
674 // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
675 $GLOBALS['BE_USER'] = $BE_USER;
676 }
677 }
678
679 /**
680 * Returns a select with simulate users
681 *
682 * @return string Complete select as HTML string
683 */
684 public function renderSimulateUserSelect($params, $pObj) {
685 return $pObj->simulateSelector;
686 }
687
688 /**
689 * Returns access check (currently only "admin" is supported)
690 *
691 * @param array $config Configuration of the field, access mode is defined in key 'access'
692 * @return boolean Whether it is allowed to modify the given field
693 */
694 protected function checkAccess(array $config) {
695 $access = $config['access'];
696 // Check for hook
697 $accessObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access] . ':&' . $access);
698 if (is_object($accessObject) && method_exists($accessObject, 'accessLevelCheck')) {
699 // Initialize vars. If method fails, $set will be set to FALSE
700 return $accessObject->accessLevelCheck($config);
701 } elseif ($access == 'admin') {
702 return $this->isAdmin;
703 }
704 }
705
706 /**
707 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
708 *
709 * @param string $str Locallang key
710 * @param string $key Alternative override-config key
711 * @param boolean $addLabelTag Defines whether the string should be wrapped in a <label> tag.
712 * @param string $altLabelTagId Alternative id for use in "for" attribute of <label> tag. By default the $str key is used prepended with "field_".
713 * @return string HTML output.
714 */
715 protected function getLabel($str, $key = '', $addLabelTag = TRUE, $altLabelTagId = '') {
716 if (substr($str, 0, 4) == 'LLL:') {
717 $out = $GLOBALS['LANG']->sL($str);
718 } else {
719 $out = htmlspecialchars($str);
720 }
721 if (isset($this->overrideConf[$key ? $key : $str])) {
722 $out = '<span style="color:#999999">' . $out . '</span>';
723 }
724 if ($addLabelTag) {
725 $out = '<label for="' . ($altLabelTagId ? $altLabelTagId : 'field_' . $key) . '">' . $out . '</label>';
726 }
727 return $out;
728 }
729
730 /**
731 * Returns the CSH Icon for given string
732 *
733 * @param string $str Locallang key
734 * @param string $label The label to be used, that should be wrapped in help
735 * @return string HTML output.
736 */
737 protected function getCSH($str, $label) {
738 $context = '_MOD_user_setup';
739 $field = $str;
740 $strParts = explode(':', $str);
741 if (count($strParts) > 1) {
742 // Setting comes from another extension
743 $context = $strParts[0];
744 $field = $strParts[1];
745 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList('language,simuser,reset', $str)) {
746 $field = 'option_' . $str;
747 }
748 return \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp($context, $field, $label);
749 }
750
751 /**
752 * Returns array with fields defined in $GLOBALS['TYPO3_USER_SETTINGS']['showitem']
753 *
754 * @return array Array with fieldnames visible in form
755 */
756 protected function getFieldsFromShowItem() {
757 $fieldList = $GLOBALS['TYPO3_USER_SETTINGS']['showitem'];
758 // Disable fields depended on settings
759 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
760 $fieldList = \TYPO3\CMS\Core\Utility\GeneralUtility::rmFromList('edit_RTE', $fieldList);
761 }
762 $fieldArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldList, TRUE);
763 return $fieldArray;
764 }
765
766 }
767
768
769 ?>