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