Initial revision
[Packages/TYPO3.CMS.git] / typo3 / alt_main.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Main frameset of the TYPO3 backend
29 *
30 * @author Kasper Skårhøj <kasper@typo3.com>
31 * @package TYPO3
32 * @subpackage core
33 *
34 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
35 */
36
37 require ('init.php');
38 require ('template.php');
39 require_once (PATH_t3lib.'class.t3lib_loadmodules.php');
40 require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
41 require_once ('class.alt_menu_functions.inc');
42
43
44
45 // ***************************
46 // Script Class
47 // ***************************
48 class SC_alt_main {
49 var $content;
50 var $mainJScode;
51 var $loadModules;
52 var $alt_menuObj;
53
54 /**
55 * Initialization
56 */
57 function init() {
58 global $TBE_MODULES;
59
60 // Initializes the backend modules structure for use later.
61 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
62 $this->loadModules->load($TBE_MODULES);
63
64 // Instantiates thee menu object which will generate some JavaScript for the goToModule() JS function in this frameset.
65 $this->alt_menuObj = t3lib_div::makeInstance('alt_menu_functions');
66 }
67
68 /**
69 * Generates the JavaScript code for the frameset.
70 */
71 function generateJScode() {
72 global $BE_USER,$LANG;
73
74 $pt3=t3lib_div::dirname(t3lib_div::getIndpEnv('SCRIPT_NAME')).'/';
75 $goToModule_switch = $this->alt_menuObj->topMenu($this->loadModules->modules,0,"",4);
76 $fsMod = implode(chr(10),$this->alt_menuObj->fsMod);
77
78 $this->mainJScode='
79 /**
80 * Function similar to PHPs rawurlencode();
81 */
82 function rawurlencode(str) {
83 var output = escape(str);
84 output = str_replace("*","%2A", output);
85 output = str_replace("+","%2B", output);
86 output = str_replace("/","%2F", output);
87 output = str_replace("@","%40", output);
88 return output;
89 }
90
91 /**
92 * String-replace function
93 */
94 function str_replace(match,replace,string) {
95 var input = ""+string;
96 var matchStr = ""+match;
97 if (!matchStr) {return string;}
98 var output = "";
99 var pointer=0;
100 var pos = input.indexOf(matchStr);
101 while (pos!=-1) {
102 output+=""+input.substr(pointer, pos-pointer)+replace;
103 pointer=pos+matchStr.length;
104 pos = input.indexOf(match,pos+1);
105 }
106 output+=""+input.substr(pointer);
107 return output;
108 }
109
110 /**
111 * TypoSetup object.
112 */
113 function typoSetup () {
114 this.PATH_typo3 = "'.$pt3.'";
115 this.username = "'.$BE_USER->user['username'].'";
116 this.uniqueID = "'.t3lib_div::shortMD5(uniqid('')).'";
117 }
118 var TS = new typoSetup();
119
120 /**
121 * Functions for session-expiry detection:
122 */
123 function busy() {
124 this.loginRefreshed = busy_loginRefreshed;
125 this.checkLoginTimeout = busy_checkLoginTimeout;
126 this.openRefreshWindow = busy_OpenRefreshWindow;
127 this.busyloadTime=0;
128 this.openRefreshW=0;
129 }
130 function busy_loginRefreshed() {
131 var date = new Date();
132 this.busyloadTime = Math.floor(date.getTime()/1000);
133 this.openRefreshW=0;
134 }
135 function busy_checkLoginTimeout() {
136 var date = new Date();
137 var theTime = Math.floor(date.getTime()/1000);
138 if (theTime > this.busyloadTime+'.intval($BE_USER->auth_timeout_field).'-10) {
139 return true;
140 }
141 }
142 function busy_OpenRefreshWindow() {
143 vHWin=window.open("login_frameset.php","relogin","height=350,width=600,status=0,menubar=0");
144 vHWin.focus();
145 this.openRefreshW=1;
146 }
147 function busy_checkLoginTimeout_timer() {
148 if (busy.checkLoginTimeout()) {
149 if (!busy.openRefreshW && confirm('.$GLOBALS['LANG']->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.refresh_login')).')) {
150 busy.openRefreshWindow();
151 }
152 }
153 window.setTimeout("busy_checkLoginTimeout_timer();",10*1000);
154 }
155
156 /**
157 * Launcing information window for records/files (fileref as "table" argument)
158 */
159 function launchView(table,uid,bP) {
160 var backPath= bP ? bP : "";
161 var thePreviewWindow="";
162 thePreviewWindow = window.open(TS.PATH_typo3+"show_item.php?table="+escape(table)+"&uid="+escape(uid),"ShowItem"+TS.uniqueID,"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
163 if (thePreviewWindow && thePreviewWindow.focus) {
164 thePreviewWindow.focus();
165 }
166 }
167
168 /**
169 * Loads a URL in the topmenuFrame
170 */
171 function loadTopMenu(url) {
172 top.topmenuFrame.location = url;
173 }
174
175 /**
176 * Returns incoming URL (to a module) unless nextLoadModuleUrl is set. If that is the case nextLoadModuleUrl is returned (and cleared)
177 * Used by the shortcut frame to set a "intermediate URL"
178 */
179 var nextLoadModuleUrl="";
180 function getModuleUrl(inUrl) {
181 var nMU;
182 if (top.nextLoadModuleUrl) {
183 nMU=top.nextLoadModuleUrl;
184 top.nextLoadModuleUrl="";
185 return nMU;
186 } else {
187 return inUrl;
188 }
189 }
190
191 /**
192 * Print properties of an object
193 */
194 function debugObj(obj,name) {
195 var acc;
196 for (i in obj) {
197 if (obj[i]) {
198 acc+=i+": "+obj[i]+"\n";
199 }
200 }
201 alert("Object: "+name+"\n\n"+acc);
202 }
203
204 /**
205 * Initialize login expiration warning object
206 */
207 var busy = new busy();
208 busy.loginRefreshed();
209 busy_checkLoginTimeout_timer();
210
211 /**
212 * Function used to switch switch module.
213 */
214 var currentModuleLoaded = "";
215 function goToModule(modName,cMR_flag) {
216 var cMR = 0;
217 if (cMR_flag) cMR=1;
218
219 currentModuleLoaded=modName;
220
221 switch(modName) {'.$goToModule_switch.'
222 }
223 }
224
225 /**
226 * Frameset Module object
227 *
228 * Used in main modules with a frameset for submodules to keep the ID between modules
229 * Typically that is set by something like this in a Web>* sub module:
230 * if (top.fsMod) top.fsMod.recentIds["web"] = "\'.intval($this->id).\'";
231 * if (top.fsMod) top.fsMod.recentIds["file"] = "...(file reference/string)...";
232 */
233 function fsModules() {
234 this.recentIds=new Array();
235 this.currentMainLoaded="";
236 }
237 var fsMod = new fsModules();
238 '.$fsMod.'
239
240 // Used by Frameset Modules
241 var condensedMode = '.($BE_USER->uc['condensedMode']?1:0).';
242 var currentSubScript = "";
243 ';
244 }
245
246 /**
247 * Creates the header and frameset of the backend interface
248 */
249 function main() {
250 global $BE_USER,$TYPO3_CONF_VARS,$TYPO_VERSION;
251
252 // Set doktype:
253 $GLOBALS["TBE_TEMPLATE"]->docType="xhtml_frames";
254
255 // Make JS:
256 $this->generateJScode();
257 $GLOBALS["TBE_TEMPLATE"]->JScode= '
258 <script type="text/javascript" src="md5.js"></script>
259 <script type="text/javascript" src="t3lib/jsfunc.evalfield.js"></script>
260 <script type="text/javascript">
261 /*<![CDATA[*/
262
263 '.$this->mainJScode.'
264
265 /*]]>*/
266 </script>';
267
268 // Title:
269 $title = $TYPO3_CONF_VARS['SYS']['sitename'] ? $TYPO3_CONF_VARS['SYS']['sitename'].' [TYPO3 '.$TYPO_VERSION.']' : 'TYPO3 '.$TYPO_VERSION;
270
271 // Start page header:
272 $this->content.=$GLOBALS["TBE_TEMPLATE"]->startPage($title);
273
274 // Creates frameset
275 $fr_content = '<frame name="content" src="'.($BE_USER->uc['startInTaskCenter']&&t3lib_extMgm::isLoaded('taskcenter')?t3lib_extMgm::extRelPath('taskcenter').'task/frameset.php':'alt_intro.php').'" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />';
276 $fr_toplogo = '<frame name="toplogo" src="alt_toplogo.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
277 $fr_topmenu = '<frame name="topmenuFrame" src="alt_topmenu_dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
278
279 $shortcutFrame=array();
280 if ($BE_USER->getTSConfigVal('options.shortcutFrame')) {
281 $shortcutFrame['rowH']=',30';
282 $shortcutFrame['frameDef']='<frame name="shortcutFrame" src="alt_shortcut.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />';
283 }
284
285 // XHTML notice: ' framespacing="0" frameborder="0" border="0"' in FRAMESET elements breaks compatibility with XHTML-frames, but HOW ELSE can I control the visual appearance?
286 if ($GLOBALS['BE_USER']->uc['noMenuMode']) {
287 $this->content.= '
288 <frameset rows="32,*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
289 '.(!strcmp($BE_USER->uc['noMenuMode'],'icons') ? '
290 <frameset cols="130,*" framespacing="0" frameborder="0" border="0">
291 '.$fr_toplogo.'
292 '.$fr_topmenu.'
293 </frameset>' : '
294 <frameset cols="130,130,*" framespacing="0" frameborder="0" border="0">
295 '.$fr_toplogo.'
296 <frame name="menu" src="alt_menu_sel.php" scrolling="no" noresize="noresize" />
297 '.$fr_topmenu.'
298 </frameset>').'
299 '.$fr_content.'
300 '.$shortcutFrame['frameDef'].'
301 </frameset>
302 ';
303 } else {
304 $this->content.='
305 <frameset rows="32,*'.$shortcutFrame['rowH'].'" framespacing="0" frameborder="0" border="0">
306 <frameset cols="130,*" framespacing="0" frameborder="0" border="0">
307 '.$fr_toplogo.'
308 '.$fr_topmenu.'
309 </frameset>
310 <frameset cols="130,*" framespacing="0" frameborder="0" border="0">
311 <frame name="menu" src="alt_menu.php" marginwidth="0" marginheight="0" scrolling="auto" noresize="noresize" />
312 '.$fr_content.'
313 </frameset>
314 '.$shortcutFrame['frameDef'].'
315 </frameset>
316 ';
317 }
318 $this->content.='
319
320 </html>';
321 }
322
323 /**
324 * Outputs it all.
325 */
326 function printContent() {
327 echo $this->content;
328 }
329 }
330
331 // Include extension?
332 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']) {
333 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_main.php']);
334 }
335
336
337
338
339
340
341
342
343
344
345
346 // ******************************
347 // Starting document output
348 // ******************************
349
350 // Make instance:
351 $SOBE = t3lib_div::makeInstance('SC_alt_main');
352 $SOBE->init();
353 $SOBE->main();
354 $SOBE->printContent();
355
356 ?>