2 /***************************************************************
5 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@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 <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 80: class t3lib_recordList
42 * 123: function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
43 * 198: function writeTop()
44 * 206: function writeBottom()
45 * 225: function fwd_rwd_nav($table='')
46 * 258: function fwd_rwd_HTML($type,$pointer,$table='')
47 * 284: function listURL($altId='')
48 * 294: function CBfunctions()
49 * 344: function initializeLanguages()
50 * 411: function languageFlag($sys_language_uid)
53 * (This index is automatically created/updated by the extension "extdeveval")
73 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
75 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
78 * @see typo3/db_list.php, typo3/file_list.php
80 class t3lib_recordList
{
82 // Used in this class:
83 var $iLimit = 10; // default Max items shown
84 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
87 var $oddColumnsTDParams =''; // If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
89 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.
90 var $addElement_tdParams = array(); // Keys are fieldnames and values are td-parameters to add in addElement();
92 // Not used in this class - but maybe extension classes...
93 var $fixedL = 50; // Max length of strings
95 var $thumbScript = 'thumbs.php';
96 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
98 var $counter=0; // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
99 var $totalItems = ''; // This could be set to the total number of items. Used by the fwd_rew_navigation...
101 // Internal (used in this class.)
102 var $firstElementNumber=0;
104 var $HTMLcode=''; // String with accumulated HTML content
106 var $pageOverlays = array(); // Contains page translation languages
107 var $languageIconTitles = array(); // Contains sys language icons and titles
112 * Returns a table-row with the content from the fields in the input data array.
113 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
115 * @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'
116 * @param string $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
117 * @param array $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
118 * @param string $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
119 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
120 * @param string $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
121 * @return string HTML content for the table row
123 function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='') {
124 $noWrap = ($this->no_noWrap
) ?
'' : ' nowrap="nowrap"';
128 <!-- Element, begin: -->
130 // Show icon and lines
131 if ($this->showIcon
) {
133 <td nowrap="nowrap"'.$tdParams.'>';
136 # $out.='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
137 $out.='<img src="clear.gif" width="1" height="8" alt="" />';
139 for ($a=0;$a<$h;$a++
) {
141 # $out.= $altLine ? $altLine : '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
142 if ($icon) $out.= $icon;
144 # $out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
157 $tdP[0] = $this->oddColumnsTDParams ?
$this->oddColumnsTDParams
: $tdParams;
160 // Traverse field array which contains the data to present:
161 reset($this->fieldArray
);
162 while(list(,$vKey)=each($this->fieldArray
)) {
163 if (isset($data[$vKey])) {
170 $this->addElement_tdParams
[$lastKey].
171 '>'.$data[$lastKey].'</td>';
177 if (!$lastKey) {$lastKey=$vKey;}
180 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
182 if ($lastKey) { $out.='
183 <td'.$noWrap.$tdP[($ccount%2
)].$colsp.$this->addElement_tdParams
[$lastKey].'>'.$data[$lastKey].'</td>'; }
194 * Dummy function, used to write the top of a table listing.
198 function writeTop() {
202 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
206 function writeBottom() {
212 <table border="0" cellpadding="0" cellspacing="0">';
213 $theIcon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" />';
214 $this->HTMLcode
.=$this->addElement(1,'','','',$this->leftMargin
,$theIcon);
220 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
222 * @param string Table name
223 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
225 function fwd_rwd_nav($table='') {
227 if ($this->eCounter
>= $this->firstElementNumber
&& $this->eCounter
< $this->firstElementNumber+
$this->iLimit
) {
228 if ($this->firstElementNumber
&& $this->eCounter
==$this->firstElementNumber
) {
231 $titleCol=$this->fieldArray
[0];
232 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter
,$table);
233 $code=$this->addElement(1,'',$theData);
235 return Array(1,$code);
237 if ($this->eCounter
==$this->firstElementNumber+
$this->iLimit
) {
240 $titleCol=$this->fieldArray
[0];
241 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter
,$table);
242 $code=$this->addElement(1,'',$theData);
244 return Array(0,$code);
250 * Creates the button with link to either forward or reverse
252 * @param string Type: "fwd" or "rwd"
253 * @param integer Pointer
254 * @param string Table name
258 function fwd_rwd_HTML($type,$pointer,$table='') {
260 $tParam = $table ?
'&table='.rawurlencode($table) : '';
263 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit
).$tParam;
264 $content = '<a href="'.htmlspecialchars($href).'">'.
265 '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/pilup.gif','width="14" height="14"').' alt="" />'.
266 '</a> <i>[1 - '.$pointer.']</i>';
269 $href = $this->listURL().'&pointer='.$pointer.$tParam;
270 $content = '<a href="'.htmlspecialchars($href).'">'.
271 '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/pildown.gif','width="14" height="14"').' alt="" />'.
272 '</a> <i>['.($pointer+
1).' - '.$this->totalItems
.']</i>';
279 * Creates the URL to this script, including all relevant GPvars
281 * @param string Alternative id value. Enter blank string for the current id ($this->id)
284 function listURL($altId='') {
285 return $this->script
.
286 '?id='.(strcmp($altId,'')?
$altId:$this->id
);
290 * Returning JavaScript for ClipBoard functionality.
294 function CBfunctions() {
297 function checkOffCB(listOfCBnames) { //
301 // Checking how many is checked, how many is not
303 var pos = listOfCBnames.indexOf(",");
305 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
308 pos = listOfCBnames.indexOf(",",pointer);
310 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
313 // Setting the status...
314 var flag = notChecked*2>total;
316 pos = listOfCBnames.indexOf(",");
318 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
321 pos = listOfCBnames.indexOf(",",pointer);
323 setcbValue(listOfCBnames.substr(pointer),flag);
326 function cbValue(CBname) { //
327 var CBfullName = "CBC["+CBname+"]";
328 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
331 function setcbValue(CBname,flag) { //
332 CBfullName = "CBC["+CBname+"]";
333 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
340 * Initializes page languages and icons
344 function initializeLanguages() {
347 // Look up page overlays:
348 $this->pageOverlays
= $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
350 'pages_language_overlay',
351 'pid='.intval($this->id
).
352 t3lib_BEfunc
::deleteClause('pages_language_overlay').
353 t3lib_BEfunc
::versioningPlaceholderClause('pages_language_overlay'),
360 $t8Tools = t3lib_div
::makeInstance('t3lib_transl8tools');
361 $this->languageIconTitles
= $t8Tools->getSystemLanguages($this->id
, $this->backPath
);
365 * Return the icon for the language
367 * @param integer Sys language uid
368 * @return string Language icon
370 function languageFlag($sys_language_uid) {
371 return ($this->languageIconTitles
[$sys_language_uid]['flagIcon'] ?
'<img src="'.$this->languageIconTitles
[$sys_language_uid]['flagIcon'].'" class="absmiddle" alt="" /> ' : '').
372 htmlspecialchars($this->languageIconTitles
[$sys_language_uid]['title']);
377 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
378 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']);