Versioning and localization details (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
105
106
107 /**
108 * Returns a table-row with the content from the fields in the input data array.
109 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
110 *
111 * @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'
112 * @param string $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
113 * @param array $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
114 * @param string $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
115 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
116 * @param string $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
117 * @return string HTML content for the table row
118 */
119 function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='') {
120 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
121
122 // Start up:
123 $out='
124 <!-- Element, begin: -->
125 <tr>';
126 // Show icon and lines
127 if ($this->showIcon) {
128 $out.='
129 <td nowrap="nowrap"'.$tdParams.'>';
130
131 if (!$h) {
132 # $out.='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
133 $out.='<img src="clear.gif" width="1" height="8" alt="" />';
134 } else {
135 for ($a=0;$a<$h;$a++) {
136 if (!$a) {
137 # $out.= $altLine ? $altLine : '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
138 if ($icon) $out.= $icon;
139 } else {
140 # $out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
141 }
142 }
143 }
144 $out.='</td>
145 ';
146 }
147
148 // Init rendering.
149 $colsp='';
150 $lastKey='';
151 $c=0;
152 $ccount=0;
153 $tdP[0] = $this->oddColumnsTDParams ? $this->oddColumnsTDParams : $tdParams;
154 $tdP[1] = $tdParams;
155
156 // Traverse field array which contains the data to present:
157 reset($this->fieldArray);
158 while(list(,$vKey)=each($this->fieldArray)) {
159 if (isset($data[$vKey])) {
160 if ($lastKey) {
161 $out.='
162 <td'.
163 $noWrap.
164 $tdP[($ccount%2)].
165 $colsp.
166 $this->addElement_tdParams[$lastKey].
167 '>'.$data[$lastKey].'</td>';
168 }
169 $lastKey=$vKey;
170 $c=1;
171 $ccount++;
172 } else {
173 if (!$lastKey) {$lastKey=$vKey;}
174 $c++;
175 }
176 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
177 }
178 if ($lastKey) { $out.='
179 <td'.$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.='
204
205 <!--
206 End of list table:
207 -->
208 <table border="0" cellpadding="0" cellspacing="0">';
209 $theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" />';
210 $this->HTMLcode.=$this->addElement(1,'','','',$this->leftMargin,$theIcon);
211 $this->HTMLcode.='
212 </table>';
213 }
214
215 /**
216 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
217 *
218 * @param string Table name
219 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
220 */
221 function fwd_rwd_nav($table='') {
222 $code='';
223 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
224 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
225 // reverse
226 $theData = Array();
227 $titleCol=$this->fieldArray[0];
228 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
229 $code=$this->addElement(1,'',$theData);
230 }
231 return Array(1,$code);
232 } else {
233 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
234 // forward
235 $theData = Array();
236 $titleCol=$this->fieldArray[0];
237 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
238 $code=$this->addElement(1,'',$theData);
239 }
240 return Array(0,$code);
241 }
242
243 }
244
245 /**
246 * Creates the button with link to either forward or reverse
247 *
248 * @param string Type: "fwd" or "rwd"
249 * @param integer Pointer
250 * @param string Table name
251 * @return string
252 * @access private
253 */
254 function fwd_rwd_HTML($type,$pointer,$table='') {
255 $tParam = $table ? '&table='.rawurlencode($table) : '';
256 switch($type) {
257 case 'fwd':
258 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
259 return '<a href="'.htmlspecialchars($href).'">'.
260 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pilup.gif','width="14" height="14"').' alt="" />'.
261 '</a> <i>[1 - '.$pointer.']</i>';
262 break;
263 case 'rwd':
264 $href = $this->listURL().'&pointer='.$pointer.$tParam;
265 return '<a href="'.htmlspecialchars($href).'">'.
266 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pildown.gif','width="14" height="14"').' alt="" />'.
267 '</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
268 break;
269 }
270 }
271
272 /**
273 * Creates the URL to this script, including all relevant GPvars
274 *
275 * @param string Alternative id value. Enter blank string for the current id ($this->id)
276 * @return string URL
277 */
278 function listURL($altId='') {
279 return $this->script.
280 '?id='.(strcmp($altId,'')?$altId:$this->id);
281 }
282
283 /**
284 * Returning JavaScript for ClipBoard functionality.
285 *
286 * @return string
287 */
288 function CBfunctions() {
289 return '
290 // checkOffCB()
291 function checkOffCB(listOfCBnames) { //
292 var notChecked=0;
293 var total=0;
294
295 // Checking how many is checked, how many is not
296 var pointer=0;
297 var pos = listOfCBnames.indexOf(",");
298 while (pos!=-1) {
299 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
300 total++;
301 pointer=pos+1;
302 pos = listOfCBnames.indexOf(",",pointer);
303 }
304 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
305 total++;
306
307 // Setting the status...
308 var flag = notChecked*2>total;
309 pointer=0;
310 pos = listOfCBnames.indexOf(",");
311 while (pos!=-1) {
312 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
313
314 pointer=pos+1;
315 pos = listOfCBnames.indexOf(",",pointer);
316 }
317 setcbValue(listOfCBnames.substr(pointer),flag);
318 }
319 // cbValue()
320 function cbValue(CBname) { //
321 var CBfullName = "CBC["+CBname+"]";
322 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
323 }
324 // setcbValue()
325 function setcbValue(CBname,flag) { //
326 CBfullName = "CBC["+CBname+"]";
327 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
328 }
329
330 ';
331 }
332 }
333
334
335 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
336 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
337 }
338 ?>