[TASK] Update copyright year to 2013
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / RecordList / AbstractRecordList.php
1 <?php
2 namespace TYPO3\CMS\Backend\RecordList;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
28 /**
29 * Library with a single function addElement that returns table
30 * rows based on some input.
31 *
32 * Base for class listing of database records and files in the
33 * modules Web>List and File>Filelist
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @see typo3/db_list.php
37 * @see typo3/sysext/filelist/mod1/index.php
38 */
39 abstract class AbstractRecordList {
40
41 // Used in this class:
42 // default Max items shown
43 /**
44 * @todo Define visibility
45 */
46 public $iLimit = 10;
47
48 // OBSOLETE - NOT USED ANYMORE. leftMargin
49 /**
50 * @todo Define visibility
51 */
52 public $leftMargin = 0;
53
54 /**
55 * @todo Define visibility
56 */
57 public $showIcon = 1;
58
59 /**
60 * @todo Define visibility
61 */
62 public $no_noWrap = 0;
63
64 // If set this is <td> CSS-classname for odd columns in addElement. Used with db_layout / pages section
65 /**
66 * @todo Define visibility
67 */
68 public $oddColumnsCssClass = '';
69
70 /**
71 * @todo Define visibility
72 */
73 public $backPath = '';
74
75 // Decides the columns shown. Filled with values that refers to the keys of the data-array. $this->fieldArray[0] is the title column.
76 /**
77 * @todo Define visibility
78 */
79 public $fieldArray = array();
80
81 // Keys are fieldnames and values are td-parameters to add in addElement(), please use $addElement_tdCSSClass for CSS-classes;
82 /**
83 * @todo Define visibility
84 */
85 public $addElement_tdParams = array();
86
87 // Keys are fieldnames and values are td-css-classes to add in addElement();
88 /**
89 * @todo Define visibility
90 */
91 public $addElement_tdCssClass = array();
92
93 // Not used in this class - but maybe extension classes...
94 // Max length of strings
95 /**
96 * @todo Define visibility
97 */
98 public $fixedL = 30;
99
100 /**
101 * @todo Define visibility
102 */
103 public $script = '';
104
105 // Set to zero, if you don't want a left-margin with addElement function
106 /**
107 * @todo Define visibility
108 */
109 public $setLMargin = 1;
110
111 // Counter increased for each element. Used to index elements for the JavaScript-code that transfers to the clipboard
112 /**
113 * @todo Define visibility
114 */
115 public $counter = 0;
116
117 // This could be set to the total number of items. Used by the fwd_rew_navigation...
118 /**
119 * @todo Define visibility
120 */
121 public $totalItems = '';
122
123 // Internal (used in this class.)
124 /**
125 * @todo Define visibility
126 */
127 public $firstElementNumber = 0;
128
129 /**
130 * @todo Define visibility
131 */
132 public $eCounter = 0;
133
134 // String with accumulated HTML content
135 /**
136 * @todo Define visibility
137 */
138 public $HTMLcode = '';
139
140 // Contains page translation languages
141 /**
142 * @todo Define visibility
143 */
144 public $pageOverlays = array();
145
146 // Contains sys language icons and titles
147 /**
148 * @todo Define visibility
149 */
150 public $languageIconTitles = array();
151
152 // TranslateTools object
153 /**
154 * @todo Define visibility
155 */
156 public $translateTools;
157
158 /**
159 * Constructor for t3lib_recordList
160 */
161 public function __construct() {
162 if (isset($GLOBALS['BE_USER']->uc['titleLen']) && $GLOBALS['BE_USER']->uc['titleLen'] > 0) {
163 $this->fixedL = $GLOBALS['BE_USER']->uc['titleLen'];
164 }
165 $this->getTranslateTools();
166 }
167
168 /**
169 * Returns a table-row with the content from the fields in the input data array.
170 * OBS: $this->fieldArray MUST be set! (represents the list of fields to display)
171 *
172 * @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'
173 * @param string $icon Is the <img>+<a> of the record. If not supplied the first 'join'-icon will be a 'line' instead
174 * @param array $data Is the dataarray, record with the fields. Notice: These fields are (currently) NOT htmlspecialchar'ed before being wrapped in <td>-tags
175 * @param string $tdParams Is insert in the <td>-tags. Must carry a ' ' as first character
176 * @param integer OBSOLETE - NOT USED ANYMORE. $lMargin is the leftMargin (integer)
177 * @param string $altLine Is the HTML <img>-tag for an alternative 'gfx/ol/line.gif'-icon (used in the top)
178 * @return string HTML content for the table row
179 * @todo Define visibility
180 */
181 public function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
182 $noWrap = $this->no_noWrap ? '' : ' nowrap="nowrap"';
183 // Start up:
184 $out = '
185 <!-- Element, begin: -->
186 <tr ' . $trParams . '>';
187 // Show icon and lines
188 if ($this->showIcon) {
189 $out .= '
190 <td nowrap="nowrap" class="col-icon">';
191 if (!$h) {
192 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
193 } else {
194 for ($a = 0; $a < $h; $a++) {
195 if (!$a) {
196 if ($icon) {
197 $out .= $icon;
198 }
199 } else {
200
201 }
202 }
203 }
204 $out .= '</td>
205 ';
206 }
207 // Init rendering.
208 $colsp = '';
209 $lastKey = '';
210 $c = 0;
211 $ccount = 0;
212 // Traverse field array which contains the data to present:
213 foreach ($this->fieldArray as $vKey) {
214 if (isset($data[$vKey])) {
215 if ($lastKey) {
216 $cssClass = $this->addElement_tdCssClass[$lastKey];
217 if ($this->oddColumnsCssClass && $ccount % 2 == 0) {
218 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
219 }
220 $out .= '
221 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
222 }
223 $lastKey = $vKey;
224 $c = 1;
225 $ccount++;
226 } else {
227 if (!$lastKey) {
228 $lastKey = $vKey;
229 }
230 $c++;
231 }
232 if ($c > 1) {
233 $colsp = ' colspan="' . $c . '"';
234 } else {
235 $colsp = '';
236 }
237 }
238 if ($lastKey) {
239 $cssClass = $this->addElement_tdCssClass[$lastKey];
240 if ($this->oddColumnsCssClass) {
241 $cssClass = implode(' ', array($this->addElement_tdCssClass[$lastKey], $this->oddColumnsCssClass));
242 }
243 $out .= '
244 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams[$lastKey] . '>' . $data[$lastKey] . '</td>';
245 }
246 // End row
247 $out .= '
248 </tr>';
249 // Return row.
250 return $out;
251 }
252
253 /**
254 * Dummy function, used to write the top of a table listing.
255 *
256 * @return void
257 * @todo Define visibility
258 */
259 public function writeTop() {
260
261 }
262
263 /**
264 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
265 *
266 * @return void
267 * @todo Define visibility
268 */
269 public function writeBottom() {
270 $this->HTMLcode .= '
271
272 <!--
273 End of list table:
274 -->
275 <table border="0" cellpadding="0" cellspacing="0">';
276 $theIcon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" />';
277 $this->HTMLcode .= $this->addElement(1, '', array(), '', $this->leftMargin, $theIcon);
278 $this->HTMLcode .= '
279 </table>';
280 }
281
282 /**
283 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
284 *
285 * @param string $table Table name
286 * @return array array([boolean], [HTML]) where [boolean] is 1 for reverse element, [HTML] is the table-row code for the element
287 * @todo Define visibility
288 */
289 public function fwd_rwd_nav($table = '') {
290 $code = '';
291 if ($this->eCounter >= $this->firstElementNumber && $this->eCounter < $this->firstElementNumber + $this->iLimit) {
292 if ($this->firstElementNumber && $this->eCounter == $this->firstElementNumber) {
293 // Reverse
294 $theData = array();
295 $titleCol = $this->fieldArray[0];
296 $theData[$titleCol] = $this->fwd_rwd_HTML('fwd', $this->eCounter, $table);
297 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
298 }
299 return array(1, $code);
300 } else {
301 if ($this->eCounter == $this->firstElementNumber + $this->iLimit) {
302 // Forward
303 $theData = array();
304 $titleCol = $this->fieldArray[0];
305 $theData[$titleCol] = $this->fwd_rwd_HTML('rwd', $this->eCounter, $table);
306 $code = $this->addElement(1, '', $theData, 'class="fwd_rwd_nav"');
307 }
308 return array(0, $code);
309 }
310 }
311
312 /**
313 * Creates the button with link to either forward or reverse
314 *
315 * @param string $type Type: "fwd" or "rwd
316 * @param integer $pointer Pointer
317 * @param string $table Table name
318 * @return string
319 * @access private
320 * @todo Define visibility
321 */
322 public function fwd_rwd_HTML($type, $pointer, $table = '') {
323 $content = '';
324 $tParam = $table ? '&table=' . rawurlencode($table) : '';
325 switch ($type) {
326 case 'fwd':
327 $href = $this->listURL() . '&pointer=' . ($pointer - $this->iLimit) . $tParam;
328 $content = '<a href="' . htmlspecialchars($href) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-move-up') . '</a> <i>[1 - ' . $pointer . ']</i>';
329 break;
330 case 'rwd':
331 $href = $this->listURL() . '&pointer=' . $pointer . $tParam;
332 $content = '<a href="' . htmlspecialchars($href) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-move-down') . '</a> <i>[' . ($pointer + 1) . ' - ' . $this->totalItems . ']</i>';
333 break;
334 }
335 return $content;
336 }
337
338 /**
339 * Creates the URL to this script, including all relevant GPvars
340 *
341 * @param string $altId Alternative id value. Enter blank string for the current id ($this->id)
342 * @return string URL
343 * @todo Define visibility
344 */
345 public function listURL($altId = '') {
346 return $this->script . '?id=' . (strcmp($altId, '') ? $altId : $this->id);
347 }
348
349 /**
350 * Returning JavaScript for ClipBoard functionality.
351 *
352 * @return string
353 * @todo Define visibility
354 */
355 public function CBfunctions() {
356 return '
357 // checkOffCB()
358 function checkOffCB(listOfCBnames, link) { //
359 var checkBoxes, flag, i;
360 var checkBoxes = listOfCBnames.split(",");
361 if (link.rel === "") {
362 link.rel = "allChecked";
363 flag = true;
364 } else {
365 link.rel = "";
366 flag = false;
367 }
368 for (i = 0; i < checkBoxes.length; i++) {
369 setcbValue(checkBoxes[i], flag);
370 }
371 }
372 // cbValue()
373 function cbValue(CBname) { //
374 var CBfullName = "CBC["+CBname+"]";
375 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
376 }
377 // setcbValue()
378 function setcbValue(CBname,flag) { //
379 CBfullName = "CBC["+CBname+"]";
380 if(document.dblistForm[CBfullName]) {
381 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
382 }
383 }
384
385 ';
386 }
387
388 /**
389 * Initializes page languages and icons
390 *
391 * @return void
392 * @todo Define visibility
393 */
394 public function initializeLanguages() {
395 // Look up page overlays:
396 $this->pageOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . intval($this->id) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('pages_language_overlay') . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause('pages_language_overlay'), '', '', '', 'sys_language_uid');
397 $this->languageIconTitles = $this->getTranslateTools()->getSystemLanguages($this->id, $this->backPath);
398 }
399
400 /**
401 * Return the icon for the language
402 *
403 * @param integer $sys_language_uid Sys language uid
404 * @param boolean $addAsAdditionalText If set to true, only the flag is returned
405 * @return string Language icon
406 * @todo Define visibility
407 */
408 public function languageFlag($sys_language_uid, $addAsAdditionalText = TRUE) {
409 $out = '';
410 $title = htmlspecialchars($this->languageIconTitles[$sys_language_uid]['title']);
411 if ($this->languageIconTitles[$sys_language_uid]['flagIcon']) {
412 $out .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon($this->languageIconTitles[$sys_language_uid]['flagIcon'], array('title' => $title));
413 if (!$addAsAdditionalText) {
414 return $out;
415 }
416 $out .= '&nbsp;';
417 }
418 $out .= $title;
419 return $out;
420 }
421
422 /**
423 * Gets an instance of t3lib_transl8tools.
424 *
425 * @return \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider
426 */
427 protected function getTranslateTools() {
428 if (!isset($this->translateTools)) {
429 $this->translateTools = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider');
430 }
431 return $this->translateTools;
432 }
433
434 /**
435 * Generates HTML code for a Reference tooltip out of
436 * sys_refindex records you hand over
437 *
438 * @param array $references array of records from sys_refindex table
439 * @param string $launchViewParameter JavaScript String, which will be passed as parameters to top.launchView
440 * @return string
441 */
442 protected function generateReferenceToolTip(array $references, $launchViewParameter = '') {
443 $result = array();
444 foreach ($references as $reference) {
445 $result[] = $reference['tablename'] . ':' . $reference['recuid'] . ':' . $reference['field'];
446 if (strlen(implode(' / ', $result)) >= 100) {
447 break;
448 }
449 }
450 if (empty($result)) {
451 $htmlCode = '-';
452 } else {
453 $htmlCode = '<a href="#"';
454 if ($launchViewParameter !== '') {
455 $htmlCode .= ' onclick="' . htmlspecialchars(('top.launchView(' . $launchViewParameter . '); return false;')) . '"';
456 }
457 $htmlCode .= ' title="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(implode(' / ', $result), 100)) . '">';
458 $htmlCode .= count($references);
459 $htmlCode .= '</a>';
460 }
461 return $htmlCode;
462 }
463
464 }
465
466
467 ?>