Bug #8422: Context Sensitive Help mode with "display full text messages"
[Packages/TYPO3.CMS.git] / typo3 / class.db_list_extra.inc
1 <?php
2 /*************************************************************
3 *  Copyright notice
4 *
5 *  (c) 1999-2008 Kasper Skaarhoj (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  * $Id$
32  * Revised for TYPO3 3.6 December/2003 by Kasper Skaarhoj
33  * XHTML compliant
34  *
35  * @author      Kasper Skaarhoj <kasperYYYY@typo3.com>
36  */
37 /**
38  * [CLASS/FUNCTION INDEX of SCRIPT]
39  *
40  *
41  *
42  *   91: class localRecordList extends recordList
43  *  123:     function writeTop($row)
44  *  304:     function getTable($table,$id,$rowlist)
45  *  559:     function renderListRow($table,$row,$cc,$titleCol,$thumbsCol,$indent=0)
46  *  648:     function renderListHeader($table,$currentIdList)
47  *
48  *              SECTION: Rendering of various elements
49  *  796:     function makeControl($table,$row)
50  *  986:     function makeClip($table,$row)
51  * 1057:     function makeRef($table,$uid)
52  * 1086:     function makeLocalizationPanel($table,$row)
53  * 1148:     function fieldSelectBox($table,$formFields=1)
54  *
55  *              SECTION: Helper functions
56  * 1231:     function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')
57  * 1242:     function clipNumPane()
58  * 1256:     function addSortLink($code,$field,$table)
59  * 1281:     function recPath($pid)
60  * 1294:     function showNewRecLink($table)
61  * 1304:     function makeReturnUrl()
62  *
63  *              SECTION: CSV related functions
64  * 1329:     function initCSV()
65  * 1352:     function addToCSV($row,$table)
66  * 1376:     function setCsvRow($csvRow)
67  * 1387:     function outputCSV($prefix)
68  *
69  * TOTAL FUNCTIONS: 19
70  * (This index is automatically created/updated by the extension "extdeveval")
71  *
72  */
73
74
75
76
77
78
79
80
81
82
83 /**
84  * Class for rendering of Web>List module
85  *
86  * @author      Kasper Skaarhoj <kasperYYYY@typo3.com>
87  * @package TYPO3
88  * @subpackage core
89  */
90 class localRecordList extends recordList {
91
92                 // External:
93         var $alternateBgColors=FALSE;                   // If true, table rows in the list will alternate in background colors (and have background colors at all!)
94         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.
95         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.
96         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!).
97
98         var $dontShowClipControlPanels=FALSE;   // If true, will disable the rendering of clipboard + control panels.
99         var $showClipboard=FALSE;                               // If true, will show the clipboard in the field list.
100         var $noControlPanels = FALSE;                   // If true, will DISABLE all control panels in lists. (Takes precedence)
101         var $clickMenuEnabled = TRUE;                   // If true, clickmenus will be rendered
102
103         var $totalRowCount;                                             // count of record rows in view
104
105         var $spaceIcon;                                                 // space icon used for alignment
106
107                 // Internal:
108         var $pageRow=array();                                   // Set to the page record (see writeTop())
109
110         var $csvLines=array();                                  // Used to accumulate CSV lines in for CSV export.
111         var $csvOutput=FALSE;                                   // If set, the listing is returned as CSV instead.
112
113         /**
114          * Clipboard object
115          *
116          * @var t3lib_clipboard
117          */
118         var $clipObj;
119         var $CBnames=array();                                   // Tracking names of elements (for clipboard use)
120         var $duplicateStack=array();                    // Used to track which elements has duplicates and how many
121
122         /**
123          * Create the panel of buttons for submitting the form or otherwise perform operations.
124          *
125          * @return      array   all available buttons as an assoc. array
126          */
127         public function getButtons()    {
128                 global $LANG;
129
130                 $buttons = array(
131                         'csh' => '',
132                         'view' => '',
133                         'edit' => '',
134                         'hide_unhide' => '',
135                         'move' => '',
136                         'new_record' => '',
137                         'paste' => '',
138                         'level_up' => '',
139                         'cache' => '',
140                         'reload' => '',
141                         'shortcut' => '',
142                         'back' => '',
143                         'csv' => '',
144                         'export' => ''
145                 );
146
147                         // Get users permissions for this page record:
148                 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageRow);
149
150                         // CSH
151                 if (!strlen($this->id)) {
152                         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_noId', $GLOBALS['BACK_PATH'], '', TRUE);
153                 } elseif(!$this->id) {
154                         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module_root', $GLOBALS['BACK_PATH'], '', TRUE);
155                 } else {
156                         $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_module', $GLOBALS['BACK_PATH'], '', TRUE);
157                 }
158
159                 if (isset($this->id)) {
160                                 // View
161                         $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick($this->id, $this->backPath, t3lib_BEfunc::BEgetRootLine($this->id))) . '">' .
162                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/zoom.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '" alt="" />' .
163                                                         '</a>';
164
165                                 // New record
166                         if (!$GLOBALS['SOBE']->modTSconfig['properties']['noCreateRecordsLink']) {
167                                 $buttons['new_record'] = '<a href="#" onclick="' . htmlspecialchars('return jumpExt(\'' . $this->backPath . 'db_new.php?id=' . $this->id . '\');') . '">' .
168                                                                 '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/new_el.gif') . ' title="' . $LANG->getLL('newRecordGeneral', 1) . '" alt="" />' .
169                                                                 '</a>';
170                         }
171
172                                 // If edit permissions are set (see class.t3lib_userauthgroup.php)
173                         if ($localCalcPerms&2 && !empty($this->id))     {
174
175                                         // Edit
176                                 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
177                                 $buttons['edit'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::editOnClick($params, $this->backPath, -1)) . '">' .
178                                                                 '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/edit2.gif') . ' title="' . $LANG->getLL('editPage', 1) . '" alt="" />' .
179                                                                 '</a>';
180                                         // Unhide
181                                 if ($this->pageRow['hidden'])   {
182                                         $params = '&data[pages][' . $this->pageRow['uid'] . '][hidden]=0';
183                                         $buttons['hide_unhide'] = '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '">' .
184                                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/button_unhide.gif') . ' title="' . $LANG->getLL('unHidePage', 1) . '" alt="" />' .
185                                                                         '</a>';
186                                         // Hide
187                                 } else {
188                                         $params = '&data[pages][' . $this->pageRow['uid'] . '][hidden]=1';
189                                         $buttons['hide_unhide'] = '<a href="#" onclick="' . htmlspecialchars('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');') . '">'.
190                                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/button_hide.gif') . ' title="' . $LANG->getLL('hidePage', 1) . '" alt="" />' .
191                                                                         '</a>';
192                                 }
193
194                                         // Move
195                                 $buttons['move'] = '<a href="#" onclick="' . htmlspecialchars('return jumpExt(\'' . $this->backPath . 'move_el.php?table=pages&uid=' . $this->pageRow['uid'] . '\');') . '">' .
196                                                                 '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/move_' . ($this->table == 'tt_content' ? 'record' : 'page') . '.gif') . ' title="' . $LANG->getLL('move_page', 1) . '" alt="" />' .
197                                                                 '</a>';
198
199                                         // Up one level
200                                 $buttons['level_up'] = '<a href="' . htmlspecialchars($this->listURL($this->pageRow['pid'])) . '" onclick="setHighlight(' . $this->pageRow['pid'] . ')">' .
201                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/i/pages_up.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel', 1) . '" alt="" />' .
202                                                         '</a>';
203
204                         }
205
206
207                                 // Paste
208                         if (($localCalcPerms&8) || ($localCalcPerms&16)) {
209                                 $elFromTable = $this->clipObj->elFromTable('');
210                                 if (count($elFromTable)) {
211                                         $buttons['paste'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('', $this->id)) . '" onclick="' . htmlspecialchars('return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into', $elFromTable)) . '">' .
212                                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/clip_pasteafter.gif') . ' title="' . $LANG->getLL('clip_paste', 1) . '" alt="" />' .
213                                                                         '</a>';
214                                 }
215                         }
216
217                                 // Cache
218                         $buttons['cache'] = '<a href="' . htmlspecialchars($this->listURL() . '&clear_cache=1') . '">' .
219                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/clear_cache.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.clear_cache', 1) . '" alt="" />' .
220                                                         '</a>';
221
222                         if ($this->table) {
223
224                                         // CSV
225                                 $buttons['csv'] = '<a href="' . htmlspecialchars($this->listURL() . '&csv=1') . '">' .
226                                                                 '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/csv.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.csv', 1) . '" alt="" />' .
227                                                                 '</a>';
228
229                                         // Export
230                                 if (t3lib_extMgm::isLoaded('impexp')) {
231                                         $buttons['export'] = '<a href="' . htmlspecialchars($this->backPath. 'mod.php?M=xMOD_tximpexp&tx_impexp[action]=export&tx_impexp[list][]=' . rawurlencode($this->table . ':' . $this->id)) . '">' .
232                                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, t3lib_extMgm::extRelPath('impexp') . 'export.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.export', 1) . '" alt="" />' .
233                                                                         '</a>';
234                                 }
235
236                         }
237
238                                 // Reload
239                         $buttons['reload'] = '<a href="' . htmlspecialchars($this->listURL()) . '">' .
240                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/refresh_n.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.reload', 1) . '" alt="" />' .
241                                                         '</a>';
242
243                                 // Shortcut
244                         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
245                                 $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');
246                         }
247
248                                 // Back
249                         if ($this->returnUrl) {
250                                 $buttons['back'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisUrl($this->returnUrl, array('id' => $this->id))) . '" class="typo3-goBack">' .
251                                                                 '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/goback.gif') . ' title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.goBack', 1) . '" alt="" />' .
252                                                                 '</a>';
253                         }
254                 }
255
256                 return $buttons;
257         }
258
259         /**
260          * Creates the listing of records from a single table
261          *
262          * @param       string          Table name
263          * @param       integer         Page id
264          * @param       string          List of fields to show in the listing. Pseudo fields will be added including the record header.
265          * @return      string          HTML table with the listing for the record.
266          */
267         function getTable($table,$id,$rowlist)  {
268                 global $TCA, $TYPO3_CONF_VARS;
269
270                         // Loading all TCA details for this table:
271                 t3lib_div::loadTCA($table);
272
273                         // Init
274                 $addWhere = '';
275                 $titleCol = $TCA[$table]['ctrl']['label'];
276                 $thumbsCol = $TCA[$table]['ctrl']['thumbnail'];
277                 $l10nEnabled = $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'] && !$TCA[$table]['ctrl']['transOrigPointerTable'];
278
279                         // prepare space icon
280                 $iconWidth  = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeWidth']  ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeWidth']  : 12;
281                 $iconHeight = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeHeight'] ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['iconSizeHeight'] : 12;
282                 $this->spaceIcon = '<img src="' . $this->backPath . 'clear.gif" width="' . $iconWidth . '" height="' . $iconHeight . '" title="" alt="" />';
283
284                         // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
285                 $this->fieldArray=array();
286                         // title Column
287                 $this->fieldArray[] = $titleCol;        // Add title column
288                         // Control-Panel
289                 if (!t3lib_div::inList($rowlist,'_CONTROL_'))   {
290                         $this->fieldArray[] = '_CONTROL_';
291                         $this->fieldArray[] = '_AFTERCONTROL_';
292                 }
293                         // Clipboard
294                 if ($this->showClipboard)       {
295                         $this->fieldArray[] = '_CLIPBOARD_';
296                 }
297                         // Ref
298                 if (!$this->dontShowClipControlPanels)  {
299                         $this->fieldArray[]='_REF_';
300                         $this->fieldArray[]='_AFTERREF_';
301                 }
302                         // Path
303                 if ($this->searchLevels)        {
304                         $this->fieldArray[]='_PATH_';
305                 }
306                         // Localization
307                 if ($this->localizationView && $l10nEnabled)    {
308                         $this->fieldArray[] = '_LOCALIZATION_';
309                         $this->fieldArray[] = '_LOCALIZATION_b';
310                         $addWhere.=' AND (
311                                 '.$TCA[$table]['ctrl']['languageField'].'<=0
312                                 OR
313                                 '.$TCA[$table]['ctrl']['transOrigPointerField'].' = 0
314                         )';
315                 }
316                         // Cleaning up:
317                 $this->fieldArray=array_unique(array_merge($this->fieldArray,t3lib_div::trimExplode(',',$rowlist,1)));
318                 if ($this->noControlPanels)     {
319                         $tempArray = array_flip($this->fieldArray);
320                         unset($tempArray['_CONTROL_']);
321                         unset($tempArray['_CLIPBOARD_']);
322                         $this->fieldArray = array_keys($tempArray);
323                 }
324
325                         // Creating the list of fields to include in the SQL query:
326                 $selectFields = $this->fieldArray;
327                 $selectFields[] = 'uid';
328                 $selectFields[] = 'pid';
329                 if ($thumbsCol) $selectFields[] = $thumbsCol;   // adding column for thumbnails
330                 if ($table=='pages')    {
331                         if (t3lib_extMgm::isLoaded('cms'))      {
332                                 $selectFields[] = 'module';
333                                 $selectFields[] = 'extendToSubpages';
334                                 $selectFields[] = 'nav_hide';
335                         }
336                         $selectFields[] = 'doktype';
337                 }
338                 if (is_array($TCA[$table]['ctrl']['enablecolumns']))    {
339                         $selectFields = array_merge($selectFields,$TCA[$table]['ctrl']['enablecolumns']);
340                 }
341                 if ($TCA[$table]['ctrl']['type'])       {
342                         $selectFields[] = $TCA[$table]['ctrl']['type'];
343                 }
344                 if ($TCA[$table]['ctrl']['typeicon_column'])    {
345                         $selectFields[] = $TCA[$table]['ctrl']['typeicon_column'];
346                 }
347                 if ($TCA[$table]['ctrl']['versioningWS'])       {
348                         $selectFields[] = 't3ver_id';
349                         $selectFields[] = 't3ver_state';
350                         $selectFields[] = 't3ver_wsid';
351                         $selectFields[] = 't3ver_swapmode';             // Filtered out when pages in makeFieldList()
352                 }
353                 if ($l10nEnabled)       {
354                         $selectFields[] = $TCA[$table]['ctrl']['languageField'];
355                         $selectFields[] = $TCA[$table]['ctrl']['transOrigPointerField'];
356                 }
357                 if ($TCA[$table]['ctrl']['label_alt'])  {
358                         $selectFields = array_merge($selectFields,t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1));
359                 }
360                 $selectFields = array_unique($selectFields);            // Unique list!
361                 $selectFields = array_intersect($selectFields,$this->makeFieldList($table,1));          // Making sure that the fields in the field-list ARE in the field-list from TCA!
362                 $selFieldList = implode(',',$selectFields);             // implode it into a list of fields for the SQL-statement.
363
364                 /**
365                  * @hook                        DB-List getTable
366                  * @date                        2007-11-16
367                  * @request             Malte Jansen  <mail@maltejansen.de>
368                  */
369                 if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'])) {
370                         foreach($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'] as $classData) {
371                                 $hookObject = &t3lib_div::getUserObj($classData);
372
373                                 if(!($hookObject instanceof t3lib_localRecordListGetTableHook)) {
374                                         throw new UnexpectedValueException('$hookObject must implement interface t3lib_localRecordListGetTableHook', 1195114460);
375                                 }
376
377                                 $hookObject->getDBlistQuery($table, $id, $addWhere, $selFieldList, $this);
378                         }
379                 }
380
381                         // Create the SQL query for selecting the elements in the listing:
382                 if ($this->csvOutput) { // do not do paging when outputting as CSV
383                         $this->iLimit = 0;
384                 }
385
386                 $queryParts = $this->makeQueryArray($table, $id,$addWhere,$selFieldList);       // (API function from class.db_list.inc)
387                 $this->setTotalItems($queryParts);              // Finding the total amount of records on the page (API function from class.db_list.inc)
388
389                         // Init:
390                 $dbCount = 0;
391                 $out = '';
392
393                         // If the count query returned any number of records, we perform the real query, selecting records.
394                 if ($this->totalItems)  {
395                                 // set the showLimit to the number of records when outputting as CSV
396                         if ($this->csvOutput) {
397                                 $this->showLimit = $this->totalItems;
398                                 $this->iLimit = $this->totalItems;
399                         }
400                         $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
401                         $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
402                 }
403
404                 $LOISmode = $this->listOnlyInSingleTableMode && !$this->table;
405
406                         // If any records was selected, render the list:
407                 if ($dbCount)   {
408
409                                 // Half line is drawn between tables:
410                         if (!$LOISmode) {
411                                 $theData = Array();
412                                 if (!$this->table && !$rowlist) {
413                                         $theData[$titleCol] = '<img src="clear.gif" width="'.($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel']?'230':'350').'" height="1" alt="" />';
414                                         if (in_array('_CONTROL_',$this->fieldArray))    $theData['_CONTROL_']='';
415                                         if (in_array('_CLIPBOARD_',$this->fieldArray))  $theData['_CLIPBOARD_']='';
416                                 }
417                                 $out.=$this->addelement(0,'',$theData,'class="c-table-row-spacer"',$this->leftMargin);
418                         }
419
420                                 // Header line is drawn
421                         $theData = Array();
422                         if ($this->disableSingleTableView)      {
423                                 $theData[$titleCol] = '<span class="c-table">'.$GLOBALS['LANG']->sL($TCA[$table]['ctrl']['title'],1).'</span> ('.$this->totalItems.')';
424                         } else {
425                                 $theData[$titleCol] = $this->linkWrapTable($table,'<span class="c-table">'.$GLOBALS['LANG']->sL($TCA[$table]['ctrl']['title'],1).'</span> ('.$this->totalItems.') <img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/'.($this->table?'minus':'plus').'bullet_list.gif','width="18" height="12"').' hspace="10" class="absmiddle" title="'.$GLOBALS['LANG']->getLL(!$this->table?'expandView':'contractView',1).'" alt="" />');
426                         }
427
428                                 // CSH:
429                         $theData[$titleCol].= t3lib_BEfunc::cshItem($table,'',$this->backPath,'',FALSE,'margin-bottom:0px; white-space: normal;');
430
431                         if ($LOISmode)  {
432                                 $out.='
433                                         <tr>
434                                                 <td class="c-headLineTable" style="width:95%;">'.$theData[$titleCol].'</td>
435                                         </tr>';
436
437                                 if ($GLOBALS['BE_USER']->uc["edit_showFieldHelp"])      {
438                                         $GLOBALS['LANG']->loadSingleTableDescription($table);
439                                         if (isset($GLOBALS['TCA_DESCR'][$table]['columns']['']))        {
440                                                 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$table.'.\',\'viewFieldHelp\',\'height=400,width=600,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
441                                                 $out.='
442                                         <tr>
443                                                 <td class="c-tableDescription">'.t3lib_BEfunc::helpTextIcon($table,'',$this->backPath,TRUE).$GLOBALS['TCA_DESCR'][$table]['columns']['']['description'].'</td>
444                                         </tr>';
445                                         }
446                                 }
447                         } else {
448                                 $theUpIcon = ($table=='pages'&&$this->id&&isset($this->pageRow['pid'])) ? '<a href="'.htmlspecialchars($this->listURL($this->pageRow['pid'])).'" onclick="setHighlight('.$this->pageRow['pid'].')"><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/pages_up.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel',1).'" alt="" /></a>':'';
449                                 $out.=$this->addelement(1,$theUpIcon,$theData,' class="c-headLineTable"','');
450                         }
451
452                         If (!$LOISmode) {
453                                         // Fixing a order table for sortby tables
454                                 $this->currentTable = array();
455                                 $currentIdList = array();
456                                 $doSort = ($TCA[$table]['ctrl']['sortby'] && !$this->sortField);
457
458                                 $prevUid = 0;
459                                 $prevPrevUid = 0;
460                                 $accRows = array();     // Accumulate rows here
461                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))    {
462
463                                                 // In offline workspace, look for alternative record:
464                                         t3lib_BEfunc::workspaceOL($table, $row, $GLOBALS['BE_USER']->workspace, TRUE);
465
466                                         if (is_array($row))     {
467                                                 $accRows[] = $row;
468                                                 $currentIdList[] = $row['uid'];
469                                                 if ($doSort)    {
470                                                         if ($prevUid)   {
471                                                                 $this->currentTable['prev'][$row['uid']] = $prevPrevUid;
472                                                                 $this->currentTable['next'][$prevUid] = '-'.$row['uid'];
473                                                                 $this->currentTable['prevUid'][$row['uid']] = $prevUid;
474                                                         }
475                                                         $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
476                                                         $prevUid=$row['uid'];
477                                                 }
478                                         }
479                                 }
480                                 $GLOBALS['TYPO3_DB']->sql_free_result($result);
481
482                                 $this->totalRowCount = count($accRows);
483
484                                         // CSV initiated
485                                 if ($this->csvOutput) $this->initCSV();
486
487                                         // Render items:
488                                 $this->CBnames=array();
489                                 $this->duplicateStack=array();
490                                 $this->eCounter=$this->firstElementNumber;
491
492                                 $iOut = '';
493                                 $cc = 0;
494                                 foreach($accRows as $row)       {
495
496                                                 // Forward/Backwards navigation links:
497                                         list($flag,$code) = $this->fwd_rwd_nav($table);
498                                         $iOut.=$code;
499
500                                                 // If render item, increment counter and call function
501                                         if ($flag)      {
502                                                 $cc++;
503                                                 $iOut.= $this->renderListRow($table,$row,$cc,$titleCol,$thumbsCol);
504
505                                                         // 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:
506                                                 if ($this->localizationView && $l10nEnabled)    {
507
508                                                                 // Look for translations of this record:
509                                                         $translations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
510                                                                 $selFieldList,
511                                                                 $table,
512                                                                 'pid='.$row['pid'].
513                                                                         ' AND '.$TCA[$table]['ctrl']['languageField'].'>0'.
514                                                                         ' AND '.$TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($row['uid']).
515                                                                         t3lib_BEfunc::deleteClause($table).
516                                                                         t3lib_BEfunc::versioningPlaceholderClause($table)
517                                                         );
518
519                                                                 // For each available translation, render the record:
520                                                         if (is_array($translations)) {
521                                                                 foreach($translations as $lRow) {
522                                                                                 // In offline workspace, look for alternative record:
523                                                                         t3lib_BEfunc::workspaceOL($table, $lRow, $GLOBALS['BE_USER']->workspace);
524
525                                                                         if (is_array($lRow) && $GLOBALS['BE_USER']->checkLanguageAccess($lRow[$TCA[$table]['ctrl']['languageField']]))  {
526                                                                                 $currentIdList[] = $lRow['uid'];
527                                                                                 $iOut.=$this->renderListRow($table,$lRow,$cc,$titleCol,$thumbsCol,18);
528                                                                         }
529                                                                 }
530                                                         }
531                                                 }
532                                         }
533
534                                                 // Counter of total rows incremented:
535                                         $this->eCounter++;
536                                 }
537
538                                         // The header row for the table is now created:
539                                 $out.=$this->renderListHeader($table,$currentIdList);
540                         }
541
542                                 // The list of records is added after the header:
543                         $out.=$iOut;
544
545                                 // ... and it is all wrapped in a table:
546                         $out='
547
548
549
550                         <!--
551                                 DB listing of elements: "'.htmlspecialchars($table).'"
552                         -->
553                                 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist'.($LOISmode?' typo3-dblist-overview':'').'">
554                                         '.$out.'
555                                 </table>';
556
557                                 // Output csv if...
558                         if ($this->csvOutput)   $this->outputCSV($table);       // This ends the page with exit.
559                 }
560
561                         // Return content:
562                 return $out;
563         }
564
565         /**
566          * Rendering a single row for the list
567          *
568          * @param       string          Table name
569          * @param       array           Current record
570          * @param       integer         Counter, counting for each time an element is rendered (used for alternating colors)
571          * @param       string          Table field (column) where header value is found
572          * @param       string          Table field (column) where (possible) thumbnails can be found
573          * @param       integer         Indent from left.
574          * @return      string          Table row for the element
575          * @access private
576          * @see getTable()
577          */
578         function renderListRow($table,$row,$cc,$titleCol,$thumbsCol,$indent=0)  {
579                 $iOut = '';
580
581                 if (strlen($this->searchString))        {       // If in search mode, make sure the preview will show the correct page
582                         $id_orig = $this->id;
583                         $this->id = $row['pid'];
584                 }
585
586                 if (is_array($row))     {
587
588                                 // add special classes for first and last row
589                         $rowSpecial = '';
590                         if ($cc == 1 && $indent == 0) {
591                                 $rowSpecial .= ' firstcol';
592                         }
593                         if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
594                                 $rowSpecial .= ' lastcol';
595                         }
596
597                                 // Background color, if any:
598                         if ($this->alternateBgColors) {
599                                 $row_bgColor = ($cc%2) ? ' class="db_list_normal'.$rowSpecial.'"' : ' class="db_list_alt'.$rowSpecial.'"';
600                         } else {
601                                 $row_bgColor = ' class="db_list_normal'.$rowSpecial.'"';
602                         }
603                                 // Overriding with versions background color if any:
604                         $row_bgColor = $row['_CSSCLASS'] ? ' class="'.$row['_CSSCLASS'].'"' : $row_bgColor;
605
606                                 // Incr. counter.
607                         $this->counter++;
608
609                                 // The icon with link
610                         $alttext = t3lib_BEfunc::getRecordIconAltText($row,$table);
611                         $iconImg = t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'title="'.htmlspecialchars($alttext).'"'.($indent ? ' style="margin-left: '.$indent.'px;"' : ''));
612                         $theIcon = $this->clickMenuEnabled ? $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,$table,$row['uid']) : $iconImg;
613
614                                 // Preparing and getting the data-array
615                         $theData = Array();
616                         foreach($this->fieldArray as $fCol)     {
617                                 if ($fCol==$titleCol)   {
618                                         $recTitle = t3lib_BEfunc::getRecordTitle($table,$row,FALSE,TRUE);
619                                                 // If the record is edit-locked by another user, we will show a little warning sign:
620                                         if (($lockInfo = t3lib_BEfunc::isRecordLocked($table, $row['uid']))) {
621                                                 $warning = '<a href="#" onclick="' . htmlspecialchars('alert(' . $GLOBALS['LANG']->JScharCode($lockInfo['msg']) . '); return false;') . '">' .
622                                                         '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/recordlock_warning3.gif', 'width="17" height="12"') . ' title="' . htmlspecialchars($lockInfo['msg']) . '" alt="" />' .
623                                                         '</a>';
624                                         }
625                                         $theData[$fCol] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
626                                 } elseif ($fCol == 'pid') {
627                                         $theData[$fCol]=$row[$fCol];
628                                 } elseif ($fCol == '_PATH_') {
629                                         $theData[$fCol]=$this->recPath($row['pid']);
630                                 } elseif ($fCol == '_REF_') {
631                                         $theData[$fCol]=$this->makeRef($table,$row['uid']);
632                                 } elseif ($fCol == '_CONTROL_') {
633                                         $theData[$fCol]=$this->makeControl($table,$row);
634                                 } elseif ($fCol == '_AFTERCONTROL_' || $fCol == '_AFTERREF_') {
635                                         $theData[$fCol] = '&nbsp;';
636                                 } elseif ($fCol == '_CLIPBOARD_') {
637                                         $theData[$fCol]=$this->makeClip($table,$row);
638                                 } elseif ($fCol == '_LOCALIZATION_') {
639                                         list($lC1, $lC2) = $this->makeLocalizationPanel($table,$row);
640                                         $theData[$fCol] = $lC1;
641                                         $theData[$fCol.'b'] = $lC2;
642                                 } elseif ($fCol == '_LOCALIZATION_b') {
643                                         // Do nothing, has been done above.
644                                 } else {
645                                         $tmpProc = t3lib_BEfunc::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid']);
646                                         $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
647                                         $row[$fCol] = $tmpProc;
648                                 }
649                         }
650
651                         if (strlen($this->searchString))        {       // Reset the ID if it was overwritten
652                                 $this->id = $id_orig;
653                         }
654
655                                 // Add row to CSV list:
656                         if ($this->csvOutput) {
657                                 $this->addToCSV($row,$table);
658                         }
659
660                         // Add classes to table cells
661                         $this->addElement_tdCssClass[$titleCol]         = 'col-title';
662                         if (!$this->dontShowClipControlPanels) {
663                                 $this->addElement_tdCssClass['_CONTROL_']       = 'col-control';
664                                 $this->addElement_tdCssClass['_AFTERCONTROL_']  = 'col-control-space';
665                                 $this->addElement_tdCssClass['_CLIPBOARD_']     = 'col-clipboard';
666                         }
667                         $this->addElement_tdCssClass['_PATH_']          = 'col-path';
668                         $this->addElement_tdCssClass['_LOCALIZATION_']  = 'col-localizationa';
669                         $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
670
671
672                                 // Create element in table cells:
673                         $iOut.=$this->addelement(1,$theIcon,$theData,$row_bgColor);
674
675                                 // Render thumbsnails if a thumbnail column exists and there is content in it:
676                         if ($this->thumbs && trim($row[$thumbsCol]))    {
677                                 $iOut.=$this->addelement(4,'', Array($titleCol=>$this->thumbCode($row,$table,$thumbsCol)),$row_bgColor);
678                         }
679
680                                 // Finally, return table row element:
681                         return $iOut;
682                 }
683         }
684
685         /**
686          * Rendering the header row for a table
687          *
688          * @param       string          Table name
689          * @param       array           Array of the currently displayed uids of the table
690          * @return      string          Header table row
691          * @access private
692          * @see getTable()
693          */
694         function renderListHeader($table, $currentIdList)       {
695                 global $TCA, $LANG, $TYPO3_CONF_VARS;
696
697                         // Init:
698                 $theData = Array();
699
700                         // Traverse the fields:
701                 foreach($this->fieldArray as $fCol)     {
702
703                                 // Calculate users permissions to edit records in the table:
704                         $permsEdit = $this->calcPerms & ($table=='pages'?2:16);
705
706                         switch((string)$fCol)   {
707                                 case '_PATH_':                  // Path
708                                         $theData[$fCol] = '<i>['.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels._PATH_',1).']</i>';
709                                 break;
710                                 case '_REF_':                   // References
711                                         $theData[$fCol] = '<i>['.$LANG->sL('LLL:EXT:lang/locallang_mod_file_list.xml:c__REF_',1).']</i>';
712                                 break;
713                                 case '_LOCALIZATION_':                  // Path
714                                         $theData[$fCol] = '<i>['.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels._LOCALIZATION_',1).']</i>';
715                                 break;
716                                 case '_LOCALIZATION_b':                 // Path
717                                         $theData[$fCol] = $LANG->getLL('Localize',1);
718                                 break;
719                                 case '_CLIPBOARD_':             // Clipboard:
720                                         $cells=array();
721
722                                                 // If there are elements on the clipboard for this table, then display the "paste into" icon:
723                                         $elFromTable = $this->clipObj->elFromTable($table);
724                                         if (count($elFromTable))        {
725                                                 $cells['pasteAfter']='<a href="'.htmlspecialchars($this->clipObj->pasteUrl($table,$this->id)).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg('pages',$this->pageRow,'into',$elFromTable)).'">'.
726                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_paste',1).'" alt="" />'.
727                                                                 '</a>';
728                                         }
729
730                                                 // If the numeric clipboard pads are enabled, display the control icons for that:
731                                         if ($this->clipObj->current!='normal')  {
732
733                                                         // The "select" link:
734                                                 $cells['copyMarked']=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_copy.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_selectMarked',1).'" alt="" />',$table,'setCB');
735
736                                                         // The "edit marked" link:
737                                                 $editIdList = implode(',',$currentIdList);
738                                                 $editIdList = "'+editList('".$table."','".$editIdList."')+'";
739                                                 $params='&edit['.$table.']['.$editIdList.']=edit&disHelp=1';
740                                                 $cells['edit']='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'">'.
741                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('clip_editMarked',1).'" alt="" />'.
742                                                                 '</a>';
743
744                                                         // The "Delete marked" link:
745                                                 $cells['delete']=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/garbage.gif','width="11" height="12"').' title="'.$LANG->getLL('clip_deleteMarked',1).'" alt="" />',$table,'delete',sprintf($LANG->getLL('clip_deleteMarkedWarning'),$LANG->sL($TCA[$table]['ctrl']['title'])));
746
747                                                         // The "Select all" link:
748                                                 $cells['markAll']='<a href="#" onclick="'.htmlspecialchars('checkOffCB(\''.implode(',',$this->CBnames).'\'); return false;').'">'.
749                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_select.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_markRecords',1).'" alt="" />'.
750                                                                 '</a>';
751                                         } else {
752                                                 $cells['empty']='';
753                                         }
754                                         /**
755                                          * @hook                        renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
756                                          * @date                        2007-11-20
757                                          * @request             Bernhard Kraft  <krafbt@kraftb.at>
758                                          * @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.
759                                          */
760                                         if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions']))        {
761                                                 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData)       {
762                                                         $hookObject = &t3lib_div::getUserObj($classData);
763                                                         if(!($hookObject instanceof localRecordList_actionsHook))       {
764                                                                 throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567850);
765                                                         }
766                                                         $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
767                                                 }
768                                         }
769                                         $theData[$fCol]=implode('',$cells);
770                                 break;
771                                 case '_CONTROL_':               // Control panel:
772                                         if (!$TCA[$table]['ctrl']['readOnly'])  {
773
774                                                         // If new records can be created on this page, add links:
775                                                 if ($this->calcPerms&($table=='pages'?8:16) && $this->showNewRecLink($table))   {
776                                                         if ($table=="tt_content" && $this->newWizards)  {
777                                                                         //  If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
778                                                                 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
779                                                                 $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
780                                                                 $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';
781
782                                                                 $icon = '<a href="#" onclick="'.htmlspecialchars('return jumpExt(\''.$newContentWizScriptPath.'?id='.$this->id.'\');').'">'.
783                                                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_'.($table=='pages'?'page':'el').'.gif','width="'.($table=='pages'?13:11).'" height="12"').' title="'.$LANG->getLL('new',1).'" alt="" />'.
784                                                                                                 '</a>';
785                                                         } elseif ($table=='pages' && $this->newWizards) {
786                                                                 $icon = '<a href="'.htmlspecialchars($this->backPath.'db_new.php?id='.$this->id.'&pagesOnly=1&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
787                                                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_'.($table=='pages'?'page':'el').'.gif','width="'.($table=='pages'?13:11).'" height="12"').' title="'.$LANG->getLL('new',1).'" alt="" />'.
788                                                                                                 '</a>';
789
790                                                         } else {
791                                                                 $params = '&edit['.$table.']['.$this->id.']=new';
792                                                                 $icon   = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'">'.
793                                                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_'.($table=='pages'?'page':'el').'.gif','width="'.($table=='pages'?13:11).'" height="12"').' title="'.$LANG->getLL('new',1).'" alt="" />'.
794                                                                                                 '</a>';
795                                                         }
796                                                 }
797
798                                                         // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
799                                                 if ($permsEdit && $this->table && is_array($currentIdList))     {
800                                                         $editIdList = implode(',',$currentIdList);
801                                                         if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
802                                                         $params = '&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.implode(',',$this->fieldArray).'&disHelp=1';
803                                                         $icon  .= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'">'.
804                                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('editShownColumns',1).'" alt="" />'.
805                                                                                         '</a>';
806                                                 }
807                                                         // add an empty entry, so column count fits again after moving this into $icon
808                                                 $theData[$fCol] = '&nbsp;';
809                                         }
810                                 break;
811                                 case '_AFTERCONTROL_':  // space column
812                                 case '_AFTERREF_':      // space column
813                                         $theData[$fCol] = '&nbsp;';
814                                 break;
815                                 default:                        // Regular fields header:
816                                         $theData[$fCol]='';
817                                         if ($this->table && is_array($currentIdList))   {
818
819                                                         // If the numeric clipboard pads are selected, show duplicate sorting link:
820                                                 if ($this->clipNumPane()) {
821                                                         $theData[$fCol].='<a href="'.htmlspecialchars($this->listURL('',-1).'&duplicateField='.$fCol).'">'.
822                                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/select_duplicates.gif','width="11" height="11"').' title="'.$LANG->getLL('clip_duplicates',1).'" alt="" />'.
823                                                                                         '</a>';
824                                                 }
825
826                                                         // If the table can be edited, add link for editing THIS field for all listed records:
827                                                 if (!$TCA[$table]['ctrl']['readOnly'] && $permsEdit && $TCA[$table]['columns'][$fCol])  {
828                                                         $editIdList = implode(',',$currentIdList);
829                                                         if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
830                                                         $params='&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.$fCol.'&disHelp=1';
831                                                         $iTitle = sprintf($LANG->getLL('editThisColumn'),ereg_replace(':$','',trim($LANG->sL(t3lib_BEfunc::getItemLabel($table,$fCol)))));
832                                                         $theData[$fCol].='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'">'.
833                                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.htmlspecialchars($iTitle).'" alt="" />'.
834                                                                                         '</a>';
835                                                 }
836                                         }
837                                         $theData[$fCol].=$this->addSortLink($LANG->sL(t3lib_BEfunc::getItemLabel($table,$fCol,'<i>[|]</i>')),$fCol,$table);
838                                 break;
839                         }
840
841                 }
842
843                 /**
844                  * @hook                        renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
845                  * @date                        2007-11-20
846                  * @request             Bernhard Kraft  <krafbt@kraftb.at>
847                  * @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.
848                  */
849                 if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions']))        {
850                         foreach($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData)       {
851                                 $hookObject = &t3lib_div::getUserObj($classData);
852                                 if(!($hookObject instanceof localRecordList_actionsHook))       {
853                                         throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567855);
854                                 }
855                                 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
856                         }
857                 }
858
859                         // Create and return header table row:
860                 return $this->addelement(1, $icon, $theData, ' class="c-headLine"', '');
861         }
862
863
864
865
866
867
868         /*********************************
869          *
870          * Rendering of various elements
871          *
872          *********************************/
873
874         /**
875          * Creates the control panel for a single record in the listing.
876          *
877          * @param       string          The table
878          * @param       array           The record for which to make the control panel.
879          * @return      string          HTML table with the control panel (unless disabled)
880          */
881         function makeControl($table,$row)       {
882                 global $TCA, $LANG, $SOBE, $TYPO3_CONF_VARS;
883
884                 if ($this->dontShowClipControlPanels)   return '';
885
886                         // Initialize:
887                 t3lib_div::loadTCA($table);
888                 $cells=array();
889
890                         // If the listed table is 'pages' we have to request the permission settings for each page:
891                 if ($table=='pages')    {
892                         $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid']));
893                 }
894
895                         // This expresses the edit permissions for this particular element:
896                 $permsEdit = ($table=='pages' && ($localCalcPerms&2)) || ($table!='pages' && ($this->calcPerms&16));
897
898                         // "Show" link (only pages and tt_content elements)
899                 if ($table=='pages' || $table=='tt_content')    {
900                         $params='&edit['.$table.']['.$row['uid'].']=edit';
901                         $cells['view']='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($table=='tt_content'?$this->id.'#'.$row['uid']:$row['uid'], $this->backPath)).'">'.
902                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/zoom.gif','width="12" height="12"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPage',1).'" alt="" />'.
903                                         '</a>';
904                 } elseif(!$this->table) {
905                         $cells['view'] = $this->spaceIcon;
906                 }
907
908                         // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
909                 if ($permsEdit) {
910                         $params='&edit['.$table.']['.$row['uid'].']=edit';
911                         $cells['edit']='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'">'.
912                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2'.(!$TCA[$table]['ctrl']['readOnly']?'':'_d').'.gif','width="11" height="12"').' title="'.$LANG->getLL('edit',1).'" alt="" />'.
913                                         '</a>';
914                 } elseif(!$this->table) {
915                         $cells['edit'] = $this->spaceIcon;
916                 }
917
918                         // "Move" wizard link for pages/tt_content elements:
919                 if (($table=="tt_content" && $permsEdit) || ($table=='pages'))  {
920                         $cells['move']='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\''.$this->backPath.'move_el.php?table='.$table.'&uid='.$row['uid'].'\');').'">'.
921                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/move_'.($table=='tt_content'?'record':'page').'.gif','width="11" height="12"').' title="'.$LANG->getLL('move_'.($table=='tt_content'?'record':'page'),1).'" alt="" />'.
922                                         '</a>';
923                 } elseif(!$this->table) {
924                         $cells['move'] = $this->spaceIcon;
925                 }
926
927                         // If the extended control panel is enabled OR if we are seeing a single table:
928                 if ($SOBE->MOD_SETTINGS['bigControlPanel'] || $this->table)     {
929
930                                 // "Info": (All records)
931                         $cells['viewBig']='<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'">'.
932                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/zoom2.gif','width="12" height="12"').' title="'.$LANG->getLL('showInfo',1).'" alt="" />'.
933                                         '</a>';
934
935                                 // If the table is NOT a read-only table, then show these links:
936                         if (!$TCA[$table]['ctrl']['readOnly'])  {
937
938                                         // "Revert" link (history/undo)
939                                 $cells['history']='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\''.$this->backPath.'show_rechis.php?element='.rawurlencode($table.':'.$row['uid']).'\',\'#latest\');').'">'.
940                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/history2.gif','width="13" height="12"').' title="'.$LANG->getLL('history',1).'" alt="" />'.
941                                                 '</a>';
942
943                                         // Versioning:
944                                 if (t3lib_extMgm::isLoaded('version'))  {
945                                         $vers = t3lib_BEfunc::selectVersionsOfRecord($table, $row['uid'], 'uid', $GLOBALS['BE_USER']->workspace);
946                                         if (is_array($vers))    {       // If table can be versionized.
947                                                 if (count($vers)>1)     {
948                                                         $st = 'background-color: #FFFF00; font-weight: bold;';
949                                                         $lab = count($vers)-1;
950                                                 } else {
951                                                         $st = 'background-color: #9999cc; font-weight: bold;';
952                                                         $lab = 'V';
953                                                 }
954
955                                                 $cells['version']='<a href="'.htmlspecialchars($this->backPath.t3lib_extMgm::extRelPath('version')).'cm1/index.php?table='.rawurlencode($table).'&uid='.rawurlencode($row['uid']).'" title="'.$LANG->getLL('displayVersions',1).'" class="typo3-ctrl-versioning" style="'.htmlspecialchars($st).'">'.
956                                                                 $lab.
957                                                                 '</a>';
958                                         } elseif(!$this->table) {
959                                                 $cells['version'] = '<span class="typo3-ctrl-versioning" style="font-weight: bold; visibility: hidden;">V</span>';
960                                         }
961                                 }
962
963                                         // "Edit Perms" link:
964                                 if ($table=='pages' && $GLOBALS['BE_USER']->check('modules','web_perm'))        {
965                                         $cells['perms']='<a href="'.htmlspecialchars('mod/web/perm/index.php?id='.$row['uid'].'&return_id='.$row['uid'].'&edit=1').'">'.
966                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/perm.gif','width="7" height="12"').' title="'.$LANG->getLL('permissions',1).'" alt="" />'.
967                                                         '</a>';
968                                 } elseif(!$this->table && $GLOBALS['BE_USER']->check('modules','web_perm')) {
969                                         $cells['perms'] = $this->spaceIcon;
970                                 }
971
972                                         // "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):
973                                 if ($TCA[$table]['ctrl']['sortby'] || $TCA[$table]['ctrl']['useColumnsForDefaultValues'])       {
974                                         if (
975                                                 ($table!='pages' && ($this->calcPerms&16)) ||   // For NON-pages, must have permission to edit content on this parent page
976                                                 ($table=='pages' && ($this->calcPerms&8))               // For pages, must have permission to create new pages here.
977                                                 )       {
978                                                 if ($this->showNewRecLink($table))      {
979                                                         $params='&edit['.$table.']['.(-($row['_MOVE_PLH']?$row['_MOVE_PLH_uid']:$row['uid'])).']=new';
980                                                         $cells['new']='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'">'.
981                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_'.($table=='pages'?'page':'el').'.gif','width="'.($table=='pages'?13:11).'" height="12"').' title="'.$LANG->getLL('new'.($table=='pages'?'Page':'Record'),1).'" alt="" />'.
982                                                                         '</a>';
983                                                 }
984                                         }
985                                 } elseif(!$this->table) {
986                                         $cells['new'] = $this->spaceIcon;
987                                 }
988
989                                         // "Up/Down" links
990                                 if ($permsEdit && $TCA[$table]['ctrl']['sortby']  && !$this->sortField && !$this->searchLevels) {
991                                         if (isset($this->currentTable['prev'][$row['uid']]))    {       // Up
992                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prev'][$row['uid']];
993                                                 $cells['moveUp']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
994                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_up.gif','width="11" height="10"').' title="'.$LANG->getLL('moveUp',1).'" alt="" />'.
995                                                                 '</a>';
996                                         } else {
997                                                 $cells['moveUp'] = $this->spaceIcon;
998                                         }
999                                         if ($this->currentTable['next'][$row['uid']])   {       // Down
1000                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['next'][$row['uid']];
1001                                                 $cells['moveDown']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
1002                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_down.gif','width="11" height="10"').' title="'.$LANG->getLL('moveDown',1).'" alt="" />'.
1003                                                                 '</a>';
1004                                         } else {
1005                                                 $cells['moveDown'] = $this->spaceIcon;
1006                                         }
1007                                 } elseif(!$this->table) {
1008                                         $cells['moveUp']  = $this->spaceIcon;
1009                                         $cells['moveDown'] = $this->spaceIcon;
1010                                 }
1011
1012                                         // "Hide/Unhide" links:
1013                                 $hiddenField = $TCA[$table]['ctrl']['enablecolumns']['disabled'];
1014                                 if ($permsEdit && $hiddenField && $TCA[$table]['columns'][$hiddenField] && (!$TCA[$table]['columns'][$hiddenField]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$table.':'.$hiddenField)))     {
1015                                         if ($row[$hiddenField]) {
1016                                                 $params='&data['.$table.']['.$row['uid'].']['.$hiddenField.']=0';
1017                                                 $cells['hide']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
1018                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_unhide.gif','width="11" height="10"').' title="'.$LANG->getLL('unHide'.($table=='pages'?'Page':''),1).'" alt="" />'.
1019                                                                 '</a>';
1020                                         } else {
1021                                                 $params='&data['.$table.']['.$row['uid'].']['.$hiddenField.']=1';
1022                                                 $cells['hide']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
1023                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_hide.gif','width="11" height="10"').' title="'.$LANG->getLL('hide'.($table=='pages'?'Page':''),1).'" alt="" />'.
1024                                                                 '</a>';
1025                                         }
1026                                 } elseif(!$this->table) {
1027                                         $cells['hide'] = $this->spaceIcon;
1028                                 }
1029
1030                                         // "Delete" link:
1031                                 if (
1032                                         ($table=='pages' && ($localCalcPerms&4)) || ($table!='pages' && ($this->calcPerms&16))
1033                                         )       {
1034                                         $params='&cmd['.$table.']['.$row['uid'].'][delete]=1';
1035                                         $cells['delete']='<a href="#" onclick="'.htmlspecialchars('if (confirm('.$LANG->JScharCode($LANG->getLL('deleteWarning').t3lib_BEfunc::referenceCount($table,$row['uid'],' (There are %s reference(s) to this record!)')).')) {jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');} return false;').'">'.
1036                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/garbage.gif','width="11" height="12"').' title="'.$LANG->getLL('delete',1).'" alt="" />'.
1037                                                         '</a>';
1038                                 } elseif(!$this->table) {
1039                                         $cells['delete'] = $this->spaceIcon;
1040                                 }
1041
1042                                         // "Levels" links: Moving pages into new levels...
1043                                 if ($permsEdit && $table=='pages' && !$this->searchLevels)      {
1044
1045                                                 // Up (Paste as the page right after the current parent page)
1046                                         if ($this->calcPerms&8) {
1047                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.-$this->id;
1048                                                 $cells['moveLeft']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
1049                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_left.gif','width="11" height="10"').' title="'.$LANG->getLL('prevLevel',1).'" alt="" />'.
1050                                                                 '</a>';
1051                                         }
1052                                                 // Down (Paste as subpage to the page right above)
1053                                         if ($this->currentTable['prevUid'][$row['uid']])        {
1054                                                 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$this->currentTable['prevUid'][$row['uid']]));
1055                                                 if ($localCalcPerms&8)  {
1056                                                         $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prevUid'][$row['uid']];
1057                                                         $cells['moveRight']='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
1058                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"').' title="'.$LANG->getLL('nextLevel',1).'" alt="" />'.
1059                                                                         '</a>';
1060                                                 } else {
1061                                                         $cells['moveRight'] = $this->spaceIcon;
1062                                                 }
1063                                         } else {
1064                                                 $cells['moveRight'] = $this->spaceIcon;
1065                                         }
1066                                 } elseif(!$this->table) {
1067                                         $cells['moveLeft'] = $this->spaceIcon;
1068                                         $cells['moveRight'] = $this->spaceIcon;
1069                                 }
1070                         }
1071                 }
1072
1073                         
1074                 /**
1075                  * @hook                        recStatInfoHooks: Allows to insert HTML before record icons on various places
1076                  * @date                        2007-09-22
1077                  * @request             Kasper Skaarhoj  <kasper2007@typo3.com>
1078                  */
1079                 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['recStatInfoHooks']))     {
1080                         $stat='';
1081                         $_params = array($table,$row['uid']);
1082                         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef)     {
1083                                 $stat.=t3lib_div::callUserFunction($_funcRef,$_params,$this);
1084                         }
1085                         $cells['stat'] = $stat;
1086                 }
1087                 /**
1088                  * @hook                        makeControl: Allows to change control icons of records in list-module
1089                  * @date                        2007-11-20
1090                  * @request             Bernhard Kraft  <krafbt@kraftb.at>
1091                  * @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 accesible by an index-key. The order of the icons is dependend on the order of those array entries.
1092                  */
1093                 if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1094                         foreach($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1095                                 $hookObject = &t3lib_div::getUserObj($classData);
1096                                 if(!($hookObject instanceof localRecordList_actionsHook))       {
1097                                         throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567840);
1098                                 }
1099                                 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1100                         }
1101                 }
1102
1103                         // Compile items into a DIV-element:
1104                 return '
1105                                                                                         <!-- CONTROL PANEL: '.$table.':'.$row['uid'].' -->
1106                                                                                         <div class="typo3-DBctrl">'.implode('',$cells).'</div>';
1107         }
1108
1109         /**
1110          * Creates the clipboard panel for a single record in the listing.
1111          *
1112          * @param       string          The table
1113          * @param       array           The record for which to make the clipboard panel.
1114          * @return      string          HTML table with the clipboard panel (unless disabled)
1115          */
1116         function makeClip($table,$row)  {
1117                 global $TCA, $LANG, $TYPO3_CONF_VARS;
1118
1119                         // Return blank, if disabled:
1120                 if ($this->dontShowClipControlPanels)   return '';
1121                 $cells=array();
1122
1123                 $cells['pasteAfter'] = $cells['pasteInto'] = $this->spaceIcon;
1124
1125                         // Return blank, if disabled:
1126                         // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1127                 if ($this->clipObj->current=='normal')  {       // For the "Normal" pad:
1128
1129                                 // Show copy/cut icons:
1130                         $isSel = (string)$this->clipObj->isSelected($table,$row['uid']);
1131                         $cells['copy']='<a href="#" onclick="'.htmlspecialchars('return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row['uid'],1,($isSel=='copy'),array('returnUrl'=>'')).'\');').'">'.
1132                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_copy'.($isSel=='copy'?'_h':'').'.gif','width="12" height="12"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:cm.copy',1).'" alt="" />'.
1133                                         '</a>';
1134                         $cells['cut']='<a href="#" onclick="'.htmlspecialchars('return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row['uid'],0,($isSel=='cut'),array('returnUrl'=>'')).'\');').'">'.
1135                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_cut'.($isSel=='cut'?'_h':'').'.gif','width="12" height="12"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:cm.cut',1).'" alt="" />'.
1136                                         '</a>';
1137
1138                 } else {        // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1139
1140                                 // Setting name of the element in ->CBnames array:
1141                         $n=$table.'|'.$row['uid'];
1142                         $this->CBnames[]=$n;
1143
1144                                 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1145                         $checked = ($this->clipObj->isSelected($table,$row['uid'])?' checked="checked"':'');
1146
1147                                 // If the "duplicateField" value is set then select all elements which are duplicates...
1148                         if ($this->duplicateField && isset($row[$this->duplicateField]))        {
1149                                 $checked='';
1150                                 if (in_array($row[$this->duplicateField], $this->duplicateStack))       {
1151                                         $checked=' checked="checked"';
1152                                 }
1153                                 $this->duplicateStack[] = $row[$this->duplicateField];
1154                         }
1155
1156                                 // Adding the checkbox to the panel:
1157                         $cells['select']='<input type="hidden" name="CBH['.$n.']" value="0" /><input type="checkbox" name="CBC['.$n.']" value="1" class="smallCheckboxes"'.$checked.' />';
1158                 }
1159
1160                         // Now, looking for selected elements from the current table:
1161                 $elFromTable = $this->clipObj->elFromTable($table);
1162                 if (count($elFromTable) && $TCA[$table]['ctrl']['sortby'])      {       // IF elements are found and they can be individually ordered, then add a "paste after" icon:
1163                         $cells['pasteAfter']='<a href="'.htmlspecialchars($this->clipObj->pasteUrl($table,-$row['uid'])).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg($table,$row,'after',$elFromTable)).'">'.
1164                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_pasteAfter',1).'" alt="" />'.
1165                                         '</a>';
1166                 }
1167
1168                         // Now, looking for elements in general:
1169                 $elFromTable = $this->clipObj->elFromTable('');
1170                 if ($table=='pages' && count($elFromTable))     {
1171                         $cells['pasteInto']='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('',$row['uid'])).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg($table,$row,'into',$elFromTable)).'">'.
1172                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clip_pasteinto.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_pasteInto',1).'" alt="" />'.
1173                                         '</a>';
1174                 }
1175
1176                 /*
1177                  * @hook                        makeClip: Allows to change clip-icons of records in list-module
1178                  * @date                        2007-11-20
1179                  * @request             Bernhard Kraft  <krafbt@kraftb.at>
1180                  * @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 accesible by an index-key. The order of the icons is dependend on the order of those array entries.
1181                  */
1182                 if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1183                         foreach($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1184                                 $hookObject = &t3lib_div::getUserObj($classData);
1185                                 if(!($hookObject instanceof localRecordList_actionsHook))       {
1186                                         throw new UnexpectedValueException('$hookObject must implement interface localRecordList_actionsHook', 1195567845);
1187                                 }
1188                                 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1189                         }
1190                 }
1191
1192                         // Compile items into a DIV-element:
1193                 return '                                                        <!-- CLIPBOARD PANEL: '.$table.':'.$row['uid'].' -->
1194                                                                                         <div class="typo3-clipCtrl">'.implode('',$cells).'</div>';
1195         }
1196
1197         /**
1198          * Make reference count
1199          *
1200          * @param       string          Table name
1201          * @param       integer         UID of record
1202          * @return      string          HTML-table
1203          */
1204         function makeRef($table,$uid)   {
1205
1206                         // Look up the path:
1207                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
1208                         '*',
1209                         'sys_refindex',
1210                         'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
1211                                 ' AND ref_uid='.intval($uid).
1212                                 ' AND deleted=0'
1213                 );
1214
1215                         // Compile information for title tag:
1216                 $infoData=array();
1217                 if (is_array($rows)) {
1218                         foreach($rows as $row)  {
1219                                 $infoData[]=$row['tablename'].':'.$row['recuid'].':'.$row['field'];
1220                         }
1221                 }
1222
1223                 return count($infoData) ? '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$uid.'\'); return false;').'" title="'.htmlspecialchars(t3lib_div::fixed_lgd(implode(' / ',$infoData),100)).'">'.count($infoData).'</a>' : '';
1224         }
1225
1226         /**
1227          * Creates the localization panel
1228          *
1229          * @param       string          The table
1230          * @param       array           The record for which to make the localization panel.
1231          * @return      array           Array with key 0/1 with content for column 1 and 2
1232          */
1233         function makeLocalizationPanel($table,$row)     {
1234                 global $TCA,$LANG;
1235
1236                 $out = array(
1237                         0 => '',
1238                         1 => '',
1239                 );
1240
1241                 $t8Tools = t3lib_div::makeInstance('t3lib_transl8tools');
1242                 $translations = $t8Tools->translationInfo($table,$row['uid']);
1243
1244                         // Language title and icon:
1245                 $out[0] = $this->languageFlag($row[$TCA[$table]['ctrl']['languageField']]);
1246
1247                 if (is_array($translations))    {
1248
1249                                 // Traverse page translations and add icon for each language that does NOT yet exist:
1250                         $lNew = '';
1251                         foreach($this->pageOverlays as $lUid_OnPage => $lsysRec)        {
1252                                 if (!isset($translations['translations'][$lUid_OnPage]) && $GLOBALS['BE_USER']->checkLanguageAccess($lUid_OnPage))      {
1253                                         $href = $GLOBALS['TBE_TEMPLATE']->issueCommand(
1254                                                 '&cmd['.$table.']['.$row['uid'].'][localize]='.$lUid_OnPage,
1255                                                 $this->listURL().'&justLocalized='.rawurlencode($table.':'.$row['uid'].':'.$lUid_OnPage)
1256                                         );
1257
1258                                         $lC = ($this->languageIconTitles[$lUid_OnPage]['flagIcon'] ? '<img src="'.$this->languageIconTitles[$lUid_OnPage]['flagIcon'].'" class="absmiddle" alt="" />' : $this->languageIconTitles[$lUid_OnPage]['title']);
1259                                         $lC = '<a href="'.htmlspecialchars($href).'">'.$lC.'</a> ';
1260
1261                                         $lNew.=$lC;
1262                                 }
1263                         }
1264
1265                         if ($lNew)      $out[1].= $lNew;
1266                 } else {
1267                         $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;'.$out[0];
1268                 }
1269
1270
1271                 return $out;
1272         }
1273
1274         /**
1275          * Create the selector box for selecting fields to display from a table:
1276          *
1277          * @param       string          Table name
1278          * @param       boolean         If true, form-fields will be wrapped around the table.
1279          * @return      string          HTML table with the selector box (name: displayFields['.$table.'][])
1280          */
1281         function fieldSelectBox($table,$formFields=1)   {
1282                 global $TCA, $LANG;
1283
1284                         // Init:
1285                 t3lib_div::loadTCA($table);
1286                 $formElements=array('','');
1287                 if ($formFields)        {
1288                         $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>');
1289                 }
1290
1291                         // Load already selected fields, if any:
1292                 $setFields=is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
1293
1294                         // Request fields from table:
1295                 $fields = $this->makeFieldList($table, false, true);
1296
1297                         // Add pseudo "control" fields
1298                 $fields[]='_PATH_';
1299                 $fields[]='_REF_';
1300                 $fields[]='_LOCALIZATION_';
1301                 $fields[]='_CONTROL_';
1302                 $fields[]='_CLIPBOARD_';
1303
1304                         // Create an option for each field:
1305                 $opt=array();
1306                 $opt[] = '<option value=""></option>';
1307                 foreach($fields as $fN) {
1308                         $fL = is_array($TCA[$table]['columns'][$fN]) ? ereg_replace(':$','',$LANG->sL($TCA[$table]['columns'][$fN]['label'])) : '['.$fN.']';    // Field label
1309                         $opt[] = '
1310                                                                                         <option value="'.$fN.'"'.(in_array($fN,$setFields)?' selected="selected"':'').'>'.htmlspecialchars($fL).'</option>';
1311                 }
1312
1313                         // Compile the options into a multiple selector box:
1314                 $lMenu = '
1315                                                                                 <select size="'.t3lib_div::intInRange(count($fields)+1,3,20).'" multiple="multiple" name="displayFields['.$table.'][]">'.implode('',$opt).'
1316                                                                                 </select>
1317                                 ';
1318
1319                         // Table with the field selector::
1320                 $content.= '
1321                         '.$formElements[0].'
1322
1323                                 <!--
1324                                         Field selector for extended table view:
1325                                 -->
1326                                 <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-fieldSelect">
1327                                         <tr>
1328                                                 <td>'.$lMenu.'</td>
1329                                                 <td><input type="submit" name="search" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.setFields',1).'" /></td>
1330                                         </tr>
1331                                 </table>
1332                         '.$formElements[1];
1333                 return $content;
1334         }
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346         /*********************************
1347          *
1348          * Helper functions
1349          *
1350          *********************************/
1351
1352         /**
1353          * Creates a link around $string. The link contains an onclick action which submits the script with some clipboard action.
1354          * Currently, this is used for setting elements / delete elements.
1355          *
1356          * @param       string          The HTML content to link (image/text)
1357          * @param       string          Table name
1358          * @param       string          Clipboard command (eg. "setCB" or "delete")
1359          * @param       string          Warning text, if any ("delete" uses this for confirmation)
1360          * @return      string          <a> tag wrapped link.
1361          */
1362         function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')       {
1363                 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.cmd_table.value=\''.$table.'\';document.dblistForm.submit();';
1364                 if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
1365                 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent.'return false;').'">'.$string.'</a>';
1366         }
1367
1368         /**
1369          * Returns true if a numeric clipboard pad is selected/active
1370          *
1371          * @return      boolean
1372          */
1373         function clipNumPane()  {
1374                 return in_Array('_CLIPBOARD_',$this->fieldArray) && $this->clipObj->current!='normal';
1375         }
1376
1377         /**
1378          * Creates a sort-by link on the input string ($code).
1379          * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
1380          * Also some fields will not be possible to sort (including if single-table-view is disabled).
1381          *
1382          * @param       string          The string to link (text)
1383          * @param       string          The fieldname represented by the title ($code)
1384          * @param       string          Table name
1385          * @return      string          Linked $code variable
1386          */
1387         function addSortLink($code,$field,$table)       {
1388
1389                         // Certain circumstances just return string right away (no links):
1390                 if ($field=='_CONTROL_' || $field=='_LOCALIZATION_' || $field=='_CLIPBOARD_' || $field=='_REF_' || $this->disableSingleTableView)       return $code;
1391
1392                         // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
1393                 if ($field=='_PATH_')   $field=pid;
1394
1395                         //       Create the sort link:
1396                 $sortUrl = $this->listURL('',-1,'sortField,sortRev,table').'&table='.$table.'&sortField='.$field.'&sortRev='.($this->sortRev || ($this->sortField!=$field)?0:1);
1397                 $sortArrow = ($this->sortField==$field?'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/red'.($this->sortRev?'up':'down').'.gif','width="7" height="4"').' alt="" />':'');
1398
1399                         // Return linked field:
1400                 return '<a href="'.htmlspecialchars($sortUrl).'">'.$code.
1401                                 $sortArrow.
1402                                 '</a>';
1403         }
1404
1405         /**
1406          * Returns the path for a certain pid
1407          * The result is cached internally for the session, thus you can call this function as much as you like without performance problems.
1408          *
1409          * @param       integer         The page id for which to get the path
1410          * @return      string          The path.
1411          */
1412         function recPath($pid)  {
1413                 if (!isset($this->recPath_cache[$pid])) {
1414                         $this->recPath_cache[$pid] = t3lib_BEfunc::getRecordPath($pid,$this->perms_clause,20);
1415                 }
1416                 return $this->recPath_cache[$pid];
1417         }
1418
1419         /**
1420          * Returns true if a link for creating new records should be displayed for $table
1421          *
1422          * @param       string          Table name
1423          * @return      boolean         Returns true if a link for creating new records should be displayed for $table
1424          * @see         SC_db_new::showNewRecLink
1425          */
1426         function showNewRecLink($table) {
1427                         // No deny/allow tables are set:
1428                 if (!count($this->allowedNewTables) && !count($this->deniedNewTables)) {
1429                         return true;
1430                         // If table is not denied (which takes precedence over allowed tables):
1431                 } elseif (!in_array($table, $this->deniedNewTables) && (!count($this->allowedNewTables) || in_array($table, $this->allowedNewTables))) {
1432                         return true;
1433                         // If table is denied or allowed tables are set, but table is not part of:
1434                 } else {
1435                         return false;
1436                 }
1437         }
1438
1439         /**
1440          * 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.
1441          * Uses REQUEST_URI as value.
1442          *
1443          * @return      string
1444          */
1445         function makeReturnUrl()        {
1446                 return '&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
1447         }
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459         /************************************
1460          *
1461          * CSV related functions
1462          *
1463          ************************************/
1464
1465         /**
1466          * Initializes internal csvLines array with the header of field names
1467          *
1468          * @return      void
1469          */
1470         function initCSV()      {
1471
1472                         // Reset:
1473                 $this->csvLines=array();
1474
1475                         // Getting header line with field names:
1476                 $csvRow = array();
1477                 foreach ($this->fieldArray as $fN) {
1478                         if ($fN == '_CONTROL_' || $fn == '_CLIPBOARD_') {
1479                                         continue;
1480                         }
1481                         $csvRow[] = $fN;
1482                 }
1483
1484                         // Set the header + an empty row:
1485                 $this->setCsvRow($csvRow);
1486                 $this->csvLines[] = '';
1487         }
1488
1489
1490         /**
1491          * Adds the content of input array $row to the CSV list:
1492          *
1493          * @param       array           Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
1494          * @param       string          Table name
1495          * @return      void
1496          */
1497         function addToCSV($row,$table)  {
1498
1499                         // Traversing fields, adding values from $row:
1500                 $csvRow = array();
1501                 foreach ($this->fieldArray as $fN) {
1502                         switch ($fN) {
1503                                 case '_PATH':
1504                                         $csvRow[] = $this->recPath($row['pid']);
1505                                         break;
1506
1507                                 case '_REF_':
1508                                         $csvRow[] = $this->makeRef($table, $row['uid']);
1509                                         break;
1510
1511                                         // remove these columns from the CSV view
1512                                 case '_CONTROL_':
1513                                 case '_CLIPBOARD_':
1514                                         continue;
1515                                         break;
1516
1517                                 default:
1518                                         $csvRow[] = $row[$fN];
1519                         }
1520                 }
1521
1522                         // Set the values in the CSV list
1523                 $this->setCsvRow($csvRow);
1524         }
1525
1526
1527         /**
1528          * Adds input row of values to the internal csvLines array as a CSV formatted line
1529          *
1530          * @param       array           Array with values to be listed.
1531          * @return      void
1532          */
1533         function setCsvRow($csvRow)     {
1534                 $this->csvLines[] = t3lib_div::csvValues($csvRow);
1535         }
1536
1537         /**
1538          * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
1539          * This function exits!
1540          *
1541          * @param       string          Filename prefix:
1542          * @return      void            EXITS php execusion!
1543          */
1544         function outputCSV($prefix)     {
1545
1546                         // Setting filename:
1547                 $filename=$prefix.'_'.date('dmy-Hi').'.csv';
1548
1549                         // Creating output header:
1550                 $mimeType = 'application/octet-stream';
1551                 Header('Content-Type: '.$mimeType);
1552                 Header('Content-Disposition: attachment; filename='.$filename);
1553
1554                         // Printing the content of the CSV lines:
1555                 echo implode(chr(13).chr(10),$this->csvLines);
1556
1557                         // Exits:
1558                 exit;
1559         }
1560 }
1561
1562
1563
1564 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc'])   {
1565         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc']);
1566 }
1567
1568 ?>