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