Fixed bug RFC #12326: EXT:setup CSH mode setting gets lost (thanks to Steffen Gebert)
[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 = 0;
116 protected $setupIsUpdated = FALSE;
117
118
119 /******************************
120 *
121 * Saving data
122 *
123 ******************************/
124
125 /**
126 * If settings are submitted to _POST[DATA], store them
127 * NOTICE: This method is called before the template.php is included. See buttom of document
128 *
129 * @return void
130 */
131 function storeIncomingData() {
132 global $BE_USER;
133
134 // First check if something is submittet in the data-array from POST vars
135 $d = t3lib_div::_POST('data');
136 $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns'];
137 $storeRec = array();
138
139 if (is_array($d)) {
140
141 // UC hashed before applying changes
142 $save_before = md5(serialize($BE_USER->uc));
143
144 // PUT SETTINGS into the ->uc array:
145
146 // reload left frame when switching BE language
147 if (isset($d['lang']) && ($d['lang'] != $BE_USER->uc['lang'])) {
148 $this->languageUpdate = true;
149 }
150
151 if ($d['setValuesToDefault']) {
152 // If every value should be default
153 $BE_USER->resetUC();
154 } elseif ($d['clearSessionVars']) {
155 foreach ($BE_USER->uc as $key => $value) {
156 if (!isset($columns[$key])) {
157 unset ($BE_USER->uc[$key]);
158 }
159 }
160 } else {
161 // save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns]
162 foreach($columns as $field => $config) {
163 if ($config['table']) {
164 if ($config['table'] == 'be_users' && !in_array($field, array('password', 'password2', 'email', 'realName', 'admin'))) {
165 if (!isset($config['access']) || $this->checkAccess($config)) {
166 $storeRec['be_users'][$BE_USER->user['uid']][$field] = $d['be_users'][$field];
167 $BE_USER->user[$field] = $d['be_users'][$field];
168 }
169 }
170 }
171 if ($config['type'] == 'check') {
172 $BE_USER->uc[$field] = isset($d[$field]) ? 1 : 0;
173 } else {
174 $BE_USER->uc[$field] = htmlspecialchars($d[$field]);
175 }
176 }
177 }
178 $BE_USER->overrideUC(); // Inserts the overriding values.
179
180 $save_after = md5(serialize($BE_USER->uc));
181 if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
182 $BE_USER->writeUC($BE_USER->uc);
183 $BE_USER->writelog(254, 1, 0, 1, 'Personal settings changed', array());
184 $this->setupIsUpdated = TRUE;
185 }
186
187
188 // Personal data for the users be_user-record (email, name, password...)
189 // If email and name is changed, set it in the users record:
190 $be_user_data = $d['be_users'];
191 $this->passwordIsUpdated = strlen($be_user_data['password'].$be_user_data['password2'])>0 ? -1 : 0;
192 if ($be_user_data['email']!=$BE_USER->user['email']
193 || $be_user_data['realName']!=$BE_USER->user['realName']
194 || ( (strlen($be_user_data['password'])==32 || (isset($columns['password']['eval']) && substr($columns['password']['eval'], 0, 3) == 'tx_'))
195 && !strcmp($be_user_data['password'],$be_user_data['password2']))
196 ) {
197
198 $BE_USER->user['realName'] = $storeRec['be_users'][$BE_USER->user['uid']]['realName'] = substr($be_user_data['realName'],0,80);
199 $BE_USER->user['email'] = $storeRec['be_users'][$BE_USER->user['uid']]['email'] = substr($be_user_data['email'],0,80);
200
201 if (isset($columns['password']['eval']) && substr($columns['password']['eval'], 0, 3) == 'tx_') {
202 // password encryption by external script (e.g. EXT:saltedpasswords)
203 $func = $columns['password']['eval'];
204 $evalObj = t3lib_div::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func].':&'.$func);
205 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
206 // initialize vars. If method fails, $set will be set to false
207 $is_in = '';
208 $set = TRUE;
209 $newPassword = $evalObj->evaluateFieldValue($be_user_data['password2'], $is_in, $set);
210 if ($set === TRUE) {
211 // password was changed
212 $storeRec['be_users'][$BE_USER->user['uid']]['password'] = $newPassword;
213 $this->passwordIsUpdated = 1;
214 }
215 }
216 } else {
217 if (strlen($be_user_data['password'])==32 && !strcmp($be_user_data['password'],$be_user_data['password2'])) {
218 $storeRec['be_users'][$BE_USER->user['uid']]['password'] = $be_user_data['password2'];
219 $this->passwordIsUpdated = 1;
220 }
221 }
222 }
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 $this->setupIsUpdated = TRUE;
233 }
234 }
235 }
236
237
238
239
240
241
242
243
244
245
246
247
248 /******************************
249 *
250 * Rendering module
251 *
252 ******************************/
253
254 /**
255 * Initializes the module for display of the settings form.
256 *
257 * @return void
258 */
259 function init() {
260 $this->MCONF = $GLOBALS['MCONF'];
261
262
263 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
264 $scriptUser = $this->getRealScriptUserObj();
265 // ... and checking module access for the logged in user.
266 $scriptUser->modAccess($this->MCONF, 1);
267
268 $this->isAdmin = $scriptUser->isAdmin();
269
270 // Getting the 'override' values as set might be set in User TSconfig
271 $this->overrideConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.override');
272 // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1)
273 $this->tsFieldConf = $GLOBALS['BE_USER']->getTSConfigProp('setup.fields');
274
275 // Create instance of object for output of data
276 $this->doc = t3lib_div::makeInstance('template');
277 $this->doc->backPath = $GLOBALS['BACK_PATH'];
278 $this->doc->setModuleTemplate('templates/setup.html');
279 $this->doc->JScodeLibArray['dyntabmenu'] = $this->doc->getDynTabMenuJScode();
280 $this->doc->form = '<form action="index.php" method="post" name="usersetup" enctype="application/x-www-form-urlencoded">';
281 $this->doc->tableLayout = array(
282 'defRow' => array(
283 '0' => array('<td class="td-label">','</td>'),
284 'defCol' => array('<td valign="top">','</td>')
285 )
286 );
287 $this->doc->table_TR = '<tr>';
288 $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2" class="typo3-usersettings">';
289 }
290
291 /**
292 * Generate the main settings formular:
293 *
294 * @return void
295 */
296 function main() {
297 global $BE_USER,$LANG,$BACK_PATH,$TBE_MODULES;
298
299 // file creation / delete
300 if ($this->isAdmin) {
301 if (t3lib_div::_POST('deleteInstallToolEnableFile')) {
302 unlink(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
303 }
304 if (t3lib_div::_POST('createInstallToolEnableFile')) {
305 touch(PATH_typo3conf . 'ENABLE_INSTALL_TOOL');
306 }
307 }
308
309 if ($this->languageUpdate) {
310 $this->doc->JScodeArray['languageUpdate'] .= '
311 if (top.refreshMenu) {
312 top.refreshMenu();
313 } else {
314 top.TYPO3ModuleMenu.refreshMenu();
315 }
316
317 if (top.shortcutFrame) {
318 top.shortcutFrame.refreshShortcuts();
319 }
320 ';
321 }
322
323 // Start page:
324 $this->doc->loadJavascriptLib('md5.js');
325
326 // use a wrapper div
327 $this->content .= '<div id="user-setup-wrapper">';
328
329 // Load available backend modules
330 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
331 $this->loadModules->observeWorkspaces = true;
332 $this->loadModules->load($TBE_MODULES);
333
334 $this->content .= $this->doc->header($LANG->getLL('UserSettings').' - '.$BE_USER->user['realName'].' ['.$BE_USER->user['username'].']');
335
336 // show if setup was saved
337 if ($this->setupIsUpdated) {
338 $flashMessage = t3lib_div::makeInstance(
339 't3lib_FlashMessage',
340 $LANG->getLL('setupWasUpdated'),
341 $LANG->getLL('UserSettings')
342 );
343 $this->content .= $flashMessage->render();
344 }
345 // If password is updated, output whether it failed or was OK.
346 if ($this->passwordIsUpdated) {
347 if ($this->passwordIsUpdated > 0) {
348 $flashMessage = t3lib_div::makeInstance(
349 't3lib_FlashMessage',
350 $LANG->getLL('newPassword_ok'),
351 $LANG->getLL('newPassword')
352 );
353 } else {
354 $flashMessage = t3lib_div::makeInstance(
355 't3lib_FlashMessage',
356 $LANG->getLL('newPassword_failed'),
357 $LANG->getLL('newPassword'),
358 t3lib_FlashMessage::ERROR
359 );
360 }
361 $this->content .= $flashMessage->render();
362 }
363
364
365 // render the menu items
366 $menuItems = $this->renderUserSetup();
367
368 $this->content .= $this->doc->spacer(20) . $this->doc->getDynTabMenu($menuItems, 'user-setup', false, false, 100, 1, false, 1, $this->dividers2tabs);
369
370
371 // Submit and reset buttons
372 $this->content .= $this->doc->spacer(20);
373 $this->content .= $this->doc->section('',
374 t3lib_BEfunc::cshItem('_MOD_user_setup', 'reset', $BACK_PATH) . '
375 <input type="hidden" name="simUser" value="'.$this->simUser.'" />
376 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
377 <input type="submit" name="data[setValuesToDefault]" value="'.$LANG->getLL('resetConfiguration').'" onclick="return confirm(\''.$LANG->getLL('setToStandardQuestion').'\');" />
378 <input type="submit" name="data[clearSessionVars]" value="'.$LANG->getLL('clearSessionVars').'" />'
379 );
380
381
382
383 // Notice
384 $this->content .= $this->doc->spacer(30);
385 $this->content .= $this->doc->section('', $LANG->getLL('activateChanges'));
386
387 // Setting up the buttons and markers for docheader
388 $docHeaderButtons = $this->getButtons();
389 $markers['CSH'] = $docHeaderButtons['csh'];
390 $markers['CONTENT'] = $this->content;
391
392 // Build the <body> for the module
393 $this->content = $this->doc->startPage($LANG->getLL('UserSettings'));
394 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
395 // end of wrapper div
396 $this->content .= '</div>';
397 $this->content.= $this->doc->endPage();
398 $this->content = $this->doc->insertStylesAndJS($this->content);
399
400 }
401
402 /**
403 * Prints the content / ends page
404 *
405 * @return void
406 */
407 function printContent() {
408 echo $this->content;
409 }
410
411 /**
412 * Create the panel of buttons for submitting the form or otherwise perform operations.
413 *
414 * @return array all available buttons as an assoc. array
415 */
416 protected function getButtons() {
417 $buttons = array(
418 'csh' => '',
419 'save' => '',
420 'shortcut' => '',
421 );
422
423 $buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'], '|', true);
424
425 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
426 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','',$this->MCONF['name']);
427 }
428
429 return $buttons;
430 }
431
432
433
434
435 /******************************
436 *
437 * Render module
438 *
439 ******************************/
440
441
442 /**
443 * renders the data for all tabs in the user setup and returns
444 * everything that is needed with tabs and dyntab menu
445 *
446 * @return ready to use for the dyntabmenu itemarray
447 */
448 protected function renderUserSetup() {
449 $result = array();
450 $firstTabLabel = '';
451 $code = array();
452 $i = 0;
453
454 $fieldList = $GLOBALS['TYPO3_USER_SETTINGS']['showitem'];
455
456 // disable fields depended on settings
457 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
458 $fieldList = t3lib_div::rmFromList('edit_RTE', $fieldList);
459 }
460
461 if ($GLOBALS['BE_USER']->uc['interfaceSetup'] != 'backend_old') {
462 $fieldList = t3lib_div::rmFromList('noMenuMode', $fieldList);
463 }
464
465 $fieldArray = t3lib_div::trimExplode(',', $fieldList, true);
466 $this->dividers2tabs = isset($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) ? intval($GLOBALS['TYPO3_USER_SETTINGS']['ctrl']['dividers2tabs']) : 0;
467
468
469 // "display full help" is active?
470 $displayFullText = ($GLOBALS['BE_USER']->uc['edit_showFieldHelp'] == 'text');
471 if ($displayFullText) {
472 $this->doc->tableLayout['defRowEven'] = array('defCol' => array ('<td valign="top" colspan="3">','</td>'));
473 }
474
475 foreach ($fieldArray as $fieldName) {
476 $more = '';
477
478 if (substr($fieldName, 0, 8) == '--div--;') {
479 if ($firstTabLabel == '') {
480 // first tab
481 $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
482 $firstTabLabel = $tabLabel;
483 } else {
484 if ($this->dividers2tabs) {
485 $result[] = array(
486 'label' => $tabLabel,
487 'content' => count($code) ? $this->doc->spacer(20) . $this->doc->table($code) : ''
488 );
489 $tabLabel = $this->getLabel(substr($fieldName, 8), '', false);
490 $i = 0;
491 $code = array();
492 }
493 }
494 continue;
495 }
496
497 $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName];
498
499 // field my be disabled in setup.fields
500 if (isset($this->tsFieldConf[$fieldName . '.']['disabled']) && $this->tsFieldConf[$fieldName . '.']['disabled'] == 1) {
501 continue;
502 }
503 if (isset($config['access']) && !$this->checkAccess($config)) {
504 continue;
505 }
506
507 $label = $this->getLabel($config['label'], $fieldName);
508 $csh = $this->getCSH($config['csh'] ? $config['csh'] : $fieldName);
509 $type = $config['type'];
510 $eval = $config['eval'];
511 $class = $config['class'];
512 $style = $config['style'];
513
514 if ($class) {
515 $more .= ' class="' . $class . '"';
516 }
517 if ($style) {
518 $more .= ' style="' . $style . '"';
519 }
520
521 $value = $config['table'] == 'be_users' ? $GLOBALS['BE_USER']->user[$fieldName] : $GLOBALS['BE_USER']->uc[$fieldName];
522 if (!$value && isset($config['default'])) {
523 $value = $config['default'];
524 }
525
526 switch ($type) {
527 case 'text':
528 case 'password':
529 $dataAdd = '';
530 if ($config['table'] == 'be_users') {
531 $dataAdd = '[be_users]';
532 }
533 if ($eval == 'md5') {
534 $more .= ' onchange="this.value=this.value?MD5(this.value):\'\';"';
535 }
536
537 if ($type == 'password') {
538 $value = '';
539 }
540
541 $html = '<input id="field_' . $fieldName . '"
542 type="' . $type . '"
543 name="data' . $dataAdd . '[' . $fieldName . ']"
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 => $label) {
565 $html .= '<option value="' . $key . '"' .
566 ($value == $key ? ' selected="selected"' : '') .
567 '>' . $this->getLabel($label,'',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 ?>