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