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();
104 /******************************
108 ******************************/
111 * If settings are submitted to _POST[DATA], store them
112 * NOTICE: This method is called before the template.php is included. See buttom of document
116 function storeIncomingData() {
120 // First check if something is submittet in the data-array from POST vars
121 $d = t3lib_div
::_POST('data');
124 // UC hashed before applying changes
125 $save_before = md5(serialize($BE_USER->uc
));
127 // PUT SETTINGS into the ->uc array:
129 // reload left frame when switching BE language
130 if (isset($d['lang']) && ($d['lang'] != $BE_USER->uc
['lang'])) {
131 $this->languageUpdate
= true;
134 $BE_USER->uc
['lang'] = $d['lang'];
137 $BE_USER->uc
['condensedMode'] = $d['condensedMode'];
138 $BE_USER->uc
['noMenuMode'] = $d['noMenuMode'];
139 $BE_USER->uc
['startModule'] = $d['startModule'];
140 $BE_USER->uc
['thumbnailsByDefault'] = $d['thumbnailsByDefault'];
141 $BE_USER->uc
['helpText'] = $d['helpText'];
142 $BE_USER->uc
['titleLen'] = intval($d['titleLen']);
144 // Advanced functions:
145 $BE_USER->uc
['copyLevels'] = t3lib_div
::intInRange($d['copyLevels'],0,100);
146 $BE_USER->uc
['recursiveDelete'] = $d['recursiveDelete'];
149 $BE_USER->uc
['edit_wideDocument'] = $d['edit_wideDocument'];
150 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) { $BE_USER->uc
['edit_RTE'] = $d['edit_RTE']; }
151 $BE_USER->uc
['edit_docModuleUpload'] = $d['edit_docModuleUpload'];
152 $BE_USER->uc
['edit_showFieldHelp'] = $d['edit_showFieldHelp'];
153 $BE_USER->uc
['disableCMlayers'] = $d['disableCMlayers'];
156 $BE_USER->uc
['emailMeAtLogin'] = $d['emailMeAtLogin'];
159 if ($d['setValuesToDefault']) { // If every value should be default
162 $BE_USER->overrideUC(); // Inserts the overriding values.
164 $save_after = md5(serialize($BE_USER->uc
));
165 if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
166 $BE_USER->writeUC($BE_USER->uc
);
167 $BE_USER->writelog(254,1,0,1,'Personal settings changed',Array());
171 // Personal data for the users be_user-record (email, name, password...)
172 // If email and name is changed, set it in the users record:
173 $be_user_data = t3lib_div
::_GP('ext_beuser');
174 $this->PASSWORD_UPDATED
= strlen($be_user_data['password1'].$be_user_data['password2'])>0 ?
-1 : 0;
175 if ($be_user_data['email']!=$BE_USER->user
['email']
176 ||
$be_user_data['realName']!=$BE_USER->user
['realName']
177 ||
(strlen($be_user_data['password1'])==32
178 && !strcmp($be_user_data['password1'],$be_user_data['password2']))
181 $BE_USER->user
['realName'] = $storeRec['be_users'][$BE_USER->user
['uid']]['realName'] = substr($be_user_data['realName'],0,80);
182 $BE_USER->user
['email'] = $storeRec['be_users'][$BE_USER->user
['uid']]['email'] = substr($be_user_data['email'],0,80);
183 if (strlen($be_user_data['password1'])==32 && !strcmp($be_user_data['password1'],$be_user_data['password2'])) {
184 $BE_USER->user
['password'] = $storeRec['be_users'][$BE_USER->user
['uid']]['password'] = $be_user_data['password1'];
185 $this->PASSWORD_UPDATED
= 1;
188 // Make instance of TCE for storing the changes.
189 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
190 $tce->stripslashes_values
=0;
191 $tce->start($storeRec,Array(),$BE_USER);
192 $tce->admin
= 1; // This is so the user can actually update his user record.
193 $tce->bypassWorkspaceRestrictions
= TRUE; // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
194 $tce->process_datamap();
211 /******************************
215 ******************************/
218 * Initializes the module for display of the settings form.
223 global $BE_USER,$BACK_PATH;
224 $this->MCONF
= $GLOBALS['MCONF'];
226 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
227 $scriptUser = $this->getRealScriptUserObj();
228 $scriptUser->modAccess($this->MCONF
,1); // ... and checking module access for the logged in user.
230 // Getting the 'override' values as set might be set in User TSconfig
231 $this->overrideConf
= $BE_USER->getTSConfigProp('setup.override');
233 // Create instance of object for output of data
234 $this->doc
= t3lib_div
::makeInstance('mediumDoc');
235 $this->doc
->backPath
= $BACK_PATH;
236 $this->doc
->docType
= 'xhtml_trans';
238 $this->doc
->form
= '<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">';
239 $this->doc
->tableLayout
= Array (
241 '0' => Array('<td align="left" width="300">','</td>'),
242 'defCol' => Array('<td valign="top">','</td>')
245 $this->doc
->table_TR
= '<tr class="bgColor4">';
246 $this->doc
->table_TABLE
= '<table border="0" cellspacing="1" cellpadding="2">';
250 * Generate the main settings formular:
255 global $BE_USER,$LANG,$BACK_PATH,$TBE_MODULES;
257 if ($this->languageUpdate
) {
258 $this->doc
->JScode
.= '<script language="javascript" type="text/javascript">
260 if(top.shortcutFrame) {
261 top.shortcutFrame.refreshShortcuts();
267 $this->doc
->JScode
.= '<script language="javascript" type="text/javascript" src="'.$BACK_PATH.'md5.js"></script>';
268 $this->content
.= $this->doc
->startPage($LANG->getLL('UserSettings'));
269 $this->content
.= $this->doc
->header($LANG->getLL('UserSettings').' - ['.$BE_USER->user
['username'].']');
271 // Load available backend modules
272 $this->loadModules
= t3lib_div
::makeInstance('t3lib_loadModules');
273 $this->loadModules
->observeWorkspaces
= TRUE;
274 $this->loadModules
->load($TBE_MODULES);
277 $this->content
.= t3lib_BEfunc
::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'],'|');
279 // If password is updated, output whether it failed or was OK.
280 if ($this->PASSWORD_UPDATED
) {
281 if ($this->PASSWORD_UPDATED
>0) {
282 $this->content
.=$this->doc
->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_ok'),1,0,1);
284 $this->content
.=$this->doc
->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_failed'),1,0,2);
286 $this->content
.=$this->doc
->spacer(25);
289 // Simulate selector box:
290 if ($this->simulateSelector
) {
291 $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));
298 <option value="">'.$LANG->getLL('lang_default',1).'</option>';
299 $theLanguages = t3lib_div
::trimExplode('|',TYPO3_languages
);
301 // Character set conversion object:
302 $csConvObj = t3lib_div
::makeInstance('t3lib_cs');
304 // traverse the number of languages:
305 foreach($theLanguages as $val) {
306 if ($val!='default') {
307 $localLabel = ' - ['.htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_'.$val]).']';
308 $unavailable = $val!='default' && !@is_dir
(PATH_typo3conf
.'l10n/'.$val) ?
'1' : '';
309 $opt[$GLOBALS['LOCAL_LANG']['default']['lang_'.$val].'--'.$val]='
310 <option value="'.$val.'"'.($BE_USER->uc
['lang']==$val?
' selected="selected"':'').($unavailable ?
' class="c-na"' : '').'>'.$LANG->getLL('lang_'.$val,1).$localLabel.'</option>';
315 <select name="data[lang]">'.
318 t3lib_BEfunc
::cshItem('_MOD_user_setup', 'language', $GLOBALS['BACK_PATH'],'|');
319 if ($BE_USER->uc
['lang'] && !@is_dir
(PATH_typo3conf
.'l10n/'.$BE_USER->uc
['lang'])) {
320 $code.= '<table border="0" cellpadding="0" cellspacing="0" class="warningbox"><tr><td>'.
321 $this->doc
->icons(3).
322 'The selected language is not available before the language pack is installed.<br />'.
323 ($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.').
324 '</td></tr></table>';
326 $this->content
.=$this->doc
->section($LANG->getLL('language').':',$code,0,1);
329 // 'Startup' section:
332 $code[2][1] = $this->setLabel('condensedMode','condensedMode');
333 $code[2][2] = '<input type="checkbox" name="data[condensedMode]"'.($BE_USER->uc
['condensedMode']?
' checked="checked"':'').' />';
334 $code[3][1] = $this->setLabel('noMenuMode','noMenuMode');
335 $code[3][2] = '<select name="data[noMenuMode]">
336 <option value=""'.(!$BE_USER->uc
['noMenuMode']?
' selected="selected"':'').'>'.$this->setLabel('noMenuMode_def').'</option>
337 <option value="1"'.($BE_USER->uc
['noMenuMode'] && (string)$BE_USER->uc
['noMenuMode']!="icons"?
' selected="selected"':'').'>'.$this->setLabel('noMenuMode_sel').'</option>
338 <option value="icons"'.((string)$BE_USER->uc
['noMenuMode']=='icons'?
' selected="selected"':'').'>'.$this->setLabel('noMenuMode_icons').'</option>
340 $code[4][1] = $this->setLabel('startModule','startModule');
341 $modSelect = '<select name="data[startModule]">';
342 $modSelect .= '<option value=""></option>';
343 if (empty($BE_USER->uc
['startModule'])) {
344 $BE_USER->uc
['startModule'] = $BE_USER->uc_default
['startModule'];
346 foreach ($this->loadModules
->modules
as $mainMod => $modData) {
347 if (isset($modData['sub']) && is_array($modData['sub'])) {
348 $modSelect .= '<option disabled="disabled">'.$LANG->moduleLabels
['tabs'][$mainMod.'_tab'].'</option>';
349 foreach ($modData['sub'] as $subKey => $subData) {
350 $modName = $subData['name'];
351 $modSelect .= '<option value="'.$modName.'"'.($BE_USER->uc
['startModule']==$modName?
' selected="selected"':'').'>';
352 $modSelect .= ' - '.$LANG->moduleLabels
['tabs'][$modName.'_tab'].'</option>';
356 $modSelect .= '</select>';
357 $code[4][2] = $modSelect;
359 $code[5][1] = $this->setLabel('showThumbs','thumbnailsByDefault');
360 $code[5][2] = '<input type="checkbox" name="data[thumbnailsByDefault]"'.($BE_USER->uc
['thumbnailsByDefault']?
' checked="checked"':'').' />';
361 $code[6][1] = $this->setLabel('helpText');
362 $code[6][2] = '<input type="checkbox" name="data[helpText]"'.($BE_USER->uc
['helpText']?
' checked="checked"':'').' />';
363 $code[7][1] = $this->setLabel('maxTitleLen','titleLen');
364 $code[7][2] = '<input type="text" name="data[titleLen]" value="'.$BE_USER->uc
['titleLen'].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' maxlength="5" />';
366 $this->content
.=$this->doc
->section($LANG->getLL('opening').':',$this->doc
->table($code),0,1);
369 // Advanced Operations:
371 $code[1][1] = $this->setLabel('copyLevels');
372 $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');
373 $code[2][1] = $this->setLabel('recursiveDelete');
374 $code[2][2] = '<input type="checkbox" name="data[recursiveDelete]"'.($BE_USER->uc
['recursiveDelete']?
' checked="checked"':'').' />';
376 $this->content
.=$this->doc
->section($LANG->getLL('functions').":",$this->doc
->table($code),0,1);
381 $code[2][1] = $this->setLabel('edit_wideDocument');
382 $code[2][2] = '<input type="checkbox" name="data[edit_wideDocument]"'.($BE_USER->uc
['edit_wideDocument']?
' checked="checked"':'').' />';
383 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
384 $code[3][1] = $this->setLabel('edit_RTE');
385 $code[3][2] = '<input type="checkbox" name="data[edit_RTE]"'.($BE_USER->uc
['edit_RTE']?
' checked="checked"':'').' />';
387 $code[4][1] = $this->setLabel('edit_docModuleUpload');
388 $code[4][2] = '<input type="checkbox" name="data[edit_docModuleUpload]"'.($BE_USER->uc
['edit_docModuleUpload']?
' checked="checked"':'').' />';
390 $code[6][1] = $this->setLabel('edit_showFieldHelp');
391 $code[6][2] = '<select name="data[edit_showFieldHelp]">
392 <option value=""></option>
393 <option value="icon"'.($BE_USER->uc
['edit_showFieldHelp']=='icon'?
' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_icon').'</option>
394 <option value="text"'.($BE_USER->uc
['edit_showFieldHelp']=='text'?
' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_message').'</option>
397 $code[7][1] = $this->setLabel('disableCMlayers');
398 $code[7][2] = '<input type="checkbox" name="data[disableCMlayers]"'.($BE_USER->uc
['disableCMlayers']?
' checked="checked"':'').' />';
400 $this->content
.=$this->doc
->section($LANG->getLL('edit_functions').":",$this->doc
->table($code),0,1);
405 $code[1][1] = $this->setLabel('beUser_realName');
406 $code[1][2] = '<input type="text" name="ext_beuser[realName]" value="'.htmlspecialchars($BE_USER->user
['realName']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
407 $code[2][1] = $this->setLabel('beUser_email');
408 $code[2][2] = '<input type="text" name="ext_beuser[email]" value="'.htmlspecialchars($BE_USER->user
['email']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
409 $code[3][1] = $this->setLabel('emailMeAtLogin').' ('.$GLOBALS['BE_USER']->user
['email'].')';
410 $code[3][2] = '<input type="checkbox" name="data[emailMeAtLogin]"'.($BE_USER->uc
['emailMeAtLogin']?
' checked="checked"':'').' />';
411 $code[4][1] = $this->setLabel('newPassword');
412 $code[4][2] = '<input type="password" name="ext_beuser[password1]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\';" />';
413 $code[5][1] = $this->setLabel('newPasswordAgain');
414 $code[5][2] = '<input type="password" name="ext_beuser[password2]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\'" />';
416 $this->content
.=$this->doc
->section($LANG->getLL('personal_data').":",$this->doc
->table($code),0,1);
420 $this->content
.=$this->doc
->spacer(20);
421 $this->content
.=$this->doc
->section('','
422 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
423 <label for="setValuesToDefault"><b>'.$LANG->getLL('setToStandard').':</b></label> <input type="checkbox" name="data[setValuesToDefault]" id="setValuesToDefault" />'.
424 t3lib_BEfunc
::cshItem('_MOD_user_setup', 'reset', $GLOBALS['BACK_PATH'],'|').'
425 <input type="hidden" name="simUser" value="'.$this->simUser
.'" />');
429 $this->content
.=$this->doc
->spacer(5);
430 $this->content
.=$this->doc
->section('',$LANG->getLL('activateChanges'));
434 * Prints the content / ends page
438 function printContent() {
439 $this->content
.= $this->doc
->endPage();
455 /******************************
459 ******************************/
462 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
463 * Anyway: The REAL user is returned - the one logged in.
465 * @return object The REAL user is returned - the one logged in.
467 function getRealScriptUserObj() {
468 return is_object($this->OLD_BE_USER
) ?
$this->OLD_BE_USER
: $GLOBALS['BE_USER'];
472 * Will make the simulate-user selector if the logged in user is administrator.
473 * 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)
477 function simulateUser() {
478 global $BE_USER,$LANG,$BACK_PATH;
480 // *******************************************************************************
481 // If admin, allow simulation of another user
482 // *******************************************************************************
484 $this->simulateSelector
= '';
485 unset($this->OLD_BE_USER
);
486 if ($BE_USER->isAdmin()) {
487 $this->simUser
= t3lib_div
::_GP('simUser');
489 // Make user-selector:
490 $users = t3lib_BEfunc
::getUserNames('username,usergroup,usergroup_cached_list,uid,realName');
493 $opt[] = '<option></option>';
494 while(list(,$rr)=each($users)) {
495 if ($rr['uid']!=$BE_USER->user
['uid']) {
496 $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser
==$rr['uid']?
' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
499 $this->simulateSelector
= '<select name="simulateUser" onchange="window.location.href=\'index.php?simUser=\'+this.options[this.selectedIndex].value;">'.implode('',$opt).'</select>';
502 if ($this->simUser
>0) { // This can only be set if the previous code was executed.
503 $this->OLD_BE_USER
= $BE_USER; // Save old user...
504 unset($BE_USER); // Unset current
506 $BE_USER = t3lib_div
::makeInstance('t3lib_beUserAuth'); // New backend user object
507 $BE_USER->OS
= TYPO3_OS
;
508 $BE_USER->setBeUserByUid($this->simUser
);
509 $BE_USER->fetchGroupData();
510 $BE_USER->backendSetUC();
511 $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
516 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
517 * Adds CSH as well if applicable.
519 * @param string Locallang key
520 * @param string Alternative override-config key
521 * @return string HTML output.
523 function setLabel($str,$key='') {
524 $out = $GLOBALS['LANG']->getLL($str);
525 if (isset($this->overrideConf
[($key?
$key:$str)])) {
526 $out = '<span style="color:#999999">'.$out.'</span>';
530 $csh = t3lib_BEfunc
::cshItem('_MOD_user_setup', 'option_'.$str, $GLOBALS['BACK_PATH'],'|',FALSE,'margin-bottom:0px;');
531 if (strlen($csh)) $csh = ': '.$csh;
538 // Include extension?
539 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/setup/mod/index.php']) {
540 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['ext/setup/mod/index.php']);
555 $SOBE = t3lib_div
::makeInstance('SC_mod_user_setup_index');
556 $SOBE->simulateUser();
557 $SOBE->storeIncomingData();
559 // These includes MUST be afterwards the settings are saved...!
560 require ($BACK_PATH.'template.php');
561 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
565 $SOBE->printContent();