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