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