More CSH related stuff
[Packages/TYPO3.CMS.git] / typo3 / sysext / setup / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
33 * Revised for TYPO3 3.7 6/2004 by Kasper Skårhøj
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 * 215: function init()
48 * 247: function main()
49 * 392: function printContent()
50 *
51 * SECTION: Helper functions
52 * 421: function getRealScriptUserObj()
53 * 431: function simulateUser()
54 * 477: 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 <kasper@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;
187 $tce->process_datamap();
188 unset($tce);
189 }
190 }
191 }
192
193
194
195
196
197
198
199
200
201
202
203
204 /******************************
205 *
206 * Rendering module
207 *
208 ******************************/
209
210 /**
211 * Initializes the module for display of the settings form.
212 *
213 * @return void
214 */
215 function init() {
216 global $BE_USER,$BACK_PATH;
217 $this->MCONF = $GLOBALS['MCONF'];
218
219 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
220 $scriptUser = $this->getRealScriptUserObj();
221 $scriptUser->modAccess($this->MCONF,1); // ... and checking module access for the logged in user.
222
223 // Getting the 'override' values as set might be set in User TSconfig
224 $this->overrideConf = $BE_USER->getTSConfigProp('setup.override');
225
226 // Create instance of object for output of data
227 $this->doc = t3lib_div::makeInstance('mediumDoc');
228 $this->doc->backPath = $BACK_PATH;
229 $this->doc->docType = 'xhtml_trans';
230
231 $this->doc->form = '<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">';
232 $this->doc->tableLayout = Array (
233 'defRow' => Array (
234 '0' => Array('<td align="left" width="300">','</td>'),
235 'defCol' => Array('<td valign="top">','</td>')
236 )
237 );
238 $this->doc->table_TR = '<tr class="bgColor4">';
239 $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2">';
240 }
241
242 /**
243 * Generate the main settings formular:
244 *
245 * @return void
246 */
247 function main() {
248 global $BE_USER,$LANG,$BACK_PATH;
249
250 // Start page:
251 $this->doc->JScode.= '<script language="javascript" type="text/javascript" src="'.$BACK_PATH.'md5.js"></script>';
252 $this->content.= $this->doc->startPage($LANG->getLL('UserSettings'));
253 $this->content.= $this->doc->header($LANG->getLL('UserSettings').' - ['.$BE_USER->user['username'].']');
254
255 // CSH general:
256 $this->content.= t3lib_BEfunc::cshItem('_MOD_user_setup', '', $GLOBALS['BACK_PATH'],'|');
257
258 // If password is updated, output whether it failed or was OK.
259 if ($this->PASSWORD_UPDATED) {
260 if ($this->PASSWORD_UPDATED>0) {
261 $this->content.=$this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_ok'),1,0,1);
262 } else {
263 $this->content.=$this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_failed'),1,0,2);
264 }
265 $this->content.=$this->doc->spacer(25);
266 }
267
268 // Simulate selector box:
269 if ($this->simulateSelector) {
270 $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));
271 }
272
273
274 // Languages:
275 $opt = array();
276 $opt['000000000']='
277 <option value="">'.$LANG->getLL('lang_default',1).'</option>';
278 $theLanguages = t3lib_div::trimExplode('|',TYPO3_languages);
279
280 // Character set conversion object:
281 $csConvObj = t3lib_div::makeInstance('t3lib_cs');
282
283 // traverse the number of languages:
284 foreach($theLanguages as $val) {
285 if ($val!='default') {
286 if ($BE_USER->uc['lang']!='default') {
287 $localLabel = ' - ['.htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_'.$val]).']';
288 } else $localLabel='';
289
290 $opt[$GLOBALS['LOCAL_LANG']['default']['lang_'.$val].'--'.$val]='
291 <option value="'.$val.'"'.($BE_USER->uc['lang']==$val?' selected="selected"':'').'>'.$LANG->getLL('lang_'.$val,1).$localLabel.'</option>';
292 }
293 }
294 ksort($opt);
295 $code='
296 <select name="data[lang]">'.
297 implode('',$opt).'
298 </select>'.
299 t3lib_BEfunc::cshItem('_MOD_user_setup', 'language', $GLOBALS['BACK_PATH'],'|');
300 $this->content.=$this->doc->section($LANG->getLL('language').':',$code,0,1);
301
302
303 // 'Startup' section:
304 $code = Array();
305
306 $code[2][1] = $this->setLabel('condensedMode','condensedMode').':';
307 $code[2][2] = '<input type="checkbox" name="data[condensedMode]"'.($BE_USER->uc['condensedMode']?' checked="checked"':'').' />';
308 $code[3][1] = $this->setLabel('noMenuMode','noMenuMode').':';
309 $code[3][2] = '<select name="data[noMenuMode]">
310 <option value=""'.(!$BE_USER->uc['noMenuMode']?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_def').'</option>
311 <option value="1"'.($BE_USER->uc['noMenuMode'] && (string)$BE_USER->uc['noMenuMode']!="icons"?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_sel').'</option>
312 <option value="icons"'.((string)$BE_USER->uc['noMenuMode']=='icons'?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_icons').'</option>
313 </select>';
314 if (t3lib_extMgm::isLoaded('taskcenter')) {
315 $code[4][1] = $this->setLabel('startInTaskCenter','startInTaskCenter').':';
316 $code[4][2] = '<input type="checkbox" name="data[startInTaskCenter]"'.($BE_USER->uc['startInTaskCenter']?' checked="checked"':'').' />';
317 }
318 $code[5][1] = $this->setLabel('showThumbs','thumbnailsByDefault').':';
319 $code[5][2] = '<input type="checkbox" name="data[thumbnailsByDefault]"'.($BE_USER->uc['thumbnailsByDefault']?' checked="checked"':'').' />';
320 $code[6][1] = $this->setLabel('helpText').':';
321 $code[6][2] = '<input type="checkbox" name="data[helpText]"'.($BE_USER->uc['helpText']?' checked="checked"':'').' />';
322 $code[7][1] = $this->setLabel('maxTitleLen','titleLen').':';
323 $code[7][2] = '<input type="text" name="data[titleLen]" value="'.$BE_USER->uc['titleLen'].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' maxlength="5" />';
324
325 $this->content.=$this->doc->section($LANG->getLL('opening').':',$this->doc->table($code),0,1);
326
327
328 // Advanced Operations:
329 $code = Array();
330 $code[1][1] = $this->setLabel('copyLevels').':';
331 $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');
332 $code[2][1] = $this->setLabel('recursiveDelete').':';
333 $code[2][2] = '<input type="checkbox" name="data[recursiveDelete]"'.($BE_USER->uc['recursiveDelete']?' checked="checked"':'').' />';
334
335 $this->content.=$this->doc->section($LANG->getLL('functions').":",$this->doc->table($code),0,1);
336
337
338 // Edit
339 $code = Array();
340 $code[2][1] = $this->setLabel('edit_wideDocument').':';
341 $code[2][2] = '<input type="checkbox" name="data[edit_wideDocument]"'.($BE_USER->uc['edit_wideDocument']?' checked="checked"':'').' />';
342 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
343 $code[3][1] = $this->setLabel('edit_RTE').':';
344 $code[3][2] = '<input type="checkbox" name="data[edit_RTE]"'.($BE_USER->uc['edit_RTE']?' checked="checked"':'').' />';
345 }
346 $code[4][1] = $this->setLabel('edit_docModuleUpload').':';
347 $code[4][2] = '<input type="checkbox" name="data[edit_docModuleUpload]"'.($BE_USER->uc['edit_docModuleUpload']?' checked="checked"':'').' />';
348
349 $code[6][1] = $this->setLabel('edit_showFieldHelp').':';
350 $code[6][2] = '<select name="data[edit_showFieldHelp]">
351 <option value=""></option>
352 <option value="icon"'.($BE_USER->uc['edit_showFieldHelp']=='icon'?' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_icon').'</option>
353 <option value="text"'.($BE_USER->uc['edit_showFieldHelp']=='text'?' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_message').'</option>
354 </select>';
355
356 $code[7][1] = $this->setLabel('disableCMlayers').':';
357 $code[7][2] = '<input type="checkbox" name="data[disableCMlayers]"'.($BE_USER->uc['disableCMlayers']?' checked="checked"':'').' />';
358
359 $this->content.=$this->doc->section($LANG->getLL('edit_functions').":",$this->doc->table($code),0,1);
360
361
362 // Personal data
363 $code = Array();
364 $code[1][1] = $this->setLabel('beUser_realName').':';
365 $code[1][2] = '<input type="text" name="ext_beuser[realName]" value="'.htmlspecialchars($BE_USER->user['realName']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
366 $code[2][1] = $this->setLabel('beUser_email').':';
367 $code[2][2] = '<input type="text" name="ext_beuser[email]" value="'.htmlspecialchars($BE_USER->user['email']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
368 $code[3][1] = $this->setLabel('emailMeAtLogin').' ('.$GLOBALS['BE_USER']->user['email'].'):';
369 $code[3][2] = '<input type="checkbox" name="data[emailMeAtLogin]"'.($BE_USER->uc['emailMeAtLogin']?' checked="checked"':'').' />';
370 $code[4][1] = $this->setLabel('newPassword').':';
371 $code[4][2] = '<input type="password" name="ext_beuser[password1]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\';" />';
372 $code[5][1] = $this->setLabel('newPasswordAgain').':';
373 $code[5][2] = '<input type="password" name="ext_beuser[password2]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\'" />';
374
375 $this->content.=$this->doc->section($LANG->getLL('personal_data').":",$this->doc->table($code),0,1);
376
377
378 // Submit:
379 $this->content.=$this->doc->spacer(20);
380 $this->content.=$this->doc->section('','
381 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
382 &nbsp; <b>'.$LANG->getLL('setToStandard').': </b><input type="checkbox" name="data[setValuesToDefault]" />'.
383 t3lib_BEfunc::cshItem('_MOD_user_setup', 'reset', $GLOBALS['BACK_PATH'],'|').'
384 <input type="hidden" name="simUser" value="'.$this->simUser.'" />');
385
386
387 // Notice
388 $this->content.=$this->doc->spacer(5);
389 $this->content.=$this->doc->section('',$LANG->getLL('activateChanges'));
390 }
391
392 /**
393 * Prints the content / ends page
394 *
395 * @return void
396 */
397 function printContent() {
398 $this->content.= $this->doc->endPage();
399 echo $this->content;
400 exit;
401 }
402
403
404
405
406
407
408
409
410
411
412
413
414 /******************************
415 *
416 * Helper functions
417 *
418 ******************************/
419
420 /**
421 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
422 * Anyway: The REAL user is returned - the one logged in.
423 *
424 * @return object The REAL user is returned - the one logged in.
425 */
426 function getRealScriptUserObj() {
427 return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
428 }
429
430 /**
431 * Will make the simulate-user selector if the logged in user is administrator.
432 * 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)
433 *
434 * @return void
435 */
436 function simulateUser() {
437 global $BE_USER,$LANG,$BACK_PATH;
438
439 // *******************************************************************************
440 // If admin, allow simulation of another user
441 // *******************************************************************************
442 $this->simUser = 0;
443 $this->simulateSelector = '';
444 unset($this->OLD_BE_USER);
445 if ($BE_USER->isAdmin()) {
446 $this->simUser = t3lib_div::_GP('simUser');
447
448 // Make user-selector:
449 $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName');
450 $opt = array();
451 reset($users);
452 $opt[] = '<option></option>';
453 while(list(,$rr)=each($users)) {
454 if ($rr['uid']!=$BE_USER->user['uid']) {
455 $opt[] = '<option value="'.$rr['uid'].'"'.($this->simUser==$rr['uid']?' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
456 }
457 }
458 $this->simulateSelector = '<select name="simulateUser" onchange="document.location=\'index.php?simUser=\'+this.options[this.selectedIndex].value;">'.implode('',$opt).'</select>';
459 }
460
461 if ($this->simUser>0) { // This can only be set if the previous code was executed.
462 $this->OLD_BE_USER = $BE_USER; // Save old user...
463 unset($BE_USER); // Unset current
464
465 $BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth'); // New backend user object
466 $BE_USER->OS = TYPO3_OS;
467 $BE_USER->setBeUserByUid($this->simUser);
468 $BE_USER->fetchGroupData();
469 $BE_USER->backendSetUC();
470 $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
471 }
472 }
473
474 /**
475 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
476 * Adds CSH as well if applicable.
477 *
478 * @param string Locallang key
479 * @param string Alternative override-config key
480 * @return string HTML output.
481 */
482 function setLabel($str,$key='') {
483 $out = $GLOBALS['LANG']->getLL($str);
484 if (isset($this->overrideConf[($key?$key:$str)])) {
485 $out = '<span style="color:#999999">'.$out.'</span>';
486 }
487
488 // CSH:
489 $out.= t3lib_BEfunc::cshItem('_MOD_user_setup', 'option_'.$str, $GLOBALS['BACK_PATH'],'|',FALSE,'margin-bottom:0px;');
490
491 // Return value:
492 return $out;
493 }
494 }
495
496 // Include extension?
497 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']) {
498 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']);
499 }
500
501
502
503
504
505
506
507
508
509
510
511
512 // Make instance:
513 $SOBE = t3lib_div::makeInstance('SC_mod_user_setup_index');
514 $SOBE->simulateUser();
515 $SOBE->storeIncomingData();
516
517 // These includes MUST be afterwards the settings are saved...!
518 require ($BACK_PATH.'template.php');
519 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
520
521 $SOBE->init();
522 $SOBE->main();
523 $SOBE->printContent();
524 ?>