*** empty log message ***
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.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 * 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 <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
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 * 282: function listURL($altId='')
48 * 292: function CBfunctions()
49 * 342: function initializeLanguages()
50 * 408: function languageFlag($sys_language_uid)
51 *
52 * TOTAL FUNCTIONS: 9
53 * (This index is automatically created/updated by the extension "extdeveval")
54 *
55 */
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 /**
73 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
74 *
75 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
76 * @package TYPO3
77 * @subpackage t3lib
78 * @see typo3/db_list.php, typo3/file_list.php
79 */
80 class t3lib_recordList {
81
82 // Used in this class:
83 var $iLimit = 10; // default Max items shown
84 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
85 var $showIcon = 1;
86 var $no_noWrap = 0;
87 var $oddColumnsTDParams =''; // If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
88 var $backPath='';
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();
91
92 // Not used in this class - but maybe extension classes...
93 var $fixedL = 50; // Max length of strings
94 var $script = '';
95 var $thumbScript = 'thumbs.php';
96 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
97
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...
100
101 // Internal (used in this class.)
102 var $firstElementNumber=0;
103 var $eCounter=0;
104 var $HTMLcode=''; // String with accumulated HTML content
105
106 var $pageOverlays = array(); // Contains page translation languages
107 var $languageIconTitles = array(); // Contains sys language icons and titles
108
109
110
111 /**
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)
114 *
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
122 */
123 function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='') {
124 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
125
126 // Start up:
127 $out='
128 <!-- Element, begin: -->
129 <tr>';
130 // Show icon and lines
131 if ($this->showIcon) {
132 $out.='
133 <td nowrap="nowrap"'.$tdParams.'>';
134
135 if (!$h) {
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="" />';
138 } else {
139 for ($a=0;$a<$h;$a++) {
140 if (!$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;
143 } else {
144 # $out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
145 }
146 }
147 }
148 $out.='</td>
149 ';
150 }
151
152 // Init rendering.
153 $colsp='';
154 $lastKey='';
155 $c=0;
156 $ccount=0;
157 $tdP[0] = $this->oddColumnsTDParams ? $this->oddColumnsTDParams : $tdParams;
158 $tdP[1] = $tdParams;
159
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])) {
164 if ($lastKey) {
165 $out.='
166 <td'.
167 $noWrap.
168 $tdP[($ccount%2)].
169 $colsp.
170 $this->addElement_tdParams[$lastKey].
171 '>'.$data[$lastKey].'</td>';
172 }
173 $lastKey=$vKey;
174 $c=1;
175 $ccount++;
176 } else {
177 if (!$lastKey) {$lastKey=$vKey;}
178 $c++;
179 }
180 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
181 }
182 if ($lastKey) { $out.='
183 <td'.$noWrap.$tdP[($ccount%2)].$colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>'; }
184
185 // End row
186 $out.='
187 </tr>';
188
189 // Return row.
190 return $out;
191 }
192
193 /**
194 * Dummy function, used to write the top of a table listing.
195 *
196 * @return void
197 */
198 function writeTop() {
199 }
200
201 /**
202 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
203 *
204 * @return void
205 */
206 function writeBottom() {
207 $this->HTMLcode.='
208
209 <!--
210 End of list table:
211 -->
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);
215 $this->HTMLcode.='
216 </table>';
217 }
218
219 /**
220 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
221 *
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
224 */
225 function fwd_rwd_nav($table='') {
226 $code='';
227 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
228 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
229 // reverse
230 $theData = Array();
231 $titleCol=$this->fieldArray[0];
232 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
233 $code=$this->addElement(1,'',$theData);
234 }
235 return Array(1,$code);
236 } else {
237 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
238 // forward
239 $theData = Array();
240 $titleCol=$this->fieldArray[0];
241 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
242 $code=$this->addElement(1,'',$theData);
243 }
244 return Array(0,$code);
245 }
246
247 }
248
249 /**
250 * Creates the button with link to either forward or reverse
251 *
252 * @param string Type: "fwd" or "rwd"
253 * @param integer Pointer
254 * @param string Table name
255 * @return string
256 * @access private
257 */
258 function fwd_rwd_HTML($type,$pointer,$table='') {
259 $tParam = $table ? '&table='.rawurlencode($table) : '';
260 switch($type) {
261 case 'fwd':
262 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
263 return '<a href="'.htmlspecialchars($href).'">'.
264 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pilup.gif','width="14" height="14"').' alt="" />'.
265 '</a> <i>[1 - '.$pointer.']</i>';
266 break;
267 case 'rwd':
268 $href = $this->listURL().'&pointer='.$pointer.$tParam;
269 return '<a href="'.htmlspecialchars($href).'">'.
270 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pildown.gif','width="14" height="14"').' alt="" />'.
271 '</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
272 break;
273 }
274 }
275
276 /**
277 * Creates the URL to this script, including all relevant GPvars
278 *
279 * @param string Alternative id value. Enter blank string for the current id ($this->id)
280 * @return string URL
281 */
282 function listURL($altId='') {
283 return $this->script.
284 '?id='.(strcmp($altId,'')?$altId:$this->id);
285 }
286
287 /**
288 * Returning JavaScript for ClipBoard functionality.
289 *
290 * @return string
291 */
292 function CBfunctions() {
293 return '
294 // checkOffCB()
295 function checkOffCB(listOfCBnames) { //
296 var notChecked=0;
297 var total=0;
298
299 // Checking how many is checked, how many is not
300 var pointer=0;
301 var pos = listOfCBnames.indexOf(",");
302 while (pos!=-1) {
303 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
304 total++;
305 pointer=pos+1;
306 pos = listOfCBnames.indexOf(",",pointer);
307 }
308 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
309 total++;
310
311 // Setting the status...
312 var flag = notChecked*2>total;
313 pointer=0;
314 pos = listOfCBnames.indexOf(",");
315 while (pos!=-1) {
316 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
317
318 pointer=pos+1;
319 pos = listOfCBnames.indexOf(",",pointer);
320 }
321 setcbValue(listOfCBnames.substr(pointer),flag);
322 }
323 // cbValue()
324 function cbValue(CBname) { //
325 var CBfullName = "CBC["+CBname+"]";
326 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
327 }
328 // setcbValue()
329 function setcbValue(CBname,flag) { //
330 CBfullName = "CBC["+CBname+"]";
331 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
332 }
333
334 ';
335 }
336
337 /**
338 * Initializes page languages and icons
339 *
340 * @return void
341 */
342 function initializeLanguages() {
343 global $TCA,$LANG;
344
345 // Look up page overlays:
346 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
347 '*',
348 'pages_language_overlay',
349 'pid='.intval($this->id).
350 t3lib_BEfunc::deleteClause('pages_language_overlay').
351 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
352 '',
353 '',
354 '',
355 'sys_language_uid'
356 );
357
358 // icons and language titles:
359 t3lib_div::loadTCA ('sys_language');
360 $flagAbsPath = t3lib_div::getFileAbsFileName($TCA['sys_language']['columns']['flag']['config']['fileFolder']);
361 $flagIconPath = $this->backPath.'../'.substr($flagAbsPath, strlen(PATH_site));
362
363 $this->modSharedTSconfig = t3lib_BEfunc::getModTSconfig($this->id, 'mod.SHARED');
364 $this->languageIconTitles = array();
365
366 // Set default:
367 $this->languageIconTitles[0]=array(
368 'uid' => 0,
369 'title' => strlen ($this->modSharedTSconfig['properties']['defaultLanguageFlag']) ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$LANG->getLL('defaultLanguage').')' : $LANG->getLL('defaultLanguage'),
370 'ISOcode' => 'DEF',
371 'flagIcon' => strlen($this->modSharedTSconfig['properties']['defaultLanguageFlag']) && @is_file($flagAbsPath.$this->modSharedTSconfig['properties']['defaultLanguageFlag']) ? $flagIconPath.$this->modSharedTSconfig['properties']['defaultLanguageFlag'] : null,
372 );
373
374 // Set "All" language:
375 $this->languageIconTitles[-1]=array(
376 'uid' => -1,
377 'title' => $LANG->getLL ('multipleLanguages'),
378 'ISOcode' => 'DEF',
379 'flagIcon' => $flagIconPath.'multi-language.gif',
380 );
381
382 // Find all system languages:
383 $sys_languages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
384 '*',
385 'sys_language',
386 ''
387 );
388 foreach($sys_languages as $row) {
389 $this->languageIconTitles[$row['uid']] = $row;
390
391 if ($row['static_lang_isocode']) {
392 $staticLangRow = t3lib_BEfunc::getRecord('static_languages',$row['static_lang_isocode'],'lg_iso_2');
393 if ($staticLangRow['lg_iso_2']) {
394 $this->languageIconTitles[$row['uid']]['ISOcode'] = $staticLangRow['lg_iso_2'];
395 }
396 }
397 if (strlen ($row['flag'])) {
398 $this->languageIconTitles[$row['uid']]['flagIcon'] = @is_file($flagAbsPath.$row['flag']) ? $flagIconPath.$row['flag'] : '';
399 }
400 }
401 }
402
403 /**
404 * Return the icon for the language
405 *
406 * @param integer Sys language uid
407 * @return string Language icon
408 */
409 function languageFlag($sys_language_uid) {
410 return ($this->languageIconTitles[$sys_language_uid]['flagIcon'] ? '<img src="'.$this->languageIconTitles[$sys_language_uid]['flagIcon'].'" class="absmiddle" alt="" />&nbsp;' : '').
411 htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
412 }
413 }
414
415
416 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
417 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
418 }
419 ?>