2 /***************************************************************
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Library with a single function addElement that returns tablerows based on some input.
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
34 * @author Kasper Skaarhoj <kasper@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 78: class t3lib_recordList
42 * 119: function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
43 * 194: function writeTop()
44 * 202: function writeBottom()
45 * 221: function fwd_rwd_nav($table='')
46 * 254: function fwd_rwd_HTML($type,$pointer,$table='')
47 * 277: function listURL()
48 * 286: function CBfunctions()
51 * (This index is automatically created/updated by the extension "extdeveval")
71 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
73 * @author Kasper Skaarhoj <kasper@typo3.com>
76 * @see typo3/db_list.php, typo3/file_list.php
78 class t3lib_recordList
{
80 // Used in this class:
81 var $iLimit = 10; // default Max items shown
82 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
85 var $oddColumnsTDParams =''; // If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
87 var $fieldArray = Array(); // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
88 var $addElement_tdParams = array(); // Keys are fieldnames and values are td-parameters to add in addElement();
90 // Not used in this class - but maybe extension classes...
91 var $fixedL = 50; // Max length of strings
93 var $thumbScript = 'thumbs.php';
94 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
96 var $counter=0; // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
97 var $totalItems = ''; // This could be set to the total number of items. Used by the fwd_rew_navigation...
99 // Internal (used in this class.)
100 var $firstElementNumber=0;
102 var $HTMLcode=''; // String with accumulated HTML content
104 var $pageOverlays = array(); // Contains page translation languages
105 var $languageIconTitles = array(); // Contains sys language icons and titles
110 * Returns a table-row with the content from the fields in the input data array.
111 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
113 * @param integer $h is an integer >=0 and denotes how tall a element is. Set to '0' makes a halv line, -1 = full line, set to 1 makes a 'join' and above makes 'line'
114 * @param string $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
115 * @param array $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
116 * @param string $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
117 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
118 * @param string $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
119 * @return string HTML content for the table row
121 function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='') {
122 $noWrap = ($this->no_noWrap
) ?
'' : ' nowrap="nowrap"';
126 <!-- Element, begin: -->
128 // Show icon and lines
129 if ($this->showIcon
) {
131 <td nowrap="nowrap"'.$tdParams.'>';
134 # $out.='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
135 $out.='<img src="clear.gif" width="1" height="8" alt="" />';
137 for ($a=0;$a<$h;$a++
) {
139 # $out.= $altLine ? $altLine : '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
140 if ($icon) $out.= $icon;
142 # $out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
155 $tdP[0] = $this->oddColumnsTDParams ?
$this->oddColumnsTDParams
: $tdParams;
158 // Traverse field array which contains the data to present:
159 reset($this->fieldArray
);
160 while(list(,$vKey)=each($this->fieldArray
)) {
161 if (isset($data[$vKey])) {
168 $this->addElement_tdParams
[$lastKey].
169 '>'.$data[$lastKey].'</td>';
175 if (!$lastKey) {$lastKey=$vKey;}
178 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
180 if ($lastKey) { $out.='
181 <td'.$noWrap.$tdP[($ccount%2
)].$colsp.$this->addElement_tdParams
[$lastKey].'>'.$data[$lastKey].'</td>'; }
192 * Dummy function, used to write the top of a table listing.
196 function writeTop() {
200 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
204 function writeBottom() {
210 <table border="0" cellpadding="0" cellspacing="0">';
211 $theIcon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" />';
212 $this->HTMLcode
.=$this->addElement(1,'','','',$this->leftMargin
,$theIcon);
218 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
220 * @param string Table name
221 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
223 function fwd_rwd_nav($table='') {
225 if ($this->eCounter
>= $this->firstElementNumber
&& $this->eCounter
< $this->firstElementNumber+
$this->iLimit
) {
226 if ($this->firstElementNumber
&& $this->eCounter
==$this->firstElementNumber
) {
229 $titleCol=$this->fieldArray
[0];
230 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter
,$table);
231 $code=$this->addElement(1,'',$theData);
233 return Array(1,$code);
235 if ($this->eCounter
==$this->firstElementNumber+
$this->iLimit
) {
238 $titleCol=$this->fieldArray
[0];
239 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter
,$table);
240 $code=$this->addElement(1,'',$theData);
242 return Array(0,$code);
248 * Creates the button with link to either forward or reverse
250 * @param string Type: "fwd" or "rwd"
251 * @param integer Pointer
252 * @param string Table name
256 function fwd_rwd_HTML($type,$pointer,$table='') {
257 $tParam = $table ?
'&table='.rawurlencode($table) : '';
260 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit
).$tParam;
261 return '<a href="'.htmlspecialchars($href).'">'.
262 '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/pilup.gif','width="14" height="14"').' alt="" />'.
263 '</a> <i>[1 - '.$pointer.']</i>';
266 $href = $this->listURL().'&pointer='.$pointer.$tParam;
267 return '<a href="'.htmlspecialchars($href).'">'.
268 '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/pildown.gif','width="14" height="14"').' alt="" />'.
269 '</a> <i>['.($pointer+
1).' - '.$this->totalItems
.']</i>';
275 * Creates the URL to this script, including all relevant GPvars
277 * @param string Alternative id value. Enter blank string for the current id ($this->id)
280 function listURL($altId='') {
281 return $this->script
.
282 '?id='.(strcmp($altId,'')?
$altId:$this->id
);
286 * Returning JavaScript for ClipBoard functionality.
290 function CBfunctions() {
293 function checkOffCB(listOfCBnames) { //
297 // Checking how many is checked, how many is not
299 var pos = listOfCBnames.indexOf(",");
301 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
304 pos = listOfCBnames.indexOf(",",pointer);
306 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
309 // Setting the status...
310 var flag = notChecked*2>total;
312 pos = listOfCBnames.indexOf(",");
314 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
317 pos = listOfCBnames.indexOf(",",pointer);
319 setcbValue(listOfCBnames.substr(pointer),flag);
322 function cbValue(CBname) { //
323 var CBfullName = "CBC["+CBname+"]";
324 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
327 function setcbValue(CBname,flag) { //
328 CBfullName = "CBC["+CBname+"]";
329 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
336 * Initializes page languages and icons
340 function initializeLanguages() {
343 // Look up page overlays:
344 $this->pageOverlays
= $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
346 'pages_language_overlay',
347 'pid='.intval($this->id
).
348 t3lib_BEfunc
::deleteClause('pages_language_overlay'),
355 // icons and language titles:
356 t3lib_div
::loadTCA ('sys_language');
357 $flagAbsPath = t3lib_div
::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
358 $flagIconPath = $this->backPath
.'../'.substr($flagAbsPath, strlen(PATH_site
));
360 $this->modSharedTSconfig
= t3lib_BEfunc
::getModTSconfig($this->id
, 'mod.SHARED');
361 $this->languageIconTitles
= array();
364 $this->languageIconTitles
[0]=array(
366 'title' => strlen ($this->modSharedTSconfig
['properties']['defaultLanguageFlag']) ?
$this->modSharedTSconfig
['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
368 'flagIcon' => strlen($this->modSharedTSconfig
['properties']['defaultLanguageFlag']) && @is_file
($flagAbsPath.$this->modSharedTSconfig
['properties']['defaultLanguageFlag']) ?
$flagIconPath.$this->modSharedTSconfig
['properties']['defaultLanguageFlag'] : null,
371 // Set "All" language:
372 $this->languageIconTitles
[-1]=array(
374 'title' => $LANG->getLL ('multipleLanguages'),
376 'flagIcon' => $flagIconPath.'multi-language.gif',
379 // Find all system languages:
380 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
385 foreach($sys_languages as $row) {
386 $this->languageIconTitles
[$row['uid']] = $row;
388 if ($row['static_lang_isocode']) {
389 $staticLangRow = t3lib_BEfunc
::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
390 if ($staticLangRow['lg_iso_2']) {
391 $this->languageIconTitles
[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
394 if (strlen ($row['flag'])) {
395 $this->languageIconTitles
[$row['uid']]['flagIcon'] = @is_file
($flagAbsPath.$row['flag']) ?
$flagIconPath.$row['flag'] : '';
401 * Return the icon for the language
403 * @param integer Sys language uid
404 * @return string Language icon
406 function languageFlag($sys_language_uid) {
407 return ($this->languageIconTitles
[$sys_language_uid]['flagIcon'] ?
'<img src="'.$this->languageIconTitles
[$sys_language_uid]['flagIcon'].'" class="absmiddle" alt="" /> ' : '').
408 htmlspecialchars($this->languageIconTitles
[$sys_language_uid]['title']);
413 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
414 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']);