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