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