2 /***************************************************************
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Module: User configuration
30 * This module lets users viev and change their individual settings
32 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
33 * Revised for TYPO3 3.7 6/2004 by Kasper Skaarhoj
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 86: class SC_mod_user_setup_index
43 * SECTION: Saving data
44 * 114: function storeIncomingData()
46 * SECTION: Rendering module
47 * 216: function init()
48 * 248: function main()
49 * 403: function printContent()
51 * SECTION: Helper functions
52 * 432: function getRealScriptUserObj()
53 * 442: function simulateUser()
54 * 488: function setLabel($str,$key='')
57 * (This index is automatically created/updated by the extension "extdeveval")
63 require($BACK_PATH.'init.php');
64 require_once(PATH_t3lib
.'class.t3lib_tcemain.php');
65 require_once(PATH_t3lib
.'class.t3lib_loadmodules.php');
81 * Script class for the Setup module
83 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
85 * @subpackage tx_setup
87 class SC_mod_user_setup_index
{
89 // Internal variables:
91 var $MOD_MENU = array();
92 var $MOD_SETTINGS = array();
103 /******************************
107 ******************************/
110 * If settings are submitted to _POST[DATA], store them
111 * NOTICE: This method is called before the template.php is included. See buttom of document
115 function storeIncomingData() {
119 // First check if something is submittet in the data-array from POST vars
120 $d = t3lib_div
::_POST('data');
123 // UC hashed before applying changes
124 $save_before = md5(serialize($BE_USER->uc
));
126 // PUT SETTINGS into the ->uc array:
129 $BE_USER->uc
['lang'] = $d['lang'];
132 $BE_USER->uc
['condensedMode'] = $d['condensedMode'];
133 $BE_USER->uc
['noMenuMode'] = $d['noMenuMode'];
134 $BE_USER->uc
['startModule'] = $d['startModule'];
135 $BE_USER->uc
['thumbnailsByDefault'] = $d['thumbnailsByDefault'];
136 $BE_USER->uc
['helpText'] = $d['helpText'];
137 $BE_USER->uc
['titleLen'] = intval($d['titleLen']);
139 // Advanced functions:
140 $BE_USER->uc
['copyLevels'] = t3lib_div
::intInRange($d['copyLevels'],0,100);
141 $BE_USER->uc
['recursiveDelete'] = $d['recursiveDelete'];
144 $BE_USER->uc
['edit_wideDocument'] = $d['edit_wideDocument'];
145 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) { $BE_USER->uc
['edit_RTE'] = $d['edit_RTE']; }
146 $BE_USER->uc
['edit_docModuleUpload'] = $d['edit_docModuleUpload'];
147 $BE_USER->uc
['edit_showFieldHelp'] = $d['edit_showFieldHelp'];
148 $BE_USER->uc
['disableCMlayers'] = $d['disableCMlayers'];
151 $BE_USER->uc
['emailMeAtLogin'] = $d['emailMeAtLogin'];
154 if ($d['setValuesToDefault']) { // If every value should be default
157 $BE_USER->overrideUC(); // Inserts the overriding values.
159 $save_after = md5(serialize($BE_USER->uc
));
160 if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
161 $BE_USER->writeUC($BE_USER->uc
);
162 $BE_USER->writelog(254,1,0,1,'Personal settings changed',Array());
166 // Personal data for the users be_user-record (email, name, password...)
167 // If email and name is changed, set it in the users record:
168 $be_user_data = t3lib_div
::_GP('ext_beuser');
169 $this->PASSWORD_UPDATED
= strlen($be_user_data['password1'].$be_user_data['password2'])>0 ?
-1 : 0;
170 if ($be_user_data['email']!=$BE_USER->user
['email']
171 ||
$be_user_data['realName']!=$BE_USER->user
['realName']
172 ||
(strlen($be_user_data['password1'])==32
173 && !strcmp($be_user_data['password1'],$be_user_data['password2']))
176 $BE_USER->user
['realName'] = $storeRec['be_users'][$BE_USER->user
['uid']]['realName'] = substr($be_user_data['realName'],0,80);
177 $BE_USER->user
['email'] = $storeRec['be_users'][$BE_USER->user
['uid']]['email'] = substr($be_user_data['email'],0,80);
178 if (strlen($be_user_data['password1'])==32 && !strcmp($be_user_data['password1'],$be_user_data['password2'])) {
179 $BE_USER->user
['password'] = $storeRec['be_users'][$BE_USER->user
['uid']]['password'] = $be_user_data['password1'];
180 $this->PASSWORD_UPDATED
= 1;
183 // Make instance of TCE for storing the changes.
184 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
185 $tce->stripslashes_values
=0;
186 $tce->start($storeRec,Array(),$BE_USER);
187 $tce->admin
= 1; // This is so the user can actually update his user record.
188 $tce->bypassWorkspaceRestrictions
= TRUE; // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
189 $tce->process_datamap();
206 /******************************
210 ******************************/
213 * Initializes the module for display of the settings form.
218 global $BE_USER,$BACK_PATH;
219 $this->MCONF
= $GLOBALS['MCONF'];
221 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
222 $scriptUser = $this->getRealScriptUserObj();
223 $scriptUser->modAccess($this->MCONF
,1); // ... and checking module access for the logged in user.
225 // Getting the 'override' values as set might be set in User TSconfig
226 $this->overrideConf
= $BE_USER->getTSConfigProp('setup.override');
228 // Create instance of object for output of data
229 $this->doc
= t3lib_div
::makeInstance('mediumDoc');
230 $this->doc
->backPath
= $BACK_PATH;
231 $this->doc
->docType
= 'xhtml_trans';
233 $this->doc
->form
= '<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">';
234 $this->doc
->tableLayout
= Array (
236 '0' => Array('<td align="left" width="300">','</td>'),
237 'defCol' => Array('<td valign="top">','</td>')
240 $this->doc
->table_TR
= '<tr class="bgColor4">';
241 $this->doc
->table_TABLE
= '<table border="0" cellspacing="1" cellpadding="2">';
245 * Generate the main settings formular:
250 global $BE_USER,$LANG,$BACK_PATH,$TBE_MODULES;;
253 $this->doc
->JScode
.= '<script language="javascript" type="text/javascript" src="'.$BACK_PATH.'md5.js"></script>';
254 $this->content
.= $this->doc
->startPage($LANG->getLL('UserSettings'));
255 $this->content
.= $this->doc
->header($LANG->getLL('UserSettings').' - ['.$BE_USER->user
['username'].']');
257 // Load available backend modules
258 $this->loadModules
= t3lib_div
::makeInstance('t3lib_loadModules');
259 $this->loadModules
->observeWorkspaces
= TRUE;
260 $this->loadModules
->load($TBE_MODULES);
263 $this->content
.= t3lib_BEfunc
::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'],'|');
265 // If password is updated, output whether it failed or was OK.
266 if ($this->PASSWORD_UPDATED
) {
267 if ($this->PASSWORD_UPDATED
>0) {
268 $this->content
.=$this->doc
->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_ok'),1,0,1);
270 $this->content
.=$this->doc
->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_failed'),1,0,2);
272 $this->content
.=$this->doc
->spacer(25);
275 // Simulate selector box:
276 if ($this->simulateSelector
) {
277 $this->content
.=$this->doc
->section($LANG->getLL('simulate').':',$this->simulateSelector
.t3lib_BEfunc
::cshItem('_MOD_user_setup', 'simuser', $GLOBALS['BACK_PATH'],'|'),1,0,($this->simUser?
2:0));
284 <option value="">'.$LANG->getLL('lang_default',1).'</option>';
285 $theLanguages = t3lib_div
::trimExplode('|',TYPO3_languages
);
287 // Character set conversion object:
288 $csConvObj = t3lib_div
::makeInstance('t3lib_cs');
290 // traverse the number of languages:
291 foreach($theLanguages as $val) {
292 if ($val!='default') {
293 $localLabel = ' - ['.htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_'.$val]).']';
294 $unavailable = $val!='default' && !@is_dir
(PATH_typo3conf
.'l10n/'.$val) ?
'1' : '';
295 $opt[$GLOBALS['LOCAL_LANG']['default']['lang_'.$val].'--'.$val]='
296 <option value="'.$val.'"'.($BE_USER->uc
['lang']==$val?
' selected="selected"':'').($unavailable ?
' class="c-na"' : '').'>'.$LANG->getLL('lang_'.$val,1).$localLabel.'</option>';
301 <select name="data[lang]">'.
304 t3lib_BEfunc
::cshItem('_MOD_user_setup', 'language', $GLOBALS['BACK_PATH'],'|');
305 if ($BE_USER->uc
['lang'] && !@is_dir
(PATH_typo3conf
.'l10n/'.$BE_USER->uc
['lang'])) {
306 $code.= '<table border="0" cellpadding="0" cellspacing="0" class="warningbox"><tr><td>'.
307 $this->doc
->icons(3).
308 'The selected language is not available before the language pack is installed.<br />'.
309 ($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.').
310 '</td></tr></table>';
312 $this->content
.=$this->doc
->section($LANG->getLL('language').':',$code,0,1);
315 // 'Startup' section:
318 $code[2][1] = $this->setLabel('condensedMode','condensedMode');
319 $code[2][2] = '<input type="checkbox" name="data[condensedMode]"'.($BE_USER->uc
['condensedMode']?
' checked="checked"':'').' />';
320 $code[3][1] = $this->setLabel('noMenuMode','noMenuMode');
321 $code[3][2] = '<select name="data[noMenuMode]">
322 <option value=""'.(!$BE_USER->uc
['noMenuMode']?
' selected="selected"':'').'>'.$this->setLabel('noMenuMode_def').'</option>
323 <option value="1"'.($BE_USER->uc
['noMenuMode'] && (string)$BE_USER->uc
['noMenuMode']!="icons"?
' selected="selected"':'').'>'.$this->setLabel('noMenuMode_sel').'</option>
324 <option value="icons"'.((string)$BE_USER->uc
['noMenuMode']=='icons'?
' selected="selected"':'').'>'.$this->setLabel('noMenuMode_icons').'</option>
326 $code[4][1] = $this->setLabel('startModule','startModule');
327 $modSelect = '<select name="data[startModule]">';
328 $modSelect .= '<option value=""></option>';
329 if (empty($BE_USER->uc
['startModule'])) {
330 $BE_USER->uc
['startModule'] = $BE_USER->uc_default
['startModule'];
332 foreach ($this->loadModules
->modules
as $mainMod => $modData) {
333 if (isset($modData['sub']) && is_array($modData['sub'])) {
334 $modSelect .= '<option disabled="disabled">'.$LANG->moduleLabels
['tabs'][$mainMod.'_tab'].'</option>';
335 foreach ($modData['sub'] as $subKey => $subData) {
336 $modName = $subData['name'];
337 $modSelect .= '<option value="'.$modName.'"'.($BE_USER->uc
['startModule']==$modName?
' selected="selected"':'').'>';
338 $modSelect .= ' - '.$LANG->moduleLabels
['tabs'][$modName.'_tab'].'</option>';
342 $modSelect .= '</select>';
343 $code[4][2] = $modSelect;
345 $code[5][1] = $this->setLabel('showThumbs','thumbnailsByDefault');
346 $code[5][2] = '<input type="checkbox" name="data[thumbnailsByDefault]"'.($BE_USER->uc
['thumbnailsByDefault']?
' checked="checked"':'').' />';
347 $code[6][1] = $this->setLabel('helpText');
348 $code[6][2] = '<input type="checkbox" name="data[helpText]"'.($BE_USER->uc
['helpText']?
' checked="checked"':'').' />';
349 $code[7][1] = $this->setLabel('maxTitleLen','titleLen');
350 $code[7][2] = '<input type="text" name="data[titleLen]" value="'.$BE_USER->uc
['titleLen'].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' maxlength="5" />';
352 $this->content
.=$this->doc
->section($LANG->getLL('opening').':',$this->doc
->table($code),0,1);
355 // Advanced Operations:
357 $code[1][1] = $this->setLabel('copyLevels');
358 $code[1][2] = '<input type="text" name="data[copyLevels]" value="'.$BE_USER->uc
['copyLevels'].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' maxlength="5" /> '.$this->setLabel('levels','copyLevels');
359 $code[2][1] = $this->setLabel('recursiveDelete');
360 $code[2][2] = '<input type="checkbox" name="data[recursiveDelete]"'.($BE_USER->uc
['recursiveDelete']?
' checked="checked"':'').' />';
362 $this->content
.=$this->doc
->section($LANG->getLL('functions').":",$this->doc
->table($code),0,1);
367 $code[2][1] = $this->setLabel('edit_wideDocument');
368 $code[2][2] = '<input type="checkbox" name="data[edit_wideDocument]"'.($BE_USER->uc
['edit_wideDocument']?
' checked="checked"':'').' />';
369 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
370 $code[3][1] = $this->setLabel('edit_RTE');
371 $code[3][2] = '<input type="checkbox" name="data[edit_RTE]"'.($BE_USER->uc
['edit_RTE']?
' checked="checked"':'').' />';
373 $code[4][1] = $this->setLabel('edit_docModuleUpload');
374 $code[4][2] = '<input type="checkbox" name="data[edit_docModuleUpload]"'.($BE_USER->uc
['edit_docModuleUpload']?
' checked="checked"':'').' />';
376 $code[6][1] = $this->setLabel('edit_showFieldHelp');
377 $code[6][2] = '<select name="data[edit_showFieldHelp]">
378 <option value=""></option>
379 <option value="icon"'.($BE_USER->uc
['edit_showFieldHelp']=='icon'?
' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_icon').'</option>
380 <option value="text"'.($BE_USER->uc
['edit_showFieldHelp']=='text'?
' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_message').'</option>
383 $code[7][1] = $this->setLabel('disableCMlayers');
384 $code[7][2] = '<input type="checkbox" name="data[disableCMlayers]"'.($BE_USER->uc
['disableCMlayers']?
' checked="checked"':'').' />';
386 $this->content
.=$this->doc
->section($LANG->getLL('edit_functions').":",$this->doc
->table($code),0,1);
391 $code[1][1] = $this->setLabel('beUser_realName');
392 $code[1][2] = '<input type="text" name="ext_beuser[realName]" value="'.htmlspecialchars($BE_USER->user
['realName']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
393 $code[2][1] = $this->setLabel('beUser_email');
394 $code[2][2] = '<input type="text" name="ext_beuser[email]" value="'.htmlspecialchars($BE_USER->user
['email']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
395 $code[3][1] = $this->setLabel('emailMeAtLogin').' ('.$GLOBALS['BE_USER']->user
['email'].')';
396 $code[3][2] = '<input type="checkbox" name="data[emailMeAtLogin]"'.($BE_USER->uc
['emailMeAtLogin']?
' checked="checked"':'').' />';
397 $code[4][1] = $this->setLabel('newPassword');
398 $code[4][2] = '<input type="password" name="ext_beuser[password1]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\';" />';
399 $code[5][1] = $this->setLabel('newPasswordAgain');
400 $code[5][2] = '<input type="password" name="ext_beuser[password2]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\'" />';
402 $this->content
.=$this->doc
->section($LANG->getLL('personal_data').":",$this->doc
->table($code),0,1);
406 $this->content
.=$this->doc
->spacer(20);
407 $this->content
.=$this->doc
->section('','
408 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
409 <label for="setValuesToDefault"><b>'.$LANG->getLL('setToStandard').':</b></label> <input type="checkbox" name="data[setValuesToDefault]" id="setValuesToDefault" />'.
410 t3lib_BEfunc
::cshItem('_MOD_user_setup', 'reset', $GLOBALS['BACK_PATH'],'|').'
411 <input type="hidden" name="simUser" value="'.$this->simUser
.'" />');
415 $this->content
.=$this->doc
->spacer(5);
416 $this->content
.=$this->doc
->section('',$LANG->getLL('activateChanges'));
420 * Prints the content / ends page
424 function printContent() {
425 $this->content
.= $this->doc
->endPage();
441 /******************************
445 ******************************/
448 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
449 * Anyway: The REAL user is returned - the one logged in.
451 * @return object The REAL user is returned - the one logged in.
453 function getRealScriptUserObj() {
454 return is_object($this->OLD_BE_USER
) ?
$this->OLD_BE_USER
: $GLOBALS['BE_USER'];
458 * Will make the simulate-user selector if the logged in user is administrator.
459 * 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)
463 function simulateUser() {
464 global $BE_USER,$LANG,$BACK_PATH;
466 // *******************************************************************************
467 // If admin, allow simulation of another user
468 // *******************************************************************************
470 $this->simulateSelector
= '';
471 unset($this->OLD_BE_USER
);
472 if ($BE_USER->isAdmin()) {
473 $this->simUser
= t3lib_div
::_GP('simUser');
475 // Make user-selector:
476 $users = t3lib_BEfunc
::getUserNames('username,usergroup,usergroup_cached_list,uid,realName');
479 $opt[] = '<option></option>';
480 while(list(,$rr)=each($users)) {
481 if ($rr['uid']!=$BE_USER->user
['uid']) {
482 $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser
==$rr['uid']?
' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
485 $this->simulateSelector
= '<select name="simulateUser" onchange="window.location.href=\'index.php?simUser=\'+this.options[this.selectedIndex].value;">'.implode('',$opt).'</select>';
488 if ($this->simUser
>0) { // This can only be set if the previous code was executed.
489 $this->OLD_BE_USER
= $BE_USER; // Save old user...
490 unset($BE_USER); // Unset current
492 $BE_USER = t3lib_div
::makeInstance('t3lib_beUserAuth'); // New backend user object
493 $BE_USER->OS
= TYPO3_OS
;
494 $BE_USER->setBeUserByUid($this->simUser
);
495 $BE_USER->fetchGroupData();
496 $BE_USER->backendSetUC();
497 $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
502 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
503 * Adds CSH as well if applicable.
505 * @param string Locallang key
506 * @param string Alternative override-config key
507 * @return string HTML output.
509 function setLabel($str,$key='') {
510 $out = $GLOBALS['LANG']->getLL($str);
511 if (isset($this->overrideConf
[($key?
$key:$str)])) {
512 $out = '<span style="color:#999999">'.$out.'</span>';
516 $csh = t3lib_BEfunc
::cshItem('_MOD_user_setup', 'option_'.$str, $GLOBALS['BACK_PATH'],'|',FALSE,'margin-bottom:0px;');
517 if (strlen($csh)) $csh = ': '.$csh;
524 // Include extension?
525 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/setup/mod/index.php']) {
526 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/setup/mod/index.php']);
541 $SOBE = t3lib_div
::makeInstance('SC_mod_user_setup_index');
542 $SOBE->simulateUser();
543 $SOBE->storeIncomingData();
545 // These includes MUST be afterwards the settings are saved...!
546 require ($BACK_PATH.'template.php');
547 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
551 $SOBE->printContent();