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