Tons of changes made to the CORE. All scripts has more a less been modified. Primaril...
[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 * 78: class t3lib_recordList
42 * 119: function addElement($h,$icon,$data,$tdParams='',$lMargin='',$altLine='')
43 * 193: function writeTop()
44 * 201: function writeBottom()
45 * 220: function fwd_rwd_nav($table='')
46 * 253: function fwd_rwd_HTML($type,$pointer,$table='')
47 * 276: function listURL()
48 * 285: 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 } else {
134 for ($a=0;$a<$h;$a++) {
135 if (!$a) {
136 $out.= $altLine ? $altLine : '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
137 if ($icon) $out.= $icon;
138 } else {
139 $out.= $altLine ? $altLine :'<br /><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />';
140 }
141 }
142 }
143 $out.='</td>
144 ';
145 }
146
147 // Init rendering.
148 $colsp='';
149 $lastKey='';
150 $c=0;
151 $ccount=0;
152 $tdP[0]= $this->oddColumnsTDParams ? $this->oddColumnsTDParams : $tdParams;
153 $tdP[1]=$tdParams;
154
155 // Traverse field array which contains the data to present:
156 reset($this->fieldArray);
157 while(list(,$vKey)=each($this->fieldArray)) {
158 if (isset($data[$vKey])) {
159 if ($lastKey) {
160 $out.='
161 <td'.
162 $noWrap.
163 $tdP[($ccount%2)].
164 $colsp.
165 $this->addElement_tdParams[$lastKey].
166 '>'.$data[$lastKey].'</td>';
167 }
168 $lastKey=$vKey;
169 $c=1;
170 $ccount++;
171 } else {
172 if (!$lastKey) {$lastKey=$vKey;}
173 $c++;
174 }
175 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
176 }
177 if ($lastKey) { $out.='
178 <td'.$noWrap.$tdP[($ccount%2)].$colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>'; }
179
180 // End row
181 $out.='
182 </tr>';
183
184 // Return row.
185 return $out;
186 }
187
188 /**
189 * Dummy function, used to write the top of a table listing.
190 *
191 * @return void
192 */
193 function writeTop() {
194 }
195
196 /**
197 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
198 *
199 * @return void
200 */
201 function writeBottom() {
202 $this->HTMLcode.='
203
204 <!--
205 End of list table:
206 -->
207 <table border="0" cellpadding="0" cellspacing="0">';
208 $theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" />';
209 $this->HTMLcode.=$this->addElement(1,'','','',$this->leftMargin,$theIcon);
210 $this->HTMLcode.='
211 </table>';
212 }
213
214 /**
215 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
216 *
217 * @param string Table name
218 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
219 */
220 function fwd_rwd_nav($table='') {
221 $code='';
222 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
223 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
224 // reverse
225 $theData = Array();
226 $titleCol=$this->fieldArray[0];
227 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
228 $code=$this->addElement(1,'',$theData);
229 }
230 return Array(1,$code);
231 } else {
232 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
233 // forward
234 $theData = Array();
235 $titleCol=$this->fieldArray[0];
236 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
237 $code=$this->addElement(1,'',$theData);
238 }
239 return Array(0,$code);
240 }
241
242 }
243
244 /**
245 * Creates the button with link to either forward or reverse
246 *
247 * @param string Type: "fwd" or "rwd"
248 * @param integer Pointer
249 * @param string Table name
250 * @return string
251 * @access private
252 */
253 function fwd_rwd_HTML($type,$pointer,$table='') {
254 $tParam = $table ? '&table='.rawurlencode($table) : '';
255 switch($type) {
256 case 'fwd':
257 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
258 return '<a href="'.htmlspecialchars($href).'">'.
259 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pilup.gif','width="14" height="14"').' alt="" />'.
260 '</a> <i>[1 - '.$pointer.']</i>';
261 break;
262 case 'rwd':
263 $href = $this->listURL().'&pointer='.$pointer.$tParam;
264 return '<a href="'.htmlspecialchars($href).'">'.
265 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/pildown.gif','width="14" height="14"').' alt="" />'.
266 '</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
267 break;
268 }
269 }
270
271 /**
272 * Returning "listURL" - the script with parameters to which forward/backward requests are sent
273 *
274 * @return string
275 */
276 function listURL() {
277 return 'dummy.php?';
278 }
279
280 /**
281 * Returning JavaScript for ClipBoard functionality.
282 *
283 * @return string
284 */
285 function CBfunctions() {
286 return '
287 // checkOffCB()
288 function checkOffCB(listOfCBnames) { //
289 var notChecked=0;
290 var total=0;
291
292 // Checking how many is checked, how many is not
293 var pointer=0;
294 var pos = listOfCBnames.indexOf(",");
295 while (pos!=-1) {
296 if (!cbValue(listOfCBnames.substr(pointer,pos-pointer))) notChecked++;
297 total++;
298 pointer=pos+1;
299 pos = listOfCBnames.indexOf(",",pointer);
300 }
301 if (!cbValue(listOfCBnames.substr(pointer))) notChecked++;
302 total++;
303
304 // Setting the status...
305 var flag = notChecked*2>total;
306 pointer=0;
307 pos = listOfCBnames.indexOf(",");
308 while (pos!=-1) {
309 setcbValue(listOfCBnames.substr(pointer,pos-pointer),flag);
310
311 pointer=pos+1;
312 pos = listOfCBnames.indexOf(",",pointer);
313 }
314 setcbValue(listOfCBnames.substr(pointer),flag);
315 }
316 // cbValue()
317 function cbValue(CBname) { //
318 var CBfullName = "CBC["+CBname+"]";
319 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
320 }
321 // setcbValue()
322 function setcbValue(CBname,flag) { //
323 CBfullName = "CBC["+CBname+"]";
324 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
325 }
326
327 ';
328 }
329 }
330
331
332 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
333 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
334 }
335 ?>