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