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