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")
73 * This class is the base for listing of database records and files in the modules Web>List and File>Filelist
75 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
78 * @see typo3/db_list.php, typo3/file_list.php
80 class t3lib_recordList
{
82 // Used in this class:
83 var $iLimit = 10; // default Max items shown
84 var $leftMargin = 0; // OBSOLETE - NOT USED ANYMORE. leftMargin
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
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();
94 // Not used in this class - but maybe extension classes...
95 var $fixedL = 30; // Max length of strings
97 var $thumbScript = 'thumbs.php';
98 var $setLMargin=1; // Set to zero, if you don't want a left-margin with addElement function
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...
103 // Internal (used in this class.)
104 var $firstElementNumber=0;
106 var $HTMLcode=''; // String with accumulated HTML content
108 var $pageOverlays = array(); // Contains page translation languages
109 var $languageIconTitles = array(); // Contains sys language icons and titles
110 var $translateTools; // translateTools object
113 * constructor for t3lib_recordList
115 * @author Ingo Renner <ingo@typo3.org>
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'];
121 $this->getTranslateTools();
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)
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
137 function addElement($h, $icon, $data, $trParams = '', $lMargin = '', $altLine = '') {
138 $noWrap = ($this->no_noWrap
) ?
'' : ' nowrap="nowrap"';
142 <!-- Element, begin: -->
144 // Show icon and lines
145 if ($this->showIcon
) {
147 <td nowrap="nowrap" class="col-icon">';
150 $out.='<img src="clear.gif" width="1" height="8" alt="" />';
152 for ($a=0;$a<$h;$a++
) {
154 if ($icon) $out.= $icon;
169 // Traverse field array which contains the data to present:
170 foreach ($this->fieldArray
as $vKey) {
171 if (isset($data[$vKey])) {
173 $cssClass = $this->addElement_tdCssClass
[$lastKey];
174 if($this->oddColumnsCssClass
&& $ccount %
2 == 0) {
175 $cssClass = implode(' ', array($this->addElement_tdCssClass
[$lastKey], $this->oddColumnsCssClass
));
181 ' class="' . $cssClass . '"'.
183 $this->addElement_tdParams
[$lastKey].
184 '>'.$data[$lastKey].'</td>';
190 if (!$lastKey) {$lastKey=$vKey;}
193 if ($c>1) {$colsp=' colspan="'.$c.'"';} else {$colsp='';}
196 $cssClass = $this->addElement_tdCssClass
[$lastKey];
197 if($this->oddColumnsCssClass
) {
198 $cssClass = implode(' ', array($this->addElement_tdCssClass
[$lastKey], $this->oddColumnsCssClass
));
202 <td'.$noWrap.' class="' . $cssClass . '"' . $colsp.$this->addElement_tdParams
[$lastKey].'>'.$data[$lastKey].'</td>'; }
213 * Dummy function, used to write the top of a table listing.
217 function writeTop() {
221 * Finishes the list with the "stopper"-gif, adding the HTML code for that item to the internal ->HTMLcode string
225 function writeBottom() {
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);
239 * Creates a forward/reverse button based on the status of ->eCounter, ->firstElementNumber, ->iLimit
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
244 function fwd_rwd_nav($table='') {
246 if ($this->eCounter
>= $this->firstElementNumber
&& $this->eCounter
< $this->firstElementNumber+
$this->iLimit
) {
247 if ($this->firstElementNumber
&& $this->eCounter
==$this->firstElementNumber
) {
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"');
254 return array(1, $code);
256 if ($this->eCounter
==$this->firstElementNumber+
$this->iLimit
) {
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"');
263 return array(0, $code);
269 * Creates the button with link to either forward or reverse
271 * @param string Type: "fwd" or "rwd"
272 * @param integer Pointer
273 * @param string Table name
277 function fwd_rwd_HTML($type,$pointer,$table='') {
279 $tParam = $table ?
'&table='.rawurlencode($table) : '';
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>';
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>';
298 * Creates the URL to this script, including all relevant GPvars
300 * @param string Alternative id value. Enter blank string for the current id ($this->id)
303 function listURL($altId='') {
304 return $this->script
.
305 '?id='.(strcmp($altId,'')?
$altId:$this->id
);
309 * Returning JavaScript for ClipBoard functionality.
313 function CBfunctions() {
316 function checkOffCB(listOfCBnames, link) { //
317 var checkBoxes, flag, i;
318 var checkBoxes = listOfCBnames.split(",");
319 if (link.rel === "") {
320 link.rel = "allChecked";
326 for (i = 0; i < checkBoxes.length; i++) {
327 setcbValue(checkBoxes[i], flag);
331 function cbValue(CBname) { //
332 var CBfullName = "CBC["+CBname+"]";
333 return (document.dblistForm[CBfullName] && document.dblistForm[CBfullName].checked ? 1 : 0);
336 function setcbValue(CBname,flag) { //
337 CBfullName = "CBC["+CBname+"]";
338 if(document.dblistForm[CBfullName]) {
339 document.dblistForm[CBfullName].checked = flag ? "on" : 0;
347 * Initializes page languages and icons
351 function initializeLanguages() {
354 // Look up page overlays:
355 $this->pageOverlays
= $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
357 'pages_language_overlay',
358 'pid='.intval($this->id
).
359 t3lib_BEfunc
::deleteClause('pages_language_overlay').
360 t3lib_BEfunc
::versioningPlaceholderClause('pages_language_overlay'),
367 $this->languageIconTitles
= $this->getTranslateTools()->getSystemLanguages($this->id
, $this->backPath
);
371 * Return the icon for the language
373 * @param integer Sys language uid
374 * @return string Language icon
376 function languageFlag($sys_language_uid) {
378 if ($this->languageIconTitles
[$sys_language_uid]['flagIcon']) {
379 $out .= t3lib_iconWorks
::getSpriteIcon($this->languageIconTitles
[$sys_language_uid]['flagIcon']);
382 $out .= htmlspecialchars($this->languageIconTitles
[$sys_language_uid]['title']);
387 * Gets an instance of t3lib_transl8tools.
389 * @return t3lib_transl8tools
391 protected function getTranslateTools() {
392 if (!isset($this->translateTools
)) {
393 $this->translateTools
= t3lib_div
::makeInstance('t3lib_transl8tools');
395 return $this->translateTools
;
400 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']) {
401 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_recordlist.php']);