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