See changelog
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Library with a single function addElement that returns tablerows based on some input.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
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()
49 *
50 * TOTAL FUNCTIONS: 7
51 * (This index is automatically created/updated by the extension "extdeveval")
52 *
53 */
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 /**
71 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
72 *
73 * @author Kasper Skaarhoj <kasper@typo3.com>
74 * @package TYPO3
75 * @subpackage t3lib
76 * @see typo3/db_list.php, typo3/file_list.php
77 */
78 class t3lib_recordList {
79
80 // Used in this class:
81 var $iLimit = 10; // default Max items shown
82 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
83 var $showIcon = 1;
84 var $no_noWrap = 0;
85 var $oddColumnsTDParams =''; // If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
86 var $backPath='';
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();
89
90 // Not used in this class - but maybe extension classes...
91 var $fixedL = 50; // Max length of strings
92 var $script = '';
93 var $thumbScript = 'thumbs.php';
94 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
95
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...
98
99 // Internal (used in this class.)
100 var $firstElementNumber=0;
101 var $eCounter=0;
102 var $HTMLcode=''; // String with accumulated HTML content
103
104 var $pageOverlays = array(); // Contains page translation languages
105 var $languageIconTitles = array(); // Contains sys language icons and titles
106
107
108
109 /**
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)
112 *
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
120 */
121 function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='') {
122 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
123
124 // Start up:
125 $out='
126 <!-- Element, begin: -->
127 <tr>';
128 // Show icon and lines
129 if ($this->showIcon) {
130 $out.='
131 <td nowrap="nowrap"'.$tdParams.'>';
132
133 if (!$h) {
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="" />';
136 } else {
137 for ($a=0;$a<$h;$a++) {
138 if (!$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;
141 } else {
142 # $out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
143 }
144 }
145 }
146 $out.='</td>
147 ';
148 }
149
150 // Init rendering.
151 $colsp='';
152 $lastKey='';
153 $c=0;
154 $ccount=0;
155 $tdP[0] = $this->oddColumnsTDParams ? $this->oddColumnsTDParams : $tdParams;
156 $tdP[1] = $tdParams;
157
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])) {
162 if ($lastKey) {
163 $out.='
164 <td'.
165 $noWrap.
166 $tdP[($ccount%2)].
167 $colsp.
168 $this->addElement_tdParams[$lastKey].
169 '>'.$data[$lastKey].'</td>';
170 }
171 $lastKey=$vKey;
172 $c=1;
173 $ccount++;
174 } else {
175 if (!$lastKey) {$lastKey=$vKey;}
176 $c++;
177 }
178 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
179 }
180 if ($lastKey) { $out.='
181 <td'.$noWrap.$tdP[($ccount%2)].$colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>'; }
182
183 // End row
184 $out.='
185 </tr>';
186
187 // Return row.
188 return $out;
189 }
190
191 /**
192 * Dummy function, used to write the top of a table listing.
193 *
194 * @return void
195 */
196 function writeTop() {
197 }
198
199 /**
200 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
201 *
202 * @return void
203 */
204 function writeBottom() {
205 $this->HTMLcode.='
206
207 <!--
208 End of list table:
209 -->
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);
213 $this->HTMLcode.='
214 </table>';
215 }
216
217 /**
218 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
219 *
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
222 */
223 function fwd_rwd_nav($table='') {
224 $code='';
225 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
226 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
227 // reverse
228 $theData = Array();
229 $titleCol=$this->fieldArray[0];
230 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
231 $code=$this->addElement(1,'',$theData);
232 }
233 return Array(1,$code);
234 } else {
235 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
236 // forward
237 $theData = Array();
238 $titleCol=$this->fieldArray[0];
239 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
240 $code=$this->addElement(1,'',$theData);
241 }
242 return Array(0,$code);
243 }
244
245 }
246
247 /**
248 * Creates the button with link to either forward or reverse
249 *
250 * @param string Type: "fwd" or "rwd"
251 * @param integer Pointer
252 * @param string Table name
253 * @return string
254 * @access private
255 */
256 function fwd_rwd_HTML($type,$pointer,$table='') {
257 $tParam = $table ? '&table='.rawurlencode($table) : '';
258 switch($type) {
259 case 'fwd':
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>';
264 break;
265 case 'rwd':
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>';
270 break;
271 }
272 }
273
274 /**
275 * Creates the URL to this script, including all relevant GPvars
276 *
277 * @param string Alternative id value. Enter blank string for the current id ($this->id)
278 * @return string URL
279 */
280 function listURL($altId='') {
281 return $this->script.
282 '?id='.(strcmp($altId,'')?$altId:$this->id);
283 }
284
285 /**
286 * Returning JavaScript for ClipBoard functionality.
287 *
288 * @return string
289 */
290 function CBfunctions() {
291 return '
292 // checkOffCB()
293 function checkOffCB(listOfCBnames) { //
294 var notChecked=0;
295 var total=0;
296
297 // Checking how many is checked, how many is not
298 var pointer=0;
299 var pos = listOfCBnames.indexOf(",");
300 while (pos!=-1) {
301 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
302 total++;
303 pointer=pos+1;
304 pos = listOfCBnames.indexOf(",",pointer);
305 }
306 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
307 total++;
308
309 // Setting the status...
310 var flag = notChecked*2>total;
311 pointer=0;
312 pos = listOfCBnames.indexOf(",");
313 while (pos!=-1) {
314 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
315
316 pointer=pos+1;
317 pos = listOfCBnames.indexOf(",",pointer);
318 }
319 setcbValue(listOfCBnames.substr(pointer),flag);
320 }
321 // cbValue()
322 function cbValue(CBname) { //
323 var CBfullName = "CBC["+CBname+"]";
324 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
325 }
326 // setcbValue()
327 function setcbValue(CBname,flag) { //
328 CBfullName = "CBC["+CBname+"]";
329 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
330 }
331
332 ';
333 }
334
335 /**
336 * Initializes page languages and icons
337 *
338 * @return void
339 */
340 function initializeLanguages() {
341 global $TCA,$LANG;
342
343 // Look up page overlays:
344 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
345 '*',
346 'pages_language_overlay',
347 'pid='.intval($this->id).
348 t3lib_BEfunc::deleteClause('pages_language_overlay'),
349 '',
350 '',
351 '',
352 'sys_language_uid'
353 );
354
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));
359
360 $this->modSharedTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.SHARED');
361 $this->languageIconTitles = array();
362
363 // Set default:
364 $this->languageIconTitles[0]=array(
365 'uid' => 0,
366 'title' => strlen ($this->modSharedTSconfig['properties']['defaultLanguageFlag']) ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
367 'ISOcode' => 'DEF',
368 'flagIcon' => strlen($this->modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$this->modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$this->modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
369 );
370
371 // Set "All" language:
372 $this->languageIconTitles[-1]=array(
373 'uid' => -1,
374 'title' => $LANG->getLL ('multipleLanguages'),
375 'ISOcode' => 'DEF',
376 'flagIcon' => $flagIconPath.'multi-language.gif',
377 );
378
379 // Find all system languages:
380 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
381 '*',
382 'sys_language',
383 ''
384 );
385 foreach($sys_languages as $row) {
386 $this->languageIconTitles[$row['uid']] = $row;
387
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'];
392 }
393 }
394 if (strlen ($row['flag'])) {
395 $this->languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : '';
396 }
397 }
398 }
399
400 /**
401 * Return the icon for the language
402 *
403 * @param integer Sys language uid
404 * @return string Language icon
405 */
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="" />&nbsp;' : '').
408 htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
409 }
410 }
411
412
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']);
415 }
416 ?>