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