[FEATURE] Use mod dispatcher for filelist module
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_recordlist.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36 /**
37 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 * @package TYPO3
41 * @subpackage t3lib
42 * @see typo3/db_list.php, typo3/sysext/filelist/mod1/index.php
43 */
44 class t3lib_recordList {
45
46 // Used in this class:
47 // default Max items shown
48 var $iLimit = 10;
49 // OBSOLETE - NOT USED ANYMORE. leftMargin
50 var $leftMargin = 0;
51 var $showIcon = 1;
52 var $no_noWrap = 0;
53 // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
54 var $oddColumnsCssClass = '';
55 var $backPath = '';
56 // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
57 var $fieldArray = array();
58 // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
59 var $addElement_tdParams = array();
60 // Keys are fieldnames and values are td-css-classes to add in addElement();
61 var $addElement_tdCssClass = array();
62
63 // Not used in this class - but maybe extension classes...
64 // Max length of strings
65 var $fixedL = 30;
66 var $script = '';
67 // Set to zero, if you don't want a left-margin with addElement function
68 var $setLMargin = 1;
69
70 // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
71 var $counter = 0;
72 // This could be set to the total number of items. Used by the fwd_rew_navigation...
73 var $totalItems = '';
74
75 // Internal (used in this class.)
76 var $firstElementNumber = 0;
77 var $eCounter = 0;
78 // String with accumulated HTML content
79 var $HTMLcode = '';
80
81 // Contains page translation languages
82 var $pageOverlays = array();
83 // Contains sys language icons and titles
84 var $languageIconTitles = array();
85 // TranslateTools object
86 var $translateTools;
87
88 /**
89 * Constructor for t3lib_recordList
90 */
91 public function __construct() {
92 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
93 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
94 }
95 $this->getTranslateTools();
96 }
97
98
99 /**
100 * Returns a table-row with the content from the fields in the input data array.
101 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
102 *
103 * @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'
104 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
105 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
106 * @param string $tdParams Is insert in the <td>-tags. Must carry a ' ' as first character
107 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
108 * @param string $altLine Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
109 * @return string HTML content for the table row
110 */
111 function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
112 $noWrap = ($this->no_noWrap) ? '' : ' nowrap="nowrap"';
113
114 // Start up:
115 $out = '
116 <!-- Element, begin: -->
117 <tr ' . $trParams . '>';
118 // Show icon and lines
119 if ($this->showIcon) {
120 $out .= '
121 <td nowrap="nowrap" class="col-icon">';
122
123 if (!$h) {
124 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
125 } else {
126 for ($a = 0; $a < $h; $a++) {
127 if (!$a) {
128 if ($icon) {
129 $out .= $icon;
130 }
131 } else {
132 }
133 }
134 }
135 $out .= '</td>
136 ';
137 }
138
139 // Init rendering.
140 $colsp = '';
141 $lastKey = '';
142 $c = 0;
143 $ccount = 0;
144
145 // Traverse field array which contains the data to present:
146 foreach ($this->fieldArray as $vKey) {
147 if (isset($data[$vKey])) {
148 if ($lastKey) {
149 $cssClass = $this->addElement_tdCssClass[$lastKey];
150 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
151 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
152 }
153
154 $out .= '
155 <td' .
156 $noWrap .
157 ' class="' . $cssClass . '"' .
158 $colsp .
159 $this->addElement_tdParams[$lastKey] .
160 '>' . $data[$lastKey] . '</td>';
161 }
162 $lastKey = $vKey;
163 $c = 1;
164 $ccount++;
165 } else {
166 if (!$lastKey) {
167 $lastKey = $vKey;
168 }
169 $c++;
170 }
171 if ($c > 1) {
172 $colsp = ' colspan="' . $c . '"';
173 } else {
174 $colsp = '';
175 }
176 }
177 if ($lastKey) {
178 $cssClass = $this->addElement_tdCssClass[$lastKey];
179 if ($this->oddColumnsCssClass) {
180 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
181 }
182
183 $out .= '
184 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
185 }
186
187 // End row
188 $out .= '
189 </tr>';
190
191 // Return row.
192 return $out;
193 }
194
195 /**
196 * Dummy function, used to write the top of a table listing.
197 *
198 * @return void
199 */
200 function writeTop() {
201 }
202
203 /**
204 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
205 *
206 * @return void
207 */
208 function writeBottom() {
209 $this->HTMLcode .= '
210
211 <!--
212 End of list table:
213 -->
214 <table border="0" cellpadding="0" cellspacing="0">';
215 $theIcon = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" />';
216 $this->HTMLcode .= $this->addElement(1, '', '', '', $this->leftMargin, $theIcon);
217 $this->HTMLcode .= '
218 </table>';
219 }
220
221 /**
222 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
223 *
224 * @param string $table Table name
225 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
226 */
227 function fwd_rwd_nav($table = '') {
228 $code = '';
229 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
230 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
231 // Reverse
232 $theData = Array();
233 $titleCol = $this->fieldArray[0];
234 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
235 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
236 }
237 return array(1, $code);
238 } else {
239 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
240 // Forward
241 $theData = Array();
242 $titleCol = $this->fieldArray[0];
243 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
244 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
245 }
246 return array(0, $code);
247 }
248
249 }
250
251 /**
252 * Creates the button with link to either forward or reverse
253 *
254 * @param string $type Type: "fwd" or "rwd"
255 * @param integer $pointer Pointer
256 * @param string $table Table name
257 * @return string
258 * @access private
259 */
260 function fwd_rwd_HTML($type, $pointer, $table = '') {
261 $content = '';
262 $tParam = $table ? '&table=' . rawurlencode($table) : '';
263 switch ($type) {
264 case 'fwd':
265 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
266 $content = '<a href="' . htmlspecialchars($href) . '">' .
267 t3lib_iconWorks::getSpriteIcon('actions-move-up') .
268 '</a> <i>[1 - ' . $pointer . ']</i>';
269 break;
270 case 'rwd':
271 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
272 $content = '<a href="' . htmlspecialchars($href) . '">' .
273 t3lib_iconWorks::getSpriteIcon('actions-move-down') .
274 '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
275 break;
276 }
277 return $content;
278 }
279
280 /**
281 * Creates the URL to this script, including all relevant GPvars
282 *
283 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
284 * @return string URL
285 */
286 function listURL($altId = '') {
287 return $this->script .
288 '?id=' . (strcmp($altId, '') ? $altId : $this->id);
289 }
290
291 /**
292 * Returning JavaScript for ClipBoard functionality.
293 *
294 * @return string
295 */
296 function CBfunctions() {
297 return '
298 // checkOffCB()
299 function checkOffCB(listOfCBnames, link) { //
300 var checkBoxes, flag, i;
301 var checkBoxes = listOfCBnames.split(",");
302 if (link.rel === "") {
303 link.rel = "allChecked";
304 flag = true;
305 } else {
306 link.rel = "";
307 flag = false;
308 }
309 for (i = 0; i < checkBoxes.length; i++) {
310 setcbValue(checkBoxes[i], flag);
311 }
312 }
313 // cbValue()
314 function cbValue(CBname) { //
315 var CBfullName = "CBC["+CBname+"]";
316 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
317 }
318 // setcbValue()
319 function setcbValue(CBname,flag) { //
320 CBfullName = "CBC["+CBname+"]";
321 if(document.dblistForm[CBfullName]) {
322 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
323 }
324 }
325
326 ';
327 }
328
329 /**
330 * Initializes page languages and icons
331 *
332 * @return void
333 */
334 function initializeLanguages() {
335
336 // Look up page overlays:
337 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
338 '*',
339 'pages_language_overlay',
340 'pid=' . intval($this->id) .
341 t3lib_BEfunc::deleteClause('pages_language_overlay') .
342 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay'),
343 '',
344 '',
345 '',
346 'sys_language_uid'
347 );
348
349 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
350 }
351
352 /**
353 * Return the icon for the language
354 *
355 * @param integer $sys_language_uid Sys language uid
356 * @param boolean $addAsAdditionalText If set to true, only the flag is returned
357 *
358 * @return string Language icon
359 */
360 function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
361 $out = '';
362 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
363 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
364 $out .= t3lib_iconWorks::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
365
366 if (!$addAsAdditionalText) {
367 return $out;
368 }
369 $out .= '&nbsp;';
370 }
371 $out .= $title;
372 return $out;
373 }
374
375 /**
376 * Gets an instance of t3lib_transl8tools.
377 *
378 * @return t3lib_transl8tools
379 */
380 protected function getTranslateTools() {
381 if (!isset($this->translateTools)) {
382 $this->translateTools = t3lib_div::makeInstance('t3lib_transl8tools');
383 }
384 return $this->translateTools;
385 }
386 }
387
388 ?>