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