Initial revision
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (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 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasper@typo3.com>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 79: class t3lib_recordList
43 * 121: function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
44 * 193: function writeTop()
45 * 201: function writeBottom()
46 * 214: function fwd_rwd_nav($table='')
47 * 247: function fwd_rwd_HTML($type,$pointer,$table='')
48 * 270: function listURL()
49 * 279: function CBfunctions()
50 * 282: function checkOffCB(listOfCBnames)
51 * 311: function cbValue(CBname)
52 * 316: function setcbValue(CBname,flag)
53 *
54 * TOTAL FUNCTIONS: 10
55 * (This index is automatically created/updated by the extension "extdeveval")
56 *
57 */
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 /**
75 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
76 *
77 * @see typo3/db_list.php, typo3/file_list.php
78 * @author Kasper Skårhøj <kasper@typo3.com>
79 */
80 class t3lib_recordList {
81 // Used in this class:
82 var $iLimit = 10; // default Max items shown
83 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
84 var $showIcon = 1;
85 var $no_noWrap = 0;
86 var $oddColumnsTDParams =''; // If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
87 var $backPath='';
88 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.
89 var $addElement_tdParams=array(); // Keys are fieldnames and values are td-parameters to add in addElement();
90
91 // Not used in this class - but maybe extension classes...
92 var $fixedL = 50; // Max length of strings
93 var $headLineCol = '#dddddd'; // Head line color
94 var $subHeadLineCol = '#eeeeee';
95 var $script = '';
96 var $thumbScript = 'thumbs.php';
97 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
98
99 var $counter=0; // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
100 var $totalItems = ''; // This could be set to the total number of items. Used by the fwd_rew_navigation...
101
102 // Internal (used in this class.)
103 var $firstElementNumber=0;
104 var $eCounter=0;
105 var $HTMLcode=''; // String with accumulated HTML content
106
107
108
109
110 /**
111 * Returns a table-row with the content from the fields in the input data array.
112 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
113 *
114 * @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'
115 * @param string $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
116 * @param array $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
117 * @param string $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
118 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
119 * @param string $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
120 * @return string HTML content for the table row
121 */
122 function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='') {
123 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
124
125 // Start up:
126 $out='
127 <tr>';
128 // Show icon and lines
129 if ($this->showIcon) {
130 $out.='
131 <td valign="top" align="left" nowrap="nowrap"'.$tdParams.'>';
132
133 if (!$h) {
134 $out.='<img src="'.$this->backPath.'t3lib/gfx/ol/halfline.gif" width="18" height="8" alt="" />';
135 } else {
136 for ($a=0;$a<$h;$a++) {
137 if (!$a) {
138 $out.= $altLine ? $altLine : '<img src="'.$this->backPath.'t3lib/gfx/ol/line.gif" width="18" height="16" alt="" />';
139 if ($icon) $out.= $icon;
140 } else {
141 $out.= $altLine ? $altLine :'<br /><img src="'.$this->backPath.'t3lib/gfx/ol/line.gif" width="18" height="16" alt="" />';
142 }
143 }
144 }
145 $out.='</td>
146 ';
147 }
148
149 // Init rendering.
150 $colsp='';
151 $lastKey='';
152 $c=0;
153 $ccount=0;
154 $tdP[0]= $this->oddColumnsTDParams ? $this->oddColumnsTDParams : $tdParams;
155 $tdP[1]=$tdParams;
156
157 // Traverse field array which contains the data to present:
158 reset($this->fieldArray);
159 while(list(,$vKey)=each($this->fieldArray)) {
160 if (isset($data[$vKey])) {
161 if ($lastKey) {
162 $out.='
163 <td valign="top"'.
164 $noWrap.
165 $tdP[($ccount%2)].
166 $colsp.
167 $this->addElement_tdParams[$lastKey].
168 '>'.$data[$lastKey].'</td>';
169 }
170 $lastKey=$vKey;
171 $c=1;
172 $ccount++;
173 } else {
174 if (!$lastKey) {$lastKey=$vKey;}
175 $c++;
176 }
177 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
178 }
179 if ($lastKey) { $out.='<td valign="top"'.$noWrap.$tdP[($ccount%2)].$colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>'; }
180
181 // End row
182 $out.='
183 </tr>';
184
185 // Return row.
186 return $out;
187 }
188
189 /**
190 * Dummy function, used to write the top of a table listing.
191 *
192 * @return void
193 */
194 function writeTop() {
195 }
196
197 /**
198 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
199 *
200 * @return void
201 */
202 function writeBottom() {
203 $this->HTMLcode.='<table border="0" cellpadding="0" cellspacing="0">';
204 $theIcon='<img src="'.$this->backPath.'t3lib/gfx/ol/stopper.gif" width="18" height="16" alt="" />';
205 $this->HTMLcode.=$this->addElement(1,'','','',$this->leftMargin,$theIcon);
206 $this->HTMLcode.='</table>';
207 }
208
209 /**
210 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
211 *
212 * @param string Table name
213 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
214 */
215 function fwd_rwd_nav($table='') {
216 $code='';
217 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
218 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
219 // reverse
220 $theData = Array();
221 $titleCol=$this->fieldArray[0];
222 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
223 $code=$this->addElement(1,'',$theData);
224 }
225 return Array(1,$code);
226 } else {
227 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
228 // forward
229 $theData = Array();
230 $titleCol=$this->fieldArray[0];
231 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
232 $code=$this->addElement(1,'',$theData);
233 }
234 return Array(0,$code);
235 }
236
237 }
238
239 /**
240 * Creates the button with link to either forward or reverse
241 *
242 * @param string Type: "fwd" or "rwd"
243 * @param integer Pointer
244 * @param string Table name
245 * @return string
246 * @access private
247 */
248 function fwd_rwd_HTML($type,$pointer,$table='') {
249 $tParam = $table ? '&table='.rawurlencode($table) : '';
250 switch($type) {
251 case 'fwd':
252 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
253 return '&nbsp;<a href="'.htmlspecialchars($href).'">'.
254 '<img src="'.$this->backPath.'gfx/pilup.gif" width="14" height="14" valign="top" border="0" alt="" />'.
255 '</a> <i>[1 - '.$pointer.']</i>';
256 break;
257 case 'rwd':
258 $href = $this->listURL().'&pointer='.$pointer.$tParam;
259 return '&nbsp;<a href="'.htmlspecialchars($href).'">'.
260 '<img src="'.$this->backPath.'gfx/pildown.gif" width="14" height="14" valign="top" border="0" alt="" />'.
261 '</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
262 break;
263 }
264 }
265
266 /**
267 * Returning "listURL" - the script with parameters to which forward/backward requests are sent
268 *
269 * @return string
270 */
271 function listURL() {
272 return 'dummy.php?';
273 }
274
275 /**
276 * Returning JavaScript for ClipBoard functionality.
277 *
278 * @return string
279 */
280 function CBfunctions() {
281 return '
282 // checkOffCB()
283 function checkOffCB(listOfCBnames) {
284 var notChecked=0;
285 var total=0;
286
287 // Checking how many is checked, how many is not
288 var pointer=0;
289 var pos = listOfCBnames.indexOf(",");
290 while (pos!=-1) {
291 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
292 total++;
293 pointer=pos+1;
294 pos = listOfCBnames.indexOf(",",pointer);
295 }
296 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
297 total++;
298
299 // Setting the status...
300 var flag = notChecked*2>total;
301 pointer=0;
302 pos = listOfCBnames.indexOf(",");
303 while (pos!=-1) {
304 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
305
306 pointer=pos+1;
307 pos = listOfCBnames.indexOf(",",pointer);
308 }
309 setcbValue(listOfCBnames.substr(pointer),flag);
310 }
311 // cbValue()
312 function cbValue(CBname) {
313 var CBfullName = "CBC["+CBname+"]";
314 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
315 }
316 // setcbValue()
317 function setcbValue(CBname,flag) {
318 CBfullName = "CBC["+CBname+"]";
319 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
320 }
321
322 ';
323 }
324 }
325
326
327 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
328 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
329 }
330 ?>