More locallang-XML stuff. Also added feature to "php_tree_stop" so it exploits the...
[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.6 2/2003 by Kasper Skårhøj
34 * XHTML compatible.
35 */
36
37
38 unset($MCONF);
39 require('conf.php');
40 require($BACK_PATH.'init.php');
41 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
42
43
44 // ***************************
45 // Script Class
46 // ***************************
47 class SC_mod_user_setup_index {
48 var $MCONF=array();
49 var $MOD_MENU=array();
50 var $MOD_SETTINGS=array();
51 var $doc;
52
53 var $content;
54 var $overrideConf;
55 var $OLD_BE_USER;
56
57 /**
58 * If settings are submitted to _POST[DATA], store them
59 * NOTICE: This method is called before the template.php is included. See buttom of document
60 */
61 function storeIncomingData() {
62 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
63
64 // *******************************************************************************
65 // First check if something is submittet in the data-array from post vars
66 // *******************************************************************************
67 $d = t3lib_div::_POST('data');
68 if (is_array($d)) {
69
70 // UC hashed before applying changes
71 $save_before=md5(serialize($BE_USER->uc));
72
73
74 // PUT SETTINGS into the ->uc array
75 // Language
76 $BE_USER->uc['lang']=$d['lang'];
77 // Startup
78 $BE_USER->uc['condensedMode']=$d['condensedMode'];
79 $BE_USER->uc['noMenuMode']=$d['noMenuMode'];
80 if (t3lib_extMgm::isLoaded('taskcenter')) $BE_USER->uc['startInTaskCenter']=$d['startInTaskCenter'];
81 $BE_USER->uc['thumbnailsByDefault']=$d['thumbnailsByDefault'];
82 $BE_USER->uc['helpText']=$d['helpText'];
83 $BE_USER->uc['titleLen']=intval($d['titleLen']);
84 // Advanced functions:
85 $BE_USER->uc['copyLevels']=t3lib_div::intInRange($d['copyLevels'],0,100);
86 $BE_USER->uc['recursiveDelete']=$d['recursiveDelete'];
87 // Edit
88 $BE_USER->uc['edit_wideDocument']=$d['edit_wideDocument'];
89 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {$BE_USER->uc['edit_RTE']=$d['edit_RTE'];}
90 $BE_USER->uc['edit_docModuleUpload']=$d['edit_docModuleUpload'];
91 $BE_USER->uc['edit_showFieldHelp']=$d['edit_showFieldHelp'];
92 $BE_USER->uc['disableCMlayers']=$d['disableCMlayers'];
93 // Personal:
94 $BE_USER->uc['emailMeAtLogin']=$d['emailMeAtLogin'];
95
96
97 if ($d['setValuesToDefault']) { // If every value should be default
98 $BE_USER->resetUC();
99 }
100 $BE_USER->overrideUC(); // Inserts the overriding values.
101
102 $save_after=md5(serialize($BE_USER->uc));
103 if ($save_before!=$save_after) { // If something in the uc-array of the user has changed, we save the array...
104 $BE_USER->writeUC($BE_USER->uc);
105 $BE_USER->writelog(254,1,0,1,'Personal settings changed',Array());
106 }
107
108 // Personal data for the users be_user-record (email, name, password...)
109 // If email and name is changed, set it in the users record:
110 $be_user_data=t3lib_div::_GP('ext_beuser');
111 $this->PASSWORD_UPDATED=strlen($be_user_data['password1'].$be_user_data['password2'])>0 ? -1 : 0;
112 if ($be_user_data['email']!=$BE_USER->user['email']
113 || $be_user_data['realName']!=$BE_USER->user['realName']
114 || (strlen($be_user_data['password1'])==32
115 && !strcmp($be_user_data['password1'],$be_user_data['password2']))
116 ) {
117 $storeRec=array();
118 $BE_USER->user['realName'] = $storeRec['be_users'][$BE_USER->user['uid']]['realName'] = substr($be_user_data['realName'],0,80);
119 $BE_USER->user['email'] = $storeRec['be_users'][$BE_USER->user['uid']]['email'] = substr($be_user_data['email'],0,80);
120 if (strlen($be_user_data['password1'])==32 && !strcmp($be_user_data['password1'],$be_user_data['password2'])) {
121 $BE_USER->user['password'] = $storeRec['be_users'][$BE_USER->user['uid']]['password'] = $be_user_data['password1'];
122 $this->PASSWORD_UPDATED=1;
123 }
124 // Make instance of TCE for storing the changes.
125 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
126 $tce->stripslashes_values=0;
127 $tce->start($storeRec,Array(),$BE_USER);
128 $tce->admin=1;
129 $tce->process_datamap();
130 unset($tce);
131 }
132 }
133 }
134
135 /**
136 * Initializes the module for display of the settings form.
137 */
138 function init() {
139 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
140 $this->MCONF = $GLOBALS['MCONF'];
141
142 // Returns the script user - that is the REAL logged in user! ($GLOBALS[BE_USER] might be another user due to simulation!)
143 $scriptUser = $this->getRealScriptUserObj();
144 $scriptUser->modAccess($this->MCONF,1); // ... and checking module access for the logged in user.
145
146 // Getting the 'override' values as set might be set in User TSconfig
147 $this->overrideConf = $BE_USER->getTSConfigProp('setup.override');
148
149 // Create instance of object for output of data
150 $this->doc = t3lib_div::makeInstance('mediumDoc');
151 $this->doc->backPath = $BACK_PATH;
152 $this->doc->docType = "xhtml_trans";
153 # $this->doc->docType = "xhtml_strict";
154
155 $this->doc->form='<form action="index.php" method="post" enctype="application/x-www-form-urlencoded">';
156 $this->doc->tableLayout = Array (
157 'defRow' => Array (
158 '0' => Array('<td align="left" width="300">','</td>'),
159 'defCol' => Array('<td valign="top">','</td>')
160 )
161 );
162 $this->doc->table_TR = '<tr class="bgColor4">';
163 $this->doc->table_TABLE = '<table border="0" cellspacing="1" cellpadding="2">';
164 }
165
166 /**
167 * Generate the main settings formular:
168 */
169 function main() {
170 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
171
172 $this->doc->JScode.='<script language="javascript" type="text/javascript" src="'.$BACK_PATH.'md5.js"></script>';
173 $this->content.=$this->doc->startPage($LANG->getLL('UserSettings'));
174 $this->content.=$this->doc->header($LANG->getLL('UserSettings').' - ['.$BE_USER->user['username'].']');
175
176 // If password is updated, output whether it failed or was OK.
177 if ($this->PASSWORD_UPDATED) {
178 if ($this->PASSWORD_UPDATED>0) {
179 $this->content.=$this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_ok'),1,0,1);
180 } else {
181 $this->content.=$this->doc->section($LANG->getLL('newPassword').':',$LANG->getLL('newPassword_failed'),1,0,2);
182 }
183 $this->content.=$this->doc->spacer(25);
184 }
185
186 // Simulate selector box:
187 if ($this->simulateSelector) {
188 $this->content.=$this->doc->section($LANG->getLL('simulate').':',$this->simulateSelector,1,0,($this->simUser?2:0));
189 }
190
191 // Languages:
192 $opt=array();
193 $opt['000000000']='
194 <option value="">'.$LANG->getLL('lang_default',1).'</option>';
195 $theLanguages=t3lib_div::trimExplode('|',TYPO3_languages);
196
197 // Character set conversion object:
198 $csConvObj = t3lib_div::makeInstance('t3lib_cs');
199
200 // traverse the number of languages:
201 foreach($theLanguages as $val) {
202 if ($val!='default') {
203 if ($BE_USER->uc['lang']!='default') {
204 $localLabel = ' - ['.htmlspecialchars($GLOBALS['LOCAL_LANG']['default']['lang_'.$val]).']';
205 } else $localLabel='';
206
207 $opt[$GLOBALS['LOCAL_LANG']['default']['lang_'.$val].'--'.$val]='
208 <option value="'.$val.'"'.($BE_USER->uc['lang']==$val?' selected="selected"':'').'>'.$LANG->getLL('lang_'.$val,1).$localLabel.'</option>';
209 }
210 }
211 ksort($opt);
212 $code='
213 <select name="data[lang]">'.
214 implode('',$opt).'
215 </select>';
216 $this->content.=$this->doc->section($LANG->getLL('language').':',$code,0,1);
217
218
219 // 'Startup' section:
220 $code = Array();
221
222 $code[2][1] = $this->setLabel('condensedMode','condensedMode').':';
223 $code[2][2] = '<input type="checkbox" name="data[condensedMode]"'.($BE_USER->uc['condensedMode']?' checked="checked"':'').' />';
224 $code[3][1] = $this->setLabel('noMenuMode','noMenuMode').':';
225 $code[3][2] = '<select name="data[noMenuMode]">
226 <option value=""'.(!$BE_USER->uc['noMenuMode']?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_def').'</option>
227 <option value="1"'.($BE_USER->uc['noMenuMode'] && (string)$BE_USER->uc['noMenuMode']!="icons"?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_sel').'</option>
228 <option value="icons"'.((string)$BE_USER->uc['noMenuMode']=='icons'?' selected="selected"':'').'>'.$this->setLabel('noMenuMode_icons').'</option>
229 </select>';
230 if (t3lib_extMgm::isLoaded('taskcenter')) {
231 $code[4][1] = $this->setLabel('startInTaskCenter','startInTaskCenter').':';
232 $code[4][2] = '<input type="checkbox" name="data[startInTaskCenter]"'.($BE_USER->uc['startInTaskCenter']?' checked="checked"':'').' />';
233 }
234 $code[5][1] = $this->setLabel('showThumbs','thumbnailsByDefault').':';
235 $code[5][2] = '<input type="checkbox" name="data[thumbnailsByDefault]"'.($BE_USER->uc['thumbnailsByDefault']?' checked="checked"':'').' />';
236 $code[6][1] = $this->setLabel('helpText').':';
237 $code[6][2] = '<input type="checkbox" name="data[helpText]"'.($BE_USER->uc['helpText']?' checked="checked"':'').' />';
238 $code[7][1] = $this->setLabel('maxTitleLen','titleLen').':';
239 $code[7][2] = '<input type="text" name="data[titleLen]" value="'.$BE_USER->uc['titleLen'].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(5).' maxlength="5" />';
240
241 $this->content.=$this->doc->section($LANG->getLL('opening').':',$this->doc->table($code),0,1);
242
243
244 // Advanced Operations:
245 $code = Array();
246 $code[1][1] = $this->setLabel('copyLevels').':';
247 $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');
248 $code[2][1] = $this->setLabel('recursiveDelete').':';
249 $code[2][2] = '<input type="checkbox" name="data[recursiveDelete]"'.($BE_USER->uc['recursiveDelete']?' checked="checked"':'').' />';
250
251 $this->content.=$this->doc->section($LANG->getLL('functions').":",$this->doc->table($code),0,1);
252
253
254 // Edit
255 $code = Array();
256 $code[2][1] = $this->setLabel('edit_wideDocument').':';
257 $code[2][2] = '<input type="checkbox" name="data[edit_wideDocument]"'.($BE_USER->uc['edit_wideDocument']?' checked="checked"':'').' />';
258 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['RTEenabled']) {
259 $code[3][1] = $this->setLabel('edit_RTE').':';
260 $code[3][2] = '<input type="checkbox" name="data[edit_RTE]"'.($BE_USER->uc['edit_RTE']?' checked="checked"':'').' />';
261 }
262 $code[4][1] = $this->setLabel('edit_docModuleUpload').':';
263 $code[4][2] = '<input type="checkbox" name="data[edit_docModuleUpload]"'.($BE_USER->uc['edit_docModuleUpload']?' checked="checked"':'').' />';
264
265 $code[6][1] = $this->setLabel('edit_showFieldHelp').':';
266 $code[6][2] = '<select name="data[edit_showFieldHelp]">
267 <option value=""></option>
268 <option value="icon"'.($BE_USER->uc['edit_showFieldHelp']=='icon'?' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_icon').'</option>
269 <option value="text"'.($BE_USER->uc['edit_showFieldHelp']=='text'?' selected="selected"':'').'>'.$this->setLabel('edit_showFieldHelp_message').'</option>
270 </select>';
271
272 $code[7][1] = $this->setLabel('disableCMlayers').':';
273 $code[7][2] = '<input type="checkbox" name="data[disableCMlayers]"'.($BE_USER->uc['disableCMlayers']?' checked="checked"':'').' />';
274
275 $this->content.=$this->doc->section($LANG->getLL('edit_functions').":",$this->doc->table($code),0,1);
276
277
278 // Personal data
279 $code = Array();
280 $code[1][1] = $this->setLabel('beUser_realName').':';
281 $code[1][2] = '<input type="text" name="ext_beuser[realName]" value="'.htmlspecialchars($BE_USER->user['realName']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
282 $code[2][1] = $this->setLabel('beUser_email').':';
283 $code[2][2] = '<input type="text" name="ext_beuser[email]" value="'.htmlspecialchars($BE_USER->user['email']).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' />';
284 $code[3][1] = $this->setLabel('emailMeAtLogin').' ('.$GLOBALS['BE_USER']->user['email'].'):';
285 $code[3][2] = '<input type="checkbox" name="data[emailMeAtLogin]"'.($BE_USER->uc['emailMeAtLogin']?' checked="checked"':'').' />';
286 $code[4][1] = $this->setLabel('newPassword').':';
287 $code[4][2] = '<input type="password" name="ext_beuser[password1]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\';" />';
288 $code[5][1] = $this->setLabel('newPasswordAgain').':';
289 $code[5][2] = '<input type="password" name="ext_beuser[password2]" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' onchange="this.value=this.value?MD5(this.value):\'\'" />';
290
291 $this->content.=$this->doc->section($LANG->getLL('personal_data').":",$this->doc->table($code),0,1);
292
293
294 // Submit:
295 $this->content.=$this->doc->spacer(20);
296 $this->content.=$this->doc->section('','
297 <input type="submit" name="submit" value="'.$LANG->getLL('save').'" />
298 &nbsp; <b>'.$LANG->getLL('setToStandard').': </b><input type="checkbox" name="data[setValuesToDefault]" />
299 <input type="hidden" name="simUser" value="'.$this->simUser.'" />');
300
301
302 // Notice
303 $this->content.=$this->doc->spacer(5);
304 $this->content.=$this->doc->section('',$LANG->getLL('activateChanges'));
305 }
306
307 /**
308 * Returns the backend user object, either the global OR the $this->OLD_BE_USER which is set during simulate-user operation.
309 * Anyways: The REAL user is returned - the one logged in.
310 */
311 function getRealScriptUserObj() {
312 return is_object($this->OLD_BE_USER) ? $this->OLD_BE_USER : $GLOBALS['BE_USER'];
313 }
314
315 /**
316 * Will make the simulate-user selector if the logged in user is administrator.
317 * 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)
318 */
319 function simulateUser() {
320 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
321
322 // *******************************************************************************
323 // If admin, allow simulation of another user
324 // *******************************************************************************
325 $this->simUser = 0;
326 $this->simulateSelector='';
327 unset($this->OLD_BE_USER);
328 if ($BE_USER->isAdmin()) {
329 $this->simUser = t3lib_div::_GP('simUser');
330
331 // Make user-selector:
332 $users = t3lib_BEfunc::getUserNames('username,usergroup,usergroup_cached_list,uid,realName');
333 $opt=array();
334 reset($users);
335 $opt[]='<option></option>';
336 while(list(,$rr)=each($users)) {
337 if ($rr['uid']!=$BE_USER->user['uid']) {
338 $opt[]='<option value="'.$rr['uid'].'"'.($this->simUser==$rr['uid']?' selected="selected"':'').'>'.htmlspecialchars($rr['username'].' ('.$rr['realName'].')').'</option>';
339 }
340 }
341 $this->simulateSelector = '<select name="simulateUser" onchange="document.location=\'index.php?simUser=\'+this.options[this.selectedIndex].value;">'.implode('',$opt).'</select>';
342 }
343
344 if ($this->simUser>0) { // This can only be set if the previous code was executed.
345 $this->OLD_BE_USER = $BE_USER; // Save old user...
346 unset($BE_USER); // Unset current
347
348 $BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth'); // New backend user object
349 $BE_USER->OS = TYPO3_OS;
350 $BE_USER->setBeUserByUid($this->simUser);
351 $BE_USER->fetchGroupData();
352 $BE_USER->backendSetUC();
353 $GLOBALS['BE_USER'] = $BE_USER; // Must do this, because unsetting $BE_USER before apparently unsets the reference to the global variable by this name!
354 }
355 }
356
357 /**
358 * Prints the content / ends page
359 */
360 function printContent() {
361 global $SOBE;
362
363 $this->content.=$this->doc->endPage();
364 echo $this->content; exit;
365 echo debug(array($this->content));
366 }
367
368 /**
369 * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array
370 */
371 function setLabel($str,$key='') {
372 $out = $GLOBALS['LANG']->getLL($str);
373 if (isset($this->overrideConf[($key?$key:$str)])) {
374 $out = '<span style="color:#999999">'.$out.'</span>';
375 }
376 return $out;
377 }
378 }
379
380 // Include extension?
381 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']) {
382 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/setup/mod/index.php']);
383 }
384
385
386
387
388
389
390
391
392
393
394
395
396 // Make instance:
397 $SOBE = t3lib_div::makeInstance('SC_mod_user_setup_index');
398 $SOBE->simulateUser();
399 $SOBE->storeIncomingData();
400
401 // These includes MUST be afterwards the settings are saved...!
402 require ($BACK_PATH.'template.php');
403 $LANG->includeLLFile('EXT:setup/mod/locallang.xml');
404
405 $SOBE->init();
406 $SOBE->main();
407 $SOBE->printContent();
408 ?>