Fixed bug #10375: 2 little JS-Errors that bug IE
[Packages/TYPO3.CMS.git] / typo3 / backend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007 Ingo Renner <ingo@typo3.org>
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 require_once('init.php');
29 require_once('template.php');
30 require_once('interfaces/interface.backend_toolbaritem.php');
31
32 require('classes/class.typo3logo.php');
33 require('classes/class.modulemenu.php');
34
35 // core toolbar items
36 require('classes/class.workspaceselector.php');
37 require('classes/class.clearcachemenu.php');
38 require('classes/class.shortcutmenu.php');
39 require('classes/class.backendsearchmenu.php');
40
41 require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
42 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
43 require_once('class.alt_menu_functions.inc');
44 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
45
46
47 /**
48 * Class for rendering the TYPO3 backend version 4.2+
49 *
50 * @author Ingo Renner <ingo@typo3.org>
51 * @package TYPO3
52 * @subpackage core
53 */
54 class TYPO3backend {
55
56 protected $content;
57 protected $css;
58 protected $cssFiles;
59 protected $js;
60 protected $jsFiles;
61 protected $toolbarItems;
62 private $menuWidthDefault = 160; // intentionally private as nobody should modify defaults
63 protected $menuWidth;
64
65 /**
66 * Object for loading backend modules
67 *
68 * @var t3lib_loadModules
69 */
70 protected $moduleLoader;
71
72 /**
73 * module menu generating object
74 *
75 * @var ModuleMenu
76 */
77 protected $moduleMenu;
78
79 /**
80 * constructor
81 *
82 * @return void
83 */
84 public function __construct() {
85
86 // Initializes the backend modules structure for use later.
87 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules');
88 $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
89
90 $this->moduleMenu = t3lib_div::makeInstance('ModuleMenu');
91
92 // add default BE javascript
93 $this->js = '';
94 $this->jsFiles = array(
95 'contrib/prototype/prototype.js',
96 'contrib/scriptaculous/scriptaculous.js?load=builder,effects,controls,dragdrop',
97 'contrib/extjs/adapter/prototype/ext-prototype-adapter.js',
98 'contrib/extjs/ext-all.js',
99 'md5.js',
100 'js/backend.js',
101 'js/common.js',
102 'js/sizemanager.js',
103 'js/toolbarmanager.js',
104 'js/modulemenu.js',
105 'js/iecompatibility.js',
106 '../t3lib/jsfunc.evalfield.js'
107 );
108
109 // add default BE css
110 $this->css = '';
111 $this->cssFiles = array(
112 'backend-scaffolding' => 'css/backend-scaffolding.css',
113 'backend-style' => 'css/backend-style.css',
114 'modulemenu' => 'css/modulemenu.css',
115 'extJS' => 'contrib/extjs/resources/css/ext-all.css',
116 'extJS-gray' => 'contrib/extjs/resources/css/xtheme-gray.css'
117 );
118
119 $this->toolbarItems = array();
120 $this->initializeCoreToolbarItems();
121
122 $this->menuWidth = $this->menuWidthDefault;
123 if (isset($GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW']) && (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'] != (int) $this->menuWidth) {
124 $this->menuWidth = (int) $GLOBALS['TBE_STYLES']['dims']['leftMenuFrameW'];
125 }
126 }
127
128 /**
129 * initializes the core toolbar items
130 *
131 * @return void
132 */
133 protected function initializeCoreToolbarItems() {
134
135 $coreToolbarItems = array(
136 'workspaceSelector' => 'WorkspaceSelector',
137 'shortcuts' => 'ShortcutMenu',
138 'clearCacheActions' => 'ClearCacheMenu',
139 'backendSearch' => 'BackendSearchMenu'
140 );
141
142 foreach($coreToolbarItems as $toolbarItemName => $toolbarItemClassName) {
143 // Get name of XCLASS (if any):
144 $toolbarItemClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
145 $toolbarItem = new $toolbarItemClassName($this);
146
147 if(!($toolbarItem instanceof backend_toolbarItem)) {
148 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195126772);
149 }
150
151 if($toolbarItem->checkAccess()) {
152 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
153 } else {
154 unset($toolbarItem);
155 }
156 }
157 }
158
159 /**
160 * main function generating the BE scaffolding
161 *
162 * @return void
163 */
164 public function render() {
165
166 // prepare the scaffolding, at this point extension may still add javascript and css
167 $logo = t3lib_div::makeInstance('TYPO3Logo');
168 $logo->setLogo('gfx/typo3logo_mini.png');
169
170 $menu = $this->moduleMenu->render();
171
172 if ($this->menuWidth != $this->menuWidthDefault) {
173 $this->css .= '
174 #typo3-logo,
175 #typo3-side-menu {
176 width: ' . ($this->menuWidth - 1) . 'px;
177 }
178
179 #typo3-top,
180 #typo3-content {
181 margin-left: ' . $this->menuWidth . 'px;
182 }
183 ';
184 }
185
186 // create backend scaffolding
187 $backendScaffolding = '
188 <div id="typo3-backend">
189 <div id="typo3-top-container">
190 <div id="typo3-logo">'.$logo->render().'</div>
191 <div id="typo3-top" class="typo3-top-toolbar">'
192 .$this->renderToolbar()
193 .'</div>
194 </div>
195 <div id="typo3-main-container">
196 <div id="typo3-side-menu">
197 '.$menu.'
198 </div>
199 <div id="typo3-content">
200 <iframe src="alt_intro.php" name="content" id="content" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize"></iframe>
201 </div>
202 </div>
203 </div>
204 ';
205
206 /******************************************************
207 * now put the complete backend document together
208 ******************************************************/
209
210 // remove duplicate entries
211 $this->jsFiles = array_unique($this->jsFiles);
212
213 // add javascript
214 foreach($this->jsFiles as $jsFile) {
215 $GLOBALS['TBE_TEMPLATE']->JScode .= '
216 <script type="text/javascript" src="'.$jsFile.'"></script>';
217 }
218 $GLOBALS['TBE_TEMPLATE']->JScode .= chr(10);
219 $this->generateJavascript();
220 $GLOBALS['TBE_TEMPLATE']->JScode .= $GLOBALS['TBE_TEMPLATE']->wrapScriptTags($this->js);
221
222 // FIXME abusing the JS container to add CSS, need to fix template.php
223 foreach($this->cssFiles as $cssFileName => $cssFile) {
224 $GLOBALS['TBE_TEMPLATE']->JScode .= '
225 <link rel="stylesheet" type="text/css" href="'.$cssFile.'" />
226 ';
227
228 // load addditional css files to overwrite existing core styles
229 if(!empty($GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName])) {
230 $GLOBALS['TBE_TEMPLATE']->JScode .= '
231 <link rel="stylesheet" type="text/css" href="'.$GLOBALS['TBE_STYLES']['stylesheets'][$cssFileName].'" />
232 ';
233 }
234 }
235
236 if(!empty($this->css)) {
237 $GLOBALS['TBE_TEMPLATE']->JScode .= '
238 <style type="text/css" id="internalStyle">
239 '.$this->css.'
240 </style>';
241 }
242
243 // set document title:
244 $title = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
245 ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'].' [TYPO3 '.TYPO3_version.']'
246 : 'TYPO3 '.TYPO3_version
247 );
248
249 // start page header:
250 $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage($title);
251 $this->content .= $backendScaffolding;
252 $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage();
253
254 echo $this->content;
255 }
256
257 /**
258 * renders the items in the top toolbar
259 *
260 * @return string top toolbar elements as HTML
261 */
262 protected function renderToolbar() {
263
264 // move search to last position
265 $search = $this->toolbarItems['backendSearch'];
266 unset($this->toolbarItems['backendSearch']);
267 $this->toolbarItems['backendSearch'] = $search;
268
269 $toolbar = '<ul id="typo3-toolbar">';
270 $toolbar.= '<li>'.$this->getLoggedInUserLabel().'</li>
271 <li><div id="logout-button" class="toolbar-item no-separator">'.$this->moduleMenu->renderLogoutButton().'</div></li>';
272
273 foreach($this->toolbarItems as $toolbarItem) {
274 $menu = $toolbarItem->render();
275 if ($menu) {
276 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
277 $toolbar .= '<li' . $additionalAttributes . '>' .$menu. '</li>';
278 }
279 }
280
281 return $toolbar.'</ul>';
282 }
283
284 /**
285 * gets the label of the currently loged in BE user
286 *
287 * @return string html code snippet displaying the currently logged in user
288 */
289 protected function getLoggedInUserLabel() {
290 global $BE_USER, $BACK_PATH;
291
292 $icon = '<img'.t3lib_iconWorks::skinImg(
293 '',
294 $BE_USER->isAdmin() ?
295 'gfx/i/be_users_admin.gif' :
296 'gfx/i/be_users.gif',
297 'width="18" height="16"'
298 )
299 .' title="" alt="" />';
300
301 $label = $GLOBALS['BE_USER']->user['realName'] ?
302 $BE_USER->user['realName'].' ['.$BE_USER->user['username'].']' :
303 $BE_USER->user['username'];
304
305 // Link to user setup if it's loaded and user has access
306 $link = '';
307 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
308 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
309 }
310
311 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
312
313 // superuser mode
314 if($BE_USER->user['ses_backuserid']) {
315 $username = ' su-user">'.$icon.
316 '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:switchtouser').'">SU: </span>'.
317 '<span>'.htmlspecialchars($label).'</span>';
318 }
319
320 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
321 }
322
323 /**
324 * Generates the JavaScript code for the backend.
325 *
326 * @return void
327 */
328 protected function generateJavascript() {
329
330 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
331 $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
332 $moduleFramesHelper = implode(chr(10), $this->moduleMenu->getFsMod());
333
334 // If another page module was specified, replace the default Page module with the new one
335 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
336 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
337
338 $menuFrameName = 'menu';
339 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
340 $menuFrameName = 'topmenuFrame';
341 }
342
343 // create challenge for the (re)login form and save it in the session.
344 $challenge = md5(uniqid('').getmypid());
345 session_start();
346 $_SESSION['login_challenge'] = $challenge;
347
348 // determine security level from conf vars and default to super challenged
349 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
350 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
351 } else {
352 $this->loginSecurityLevel = 'superchallenged';
353 }
354
355 $this->js .= '
356 Ext.BLANK_IMAGE_URL = "' .
357 // t3lib_div::locationHeaderUrl() will include '/typo3/' in the URL
358 htmlspecialchars(t3lib_div::locationHeaderUrl('gfx/clear.gif')) .
359 '";
360
361 /**
362 * Function similar to PHPs rawurlencode();
363 */
364 function rawurlencode(str) {
365 var output = escape(str);
366 output = str_replace("*","%2A", output);
367 output = str_replace("+","%2B", output);
368 output = str_replace("/","%2F", output);
369 output = str_replace("@","%40", output);
370 return output;
371 }
372
373 /**
374 * Function to similar to PHPs rawurlencode() which removes TYPO3_SITE_URL;
375 */
376 function rawurlencodeAndRemoveSiteUrl(str) { //
377 var siteUrl = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . '";
378 return rawurlencode(str_replace(siteUrl, \'\', str));
379 }
380
381 /**
382 * String-replace function
383 */
384 function str_replace(match,replace,string) { //
385 var input = ""+string;
386 var matchStr = ""+match;
387 if (!matchStr) {return string;}
388 var output = "";
389 var pointer=0;
390 var pos = input.indexOf(matchStr);
391 while (pos!=-1) {
392 output+=""+input.substr(pointer, pos-pointer)+replace;
393 pointer=pos+matchStr.length;
394 pos = input.indexOf(match,pos+1);
395 }
396 output+=""+input.substr(pointer);
397 return output;
398 }
399
400 /**
401 * TypoSetup object.
402 */
403 function typoSetup() { //
404 this.PATH_typo3 = "'.$pathTYPO3.'";
405 this.PATH_typo3_enc = "'.rawurlencode($pathTYPO3).'";
406 this.username = "'.$GLOBALS['BE_USER']->user['username'].'";
407 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
408 this.navFrameWidth = 0;
409 this.securityLevel = "'.$this->loginSecurityLevel.'";
410 }
411 var TS = new typoSetup();
412
413 /**
414 * Functions for session-expiry detection:
415 */
416 function busy() { //
417 this.loginRefreshed = busy_loginRefreshed;
418 this.openRefreshWindow = busy_OpenRefreshWindow;
419 this.openLockedWaitWindow = busy_openLockedWaitWindow;
420 this.busyloadTime=0;
421 this.openRefreshW=0;
422 this.reloginCancelled=0;
423 this.earlyRelogin=0;
424 this.locked=0;
425
426 // starts the timer and resets the earlyRelogin variable so that
427 // the countdown works properly.
428 this.startTimer = function() {
429 this.earlyRelogin = 0;
430 this.timer.start();
431 }
432
433 this.stopTimer = function() {
434 this.timer.stop();
435 }
436
437 // simple timer that polls the server to determine imminent timeout.
438 this.timer = new Ajax.PeriodicalUpdater("","ajax.php", {
439 method: "get",
440 frequency: 60,
441 decay: 1,
442 parameters: "ajaxID=BackendLogin::isTimedOut&skipSessionUpdate=1",
443 onSuccess: function(e) {
444 var login = e.responseJSON.login.evalJSON();
445 if(login.locked) {
446 busy.locked = 1;
447 busy.openLockedWaitWindow();
448 } else if(login.timed_out) {
449 busy.openRefreshWindow();
450 }
451 if (busy.locked && !login.locked && !login.timed_out) {
452 busy.locked = 0;
453 Ext.MessageBox.hide();
454 }
455 }
456 });
457
458 // this function runs the countdown and opens the login window
459 // as soon as the countdown expires.
460 this.countDown = function(progressControl, progressTextFormatPlural, progressTextFormatSingular, secondsRemaining, totalSeconds) {
461
462 if(busy.earlyRelogin == 0) {
463 if(secondsRemaining > 1) {
464 progressControl.updateText(String.format(progressTextFormatPlural, secondsRemaining));
465 progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
466 setTimeout(function () {
467 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
468 }, 1000);
469 } else if(secondsRemaining > 0) {
470 progressControl.updateText(String.format(progressTextFormatSingular, secondsRemaining));
471 progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
472 setTimeout(function () {
473 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
474 }, 1000);
475 } else {
476 busy.openRefreshW = 1;
477 busy.openLogin();
478 }
479 }
480 };
481
482 // Closes the countdown window and opens a new one with a login form.
483 this.openLogin = function() {
484 var login;
485 doChallengeResponse = function(superchallenged) {
486 password = $$("#loginform form")[0].p_field.value;
487
488 if (password) {
489 if (superchallenged) {
490 password = MD5(password); // this makes it superchallenged!!
491 }
492 str = $("login_username").value+":"+password+":"+$("challenge").value;
493 $("userident").value = MD5(str);
494 $("password").value = "";
495
496 return true;
497 }
498 }
499
500 submitForm = function() {
501 if(TS.securityLevel == "superchallenged") {
502 doChallengeResponse(1);
503 } else if (TS.securityLevel == "challenged") {
504 doChallengeResponse(0);
505 } else {
506 $("userident").value = $$("#loginform form")[0].p_field.value;
507 $("password").value= "";
508 }
509
510 login.getForm().submit({
511 method: "post",
512 waitTitle: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_logging_in') . '",
513 waitMsg: " ",
514 params: "ajaxID=BackendLogin::login&login_status=login",
515 success: function() {
516 win.close();
517 setTimeout(busy.startTimer(), 2000);
518
519 },
520
521 failure: function() {
522 // TODO: add failure to notification system instead of alert
523 // Ext.tip.msg("Login failed", "Username or Password incorrect!");
524 Ext.Msg.alert("' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_failed') . '", "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_failed_message') . '");
525 }
526 });
527 }
528
529 logout = new Ajax.Request("ajax.php", {
530 method: "get",
531 parameters: "ajaxID=BackendLogin::logout"
532 });
533
534 Ext.onReady(function(){
535 login = new Ext.FormPanel({
536 url: "ajax.php",
537 id: "loginform",
538 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_title') . '",
539 defaultType: "textfield",
540 width: "100%",
541 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
542
543 items: [{
544 xtype: "panel",
545 bodyStyle: "margin-bottom: 7px; border: none;",
546 html: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_expired') . '"
547 },{
548 fieldLabel: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_username') . '",
549 name: "username",
550 id: "login_username",
551 allowBlank: false,
552 width: 250
553 },{
554 fieldLabel: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_password') . '",
555 name: "p_field",
556 width: 250,
557 id: "password",
558 inputType: "password"
559 },{
560 xtype: "hidden",
561 name: "userident",
562 id: "userident",
563 value: ""
564 }, {
565 xtype: "hidden",
566 name: "challenge",
567 id: "challenge",
568 value: "' . $challenge . '"
569 }
570 ],
571 keys:({
572 key: Ext.EventObject.ENTER,
573 fn: submitForm,
574 scope: this
575 }),
576 buttons: [{
577 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_button') . '",
578 formBind: true,
579 handler: submitForm
580 }, {
581 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_logout_button') . '",
582 formBind: true,
583 handler: function() {
584 top.location.href = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . '";
585 }
586 }]
587 });
588 win.close();
589 win = new Ext.Window({
590 width: 450,
591 autoHeight: true,
592 closable: false,
593 resizable: false,
594 plain: true,
595 border: false,
596 modal: true,
597 draggable: false,
598 items: [login]
599 });
600 win.show();
601 });
602 }
603 }
604
605 function busy_loginRefreshed() { //
606 this.openRefreshW=0;
607 this.earlyRelogin=0;
608 }
609
610 function busy_openLockedWaitWindow() {
611 Ext.MessageBox.show({
612 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.please_wait') . '",
613 msg: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.be_locked') . '",
614 width: 500,
615 icon: Ext.MessageBox.INFO,
616 closable: false
617 });
618 }
619
620 function busy_OpenRefreshWindow() {
621 this.openRefreshW = 1;
622
623 busy.stopTimer();
624
625 var seconds = 30;
626 var progressTextFormatSingular = "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_countdown_singular') . '";
627 var progressTextFormatPlural = "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_countdown') . '";
628 var progressText = String.format(progressTextFormatPlural, seconds);
629 var progressControl = new Ext.ProgressBar({
630 autoWidth: true,
631 autoHeight: true,
632 value: 1,
633 text: progressText
634 });
635
636 win = new Ext.Window({
637 closable: false,
638 resizable: false,
639 draggable: false,
640 modal: true,
641 items: [{
642 xtype: "panel",
643 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
644 bodyBorder: false,
645 autoHeight: true,
646 autoWidth: true,
647 html: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_about_to_expire') . '"
648 },
649 progressControl
650 ],
651 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_about_to_expire_title') . '",
652 width: 450,
653
654 buttons: [{
655 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_refresh_button') . '",
656 handler: function() {
657 refresh = new Ajax.Request("ajax.php", {
658 method: "get",
659 parameters: "ajaxID=BackendLogin::refreshLogin"
660 });
661 win.close();
662 busy.earlyRelogin = 1;
663 setTimeout("busy.startTimer()", 2000);
664 }
665 }, {
666 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_direct_logout_button') . '",
667 handler: function() {
668 top.location.href = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . 'logout.php";
669 }
670 }]
671 });
672 win.show();
673 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular, seconds, seconds);
674 }
675
676 /**
677 * Launcing information window for records/files (fileref as "table" argument)
678 */
679 function launchView(table,uid,bP) { //
680 var backPath= bP ? bP : "";
681 var thePreviewWindow="";
682 thePreviewWindow = window.open(TS.PATH_typo3+"show_item.php?table="+encodeURIComponent(table)+"&uid="+encodeURIComponent(uid),"ShowItem"+TS.uniqueID,"height=400,width=550,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
683 if (thePreviewWindow && thePreviewWindow.focus) {
684 thePreviewWindow.focus();
685 }
686 }
687
688 /**
689 * Opens plain window with url
690 */
691 function openUrlInWindow(url,windowName) { //
692 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
693 regularWindow.focus();
694 return false;
695 }
696
697 /**
698 * Loads a page id for editing in the page edit module:
699 */
700 function loadEditId(id,addGetVars) { //
701 top.fsMod.recentIds["web"]=id;
702 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
703
704 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
705 top.content.nav_frame.refresh_nav();
706 }
707
708 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
709 }
710
711 /**
712 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
713 * Used by the shortcut frame to set a "intermediate URL"
714 */
715 var nextLoadModuleUrl="";
716 function getModuleUrl(inUrl) { //
717 var nMU;
718 if (top.nextLoadModuleUrl) {
719 nMU=top.nextLoadModuleUrl;
720 top.nextLoadModuleUrl="";
721 return nMU;
722 } else {
723 return inUrl;
724 }
725 }
726
727 /**
728 * Print properties of an object
729 */
730 function debugObj(obj,name) { //
731 var acc;
732 for (i in obj) {
733 if (obj[i]) {
734 acc+=i+": "+obj[i]+"\n";
735 }
736 }
737 alert("Object: "+name+"\n\n"+acc);
738 }
739
740 /**
741 * Initialize login expiration warning object
742 */
743 var busy = new busy();
744 busy.loginRefreshed();
745
746 /**
747 * Function used to switch modules
748 */
749 var currentModuleLoaded = "";
750 var goToModule = '.$goToModuleSwitch.'
751
752 /**
753 * Frameset Module object
754 *
755 * Used in main modules with a frameset for submodules to keep the ID between modules
756 * Typically that is set by something like this in a Web>* sub module:
757 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
758 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
759 */
760 function fsModules() { //
761 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
762 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
763 this.currentMainLoaded="";
764 this.currentBank="0";
765 }
766 var fsMod = new fsModules();
767 '.$moduleFramesHelper.'
768
769 // Used by Frameset Modules
770 var condensedMode = '.($GLOBALS['BE_USER']->uc['condensedMode']?1:0).';
771 var currentSubScript = "";
772 var currentSubNavScript = "";
773
774 // Used for tab-panels:
775 var DTM_currentTabs = new Array();
776
777 // status of WS FE preview
778 var WorkspaceFrontendPreviewEnabled = ' . (($GLOBALS['BE_USER']->workspace != 0 && !$GLOBALS['BE_USER']->user['workspace_preview']) ? 'false' : 'true') . ';
779 ';
780
781 // Check editing of page:
782 $this->handlePageEditing();
783 $this->setStartupModule();
784 }
785
786 /**
787 * Checking if the "&edit" variable was sent so we can open it for editing the page.
788 * Code based on code from "alt_shortcut.php"
789 *
790 * @return void
791 */
792 protected function handlePageEditing() {
793
794 if(!t3lib_extMgm::isLoaded('cms')) {
795 return;
796 }
797
798 // EDIT page:
799 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
800 $editRecord = '';
801
802 if($editId) {
803
804 // Looking up the page to edit, checking permissions:
805 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
806 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
807
808 if(t3lib_div::testInt($editId)) {
809 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
810 } else {
811 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
812
813 if(is_array($records)) {
814 reset($records);
815 $editRecord = current($records);
816 t3lib_BEfunc::workspaceOL('pages', $editRecord);
817 }
818 }
819
820 // If the page was accessible, then let the user edit it.
821 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
822 // Setting JS code to open editing:
823 $this->js .= '
824 // Load page to edit:
825 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
826 ';
827 // Checking page edit parameter:
828 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
829
830 // Expanding page tree:
831 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
832 }
833 } else {
834 $this->js .= '
835 // Warning about page editing:
836 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
837 ';
838 }
839 }
840 }
841
842 /**
843 * Sets the startup module from either GETvars module and mpdParams or user configuration.
844 *
845 * @return void
846 */
847 protected function setStartupModule() {
848 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
849
850 if(!$startModule) {
851 if ($GLOBALS['BE_USER']->uc['startModule']) {
852 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
853 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
854 $startModule = 'user_task';
855 }
856 }
857
858 $moduleParameters = t3lib_div::_GET('modParams');
859 if($startModule) {
860 $this->js .= '
861 // start in module:
862 function startInModule(modName, cMR_flag, addGetVars) {
863 Event.observe(document, \'dom:loaded\', function() {
864 top.goToModule(modName, cMR_flag, addGetVars);
865 });
866 }
867
868 startInModule(\''.$startModule.'\', false, \''.$moduleParameters.'\');
869 ';
870 }
871 }
872
873 /**
874 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
875 *
876 * @return string HTML code snippet to display the TYPO3 logo
877 */
878 protected function getLogo() {
879 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
880 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
881 '</a>';
882
883 // overwrite with custom logo
884 if($GLOBALS['TBE_STYLES']['logo']) {
885 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
886 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
887 }
888 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
889 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
890 '</a>';
891 }
892
893 return $logo;
894 }
895
896 /**
897 * adds a javascript snippet to the backend
898 *
899 * @param string javascript snippet
900 * @return void
901 */
902 public function addJavascript($javascript) {
903 // TODO do we need more checks?
904 if(!is_string($javascript)) {
905 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
906 }
907
908 $this->js .= $javascript;
909 }
910
911 /**
912 * adds a javscript file to the backend after it has been checked that it exists
913 *
914 * @param string javascript file reference
915 * @return boolean true if the javascript file was successfully added, false otherwise
916 */
917 public function addJavascriptFile($javascriptFile) {
918 $jsFileAdded = false;
919
920 //TODO add more checks if neccessary
921 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
922 $this->jsFiles[] = $javascriptFile;
923 $jsFileAdded = true;
924 }
925
926 return $jsFileAdded;
927 }
928
929 /**
930 * adds a css snippet to the backend
931 *
932 * @param string css snippet
933 * @return void
934 */
935 public function addCss($css) {
936 if(!is_string($css)) {
937 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
938 }
939
940 $this->css .= $css;
941 }
942
943 /**
944 * adds a css file to the backend after it has been checked that it exists
945 *
946 * @param string the css file's name with out the .css ending
947 * @param string css file reference
948 * @return boolean true if the css file was added, false otherwise
949 */
950 public function addCssFile($cssFileName, $cssFile) {
951 $cssFileAdded = false;
952
953 //TODO add more checks if neccessary
954 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$cssFile))) {
955 // prevent overwriting existing css files
956 if(empty($this->cssFiles[$cssFileName])) {
957 $this->cssFiles[$cssFileName] = $cssFile;
958 $cssFileAdded = true;
959 }
960 }
961
962 return $cssFileAdded;
963 }
964
965 /**
966 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
967 *
968 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
969 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
970 * @return void
971 */
972 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
973 $toolbarItemResolvedClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
974 $toolbarItem = new $toolbarItemResolvedClassName($this);
975
976 if(!($toolbarItem instanceof backend_toolbarItem)) {
977 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
978 }
979
980 if($toolbarItem->checkAccess()) {
981 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
982 } else {
983 unset($toolbarItem);
984 }
985 }
986 }
987
988
989 // include XCLASS
990 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
991 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
992 }
993
994
995 // document generation
996 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
997
998 // include extensions which may add css, javascript or toolbar items
999 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
1000 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
1001 include_once($additionalBackendItem);
1002 }
1003 }
1004
1005 $TYPO3backend->render();
1006
1007 ?>