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