2 /***************************************************************
5 * (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Library with a single function addElement that returns tablerows based on some input.
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
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)
53 * (This index is automatically created/updated by the extension "extdeveval")
59 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
61 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
64 * @see typo3/db_list.php, typo3/file_list.php
66 class t3lib_recordList
{
68 // Used in this class:
69 var $iLimit = 10; // default Max items shown
70 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
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
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();
80 // Not used in this class - but maybe extension classes...
81 var $fixedL = 30; // Max length of strings
83 var $thumbScript = 'thumbs.php';
84 var $setLMargin = 1; // Set to zero, if you don't want a left-margin with addElement function
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...
89 // Internal (used in this class.)
90 var $firstElementNumber = 0;
92 var $HTMLcode = ''; // String with accumulated HTML content
94 var $pageOverlays = array(); // Contains page translation languages
95 var $languageIconTitles = array(); // Contains sys language icons and titles
96 var $translateTools; // translateTools object
99 * constructor for t3lib_recordList
101 * @author Ingo Renner <ingo@typo3.org>
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'];
107 $this->getTranslateTools();
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)
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
123 function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
124 $noWrap = ($this->no_noWrap
) ?
'' : ' nowrap="nowrap"';
128 <!-- Element, begin: -->
129 <tr ' . $trParams . '>';
130 // Show icon and lines
131 if ($this->showIcon
) {
133 <td nowrap="nowrap" class="col-icon">';
136 $out .= '<img src="clear.gif" width="1" height="8" alt="" />';
138 for ($a = 0; $a < $h; $a++
) {
157 // Traverse field array which contains the data to present:
158 foreach ($this->fieldArray
as $vKey) {
159 if (isset($data[$vKey])) {
161 $cssClass = $this->addElement_tdCssClass
[$lastKey];
162 if ($this->oddColumnsCssClass
&& $ccount %
2 == 0) {
163 $cssClass = implode(' ', array($this->addElement_tdCssClass
[$lastKey], $this->oddColumnsCssClass
));
169 ' class="' . $cssClass . '"' .
171 $this->addElement_tdParams
[$lastKey] .
172 '>' . $data[$lastKey] . '</td>';
184 $colsp = ' colspan="' . $c . '"';
190 $cssClass = $this->addElement_tdCssClass
[$lastKey];
191 if ($this->oddColumnsCssClass
) {
192 $cssClass = implode(' ', array($this->addElement_tdCssClass
[$lastKey], $this->oddColumnsCssClass
));
196 <td' . $noWrap . ' class="' . $cssClass . '"' . $colsp . $this->addElement_tdParams
[$lastKey] . '>' . $data[$lastKey] . '</td>';
208 * Dummy function, used to write the top of a table listing.
212 function writeTop() {
216 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
220 function writeBottom() {
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);
234 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
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
239 function fwd_rwd_nav($table = '') {
241 if ($this->eCounter
>= $this->firstElementNumber
&& $this->eCounter
< $this->firstElementNumber +
$this->iLimit
) {
242 if ($this->firstElementNumber
&& $this->eCounter
== $this->firstElementNumber
) {
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"');
249 return array(1, $code);
251 if ($this->eCounter
== $this->firstElementNumber +
$this->iLimit
) {
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"');
258 return array(0, $code);
264 * Creates the button with link to either forward or reverse
266 * @param string Type: "fwd" or "rwd"
267 * @param integer Pointer
268 * @param string Table name
272 function fwd_rwd_HTML($type, $pointer, $table = '') {
274 $tParam = $table ?
'&table=' . rawurlencode($table) : '';
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>';
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>';
293 * Creates the URL to this script, including all relevant GPvars
295 * @param string Alternative id value. Enter blank string for the current id ($this->id)
298 function listURL($altId = '') {
299 return $this->script
.
300 '?id=' . (strcmp($altId, '') ?
$altId : $this->id
);
304 * Returning JavaScript for ClipBoard functionality.
308 function CBfunctions() {
311 function checkOffCB(listOfCBnames, link) { //
312 var checkBoxes, flag, i;
313 var checkBoxes = listOfCBnames.split(",");
314 if (link.rel === "") {
315 link.rel = "allChecked";
321 for (i = 0; i < checkBoxes.length; i++) {
322 setcbValue(checkBoxes[i], flag);
326 function cbValue(CBname) { //
327 var CBfullName = "CBC["+CBname+"]";
328 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
331 function setcbValue(CBname,flag) { //
332 CBfullName = "CBC["+CBname+"]";
333 if(document.dblistForm[CBfullName]) {
334 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
342 * Initializes page languages and icons
346 function initializeLanguages() {
349 // Look up page overlays:
350 $this->pageOverlays
= $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
352 'pages_language_overlay',
353 'pid=' . intval($this->id
) .
354 t3lib_BEfunc
::deleteClause('pages_language_overlay') .
355 t3lib_BEfunc
::versioningPlaceholderClause('pages_language_overlay'),
362 $this->languageIconTitles
= $this->getTranslateTools()->getSystemLanguages($this->id
, $this->backPath
);
366 * Return the icon for the language
368 * @param integer Sys language uid
369 * @return string Language icon
371 function languageFlag($sys_language_uid) {
373 if ($this->languageIconTitles
[$sys_language_uid]['flagIcon']) {
374 $out .= t3lib_iconWorks
::getSpriteIcon($this->languageIconTitles
[$sys_language_uid]['flagIcon']);
377 $out .= htmlspecialchars($this->languageIconTitles
[$sys_language_uid]['title']);
382 * Gets an instance of t3lib_transl8tools.
384 * @return t3lib_transl8tools
386 protected function getTranslateTools() {
387 if (!isset($this->translateTools
)) {
388 $this->translateTools
= t3lib_div
::makeInstance('t3lib_transl8tools');
390 return $this->translateTools
;
395 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php'])) {
396 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']);