[BUGFIX] t3lib_http_Request can not be loaded in frontend
[Packages/TYPO3.CMS.git] / typo3 / class.db_list_extra.inc
1 <?php
2 /*************************************************************
3 *  Copyright notice
4 *
5 *  (c) 1999-2009 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  * Include file extending recordList which extended t3lib_recordList
29  * Used specifically for the Web>List module (db_list.php)
30  *
31  * Revised for TYPO3 3.6 December/2003 by Kasper Skårhøj
32  * XHTML compliant
33  *
34  * @author      Kasper Skårhøj <kasperYYYY@typo3.com>
35  */
36
37
38
39
40
41
42
43
44
45
46 /**
47  * Class for rendering of Web>List module
48  *
49  * @author      Kasper Skårhøj <kasperYYYY@typo3.com>
50  * @package TYPO3
51  * @subpackage core
52  */
53 class localRecordList extends recordList {
54
55                 // External:
56         var $alternateBgColors=FALSE;                   // If TRUE, table rows in the list will alternate in background colors (and have background colors at all!)
57         var $allowedNewTables=array();                  // Used to indicate which tables (values in the array) that can have a create-new-record link. If the array is empty, all tables are allowed.
58         var $deniedNewTables=array();                   // Used to indicate which tables (values in the array) that cannot have a create-new-record link. If the array is empty, all tables are allowed.
59         var $newWizards=FALSE;                                  // If TRUE, the control panel will contain links to the create-new wizards for pages and tt_content elements (normally, the link goes to just creating a new element without the wizards!).
60
61         var $dontShowClipControlPanels=FALSE;   // If TRUE, will disable the rendering of clipboard + control panels.
62         var $showClipboard=FALSE;                               // If TRUE, will show the clipboard in the field list.
63         var $noControlPanels = FALSE;                   // If TRUE, will DISABLE all control panels in lists. (Takes precedence)
64         var $clickMenuEnabled = TRUE;                   // If TRUE, clickmenus will be rendered
65
66         var $totalRowCount;                                             // count of record rows in view
67
68         var $spaceIcon;                                                 // space icon used for alignment
69
70                 // Internal:
71         var $pageRow=array();                                   // Set to the page record (see writeTop())
72
73                 // Used to accumulate CSV lines for CSV export.
74         protected $csvLines = array();
75
76         var $csvOutput=FALSE;                                   // If set, the listing is returned as CSV instead.
77
78         /**
79          * Clipboard object
80          *
81          * @var t3lib_clipboard
82          */
83         var $clipObj;
84         var $CBnames=array();                                   // Tracking names of elements (for clipboard use)
85         var $duplicateStack=array();                    // Used to track which elements has duplicates and how many
86
87         /**
88          * [$tablename][$uid] = number of references to this record
89          *
90          * @var array
91          */
92         protected $referenceCount = array();
93
94         var $translations;                                              // Translations of the current record
95         var $selFieldList;                                              // select fields for the query which fetches the translations of the current record
96
97         public $disableSingleTableView = FALSE;
98
99         public function __construct() {
100                 parent::__construct();
101         }
102
103         /**
104          * Create the panel of buttons for submitting the form or otherwise perform operations.
105          *
106          * @return      array   all available buttons as an assoc. array
107          */
108         public function getButtons()    {
109                 $buttons = array(
110                         'csh' => '',
111                         'view' => '',
112                         'edit' => '',
113                         'hide_unhide' => '',
114                         'move' => '',
115                         'new_record' => '',
116                         'paste' => '',
117                         'level_up' => '',
118                         'cache' => '',
119                         'reload' => '',
120                         'shortcut' => '',
121                         'back' => '',
122                         'csv' => '',
123                         'export' => ''
124                 );
125
126                         // Get users permissions for this page record:
127                 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageRow);
128
129                         // CSH
130                 if (!strlen($this->id)) {
131                         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_noId', $GLOBALS['BACK_PATH'], '', TRUE);
132                 } elseif(!$this->id) {
133                         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_root', $GLOBALS['BACK_PATH'], '', TRUE);
134                 } else {
135                         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module', $GLOBALS['BACK_PATH'], '', TRUE);
136                 }
137
138                 if (isset($this->id)) {
139                                 // View  Exclude doktypes 254,255 Configuration: mod.web_list.noViewWithDokTypes = 254,255
140                         if (isset($GLOBALS['SOBE']->modTSconfig['properties']['noViewWithDokTypes'])) {
141                                 $noViewDokTypes = t3lib_div::trimExplode(',', $GLOBALS['SOBE']->modTSconfig['properties']['noViewWithDokTypes'], TRUE);
142                         } else {
143                                         //default exclusion: doktype 254 (folder), 255 (recycler)
144                                 $noViewDokTypes = array(t3lib_pageSelect::DOKTYPE_SYSFOLDER, t3lib_pageSelect::DOKTYPE_RECYCLER);
145                         }
146
147                         if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
148                                 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick($this->id, $this->backPath, t3lib_BEfunc::BEgetRootLine($this->id))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', TRUE) . '">' .
149                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
150                                                         '</a>';
151                         }
152
153                                 // New record
154                         if (!$GLOBALS['SOBE']->modTSconfig['properties']['noCreateRecordsLink']) {
155                                 $buttons['new_record'] = '<a href="#" onclick="' . htmlspecialchars('return jumpExt(\'' . $this->backPath . 'db_new.php?id=' . $this->id . '\');') . '" title="' . $GLOBALS['LANG']->getLL('newRecordGeneral', TRUE) . '">' .
156                                                                         t3lib_iconWorks::getSpriteIcon('actions-document-new') .
157                                                                 '</a>';
158                         }
159
160                                 // If edit permissions are set (see class.t3lib_userauthgroup.php)
161                         if ($localCalcPerms&2 && !empty($this->id))     {
162
163                                         // Edit
164                                 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
165                                 $buttons['edit'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('editPage', TRUE) . '">' .
166                                                                         t3lib_iconWorks::getSpriteIcon('actions-page-open') .
167                                                                 '</a>';
168                                         // Unhide
169                                 if ($this->pageRow['hidden'])   {
170                                         $params = '&data[pages][' . $this->pageRow['uid'] . '][hidden]=0';
171                                         $buttons['hide_unhide'] = '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '" title="' . $GLOBALS['LANG']->getLL('unHidePage', TRUE) . '">' .
172                                                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-unhide') .
173                                                                         '</a>';
174                                         // Hide
175                                 } else {
176                                         $params = '&data[pages][' . $this->pageRow['uid'] . '][hidden]=1';
177                                         $buttons['hide_unhide'] = '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '" title="' . $GLOBALS['LANG']->getLL('hidePage', TRUE) . '">'.
178                                                                                 t3lib_iconWorks::getSpriteIcon('actions-edit-hide') .
179                                                                         '</a>';
180                                 }
181
182                                         // Move
183                                 $buttons['move'] = '<a href="#" onclick="' . htmlspecialchars('return jumpExt(\'' . $this->backPath . 'move_el.php?table=pages&uid=' . $this->pageRow['uid'] . '\');') . '" title="' . $GLOBALS['LANG']->getLL('move_page', TRUE) . '">' .
184                                                                         (($this->table == 'tt_content') ? t3lib_iconWorks::getSpriteIcon('actions-document-move') : t3lib_iconWorks::getSpriteIcon('actions-page-move')) .
185                                                                 '</a>';
186
187                                         // Up one level
188                                 $buttons['level_up'] = '<a href="' . htmlspecialchars($this->listURL($this->pageRow['pid'], '-1', 'firstElementNumber')) . '" onclick="setHighlight(' . $this->pageRow['pid'] . ')" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', TRUE) . '">' .
189                                                                 t3lib_iconWorks::getSpriteIcon('actions-view-go-up') .
190                                                         '</a>';
191
192                         }
193
194
195                                 // Paste
196                         if (($localCalcPerms&8) || ($localCalcPerms&16)) {
197                                 $elFromTable = $this->clipObj->elFromTable('');
198                                 if (count($elFromTable)) {
199                                         $buttons['paste'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('', $this->id)) . '" onclick="' . htmlspecialchars('return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', TRUE) . '">' .
200                                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-paste-after') .
201                                                                         '</a>';
202                                 }
203                         }
204
205                                 // Cache
206                         $buttons['cache'] = '<a href="' . htmlspecialchars($this->listURL() . '&clear_cache=1') . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.clear_cache', TRUE) . '">' .
207                                                                 t3lib_iconWorks::getSpriteIcon('actions-system-cache-clear') .
208                                                         '</a>';
209
210                         if ($this->table) {
211
212                                         // CSV
213                                 $buttons['csv'] = '<a href="' . htmlspecialchars($this->listURL() . '&csv=1') . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.csv', TRUE) . '">' .
214                                                                         t3lib_iconWorks::getSpriteIcon('mimetypes-text-csv') .
215                                                                 '</a>';
216
217                                         // Export
218                                 if (t3lib_extMgm::isLoaded('impexp')) {
219                                         $url = $this->backPath . t3lib_extMgm::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export';
220                                         $buttons['export'] = '<a href="' . htmlspecialchars($url . '&tx_impexp[list][]=' . rawurlencode($this->table . ':' . $this->id)) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.export', TRUE) . '">' .
221                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-export-t3d') .
222                                                         '</a>';
223                                 }
224
225                         }
226
227                                 // Reload
228                         $buttons['reload'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.reload', TRUE) . '">' .
229                                                                 t3lib_iconWorks::getSpriteIcon('actions-system-refresh') .
230                                                         '</a>';
231
232                                 // Shortcut
233                         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
234                                 $buttons['shortcut'] = $GLOBALS['TBE_TEMPLATE']->makeShortcutIcon('id, imagemode, pointer, table, search_field, search_levels, showLimit, sortField, sortRev', implode(',', array_keys($this->MOD_MENU)), 'web_list');
235                         }
236
237                                 // Back
238                         if ($this->returnUrl) {
239                                 $buttons['back'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisUrl($this->returnUrl, array('id' => $this->id))) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.goBack', TRUE) . '">' .
240                                                                         t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
241                                                                 '</a>';
242                         }
243                 }
244
245                 return $buttons;
246         }
247
248         /**
249          * Creates the listing of records from a single table
250          *
251          * @param       string          Table name
252          * @param       integer         Page id
253          * @param       string          List of fields to show in the listing. Pseudo fields will be added including the record header.
254          * @return      string          HTML table with the listing for the record.
255          */
256         function getTable($table,$id,$rowlist)  {
257                         // Loading all TCA details for this table:
258                 t3lib_div::loadTCA($table);
259
260                         // Init
261                 $addWhere = '';
262                 $titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'];
263                 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
264                 $l10nEnabled = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
265                         && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'];
266                 $tableCollapsed = (!$this->tablesCollapsed[$table]) ? FALSE : TRUE;
267
268                 // prepare space icon
269                 $this->spaceIcon = t3lib_iconWorks::getSpriteIcon('empty-empty', array('style' => 'background-position: 0 10px;'));
270
271                         // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
272                 $this->fieldArray=array();
273                         // title Column
274                 $this->fieldArray[] = $titleCol;        // Add title column
275                         // Control-Panel
276                 if (!t3lib_div::inList($rowlist,'_CONTROL_'))   {
277                         $this->fieldArray[] = '_CONTROL_';
278                         $this->fieldArray[] = '_AFTERCONTROL_';
279                 }
280                         // Clipboard
281                 if ($this->showClipboard)       {
282                         $this->fieldArray[] = '_CLIPBOARD_';
283                 }
284                         // Ref
285                 if (!$this->dontShowClipControlPanels)  {
286                         $this->fieldArray[]='_REF_';
287                         $this->fieldArray[]='_AFTERREF_';
288                 }
289                         // Path
290                 if ($this->searchLevels)        {
291                         $this->fieldArray[]='_PATH_';
292                 }
293                         // Localization
294                 if ($this->localizationView && $l10nEnabled)    {
295                         $this->fieldArray[] = '_LOCALIZATION_';
296                         $this->fieldArray[] = '_LOCALIZATION_b';
297                         $addWhere.=' AND (
298                                 ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '<=0
299                                 OR
300                                 ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . ' = 0
301                         )';
302                 }
303                         // Cleaning up:
304                 $this->fieldArray=array_unique(array_merge($this->fieldArray,t3lib_div::trimExplode(',',$rowlist,1)));
305                 if ($this->noControlPanels)     {
306                         $tempArray = array_flip($this->fieldArray);
307                         unset($tempArray['_CONTROL_']);
308                         unset($tempArray['_CLIPBOARD_']);
309                         $this->fieldArray = array_keys($tempArray);
310                 }
311
312                         // Creating the list of fields to include in the SQL query:
313                 $selectFields = $this->fieldArray;
314                 $selectFields[] = 'uid';
315                 $selectFields[] = 'pid';
316                 if ($thumbsCol) $selectFields[] = $thumbsCol;   // adding column for thumbnails
317                 if ($table=='pages')    {
318                         if (t3lib_extMgm::isLoaded('cms'))      {
319                                 $selectFields[] = 'module';
320                                 $selectFields[] = 'extendToSubpages';
321                                 $selectFields[] = 'nav_hide';
322                         }
323                         $selectFields[] = 'doktype';
324                 }
325                 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
326                         $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
327                 }
328                 if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
329                         $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
330                 }
331                 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
332                         $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
333                 }
334                 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
335                         $selectFields[] = 't3ver_id';
336                         $selectFields[] = 't3ver_state';
337                         $selectFields[] = 't3ver_wsid';
338                         $selectFields[] = 't3ver_swapmode';             // Filtered out when pages in makeFieldList()
339                 }
340                 if ($l10nEnabled)       {
341                         $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
342                         $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
343                 }
344                 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt'])       {
345                         $selectFields = array_merge(
346                                 $selectFields,
347                                 t3lib_div::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], 1)
348                         );
349                 }
350                 $selectFields = array_unique($selectFields);            // Unique list!
351                 $fieldListFields = $this->makeFieldList($table, 1);
352                 if (empty($fieldListFields) && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
353
354                         $message = sprintf(
355                                 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.php:missingTcaColumnsMessage', TRUE),
356                                 $table,
357                                 $table
358                         );
359                         $messageTitle = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.php:missingTcaColumnsMessageTitle', TRUE);
360
361                         $flashMessage = t3lib_div::makeInstance(
362                                 't3lib_FlashMessage',
363                                 $message,
364                                 $messageTitle,
365                                 t3lib_FlashMessage::WARNING,
366                                 TRUE
367                         );
368                         /** @var t3lib_FlashMessage $flashMessage */
369                         t3lib_FlashMessageQueue::addMessage($flashMessage);
370                 }
371                 $selectFields = array_intersect($selectFields, $fieldListFields);       // Making sure that the fields in the field-list ARE in the field-list from TCA!
372                 $selFieldList = implode(',', $selectFields);            // implode it into a list of fields for the SQL-statement.
373                 $this->selFieldList = $selFieldList;
374
375                 /**
376                  * @hook                        DB-List getTable
377                  * @date                        2007-11-16
378                  * @request             Malte Jansen  <mail@maltejansen.de>
379                  */
380                 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'])) {
381                         foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'] as $classData) {
382                                 $hookObject = t3lib_div::getUserObj($classData);
383
384                                 if(!($hookObject instanceof t3lib_localRecordListGetTableHook)) {
385                                         throw new UnexpectedValueException('$hookObject must implement interface t3lib_localRecordListGetTableHook', 1195114460);
386                                 }
387
388                                 $hookObject->getDBlistQuery($table, $id, $addWhere, $selFieldList, $this);
389                         }
390                 }
391
392                         // Create the SQL query for selecting the elements in the listing:
393                 if ($this->csvOutput) { // do not do paging when outputting as CSV
394                         $this->iLimit = 0;
395                 }
396
397                 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
398                                 // Get the two previous rows for sorting if displaying page > 1
399                         $this->firstElementNumber = $this->firstElementNumber - 2;
400                         $this->iLimit = $this->iLimit + 2;
401                         $queryParts = $this->makeQueryArray($table, $id,$addWhere,$selFieldList);       // (API function from class.db_list.inc)
402                         $this->firstElementNumber = $this->firstElementNumber + 2;
403                         $this->iLimit = $this->iLimit - 2;
404                 } else {
405                         $queryParts = $this->makeQueryArray($table, $id,$addWhere,$selFieldList);       // (API function from class.db_list.inc)
406                 }
407
408                 $this->setTotalItems($queryParts);              // Finding the total amount of records on the page (API function from class.db_list.inc)
409
410                         // Init:
411                 $dbCount = 0;
412                 $out = '';
413                 $listOnlyInSingleTableMode = $this->listOnlyInSingleTableMode && !$this->table;
414
415                         // If the count query returned any number of records, we perform the real query, selecting records.
416                 if ($this->totalItems)  {
417                         // Fetch records only if not in single table mode or if in multi table mode and not collapsed
418                         if ($listOnlyInSingleTableMode || (!$this->table && $tableCollapsed)) {
419                                 $dbCount = $this->totalItems;
420                         } else {
421                                         // set the showLimit to the number of records when outputting as CSV
422                                 if ($this->csvOutput) {
423                                         $this->showLimit = $this->totalItems;
424                                         $this->iLimit = $this->totalItems;
425                                 }
426                                 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
427                                 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
428                         }
429                 }
430
431                         // If any records was selected, render the list:
432                 if ($dbCount)   {
433
434                                 // Half line is drawn between tables:
435                         if (!$listOnlyInSingleTableMode)        {
436                                 $theData = Array();
437                                 if (!$this->table && !$rowlist) {
438                                         $theData[$titleCol] = '<img src="clear.gif" width="'.($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel']?'230':'350').'" height="1" alt="" />';
439                                         if (in_array('_CONTROL_',$this->fieldArray))    $theData['_CONTROL_']='';
440                                         if (in_array('_CLIPBOARD_',$this->fieldArray))  $theData['_CLIPBOARD_']='';
441                                 }
442                                 $out.=$this->addelement(0,'',$theData,'class="c-table-row-spacer"',$this->leftMargin);
443                         }
444
445                         $tableTitle = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title'], TRUE);
446                         if ($tableTitle === '') {
447                                 $tableTitle = $table;
448                         }
449                                 // Header line is drawn
450                         $theData = array();
451                         if ($this->disableSingleTableView)      {
452                                 $theData[$titleCol] = '<span class="c-table">' .
453                                                 t3lib_BEfunc::wrapInHelp($table, '', $tableTitle) .
454                                                 '</span> (' . $this->totalItems . ')';
455                         } else {
456                                 $theData[$titleCol] = $this->linkWrapTable($table, '<span class="c-table">' . $tableTitle . '</span> (' . $this->totalItems . ') ' .
457                                                 ($this->table ? t3lib_iconWorks::getSpriteIcon('actions-view-table-collapse', array('title' => $GLOBALS['LANG']->getLL('contractView', TRUE))) : t3lib_iconWorks::getSpriteIcon('actions-view-table-expand', array('title' => $GLOBALS['LANG']->getLL('expandView', TRUE))))
458                                         );
459                         }
460
461                         if ($listOnlyInSingleTableMode) {
462                                 $out.='
463                                         <tr>
464                                                 <td class="t3-row-header" style="width:95%;">' . t3lib_BEfunc::wrapInHelp($table, '', $theData[$titleCol]) . '</td>
465                                         </tr>';
466                         } else {
467                                 // Render collapse button if in multi table mode
468                                 $collapseIcon = '';
469                                 if (!$this->table) {
470                                         $collapseIcon = '<a href="' . htmlspecialchars($this->listURL() . '&collapse[' . $table . ']=' . ($tableCollapsed ? '0' : '1')) . '" title="' . ($tableCollapsed ? $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.expandTable', TRUE) : $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.collapseTable', TRUE)) . '">' .
471                                                         ($tableCollapsed ? t3lib_iconWorks::getSpriteIcon('actions-view-list-expand', array('class' => 'collapseIcon')) : t3lib_iconWorks::getSpriteIcon('actions-view-list-collapse', array('class' => 'collapseIcon'))) .
472                                                 '</a>';
473                                 }
474                                 $out .= $this->addElement(1, $collapseIcon, $theData, ' class="t3-row-header"', '');
475                         }
476
477                         // Render table rows only if in multi table view and not collapsed or if in single table view
478                         if (!$listOnlyInSingleTableMode && (!$tableCollapsed || $this->table)) {
479                                         // Fixing a order table for sortby tables
480                                 $this->currentTable = array();
481                                 $currentIdList = array();
482                                 $doSort = ($GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField);
483
484                                 $prevUid = 0;
485                                 $prevPrevUid = 0;
486
487                                         // Get first two rows and initialize prevPrevUid and prevUid if on page > 1
488                                 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
489                                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
490                                         $prevPrevUid = -(int) $row['uid'];
491                                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
492                                         $prevUid = $row['uid'];
493                                 }
494
495                                 $accRows = array();     // Accumulate rows here
496                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))    {
497
498                                                 // In offline workspace, look for alternative record:
499                                         t3lib_BEfunc::workspaceOL($table, $row, $GLOBALS['BE_USER']->workspace, TRUE);
500
501                                         if (is_array($row))     {
502                                                 $accRows[] = $row;
503                                                 $currentIdList[] = $row['uid'];
504                                                 if ($doSort)    {
505                                                         if ($prevUid)   {
506                                                                 $this->currentTable['prev'][$row['uid']] = $prevPrevUid;
507                                                                 $this->currentTable['next'][$prevUid] = '-'.$row['uid'];
508                                                                 $this->currentTable['prevUid'][$row['uid']] = $prevUid;
509                                                         }
510                                                         $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
511                                                         $prevUid=$row['uid'];
512                                                 }
513                                         }
514                                 }
515                                 $GLOBALS['TYPO3_DB']->sql_free_result($result);
516
517                                 $this->totalRowCount = count($accRows);
518
519                                         // CSV initiated
520                                 if ($this->csvOutput) $this->initCSV();
521
522                                         // Render items:
523                                 $this->CBnames=array();
524                                 $this->duplicateStack=array();
525                                 $this->eCounter=$this->firstElementNumber;
526
527                                 $iOut = '';
528                                 $cc = 0;
529
530                                 foreach($accRows as $row)       {
531                                         // Render item row if counter < limit
532                                         if ($cc < $this->iLimit) {
533                                                 $cc++;
534                                                 $this->translations = FALSE;
535                                                 $iOut.= $this->renderListRow($table,$row,$cc,$titleCol,$thumbsCol);
536
537                                                         // If localization view is enabled it means that the selected records are either default or All language and here we will not select translations which point to the main record:
538                                                 if ($this->localizationView && $l10nEnabled)    {
539                                                                 // For each available translation, render the record:
540                                                         if (is_array($this->translations)) {
541                                                                 foreach ($this->translations as $lRow) {
542                                                                                 // $lRow isn't always what we want - if record was moved we've to work with the placeholder records otherwise the list is messed up a bit
543                                                                         if ($row['_MOVE_PLH_uid'] && $row['_MOVE_PLH_pid']) {
544                                                                                 $tmpRow = t3lib_BEfunc::getRecordRaw($table, 't3ver_move_id="'.intval($lRow['uid']) . '" AND pid="' . $row['_MOVE_PLH_pid'] . '" AND t3ver_wsid=' . $row['t3ver_wsid'] . t3lib_beFunc::deleteClause($table), $selFieldList);
545                                                                                 $lRow = is_array($tmpRow)?$tmpRow:$lRow;
546                                                                         }
547                                                                                 // In offline workspace, look for alternative record:
548                                                                         t3lib_BEfunc::workspaceOL($table, $lRow, $GLOBALS['BE_USER']->workspace, TRUE);
549                                                                         if (is_array($lRow) && $GLOBALS['BE_USER']->checkLanguageAccess($lRow[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
550                                                                                 $currentIdList[] = $lRow['uid'];
551                                                                                 $iOut.=$this->renderListRow($table,$lRow,$cc,$titleCol,$thumbsCol,18);
552                                                                         }
553                                                                 }
554                                                         }
555                                                 }
556                                         }
557
558                                                 // Counter of total rows incremented:
559                                         $this->eCounter++;
560                                 }
561
562                                         // Record navigation is added to the beginning and end of the table if in single table mode
563                                 if ($this->table) {
564                                         $iOut = $this->renderListNavigation('top') . $iOut . $this->renderListNavigation('bottom');
565                                 } else {
566                                                 // show that there are more records than shown
567                                         if ($this->totalItems > $this->itemsLimitPerTable) {
568                                                 $countOnFirstPage = $this->totalItems > $this->itemsLimitSingleTable ? $this->itemsLimitSingleTable : $this->totalItems;
569                                                 $hasMore = ($this->totalItems > $this->itemsLimitSingleTable);
570                                                 $iOut .= '<tr><td colspan="' . count($this->fieldArray) . '" style="padding:5px;">
571                                                                 <a href="'.htmlspecialchars($this->listURL() . '&table=' . rawurlencode($table)) . '">' .
572                                                                 '<img' . t3lib_iconWorks::skinImg($this->backPath,'gfx/pildown.gif', 'width="14" height="14"') .' alt="" />'.
573                                                                 ' <i>[1 - ' . $countOnFirstPage . ($hasMore ? '+' : '') . ']</i></a>
574                                                                 </td></tr>';
575                                                 }
576
577                                 }
578
579                                         // The header row for the table is now created:
580                                 $out .= $this->renderListHeader($table,$currentIdList);
581                         }
582
583                                 // The list of records is added after the header:
584                         $out .= $iOut;
585                         unset($iOut);
586
587                                 // ... and it is all wrapped in a table:
588                         $out='
589
590
591
592                         <!--
593                                 DB listing of elements: "'.htmlspecialchars($table).'"
594                         -->
595                                 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist'.($listOnlyInSingleTableMode?' typo3-dblist-overview':'').'">
596                                         '.$out.'
597                                 </table>';
598
599                                 // Output csv if...
600                         if ($this->csvOutput)   $this->outputCSV($table);       // This ends the page with exit.
601                 }
602
603                         // Return content:
604                 return $out;
605         }
606
607         /**
608          * Rendering a single row for the list
609          *
610          * @param       string          Table name
611          * @param       array           Current record
612          * @param       integer         Counter, counting for each time an element is rendered (used for alternating colors)
613          * @param       string          Table field (column) where header value is found
614          * @param       string          Table field (column) where (possible) thumbnails can be found
615          * @param       integer         Indent from left.
616          * @return      string          Table row for the element
617          * @access private
618          * @see getTable()
619          */
620         function renderListRow($table,$row,$cc,$titleCol,$thumbsCol,$indent=0)  {
621                 $iOut = '';
622
623                 if (strlen($this->searchString))        {       // If in search mode, make sure the preview will show the correct page
624                         $id_orig = $this->id;
625                         $this->id = $row['pid'];
626                 }
627
628                 if (is_array($row))     {
629                                 // add special classes for first and last row
630                         $rowSpecial = '';
631                         if ($cc == 1 && $indent == 0) {
632                                 $rowSpecial .= ' firstcol';
633                         }
634                         if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
635                                 $rowSpecial .= ' lastcol';
636                         }
637
638                                 // Background color, if any:
639                         if ($this->alternateBgColors) {
640                                 $row_bgColor = ($cc%2) ? ' class="db_list_normal'.$rowSpecial.'"' : ' class="db_list_alt'.$rowSpecial.'"';
641                         } else {
642                                 $row_bgColor = ' class="db_list_normal'.$rowSpecial.'"';
643                         }
644                                 // Overriding with versions background color if any:
645                         $row_bgColor = $row['_CSSCLASS'] ? ' class="'.$row['_CSSCLASS'].'"' : $row_bgColor;
646
647                                 // Incr. counter.
648                         $this->counter++;
649
650                                 // The icon with link
651                         $alttext = t3lib_BEfunc::getRecordIconAltText($row,$table);
652                         $iconImg = t3lib_iconWorks::getSpriteIconForRecord($table, $row, array('title' => htmlspecialchars($alttext), 'style' => ($indent ? ' margin-left: ' . $indent . 'px;' : '')));
653
654
655                         $theIcon = $this->clickMenuEnabled ? $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,$table,$row['uid']) : $iconImg;
656
657                                 // Preparing and getting the data-array
658                         $theData = Array();
659                         foreach($this->fieldArray as $fCol)     {
660                                 if ($fCol==$titleCol)   {
661                                         $recTitle = t3lib_BEfunc::getRecordTitle($table,$row,FALSE,TRUE);
662                                                 // If the record is edit-locked by another user, we will show a little warning sign:
663                                         if (($lockInfo = t3lib_BEfunc::isRecordLocked($table, $row['uid']))) {
664                                                 $warning = '<a href="#" onclick="' . htmlspecialchars('alert(' . $GLOBALS['LANG']->JScharCode($lockInfo['msg']) . '); return false;') . '" title="' . htmlspecialchars($lockInfo['msg']) . '">' .
665                                                                 t3lib_iconWorks::getSpriteIcon('status-warning-in-use') .
666                                                         '</a>';
667                                         }
668                                         $theData[$fCol] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
669
670                                                 // Render thumbsnails if a thumbnail column exists and there is content in it:
671                                         if ($this->thumbs && trim($row[$thumbsCol])) {
672                                                 $theData[$fCol] .= '<br />' . $this->thumbCode($row,$table,$thumbsCol);
673                                         }
674
675                                         $localizationMarkerClass = '';
676                                         if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
677                                         && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0
678                                         && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
679                                                         // it's a translated record with a language parent
680                                                 $localizationMarkerClass = ' localization';
681                                         }
682                                 } elseif ($fCol == 'pid') {
683                                         $theData[$fCol]=$row[$fCol];
684                                 } elseif ($fCol == '_PATH_') {
685                                         $theData[$fCol]=$this->recPath($row['pid']);
686                                 } elseif ($fCol == '_REF_') {
687                                         $theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
688                                 } elseif ($fCol == '_CONTROL_') {
689                                         $theData[$fCol]=$this->makeControl($table,$row);
690                                 } elseif ($fCol == '_AFTERCONTROL_' || $fCol == '_AFTERREF_') {
691                                         $theData[$fCol] = '&nbsp;';
692                                 } elseif ($fCol == '_CLIPBOARD_') {
693                                         $theData[$fCol]=$this->makeClip($table,$row);
694                                 } elseif ($fCol == '_LOCALIZATION_') {
695                                         list($lC1, $lC2) = $this->makeLocalizationPanel($table,$row);
696                                         $theData[$fCol] = $lC1;
697                                         $theData[$fCol.'b'] = $lC2;
698                                 } elseif ($fCol == '_LOCALIZATION_b') {
699                                         // Do nothing, has been done above.
700                                 } else {
701                                         $tmpProc = t3lib_BEfunc::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid']);
702                                         $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
703                                         if ($this->csvOutput) {
704                                                 $row[$fCol] = t3lib_BEfunc::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
705                                         }
706                                 }
707                         }
708
709                         if (strlen($this->searchString))        {       // Reset the ID if it was overwritten
710                                 $this->id = $id_orig;
711                         }
712
713                                 // Add row to CSV list:
714                         if ($this->csvOutput) {
715                                 $this->addToCSV($row,$table);
716                         }
717
718                         // Add classes to table cells
719                         $this->addElement_tdCssClass[$titleCol]         = 'col-title' . $localizationMarkerClass;
720                         if (!$this->dontShowClipControlPanels) {
721                                 $this->addElement_tdCssClass['_CONTROL_']       = 'col-control';
722                                 $this->addElement_tdCssClass['_AFTERCONTROL_']  = 'col-control-space';
723                                 $this->addElement_tdCssClass['_CLIPBOARD_']     = 'col-clipboard';
724                         }
725                         $this->addElement_tdCssClass['_PATH_']          = 'col-path';
726                         $this->addElement_tdCssClass['_LOCALIZATION_']  = 'col-localizationa';
727                         $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
728
729                                 // Create element in table cells:
730                         $iOut.=$this->addelement(1,$theIcon,$theData,$row_bgColor);
731
732                                 // Finally, return table row element:
733                         return $iOut;
734                 }
735         }
736
737         /**
738          * Gets the number of records referencing the record with the UID $uid in
739          * the table $tableName.
740          *
741          * @param string $tableName
742          *        table name of the referenced record, must not be empty
743          * @param integer $uid
744          *        UID of the referenced record, must be > 0
745          *
746          * @return integer the number of references to record $uid in table
747          *                 $tableName, will be >= 0
748          */
749         protected function getReferenceCount($tableName, $uid) {
750                 if (!isset($this->referenceCount[$tableName][$uid])) {
751                         $numberOfReferences = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
752                                 '*',
753                                 'sys_refindex',
754                                 'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr(
755                                         $tableName, 'sys_refindex'
756                                 ) .
757                                         ' AND ref_uid = ' . $uid .
758                                         ' AND deleted = 0'
759                         );
760
761                         $this->referenceCount[$tableName][$uid] = $numberOfReferences;
762                 }
763
764                 return $this->referenceCount[$tableName][$uid];
765         }
766
767         /**
768          * Rendering the header row for a table
769          *
770          * @param       string          Table name
771          * @param       array           Array of the currently displayed uids of the table
772          * @return      string          Header table row
773          * @access private
774          * @see getTable()
775          */
776         function renderListHeader($table, $currentIdList)       {
777                         // Init:
778                 $theData = Array();
779
780                         // Traverse the fields:
781                 foreach($this->fieldArray as $fCol)     {
782
783                                 // Calculate users permissions to edit records in the table:
784                         $permsEdit = $this->calcPerms & ($table=='pages'?2:16);
785
786                         switch((string)$fCol)   {
787                                 case '_PATH_':                  // Path
788                                         $theData[$fCol] = '<i>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels._PATH_', 1) . ']</i>';
789                                 break;
790                                 case '_REF_':                   // References
791                                         $theData[$fCol] = '<i>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:c__REF_', 1) . ']</i>';
792                                 break;
793                                 case '_LOCALIZATION_':                  // Path
794                                         $theData[$fCol] = '<i>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels._LOCALIZATION_', 1) . ']</i>';
795                                 break;
796                                 case '_LOCALIZATION_b':                 // Path
797                                         $theData[$fCol] = $GLOBALS['LANG']->getLL('Localize', 1);
798                                 break;
799                                 case '_CLIPBOARD_':             // Clipboard:
800                                         $cells=array();
801
802                                                 // If there are elements on the clipboard for this table, then display the "paste into" icon:
803                                         $elFromTable = $this->clipObj->elFromTable($table);
804                                         if (count($elFromTable))        {
805                                                 $cells['pasteAfter'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl($table, $this->id)) .
806                                                         '" onclick="' . htmlspecialchars('return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into' ,$elFromTable)) .
807                                                         '" title="' . $GLOBALS['LANG']->getLL('clip_paste', TRUE) . '">' .
808                                                         t3lib_iconWorks::getSpriteIcon('actions-document-paste-after') . '</a>';
809                                         }
810
811                                                 // If the numeric clipboard pads are enabled, display the control icons for that:
812                                         if ($this->clipObj->current!='normal')  {
813
814                                                         // The "select" link:
815                                                 $cells['copyMarked'] = $this->linkClipboardHeaderIcon(
816                                                         t3lib_iconWorks::getSpriteIcon(
817                                                                 'actions-edit-copy',
818                                                                 array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))
819                                                         ),
820                                                         $table,
821                                                         'setCB');
822
823                                                         // The "edit marked" link:
824                                                 $editIdList = implode(',',$currentIdList);
825                                                 $editIdList = "'+editList('".$table."','".$editIdList."')+'";
826                                                 $params='&edit['.$table.']['.$editIdList.']=edit&disHelp=1';
827                                                 $cells['edit'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath, -1)) .
828                                                                 '" title="' . $GLOBALS['LANG']->getLL('clip_editMarked', TRUE) . '">' .
829                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
830                                                                 '</a>';
831
832                                                         // The "Delete marked" link:
833                                                 $cells['delete'] = $this->linkClipboardHeaderIcon(
834                                                         t3lib_iconWorks::getSpriteIcon(
835                                                                 'actions-edit-delete',
836                                                                 array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked', TRUE))
837                                                         ),
838                                                         $table,
839                                                         'delete',
840                                                         sprintf($GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'), $GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title']))
841                                                 );
842
843                                                         // The "Select all" link:
844                                                 $cells['markAll'] = '<a class="cbcCheckAll" rel="" href="#" onclick="' .
845                                                                 htmlspecialchars('checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;') .
846                                                                 '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' .
847                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-select') .
848                                                                 '</a>';
849                                         } else {
850                                                 $cells['empty']='';
851                                         }
852                                         /**
853                                          * @hook                        renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
854                                          * @date                        2007-11-20
855                                          * @request             Bernhard Kraft  <krafbt@kraftb.at>
856                                          * @usage               Above each listed table in Web>List a header row is shown. This hook allows to modify the icons responsible for the clipboard functions (shown above the clipboard checkboxes when a clipboard other than "Normal" is selected), or other "Action" functions which perform operations on the listed records.
857                                          */
858                                         if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions']))     {
859                                                 foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData)    {
860                                                         $hookObject = t3lib_div::getUserObj($classData);
861                                                         if(!($hookObject instanceof localRecordList_actionsHook))       {
862                                                                 throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567850);
863                                                         }
864                                                         $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
865                                                 }
866                                         }
867                                         $theData[$fCol]=implode('',$cells);
868                                 break;
869                                 case '_CONTROL_':               // Control panel:
870                                         if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
871
872                                                         // If new records can be created on this page, add links:
873                                                 if ($this->calcPerms&($table=='pages'?8:16) && $this->showNewRecLink($table))   {
874                                                         if ($table=="tt_content" && $this->newWizards)  {
875                                                                         //  If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
876                                                                 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
877                                                                 $tmpTSc = $tmpTSc['properties']['newContentWiz.']['overrideWithExtension'];
878                                                                 $newContentWizScriptPath = $this->backPath.t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
879
880                                                                 $icon = '<a href="#" onclick="' . htmlspecialchars('return jumpExt(\'' . $newContentWizScriptPath . '?id=' . $this->id . '\');') . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">'.
881                                                                                                         ($table == 'pages' ? t3lib_iconWorks::getSpriteIcon('actions-page-new') : t3lib_iconWorks::getSpriteIcon('actions-document-new')) .
882                                                                                                 '</a>';
883                                                         } elseif ($table=='pages' && $this->newWizards) {
884                                                                 $icon = '<a href="' . htmlspecialchars($this->backPath . 'db_new.php?id=' . $this->id . '&pagesOnly=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))) . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">'.
885                                                                                                         ($table=='pages' ? t3lib_iconWorks::getSpriteIcon('actions-page-new') : t3lib_iconWorks::getSpriteIcon('actions-document-new')) .
886                                                                                                 '</a>';
887
888                                                         } else {
889                                                                 $params = '&edit['.$table.']['.$this->id.']=new';
890                                                                 if ($table == 'pages_language_overlay') {
891                                                                         $params .= '&overrideVals[pages_language_overlay][doktype]=' . (int) $this->pageRow['doktype'];
892                                                                 }
893                                                                 $icon   = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">'.
894                                                                                                         ($table=='pages' ? t3lib_iconWorks::getSpriteIcon('actions-page-new') : t3lib_iconWorks::getSpriteIcon('actions-document-new')) .
895                                                                                                 '</a>';
896                                                         }
897                                                 }
898
899                                                         // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
900                                                 if ($permsEdit && $this->table && is_array($currentIdList))     {
901                                                         $editIdList = implode(',',$currentIdList);
902                                                         if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
903                                                         $params = '&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.implode(',',$this->fieldArray).'&disHelp=1';
904                                                         $icon  .= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, -1 )) . '" title="' . $GLOBALS['LANG']->getLL('editShownColumns', TRUE) . '">' .
905                                                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
906                                                                                         '</a>';
907                                                 }
908                                                         // add an empty entry, so column count fits again after moving this into $icon
909                                                 $theData[$fCol] = '&nbsp;';
910                                         }
911                                 break;
912                                 case '_AFTERCONTROL_':  // space column
913                                 case '_AFTERREF_':      // space column
914                                         $theData[$fCol] = '&nbsp;';
915                                 break;
916                                 default:                        // Regular fields header:
917                                         $theData[$fCol]='';
918                                         if ($this->table && is_array($currentIdList))   {
919
920                                                         // If the numeric clipboard pads are selected, show duplicate sorting link:
921                                                 if ($this->clipNumPane()) {
922                                                         $theData[$fCol] .= '<a href="' . htmlspecialchars($this->listURL('', -1) . '&duplicateField=' . $fCol) . '" title="' . $GLOBALS['LANG']->getLL('clip_duplicates', TRUE) . '">' .
923                                                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-duplicates-select') .
924                                                                                         '</a>';
925                                                 }
926
927                                                         // If the table can be edited, add link for editing THIS field for all listed records:
928                                                 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly'] && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
929                                                         $editIdList = implode(',',$currentIdList);
930                                                         if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
931                                                         $params='&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.$fCol.'&disHelp=1';
932                                                         $iTitle = sprintf($GLOBALS['LANG']->getLL('editThisColumn'), rtrim(trim($GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($table, $fCol))), ':'));
933                                                         $theData[$fCol].='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'" title="'.htmlspecialchars($iTitle).'">'.
934                                                                                                 t3lib_iconWorks::getSpriteIcon('actions-document-open') .
935                                                                                         '</a>';
936                                                 }
937                                         }
938                                         $theData[$fCol] .= $this->addSortLink($GLOBALS['LANG']->sL(t3lib_BEfunc::getItemLabel($table, $fCol, '<i>[|]</i>')), $fCol, $table);
939                                 break;
940                         }
941
942                 }
943
944                 /**
945                  * @hook                        renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
946                  * @date                        2007-11-20
947                  * @request             Bernhard Kraft  <krafbt@kraftb.at>
948                  * @usage               Above each listed table in Web>List a header row is shown. Containing the labels of all shown fields and additional icons to create new records for this table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
949                  */
950                 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions']))     {
951                         foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData)    {
952                                 $hookObject = t3lib_div::getUserObj($classData);
953                                 if(!($hookObject instanceof localRecordList_actionsHook))       {
954                                         throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567855);
955                                 }
956                                 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
957                         }
958                 }
959
960                         // Create and return header table row:
961                 return $this->addelement(1, $icon, $theData, ' class="c-headLine"', '');
962         }
963
964         /**
965          * Creates a page browser for tables with many records
966          *
967          * @param       string          Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
968          * @return      string  Navigation HTML
969          *
970          */
971         protected function renderListNavigation($renderPart = 'top') {
972                 $totalPages = ceil($this->totalItems / $this->iLimit);
973
974                 $content = '';
975                 $returnContent = '';
976
977                         // Show page selector if not all records fit into one page
978                 if ($totalPages > 1) {
979                         $first = $previous = $next = $last = $reload = '';
980                         $listURL = $this->listURL('', $this->table);
981
982                                 // 1 = first page
983                         $currentPage = floor(($this->firstElementNumber + 1) / $this->iLimit) + 1;
984
985                                 // Compile first, previous, next, last and refresh buttons
986                         if ($currentPage > 1) {
987                                 $labelFirst = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:first');
988
989                                 $first = '<a href="' . $listURL . '&pointer=0">' .
990                                         t3lib_iconWorks::getSpriteIcon('actions-view-paging-first', array('title'=> $labelFirst)) .
991                                 '</a>';
992                         } else {
993                                 $first = t3lib_iconWorks::getSpriteIcon('actions-view-paging-first-disabled');
994                         }
995
996                         if (($currentPage - 1) > 0) {
997                                 $labelPrevious = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:previous');
998
999                                 $previous = '<a href="' . $listURL . '&pointer=' . (($currentPage - 2) * $this->iLimit) . '">' .
1000                                         t3lib_iconWorks::getSpriteIcon('actions-view-paging-previous', array('title' => $labelPrevious)) .
1001                                         '</a>';
1002                         } else {
1003                                 $previous = t3lib_iconWorks::getSpriteIcon('actions-view-paging-previous-disabled');
1004                         }
1005
1006                         if (($currentPage + 1) <= $totalPages) {
1007                                 $labelNext = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:next');
1008
1009                                 $next = '<a href="' . $listURL . '&pointer=' . (($currentPage) * $this->iLimit) . '">' .
1010                                         t3lib_iconWorks::getSpriteIcon('actions-view-paging-next', array('title' => $labelNext)) .
1011                                         '</a>';
1012                         } else {
1013                                 $next = t3lib_iconWorks::getSpriteIcon('actions-view-paging-next-disabled');
1014                         }
1015
1016                         if ($currentPage != $totalPages) {
1017                                 $labelLast = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:last');
1018
1019                                 $last = '<a href="' . $listURL . '&pointer=' . (($totalPages - 1) * $this->iLimit) . '">' .
1020                                         t3lib_iconWorks::getSpriteIcon('actions-view-paging-last', array('title' => $labelLast)) .
1021                                         '</a>';
1022                         } else {
1023                                 $last = t3lib_iconWorks::getSpriteIcon('actions-view-paging-last-disabled');
1024                         }
1025
1026                         $reload = '<a href="#" onclick="document.dblistForm.action=\''
1027                                 . $listURL . '&pointer=\'+calculatePointer(document.getElementById(\'jumpPage-' . $renderPart .'\').value); document.dblistForm.submit(); return true;" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:reload', TRUE) . '">' .
1028                                         t3lib_iconWorks::getSpriteIcon('actions-system-refresh') .
1029                                 '</a>';
1030
1031                         if ($renderPart === 'top') {
1032                                         // Add js to traverse a page select input to a pointer value
1033                                 $content = '
1034 <script type="text/JavaScript">
1035 /*<![CDATA[*/
1036
1037         function calculatePointer(page) {
1038                 if (page > ' . $totalPages . ') {
1039                         page = ' . $totalPages . ';
1040                 }
1041
1042                 if (page < 1) {
1043                         page = 1;
1044                 }
1045
1046                 pointer = (page - 1) * ' . $this->iLimit . ';
1047
1048                 return pointer;
1049         }
1050
1051 /*]]>*/
1052 </script>
1053 ';
1054                         }
1055                         $pageNumberInput = '<span>
1056                                 <input type="text" value="' . $currentPage
1057                                 . '" size="3" id="jumpPage-' . $renderPart . '" name="jumpPage-' . $renderPart . '" onkeyup="if (event.keyCode == Event.KEY_RETURN) { document.dblistForm.action=\'' . $listURL . '&pointer=\'+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
1058                                 </span>';
1059                         $pageIndicator = '<span class="pageIndicator">'
1060                                 . sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xml:pageIndicator'), $pageNumberInput, $totalPages)
1061                                 . '</span>';
1062
1063                         if ($this->totalItems > ($this->firstElementNumber + $this->iLimit)) {
1064                                 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
1065                         } else {
1066                                 $lastElementNumber = $this->totalItems;
1067                         }
1068                         $rangeIndicator = '<span class="pageIndicator">'
1069                                 . sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xml:rangeIndicator'), $this->firstElementNumber + 1, $lastElementNumber)
1070                                 . '</span>';
1071
1072                         $content .= '<div id="typo3-dblist-pagination">'
1073                                 . $first . $previous
1074                                 . '<span class="bar">&nbsp;</span>'
1075                                 . $rangeIndicator . '<span class="bar">&nbsp;</span>'
1076                                 . $pageIndicator . '<span class="bar">&nbsp;</span>'
1077                                 . $next . $last . '<span class="bar">&nbsp;</span>'
1078                                 . $reload
1079                                 . '</div>';
1080
1081                         $data = Array();
1082                         $titleColumn = $this->fieldArray[0];
1083                         $data[$titleColumn] = $content;
1084
1085                         $returnContent = $this->addElement(1, '', $data);
1086                 } // end of if pages > 1
1087
1088                 return $returnContent;
1089         }
1090
1091
1092
1093
1094
1095
1096         /*********************************
1097          *
1098          * Rendering of various elements
1099          *
1100          *********************************/
1101
1102         /**
1103          * Creates the control panel for a single record in the listing.
1104          *
1105          * @param       string          The table
1106          * @param       array           The record for which to make the control panel.
1107          * @return      string          HTML table with the control panel (unless disabled)
1108          */
1109         function makeControl($table,$row)       {
1110                 if ($this->dontShowClipControlPanels)   return '';
1111
1112                 $rowUid = $row['uid'];
1113                 if (t3lib_extMgm::isLoaded('version') && isset($row['_ORIG_uid'])) {
1114                         $rowUid = $row['_ORIG_uid'];
1115                 }
1116
1117                         // Initialize:
1118                 t3lib_div::loadTCA($table);
1119                 $cells=array();
1120
1121                         // If the listed table is 'pages' we have to request the permission settings for each page:
1122                 if ($table=='pages')    {
1123                         $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid']));
1124                 }
1125
1126                         // This expresses the edit permissions for this particular element:
1127                 $permsEdit = ($table=='pages' && ($localCalcPerms&2)) || ($table!='pages' && ($this->calcPerms&16));
1128
1129                         // "Show" link (only pages and tt_content elements)
1130                 if ($table=='pages' || $table=='tt_content')    {
1131                         $params='&edit['.$table.']['.$row['uid'].']=edit';
1132                         $cells['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick(
1133                                         $table=='tt_content' ? $this->id . '#' . $row['uid'] : $row['uid'],
1134                                         $this->backPath)
1135                                 ) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', TRUE) . '">' .
1136                                 t3lib_iconWorks::getSpriteIcon('actions-document-view') . '</a>';
1137                 } elseif(!$this->table) {
1138                         $cells['view'] = $this->spaceIcon;
1139                 }
1140
1141                         // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1142                 if ($permsEdit) {
1143                         $params='&edit['.$table.']['.$row['uid'].']=edit';
1144                         $cells['edit'] = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, -1)) .
1145                                 '" title="' . $GLOBALS['LANG']->getLL('edit', TRUE) . '">' .
1146                                 ( $GLOBALS['TCA'][$table]['ctrl']['readOnly'] ? t3lib_iconWorks::getSpriteIcon('actions-document-open-read-only') : t3lib_iconWorks::getSpriteIcon('actions-document-open')) .
1147                                 '</a>';
1148                 } elseif(!$this->table) {
1149                         $cells['edit'] = $this->spaceIcon;
1150                 }
1151
1152                         // "Move" wizard link for pages/tt_content elements:
1153                 if (($table=="tt_content" && $permsEdit) || ($table=='pages'))  {
1154                         $cells['move'] = '<a href="#" onclick="' .
1155                                 htmlspecialchars(
1156                                         'return jumpExt(\'' . $this->backPath . 'move_el.php?table=' . $table . '&uid='.$row['uid'] . '\');'
1157                                 ) .'" title="' . $GLOBALS['LANG']->getLL('move_' . ($table == 'tt_content' ? 'record' : 'page'), TRUE) . '">' .
1158                                                 ($table == 'tt_content' ? t3lib_iconWorks::getSpriteIcon('actions-document-move') : t3lib_iconWorks::getSpriteIcon('actions-page-move')) .
1159                                         '</a>';
1160                 } elseif(!$this->table) {
1161                         $cells['move'] = $this->spaceIcon;
1162                 }
1163
1164                         // If the extended control panel is enabled OR if we are seeing a single table:
1165                 if ($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel'] || $this->table)  {
1166
1167                                 // "Info": (All records)
1168                         $cells['viewBig'] = '<a href="#" onclick="' . htmlspecialchars(
1169                                         'top.launchView(\'' . $table . '\', \''.$row['uid'] . '\'); return false;'
1170                                 ) . '" title="' . $GLOBALS['LANG']->getLL('showInfo', TRUE) . '">'.
1171                                 t3lib_iconWorks::getSpriteIcon('actions-document-info') .
1172                                 '</a>';
1173
1174                                 // If the table is NOT a read-only table, then show these links:
1175                         if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
1176
1177                                         // "Revert" link (history/undo)
1178                                 $cells['history'] = '<a href="#" onclick="' . htmlspecialchars(
1179                                         'return jumpExt(\'' . $this->backPath . 'show_rechis.php?element=' . rawurlencode($table . ':' . $row['uid']) . '\',\'#latest\');') .
1180                                         '" title="' . $GLOBALS['LANG']->getLL('history', TRUE) . '">'.
1181                                         t3lib_iconWorks::getSpriteIcon('actions-document-history-open') .
1182                                         '</a>';
1183
1184                                         // Versioning:
1185                                 if (t3lib_extMgm::isLoaded('version') && !t3lib_extMgm::isLoaded('workspaces')) {
1186                                         $vers = t3lib_BEfunc::selectVersionsOfRecord($table, $row['uid'], 'uid', $GLOBALS['BE_USER']->workspace, FALSE, $row);
1187                                         if (is_array($vers))    {       // If table can be versionized.
1188                                                 $versionIcon = 'no-version';
1189                                                 if (count($vers) > 1) {
1190                                                         $versionIcon = count($vers) - 1;
1191                                                 }
1192
1193                                                 $cells['version'] = '<a href="' . htmlspecialchars($this->backPath . t3lib_extMgm::extRelPath('version') . 'cm1/index.php?table=' . rawurlencode($table) . '&uid=' . rawurlencode($row['uid'])) . '" title="' . $GLOBALS['LANG']->getLL('displayVersions', TRUE) . '">' .
1194                                                                 t3lib_iconWorks::getSpriteIcon('status-version-' . $versionIcon) .
1195                                                                 '</a>';
1196                                         } elseif(!$this->table) {
1197                                                 $cells['version'] = $this->spaceIcon;
1198                                         }
1199                                 }
1200
1201                                         // "Edit Perms" link:
1202                                 if ($table == 'pages' && $GLOBALS['BE_USER']->check('modules','web_perm') && t3lib_extMgm::isLoaded('perm'))    {
1203                                         $cells['perms'] =
1204                                                 '<a href="' .
1205                                                         htmlspecialchars(
1206                                                                 t3lib_extMgm::extRelPath('perm') . 'mod1/index.php' .
1207                                                                 '?id=' . $row['uid'] . '&return_id=' . $row['uid'] . '&edit=1'
1208                                                         ) .
1209                                                         '" title="' . $GLOBALS['LANG']->getLL('permissions', TRUE) .
1210                                                 '">'.
1211                                                         t3lib_iconWorks::getSpriteIcon('status-status-locked') .
1212                                                 '</a>';
1213                                 } elseif(!$this->table && $GLOBALS['BE_USER']->check('modules','web_perm')) {
1214                                         $cells['perms'] = $this->spaceIcon;
1215                                 }
1216
1217                                         // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row or if default values can depend on previous record):
1218                                 if ($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) {
1219                                         if (
1220                                                 ($table!='pages' && ($this->calcPerms&16)) ||   // For NON-pages, must have permission to edit content on this parent page
1221                                                 ($table=='pages' && ($this->calcPerms&8))               // For pages, must have permission to create new pages here.
1222                                                 )       {
1223                                                 if ($this->showNewRecLink($table))      {
1224                                                         $params='&edit['.$table.']['.(-($row['_MOVE_PLH']?$row['_MOVE_PLH_uid']:$row['uid'])).']=new';
1225                                                         $cells['new'] = '<a href="#" onclick="' . htmlspecialchars(
1226                                                                 t3lib_BEfunc::editOnClick($params, $this->backPath, -1)) .
1227                                                                 '" title="' . $GLOBALS['LANG']->getLL('new' . ($table == 'pages '? 'Page' : 'Record'), TRUE) . '">' .
1228                                                                 ($table == 'pages' ? t3lib_iconWorks::getSpriteIcon('actions-page-new') : t3lib_iconWorks::getSpriteIcon('actions-document-new')) .
1229                                                                 '</a>';
1230                                                 }
1231                                         }
1232                                 } elseif(!$this->table) {
1233                                         $cells['new'] = $this->spaceIcon;
1234                                 }
1235
1236                                         // "Up/Down" links
1237                                 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby']  && !$this->sortField && !$this->searchLevels) {
1238                                         if (isset($this->currentTable['prev'][$row['uid']]))    {       // Up
1239                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prev'][$row['uid']];
1240                                                 $cells['moveUp'] = '<a href="#" onclick="' . htmlspecialchars(
1241                                                                         'return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');'
1242                                                                 ) .'" title="'.$GLOBALS['LANG']->getLL('moveUp', TRUE) . '">' .
1243                                                                 t3lib_iconWorks::getSpriteIcon('actions-move-up') .
1244                                                                 '</a>';
1245                                         } else {
1246                                                 $cells['moveUp'] = $this->spaceIcon;
1247                                         }
1248                                         if ($this->currentTable['next'][$row['uid']])   {       // Down
1249                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['next'][$row['uid']];
1250                                                 $cells['moveDown']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$GLOBALS['SOBE']->doc->issueCommand($params,-1).'\');').'" title="'.$GLOBALS['LANG']->getLL('moveDown', TRUE) . '">' .
1251                                                                         t3lib_iconWorks::getSpriteIcon('actions-move-down') .
1252                                                                 '</a>';
1253                                         } else {
1254                                                 $cells['moveDown'] = $this->spaceIcon;
1255                                         }
1256                                 } elseif(!$this->table) {
1257                                         $cells['moveUp']  = $this->spaceIcon;
1258                                         $cells['moveDown'] = $this->spaceIcon;
1259                                 }
1260
1261                                         // "Hide/Unhide" links:
1262                                 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1263                                 if ($permsEdit && $hiddenField && $GLOBALS['TCA'][$table]['columns'][$hiddenField] && (!$GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $hiddenField))) {
1264                                         if ($row[$hiddenField]) {
1265                                                 $params = '&data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
1266                                                 $cells['hide']='<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '" title="'.$GLOBALS['LANG']->getLL('unHide' . ($table == 'pages' ? 'Page' : ''), TRUE) . '">' .
1267                                                                         t3lib_iconWorks::getSpriteIcon('actions-edit-unhide') .
1268                                                                 '</a>';
1269                                         } else {
1270                                                 $params = '&data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
1271                                                 $cells['hide']='<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '" title="' . $GLOBALS['LANG']->getLL('hide' . ($table == 'pages' ? 'Page' : ''), TRUE) . '">' .
1272                                                                         t3lib_iconWorks::getSpriteIcon('actions-edit-hide') .
1273                                                                 '</a>';
1274                                         }
1275                                 } elseif(!$this->table) {
1276                                         $cells['hide'] = $this->spaceIcon;
1277                                 }
1278
1279                                         // "Delete" link:
1280                                 if (($table=='pages' && ($localCalcPerms&4)) || ($table!='pages' && ($this->calcPerms&16))) {
1281                                         $titleOrig = t3lib_BEfunc::getRecordTitle($table,$row,FALSE,TRUE);
1282                                         $title = t3lib_div::slashJS(t3lib_div::fixed_lgd_cs($titleOrig, $this->fixedL), 1);
1283                                         $params = '&cmd['.$table.']['.$row['uid'].'][delete]=1';
1284
1285                                         $refCountMsg = t3lib_BEfunc::referenceCount(
1286                                                 $table,
1287                                                 $row['uid'],
1288                                                 ' ' . $GLOBALS['LANG']->sL(
1289                                                         'LLL:EXT:lang/locallang_core.xml:labels.referencesToRecord'
1290                                                 ),
1291                                                 $this->getReferenceCount($table, $row['uid'])
1292                                         ) .
1293                                                 t3lib_BEfunc::translationCount($table, $row['uid'], ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.translationsOfRecord'));
1294                                         $cells['delete'] = '<a href="#" onclick="' . htmlspecialchars('if (confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('deleteWarning') . ' "' .  $title . '" ' . $refCountMsg) . ')) {jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');} return false;') . '" title="' . $GLOBALS['LANG']->getLL('delete', TRUE) . '">' .
1295                                                         t3lib_iconWorks::getSpriteIcon('actions-edit-delete') .
1296                                                         '</a>';
1297                                 } elseif(!$this->table) {
1298                                         $cells['delete'] = $this->spaceIcon;
1299                                 }
1300
1301                                         // "Levels" links: Moving pages into new levels...
1302                                 if ($permsEdit && $table=='pages' && !$this->searchLevels)      {
1303
1304                                                 // Up (Paste as the page right after the current parent page)
1305                                         if ($this->calcPerms&8) {
1306                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.-$this->id;
1307                                                 $cells['moveLeft'] = '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '" title="' . $GLOBALS['LANG']->getLL('prevLevel', TRUE) . '">' .
1308                                                                         t3lib_iconWorks::getSpriteIcon('actions-move-left') .
1309                                                                 '</a>';
1310                                         }
1311                                                 // Down (Paste as subpage to the page right above)
1312                                         if ($this->currentTable['prevUid'][$row['uid']])        {
1313                                                 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$this->currentTable['prevUid'][$row['uid']]));
1314                                                 if ($localCalcPerms&8)  {
1315                                                         $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prevUid'][$row['uid']];
1316                                                         $cells['moveRight'] = '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '" title="' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '">' .
1317                                                                                 t3lib_iconWorks::getSpriteIcon('actions-move-right') .
1318                                                                         '</a>';
1319                                                 } else {
1320                                                         $cells['moveRight'] = $this->spaceIcon;
1321                                                 }
1322                                         } else {
1323                                                 $cells['moveRight'] = $this->spaceIcon;
1324                                         }
1325                                 } elseif(!$this->table) {
1326                                         $cells['moveLeft'] = $this->spaceIcon;
1327                                         $cells['moveRight'] = $this->spaceIcon;
1328                                 }
1329                         }
1330                 }
1331
1332
1333                 /**
1334                  * @hook                        recStatInfoHooks: Allows to insert HTML before record icons on various places
1335                  * @date                        2007-09-22
1336                  * @request             Kasper Skårhøj  <kasper2007@typo3.com>
1337                  */
1338                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks']))  {
1339                         $stat='';
1340                         $_params = array($table,$row['uid']);
1341                         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef)  {
1342                                 $stat.=t3lib_div::callUserFunction($_funcRef,$_params,$this);
1343                         }
1344                         $cells['stat'] = $stat;
1345                 }
1346                 /**
1347                  * @hook                        makeControl: Allows to change control icons of records in list-module
1348                  * @date                        2007-11-20
1349                  * @request             Bernhard Kraft  <krafbt@kraftb.at>
1350                  * @usage               This hook method gets passed the current $cells array as third parameter. This array contains values for the icons/actions generated for each record in Web>List. Each array entry is accessible by an index-key. The order of the icons is dependend on the order of those array entries.
1351                  */
1352                 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1353                         foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1354                                 $hookObject = t3lib_div::getUserObj($classData);
1355                                 if(!($hookObject instanceof localRecordList_actionsHook))       {
1356                                         throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567840);
1357                                 }
1358                                 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1359                         }
1360                 }
1361
1362                         // Compile items into a DIV-element:
1363                 return '
1364                                                                                         <!-- CONTROL PANEL: '.$table.':'.$row['uid'].' -->
1365                                                                                         <div class="typo3-DBctrl">'.implode('',$cells).'</div>';
1366         }
1367
1368         /**
1369          * Creates the clipboard panel for a single record in the listing.
1370          *
1371          * @param       string          The table
1372          * @param       array           The record for which to make the clipboard panel.
1373          * @return      string          HTML table with the clipboard panel (unless disabled)
1374          */
1375         function makeClip($table,$row)  {
1376                         // Return blank, if disabled:
1377                 if ($this->dontShowClipControlPanels)   return '';
1378                 $cells=array();
1379
1380                 $cells['pasteAfter'] = $cells['pasteInto'] = $this->spaceIcon;
1381                         //enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
1382                 $isL10nOverlay = $this->localizationView && $table != 'pages_language_overlay' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1383                         // Return blank, if disabled:
1384                         // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1385                 if ($this->clipObj->current=='normal')  {       // For the "Normal" pad:
1386
1387                                 // Show copy/cut icons:
1388                         $isSel = (string)$this->clipObj->isSelected($table,$row['uid']);
1389                         $cells['copy'] = $isL10nOverlay ? $this->spaceIcon : '<a href="#" onclick="' . htmlspecialchars('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel=='copy'), array('returnUrl'=>'')) . '\');') . '" title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.copy', TRUE) . '">' .
1390                                                 ((!$isSel=='copy') ? t3lib_iconWorks::getSpriteIcon('actions-edit-copy') : t3lib_iconWorks::getSpriteIcon('actions-edit-copy-release')) .
1391                                         '</a>';
1392                         $cells['cut'] = $isL10nOverlay ? $this->spaceIcon : '<a href="#" onclick="' . htmlspecialchars('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel == 'cut'), array('returnUrl'=>'')) . '\');') . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.cut', TRUE) . '">' .
1393                                                 ((!$isSel=='cut') ? t3lib_iconWorks::getSpriteIcon('actions-edit-cut') : t3lib_iconWorks::getSpriteIcon('actions-edit-cut-release')) .
1394                                         '</a>';
1395
1396                 } else {        // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1397
1398                                 // Setting name of the element in ->CBnames array:
1399                         $n=$table.'|'.$row['uid'];
1400                         $this->CBnames[]=$n;
1401
1402                                 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1403                         $checked = ($this->clipObj->isSelected($table,$row['uid'])?' checked="checked"':'');
1404
1405                                 // If the "duplicateField" value is set then select all elements which are duplicates...
1406                         if ($this->duplicateField && isset($row[$this->duplicateField]))        {
1407                                 $checked='';
1408                                 if (in_array($row[$this->duplicateField], $this->duplicateStack))       {
1409                                         $checked=' checked="checked"';
1410                                 }
1411                                 $this->duplicateStack[] = $row[$this->duplicateField];
1412                         }
1413
1414                                 // Adding the checkbox to the panel:
1415                         $cells['select'] = $isL10nOverlay ? $this->spaceIcon : '<input type="hidden" name="CBH['.$n.']" value="0" /><input type="checkbox" name="CBC['.$n.']" value="1" class="smallCheckboxes"'.$checked.' />';
1416                 }
1417
1418                         // Now, looking for selected elements from the current table:
1419                 $elFromTable = $this->clipObj->elFromTable($table);
1420                 if (count($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']){
1421                                 // IF elements are found and they can be individually ordered, then add a "paste after" icon:
1422                         $cells['pasteAfter'] = $isL10nOverlay ? $this->spaceIcon : '<a href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '" onclick="' . htmlspecialchars('return '. $this->clipObj->confirmMsg($table, $row, 'after', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteAfter', TRUE) . '">' .
1423                                                 t3lib_iconWorks::getSpriteIcon('actions-document-paste-after') .
1424                                         '</a>';
1425                 }
1426
1427                         // Now, looking for elements in general:
1428                 $elFromTable = $this->clipObj->elFromTable('');
1429                 if ($table=='pages' && count($elFromTable))     {
1430                         $cells['pasteInto'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid'])) . '" onclick="' . htmlspecialchars('return ' . $this->clipObj->confirmMsg($table, $row, 'into', $elFromTable)) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">' .
1431                                                 t3lib_iconWorks::getSpriteIcon('actions-document-paste-into') .
1432                                         '</a>';
1433                 }
1434
1435                 /*
1436                  * @hook                        makeClip: Allows to change clip-icons of records in list-module
1437                  * @date                        2007-11-20
1438                  * @request             Bernhard Kraft  <krafbt@kraftb.at>
1439                  * @usage               This hook method gets passed the current $cells array as third parameter. This array contains values for the clipboard icons generated for each record in Web>List. Each array entry is accessible by an index-key. The order of the icons is dependend on the order of those array entries.
1440                  */
1441                 if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1442                         foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1443                                 $hookObject = t3lib_div::getUserObj($classData);
1444                                 if(!($hookObject instanceof localRecordList_actionsHook))       {
1445                                         throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567845);
1446                                 }
1447                                 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1448                         }
1449                 }
1450
1451                         // Compile items into a DIV-element:
1452                 return '                                                        <!-- CLIPBOARD PANEL: '.$table.':'.$row['uid'].' -->
1453                                                                                         <div class="typo3-clipCtrl">'.implode('',$cells).'</div>';
1454         }
1455
1456         /**
1457          * Creates the HTML for a reference count for the record with the UID $uid
1458          * in the table $tableName.
1459          *
1460          * @param string $tableName
1461          *        table name of the referenced record, must not be empty
1462          * @param integer $uid
1463          *        UID of the referenced record, must be > 0
1464          *
1465          * @return string HTML of reference a link, will be empty if there are no
1466          *                references to the corresponding record
1467          */
1468         protected function createReferenceHtml($tableName, $uid) {
1469                 $referenceCount = $this->getReferenceCount($tableName, $uid);
1470                 if ($referenceCount == 0) {
1471                         return '';
1472                 }
1473
1474                 $queryResult = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1475                         'tablename, recuid, field',
1476                         'sys_refindex',
1477                         'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr(
1478                                 $tableName, 'sys_refindex'
1479                         ) .
1480                                 ' AND ref_uid = ' . $uid .
1481                                 ' AND deleted = 0',
1482                         '',
1483                         '',
1484                         '0,20'
1485                 );
1486
1487                 $referenceTitles = array();
1488
1489                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResult)) {
1490                         $referenceTitles[] = $row['tablename'] . ':' . $row['recuid'] .
1491                                 ':' . $row['field'];
1492                         if (strlen(implode(' / ', $referenceTitles)) >= 100) {
1493                                 break;
1494                         }
1495                 }
1496                 $GLOBALS['TYPO3_DB']->sql_free_result($queryResult);
1497
1498                 return '<a href="#" ' .
1499                         'onclick="' . htmlspecialchars(
1500                                 'top.launchView(\'' . $tableName . '\', \'' . $uid .
1501                                 '\'); return false;'
1502                         ) . '" ' .
1503                         'title="' . htmlspecialchars(
1504                                 t3lib_div::fixed_lgd_cs(implode(' / ', $referenceTitles), 100)
1505                         ) . '">' . $referenceCount . '</a>';
1506         }
1507
1508         /**
1509          * Creates the localization panel
1510          *
1511          * @param       string          The table
1512          * @param       array           The record for which to make the localization panel.
1513          * @return      array           Array with key 0/1 with content for column 1 and 2
1514          */
1515         function makeLocalizationPanel($table,$row)     {
1516                 $out = array(
1517                         0 => '',
1518                         1 => '',
1519                 );
1520
1521                 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
1522                 $this->translations = $translations['translations'];
1523
1524                         // Language title and icon:
1525                 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
1526
1527                 if (is_array($translations))    {
1528
1529                                 // Traverse page translations and add icon for each language that does NOT yet exist:
1530                         $lNew = '';
1531                         foreach($this->pageOverlays as $lUid_OnPage => $lsysRec)        {
1532                                 if (!isset($translations['translations'][$lUid_OnPage]) && $GLOBALS['BE_USER']->checkLanguageAccess($lUid_OnPage))      {
1533                                         $url = substr($this->listURL(), strlen($this->backPath));
1534                                         $href = $GLOBALS['SOBE']->doc->issueCommand(
1535                                                 '&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage,
1536                                                 $url . '&justLocalized=' . rawurlencode($table . ':' . $row['uid'] . ':' . $lUid_OnPage)
1537                                         );
1538                                         $language = t3lib_BEfunc::getRecord('sys_language', $lUid_OnPage, 'title');
1539                                         if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
1540                                                 $lC = t3lib_iconWorks::getSpriteIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon']);
1541                                         } else {
1542                                                 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
1543                                         }
1544                                         $lC = '<a href="' . htmlspecialchars($href) . '" title="' . htmlspecialchars($language['title']) . '">' . $lC . '</a> ';
1545
1546                                         $lNew.=$lC;
1547                                 }
1548                         }
1549
1550                         if ($lNew)      $out[1].= $lNew;
1551                 } elseif ($row['l18n_parent']) {
1552                         $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;'.$out[0];
1553                 }
1554
1555
1556                 return $out;
1557         }
1558
1559         /**
1560          * Create the selector box for selecting fields to display from a table:
1561          *
1562          * @param       string          Table name
1563          * @param       boolean         If TRUE, form-fields will be wrapped around the table.
1564          * @return      string          HTML table with the selector box (name: displayFields['.$table.'][])
1565          */
1566         function fieldSelectBox($table,$formFields=1)   {
1567
1568                         // Init:
1569                 t3lib_div::loadTCA($table);
1570                 $formElements=array('','');
1571                 if ($formFields)        {
1572                         $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>');
1573                 }
1574
1575                         // Load already selected fields, if any:
1576                 $setFields=is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
1577
1578                         // Request fields from table:
1579                 $fields = $this->makeFieldList($table, FALSE, TRUE);
1580
1581                         // Add pseudo "control" fields
1582                 $fields[]='_PATH_';
1583                 $fields[]='_REF_';
1584                 $fields[]='_LOCALIZATION_';
1585                 $fields[]='_CONTROL_';
1586                 $fields[]='_CLIPBOARD_';
1587
1588                         // Create an option for each field:
1589                 $opt=array();
1590                 $opt[] = '<option value=""></option>';
1591                 foreach($fields as $fN) {
1592                                 // Field label
1593                         $fL = (is_array($GLOBALS['TCA'][$table]['columns'][$fN])
1594                                 ? rtrim($GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label']), ':')
1595                                 : '[' . $fN . ']');
1596                         $opt[] = '
1597                                                                                         <option value="'.$fN.'"'.(in_array($fN,$setFields)?' selected="selected"':'').'>'.htmlspecialchars($fL).'</option>';
1598                 }
1599
1600                         // Compile the options into a multiple selector box:
1601                 $lMenu = '
1602                                                                                 <select size="'.t3lib_utility_Math::forceIntegerInRange(count($fields)+1,3,20).'" multiple="multiple" name="displayFields['.$table.'][]">'.implode('',$opt).'
1603                                                                                 </select>
1604                                 ';
1605
1606                         // Table with the field selector::
1607                 $content = $formElements[0] . '
1608
1609                                 <!--
1610                                         Field selector for extended table view:
1611                                 -->
1612                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-dblist-fieldSelect">
1613                                         <tr>
1614                                                 <td>'.$lMenu.'</td>
1615                                                 <td><input type="submit" name="search" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.setFields', 1) . '" /></td>
1616                                         </tr>
1617                                 </table>
1618                         ' . $formElements[1];
1619
1620                 return '<div class="db_list-fieldSelect">' . $content . '</div>';
1621         }
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633         /*********************************
1634          *
1635          * Helper functions
1636          *
1637          *********************************/
1638
1639         /**
1640          * Creates a link around $string. The link contains an onclick action which submits the script with some clipboard action.
1641          * Currently, this is used for setting elements / delete elements.
1642          *
1643          * @param       string          The HTML content to link (image/text)
1644          * @param       string          Table name
1645          * @param       string          Clipboard command (eg. "setCB" or "delete")
1646          * @param       string          Warning text, if any ("delete" uses this for confirmation)
1647          * @return      string          <a> tag wrapped link.
1648          */
1649         function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')       {
1650                 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.cmd_table.value=\''.$table.'\';document.dblistForm.submit();';
1651                 if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
1652                 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent.'return false;').'">'.$string.'</a>';
1653         }
1654
1655         /**
1656          * Returns TRUE if a numeric clipboard pad is selected/active
1657          *
1658          * @return      boolean
1659          */
1660         function clipNumPane()  {
1661                 return in_Array('_CLIPBOARD_',$this->fieldArray) && $this->clipObj->current!='normal';
1662         }
1663
1664         /**
1665          * Creates a sort-by link on the input string ($code).
1666          * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
1667          * Also some fields will not be possible to sort (including if single-table-view is disabled).
1668          *
1669          * @param       string          The string to link (text)
1670          * @param       string          The fieldname represented by the title ($code)
1671          * @param       string          Table name
1672          * @return      string          Linked $code variable
1673          */
1674         function addSortLink($code,$field,$table)       {
1675
1676                         // Certain circumstances just return string right away (no links):
1677                 if ($field=='_CONTROL_' || $field=='_LOCALIZATION_' || $field=='_CLIPBOARD_' || $field=='_REF_' || $this->disableSingleTableView)       return $code;
1678
1679                         // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
1680                 if ($field=='_PATH_')   $field=pid;
1681
1682                         //       Create the sort link:
1683                 $sortUrl = $this->listURL('', -1, 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || ($this->sortField != $field) ? 0 : 1);
1684                 $sortArrow = ($this->sortField==$field?'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/red'.($this->sortRev?'up':'down').'.gif','width="7" height="4"').' alt="" />':'');
1685
1686                         // Return linked field:
1687                 return '<a href="'.htmlspecialchars($sortUrl).'">'.$code.
1688                                 $sortArrow.
1689                                 '</a>';
1690         }
1691
1692         /**
1693          * Returns the path for a certain pid
1694          * The result is cached internally for the session, thus you can call this function as much as you like without performance problems.
1695          *
1696          * @param       integer         The page id for which to get the path
1697          * @return      string          The path.
1698          */
1699         function recPath($pid)  {
1700                 if (!isset($this->recPath_cache[$pid])) {
1701                         $this->recPath_cache[$pid] = t3lib_BEfunc::getRecordPath($pid,$this->perms_clause,20);
1702                 }
1703                 return $this->recPath_cache[$pid];
1704         }
1705
1706         /**
1707          * Returns TRUE if a link for creating new records should be displayed for $table
1708          *
1709          * @param       string          Table name
1710          * @return      boolean         Returns TRUE if a link for creating new records should be displayed for $table
1711          * @see         SC_db_new::showNewRecLink
1712          */
1713         function showNewRecLink($table) {
1714                         // No deny/allow tables are set:
1715                 if (!count($this->allowedNewTables) && !count($this->deniedNewTables)) {
1716                         return TRUE;
1717                         // If table is not denied (which takes precedence over allowed tables):
1718                 } elseif (!in_array($table, $this->deniedNewTables) && (!count($this->allowedNewTables) || in_array($table, $this->allowedNewTables))) {
1719                         return TRUE;
1720                         // If table is denied or allowed tables are set, but table is not part of:
1721                 } else {
1722                         return FALSE;
1723                 }
1724         }
1725
1726         /**
1727          * Creates the "&returnUrl" parameter for links - this is used when the script links to other scripts and passes its own URL with the link so other scripts can return to the listing again.
1728          * Uses REQUEST_URI as value.
1729          *
1730          * @return      string
1731          */
1732         function makeReturnUrl()        {
1733                 return '&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
1734         }
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746         /************************************
1747          *
1748          * CSV related functions
1749          *
1750          ************************************/
1751
1752         /**
1753          * Initializes internal csvLines array with the header of field names
1754          *
1755          * @return      void
1756          */
1757         protected function initCSV() {
1758                 $this->addHeaderRowToCSV();
1759         }
1760
1761         /**
1762          * Add header line with field names as CSV line
1763          *
1764          * @return void
1765          */
1766         protected function addHeaderRowToCSV() {
1767                         // Add header row, control fields will be reduced inside addToCSV()
1768                 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
1769         }
1770
1771         /**
1772          * Adds selected columns of one table row as CSV line.
1773          *
1774          * @param       array           Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
1775          * @return      void
1776          */
1777         protected function addToCSV(array $row = array()) {
1778                 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
1779                 $rowReducedToSelectedColumns = array_intersect_key($rowReducedByControlFields, array_flip($this->fieldArray));
1780                 $this->setCsvRow($rowReducedToSelectedColumns);
1781         }
1782
1783         /**
1784          * Remove control fields from row for CSV export
1785          *
1786          * @param array fieldNames => fieldValues
1787          * @return array Input array reduces by control fields
1788          */
1789         protected static function removeControlFieldsFromFieldRow(array $row = array()) {
1790                         // Possible control fields in a list row
1791                 $controlFields = array(
1792                         '_PATH_',
1793                         '_REF_',
1794                         '_CONTROL_',
1795                         '_AFTERCONTROL_',
1796                         '_AFTERREF_',
1797                         '_CLIPBOARD_',
1798                         '_LOCALIZATION_',
1799                         '_LOCALIZATION_b',
1800                 );
1801                 return array_diff_key($row, array_flip($controlFields));
1802         }
1803
1804
1805         /**
1806          * Adds input row of values to the internal csvLines array as a CSV formatted line
1807          *
1808          * @param       array           Array with values to be listed.
1809          * @return      void
1810          */
1811         function setCsvRow($csvRow)     {
1812                 $this->csvLines[] = t3lib_div::csvValues($csvRow);
1813         }
1814
1815         /**
1816          * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
1817          * This function exits!
1818          *
1819          * @param       string          Filename prefix:
1820          * @return      void            EXITS php execusion!
1821          */
1822         function outputCSV($prefix)     {
1823
1824                         // Setting filename:
1825                 $filename=$prefix.'_'.date('dmy-Hi').'.csv';
1826
1827                         // Creating output header:
1828                 $mimeType = 'application/octet-stream';
1829                 Header('Content-Type: '.$mimeType);
1830                 Header('Content-Disposition: attachment; filename='.$filename);
1831
1832                         // Printing the content of the CSV lines:
1833                 echo implode(chr(13).chr(10),$this->csvLines);
1834
1835                         // Exits:
1836                 exit;
1837         }
1838 }
1839
1840
1841
1842 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc'])) {
1843         include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc']);
1844 }
1845
1846 ?>