* Fixed bug #3729: Roll-over (RO) on a GMENU in IE didn't work with xhtml_strict
[Packages/TYPO3.CMS.git] / typo3 / sysext / setup / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (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 Skaarhoj <kasperYYYY@typo3.com>
33 * Revised for TYPO3 3.7 6/2004 by Kasper Skaarhoj
34 * XHTML compatible.
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 86: class SC_mod_user_setup_index
42 *
43 * SECTION: Saving data
44 * 114: function storeIncomingData()
45 *
46 * SECTION: Rendering module
47 * 216: function init()
48 * 248: function main()
49 * 403: function printContent()
50 *
51 * SECTION: Helper functions
52 * 432: function getRealScriptUserObj()
53 * 442: function simulateUser()
54 * 488: function setLabel($str,$key='')
55 *
56 * TOTAL FUNCTIONS: 7
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61 unset($MCONF);
62 require('conf.php');
63 require($BACK_PATH.'init.php');
64 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 /**
80 * Script class for the Setup module
81 *
82 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
83 * @package TYPO3
84 * @subpackage tx_setup
85 */
86 class SC_mod_user_setup_index {
87
88 // Internal variables:
89 var $MCONF = array();
90 var $MOD_MENU = array();
91 var $MOD_SETTINGS = array();
92 var $doc;
93
94 var $content;
95 var $overrideConf;
96 var $OLD_BE_USER;
97
98
99
100
101
102 /******************************
103 *
104 * Saving data
105 *
106 ******************************/
107
108 /**
109 * If settings are submitted to _POST[DATA], store them
110 * NOTICE: This method is called before the template.php is included. See buttom of document
111 *
112 * @return void
113 */
114 function storeIncomingData() {
115 global $BE_USER;
116
117
118 // First check if something is submittet in the data-array from POST vars
119 $d = t3lib_div::_POST('data');
120 if (is_array($d)) {
121
122 // UC hashed before applying changes
123 $save_before = md5(serialize($BE_USER->uc));
124
125 // PUT SETTINGS into the ->uc array:
126
127 // Language
128 $BE_USER->uc['lang'] = $d['lang'];
129
130 // Startup
131 $BE_USER->uc['condensedMode'] = $d['condensedMode'];
132 $BE_USER->uc['noMenuMode'] = $d['noMenuMode'];
133 if (t3lib_extMgm::isLoaded('taskcenter')) $BE_USER->uc['startInTaskCenter'] = $d['startInTaskCenter'];
134 $BE_USER->uc['thumbnailsByDefault'] = $d['thumbnailsByDefault'];
135 $BE_USER->uc['helpText'] = $d['helpText'];
136 $BE_USER->uc['titleLen'] = intval($d['titleLen']);
137
138 // Advanced functions:
139 $BE_USER->uc['copyLevels'] = t3lib_div::intInRange($d['copyLevels'],0,100);
140 $BE_USER->uc['recursiveDelete'] = $d['recursiveDelete'];
141
142 // Edit
143 $BE_USER->uc['edit_wideDocument'] = $d['edit_wideDocument'];
144 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) { $BE_USER->uc['edit_RTE'] = $d['edit_RTE']; }
145 $BE_USER->uc['edit_docModuleUpload'] = $d['edit_docModuleUpload'];
146 $BE_USER->uc['edit_showFieldHelp'] = $d['edit_showFieldHelp'];
147 $BE_USER->uc['disableCMlayers'] = $d['disableCMlayers'];
148
149 // Personal:
150 $BE_USER->uc['emailMeAtLogin'] = $d['emailMeAtLogin'];
151
152
153 if ($d['setValuesToDefault']) { // If every value should be default
154 $BE_USER->resetUC();
155 }
156 $BE_USER->overrideUC(); // Inserts the overriding values.
157
158 $save_after = md5(serialize($BE_USER->uc));
159 if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
160 $BE_USER->writeUC($BE_USER->uc);
161 $BE_USER->writelog(254,1,0,1,'Personal settings changed',Array());
162 }
163
164
165 // Personal data for the users be_user-record (email, name, password...)
166 // If email and name is changed, set it in the users record:
167 $be_user_data = t3lib_div::_GP('ext_beuser');
168 $this->PASSWORD_UPDATED = strlen($be_user_data['password1'].$be_user_data['password2'])>0 ? -1 : 0;
169 if ($be_user_data['email']!=$BE_USER->user['email']
170 || $be_user_data['realName']!=$BE_USER->user['realName']
171 || (strlen($be_user_data['password1'])==32
172 && !strcmp($be_user_data['password1'],$be_user_data['password2']))
173 ) {
174 $storeRec = array();
175 $BE_USER->user['realName'] = $storeRec['be_users'][$BE_USER->user['uid']]['realName'] = substr($be_user_data['realName'],0,80);
176 $BE_USER->user['email'] = $storeRec['be_users'][$BE_USER->user['uid']]['email'] = substr($be_user_data['email'],0,80);
177 if (strlen($be_user_data['password1'])==32 && !strcmp($be_user_data['password1'],$be_user_data['password2'])) {
178 $BE_USER->user['password'] = $storeRec['be_users'][$BE_USER->user['uid']]['password'] = $be_user_data['password1'];
179 $this->PASSWORD_UPDATED = 1;
180 }
181
182 // Make instance of TCE for storing the changes.
183 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
184 $tce->stripslashes_values=0;
185 $tce->start($storeRec,Array(),$BE_USER);
186 $tce->admin = 1; // This is so the user can actually update his user record.
187 $tce->bypassWorkspaceRestrictions = TRUE; // This is to make sure that the users record can be updated even if in another workspace. This is tolerated.
188 $tce->process_datamap();
189 unset($tce);
190 }
191 }
192 }
193
194
195
196
197
198
199
200
201
202
203
204
205 /******************************
206 *
207 * Rendering module
208 *
209 ******************************/
210
211 /**
212 * Initializes the module for display of the settings form.
213 *
214 * @return void
215 */
216 function init() {
217 global $BE_USER,$BACK_PATH;
218 $this->MCONF = $GLOBALS['MCONF'];
219
220 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
221 $scriptUser = $this->getRealScriptUserObj();
222 $scriptUser->modAccess($this->MCONF,1); // ... and checking module access for the logged in user.
223
224 // Getting the 'override' values as set might be set in User TSconfig
225 $this->overrideConf = $BE_USER->getTSConfigProp('setup.override');
226
227 // Create instance of object for output of data
228 $this->doc = t3lib_div::makeInstance('mediumDoc');
229 $this->doc->backPath = $BACK_PATH;
230 $this->doc->docType = 'xhtml_trans';
231
232 $this->doc->form = '<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">';
233 $this->doc->tableLayout = Array (
234 'defRow' => Array (
235 '0' => Array('<td align="left" width="300">','</td>'),
236 'defCol' => Array('<td valign="top">','</td>')
237 )
238 );
239 $this->doc->table_TR = '<tr class="bgColor4">';
240 $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2">';
241 }
242
243 /**
244 * Generate the main settings formular:
245 *
246 * @return void
247 */
248 function main() {
249 global $BE_USER,$LANG,$BACK_PATH;
250
251 // Start page:
252 $this->doc->JScode.= '<script language="javascript" type="text/javascript" src="'.$BACK_PATH.'md5.js"></script>';
253 $this->content.= $this->doc->startPage($LANG->getLL('UserSettings'));
254 $this->content.= $this->doc->header($LANG->getLL('UserSettings').' - ['.$BE_USER->user['username'].']');
255
256 // CSH general:
257 $this->content.= t3lib_BEfunc::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'],'|');
258
259 // If password is updated, output whether it failed or was OK.
260 if ($this->PASSWORD_UPDATED) {
261 if ($this->PASSWORD_UPDATED>0) {
262 $this->content.=$this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_ok'),1,0,1);
263 } else {
264 $this->content.=$this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_failed'),1,0,2);
265 }
266 $this->content.=$this->doc->spacer(25);
267 }
268
269 // Simulate selector box:
270 if ($this->simulateSelector) {
271 $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));
272 }
273
274
275 // Languages:
276 $opt = array();
277 $opt['000000000']='
278 <option value="">'.$LANG->getLL('lang_default',1).'</option>';
279 $theLanguages = t3lib_div::trimExplode('|',TYPO3_languages);
280
281 // Character set conversion object:
282 $csConvObj = t3lib_div::makeInstance('t3lib_cs');
283
284 // traverse the number of languages:
285 foreach($theLanguages as $val) {
286 if ($val!='default') {
287 $localLabel = ' - ['.htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_'.$val]).']';
288 $unavailable = $val!='default' && !@is_dir(PATH_typo3conf.'l10n/'.$val) ? '1' : '';
289 $opt[$GLOBALS['LOCAL_LANG']['default']['lang_'.$val].'--'.$val]='
290 <option value="'.$val.'"'.($BE_USER->uc['lang']==$val?' selected="selected"':'').($unavailable ? ' class="c-na"' : '').'>'.$LANG->getLL('lang_'.$val,1).$localLabel.'</option>';
291 }
292 }
293 ksort($opt);
294 $code='
295 <select name="data[lang]">'.
296 implode('',$opt).'
297 </select>'.
298 t3lib_BEfunc::cshItem('_MOD_user_setup', 'language', $GLOBALS['BACK_PATH'],'|');
299 if ($BE_USER->uc['lang'] && !@is_dir(PATH_typo3conf.'l10n/'.$BE_USER->uc['lang'])) {
300 $code.= '<table border="0" cellpadding="0" cellspacing="0" class="warningbox"><tr><td>'.
301 $this->doc->icons(3).
302 'The selected language is not available before the language pack is installed.<br />'.
303 ($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.').
304 '</td></tr></table>';
305 }
306 $this->content.=$this->doc->section($LANG->getLL('language').':',$code,0,1);
307
308
309 // 'Startup' section:
310 $code = Array();
311
312 $code[2][1] = $this->setLabel('condensedMode','condensedMode');
313 $code[2][2] = '<input type="checkbox" name="data[condensedMode]"'.($BE_USER->uc['condensedMode']?' checked="checked"':'').' />';
314 $code[3][1] = $this->setLabel('noMenuMode','noMenuMode');
315 $code[3][2] = '<select name="data[noMenuMode]">
316 <option value=""'.(!$BE_USER->uc['noMenuMode']?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_def').'</option>
317 <option value="1"'.($BE_USER->uc['noMenuMode'] && (string)$BE_USER->uc['noMenuMode']!="icons"?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_sel').'</option>
318 <option value="icons"'.((string)$BE_USER->uc['noMenuMode']=='icons'?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_icons').'</option>
319 </select>';
320 if (t3lib_extMgm::isLoaded('taskcenter')) {
321 $code[4][1] = $this->setLabel('startInTaskCenter','startInTaskCenter');
322 $code[4][2] = '<input type="checkbox" name="data[startInTaskCenter]"'.($BE_USER->uc['startInTaskCenter']?' checked="checked"':'').' />';
323 }
324 $code[5][1] = $this->setLabel('showThumbs','thumbnailsByDefault');
325 $code[5][2] = '<input type="checkbox" name="data[thumbnailsByDefault]"'.($BE_USER->uc['thumbnailsByDefault']?' checked="checked"':'').' />';
326 $code[6][1] = $this->setLabel('helpText');
327 $code[6][2] = '<input type="checkbox" name="data[helpText]"'.($BE_USER->uc['helpText']?' checked="checked"':'').' />';
328 $code[7][1] = $this->setLabel('maxTitleLen','titleLen');
329 $code[7][2] = '<input type="text" name="data[titleLen]" value="'.$BE_USER->uc['titleLen'].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' maxlength="5" />';
330
331 $this->content.=$this->doc->section($LANG->getLL('opening').':',$this->doc->table($code),0,1);
332
333
334 // Advanced Operations:
335 $code = Array();
336 $code[1][1] = $this->setLabel('copyLevels');
337 $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');
338 $code[2][1] = $this->setLabel('recursiveDelete');
339 $code[2][2] = '<input type="checkbox" name="data[recursiveDelete]"'.($BE_USER->uc['recursiveDelete']?' checked="checked"':'').' />';
340
341 $this->content.=$this->doc->section($LANG->getLL('functions').":",$this->doc->table($code),0,1);
342
343
344 // Edit
345 $code = Array();
346 $code[2][1] = $this->setLabel('edit_wideDocument');
347 $code[2][2] = '<input type="checkbox" name="data[edit_wideDocument]"'.($BE_USER->uc['edit_wideDocument']?' checked="checked"':'').' />';
348 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
349 $code[3][1] = $this->setLabel('edit_RTE');
350 $code[3][2] = '<input type="checkbox" name="data[edit_RTE]"'.($BE_USER->uc['edit_RTE']?' checked="checked"':'').' />';
351 }
352 $code[4][1] = $this->setLabel('edit_docModuleUpload');
353 $code[4][2] = '<input type="checkbox" name="data[edit_docModuleUpload]"'.($BE_USER->uc['edit_docModuleUpload']?' checked="checked"':'').' />';
354
355 $code[6][1] = $this->setLabel('edit_showFieldHelp');
356 $code[6][2] = '<select name="data[edit_showFieldHelp]">
357 <option value=""></option>
358 <option value="icon"'.($BE_USER->uc['edit_showFieldHelp']=='icon'?' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_icon').'</option>
359 <option value="text"'.($BE_USER->uc['edit_showFieldHelp']=='text'?' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_message').'</option>
360 </select>';
361
362 $code[7][1] = $this->setLabel('disableCMlayers');
363 $code[7][2] = '<input type="checkbox" name="data[disableCMlayers]"'.($BE_USER->uc['disableCMlayers']?' checked="checked"':'').' />';
364
365 $this->content.=$this->doc->section($LANG->getLL('edit_functions').":",$this->doc->table($code),0,1);
366
367
368 // Personal data
369 $code = Array();
370 $code[1][1] = $this->setLabel('beUser_realName');
371 $code[1][2] = '<input type="text" name="ext_beuser[realName]" value="'.htmlspecialchars($BE_USER->user['realName']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
372 $code[2][1] = $this->setLabel('beUser_email');
373 $code[2][2] = '<input type="text" name="ext_beuser[email]" value="'.htmlspecialchars($BE_USER->user['email']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
374 $code[3][1] = $this->setLabel('emailMeAtLogin').' ('.$GLOBALS['BE_USER']->user['email'].')';
375 $code[3][2] = '<input type="checkbox" name="data[emailMeAtLogin]"'.($BE_USER->uc['emailMeAtLogin']?' checked="checked"':'').' />';
376 $code[4][1] = $this->setLabel('newPassword');
377 $code[4][2] = '<input type="password" name="ext_beuser[password1]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\';" />';
378 $code[5][1] = $this->setLabel('newPasswordAgain');
379 $code[5][2] = '<input type="password" name="ext_beuser[password2]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\'" />';
380
381 $this->content.=$this->doc->section($LANG->getLL('personal_data').":",$this->doc->table($code),0,1);
382
383
384 // Submit:
385 $this->content.=$this->doc->spacer(20);
386 $this->content.=$this->doc->section('','
387 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
388 &nbsp; <label for="setValuesToDefault"><b>'.$LANG->getLL('setToStandard').':</b></label> <input type="checkbox" name="data[setValuesToDefault]" id="setValuesToDefault" />'.
389 t3lib_BEfunc::cshItem('_MOD_user_setup', 'reset', $GLOBALS['BACK_PATH'],'|').'
390 <input type="hidden" name="simUser" value="'.$this->simUser.'" />');
391
392
393 // Notice
394 $this->content.=$this->doc->spacer(5);
395 $this->content.=$this->doc->section('',$LANG->getLL('activateChanges'));
396 }
397
398 /**
399 * Prints the content / ends page
400 *
401 * @return void
402 */
403 function printContent() {
404 $this->content.= $this->doc->endPage();
405 echo $this->content;
406 exit;
407 }
408
409
410
411
412
413
414
415
416
417
418
419
420 /******************************
421 *
422 * Helper functions
423 *
424 ******************************/
425
426 /**
427 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
428 * Anyway: The REAL user is returned - the one logged in.
429 *
430 * @return object The REAL user is returned - the one logged in.
431 */
432 function getRealScriptUserObj() {
433 return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
434 }
435
436 /**
437 * Will make the simulate-user selector if the logged in user is administrator.
438 * 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)
439 *
440 * @return void
441 */
442 function simulateUser() {
443 global $BE_USER,$LANG,$BACK_PATH;
444
445 // *******************************************************************************
446 // If admin, allow simulation of another user
447 // *******************************************************************************
448 $this->simUser = 0;
449 $this->simulateSelector = '';
450 unset($this->OLD_BE_USER);
451 if ($BE_USER->isAdmin()) {
452 $this->simUser = t3lib_div::_GP('simUser');
453
454 // Make user-selector:
455 $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName');
456 $opt = array();
457 reset($users);
458 $opt[] = '<option></option>';
459 while(list(,$rr)=each($users)) {
460 if ($rr['uid']!=$BE_USER->user['uid']) {
461 $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser==$rr['uid']?' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
462 }
463 }
464 $this->simulateSelector = '<select name="simulateUser" onchange="window.location.href=\'index.php?simUser=\'+this.options[this.selectedIndex].value;">'.implode('',$opt).'</select>';
465 }
466
467 if ($this->simUser>0) { // This can only be set if the previous code was executed.
468 $this->OLD_BE_USER = $BE_USER; // Save old user...
469 unset($BE_USER); // Unset current
470
471 $BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth'); // New backend user object
472 $BE_USER->OS = TYPO3_OS;
473 $BE_USER->setBeUserByUid($this->simUser);
474 $BE_USER->fetchGroupData();
475 $BE_USER->backendSetUC();
476 $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
477 }
478 }
479
480 /**
481 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
482 * Adds CSH as well if applicable.
483 *
484 * @param string Locallang key
485 * @param string Alternative override-config key
486 * @return string HTML output.
487 */
488 function setLabel($str,$key='') {
489 $out = $GLOBALS['LANG']->getLL($str);
490 if (isset($this->overrideConf[($key?$key:$str)])) {
491 $out = '<span style="color:#999999">'.$out.'</span>';
492 }
493
494 // CSH:
495 $csh = t3lib_BEfunc::cshItem('_MOD_user_setup', 'option_'.$str, $GLOBALS['BACK_PATH'],'|',FALSE,'margin-bottom:0px;');
496 if (strlen($csh)) $csh = ': '.$csh;
497
498 // Return value:
499 return $out.$csh;
500 }
501 }
502
503 // Include extension?
504 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']) {
505 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']);
506 }
507
508
509
510
511
512
513
514
515
516
517
518
519 // Make instance:
520 $SOBE = t3lib_div::makeInstance('SC_mod_user_setup_index');
521 $SOBE->simulateUser();
522 $SOBE->storeIncomingData();
523
524 // These includes MUST be afterwards the settings are saved...!
525 require ($BACK_PATH.'template.php');
526 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
527
528 $SOBE->init();
529 $SOBE->main();
530 $SOBE->printContent();
531 ?>