Fixed bug #9052: Remove JS popup when login expired
[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 $additionalAttributes = $toolbarItem->getAdditionalAttributes();
275
276 $toolbar .= '<li'.$additionalAttributes.'>'.$toolbarItem->render().'</li>';
277 }
278
279 return $toolbar.'</ul>';
280 }
281
282 /**
283 * gets the label of the currently loged in BE user
284 *
285 * @return string html code snippet displaying the currently logged in user
286 */
287 protected function getLoggedInUserLabel() {
288 global $BE_USER, $BACK_PATH;
289
290 $icon = '<img'.t3lib_iconWorks::skinImg(
291 '',
292 $BE_USER->isAdmin() ?
293 'gfx/i/be_users_admin.gif' :
294 'gfx/i/be_users.gif',
295 'width="18" height="16"'
296 )
297 .' title="" alt="" />';
298
299 $label = $GLOBALS['BE_USER']->user['realName'] ?
300 $BE_USER->user['realName'].' ['.$BE_USER->user['username'].']' :
301 $BE_USER->user['username'];
302
303 // Link to user setup if it's loaded and user has access
304 $link = '';
305 if (t3lib_extMgm::isLoaded('setup') && $BE_USER->check('modules','user_setup')) {
306 $link = '<a href="#" onclick="top.goToModule(\'user_setup\');this.blur();return false;">';
307 }
308
309 $username = '">'.$link.$icon.'<span>'.htmlspecialchars($label).'</span>'.($link?'</a>':'');
310
311 // superuser mode
312 if($BE_USER->user['ses_backuserid']) {
313 $username = ' su-user">'.$icon.
314 '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xml:switchtouser').'">SU: </span>'.
315 '<span>'.htmlspecialchars($label).'</span>';
316 }
317
318 return '<div id="username" class="toolbar-item no-separator'.$username.'</div>';
319 }
320
321 /**
322 * Generates the JavaScript code for the backend.
323 *
324 * @return void
325 */
326 protected function generateJavascript() {
327
328 $pathTYPO3 = t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
329 $goToModuleSwitch = $this->moduleMenu->getGotoModuleJavascript();
330 $moduleFramesHelper = implode(chr(10), $this->moduleMenu->getFsMod());
331
332 // If another page module was specified, replace the default Page module with the new one
333 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
334 $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
335
336 $menuFrameName = 'menu';
337 if($GLOBALS['BE_USER']->uc['noMenuMode'] === 'icons') {
338 $menuFrameName = 'topmenuFrame';
339 }
340
341 // create challenge for the (re)login form and save it in the session.
342 $challenge = md5(uniqid('').getmypid());
343 session_start();
344 $_SESSION['login_challenge'] = $challenge;
345
346 // determine security level from conf vars and default to super challenged
347 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) {
348 $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'];
349 } else {
350 $this->loginSecurityLevel = 'superchallenged';
351 }
352
353 $this->js .= '
354 /**
355 * Function similar to PHPs rawurlencode();
356 */
357 function rawurlencode(str) {
358 var output = escape(str);
359 output = str_replace("*","%2A", output);
360 output = str_replace("+","%2B", output);
361 output = str_replace("/","%2F", output);
362 output = str_replace("@","%40", output);
363 return output;
364 }
365
366 /**
367 * Function to similar to PHPs rawurlencode() which removes TYPO3_SITE_URL;
368 */
369 function rawurlencodeAndRemoveSiteUrl(str) { //
370 var siteUrl = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . '";
371 return rawurlencode(str_replace(siteUrl, \'\', str));
372 }
373
374 /**
375 * String-replace function
376 */
377 function str_replace(match,replace,string) { //
378 var input = ""+string;
379 var matchStr = ""+match;
380 if (!matchStr) {return string;}
381 var output = "";
382 var pointer=0;
383 var pos = input.indexOf(matchStr);
384 while (pos!=-1) {
385 output+=""+input.substr(pointer, pos-pointer)+replace;
386 pointer=pos+matchStr.length;
387 pos = input.indexOf(match,pos+1);
388 }
389 output+=""+input.substr(pointer);
390 return output;
391 }
392
393 /**
394 * TypoSetup object.
395 */
396 function typoSetup() { //
397 this.PATH_typo3 = "'.$pathTYPO3.'";
398 this.PATH_typo3_enc = "'.rawurlencode($pathTYPO3).'";
399 this.username = "'.$GLOBALS['BE_USER']->user['username'].'";
400 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
401 this.navFrameWidth = 0;
402 this.securityLevel = "'.$this->loginSecurityLevel.'";
403 }
404 var TS = new typoSetup();
405
406 /**
407 * Functions for session-expiry detection:
408 */
409 function busy() { //
410 this.loginRefreshed = busy_loginRefreshed;
411 this.openRefreshWindow = busy_OpenRefreshWindow;
412 this.busyloadTime=0;
413 this.openRefreshW=0;
414 this.reloginCancelled=0;
415 this.earlyRelogin=0;
416
417 // starts the timer and resets the earlyRelogin variable so that
418 // the countdown works properly.
419 this.startTimer = function() {
420 this.earlyRelogin = 0;
421 this.timer.start();
422 }
423
424 this.stopTimer = function() {
425 this.timer.stop();
426 }
427
428 // simple timer that polls the server to determine imminent timeout.
429 this.timer = new Ajax.PeriodicalUpdater("","ajax.php", {
430 method: "get",
431 frequency: 10,
432 parameters: "ajaxID=BackendLogin::isTimedOut&skipSessionUpdate=1",
433 onSuccess: function(e) {
434 var login = e.responseJSON.login.evalJSON();
435 if(login.timed_out) {
436 busy.openRefreshWindow();
437 }
438 }
439 });
440
441 // this function runs the countdown and opens the login window
442 // as soon as the countdown expires.
443 this.countDown = function(progressControl, progressTextFormatPlural, progressTextFormatSingular, secondsRemaining, totalSeconds) {
444
445 if(busy.earlyRelogin == 0) {
446 if(secondsRemaining > 1) {
447 progressControl.updateText(String.format(progressTextFormatPlural, secondsRemaining));
448 progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
449 setTimeout(function () {
450 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
451 }, 1000);
452 } else if(secondsRemaining > 0) {
453 progressControl.updateText(String.format(progressTextFormatSingular, secondsRemaining));
454 progressControl.updateProgress(secondsRemaining/(1.0*totalSeconds));
455 setTimeout(function () {
456 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular,secondsRemaining - 1, totalSeconds);
457 }, 1000);
458 } else {
459 busy.openRefreshW = 1;
460 busy.openLogin();
461 }
462 }
463 };
464
465 // Closes the countdown window and opens a new one with a login form.
466 this.openLogin = function() {
467 var login;
468 doChallengeResponse = function(superchallenged) {
469 password = $$("#loginform form")[0].p_field.value;
470
471 if (password) {
472 if (superchallenged) {
473 password = MD5(password); // this makes it superchallenged!!
474 }
475 str = $("login_username").value+":"+password+":"+$("challenge").value;
476 $("userident").value = MD5(str);
477 $("password").value = "";
478
479 return true;
480 }
481 }
482
483 submitForm = function() {
484 if(TS.securityLevel == "superchallenged") {
485 doChallengeResponse(1);
486 } else if (TS.securityLevel == "challenged") {
487 doChallengeResponse(0);
488 } else {
489 $("userident").value = $$("#loginform form")[0].p_field.value;
490 $("password").value= "";
491 }
492
493 login.getForm().submit({
494 method: "post",
495 waitTitle: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_logging_in') . '",
496 waitMsg: " ",
497 params: "ajaxID=BackendLogin::login&login_status=login",
498 success: function() {
499 win.close();
500 setTimeout("busy.startTimer()", 2000);
501
502 },
503
504 failure: function() {
505 // TODO: add failure to notification system instead of alert
506 // Ext.tip.msg("Login failed", "Username or Password incorrect!");
507 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') . '");
508 }
509 });
510 }
511
512 new Ajax.Request("ajax.php", {
513 method: "get",
514 frequency: 10,
515 parameters: "ajaxID=BackendLogin::logout",
516 });
517
518 Ext.onReady(function(){
519 login = new Ext.FormPanel({
520 url: "ajax.php",
521 id: "loginform",
522 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_title') . '",
523 defaultType: "textfield",
524 width: "100%",
525 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
526
527 items: [{
528 xtype: "panel",
529 bodyStyle: "margin-bottom: 7px; border: none;",
530 html: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_expired') . '",
531 },{
532 fieldLabel: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_username') . '",
533 name: "username",
534 id: "login_username",
535 allowBlank: false,
536 width: 250
537 },{
538 fieldLabel: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_password') . '",
539 name: "p_field",
540 width: 250,
541 id: "password",
542 inputType: "password"
543 },{
544 xtype: "hidden",
545 name: "userident",
546 id: "userident",
547 value: ""
548 }, {
549 xtype: "hidden",
550 name: "challenge",
551 id: "challenge",
552 value: "' . $challenge . '"
553 }
554 ],
555 keys:({
556 key: Ext.EventObject.ENTER,
557 fn: submitForm,
558 scope: this
559 }),
560 buttons: [{
561 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_button') . '",
562 formBind: true,
563 handler: submitForm
564 }, {
565 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_logout_button') . '",
566 formBind: true,
567 handler: function() {
568 top.location.href = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . '";
569 }
570 }]
571 });
572 win.close();
573 win = new Ext.Window({
574 width: 450,
575 autoHeight: true,
576 closable: false,
577 resizable: false,
578 plain: true,
579 border: false,
580 modal: true,
581 draggable: false,
582 items: [login]
583 });
584 win.show();
585 });
586 }
587 }
588
589 function busy_loginRefreshed() { //
590 this.openRefreshW=0;
591 this.earlyRelogin=0;
592 }
593
594 function busy_OpenRefreshWindow() {
595 this.openRefreshW = 1;
596
597 busy.stopTimer();
598
599 var seconds = 30;
600 var progressTextFormatSingular = "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_countdown_singular') . '";
601 var progressTextFormatPlural = "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_countdown') . '";
602 var progressText = String.format(progressTextFormatPlural, seconds);
603 var progressControl = new Ext.ProgressBar({
604 autoWidth: true,
605 autoHeight: true,
606 value: 1,
607 text: progressText
608 });
609
610 win = new Ext.Window({
611 closable: false,
612 resizable: false,
613 draggable: false,
614 modal: true,
615 items: [{
616 xtype: "panel",
617 bodyStyle: "padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;",
618 bodyBorder: false,
619 autoHeight: true,
620 autoWidth: true,
621 html: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_about_to_expire') . '"
622 },
623 progressControl
624 ],
625 title: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.login_about_to_expire_title') . '",
626 width: 450,
627
628 buttons: [{
629 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login_refresh_button') . '",
630 handler: function() {
631 new Ajax.Request("ajax.php", {
632 method: "get",
633 parameters: "ajaxID=BackendLogin::refreshLogin",
634 });
635 win.close();
636 busy.earlyRelogin = 1;
637 setTimeout("busy.startTimer()", 2000);
638 }
639 }, {
640 text: "' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_direct_logout_button') . '",
641 handler: function() {
642 top.location.href = "' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . 'logout.php";
643 }
644 }]
645 });
646 win.show();
647 busy.countDown(progressControl, progressTextFormatPlural, progressTextFormatSingular, seconds, seconds);
648 }
649
650 /**
651 * Launcing information window for records/files (fileref as "table" argument)
652 */
653 function launchView(table,uid,bP) { //
654 var backPath= bP ? bP : "";
655 var thePreviewWindow="";
656 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");
657 if (thePreviewWindow && thePreviewWindow.focus) {
658 thePreviewWindow.focus();
659 }
660 }
661
662 /**
663 * Opens plain window with url
664 */
665 function openUrlInWindow(url,windowName) { //
666 regularWindow = window.open(url,windowName,"status=1,menubar=1,resizable=1,location=1,directories=0,scrollbars=1,toolbar=1");
667 regularWindow.focus();
668 return false;
669 }
670
671 /**
672 * Loads a page id for editing in the page edit module:
673 */
674 function loadEditId(id,addGetVars) { //
675 top.fsMod.recentIds["web"]=id;
676 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
677
678 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
679 top.content.nav_frame.refresh_nav();
680 }
681
682 top.goToModule("'.$pageModule.'", 0, addGetVars?addGetVars:"");
683 }
684
685 /**
686 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
687 * Used by the shortcut frame to set a "intermediate URL"
688 */
689 var nextLoadModuleUrl="";
690 function getModuleUrl(inUrl) { //
691 var nMU;
692 if (top.nextLoadModuleUrl) {
693 nMU=top.nextLoadModuleUrl;
694 top.nextLoadModuleUrl="";
695 return nMU;
696 } else {
697 return inUrl;
698 }
699 }
700
701 /**
702 * Print properties of an object
703 */
704 function debugObj(obj,name) { //
705 var acc;
706 for (i in obj) {
707 if (obj[i]) {
708 acc+=i+": "+obj[i]+"\n";
709 }
710 }
711 alert("Object: "+name+"\n\n"+acc);
712 }
713
714 /**
715 * Initialize login expiration warning object
716 */
717 var busy = new busy();
718 busy.loginRefreshed();
719
720 /**
721 * Function used to switch modules
722 */
723 var currentModuleLoaded = "";
724 var goToModule = '.$goToModuleSwitch.'
725
726 /**
727 * Frameset Module object
728 *
729 * Used in main modules with a frameset for submodules to keep the ID between modules
730 * Typically that is set by something like this in a Web>* sub module:
731 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
732 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
733 */
734 function fsModules() { //
735 this.recentIds=new Array(); // used by frameset modules to track the most recent used id for list frame.
736 this.navFrameHighlightedID=new Array(); // used by navigation frames to track which row id was highlighted last time
737 this.currentMainLoaded="";
738 this.currentBank="0";
739 }
740 var fsMod = new fsModules();
741 '.$moduleFramesHelper.'
742
743 // Used by Frameset Modules
744 var condensedMode = '.($GLOBALS['BE_USER']->uc['condensedMode']?1:0).';
745 var currentSubScript = "";
746 var currentSubNavScript = "";
747
748 // Used for tab-panels:
749 var DTM_currentTabs = new Array();
750
751 // status of WS FE preview
752 var WorkspaceFrontendPreviewEnabled = ' . (($GLOBALS['BE_USER']->workspace != 0 && !$GLOBALS['BE_USER']->user['workspace_preview']) ? 'false' : 'true') . ';
753 ';
754
755 // Check editing of page:
756 $this->handlePageEditing();
757 $this->setStartupModule();
758 }
759
760 /**
761 * Checking if the "&edit" variable was sent so we can open it for editing the page.
762 * Code based on code from "alt_shortcut.php"
763 *
764 * @return void
765 */
766 protected function handlePageEditing() {
767
768 if(!t3lib_extMgm::isLoaded('cms')) {
769 return;
770 }
771
772 // EDIT page:
773 $editId = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('edit'));
774 $editRecord = '';
775
776 if($editId) {
777
778 // Looking up the page to edit, checking permissions:
779 $where = ' AND ('.$GLOBALS['BE_USER']->getPagePermsClause(2)
780 .' OR '.$GLOBALS['BE_USER']->getPagePermsClause(16).')';
781
782 if(t3lib_div::testInt($editId)) {
783 $editRecord = t3lib_BEfunc::getRecordWSOL('pages', $editId, '*', $where);
784 } else {
785 $records = t3lib_BEfunc::getRecordsByField('pages', 'alias', $editId, $where);
786
787 if(is_array($records)) {
788 reset($records);
789 $editRecord = current($records);
790 t3lib_BEfunc::workspaceOL('pages', $editRecord);
791 }
792 }
793
794 // If the page was accessible, then let the user edit it.
795 if(is_array($editRecord) && $GLOBALS['BE_USER']->isInWebMount($editRecord['uid'])) {
796 // Setting JS code to open editing:
797 $this->js .= '
798 // Load page to edit:
799 window.setTimeout("top.loadEditId('.intval($editRecord['uid']).');", 500);
800 ';
801 // Checking page edit parameter:
802 if(!$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
803
804 // Expanding page tree:
805 t3lib_BEfunc::openPageTree(intval($editRecord['pid']), !$GLOBALS['BE_USER']->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
806 }
807 } else {
808 $this->js .= '
809 // Warning about page editing:
810 alert('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->getLL('noEditPage'), $editId)).');
811 ';
812 }
813 }
814 }
815
816 /**
817 * Sets the startup module from either GETvars module and mpdParams or user configuration.
818 *
819 * @return void
820 */
821 protected function setStartupModule() {
822 $startModule = preg_replace('/[^[:alnum:]_]/', '', t3lib_div::_GET('module'));
823
824 if(!$startModule) {
825 if ($GLOBALS['BE_USER']->uc['startModule']) {
826 $startModule = $GLOBALS['BE_USER']->uc['startModule'];
827 } else if($GLOBALS['BE_USER']->uc['startInTaskCenter']) {
828 $startModule = 'user_task';
829 }
830 }
831
832 $moduleParameters = t3lib_div::_GET('modParams');
833 if($startModule) {
834 $this->js .= '
835 // start in module:
836 function startInModule(modName, cMR_flag, addGetVars) {
837 Event.observe(document, \'dom:loaded\', function() {
838 top.goToModule(modName, cMR_flag, addGetVars);
839 });
840 }
841
842 startInModule(\''.$startModule.'\', false, \''.$moduleParameters.'\');
843 ';
844 }
845 }
846
847 /**
848 * generates the code for the TYPO3 logo, either the default TYPO3 logo or a custom one
849 *
850 * @return string HTML code snippet to display the TYPO3 logo
851 */
852 protected function getLogo() {
853 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
854 '<img'.t3lib_iconWorks::skinImg('','gfx/alt_backend_logo.gif','width="117" height="32"').' title="TYPO3 Content Management Framework" alt="" />'.
855 '</a>';
856
857 // overwrite with custom logo
858 if($GLOBALS['TBE_STYLES']['logo']) {
859 if(substr($GLOBALS['TBE_STYLES']['logo'], 0, 3) == '../') {
860 $imgInfo = @getimagesize(PATH_site.substr($GLOBALS['TBE_STYLES']['logo'], 3));
861 }
862 $logo = '<a href="http://www.typo3.com/" target="_blank" onclick="'.$GLOBALS['TBE_TEMPLATE']->thisBlur().'">'.
863 '<img src="'.$GLOBALS['TBE_STYLES']['logo'].'" '.$imgInfo[3].' title="TYPO3 Content Management Framework" alt="" />'.
864 '</a>';
865 }
866
867 return $logo;
868 }
869
870 /**
871 * adds a javascript snippet to the backend
872 *
873 * @param string javascript snippet
874 * @return void
875 */
876 public function addJavascript($javascript) {
877 // TODO do we need more checks?
878 if(!is_string($javascript)) {
879 throw new InvalidArgumentException('parameter $javascript must be of type string', 1195129553);
880 }
881
882 $this->js .= $javascript;
883 }
884
885 /**
886 * adds a javscript file to the backend after it has been checked that it exists
887 *
888 * @param string javascript file reference
889 * @return boolean true if the javascript file was successfully added, false otherwise
890 */
891 public function addJavascriptFile($javascriptFile) {
892 $jsFileAdded = false;
893
894 //TODO add more checks if neccessary
895 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$javascriptFile))) {
896 $this->jsFiles[] = $javascriptFile;
897 $jsFileAdded = true;
898 }
899
900 return $jsFileAdded;
901 }
902
903 /**
904 * adds a css snippet to the backend
905 *
906 * @param string css snippet
907 * @return void
908 */
909 public function addCss($css) {
910 if(!is_string($css)) {
911 throw new InvalidArgumentException('parameter $css must be of type string', 1195129642);
912 }
913
914 $this->css .= $css;
915 }
916
917 /**
918 * adds a css file to the backend after it has been checked that it exists
919 *
920 * @param string the css file's name with out the .css ending
921 * @param string css file reference
922 * @return boolean true if the css file was added, false otherwise
923 */
924 public function addCssFile($cssFileName, $cssFile) {
925 $cssFileAdded = false;
926
927 //TODO add more checks if neccessary
928 if(file_exists(t3lib_div::resolveBackPath(PATH_typo3.$cssFile))) {
929 // prevent overwriting existing css files
930 if(empty($this->cssFiles[$cssFileName])) {
931 $this->cssFiles[$cssFileName] = $cssFile;
932 $cssFileAdded = true;
933 }
934 }
935
936 return $cssFileAdded;
937 }
938
939 /**
940 * adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
941 *
942 * @param string toolbar item name, f.e. tx_toolbarExtension_coolItem
943 * @param string toolbar item class name, f.e. tx_toolbarExtension_coolItem
944 * @return void
945 */
946 public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
947 $toolbarItemResolvedClassName = t3lib_div::makeInstanceClassName($toolbarItemClassName);
948 $toolbarItem = new $toolbarItemResolvedClassName($this);
949
950 if(!($toolbarItem instanceof backend_toolbarItem)) {
951 throw new UnexpectedValueException('$toolbarItem "'.$toolbarItemName.'" must implement interface backend_toolbarItem', 1195125501);
952 }
953
954 if($toolbarItem->checkAccess()) {
955 $this->toolbarItems[$toolbarItemName] = $toolbarItem;
956 } else {
957 unset($toolbarItem);
958 }
959 }
960 }
961
962
963 // include XCLASS
964 if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']) {
965 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/backend.php']);
966 }
967
968
969 // document generation
970 $TYPO3backend = t3lib_div::makeInstance('TYPO3backend');
971
972 // include extensions which may add css, javascript or toolbar items
973 if(is_array($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'])) {
974 foreach($GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'] as $additionalBackendItem) {
975 include_once($additionalBackendItem);
976 }
977 }
978
979 $TYPO3backend->render();
980
981 ?>