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