* Merging all changes from TYPO3_4-0 branch back into HEAD
[Packages/TYPO3.CMS.git] / typo3 / template.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@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 * Contains class with layout/output function for TYPO3 Backend Scripts
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32 * XHTML-trans compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 * 145: function fw($str)
40 *
41 *
42 * 169: class template
43 * 224: function template()
44 *
45 * SECTION: EVALUATION FUNCTIONS
46 * 298: function wrapClickMenuOnIcon($str,$table,$uid='',$listFr=1,$addParams='',$enDisItems='', $returnOnClick=FALSE)
47 * 315: function viewPageIcon($id,$backPath,$addParams='hspace="3"')
48 * 341: function issueCommand($params,$rUrl='')
49 * 356: function isCMlayers()
50 * 366: function thisBlur()
51 * 376: function helpStyle()
52 * 393: function getHeader($table,$row,$path,$noViewPageIcon=0,$tWrap=array('',''))
53 * 419: function getFileheader($title,$path,$iconfile)
54 * 434: function makeShortcutIcon($gvList,$setList,$modName,$motherModName="")
55 * 467: function makeShortcutUrl($gvList,$setList)
56 * 488: function formWidth($size=48,$textarea=0,$styleOverride='')
57 * 513: function formWidthText($size=48,$styleOverride='',$wrap='')
58 * 530: function redirectUrls($thisLocation='')
59 * 554: function formatTime($tstamp,$type)
60 * 571: function parseTime()
61 *
62 * SECTION: PAGE BUILDING FUNCTIONS.
63 * 604: function startPage($title)
64 * 686: function endPage()
65 * 720: function header($text)
66 * 741: function section($label,$text,$nostrtoupper=FALSE,$sH=FALSE,$type=0,$allowHTMLinHeader=FALSE)
67 * 765: function divider($dist)
68 * 781: function spacer($dist)
69 * 800: function sectionHeader($label,$sH=FALSE,$addAttrib='')
70 * 817: function sectionBegin()
71 * 838: function sectionEnd()
72 * 858: function middle()
73 * 867: function endPageJS()
74 * 884: function docBodyTagBegin()
75 * 894: function docStyle()
76 * 936: function insertStylesAndJS($content)
77 * 956: function initCharset()
78 * 968: function generator()
79 *
80 * SECTION: OTHER ELEMENTS
81 * 1001: function icons($type, $styleAttribValue='')
82 * 1030: function t3Button($onClick,$label)
83 * 1041: function dfw($string)
84 * 1051: function rfw($string)
85 * 1061: function wrapInCData($string)
86 * 1078: function wrapScriptTags($string, $linebreak=TRUE)
87 * 1117: function table($arr, $layout='')
88 * 1159: function menuTable($arr1,$arr2=array(), $arr3=array())
89 * 1192: function funcMenu($content,$menu)
90 * 1210: function clearCacheMenu($id,$addSaveOptions=0)
91 * 1246: function getContextMenuCode()
92 * 1251: function showClickmenu(table, uid, listFr, enDisItems, backPath, addParams)
93 * 1280: function showClickmenu_noajax(url)
94 * 1287: function showClickmenu_ajax(t3ajax)
95 * 1472: function getDragDropCode($table)
96 * 1483: function cancelDragEvent(event)
97 * 1496: function mouseMoveEvent (event)
98 * 1509: function dragElement(id,elementID)
99 * 1528: function dropElement(id)
100 * 1577: function getTabMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='')
101 * 1607: function getTabMenuRaw($menuItems)
102 * 1676: function getDynTabMenu($menuItems,$identString,$toggle=0,$foldout=FALSE,$newRowCharLimit=50,$noWrap=1,$fullWidth=FALSE,$defaultTabIndex=1)
103 * 1801: function getDynTabMenuJScode()
104 * 1892: function getVersionSelector($id,$noAction=FALSE)
105 *
106 *
107 * 2060: class bigDoc extends template
108 *
109 *
110 * 2069: class noDoc extends template
111 *
112 *
113 * 2078: class smallDoc extends template
114 *
115 *
116 * 2087: class mediumDoc extends template
117 *
118 * TOTAL FUNCTIONS: 57
119 * (This index is automatically created/updated by the extension "extdeveval")
120 *
121 */
122
123
124
125 if (!defined('TYPO3_MODE')) die("Can't include this file directly.");
126
127 require_once(PATH_t3lib.'class.t3lib_ajax.php');
128
129
130
131
132
133
134
135
136
137
138 /**
139 * Deprecated fontwrap function. Is just transparent now.
140 *
141 * @param string Input string
142 * @return string Output string (in the old days this was wrapped in <font> tags)
143 * @deprecated
144 */
145 function fw($str) {
146 return $str;
147 }
148
149
150 /**
151 * TYPO3 Backend Template Class
152 *
153 * This class contains functions for starting and ending the HTML of backend modules
154 * It also contains methods for outputting sections of content.
155 * Further there are functions for making icons, links, setting form-field widths etc.
156 * Color scheme and stylesheet definitions are also available here.
157 * Finally this file includes the language class for TYPO3's backend.
158 *
159 * After this file $LANG and $TBE_TEMPLATE are global variables / instances of their respective classes.
160 * This file is typically included right after the init.php file,
161 * if language and layout is needed.
162 *
163 * Please refer to Inside TYPO3 for a discussion of how to use this API.
164 *
165 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
166 * @package TYPO3
167 * @subpackage core
168 */
169 class template {
170
171 // Vars you typically might want to/should set from outside after making instance of this class:
172 var $backPath = ''; // 'backPath' pointing back to the PATH_typo3
173 var $form=''; // This can be set to the HTML-code for a formtag. Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
174 var $JScode=''; // Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
175 var $JScodeArray = array(); // Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
176 var $postCode=''; // Additional 'page-end' code could be accommulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
177 var $docType = ''; // Doc-type used in the header. Default is HTML 4. You can also set it to 'strict', 'xhtml_trans', or 'xhtml_frames'.
178
179 // Other vars you can change, but less frequently used:
180 var $scriptID=''; // Script ID.
181 var $bodyTagId=''; // Id which can be set for the body tag. Default value is based on script ID
182 var $bodyTagAdditions=''; // You can add additional attributes to the body-tag through this variable.
183 var $inDocStyles=''; // Additional CSS styles which will be added to the <style> section in the header
184 var $inDocStylesArray=array(); // Like $inDocStyles but for use as array with associative keys to prevent double inclusion of css code
185 var $form_rowsToStylewidth = 9.58; // Multiplication factor for formWidth() input size (default is 48* this value).
186 var $form_largeComp = 1.33; // Compensation for large documents (used in class.t3lib_tceforms.php)
187 var $endJS=1; // If set, then a JavaScript section will be outputted in the bottom of page which will try and update the top.busy session expiry object.
188
189 // TYPO3 Colorscheme.
190 // If you want to change this, please do so through a skin using the global var $TBE_STYLES
191 var $bgColor = '#F7F3EF'; // Light background color
192 var $bgColor2 = '#9BA1A8'; // Steel-blue
193 var $bgColor3 = '#F6F2E6'; // dok.color
194 var $bgColor4 = '#D9D5C9'; // light tablerow background, brownish
195 var $bgColor5 = '#ABBBB4'; // light tablerow background, greenish
196 var $bgColor6 = '#E7DBA8'; // light tablerow background, yellowish, for section headers. Light.
197 var $hoverColor = '#254D7B';
198 var $styleSheetFile = 'stylesheet.css'; // Filename of stylesheet (relative to PATH_typo3)
199 var $styleSheetFile2 = ''; // Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
200 var $styleSheetFile_post = ''; // Filename of a post-stylesheet - included right after all inline styles.
201 var $backGroundImage = ''; // Background image of page (relative to PATH_typo3)
202 var $inDocStyles_TBEstyle = ''; // Inline css styling set from TBE_STYLES array
203
204 // DEV:
205 var $parseTimeFlag = 0; // Will output the parsetime of the scripts in milliseconds (for admin-users). Set this to false when releasing TYPO3. Only for dev.
206
207 // INTERNAL
208 var $charset = 'iso-8859-1'; // Default charset. see function initCharset()
209
210 var $sectionFlag=0; // Internal: Indicates if a <div>-output section is open
211 var $divClass = ''; // (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
212
213
214
215
216
217
218 /**
219 * Constructor
220 * Imports relevant parts from global $TBE_STYLES (colorscheme)
221 *
222 * @return void
223 */
224 function template() {
225 global $TBE_STYLES;
226
227 // Setting default scriptID:
228 $this->scriptID = ereg_replace('^.*\/(sysext|ext)\/','ext/',substr(PATH_thisScript,strlen(PATH_site)));
229 if (TYPO3_mainDir!='typo3/' && substr($this->scriptID,0,strlen(TYPO3_mainDir)) == TYPO3_mainDir) {
230 $this->scriptID = 'typo3/'.substr($this->scriptID,strlen(TYPO3_mainDir)); // This fixes if TYPO3_mainDir has been changed so the script ids are STILL "typo3/..."
231 }
232
233 $this->bodyTagId = ereg_replace('[^[:alnum:]-]','-',$this->scriptID);
234
235 // Individual configuration per script? If so, make a recursive merge of the arrays:
236 if (is_array($TBE_STYLES['scriptIDindex'][$this->scriptID])) {
237 $ovr = $TBE_STYLES['scriptIDindex'][$this->scriptID]; // Make copy
238 $TBE_STYLES = t3lib_div::array_merge_recursive_overrule($TBE_STYLES,$ovr); // merge styles.
239 unset($TBE_STYLES['scriptIDindex'][$this->scriptID]); // Have to unset - otherwise the second instantiation will do it again!
240 }
241
242 // Color scheme:
243 if ($TBE_STYLES['mainColors']['bgColor']) $this->bgColor=$TBE_STYLES['mainColors']['bgColor'];
244 if ($TBE_STYLES['mainColors']['bgColor1']) $this->bgColor1=$TBE_STYLES['mainColors']['bgColor1'];
245 if ($TBE_STYLES['mainColors']['bgColor2']) $this->bgColor2=$TBE_STYLES['mainColors']['bgColor2'];
246 if ($TBE_STYLES['mainColors']['bgColor3']) $this->bgColor3=$TBE_STYLES['mainColors']['bgColor3'];
247 if ($TBE_STYLES['mainColors']['bgColor4']) $this->bgColor4=$TBE_STYLES['mainColors']['bgColor4'];
248 if ($TBE_STYLES['mainColors']['bgColor5']) $this->bgColor5=$TBE_STYLES['mainColors']['bgColor5'];
249 if ($TBE_STYLES['mainColors']['bgColor6']) $this->bgColor6=$TBE_STYLES['mainColors']['bgColor6'];
250 if ($TBE_STYLES['mainColors']['hoverColor']) $this->hoverColor=$TBE_STYLES['mainColors']['hoverColor'];
251
252 // Main Stylesheets:
253 if ($TBE_STYLES['stylesheet']) $this->styleSheetFile = $TBE_STYLES['stylesheet'];
254 if ($TBE_STYLES['stylesheet2']) $this->styleSheetFile2 = $TBE_STYLES['stylesheet2'];
255 if ($TBE_STYLES['styleSheetFile_post']) $this->styleSheetFile_post = $TBE_STYLES['styleSheetFile_post'];
256 if ($TBE_STYLES['inDocStyles_TBEstyle']) $this->inDocStyles_TBEstyle = $TBE_STYLES['inDocStyles_TBEstyle'];
257
258 // Background image
259 if ($TBE_STYLES['background']) $this->backGroundImage = $TBE_STYLES['background'];
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277 /*****************************************
278 *
279 * EVALUATION FUNCTIONS
280 * Various centralized processing
281 *
282 *****************************************/
283
284 /**
285 * Makes click menu link (context sensitive menu)
286 * Returns $str (possibly an <|img> tag/icon) wrapped in a link which will activate the context sensitive menu for the record ($table/$uid) or file ($table = file)
287 * The link will load the top frame with the parameter "&item" which is the table,uid and listFr arguments imploded by "|": rawurlencode($table.'|'.$uid.'|'.$listFr)
288 *
289 * @param string String to be wrapped in link, typ. image tag.
290 * @param string Table name/File path. If the icon is for a database record, enter the tablename from $TCA. If a file then enter the absolute filepath
291 * @param integer If icon is for database record this is the UID for the record from $table
292 * @param boolean Tells the top frame script that the link is coming from a "list" frame which means a frame from within the backend content frame.
293 * @param string Additional GET parameters for the link to alt_clickmenu.php
294 * @param string Enable / Disable click menu items. Example: "+new,view" will display ONLY these two items (and any spacers in between), "new,view" will display all BUT these two items.
295 * @param boolean If set, will return only the onclick JavaScript, not the whole link.
296 * @return string The link-wrapped input string.
297 */
298 function wrapClickMenuOnIcon($str,$table,$uid='',$listFr=1,$addParams='',$enDisItems='', $returnOnClick=FALSE) {
299 $backPath = rawurlencode($this->backPath).'|'.t3lib_div::shortMD5($this->backPath.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
300 $onClick = 'showClickmenu("'.$table.'","'.$uid.'","'.$listFr.'","'.$enDisItems.'","'.str_replace('&','&amp;',addcslashes($backPath,'"')).'","'.str_replace('&','&amp;',addcslashes($addParams,'"')).'");return false;';
301 return $returnOnClick ? $onClick : '<a href="#" onclick="'.htmlspecialchars($onClick).'"'.($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler'] ? ' oncontextmenu="'.htmlspecialchars($onClick).'"' : '').'>'.$str.'</a>';
302 }
303
304 /**
305 * Makes link to page $id in frontend (view page)
306 * Returns an magnifier-glass icon which links to the frontend index.php document for viewing the page with id $id
307 * $id must be a page-uid
308 * If the BE_USER has access to Web>List then a link to that module is shown as well (with return-url)
309 *
310 * @param integer The page id
311 * @param string The current "BACK_PATH" (the back relative to the typo3/ directory)
312 * @param string Additional parameters for the image tag(s)
313 * @return string HTML string with linked icon(s)
314 */
315 function viewPageIcon($id,$backPath,$addParams='hspace="3"') {
316 global $BE_USER;
317 $str = '';
318 // If access to Web>List for user, then link to that module.
319 if ($BE_USER->check('modules','web_list')) {
320 $href=$backPath.'db_list.php?id='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
321 $str.= '<a href="'.htmlspecialchars($href).'">'.
322 '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/list.gif','width="11" height="11"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList',1).'"'.($addParams?' '.trim($addParams):'').' alt="" />'.
323 '</a>';
324 }
325 // Make link to view page
326 $str.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($id,$backPath,t3lib_BEfunc::BEgetRootLine($id))).'">'.
327 '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/zoom.gif','width="12" height="12"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage',1).'"'.($addParams?' '.trim($addParams):"").' hspace="3" alt="" />'.
328 '</a>';
329 return $str;
330 }
331
332 /**
333 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
334 * See description of the API elsewhere.
335 *
336 * @param string $params is a set of GET params to send to tce_db.php. Example: "&cmd[tt_content][123][move]=456" or "&data[tt_content][123][hidden]=1&data[tt_content][123][title]=Hello%20World"
337 * @param string Redirect URL if any other that t3lib_div::getIndpEnv('REQUEST_URI') is wished
338 * @return string URL to tce_db.php + parameters (backpath is taken from $this->backPath)
339 * @see t3lib_BEfunc::editOnClick()
340 */
341 function issueCommand($params,$rUrl='') {
342 $rUrl = $rUrl ? $rUrl : t3lib_div::getIndpEnv('REQUEST_URI');
343 return $this->backPath.'tce_db.php?'.
344 $params.
345 '&redirect='.($rUrl==-1?"'+T3_THIS_LOCATION+'":rawurlencode($rUrl)).
346 '&vC='.rawurlencode($GLOBALS['BE_USER']->veriCode()).
347 '&prErr=1&uPT=1';
348 }
349
350 /**
351 * Returns true if click-menu layers can be displayed for the current user/browser
352 * Use this to test if click-menus (context sensitive menus) can and should be displayed in the backend.
353 *
354 * @return boolean
355 */
356 function isCMlayers() {
357 return !$GLOBALS['BE_USER']->uc['disableCMlayers'] && $GLOBALS['CLIENT']['FORMSTYLE'] && !($GLOBALS['CLIENT']['SYSTEM']=='mac' && $GLOBALS['CLIENT']['BROWSER']=='Opera');
358 }
359
360 /**
361 * Returns 'this.blur();' if the client supports CSS styles
362 * Use this in links to remove the underlining after being clicked
363 *
364 * @return string
365 */
366 function thisBlur() {
367 return ($GLOBALS['CLIENT']['FORMSTYLE']?'this.blur();':'');
368 }
369
370 /**
371 * Returns ' style='cursor:help;'' if the client supports CSS styles
372 * Use for <a>-links to help texts
373 *
374 * @return string
375 */
376 function helpStyle() {
377 return $GLOBALS['CLIENT']['FORMSTYLE'] ? ' style="cursor:help;"':'';
378 }
379
380 /**
381 * Makes the header (icon+title) for a page (or other record). Used in most modules under Web>*
382 * $table and $row must be a tablename/record from that table
383 * $path will be shown as alt-text for the icon.
384 * The title will be truncated to 45 chars.
385 *
386 * @param string Table name
387 * @param array Record row
388 * @param string Alt text
389 * @param boolean Set $noViewPageIcon true if you don't want a magnifier-icon for viewing the page in the frontend
390 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
391 * @return string HTML content
392 */
393 function getHeader($table,$row,$path,$noViewPageIcon=0,$tWrap=array('','')) {
394 global $TCA;
395 if (is_array($row) && $row['uid']) {
396 $iconImgTag=t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'title="'.htmlspecialchars($path).'"');
397 $title= strip_tags($row[$TCA[$table]['ctrl']['label']]);
398 $viewPage = $noViewPageIcon ? '' : $this->viewPageIcon($row['uid'],$this->backPath,'');
399 if ($table=='pages') $path.=' - '.t3lib_BEfunc::titleAttribForPages($row,'',0);
400 } else {
401 $iconImgTag='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif',$wHattribs='width="18" height="16"').' title="'.htmlspecialchars($path).'" alt="" />';
402 $title=$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
403 }
404
405 return '<span class="typo3-moduleHeader">'.$this->wrapClickMenuOnIcon($iconImgTag,$table,$row['uid']).
406 $viewPage.
407 $tWrap[0].htmlspecialchars(t3lib_div::fixed_lgd_cs($title,45)).$tWrap[1].'</span>';
408 }
409
410 /**
411 * Like ->getHeader() but for files in the File>* main module/submodules
412 * Returns the file-icon with the path of the file set in the alt/title attribute. Shows the file-name after the icon.
413 *
414 * @param string Title string, expected to be the filepath
415 * @param string Alt text
416 * @param string The icon file (relative to TYPO3 dir)
417 * @return string HTML content
418 */
419 function getFileheader($title,$path,$iconfile) {
420 $fileInfo = t3lib_div::split_fileref($title);
421 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['path'],-35)).'<b>'.htmlspecialchars($fileInfo['file']).'</b>';
422 return '<span class="typo3-moduleHeader"><img'.t3lib_iconWorks::skinImg($this->backPath,$iconfile,'width="18" height="16"').' title="'.htmlspecialchars($path).'" alt="" />'.$title.'</span>';
423 }
424
425 /**
426 * Returns a linked shortcut-icon which will call the shortcut frame and set a shortcut there back to the calling page/module
427 *
428 * @param string Is the list of GET variables to store (if any)
429 * @param string Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
430 * @param string Module name string
431 * @param string Is used to enter the "parent module name" if the module is a submodule under eg. Web>* or File>*. You can also set this value to "1" in which case the currentLoadedModule is sent to the shortcut script (so - not a fixed value!) - that is used in file_edit.php and wizard_rte.php scripts where those scripts are really running as a part of another module.
432 * @return string HTML content
433 */
434 function makeShortcutIcon($gvList,$setList,$modName,$motherModName="") {
435 $backPath=$this->backPath;
436 $storeUrl=$this->makeShortcutUrl($gvList,$setList);
437 $pathInfo = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
438
439 if (!strcmp($motherModName,'1')) {
440 $mMN="&motherModName='+top.currentModuleLoaded+'";
441 } elseif ($motherModName) {
442 $mMN='&motherModName='.rawurlencode($motherModName);
443 } else $mMN='';
444
445 $onClick = 'if (top.shortcutFrame && confirm('.
446 $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeShortcut')).
447 ')){top.shortcutFrame.location.href=\''.$backPath.'alt_shortcut.php?modName='.rawurlencode($modName).
448 '&URL='.rawurlencode($pathInfo['path']."?".$storeUrl).
449 $mMN.
450 '\';}return false;';
451
452 $sIcon = '<a href="#" onclick="'.htmlspecialchars($onClick).'">
453 <img'.t3lib_iconWorks::skinImg($backPath,'gfx/shortcut.gif','width="14" height="14"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeShortcut',1).'" alt="" /></a>';
454 return $sIcon;
455 }
456
457 /**
458 * MAKE url for storing
459 * Internal func
460 *
461 * @param string Is the list of GET variables to store (if any)
462 * @param string Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
463 * @return string
464 * @access private
465 * @see makeShortcutIcon()
466 */
467 function makeShortcutUrl($gvList,$setList) {
468 $GET = t3lib_div::_GET();
469 $storeArray = array_merge(
470 t3lib_div::compileSelectedGetVarsFromArray($gvList,$GET),
471 array('SET'=>t3lib_div::compileSelectedGetVarsFromArray($setList,$GLOBALS['SOBE']->MOD_SETTINGS))
472 );
473 $storeUrl = t3lib_div::implodeArrayForUrl('',$storeArray);
474 return $storeUrl;
475 }
476
477 /**
478 * Returns <input> attributes to set the width of an text-type input field.
479 * For client browsers with no CSS support the cols/size attribute is returned.
480 * For CSS compliant browsers (recommended) a ' style="width: ...px;"' is returned.
481 *
482 * @param integer A relative number which multiplied with approx. 10 will lead to the width in pixels
483 * @param boolean A flag you can set for textareas - DEPRECATED, use ->formWidthText() for textareas!!!
484 * @param string A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
485 * @return string Tag attributes for an <input> tag (regarding width)
486 * @see formWidthText()
487 */
488 function formWidth($size=48,$textarea=0,$styleOverride='') {
489 $wAttrib = $textarea?'cols':'size';
490 if (!$GLOBALS['CLIENT']['FORMSTYLE']) { // If not setting the width by style-attribute
491 $size = $size;
492 $retVal = ' '.$wAttrib.'="'.$size.'"';
493 } else { // Setting width by style-attribute. 'cols' MUST be avoided with NN6+
494 $pixels = ceil($size*$this->form_rowsToStylewidth);
495 $retVal = $styleOverride ? ' style="'.$styleOverride.'"' : ' style="width:'.$pixels.'px;"';
496 }
497 return $retVal;
498 }
499
500 /**
501 * This function is dedicated to textareas, which has the wrapping on/off option to observe.
502 * EXAMPLE:
503 * <textarea rows="10" wrap="off" '.$GLOBALS["TBE_TEMPLATE"]->formWidthText(48,"","off").'>
504 * or
505 * <textarea rows="10" wrap="virtual" '.$GLOBALS["TBE_TEMPLATE"]->formWidthText(48,"","virtual").'>
506 *
507 * @param integer A relative number which multiplied with approx. 10 will lead to the width in pixels
508 * @param string A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
509 * @param string Pass on the wrap-attribute value you use in your <textarea>! This will be used to make sure that some browsers will detect wrapping alright.
510 * @return string Tag attributes for an <input> tag (regarding width)
511 * @see formWidth()
512 */
513 function formWidthText($size=48,$styleOverride='',$wrap='') {
514 $wTags = $this->formWidth($size,1,$styleOverride);
515 // Netscape 6+/Mozilla seems to have this ODD problem where there WILL ALWAYS be wrapping with the cols-attribute set and NEVER without the col-attribute...
516 if (strtolower(trim($wrap))!='off' && $GLOBALS['CLIENT']['BROWSER']=='net' && $GLOBALS['CLIENT']['VERSION']>=5) {
517 $wTags.=' cols="'.$size.'"';
518 }
519 return $wTags;
520 }
521
522 /**
523 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
524 * Used in fx. db_list.php (Web>List)
525 *
526 * @param string URL to "this location" / current script
527 * @return string
528 * @see typo3/db_list.php
529 */
530 function redirectUrls($thisLocation='') {
531 $thisLocation = $thisLocation?$thisLocation:t3lib_div::linkThisScript(
532 array(
533 'CB'=>'',
534 'SET'=>'',
535 'cmd' => '',
536 'popViewId'=>''
537 ));
538
539 $out ="
540 var T3_RETURN_URL = '".str_replace('%20','',rawurlencode(t3lib_div::_GP('returnUrl')))."';
541 var T3_THIS_LOCATION = '".str_replace('%20','',rawurlencode($thisLocation))."';
542 ";
543 return $out;
544 }
545
546 /**
547 * Returns a formatted string of $tstamp
548 * Uses $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] and $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] to format date and time
549 *
550 * @param integer UNIX timestamp, seconds since 1970
551 * @param integer How much data to show: $type = 1: hhmm, $type = 10: ddmmmyy
552 * @return string Formatted timestamp
553 */
554 function formatTime($tstamp,$type) {
555 $dateStr = '';
556 switch($type) {
557 case 1: $dateStr = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'],$tstamp);
558 break;
559 case 10: $dateStr = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
560 break;
561 }
562 return $dateStr;
563 }
564
565 /**
566 * Returns script parsetime IF ->parseTimeFlag is set and user is "admin"
567 * Automatically outputted in page end
568 *
569 * @return string
570 */
571 function parseTime() {
572 if ($this->parseTimeFlag && $GLOBALS['BE_USER']->isAdmin()) {
573 return '<p>(ParseTime: '.(t3lib_div::milliseconds()-$GLOBALS['PARSETIME_START']).' ms</p>
574 <p>REQUEST_URI-length: '.strlen(t3lib_div::getIndpEnv('REQUEST_URI')).')</p>';
575 }
576 }
577
578
579
580
581
582
583
584
585
586
587
588
589 /*****************************************
590 *
591 * PAGE BUILDING FUNCTIONS.
592 * Use this to build the HTML of your backend modules
593 *
594 *****************************************/
595
596 /**
597 * Returns page start
598 * This includes the proper header with charset, title, meta tag and beginning body-tag.
599 *
600 * @param string HTML Page title for the header
601 * @return string Returns the whole header section of a HTML-document based on settings in internal variables (like styles, javascript code, charset, generator and docType)
602 * @see endPage()
603 */
604 function startPage($title) {
605 // Get META tag containing the currently selected charset for backend output. The function sets $this->charSet.
606 $charSet = $this->initCharset();
607 $generator = $this->generator();
608
609 // For debugging: If this outputs "QuirksMode"/"BackCompat" (IE) the browser runs in quirks-mode. Otherwise the value is "CSS1Compat"
610 # $this->JScodeArray[]='alert(document.compatMode);';
611
612 // Send HTTP header for selected charset. Added by Robert Lemke 23.10.2003
613 header ('Content-Type:text/html;charset='.$this->charset);
614
615 switch($this->docType) {
616 case 'xhtml_strict':
617 $headerStart= '<!DOCTYPE html
618 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
619 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
620 <?xml version="1.0" encoding="'.$this->charset.'"?>
621 <?xml-stylesheet href="#internalStyle" type="text/css"?>
622 ';
623 break;
624 case 'xhtml_trans':
625 $headerStart= '<!DOCTYPE html
626 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
627 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
628 <?xml version="1.0" encoding="'.$this->charset.'"?>
629 <?xml-stylesheet href="#internalStyle" type="text/css"?>
630 ';
631 break;
632 case 'xhtml_frames':
633 $headerStart= '<!DOCTYPE html
634 PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
635 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
636 <?xml version="1.0" encoding="'.$this->charset.'"?>
637 ';
638 break;
639 default:
640 $headerStart='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
641 break;
642 }
643
644 $tabJScode = '';
645 if (!$BE_USER->uc['disableTabInTextarea']) {
646 // This loads the tabulator-in-textarea feature. It automatically modifies every textarea which is found.
647 $tabJScode = '<script src="'.$this->backPath.'tab.js" type="text/javascript"></script>';
648 }
649
650 // Construct page header.
651 $str = $headerStart.'
652 <html>
653 <head>
654 <!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->
655 '.$charSet.'
656 '.$generator.'
657 <title>'.htmlspecialchars($title).'</title>
658 '.$this->docStyle().'
659 '.$this->JScode.'
660 '.$tabJScode.'
661 '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).'
662 <!--###POSTJSMARKER###-->
663 </head>
664 ';
665 $this->JScode='';
666 $this->JScodeArray=array();
667
668 if ($this->docType=='xhtml_frames') {
669 return $str;
670 } else
671 $str.=$this->docBodyTagBegin().
672 ($this->divClass?'
673
674 <!-- Wrapping DIV-section for whole page BEGIN -->
675 <div class="'.$this->divClass.'">
676 ':'').trim($this->form);
677 return $str;
678 }
679
680 /**
681 * Returns page end; This includes finishing form, div, body and html tags.
682 *
683 * @return string The HTML end of a page
684 * @see startPage()
685 */
686 function endPage() {
687 $str = $this->sectionEnd().
688 $this->postCode.
689 $this->endPageJS().
690 t3lib_BEfunc::getSetUpdateSignal().
691 $this->parseTime().
692 ($this->form?'
693 </form>':'');
694
695 if ($this->docType!='xhtml_frames') {
696
697 $str .= ($this->divClass?'
698
699 <!-- Wrapping DIV-section for whole page END -->
700 </div>':'').'
701 </body> ';
702
703 }
704
705 $str .= '</html>';
706
707 // Logging: Can't find better place to put it:
708 if (TYPO3_DLOG) t3lib_div::devLog('END of BACKEND session','',0,array('_FLUSH'=>TRUE));
709
710 return $str;
711 }
712
713 /**
714 * Returns the header-bar in the top of most backend modules
715 * Closes section if open.
716 *
717 * @param string The text string for the header
718 * @return string HTML content
719 */
720 function header($text) {
721 $str='
722
723 <!-- MAIN Header in page top -->
724 <h2>'.htmlspecialchars($text).'</h2>
725 ';
726 return $this->sectionEnd().$str;
727 }
728
729 /**
730 * Begins an output section and sets header and content
731 *
732 * @param string The header
733 * @param string The HTML-content
734 * @param boolean A flag that will prevent the header from being converted to uppercase
735 * @param boolean Defines the type of header (if set, "<h3>" rather than the default "h4")
736 * @param integer The number of an icon to show with the header (see the icon-function). -1,1,2,3
737 * @param boolean If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
738 * @return string HTML content
739 * @see icons(), sectionHeader()
740 */
741 function section($label,$text,$nostrtoupper=FALSE,$sH=FALSE,$type=0,$allowHTMLinHeader=FALSE) {
742 $str='';
743
744 // Setting header
745 if ($label) {
746 if (!$allowHTMLinHeader) $label = htmlspecialchars($label);
747 $str.=$this->sectionHeader($this->icons($type).$label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
748 }
749 // Setting content
750 $str.='
751
752 <!-- Section content -->
753 '.$text;
754
755 return $this->sectionBegin().$str;
756 }
757
758 /**
759 * Inserts a divider image
760 * Ends a section (if open) before inserting the image
761 *
762 * @param integer The margin-top/-bottom of the <hr> ruler.
763 * @return string HTML content
764 */
765 function divider($dist) {
766 $dist = intval($dist);
767 $str='
768
769 <!-- DIVIDER -->
770 <hr style="margin-top: '.$dist.'px; margin-bottom: '.$dist.'px;" />
771 ';
772 return $this->sectionEnd().$str;
773 }
774
775 /**
776 * Returns a blank <div>-section with a height
777 *
778 * @param integer Padding-top for the div-section (should be margin-top but konqueror (3.1) doesn't like it :-(
779 * @return string HTML content
780 */
781 function spacer($dist) {
782 if ($dist>0) {
783 return '
784
785 <!-- Spacer element -->
786 <div style="padding-top: '.intval($dist).'px;"></div>
787 ';
788 }
789 }
790
791 /**
792 * Make a section header.
793 * Begins a section if not already open.
794 *
795 * @param string The label between the <h3> or <h4> tags. (Allows HTML)
796 * @param boolean If set, <h3> is used, otherwise <h4>
797 * @param string Additional attributes to h-tag, eg. ' class=""'
798 * @return string HTML content
799 */
800 function sectionHeader($label,$sH=FALSE,$addAttrib='') {
801 $tag = ($sH?'h3':'h4');
802 $str='
803
804 <!-- Section header -->
805 <'.$tag.$addAttrib.'>'.$label.'</'.$tag.'>
806 ';
807 return $this->sectionBegin().$str;
808 }
809
810 /**
811 * Begins an output section.
812 * Returns the <div>-begin tag AND sets the ->sectionFlag true (if the ->sectionFlag is not already set!)
813 * You can call this function even if a section is already begun since the function will only return something if the sectionFlag is not already set!
814 *
815 * @return string HTML content
816 */
817 function sectionBegin() {
818 if (!$this->sectionFlag) {
819 $this->sectionFlag=1;
820 $str='
821
822 <!-- ***********************
823 Begin output section.
824 *********************** -->
825 <div>
826 ';
827 return $str;
828 } else return '';
829 }
830
831 /**
832 * Ends and output section
833 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
834 * See sectionBegin() also.
835 *
836 * @return string HTML content
837 */
838 function sectionEnd() {
839 if ($this->sectionFlag) {
840 $this->sectionFlag=0;
841 return '
842 </div>
843 <!-- *********************
844 End output section.
845 ********************* -->
846 ';
847 } else return '';
848 }
849
850 /**
851 * Originally it printed a kind of divider.
852 * Deprecated. Just remove function calls to it or call the divider() function instead.
853 *
854 * @return void
855 * @internal
856 * @deprecated
857 */
858 function middle() {
859 }
860
861 /**
862 * If a form-tag is defined in ->form then and end-tag for that <form> element is outputted
863 * Further a JavaScript section is outputted which will update the top.busy session-expiry object (unless $this->endJS is set to false)
864 *
865 * @return string HTML content (<script> tag section)
866 */
867 function endPageJS() {
868 return ($this->endJS?'
869 <script type="text/javascript">
870 /*<![CDATA[*/
871 if (top.busy && top.busy.loginRefreshed) {
872 top.busy.loginRefreshed();
873 }
874 /*]]>*/
875 </script>':'');
876 }
877
878 /**
879 * Creates the bodyTag.
880 * You can add to the bodyTag by $this->bodyTagAdditions
881 *
882 * @return string HTML body tag
883 */
884 function docBodyTagBegin() {
885 $bodyContent = 'body '.trim($this->bodyTagAdditions.($this->bodyTagId ? ' id="'.$this->bodyTagId.'"' : ''));
886 return '<'.trim($bodyContent).'>';
887 }
888
889 /**
890 * Outputting document style
891 *
892 * @return string HTML style section/link tags
893 */
894 function docStyle() {
895
896 // Request background image:
897 if ($this->backGroundImage) {
898 $this->inDocStylesArray[]=' BODY { background-image: url('.$this->backPath.$this->backGroundImage.'); }';
899 }
900
901 // Add inDoc styles variables as well:
902 $this->inDocStylesArray[] = $this->inDocStyles;
903 $this->inDocStylesArray[] = $this->inDocStyles_TBEstyle;
904
905 // Implode it all:
906 $inDocStyles = implode('
907 ',$this->inDocStylesArray);
908
909 // The default color scheme should also in full be represented in the stylesheet.
910 $style=trim('
911 '.($this->styleSheetFile?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile.'" />':'').'
912 '.($this->styleSheetFile2?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile2.'" />':'').'
913 <style type="text/css" id="internalStyle">
914 /*<![CDATA[*/
915 '.trim($inDocStyles).'
916 /*###POSTCSSMARKER###*/
917 /*]]>*/
918 </style>
919 '.($this->styleSheetFile_post?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile_post.'" />':'')
920 )
921 ;
922 $this->inDocStyles='';
923 $this->inDocStylesArray=array();
924
925 return '
926 '.$style;
927 }
928
929 /**
930 * Insert post rendering document style into already rendered content
931 * This is needed for extobjbase
932 *
933 * @param string style-content to insert.
934 * @return string content with inserted styles
935 */
936 function insertStylesAndJS($content) {
937 // insert accumulated CSS
938 $this->inDocStylesArray[] = $this->inDocStyles;
939 $styles = "\n".implode("\n", $this->inDocStylesArray);
940 $content = str_replace('/*###POSTCSSMARKER###*/',$styles,$content);
941
942 // insert accumulated JS
943 $jscode = $this->JScode."\n".$this->wrapScriptTags(implode("\n", $this->JScodeArray));
944 $content = str_replace('<!--###POSTJSMARKER###-->',$jscode,$content);
945
946 return $content;
947 }
948
949 /**
950 * Initialize the charset.
951 * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
952 * Returns the meta-tag for the document header
953 *
954 * @return string <meta> tag with charset from $this->charset or $GLOBALS['LANG']->charSet
955 */
956 function initCharset() {
957 // Set charset to the charset provided by the current backend users language selection:
958 $this->charset = $GLOBALS['LANG']->charSet ? $GLOBALS['LANG']->charSet : $this->charset;
959 // Return meta tag:
960 return '<meta http-equiv="Content-Type" content="text/html; charset='.$this->charset.'" />';
961 }
962
963 /**
964 * Returns generator meta tag
965 *
966 * @return string <meta> tag with name "generator"
967 */
968 function generator() {
969 $str = 'TYPO3 '.TYPO3_branch.', http://typo3.com, &#169; Kasper Sk&#229;rh&#248;j 1998-2006, extensions are copyright of their respective owners.';
970 return '<meta name="generator" content="'.$str .'" />';
971 }
972
973
974
975
976
977
978
979
980 /*****************************************
981 *
982 * OTHER ELEMENTS
983 * Tables, buttons, formatting dimmed/red strings
984 *
985 ******************************************/
986
987
988 /**
989 * Returns an image-tag with an 18x16 icon of the following types:
990 *
991 * $type:
992 * -1: OK icon (Check-mark)
993 * 1: Notice (Speach-bubble)
994 * 2: Warning (Yellow triangle)
995 * 3: Fatal error (Red stop sign)
996 *
997 * @param integer See description
998 * @param string Value for style attribute
999 * @return string HTML image tag (if applicable)
1000 */
1001 function icons($type, $styleAttribValue='') {
1002 switch($type) {
1003 case '3':
1004 $icon = 'gfx/icon_fatalerror.gif';
1005 break;
1006 case '2':
1007 $icon = 'gfx/icon_warning.gif';
1008 break;
1009 case '1':
1010 $icon = 'gfx/icon_note.gif';
1011 break;
1012 case '-1':
1013 $icon = 'gfx/icon_ok.gif';
1014 break;
1015 default:
1016 break;
1017 }
1018 if ($icon) {
1019 return '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' class="absmiddle"'.($styleAttribValue ? ' style="'.htmlspecialchars($styleAttribValue).'"' : '').' alt="" />';
1020 }
1021 }
1022
1023 /**
1024 * Returns an <input> button with the $onClick action and $label
1025 *
1026 * @param string The value of the onclick attribute of the input tag (submit type)
1027 * @param string The label for the button (which will be htmlspecialchar'ed)
1028 * @return string A <input> tag of the type "submit"
1029 */
1030 function t3Button($onClick,$label) {
1031 $button = '<input type="submit" onclick="'.htmlspecialchars($onClick).'; return false;" value="'.htmlspecialchars($label).'" />';
1032 return $button;
1033 }
1034
1035 /**
1036 * dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
1037 *
1038 * @param string Input string
1039 * @return string Output string
1040 */
1041 function dfw($string) {
1042 return '<span class="typo3-dimmed">'.$string.'</span>';
1043 }
1044
1045 /**
1046 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1047 *
1048 * @param string Input string
1049 * @return string Output string
1050 */
1051 function rfw($string) {
1052 return '<span class="typo3-red">'.$string.'</span>';
1053 }
1054
1055 /**
1056 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1057 *
1058 * @param string Input string
1059 * @return string Output string
1060 */
1061 function wrapInCData($string) {
1062 $string = '/*<![CDATA[*/'.
1063 $string.
1064 '/*]]>*/';
1065
1066 return $string;
1067 }
1068
1069 /**
1070 * Wraps the input string in script tags.
1071 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1072 * This is nice for identing JS code with PHP code on the same level.
1073 *
1074 * @param string Input string
1075 * @param boolean Wrap script element in linebreaks? Default is TRUE.
1076 * @return string Output string
1077 */
1078 function wrapScriptTags($string, $linebreak=TRUE) {
1079 if(trim($string)) {
1080 // <script wrapped in nl?
1081 $cr = $linebreak? "\n" : '';
1082
1083 // remove nl from the beginning
1084 $string = preg_replace ('/^\n+/', '', $string);
1085 // re-ident to one tab using the first line as reference
1086 $match = array();
1087 if(preg_match('/^(\t+)/',$string,$match)) {
1088 $string = str_replace($match[1],"\t", $string);
1089 }
1090 $string = $cr.'<script type="text/javascript">
1091 /*<![CDATA[*/
1092 '.$string.'
1093 /*]]>*/
1094 </script>'.$cr;
1095 }
1096 return trim($string);
1097 }
1098
1099 // These vars defines the layout for the table produced by the table() function.
1100 // You can override these values from outside if you like.
1101 var $tableLayout = Array (
1102 'defRow' => Array (
1103 'defCol' => Array('<td valign="top">','</td>')
1104 )
1105 );
1106 var $table_TR = '<tr>';
1107 var $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-tmpltable">';
1108
1109 /**
1110 * Returns a table based on the input $arr
1111 *
1112 * @param array Multidim array with first levels = rows, second levels = cells
1113 * @param array If set, then this provides an alternative layout array instead of $this->tableLayout
1114 * @return string The HTML table.
1115 * @internal
1116 */
1117 function table($arr, $layout='') {
1118 if (is_array($arr)) {
1119 $tableLayout = (is_array($layout)) ? $layout : $this->tableLayout;
1120
1121 reset($arr);
1122 $code='';
1123 $rc=0;
1124 while(list(,$val)=each($arr)) {
1125 if ($rc % 2) {
1126 $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
1127 } else {
1128 $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
1129 }
1130 $layoutRow = is_array($tableLayout[$rc]) ? $tableLayout[$rc] : $layout;
1131 $code_td='';
1132 if (is_array($val)) {
1133 $cc=0;
1134 while(list(,$content)=each($val)) {
1135 $wrap= is_array($layoutRow[$cc]) ? $layoutRow[$cc] : (is_array($layoutRow['defCol']) ? $layoutRow['defCol'] : (is_array($layout[$cc]) ? $layout[$cc] : $layout['defCol']));
1136 $code_td.=$wrap[0].$content.$wrap[1];
1137 $cc++;
1138 }
1139 }
1140 $trWrap = is_array($layoutRow['tr']) ? $layoutRow['tr'] : (is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>'));
1141 $code.=$trWrap[0].$code_td.$trWrap[1];
1142 $rc++;
1143 }
1144 $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
1145 $code=$tableWrap[0].$code.$tableWrap[1];
1146 }
1147 return $code;
1148 }
1149
1150 /**
1151 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1152 * Used in eg. ext/belog/mod/index.php - refer to that for examples
1153 *
1154 * @param array Menu elements on first level
1155 * @param array Secondary items
1156 * @param array Third-level items
1157 * @return string HTML content, <table>...</table>
1158 */
1159 function menuTable($arr1,$arr2=array(), $arr3=array()) {
1160 $rows = max(array(count($arr1),count($arr2),count($arr3)));
1161
1162 $menu='
1163 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1164 for($a=0;$a<$rows;$a++) {
1165 $menu.='<tr>';
1166 $cls=array();
1167 $valign='middle';
1168 $cls[]='<td valign="'.$valign.'">'.$arr1[$a][0].'</td><td>'.$arr1[$a][1].'</td>';
1169 if (count($arr2)) {
1170 $cls[]='<td valign="'.$valign.'">'.$arr2[$a][0].'</td><td>'.$arr2[$a][1].'</td>';
1171 if (count($arr3)) {
1172 $cls[]='<td valign="'.$valign.'">'.$arr3[$a][0].'</td><td>'.$arr3[$a][1].'</td>';
1173 }
1174 }
1175 $menu.=implode($cls,'<td>&nbsp;&nbsp;</td>');
1176 $menu.='</tr>';
1177 }
1178 $menu.='
1179 </table>
1180 ';
1181 return $menu;
1182 }
1183
1184 /**
1185 * Returns a one-row/two-celled table with $content and $menu side by side.
1186 * The table is a 100% width table and each cell is aligned left / right
1187 *
1188 * @param string Content cell content (left)
1189 * @param string Menu cell content (right)
1190 * @return string HTML output
1191 */
1192 function funcMenu($content,$menu) {
1193 return '
1194 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1195 <tr>
1196 <td valign="top" nowrap="nowrap">'.$content.'</td>
1197 <td valign="top" align="right" nowrap="nowrap">'.$menu.'</td>
1198 </tr>
1199 </table>';
1200 }
1201
1202 /**
1203 * Creates a selector box with clear-cache items.
1204 * Rather specialized functions - at least don't use it with $addSaveOptions unless you know what you do...
1205 *
1206 * @param integer The page uid of the "current page" - the one that will be cleared as "clear cache for this page".
1207 * @param boolean If $addSaveOptions is set, then also the array of save-options for TCE_FORMS will appear.
1208 * @return string <select> tag with content - a selector box for clearing the cache
1209 */
1210 function clearCacheMenu($id,$addSaveOptions=0) {
1211 global $BE_USER;
1212 $opt=array();
1213 if ($addSaveOptions) {
1214 $opt[]='<option value="">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.menu',1).'</option>';
1215 $opt[]='<option value="TBE_EDITOR_checkAndDoSubmit(1);">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'</option>';
1216 $opt[]='<option value="document.editform.closeDoc.value=-2; TBE_EDITOR_checkAndDoSubmit(1);">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc',1).'</option>';
1217 if ($BE_USER->uc['allSaveFunctions']) $opt[]='<option value="document.editform.closeDoc.value=-3; TBE_EDITOR_checkAndDoSubmit(1);">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseAllDocs',1).'</option>';
1218 $opt[]='<option value="document.editform.closeDoc.value=2; document.editform.submit();">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'</option>';
1219 $opt[]='<option value="document.editform.closeDoc.value=3; document.editform.submit();">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeAllDocs',1).'</option>';
1220 $opt[]='<option value=""></option>';
1221 }
1222 $opt[]='<option value="">[ '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_clearCache',1).' ]</option>';
1223 if ($id) $opt[]='<option value="'.$id.'">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_thisPage',1).'</option>';
1224 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.clearCache.pages')) $opt[]='<option value="pages">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_pages',1).'</option>';
1225 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.clearCache.all')) $opt[]='<option value="all">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all',1).'</option>';
1226
1227 $onChange = 'if (!this.options[this.selectedIndex].value) {
1228 this.selectedIndex=0;
1229 } else if (this.options[this.selectedIndex].value.indexOf(\';\')!=-1) {
1230 eval(this.options[this.selectedIndex].value);
1231 }else{
1232 window.location.href=\''.$this->backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).'&cacheCmd=\'+this.options[this.selectedIndex].value;
1233 }';
1234 $af_content = '<select name="cacheCmd" onchange="'.htmlspecialchars($onChange).'">'.implode('',$opt).'</select>';
1235
1236 if (count($opt)>2) {
1237 return $af_content;
1238 }
1239 }
1240
1241 /**
1242 * Returns an array with parts (JavaScript, init-functions, <div>-layers) for use on pages which displays the clickmenu layers (context sensitive menus)
1243 *
1244 * @return array If values are present: [0] = A <script> section for the HTML page header, [1] = onmousemove/onload handler for HTML tag or alike, [2] = Two empty <div> layers for the context menu
1245 */
1246 function getContextMenuCode() {
1247 $content = '
1248 <script type="text/javascript">
1249 /*<![CDATA[*/
1250 // is called from most clickmenu links
1251 function showClickmenu(table, uid, listFr, enDisItems, backPath, addParams) {
1252 var url = "'.$this->backPath.'alt_clickmenu.php?table=" + table
1253 + "&uid=" + uid
1254 + "&listFr=" + listFr
1255 + "&enDisItems=" + enDisItems
1256 + "&backPath=" + backPath
1257 + "&addParams=" + addParams;
1258
1259 showClickmenu_raw(url);
1260 }
1261 // switch - either forwards call to ajax or does the request in the top frame
1262 function showClickmenu_raw(url) {';
1263 if($this->isCMlayers()) { // ajax
1264 $content .= '
1265 url += "&ajax=1";
1266 ajax_doRequest(url);';
1267 } else { // no ajax
1268 $content .= '
1269 showClickmenu_noajax(url);';
1270 }
1271 $content .= '
1272 }
1273
1274 /**
1275 * [Describe function...]
1276 *
1277 * @param [type] $url: ...
1278 * @return [type] ...
1279 */
1280 function showClickmenu_noajax(url) {
1281 top.loadTopMenu(url);
1282 }';
1283 if ($this->isCMlayers()) {
1284 $content .= t3lib_ajax::getJScode('showClickmenu_ajax', 'showClickmenu_noajax');
1285 $content.='
1286 // opens the clickmenu, is called from ajax_doRequest
1287 function showClickmenu_ajax(t3ajax) {
1288 if (t3ajax.getElementsByTagName("data")[0]) {
1289 var clickmenu = t3ajax.getElementsByTagName("data")[0].getElementsByTagName("clickmenu")[0];
1290 var tableData = clickmenu.getElementsByTagName("htmltable")[0].firstChild.data;
1291 var cmlevel = clickmenu.getElementsByTagName("cmlevel")[0].firstChild.data;
1292 setLayerObj(tableData,cmlevel);
1293 }
1294 }
1295
1296 var GLV_gap=10;
1297 var GLV_curLayerX=new Array(0,0);
1298 var GLV_curLayerY=new Array(0,0);
1299 var GLV_curLayerWidth=new Array(0,0);
1300 var GLV_curLayerHeight=new Array(0,0);
1301 var GLV_isVisible=new Array(0,0);
1302 var GLV_x=0;
1303 var GLV_y=0;
1304 var GLV_xRel=0;
1305 var GLV_yRel=0;
1306 var layerObj=new Array();
1307 var layerObjCss=new Array();
1308
1309 //browsercheck...
1310 function GL_checkBrowser(){ //
1311 this.dom= (document.getElementById);
1312 this.op= (navigator.userAgent.indexOf("Opera")>-1);
1313 this.op7= this.op && (navigator.appVersion.indexOf("7")>-1); // check for Opera version 7
1314 this.konq= (navigator.userAgent.indexOf("Konq")>-1);
1315 this.ie4= (document.all && !this.dom && !this.op && !this.konq);
1316 this.ie5= (document.all && this.dom && !this.op && !this.konq);
1317 this.ns4= (document.layers && !this.dom && !this.konq);
1318 this.ns5= (!document.all && this.dom && !this.op && !this.konq);
1319 this.ns6= (this.ns5);
1320 this.bw= (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
1321 return this;
1322 }
1323 bw= new GL_checkBrowser();
1324
1325 // GL_getObj(obj)
1326 function GL_getObj(obj){ //
1327 nest="";
1328 this.el= (bw.ie4||bw.op7)?document.all[obj]:bw.ns4?eval(nest+"document."+obj):document.getElementById(obj);
1329 this.css= bw.ns4?this.el:this.el.style;
1330 this.ref= bw.ns4?this.el.document:document;
1331 this.x= (bw.ns4||bw.op)?this.css.left:this.el.offsetLeft;
1332 this.y= (bw.ns4||bw.op)?this.css.top:this.el.offsetTop;
1333 this.height= (bw.ie4||bw.dom)?this.el.offsetHeight:bw.ns4?this.ref.height:0;
1334 this.width= (bw.ie4||bw.dom)?this.el.offsetWidth:bw.ns4?this.ref.width:0;
1335 return this;
1336 }
1337 // GL_getObjCss(obj)
1338 function GL_getObjCss(obj){ //
1339 return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
1340 }
1341 // GL_getMouse(event)
1342 function GL_getMouse(event) { //
1343 if (layerObj) {
1344 // GLV_x= (bw.ns4||bw.ns5)?event.pageX:(bw.ie4||bw.op)?event.clientX:(event.clientX-2)+document.body.scrollLeft;
1345 // GLV_y= (bw.ns4||bw.ns5)?event.pageY:(bw.ie4||bw.op)?event.clientY:(event.clientY-2)+document.body.scrollTop;
1346 // 17/12 2003: When documents run in XHTML standard compliance mode, the old scrollLeft/Top properties of document.body is gone - and for Opera/MSIE we have to use document.documentElement:
1347
1348 GLV_xRel = event.clientX-2;
1349 GLV_yRel = event.clientY-2;
1350 GLV_x = GLV_xRel + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
1351 GLV_y = GLV_yRel + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
1352
1353 // status = (GLV_x+GLV_gap-GLV_curLayerX[0]) + " | " + (GLV_y+GLV_gap-GLV_curLayerY[0]);
1354 if (GLV_isVisible[1]) {
1355 if (outsideLayer(1)) hideSpecific(1);
1356 } else if (GLV_isVisible[0]) {
1357 if (outsideLayer(0)) hideSpecific(0);
1358 }
1359 }
1360 }
1361 // outsideLayer(level)
1362 function outsideLayer(level) { //
1363 return GLV_x+GLV_gap-GLV_curLayerX[level] <0 ||
1364 GLV_y+GLV_gap-GLV_curLayerY[level] <0 ||
1365 GLV_curLayerX[level]+GLV_curLayerWidth[level]+GLV_gap-GLV_x <0 ||
1366 GLV_curLayerY[level]+GLV_curLayerHeight[level]+GLV_gap-GLV_y <0;
1367 }
1368 // setLayerObj(html,level)
1369 function setLayerObj(html,level) { //
1370 var winHeight = document.documentElement.clientHeight && !bw.op7 ? document.documentElement.clientHeight : document.body.clientHeight;
1371 var winWidth = document.documentElement.clientWidth && !bw.op7 ? document.documentElement.clientWidth : document.body.clientWidth;
1372 var tempLayerObj = GL_getObj("contentMenu"+level);
1373 var tempLayerObjCss = GL_getObjCss("contentMenu"+level);
1374
1375 if (tempLayerObj && (level==0 || GLV_isVisible[level-1])) {
1376 tempLayerObj.el.innerHTML = html;
1377 tempLayerObj.width= (bw.ie4||bw.dom)?this.el.offsetWidth:bw.ns4?this.ref.width:0;
1378 tempLayerObj.height= (bw.ie4||bw.dom)?this.el.offsetHeight:bw.ns4?this.ref.height:0;
1379
1380 // konqueror (3.2.2) workaround
1381 winHeight = (bw.konq)?window.innerHeight:winHeight;
1382 winWidth = (bw.konq)?window.innerWidth:winWidth;
1383
1384 // Adjusting the Y-height of the layer to fit it into the window frame if it goes under the window frame in the bottom:
1385 if (winHeight-tempLayerObj.height < GLV_yRel) {
1386 if (GLV_yRel < tempLayerObj.height) {
1387 GLV_y+= (winHeight-tempLayerObj.height-GLV_yRel); // Setting it so bottom is just above window height.
1388 } else {
1389 GLV_y-= tempLayerObj.height-8; // Showing the menu upwards
1390 }
1391 }
1392 // Adjusting the X position like Y above
1393 if (winWidth-tempLayerObj.width < GLV_xRel) {
1394 if (GLV_xRel < tempLayerObj.width) {
1395 GLV_x+= (winWidth-tempLayerObj.width-GLV_xRel);
1396 } else {
1397 GLV_x-= tempLayerObj.width-8;
1398 }
1399 }
1400 GLV_x = Math.max(GLV_x,1);
1401 GLV_y = Math.max(GLV_y,1);
1402
1403 GLV_curLayerX[level] = GLV_x;
1404 GLV_curLayerY[level] = GLV_y;
1405 tempLayerObjCss.left = GLV_x+"px";
1406 tempLayerObjCss.top = GLV_y+"px";
1407 tempLayerObjCss.visibility = "visible";
1408 if (bw.ie5) showHideSelectorBoxes("hidden");
1409
1410 GLV_isVisible[level]=1;
1411 GLV_curLayerWidth[level] = tempLayerObj.width;
1412 GLV_curLayerHeight[level] = tempLayerObj.height;
1413 }
1414 }
1415 // hideEmpty()
1416 function hideEmpty() { //
1417 hideSpecific(0);
1418 hideSpecific(1);
1419 return false;
1420 }
1421 // hideSpecific(level)
1422 function hideSpecific(level) { //
1423 GL_getObjCss("contentMenu"+level).visibility = "hidden";
1424 GL_getObj("contentMenu"+level).el.innerHTML = "";
1425 GLV_isVisible[level]=0;
1426
1427 if (bw.ie5 && level==0) showHideSelectorBoxes("visible");
1428 }
1429 // debugObj(obj,name)
1430 function debugObj(obj,name) { //
1431 var acc;
1432 for (i in obj) {if (obj[i]) {acc+=i+": "+obj[i]+"\n";}}
1433 alert("Object: "+name+"\n\n"+acc);
1434 }
1435 // initLayer()
1436 function initLayer(){ //
1437 if (document.all) {
1438 window.onmousemove=GL_getMouse;
1439 }
1440 layerObj = GL_getObj("contentMenu1");
1441 layerObjCss = GL_getObjCss("contentMenu1");
1442 }
1443 function showHideSelectorBoxes(action) { // This function by Michiel van Leening
1444 for (i=0;i<document.forms.length;i++) {
1445 for (j=0;j<document.forms[i].elements.length;j++) {
1446 if(document.forms[i].elements[j].type=="select-one") {
1447 document.forms[i].elements[j].style.visibility=action;
1448 }
1449 }
1450 }
1451 }';
1452 $content.=' /*]]>*/
1453 </script>';
1454 return array(
1455 $content,
1456 ' onmousemove="GL_getMouse(event);" onload="initLayer();"',
1457 '<div id="contentMenu0" style="z-index:1; position:absolute;visibility:hidden"></div><div id="contentMenu1" style="z-index:2; position:absolute;visibility:hidden"></div>'
1458 );
1459 } else {
1460 $content.=' /*]]>*/
1461 </script>';
1462 return array($content,'','');
1463 }
1464 }
1465
1466 /**
1467 * Returns an array with parts (JavaScript, init-functions, <div>-layers) for use on pages which have the drag and drop functionality (usually pages and folder display trees)
1468 *
1469 * @param string indicator of which table the drag and drop function should work on (pages or folders)
1470 * @return array If values are present: [0] = A <script> section for the HTML page header, [1] = onmousemove/onload handler for HTML tag or alike, [2] = One empty <div> layer for the follow-mouse drag element
1471 */
1472 function getDragDropCode($table) {
1473 $content = '
1474 <script type="text/javascript">
1475 /*<![CDATA[*/
1476 ';
1477
1478 if ($this->isCMlayers()) {
1479 $content.= '
1480 var dragID = null;
1481 var dragIconCSS = null;
1482
1483 function cancelDragEvent(event) {
1484 dragID = null;
1485 dragIconCSS.visibility = "hidden";
1486 document.onmouseup = null;
1487 document.onmousemove = null;
1488 }
1489
1490 /**
1491 * [Describe function...]
1492 *
1493 * @param [type] $event: ...
1494 * @return [type] ...
1495 */
1496 function mouseMoveEvent (event) {
1497 dragIconCSS.left = GLV_x+5+"px";
1498 dragIconCSS.top = GLV_y-5+"px";
1499 dragIconCSS.visibility = "visible";
1500 return false;
1501 }
1502
1503 /**
1504 * [Describe function...]
1505 *
1506 * @param [type] $id,elementID: ...
1507 * @return [type] ...
1508 */
1509 function dragElement(id,elementID) {
1510 dragID = id;
1511 if (elementID == null) {
1512 elementID = id;
1513 }
1514 document.getElementById("dragIcon").innerHTML=document.getElementById("dragIconID_"+elementID).innerHTML + document.getElementById("dragTitleID_"+elementID).getElementsByTagName("a")[0].innerHTML;
1515 dragIconCSS = new GL_getObjCss("dragIcon");
1516 dragIconCSS.whiteSpace = "nowrap";
1517 document.onmouseup = cancelDragEvent;
1518 document.onmousemove = mouseMoveEvent;
1519 return false;
1520 }
1521
1522 /**
1523 * [Describe function...]
1524 *
1525 * @param [type] $id: ...
1526 * @return [type] ...
1527 */
1528 function dropElement(id) {
1529 if ((dragID != null) && (dragID != id)) {
1530 var url = "'.$this->backPath.'alt_clickmenu.php?dragDrop='.$table.'"
1531 + "&srcId=" + dragID
1532 + "&dstId=" + id
1533 + "&backPath='.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
1534 showClickmenu_raw(url);
1535 }
1536 cancelDragEvent();
1537 return false;
1538 }
1539 ';
1540 }
1541 else {
1542 $content.= '
1543 function dragElement(id) { return false; }
1544 function dropElement(id) { return false; }
1545 ';
1546 }
1547 $content.='
1548 /*]]>*/
1549 </script>';
1550
1551 if ($this->isCMlayers()) {
1552 return array(
1553 $content,
1554 '',
1555 '<div id="dragIcon" style="z-index:1;position:absolute;visibility:hidden;filter:alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;"><img src="" width="18" height="16"></div>'
1556 );
1557 } else {
1558 return array($content,'','');
1559 }
1560 }
1561
1562 /**
1563 * Creates a tab menu from an array definition
1564 *
1565 * Returns a tab menu for a module
1566 * Requires the JS function jumpToUrl() to be available
1567 *
1568 * @param mixed $id is the "&id=" parameter value to be sent to the module, but it can be also a parameter array which will be passed instead of the &id=...
1569 * @param string $elementName it the form elements name, probably something like "SET[...]"
1570 * @param string $currentValue is the value to be selected currently.
1571 * @param array $menuItems is an array with the menu items for the selector box
1572 * @param string $script is the script to send the &id to, if empty it's automatically found
1573 * @param string $addParams is additional parameters to pass to the script.
1574 * @return string HTML code for tab menu
1575 * @author René Fritz <r.fritz@colorcube.de>
1576 */
1577 function getTabMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='') {
1578 $content='';
1579
1580 if (is_array($menuItems)) {
1581 if (!is_array($mainParams)) {
1582 $mainParams = array('id' => $mainParams);
1583 }
1584 $mainParams = t3lib_div::implodeArrayForUrl('',$mainParams);
1585
1586 if (!$script) {$script=basename(PATH_thisScript);}
1587
1588 $menuDef = array();
1589 foreach($menuItems as $value => $label) {
1590 $menuDef[$value]['isActive'] = !strcmp($currentValue,$value);
1591 $menuDef[$value]['label'] = t3lib_div::deHSCentities(htmlspecialchars($label));
1592 $menuDef[$value]['url'] = htmlspecialchars($script.'?'.$mainParams.$addparams.'&'.$elementName.'='.$value);
1593 }
1594 $content = $this->getTabMenuRaw($menuDef);
1595
1596 }
1597 return $content;
1598 }
1599
1600 /**
1601 * Creates the HTML content for the tab menu
1602 *
1603 * @param array Menu items for tabs
1604 * @return string Table HTML
1605 * @access private
1606 */
1607 function getTabMenuRaw($menuItems) {
1608 $content='';
1609
1610 if (is_array($menuItems)) {
1611 $options='';
1612
1613 $count = count($menuItems);
1614 $widthLeft = 1;
1615 $addToAct = 5;
1616
1617 $widthRight = max (1,floor(30-pow($count,1.72)));
1618 $widthTabs = 100 - $widthRight - $widthLeft;
1619 $widthNo = floor(($widthTabs - $addToAct)/$count);
1620 $addToAct = max ($addToAct,$widthTabs-($widthNo*$count));
1621 $widthAct = $widthNo + $addToAct;
1622 $widthRight = 100 - ($widthLeft + ($count*$widthNo) + $addToAct);
1623
1624 $first=true;
1625 foreach($menuItems as $id => $def) {
1626 $isActive = $def['isActive'];
1627 $class = $isActive ? 'tabact' : 'tab';
1628 $width = $isActive ? $widthAct : $widthNo;
1629
1630 // @rene: Here you should probably wrap $label and $url in htmlspecialchars() in order to make sure its XHTML compatible! I did it for $url already since that is VERY likely to break.
1631 $label = $def['label'];
1632 $url = htmlspecialchars($def['url']);
1633 $params = $def['addParams'];
1634
1635 if($first) {
1636 $options.= '
1637 <td width="'.$width.'%" class="'.$class.'" style="border-left: solid #000 1px;"><a href="'.$url.'" style="padding-left:5px;padding-right:2px;" '.$params.'>'.$label.'</a></td>';
1638 } else {
1639 $options.='
1640 <td width="'.$width.'%" class="'.$class.'"><a href="'.$url.'" '.$params.'>'.$label.'</a></td>';
1641 }
1642 $first=false;
1643 }
1644
1645 if ($options) {
1646 $content .= '
1647 <!-- Tab menu -->
1648 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1649 <tr>
1650 <td width="'.$widthLeft.'%">&nbsp;</td>
1651 '.$options.'
1652 <td width="'.$widthRight.'%">&nbsp;</td>
1653 </tr>
1654 </table>
1655 <div class="hr" style="margin:0px"></div>';
1656 }
1657
1658 }
1659 return $content;
1660 }
1661
1662 /**
1663 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1664 * Should work in MSIE, Mozilla, Opera and Konqueror. On Konqueror I did find a serious problem: <textarea> fields loose their content when you switch tabs!
1665 *
1666 * @param array Numeric array where each entry is an array in itself with associative keys: "label" contains the label for the TAB, "content" contains the HTML content that goes into the div-layer of the tabs content. "description" contains description text to be shown in the layer. "linkTitle" is short text for the title attribute of the tab-menu link (mouse-over text of tab). "stateIcon" indicates a standard status icon (see ->icon(), values: -1, 1, 2, 3). "icon" is an image tag placed before the text.
1667 * @param string Identification string. This should be unique for every instance of a dynamic menu!
1668 * @param integer If "1", then enabling one tab does not hide the others - they simply toggles each sheet on/off. This makes most sense together with the $foldout option. If "-1" then it acts normally where only one tab can be active at a time BUT you can click a tab and it will close so you have no active tabs.
1669 * @param boolean If set, the tabs are rendered as headers instead over each sheet. Effectively this means there is no tab menu, but rather a foldout/foldin menu. Make sure to set $toggle as well for this option.
1670 * @param integer Character limit for a new row.
1671 * @param boolean If set, tab table cells are not allowed to wrap their content
1672 * @param boolean If set, the tabs will span the full width of their position
1673 * @param integer Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1 (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing) will result in no default tab open.
1674 * @return string JavaScript section for the HTML header.
1675 */
1676 function getDynTabMenu($menuItems,$identString,$toggle=0,$foldout=FALSE,$newRowCharLimit=50,$noWrap=1,$fullWidth=FALSE,$defaultTabIndex=1) {
1677 $content = '';
1678
1679 if (is_array($menuItems)) {
1680
1681 // Init:
1682 $options = array(array());
1683 $divs = array();
1684 $JSinit = array();
1685 $id = 'DTM-'.t3lib_div::shortMD5($identString);
1686 $noWrap = $noWrap ? ' nowrap="nowrap"' : '';
1687
1688 // Traverse menu items
1689 $c=0;
1690 $tabRows=0;
1691 $titleLenCount = 0;
1692 foreach($menuItems as $index => $def) {
1693 $index+=1; // Need to add one so checking for first index in JavaScript is different than if it is not set at all.
1694
1695 // Switch to next tab row if needed
1696 if (!$foldout && $titleLenCount>$newRowCharLimit) { // 50 characters is probably a reasonable count of characters before switching to next row of tabs.
1697 $titleLenCount=0;
1698 $tabRows++;
1699 $options[$tabRows] = array();
1700 }
1701
1702 if ($toggle==1) {
1703 $onclick = 'this.blur(); DTM_toggle("'.$id.'","'.$index.'"); return false;';
1704 } else {
1705 $onclick = 'this.blur(); DTM_activate("'.$id.'","'.$index.'", '.($toggle<0?1:0).'); return false;';
1706 }
1707
1708 $isActive = strcmp($def['content'],'');
1709
1710 $mouseOverOut = 'onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
1711
1712 if (!$foldout) {
1713 // Create TAB cell:
1714 $options[$tabRows][] = '
1715 <td class="'.($isActive ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$noWrap.$mouseOverOut.'>'.
1716 ($isActive ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
1717 $def['icon'].
1718 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1719 $this->icons($def['stateIcon'],'margin-left: 10px;').
1720 ($isActive ? '</a>' :'').
1721 '</td>';
1722 $titleLenCount+= strlen($def['label']);
1723 } else {
1724 // Create DIV layer for content:
1725 $divs[] = '
1726 <div class="'.($isActive ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$mouseOverOut.'>'.
1727 ($isActive ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
1728 $def['icon'].
1729 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1730 ($isActive ? '</a>' : '').
1731 '</div>';
1732 }
1733
1734 if ($isActive) {
1735 // Create DIV layer for content:
1736 $divs[] = '
1737 <div style="display: none;" id="'.$id.'-'.$index.'-DIV" class="c-tablayer">'.
1738 ($def['description'] ? '<p class="c-descr">'.nl2br(htmlspecialchars($def['description'])).'</p>' : '').
1739 $def['content'].
1740 '</div>';
1741 // Create initialization string:
1742 $JSinit[] = '
1743 DTM_array["'.$id.'"]['.$c.'] = "'.$id.'-'.$index.'";
1744 ';
1745 if ($toggle==1) {
1746 $JSinit[] = '
1747 if (top.DTM_currentTabs["'.$id.'-'.$index.'"]) { DTM_toggle("'.$id.'","'.$index.'",1); }
1748 ';
1749 }
1750
1751 $c++;
1752 }
1753 }
1754
1755 // Render menu:
1756 if (count($options)) {
1757
1758 // Tab menu is compiled:
1759 if (!$foldout) {
1760 $tabContent = '';
1761 for($a=0;$a<=$tabRows;$a++) {
1762 $tabContent.= '
1763
1764 <!-- Tab menu -->
1765 <table cellpadding="0" cellspacing="0" border="0"'.($fullWidth ? ' width="100%"' : '').' class="typo3-dyntabmenu">
1766 <tr>
1767 '.implode('',$options[$a]).'
1768 </tr>
1769 </table>';
1770 }
1771 $content.= '<div class="typo3-dyntabmenu-tabs">'.$tabContent.'</div>';
1772 }
1773
1774 // Div layers are added:
1775 $content.= '
1776 <!-- Div layers for tab menu: -->
1777 <div class="typo3-dyntabmenu-divs'.($foldout?'-foldout':'').'">
1778 '.implode('',$divs).'</div>';
1779
1780 // Java Script section added:
1781 $content.= '
1782 <!-- Initialization JavaScript for the menu -->
1783 <script type="text/javascript">
1784 DTM_array["'.$id.'"] = new Array();
1785 '.implode('',$JSinit).'
1786 '.($toggle<=0 ? 'DTM_activate("'.$id.'", top.DTM_currentTabs["'.$id.'"]?top.DTM_currentTabs["'.$id.'"]:'.intval($defaultTabIndex).', 0);' : '').'
1787 </script>
1788
1789 ';
1790 }
1791
1792 }
1793 return $content;
1794 }
1795
1796 /**
1797 * Returns dynamic tab menu header JS code.
1798 *
1799 * @return string JavaScript section for the HTML header.
1800 */
1801 function getDynTabMenuJScode() {
1802 return '
1803 <script type="text/javascript">
1804 /*<![CDATA[*/
1805 var DTM_array = new Array();
1806 var DTM_origClass = new String();
1807
1808 // if tabs are used in a popup window the array might not exists
1809 if(!top.DTM_currentTabs) {
1810 top.DTM_currentTabs = new Array();
1811 }
1812
1813 function DTM_activate(idBase,index,doToogle) { //
1814 // Hiding all:
1815 if (DTM_array[idBase]) {
1816 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
1817 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
1818 document.getElementById(DTM_array[idBase][cnt]+"-DIV").style.display = "none";
1819 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1820 }
1821 }
1822 }
1823
1824 // Showing one:
1825 if (document.getElementById(idBase+"-"+index+"-DIV")) {
1826 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
1827 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
1828 if(DTM_origClass=="") {
1829 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1830 } else {
1831 DTM_origClass = "tab";
1832 }
1833 top.DTM_currentTabs[idBase] = -1;
1834 } else {
1835 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
1836 if(DTM_origClass=="") {
1837 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
1838 } else {
1839 DTM_origClass = "tabact";
1840 }
1841 top.DTM_currentTabs[idBase] = index;
1842 }
1843 }
1844 }
1845 function DTM_toggle(idBase,index,isInit) { //
1846 // Showing one:
1847 if (document.getElementById(idBase+"-"+index+"-DIV")) {
1848 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
1849 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
1850 if(isInit) {
1851 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1852 } else {
1853 DTM_origClass = "tab";
1854 }
1855 top.DTM_currentTabs[idBase+"-"+index] = 0;
1856 } else {
1857 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
1858 if(isInit) {
1859 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
1860 } else {
1861 DTM_origClass = "tabact";
1862 }
1863 top.DTM_currentTabs[idBase+"-"+index] = 1;
1864 }
1865 }
1866 }
1867
1868 function DTM_mouseOver(obj) { //
1869 DTM_origClass = obj.attributes.getNamedItem(\'class\').nodeValue;
1870 obj.attributes.getNamedItem(\'class\').nodeValue += "_over";
1871 }
1872
1873 function DTM_mouseOut(obj) { //
1874 obj.attributes.getNamedItem(\'class\').nodeValue = DTM_origClass;
1875 DTM_origClass = "";
1876 }
1877
1878
1879 /*]]>*/
1880 </script>
1881 ';
1882 }
1883
1884 /**
1885 * Creates the version selector for the page id inputted.
1886 * Requires the core version management extension, "version" to be loaded.
1887 *
1888 * @param integer Page id to create selector for.
1889 * @param boolean If set, there will be no button for swapping page.
1890 * @return void
1891 */
1892 function getVersionSelector($id,$noAction=FALSE) {
1893
1894 if ($id>0) {
1895 if (t3lib_extMgm::isLoaded('version') && $GLOBALS['BE_USER']->workspace==0) {
1896
1897 // Get Current page record:
1898 $curPage = t3lib_BEfunc::getRecord('pages',$id);
1899 // If the selected page is not online, find the right ID
1900 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
1901 // Select all versions of online version:
1902 $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
1903
1904 // If more than one was found...:
1905 if (count($versions)>1) {
1906
1907 // Create selector box entries:
1908 $opt = array();
1909 foreach($versions as $vRow) {
1910 $opt[] = '<option value="'.htmlspecialchars(t3lib_div::linkThisScript(array('id'=>$vRow['uid']))).'"'.($id==$vRow['uid']?' selected="selected"':'').'>'.
1911 htmlspecialchars($vRow['t3ver_label'].' [v#'.$vRow['t3ver_id'].', WS:'.$vRow['t3ver_wsid'].']'.($vRow['uid']==$onlineId ? ' =>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.online').'<=':'')).
1912 '</option>';
1913 }
1914
1915 // Add management link:
1916 $opt[] = '<option value="'.htmlspecialchars(t3lib_div::linkThisScript(array('id'=>$id))).'">---</option>';
1917 $opt[] = '<option value="'.htmlspecialchars($this->backPath.t3lib_extMgm::extRelPath('version').'cm1/index.php?table=pages&uid='.$onlineId).'">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.mgm',1).'</option>';
1918
1919 // Create onchange handler:
1920 $onChange = "window.location.href=this.options[this.selectedIndex].value;";
1921
1922 // Controls:
1923 if ($id==$onlineId) {
1924 $controls = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/blinkarrow_left.gif','width="5" height="9"').' class="absmiddle" alt="" /> <b>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.online',1).'</b>';
1925 } elseif (!$noAction) {
1926 $controls = '<a href="'.$this->issueCommand('&cmd[pages]['.$onlineId.'][version][swapWith]='.$id.'&cmd[pages]['.$onlineId.'][version][action]=swap',t3lib_div::linkThisScript(array('id'=>$onlineId))).'" class="nobr">'.
1927 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/insert1.gif','width="14" height="14"').' style="margin-right: 2px;" class="absmiddle" alt="" title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swapPage',1).'" />'.
1928 '<b>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swap',1).'</b></a>';
1929 }
1930
1931 // Write out HTML code:
1932 return '
1933
1934 <!--
1935 Version selector:
1936 -->
1937 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1938 <tr>
1939 <td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.selVer',1).'</td>
1940 <td>
1941 <select onchange="'.htmlspecialchars($onChange).'">
1942 '.implode('',$opt).'
1943 </select></td>
1944 <td>'.$controls.'</td>
1945 </tr>
1946 </table>
1947 ';
1948 }
1949 } elseif ($GLOBALS['BE_USER']->workspace!==0) {
1950
1951 // Write out HTML code:
1952 switch($GLOBALS['BE_USER']->workspace) {
1953 case 0:
1954 $wsTitle = 'LIVE';
1955 break;
1956 case -1:
1957 $wsTitle = 'Draft';
1958 break;
1959 default:
1960 $wsTitle = $GLOBALS['BE_USER']->workspaceRec['title'];
1961 break;
1962 }
1963
1964 if (t3lib_BEfunc::isPidInVersionizedBranch($id)=='branchpoint') {
1965 return '
1966
1967 <!--
1968 Version selector:
1969 -->
1970 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1971 <tr>
1972 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
1973 <td><em>Inside branch, no further versioning possible</em></td>
1974 </tr>
1975 </table>
1976 ';
1977 } else {
1978 // Get Current page record:
1979 $curPage = t3lib_BEfunc::getRecord('pages',$id);
1980 // If the selected page is not online, find the right ID
1981 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
1982 // The version of page:
1983 $verPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'pages', $onlineId);
1984
1985 if (!$verPage) {
1986
1987 if (!count(t3lib_BEfunc::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $onlineId))) {
1988 if ($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0)) {
1989
1990 $onClick = $this->issueCommand('&cmd[pages]['.$onlineId.'][version][action]=new&cmd[pages]['.$onlineId.'][version][treeLevels]=0',t3lib_div::linkThisScript(array('id'=>$onlineId)));
1991 $onClick = 'window.location.href=\''.$onClick.'\'; return false;';
1992 // Write out HTML code:
1993 return '
1994
1995 <!--
1996 No version yet, create one?
1997 -->
1998 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1999 <tr>
2000 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2001 <td>
2002 <input type="submit" value="New version of page" name="_" onclick="'.htmlspecialchars($onClick).'" /></td>
2003 </tr>
2004 </table>
2005 ';
2006 }
2007 } else {
2008 return '
2009
2010 <!--
2011 Version selector:
2012 -->
2013 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
2014 <tr>
2015 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2016 <td><em>Versions found on page, no "Page" versioning possible</em></td>
2017 </tr>
2018 </table>
2019 ';
2020 }
2021 } elseif ($verPage['t3ver_swapmode']==0) {
2022 $onClick = $this->issueCommand('&cmd[pages]['.$onlineId.'][version][action]=swap&cmd[pages]['.$onlineId.'][version][swapWith]='.$verPage['uid'],t3lib_div::linkThisScript(array('id'=>$onlineId)));
2023 $onClick = 'window.location.href=\''.$onClick.'\'; return false;';
2024
2025 // Write out HTML code:
2026 return '
2027
2028 <!--
2029 Version selector:
2030 -->
2031 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
2032 <tr>
2033 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2034 <td>
2035 <input type="submit" value="Publish page" name="_" onclick="'.htmlspecialchars($onClick).'" /></td>
2036 </tr>
2037 </table>
2038 ';
2039 }
2040 }
2041 }
2042 }
2043 }
2044 }
2045
2046
2047
2048 // ******************************
2049 // Extension classes of the template class.
2050 // These are meant to provide backend screens with different widths.
2051 // They still do because of the different class-prefixes used for the <div>-sections
2052 // but obviously the final width is determined by the stylesheet used.
2053 // ******************************
2054
2055 /**
2056 * Extension class for "template" - used for backend pages which are wide. Typically modules taking up all the space in the "content" frame of the backend
2057 * The class were more significant in the past than today.
2058 *
2059 */
2060 class bigDoc extends template {
2061 var $divClass = 'typo3-bigDoc';
2062 }
2063
2064 /**
2065 * Extension class for "template" - used for backend pages without the "document" background image
2066 * The class were more significant in the past than today.
2067 *
2068 */
2069 class noDoc extends template {
2070 var $divClass = 'typo3-noDoc';
2071 }
2072
2073 /**
2074 * Extension class for "template" - used for backend pages which were narrow (like the Web>List modules list frame. Or the "Show details" pop up box)
2075 * The class were more significant in the past than today.
2076 *
2077 */
2078 class smallDoc extends template {
2079 var $divClass = 'typo3-smallDoc';
2080 }
2081
2082 /**
2083 * Extension class for "template" - used for backend pages which were medium wide. Typically submodules to Web or File which were presented in the list-frame when the content frame were divided into a navigation and list frame.
2084 * The class were more significant in the past than today. But probably you should use this one for most modules you make.
2085 *
2086 */
2087 class mediumDoc extends template {
2088 var $divClass = 'typo3-mediumDoc';
2089 }
2090
2091
2092
2093 // Include extension to the template class?
2094 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']) {
2095 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']);
2096 }
2097
2098
2099
2100 // ******************************************************
2101 // The backend language engine is started (ext: "lang")
2102 // ******************************************************
2103 require_once(PATH_typo3.'sysext/lang/lang.php');
2104 $LANG = t3lib_div::makeInstance('language');
2105 $LANG->init($BE_USER->uc['lang']);
2106
2107
2108
2109 // ******************************
2110 // The template is loaded
2111 // ******************************
2112 $TBE_TEMPLATE = t3lib_div::makeInstance('template');
2113 ?>