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