Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 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 * 81: class t3lib_recordList
42 * 123: function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
43 * 195: function writeTop()
44 * 203: function writeBottom()
45 * 216: function fwd_rwd_nav($table='')
46 * 249: function fwd_rwd_HTML($type,$pointer,$table='')
47 * 272: function listURL()
48 * 281: function CBfunctions()
49 * 284: function checkOffCB(listOfCBnames)
50 * 313: function cbValue(CBname)
51 * 318: function setcbValue(CBname,flag)
52 *
53 * TOTAL FUNCTIONS: 10
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 /**
74 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
75 *
76 * @author Kasper Skaarhoj <kasper@typo3.com>
77 * @package TYPO3
78 * @subpackage t3lib
79 * @see typo3/db_list.php, typo3/file_list.php
80 */
81 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
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 $headLineCol = '#dddddd'; // Head line color
95 var $subHeadLineCol = '#eeeeee';
96 var $script = '';
97 var $thumbScript = 'thumbs.php';
98 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
99
100 var $counter=0; // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
101 var $totalItems = ''; // This could be set to the total number of items. Used by the fwd_rew_navigation...
102
103 // Internal (used in this class.)
104 var $firstElementNumber=0;
105 var $eCounter=0;
106 var $HTMLcode=''; // String with accumulated HTML content
107
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 <tr>';
129 // Show icon and lines
130 if ($this->showIcon) {
131 $out.='
132 <td valign="top" align="left" nowrap="nowrap"'.$tdParams.'>';
133
134 if (!$h) {
135 $out.='<img src="'.$this->backPath.'t3lib/gfx/ol/halfline.gif" width="18" height="8" alt="" />';
136 } else {
137 for ($a=0;$a<$h;$a++) {
138 if (!$a) {
139 $out.= $altLine ? $altLine : '<img src="'.$this->backPath.'t3lib/gfx/ol/line.gif" width="18" height="16" alt="" />';
140 if ($icon) $out.= $icon;
141 } else {
142 $out.= $altLine ? $altLine :'<br /><img src="'.$this->backPath.'t3lib/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 valign="top"'.
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.='<td valign="top"'.$noWrap.$tdP[($ccount%2)].$colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>'; }
181
182 // End row
183 $out.='
184 </tr>';
185
186 // Return row.
187 return $out;
188 }
189
190 /**
191 * Dummy function, used to write the top of a table listing.
192 *
193 * @return void
194 */
195 function writeTop() {
196 }
197
198 /**
199 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
200 *
201 * @return void
202 */
203 function writeBottom() {
204 $this->HTMLcode.='<table border="0" cellpadding="0" cellspacing="0">';
205 $theIcon='<img src="'.$this->backPath.'t3lib/gfx/ol/stopper.gif" width="18" height="16" alt="" />';
206 $this->HTMLcode.=$this->addElement(1,'','','',$this->leftMargin,$theIcon);
207 $this->HTMLcode.='</table>';
208 }
209
210 /**
211 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
212 *
213 * @param string Table name
214 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
215 */
216 function fwd_rwd_nav($table='') {
217 $code='';
218 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
219 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
220 // reverse
221 $theData = Array();
222 $titleCol=$this->fieldArray[0];
223 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
224 $code=$this->addElement(1,'',$theData);
225 }
226 return Array(1,$code);
227 } else {
228 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
229 // forward
230 $theData = Array();
231 $titleCol=$this->fieldArray[0];
232 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
233 $code=$this->addElement(1,'',$theData);
234 }
235 return Array(0,$code);
236 }
237
238 }
239
240 /**
241 * Creates the button with link to either forward or reverse
242 *
243 * @param string Type: "fwd" or "rwd"
244 * @param integer Pointer
245 * @param string Table name
246 * @return string
247 * @access private
248 */
249 function fwd_rwd_HTML($type,$pointer,$table='') {
250 $tParam = $table ? '&table='.rawurlencode($table) : '';
251 switch($type) {
252 case 'fwd':
253 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
254 return '&nbsp;<a href="'.htmlspecialchars($href).'">'.
255 '<img src="'.$this->backPath.'gfx/pilup.gif" width="14" height="14" valign="top" border="0" alt="" />'.
256 '</a> <i>[1 - '.$pointer.']</i>';
257 break;
258 case 'rwd':
259 $href = $this->listURL().'&pointer='.$pointer.$tParam;
260 return '&nbsp;<a href="'.htmlspecialchars($href).'">'.
261 '<img src="'.$this->backPath.'gfx/pildown.gif" width="14" height="14" valign="top" border="0" alt="" />'.
262 '</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
263 break;
264 }
265 }
266
267 /**
268 * Returning "listURL" - the script with parameters to which forward/backward requests are sent
269 *
270 * @return string
271 */
272 function listURL() {
273 return 'dummy.php?';
274 }
275
276 /**
277 * Returning JavaScript for ClipBoard functionality.
278 *
279 * @return string
280 */
281 function CBfunctions() {
282 return '
283 // checkOffCB()
284 function checkOffCB(listOfCBnames) {
285 var notChecked=0;
286 var total=0;
287
288 // Checking how many is checked, how many is not
289 var pointer=0;
290 var pos = listOfCBnames.indexOf(",");
291 while (pos!=-1) {
292 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
293 total++;
294 pointer=pos+1;
295 pos = listOfCBnames.indexOf(",",pointer);
296 }
297 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
298 total++;
299
300 // Setting the status...
301 var flag = notChecked*2>total;
302 pointer=0;
303 pos = listOfCBnames.indexOf(",");
304 while (pos!=-1) {
305 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
306
307 pointer=pos+1;
308 pos = listOfCBnames.indexOf(",",pointer);
309 }
310 setcbValue(listOfCBnames.substr(pointer),flag);
311 }
312 // cbValue()
313 function cbValue(CBname) {
314 var CBfullName = "CBC["+CBname+"]";
315 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
316 }
317 // setcbValue()
318 function setcbValue(CBname,flag) {
319 CBfullName = "CBC["+CBname+"]";
320 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
321 }
322
323 ';
324 }
325 }
326
327
328 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
329 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
330 }
331 ?>