Fixed bug #11896: User Setup miss save of be_users fields and miss handling of defaul...
[Packages/TYPO3.CMS.git] / typo3 / sysext / setup / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (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 Skaarhoj <kasperYYYY@typo3.com>
33 * Revised for TYPO3 3.7 6/2004 by Kasper Skaarhoj
34 * XHTML compatible.
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 86: class SC_mod_user_setup_index
42 *
43 * SECTION: Saving data
44 * 114: function storeIncomingData()
45 *
46 * SECTION: Rendering module
47 * 216: function init()
48 * 248: function main()
49 * 403: function printContent()
50 *
51 * SECTION: Helper functions
52 * 432: function getRealScriptUserObj()
53 * 442: function simulateUser()
54 * 488: function setLabel($str,$key='')
55 *
56 * TOTAL FUNCTIONS: 7
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61 unset($MCONF);
62 require('conf.php');
63 require($BACK_PATH.'init.php');
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 /**
79 * Script class for the Setup module
80 *
81 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
82 * @package TYPO3
83 * @subpackage tx_setup
84 */
85 class SC_mod_user_setup_index {
86
87 // Internal variables:
88 var $MCONF = array();
89 var $MOD_MENU = array();
90 var $MOD_SETTINGS = array();
91
92 /**
93 * document template object
94 *
95 * @var mediumDoc
96 */
97 var $doc;
98
99 var $content;
100 var $overrideConf;
101
102 /**
103 * backend user object, set during simulate-user operation
104 *
105 * @var t3lib_beUserAuth
106 */
107 var $OLD_BE_USER;
108 var $languageUpdate;
109
110 protected $isAdmin;
111 protected $dividers2tabs;
112
113 protected $tsFieldConf;
114
115
116
117 /******************************
118 *
119 * Saving data
120 *
121 ******************************/
122
123 /**
124 * If settings are submitted to _POST[DATA], store them
125 * NOTICE: This method is called before the template.php is included. See buttom of document
126 *
127 * @return void
128 */
129 function storeIncomingData() {
130 global $BE_USER;
131
132 // First check if something is submittet in the data-array from POST vars
133 $d = t3lib_div::_POST('data');
134 $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
135 $storeRec = array();
136
137 if (is_array($d)) {
138
139 // UC hashed before applying changes
140 $save_before = md5(serialize($BE_USER->uc));
141
142 // PUT SETTINGS into the ->uc array:
143
144 // reload left frame when switching BE language
145 if (isset($d['lang']) && ($d['lang'] != $BE_USER->uc['lang'])) {
146 $this->languageUpdate = true;
147 }
148
149 if ($d['setValuesToDefault']) {
150 // If every value should be default
151 $BE_USER->resetUC();
152 } elseif ($d['clearSessionVars']) {
153 foreach ($BE_USER->uc as $key => $value) {
154 if (!isset($columns[$key])) {
155 unset ($BE_USER->uc[$key]);
156 }
157 }
158 } else {
159 // save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
160 foreach($columns as $field => $config) {
161 if ($config['table']) {
162 if ($config['table'] == 'be_users' && !in_array($field, array('password', 'password2', 'email', 'realName', 'admin'))) {
163 if (!isset($config['access']) || $this->checkAccess($config)) {
164 $storeRec['be_users'][$BE_USER->user['uid']][$field] = $d['be_users'][$field];
165 $BE_USER->user[$field] = $d['be_users'][$field];
166 }
167 }
168 }
169 if ($config['type'] == 'check') {
170 $BE_USER->uc[$field] = isset($d[$field]) ? 1 : 0;
171 } else {
172 $BE_USER->uc[$field] = htmlspecialchars($d[$field]);
173 }
174 }
175 }
176 $BE_USER->overrideUC(); // Inserts the overriding values.
177
178 $save_after = md5(serialize($BE_USER->uc));
179 if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
180 $BE_USER->writeUC($BE_USER->uc);
181 $BE_USER->writelog(254,1,0,1,'Personal settings changed',Array());
182 }
183
184
185 // Personal data for the users be_user-record (email, name, password...)
186 // If email and name is changed, set it in the users record:
187 $be_user_data = $d['be_users'];
188 $this->PASSWORD_UPDATED = strlen($be_user_data['password'].$be_user_data['password2'])>0 ? -1 : 0;
189 if ($be_user_data['email']!=$BE_USER->user['email']
190 || $be_user_data['realName']!=$BE_USER->user['realName']
191 || ( (strlen($be_user_data['password'])==32 || (isset($columns['password']['eval']) && substr($columns['password']['eval'], 0, 3) == 'tx_'))
192 && !strcmp($be_user_data['password'],$be_user_data['password2']))
193 ) {
194
195 $BE_USER->user['realName'] = $storeRec['be_users'][$BE_USER->user['uid']]['realName'] = substr($be_user_data['realName'],0,80);
196 $BE_USER->user['email'] = $storeRec['be_users'][$BE_USER->user['uid']]['email'] = substr($be_user_data['email'],0,80);
197
198 if (isset($columns['password']['eval']) && substr($columns['password']['eval'], 0, 3) == 'tx_') {
199 // password encryption by external script (e.g. EXT:saltedpasswords)
200 $func = $columns['password']['eval'];
201 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
202 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
203 // initialize vars. If method fails, $set will be set to false
204 $is_in = '';
205 $set = TRUE;
206 $newPassword = $evalObj->evaluateFieldValue($be_user_data['password2'], $is_in, $set);
207 if ($set === TRUE) {
208 // password was changed
209 $storeRec['be_users'][$BE_USER->user['uid']]['password'] = $newPassword;
210 $this->PASSWORD_UPDATED = 1;
211 }
212 }
213 } else {
214 if (strlen($be_user_data['password'])==32 && !strcmp($be_user_data['password'],$be_user_data['password2'])) {
215 $storeRec['be_users'][$BE_USER->user['uid']]['password'] = $be_user_data['password2'];
216 $this->PASSWORD_UPDATED = 1;
217 }
218 }
219 }
220 if (count($storeRec)) {
221 // Make instance of TCE for storing the changes.
222 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
223 $tce->stripslashes_values=0;
224 $tce->start($storeRec,Array(),$BE_USER);
225 $tce->admin = 1; // This is so the user can actually update his user record.
226 $tce->bypassWorkspaceRestrictions = TRUE; // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
227 $tce->process_datamap();
228 unset($tce);
229 }
230 }
231 }
232
233
234
235
236
237
238
239
240
241
242
243
244 /******************************
245 *
246 * Rendering module
247 *
248 ******************************/
249
250 /**
251 * Initializes the module for display of the settings form.
252 *
253 * @return void
254 */
255 function init() {
256 $this->MCONF = $GLOBALS['MCONF'];
257
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
271 // Create instance of object for output of data
272 $this->doc = t3lib_div::makeInstance('template');
273 $this->doc->backPath = $GLOBALS['BACK_PATH'];
274 $this->doc->setModuleTemplate('templates/setup.html');
275 $this->doc->JScodeLibArray['dyntabmenu'] = $this->doc->getDynTabMenuJScode();
276 $this->doc->form = '<form action="index.php" method="post" name="usersetup" enctype="application/x-www-form-urlencoded">';
277 $this->doc->tableLayout = array(
278 'defRow' => array(
279 '0' => array('<td class="td-label">','</td>'),
280 'defCol' => array('<td valign="top">','</td>')
281 )
282 );
283 $this->doc->table_TR = '<tr>';
284 $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2" class="typo3-usersettings">';
285 }
286
287 /**
288 * Generate the main settings formular:
289 *
290 * @return void
291 */
292 function main() {
293 global $BE_USER,$LANG,$BACK_PATH,$TBE_MODULES;
294
295 // file creation / delete
296 if ($this->isAdmin) {
297 if (t3lib_div::_POST('deleteInstallToolEnableFile')) {
298 unlink(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
299 }
300 if (t3lib_div::_POST('createInstallToolEnableFile')) {
301 touch(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
302 }
303 }
304
305 if ($this->languageUpdate) {
306 $this->doc->JScodeArray['languageUpdate'] .= '
307 if (top.refreshMenu) {
308 top.refreshMenu();
309 } else {
310 top.TYPO3ModuleMenu.refreshMenu();
311 }
312
313 if (top.shortcutFrame) {
314 top.shortcutFrame.refreshShortcuts();
315 }
316 ';
317 }
318
319 // Start page:
320 $this->doc->loadJavascriptLib('md5.js');
321
322 // use a wrapper div
323 $this->content .= '<div id="user-setup-wrapper">';
324
325 // Load available backend modules
326 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
327 $this->loadModules->observeWorkspaces = true;
328 $this->loadModules->load($TBE_MODULES);
329
330 $this->content .= $this->doc->header($LANG->getLL('UserSettings').' - '.$BE_USER->user['realName'].' ['.$BE_USER->user['username'].']');
331
332 // If password is updated, output whether it failed or was OK.
333 if ($this->PASSWORD_UPDATED) {
334 if ($this->PASSWORD_UPDATED > 0) {
335 $this->content .= $this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_ok'),1,0,1);
336 } else {
337 $this->content .= $this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_failed'),1,0,2);
338 }
339 }
340
341 // render the menu items
342 $menuItems = $this->renderUserSetup();
343
344 $this->content .= $this->doc->spacer(20) . $this->doc->getDynTabMenu($menuItems, 'user-setup', false, false, 100, 1, false, 1, $this->dividers2tabs);
345
346
347 // Submit and reset buttons
348 $this->content .= $this->doc->spacer(20);
349 $this->content .= $this->doc->section('',
350 t3lib_BEfunc::cshItem('_MOD_user_setup', 'reset', $BACK_PATH) . '
351 <input type="hidden" name="simUser" value="'.$this->simUser.'" />
352 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
353 <input type="submit" name="data[setValuesToDefault]" value="'.$LANG->getLL('resetConfiguration').'" onclick="return confirm(\''.$LANG->getLL('setToStandardQuestion').'\');" />
354 <input type="submit" name="data[clearSessionVars]" value="'.$LANG->getLL('clearSessionVars').'" />'
355 );
356
357 // Install Tool access file
358 if ($this->isAdmin) {
359 $installToolEnableFileExists = is_file(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
360 $installToolEnableButton = $installToolEnableFileExists ?
361 '<input type="submit" name="deleteInstallToolEnableFile" value="' . $LANG->getLL('enableInstallTool.deleteFile') . '" />' :
362 '<input type="submit" name="createInstallToolEnableFile" value="' . $LANG->getLL('enableInstallTool.createFile') . '" />';
363
364 $this->content .= $this->doc->spacer(30);
365 $this->content .= $this->doc->section($LANG->getLL('enableInstallTool.headerTitle'),
366 $LANG->getLL('enableInstallTool.description')
367 );
368 $this->content .= $this->doc->spacer(10);
369 $this->content .= $this->doc->section('',
370 $installToolEnableButton
371 );
372 }
373
374 // Notice
375 $this->content .= $this->doc->spacer(30);
376 $this->content .= $this->doc->section('', $LANG->getLL('activateChanges'));
377
378 // Setting up the buttons and markers for docheader
379 $docHeaderButtons = $this->getButtons();
380 $markers['CSH'] = $docHeaderButtons['csh'];
381 $markers['CONTENT'] = $this->content;
382
383 // Build the <body> for the module
384 $this->content = $this->doc->startPage($LANG->getLL('UserSettings'));
385 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
386 // end of wrapper div
387 $this->content .= '</div>';
388 $this->content.= $this->doc->endPage();
389 $this->content = $this->doc->insertStylesAndJS($this->content);
390
391 }
392
393 /**
394 * Prints the content / ends page
395 *
396 * @return void
397 */
398 function printContent() {
399 echo $this->content;
400 }
401
402 /**
403 * Create the panel of buttons for submitting the form or otherwise perform operations.
404 *
405 * @return array all available buttons as an assoc. array
406 */
407 protected function getButtons() {
408 $buttons = array(
409 'csh' => '',
410 'save' => '',
411 'shortcut' => '',
412 );
413
414 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'], '|', true);
415
416 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
417 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','',$this->MCONF['name']);
418 }
419
420 return $buttons;
421 }
422
423
424
425
426 /******************************
427 *
428 * Render module
429 *
430 ******************************/
431
432
433 /**
434 * renders the data for all tabs in the user setup and returns
435 * everything that is needed with tabs and dyntab menu
436 *
437 * @return ready to use for the dyntabmenu itemarray
438 */
439 protected function renderUserSetup() {
440 $result = array();
441 $firstTabLabel = '';
442 $code = array();
443 $i = 0;
444
445 $fieldList = $GLOBALS['TYPO3_USER_SETTINGS']['showitem'];
446
447 // disable fields depended on settings
448 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
449 $fieldList = t3lib_div::rmFromList('edit_RTE', $fieldList);
450 }
451
452 if ($GLOBALS['BE_USER']->uc['interfaceSetup'] != 'backend_old') {
453 $fieldList = t3lib_div::rmFromList('noMenuMode', $fieldList);
454 }
455
456 $fieldArray = t3lib_div::trimExplode(',', $fieldList, true);
457 $this->dividers2tabs = isset($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) ? intval($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) : 0;
458
459
460 // "display full help" is active?
461 $displayFullText = ($GLOBALS['BE_USER']->uc['edit_showFieldHelp'] == 'text');
462 if ($displayFullText) {
463 $this->doc->tableLayout['defRowEven'] = array('defCol' => array ('<td valign="top" colspan="3">','</td>'));
464 }
465
466 foreach ($fieldArray as $fieldName) {
467 $more = '';
468
469 if (substr($fieldName, 0, 8) == '--div--;') {
470 if ($firstTabLabel == '') {
471 // first tab
472 $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
473 $firstTabLabel = $tabLabel;
474 } else {
475 if ($this->dividers2tabs) {
476 $result[] = array(
477 'label' => $tabLabel,
478 'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
479 );
480 $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
481 $i = 0;
482 $code = array();
483 }
484 }
485 continue;
486 }
487
488 $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
489
490 // field my be disabled in setup.fields
491 if (isset($this->tsFieldConf[$fieldName . '.']['disabled']) && $this->tsFieldConf[$fieldName . '.']['disabled'] == 1) {
492 continue;
493 }
494 if (isset($config['access']) && !$this->checkAccess($config)) {
495 continue;
496 }
497
498 $label = $this->getLabel($config['label'], $fieldName);
499 $csh = $this->getCSH($config['csh'] ? $config['csh'] : $fieldName);
500 $type = $config['type'];
501 $eval = $config['eval'];
502 $class = $config['class'];
503 $style = $config['style'];
504
505 if ($class) {
506 $more .= ' class="' . $class . '"';
507 }
508 if ($style) {
509 $more .= ' style="' . $style . '"';
510 }
511
512 $value = $config['table'] == 'be_users' ? $GLOBALS['BE_USER']->user[$fieldName] : $GLOBALS['BE_USER']->uc[$fieldName];
513 if (!$value && isset($config['default'])) {
514 $value = $config['default'];
515 }
516
517 switch ($type) {
518 case 'text':
519 case 'password':
520 $dataAdd = '';
521 if ($config['table'] == 'be_users') {
522 $dataAdd = '[be_users]';
523 }
524 if ($eval == 'md5') {
525 $more .= ' onchange="this.value=this.value?MD5(this.value):\'\';"';
526 }
527
528 if ($type == 'password') {
529 $value = '';
530 }
531
532 $html = '<input id="field_' . $fieldName . '"
533 type="' . $type . '"
534 name="data' . $dataAdd . '[' . $fieldName . ']"
535 value="' . htmlspecialchars($value) . '" ' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . $more . ' />';
536 break;
537 case 'check':
538 if (!$class) {
539 $more .= ' class="check"';
540 }
541 $html = '<input id="field_' . $fieldName . '"
542 type="checkbox"
543 name="data[' . $fieldName . ']"' .
544 ($value ? ' checked="checked"' : '') . $more . ' />';
545 break;
546 case 'select':
547 if (!$class) {
548 $more .= ' class="select"';
549 }
550
551 if ($config['itemsProcFunc']) {
552 $html = t3lib_div::callUserFunction($config['itemsProcFunc'], $config, $this, '');
553 } else {
554 $html = '<select id="field_' . $fieldName . '" name="data[' . $fieldName . ']"' . $more . '>' . chr(10);
555 foreach ($config['items'] as $key => $value) {
556 $html .= '<option value="' . $key . '"' .
557 ($value == $key ? ' selected="selected"' : '') .
558 '>' . $this->getLabel($value,'',false) . '</option>' . chr(10);
559 }
560 $html .= '</select>';
561 }
562
563 break;
564 case 'user':
565 $html = t3lib_div::callUserFunction($config['userFunc'], $config, $this, '');
566 break;
567 default:
568 $html = '';
569 }
570
571
572 // add another table row with the full text help if needed
573 if ($displayFullText) {
574 $code[$i++][1] = $csh;
575 $csh = '';
576 }
577
578 $code[$i][1] = $csh . $label;
579 $code[$i++][2] = $html;
580
581
582
583 }
584
585 if ($this->dividers2tabs == 0) {
586 $tabLabel = $firstTabLabel;
587 }
588
589 $result[] = array(
590 'label' => $tabLabel,
591 'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
592 );
593
594
595 return $result;
596 }
597
598
599
600
601
602
603 /******************************
604 *
605 * Helper functions
606 *
607 ******************************/
608
609 /**
610 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
611 * Anyway: The REAL user is returned - the one logged in.
612 *
613 * @return object The REAL user is returned - the one logged in.
614 */
615 protected function getRealScriptUserObj() {
616 return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
617 }
618
619
620 /**
621 * Return a select with available languages
622 *
623 * @return string complete select as HTML string or warning box if something went wrong.
624 */
625 public function renderLanguageSelect($params, $pObj) {
626
627 // compile the languages dropdown
628 $languageOptions = array(
629 '000000000' => chr(10) . '<option value="">' . $GLOBALS['LANG']->getLL('lang_default', 1) . '</option>'
630 );
631 // traverse the number of languages
632 $theLanguages = t3lib_div::trimExplode('|', TYPO3_languages);
633 foreach ($theLanguages as $language) {
634 if ($language != 'default') {
635 $languageValue = $GLOBALS['LOCAL_LANG']['default']['lang_' . $language];
636 $localLabel = ' - ['.htmlspecialchars($languageValue) . ']';
637 $unavailable = (is_dir(PATH_typo3conf . 'l10n/' . $language) ? false : true);
638 if (!$unavailable) {
639 $languageOptions[$languageValue . '--' . $language] = '
640 <option value="'.$language.'"'.($GLOBALS['BE_USER']->uc['lang'] == $language ? ' selected="selected"' : '') . ($unavailable ? ' class="c-na"' : '').'>'.$GLOBALS['LANG']->getLL('lang_' . $language, 1) . $localLabel . '</option>';
641 }
642 }
643 }
644 ksort($languageOptions);
645 $languageCode = '
646 <select id="field_lang" name="data[lang]" class="select">' .
647 implode('', $languageOptions) . '
648 </select>';
649 if ($GLOBALS['BE_USER']->uc['lang'] && !@is_dir(PATH_typo3conf . 'l10n/' . $GLOBALS['BE_USER']->uc['lang'])) {
650 $languageUnavailableWarning = 'The selected language is not available before the language pack is installed.<br />'
651 . ($GLOBALS['BE_USER']->isAdmin() ?
652 'You can use the Extension Manager to easily download and install new language packs.'
653 : 'Please ask your system administrator to do this.');
654
655
656 $languageUnavailableMessage = t3lib_div::makeInstance(
657 't3lib_FlashMessage',
658 $languageUnavailableWarning,
659 '',
660 t3lib_FlashMessage::WARNING
661 );
662
663 $languageCode = $languageUnavailableMessage->render() . $languageCode;
664 }
665
666 return $languageCode;
667 }
668
669 /**
670 * Returns a select with all modules for startup
671 *
672 * @return string complete select as HTML string
673 */
674 public function renderStartModuleSelect($params, $pObj) {
675 // start module select
676 if (empty($GLOBALS['BE_USER']->uc['startModule'])) {
677 $GLOBALS['BE_USER']->uc['startModule'] = $GLOBALS['BE_USER']->uc_default['startModule'];
678 }
679 $startModuleSelect .= '<option value=""></option>';
680 foreach ($pObj->loadModules->modules as $mainMod => $modData) {
681 if (isset($modData['sub']) && is_array($modData['sub'])) {
682 $startModuleSelect .= '<option disabled="disabled">'.$GLOBALS['LANG']->moduleLabels['tabs'][$mainMod.'_tab'].'</option>';
683 foreach ($modData['sub'] as $subKey => $subData) {
684 $modName = $subData['name'];
685 $startModuleSelect .= '<option value="' . $modName . '"' . ($GLOBALS['BE_USER']->uc['startModule'] == $modName ? ' selected="selected"' : '') . '>';
686 $startModuleSelect .= ' - ' . $GLOBALS['LANG']->moduleLabels['tabs'][$modName.'_tab'] . '</option>';
687 }
688 }
689 }
690
691
692 return '<select id="field_startModule" name="data[startModule]" class="select">' . $startModuleSelect . '</select>';
693 }
694
695
696
697 /**
698 * Will make the simulate-user selector if the logged in user is administrator.
699 * 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)
700 *
701 * @return void
702 */
703 public function simulateUser() {
704 global $BE_USER,$LANG,$BACK_PATH;
705
706 // *******************************************************************************
707 // If admin, allow simulation of another user
708 // *******************************************************************************
709 $this->simUser = 0;
710 $this->simulateSelector = '';
711 unset($this->OLD_BE_USER);
712 if ($BE_USER->isAdmin()) {
713 $this->simUser = t3lib_div::_GP('simUser');
714
715 // Make user-selector:
716 $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName', t3lib_BEfunc::BEenableFields('be_users'));
717 $opt = array();
718 foreach ($users as $rr) {
719 if ($rr['uid'] != $BE_USER->user['uid']) {
720 $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser==$rr['uid']?' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
721 }
722 }
723 if (count($opt)) {
724 $this->simulateSelector = '<select id="field_simulate" name="simulateUser" onchange="window.location.href=\'index.php?simUser=\'+this.options[this.selectedIndex].value;"><option></option>'.implode('',$opt).'</select>';
725 }
726 }
727
728 if ($this->simUser>0) { // This can only be set if the previous code was executed.
729 $this->OLD_BE_USER = $BE_USER; // Save old user...
730 unset($BE_USER); // Unset current
731
732 $BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth'); // New backend user object
733 $BE_USER->OS = TYPO3_OS;
734 $BE_USER->setBeUserByUid($this->simUser);
735 $BE_USER->fetchGroupData();
736 $BE_USER->backendSetUC();
737 $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
738 }
739 }
740
741 /**
742 * Returns a select with simulate users
743 *
744 * @return string complete select as HTML string
745 */
746 public function renderSimulateUserSelect($params, $pObj) {
747 return $pObj->simulateSelector;
748 }
749
750 /**
751 * Returns access check (currently only "admin" is supported)
752 *
753 * @param array $config: Configuration of the field, access mode is defined in key 'access'
754 * @return boolean Whether it is allowed to modify the given field
755 */
756 protected function checkAccess(array $config) {
757 $access = $config['access'];
758 // check for hook
759 if (strpos($access, 'tx_') === 0) {
760 $accessObject = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access] . ':&' . $access);
761 if (is_object($accessObject) && method_exists($accessObject, 'accessLevelCheck')) {
762 // initialize vars. If method fails, $set will be set to false
763 return $accessObject->accessLevelCheck($config);
764 }
765 } elseif ($access == 'admin') {
766 return $this->isAdmin;
767 }
768 }
769
770
771 /**
772 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
773 *
774 * @param string Locallang key
775 * @param string Alternative override-config key
776 * @param boolean Defines whether the string should be wrapped in a <label> tag.
777 * @param string Alternative id for use in "for" attribute of <label> tag. By default the $str key is used prepended with "field_".
778 * @return string HTML output.
779 */
780 protected function getLabel($str, $key='', $addLabelTag=true, $altLabelTagId='') {
781 if (substr($str, 0, 4) == 'LLL:') {
782 $out = $GLOBALS['LANG']->sL($str);
783 } else {
784 $out = htmlspecialchars($str);
785 }
786
787
788 if (isset($this->overrideConf[($key?$key:$str)])) {
789 $out = '<span style="color:#999999">'.$out.'</span>';
790 }
791
792 if($addLabelTag) {
793 $out = '<label for="' . ($altLabelTagId ? $altLabelTagId : 'field_' . $key) . '">' . $out . '</label>';
794 }
795 return $out;
796 }
797
798 /**
799 * Returns the CSH Icon for given string
800 *
801 * @param string Locallang key
802 * @return string HTML output.
803 */
804 protected function getCSH($str) {
805 if (!t3lib_div::inList('language,simuser', $str)) {
806 $str = 'option_' . $str;
807 }
808 return t3lib_BEfunc::cshItem('_MOD_user_setup', $str, $GLOBALS['BACK_PATH'], '|', false, 'margin-bottom:0px;');
809 }
810 }
811
812
813 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']) {
814 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']);
815 }
816
817
818
819 // Make instance:
820 $SOBE = t3lib_div::makeInstance('SC_mod_user_setup_index');
821 $SOBE->simulateUser();
822 $SOBE->storeIncomingData();
823
824 // These includes MUST be afterwards the settings are saved...!
825 require ($BACK_PATH.'template.php');
826 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
827
828 $SOBE->init();
829 $SOBE->main();
830 $SOBE->printContent();
831
832 ?>