Fixed bug #14627: SpriteIcons: Several Icons replaced with non-existent sprite-Icons...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 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 * 284: function listURL($altId='')
48 * 294: function CBfunctions()
49 * 344: function initializeLanguages()
50 * 411: 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 = ''; // Deprecated since TYPO3 4.2, remove in 4.4. If set this is <td>-params for odd columns in addElement. Used with db_layout / pages section
88 var $oddColumnsCssClass = ''; // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
89 var $backPath='';
90 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.
91 var $addElement_tdParams = array(); // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
92 var $addElement_tdCssClass = array(); // Keys are fieldnames and values are td-css-classes to add in addElement();
93
94 // Not used in this class - but maybe extension classes...
95 var $fixedL = 30; // Max length of strings
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 var $pageOverlays = array(); // Contains page translation languages
109 var $languageIconTitles = array(); // Contains sys language icons and titles
110 var $translateTools; // translateTools object
111
112 /**
113 * constructor for t3lib_recordList
114 *
115 * @author Ingo Renner <ingo@typo3.org>
116 */
117 public function __construct() {
118 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
119 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
120 }
121 $this->getTranslateTools();
122 }
123
124
125 /**
126 * Returns a table-row with the content from the fields in the input data array.
127 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
128 *
129 * @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'
130 * @param string $icon is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
131 * @param array $data is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
132 * @param string $tdParams is insert in the <td>-tags. Must carry a ' ' as first character
133 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
134 * @param string $altLine is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
135 * @return string HTML content for the table row
136 */
137 function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
138 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
139
140 // Start up:
141 $out='
142 <!-- Element, begin: -->
143 <tr '.$trParams.'>';
144 // Show icon and lines
145 if ($this->showIcon) {
146 $out.='
147 <td nowrap="nowrap" class="col-icon">';
148
149 if (!$h) {
150 $out.='<img src="clear.gif" width="1" height="8" alt="" />';
151 } else {
152 for ($a=0;$a<$h;$a++) {
153 if (!$a) {
154 if ($icon) $out.= $icon;
155 } else {
156 }
157 }
158 }
159 $out.='</td>
160 ';
161 }
162
163 // Init rendering.
164 $colsp='';
165 $lastKey='';
166 $c=0;
167 $ccount=0;
168
169 // Traverse field array which contains the data to present:
170 foreach ($this->fieldArray as $vKey) {
171 if (isset($data[$vKey])) {
172 if ($lastKey) {
173 $cssClass = $this->addElement_tdCssClass[$lastKey];
174 if($this->oddColumnsCssClass && $ccount % 2 == 0) {
175 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
176 }
177
178 $out.='
179 <td'.
180 $noWrap.
181 ' class="' . $cssClass . '"'.
182 $colsp.
183 $this->addElement_tdParams[$lastKey].
184 '>'.$data[$lastKey].'</td>';
185 }
186 $lastKey=$vKey;
187 $c=1;
188 $ccount++;
189 } else {
190 if (!$lastKey) {$lastKey=$vKey;}
191 $c++;
192 }
193 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
194 }
195 if ($lastKey) {
196 $cssClass = $this->addElement_tdCssClass[$lastKey];
197 if($this->oddColumnsCssClass) {
198 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
199 }
200
201 $out.='
202 <td'.$noWrap.' class="' . $cssClass . '"' . $colsp.$this->addElement_tdParams[$lastKey].'>'.$data[$lastKey].'</td>'; }
203
204 // End row
205 $out.='
206 </tr>';
207
208 // Return row.
209 return $out;
210 }
211
212 /**
213 * Dummy function, used to write the top of a table listing.
214 *
215 * @return void
216 */
217 function writeTop() {
218 }
219
220 /**
221 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
222 *
223 * @return void
224 */
225 function writeBottom() {
226 $this->HTMLcode.='
227
228 <!--
229 End of list table:
230 -->
231 <table border="0" cellpadding="0" cellspacing="0">';
232 $theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" />';
233 $this->HTMLcode.=$this->addElement(1,'','','',$this->leftMargin,$theIcon);
234 $this->HTMLcode.='
235 </table>';
236 }
237
238 /**
239 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
240 *
241 * @param string Table name
242 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
243 */
244 function fwd_rwd_nav($table='') {
245 $code='';
246 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber+$this->iLimit) {
247 if ($this->firstElementNumber && $this->eCounter==$this->firstElementNumber) {
248 // reverse
249 $theData = Array();
250 $titleCol=$this->fieldArray[0];
251 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd',$this->eCounter,$table);
252 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
253 }
254 return array(1, $code);
255 } else {
256 if ($this->eCounter==$this->firstElementNumber+$this->iLimit) {
257 // forward
258 $theData = Array();
259 $titleCol=$this->fieldArray[0];
260 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd',$this->eCounter,$table);
261 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
262 }
263 return array(0, $code);
264 }
265
266 }
267
268 /**
269 * Creates the button with link to either forward or reverse
270 *
271 * @param string Type: "fwd" or "rwd"
272 * @param integer Pointer
273 * @param string Table name
274 * @return string
275 * @access private
276 */
277 function fwd_rwd_HTML($type,$pointer,$table='') {
278 $content = '';
279 $tParam = $table ? '&table='.rawurlencode($table) : '';
280 switch($type) {
281 case 'fwd':
282 $href = $this->listURL().'&pointer='.($pointer-$this->iLimit).$tParam;
283 $content = '<a href="'.htmlspecialchars($href).'">'.
284 t3lib_iconWorks::getSpriteIcon('actions-move-up').
285 '</a> <i>[1 - '.$pointer.']</i>';
286 break;
287 case 'rwd':
288 $href = $this->listURL().'&pointer='.$pointer.$tParam;
289 $content = '<a href="'.htmlspecialchars($href).'">'.
290 t3lib_iconWorks::getSpriteIcon('actions-move-down').
291 '</a> <i>['.($pointer+1).' - '.$this->totalItems.']</i>';
292 break;
293 }
294 return $content;
295 }
296
297 /**
298 * Creates the URL to this script, including all relevant GPvars
299 *
300 * @param string Alternative id value. Enter blank string for the current id ($this->id)
301 * @return string URL
302 */
303 function listURL($altId='') {
304 return $this->script.
305 '?id='.(strcmp($altId,'')?$altId:$this->id);
306 }
307
308 /**
309 * Returning JavaScript for ClipBoard functionality.
310 *
311 * @return string
312 */
313 function CBfunctions() {
314 return '
315 // checkOffCB()
316 function checkOffCB(listOfCBnames, link) { //
317 var checkBoxes, flag, i;
318 var checkBoxes = listOfCBnames.split(",");
319 if (link.rel === "") {
320 link.rel = "allChecked";
321 flag = true;
322 } else {
323 link.rel = "";
324 flag = false;
325 }
326 for (i = 0; i < checkBoxes.length; i++) {
327 setcbValue(checkBoxes[i], flag);
328 }
329 }
330 // cbValue()
331 function cbValue(CBname) { //
332 var CBfullName = "CBC["+CBname+"]";
333 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
334 }
335 // setcbValue()
336 function setcbValue(CBname,flag) { //
337 CBfullName = "CBC["+CBname+"]";
338 if(document.dblistForm[CBfullName]) {
339 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
340 }
341 }
342
343 ';
344 }
345
346 /**
347 * Initializes page languages and icons
348 *
349 * @return void
350 */
351 function initializeLanguages() {
352 global $TCA,$LANG;
353
354 // Look up page overlays:
355 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
356 '*',
357 'pages_language_overlay',
358 'pid='.intval($this->id).
359 t3lib_BEfunc::deleteClause('pages_language_overlay').
360 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
361 '',
362 '',
363 '',
364 'sys_language_uid'
365 );
366
367 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
368 }
369
370 /**
371 * Return the icon for the language
372 *
373 * @param integer Sys language uid
374 * @return string Language icon
375 */
376 function languageFlag($sys_language_uid) {
377 return ($this->languageIconTitles[$sys_language_uid]['flagIcon'] ? '<img src="'.$this->languageIconTitles[$sys_language_uid]['flagIcon'].'" class="absmiddle" alt="" />&nbsp;' : '').
378 htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
379 }
380
381 /**
382 * Gets an instance of t3lib_transl8tools.
383 *
384 * @return t3lib_transl8tools
385 */
386 protected function getTranslateTools() {
387 if (!isset($this->translateTools)) {
388 $this->translateTools = t3lib_div::makeInstance('t3lib_transl8tools');
389 }
390 return $this->translateTools;
391 }
392 }
393
394
395 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
396 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_recordlist.php']);
397 }
398
399 ?>