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