* Modified typo3/sysext/cms/tslib/class.tslib_content.php:
[Packages/TYPO3.CMS.git] / typo3 / class.db_list_extra.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *  
5 *  (c) 1999-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
36  */
37 /**
38  * [CLASS/FUNCTION INDEX of SCRIPT]
39  *
40  *
41  *
42  *   89: class localRecordList extends recordList 
43  *  121:     function writeTop($row,$path)
44  *  295:     function getTable($table,$id,$rowlist)     
45  *  476:     function renderListRow($table,$row,$cc,$titleCol,$thumbsCol)       
46  *  539:     function renderListHeader($table,$currentIdList)   
47  *
48  *              SECTION: Rendering of various elements
49  *  678:     function makeControl($table,$row)  
50  *  852:     function makeClip($table,$row)     
51  *  921:     function fieldSelectBox($table,$formFields=1)      
52  *
53  *              SECTION: Helper functions
54  * 1000:     function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')  
55  * 1011:     function clipNumPane()     
56  * 1025:     function addSortLink($code,$field,$table)  
57  * 1050:     function recPath($pid)     
58  * 1063:     function showNewRecLink($table)    
59  * 1073:     function makeReturnUrl()   
60  *
61  *              SECTION: CSV related functions
62  * 1097:     function initCSV() 
63  * 1119:     function addToCSV($row)    
64  * 1141:     function setCsvRow($csvRow)        
65  * 1152:     function outputCSV($prefix)        
66  *
67  * TOTAL FUNCTIONS: 17
68  * (This index is automatically created/updated by the extension "extdeveval")
69  *
70  */
71
72  
73  
74  
75  
76  
77  
78  
79
80
81
82 /**
83  * Class for rendering of Web>List module
84  *
85  * @author      Kasper Skaarhoj <kasper@typo3.com>
86  * @package TYPO3
87  * @subpackage core
88  */
89 class localRecordList extends recordList {
90         
91                 // External:
92         var $alternateBgColors=FALSE;                   // If true, table rows in the list will alternate in background colors (and have background colors at all!)
93         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.
94         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!).
95
96         var $dontShowClipControlPanels=FALSE;   // If true, will disable the rendering of clipboard + control panels.
97         var $showClipboard=FALSE;                               // If true, will show the clipboard in the field list.
98         var $noControlPanels = FALSE;                   // If true, will DISABLE all control panels in lists. (Takes precedence)
99
100
101
102
103                 // Internal:
104         var $pageRow=array();                                   // Set to the page record (see writeTop())
105
106         var $csvLines=array();                                  // Used to accumulate CSV lines in for CSV export.
107         var $csvOutput=FALSE;                                   // If set, the listing is returned as CSV instead.
108
109         var $clipObj;                                                   // Clipboard object
110         var $CBnames=array();                                   // Tracking names of elements (for clipboard use)
111         var $duplicateStack=array();                    // Used to track which elements has duplicates and how many
112
113
114         /**
115          * Writes the top of the full listing
116          *
117          * @param       array           Current page record
118          * @return      void            (Adds content to internal variable, $this->HTMLcode)
119          */
120         function writeTop($row) {
121                 global $LANG;
122                 
123                         // Makes the code for the pageicon in the top
124                 $this->pageRow=$row;
125                 $this->counter++;
126                 $alttext = t3lib_BEfunc::getRecordIconAltText($row,'pages');
127                 $iconImg = t3lib_iconWorks::getIconImage('pages',$row,$this->backPath,'title="'.htmlspecialchars($alttext).'"');
128                 $titleCol='test';       // pseudo title column name
129                 $this->fieldArray = Array($titleCol,'up');              // Setting the fields to display in the list (this is of course "pseudo fields" since this is the top!)
130                 
131                 
132                         // Filling in the pseudo data array:
133                 $theData = Array();
134                 $theData[$titleCol] = $this->widthGif;
135
136                         // Get users permissions for this row:
137                 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms($row);
138                 
139                 $theData['up']=array();
140
141                         // Initialize control panel for currect page ($this->id):
142                         // Some of the controls are added only if $this->id is set - since they make sense only on a real page, not root level.
143                 $theCtrlPanel =array();
144                 
145                         // "View page" icon is added:
146                 $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($this->id,'',t3lib_BEfunc::BEgetRootLine($this->id))).'">'.
147                                                 '<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="" />'.
148                                                 '</a>';
149
150                         // If edit permissions are set (see class.t3lib_userauthgroup.php)
151                 if ($localCalcPerms&2)  {
152
153                                 // Adding "Edit page" icon:
154                         if ($this->id)  {
155                                 $params='&edit[pages]['.$row['uid'].']=edit';
156                                 $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
157                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('editPage',1).'" alt="" />'.
158                                                                 '</a>';
159                         }
160                                 
161                                 // Adding "New record" icon:
162                         if (!$GLOBALS['SOBE']->modTSconfig['properties']['noCreateRecordsLink'])        {
163                                 $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'db_new.php?id='.$this->id.'\');').'">'.
164                                                                 '<img'.t3lib_iconWorks::skinImg('','gfx/new_el.gif','width="11" height="12"').' title="'.$LANG->getLL('newRecordGeneral',1).'" alt="" />'.
165                                                                 '</a>';
166                         }
167
168                                 // Adding "Hide/Unhide" icon:
169                         if ($this->id)  {
170                                 if ($row['hidden'])     {
171                                         $params='&data[pages]['.$row['uid'].'][hidden]=0';
172                                         $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$GLOBALS['SOBE']->doc->issueCommand($params,-1).'\');').'">'.
173                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_unhide.gif','width="11" height="10"').' title="'.$LANG->getLL('unHidePage',1).'" alt="" />'.
174                                                                         '</a>';
175                                 } else {
176                                         $params='&data[pages]['.$row['uid'].'][hidden]=1';
177                                         $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$GLOBALS['SOBE']->doc->issueCommand($params,-1).'\');').'">'.
178                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_hide.gif','width="11" height="10"').' title="'.$LANG->getLL('hidePage',1).'" alt="" />'.
179                                                                         '</a>';
180                                 }
181                         }
182                         
183                                 // Adding "move page" button:
184                         if ($this->id)  {
185                                 $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'move_el.php?table=pages&uid='.$row['uid'].'\');').'">'.
186                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/move_'.($table=='tt_content'?'record':'page').'.gif','width="11" height="12"').' title="'.$LANG->getLL('move_page',1).'" alt="" />'.
187                                                                 '</a>';
188                         }
189                 }
190                 
191                         // "Paste into page" link:
192                 if (($localCalcPerms&8) || ($localCalcPerms&16))        {
193                         $elFromTable = $this->clipObj->elFromTable('');
194                         if (count($elFromTable))        {
195                                 $theCtrlPanel[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('',$this->id)).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg('pages',$this->pageRow,'into',$elFromTable)).'">'.
196                                                                 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_paste',1).'" alt="" />'.
197                                                                 '</a>';
198                         }
199                 }
200                 
201                         // Finally, compile all elements of the control panel into table cells:
202                 if (count($theCtrlPanel))       {
203                         $theData['up'][]='
204                         
205                                 <!--
206                                         Control panel for page
207                                 -->
208                                 <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-ctrltop">
209                                         <tr>
210                                                 <td>'.implode('</td>
211                                                 <td>',$theCtrlPanel).'</td>
212                                         </tr>
213                                 </table>';
214                 }
215                 
216
217                         // Add "clear-cache" link:
218                 $theData['up'][]='<a href="'.htmlspecialchars($this->listURL().'&clear_cache=1').'">'.
219                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/clear_cache.gif','width="14" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.clear_cache',1).'" alt="" />'.
220                                                 '</a>';
221
222                         // Add "CSV" link, if a specific table is shown:
223                 if ($this->table)       {
224                         $theData['up'][]='<a href="'.htmlspecialchars($this->listURL().'&csv=1').'">'.
225                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/csv.gif','width="27" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.csv',1).'" alt="" />'.
226                                                         '</a>';
227                 }
228
229                         // Add "refresh" link:
230                 $theData['up'][]='<a href="'.htmlspecialchars($this->listURL()).'">'.
231                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/refresh_n.gif','width="14" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.reload',1).'" alt="" />'.
232                                                 '</a>';
233                                                 
234
235                         // Add icon with clickmenu, etc:
236                 if ($this->id)  {       // If there IS a real page...:
237                 
238                                 // Setting title of page + the "Go up" link:
239                         $theData[$titleCol].='<br /><span title="'.htmlspecialchars($row['_thePathFull']).'">'.htmlspecialchars(t3lib_div::fixed_lgd_pre($row['_thePath'],$this->fixedL)).'</span>';
240                         $theData['up'][]='<a href="'.htmlspecialchars($this->listURL($row['pid'])).'">'.
241                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/pages_up.gif','width="18" height="16"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel',1).'" alt="" />'.
242                                                         '</a>';
243
244                                 // Make Icon:
245                         $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,'pages',$this->id);
246                 } else {        // On root-level of page tree:
247                 
248                                 // Setting title of root (sitename):
249                         $theData[$titleCol].='<br />'.htmlspecialchars(t3lib_div::fixed_lgd_pre($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],$this->fixedL));
250
251                                 // Make Icon:
252                         $theIcon='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif','width="18" height="16"').' alt="" />';
253                 }
254
255                         // If there is a returnUrl given, add a back-link:
256                 if ($this->returnUrl)   {
257                         $theData['up'][]='<a href="'.htmlspecialchars(t3lib_div::linkThisUrl($this->returnUrl,array('id'=>$this->id))).'" class="typo3-goBack">'.
258                                                         '<img'.t3lib_iconWorks::skinImg($GLOBALS["BACK_PATH"],'gfx/goback.gif','width="14" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.goBack',1).'" alt="" />'.
259                                                         '</a>';
260                 }
261                 
262                         // Finally, the "up" pseudo field is compiled into a table - has been accumulated in an array:
263                 $theData['up']='
264                         <table border="0" cellpadding="0" cellspacing="0">
265                                 <tr>
266                                         <td>'.implode('</td>
267                                         <td>',$theData['up']).'</td>
268                                 </tr>
269                         </table>';
270                 
271                         // ... and the element row is created:
272                 $out.=$this->addelement(1,'',$theData,'',$this->leftMargin,$theIcon);
273
274                         // ... and wrapped into a table and added to the internal ->HTMLcode variable:
275                 $this->HTMLcode.='
276
277                         
278                 <!--
279                         Page header for db_list:
280                 -->
281                         <table border="0" cellpadding="0" cellspacing="0" id="typo3-dblist-top">
282                                 '.$out.'
283                         </table>';
284         }
285
286         /**
287          * Creates the listing of records from a single table
288          *
289          * @param       string          Table name
290          * @param       integer         Page id
291          * @param       string          List of fields to show in the listing. Pseudo fields will be added including the record header.
292          * @return      string          HTML table with the listing for the record.
293          */
294         function getTable($table,$id,$rowlist)  {
295                 global $TCA;
296
297                         // Loading all TCA details for this table:
298                 t3lib_div::loadTCA($table);
299
300                         // Init
301                 $titleCol = $TCA[$table]['ctrl']['label'];
302                 $thumbsCol = $TCA[$table]['ctrl']['thumbnail'];
303
304                         // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
305                 $this->fieldArray=array();
306                 $this->fieldArray[] = $titleCol;        // Add title column
307                 if (!t3lib_div::inList($rowlist,'_CONTROL_'))   {
308                         $this->fieldArray[] = '_CONTROL_';
309                 }
310                 if ($this->showClipboard)       {
311                         $this->fieldArray[] = '_CLIPBOARD_';
312                 }
313                 if ($this->searchLevels)        {
314                         $this->fieldArray[]='_PATH_';
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                         }
335                         $selectFields[] = 'doktype';
336                 }
337                 if (is_array($TCA[$table]['ctrl']['enablecolumns']))    {
338                         $selectFields = array_merge($selectFields,$TCA[$table]['ctrl']['enablecolumns']);
339                 }
340                 if ($TCA[$table]['ctrl']['type'])       {
341                         $selectFields[] = $TCA[$table]['ctrl']['type'];
342                 }
343                 if ($TCA[$table]['ctrl']['typeicon_column'])    {
344                         $selectFields[] = $TCA[$table]['ctrl']['typeicon_column'];
345                 }
346                 if ($TCA[$table]['ctrl']['label_alt'])  {
347                         $selectFields = array_merge($selectFields,t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1));
348                 }
349                 $selectFields = array_unique($selectFields);            // Unique list!
350                 $selectFields = array_intersect($selectFields,$this->makeFieldList($table,1));          // Making sure that the fields in the field-list ARE in the field-list from TCA!
351                 $selFieldList = implode(',',$selectFields);             // implode it into a list of fields for the SQL-statement.
352
353                         // Create the SQL query for selecting the elements in the listing:
354                 $queryParts = $this->makeQueryArray($table, $id,'',$selFieldList);      // (API function from class.db_list.inc)
355                 $this->setTotalItems($queryParts);              // Finding the total amount of records on the page (API function from class.db_list.inc)
356
357                         // Init:
358                 $dbCount = 0;   
359                 $out = '';
360
361                         // If the count query returned any number of records, we perform the real query, selecting records.             
362                 if ($this->totalItems)  {
363                         $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
364                         $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
365                 }
366                         
367                         // If any records was selected, render the list:
368                 if ($dbCount)   {
369
370                                 // Half line is drawn between tables:
371                         $theData = Array();
372                         if (!$this->table && !$rowlist) {
373                                 $theData[$titleCol] = '<img src="clear.gif" width="'.($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel']?'230':'350').'" height="1" alt="" />';
374                                 if (in_array('_CONTROL_',$this->fieldArray))    $theData['_CONTROL_']='';
375                                 if (in_array('_CLIPBOARD_',$this->fieldArray))  $theData['_CLIPBOARD_']='';
376                         }
377                         $out.=$this->addelement(0,'',$theData,'',$this->leftMargin);
378         
379                                 // Header line is drawn
380                         $theData = Array();
381                         if ($this->disableSingleTableView)      {
382                                 $theData[$titleCol] = '<span class="c-table">'.$GLOBALS['LANG']->sL($TCA[$table]['ctrl']['title'],1).'</span> ('.$this->totalItems.')';
383                         } else {
384                                 $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="" />');
385                         }
386                         $theUpIcon = ($table=='pages'&&$this->id&&isset($this->pageRow['pid'])) ? '<a href="'.htmlspecialchars($this->listURL($this->pageRow['pid'])).'"><img'.t3lib_iconWorks::skinImg('','gfx/i/pages_up.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.upOneLevel',1).'" alt="" /></a>':'';
387                         $out.=$this->addelement(1,$theUpIcon,$theData,' class="c-headLineTable"','');
388         
389                                 // Fixing a order table for sortby tables
390                         $this->currentTable=array();
391                         $currentIdList=array();
392                         $doSort = ($TCA[$table]['ctrl']['sortby'] && !$this->sortField);
393
394                         $prevUid=0;
395                         $prevPrevUid=0;
396                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))    {
397                                 $currentIdList[] = $row['uid'];
398                                 if ($doSort)    {
399                                         if ($prevUid)   {
400                                                 $this->currentTable['prev'][$row['uid']]=$prevPrevUid;
401                                                 $this->currentTable['next'][$prevUid]='-'.$row['uid'];
402                                                 $this->currentTable['prevUid'][$row['uid']]=$prevUid;
403                                         }
404                                         $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
405                                         $prevUid=$row['uid'];
406                                 }
407                         }
408                         $GLOBALS['TYPO3_DB']->sql_data_seek($result,0);
409         
410                                 // CSV initiated
411                         if ($this->csvOutput) $this->initCSV();
412         
413                                 // Render items:
414                         $this->CBnames=array();
415                         $this->duplicateStack=array();
416                         $this->eCounter=$this->firstElementNumber;
417                         
418                         $iOut='';
419                         $cc=0;
420                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))   {
421
422                                         // Forward/Backwards navigation links:
423                                 list($flag,$code) = $this->fwd_rwd_nav($table);
424                                 $iOut.=$code;
425
426                                         // If render item, increment counter and call function
427                                 if ($flag)      {
428                                         $cc++;
429                                         $iOut.=$this->renderListRow($table,$row,$cc,$titleCol,$thumbsCol);
430                                 }
431                                 
432                                         // Counter of total rows incremented:
433                                 $this->eCounter++;      
434                         }
435                         $GLOBALS['TYPO3_DB']->sql_free_result($result);
436         
437                                 // The header row for the table is now created:
438                         $out.=$this->renderListHeader($table,$currentIdList);
439
440                                 // The list of records is added after the header:
441                         $out.=$iOut;
442         
443                                 // ... and it is all wrapped in a table:
444                         $out='
445                         
446                                 
447                                 
448                         <!--
449                                 DB listing of elements: "'.htmlspecialchars($table).'"
450                         -->     
451                                 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">
452                                         '.$out.'
453                                 </table>';      
454         
455                                 // Output csv if...
456                         if ($this->csvOutput)   $this->outputCSV($table);       // This ends the page with exit.        
457                 }
458                 
459                         // Return content:
460                 return $out;
461         }
462
463         /**
464          * Rendering a single row for the list
465          *
466          * @param       string          Table name
467          * @param       array           Current record
468          * @param       integer         Counter, counting for each time an element is rendered (used for alternating colors)
469          * @param       string          Table field (column) where header value is found
470          * @param       string          Table field (column) where (possible) thumbnails can be found
471          * @return      string          Table row for the element
472          * @access private
473          * @see getTable()
474          */
475         function renderListRow($table,$row,$cc,$titleCol,$thumbsCol)    {
476                 $iOut = '';
477                 
478                         // Background color, if any:
479                 $row_bgColor=
480                         $this->alternateBgColors ? 
481                         (($cc%2)?'' :' bgcolor="'.t3lib_div::modifyHTMLColor($GLOBALS['SOBE']->doc->bgColor4,+10,+10,+10).'"') :
482                         '';
483
484                         // Initialization
485                 $alttext = t3lib_BEfunc::getRecordIconAltText($row,$table);
486                 $recTitle = t3lib_BEfunc::getRecordTitle($table,$row);
487                 
488                         // Incr. counter.
489                 $this->counter++;
490
491                         // The icon with link   
492                 $iconImg = t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'title="'.htmlspecialchars($alttext).'"');
493                 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,$table,$row['uid']);
494
495                         // Preparing and getting the data-array
496                 $theData = Array();
497                 reset($this->fieldArray);
498                 while(list(,$fCol)=each($this->fieldArray))     {
499                         if ($fCol==$titleCol)   {
500                                 $theData[$fCol] = $this->linkWrapItems($table,$row['uid'],$recTitle,$row);
501                         } elseif ($fCol=='pid') {
502                                 $theData[$fCol]=$row[$fCol];
503                         } elseif ($fCol=='_PATH_') {
504                                 $theData[$fCol]=$this->recPath($row['pid']);
505                         } elseif ($fCol=='_CONTROL_') {
506                                 $theData[$fCol]=$this->makeControl($table,$row);
507                         } elseif ($fCol=='_CLIPBOARD_') {
508                                 $theData[$fCol]=$this->makeClip($table,$row);
509                         } else {
510                                 $theData[$fCol]=htmlspecialchars(t3lib_BEfunc::getProcessedValueExtra($table,$fCol,$row[$fCol],100));
511                         }
512                 }
513
514                         // Add row to CSV list:
515                 if ($this->csvOutput) $this->addToCSV($row);
516                 
517                         // Create element in table cells:
518                 $iOut.=$this->addelement(1,$theIcon,$theData,$row_bgColor);
519                 
520                         // Render thumbsnails if a thumbnail column exists and there is content in it:
521                 if ($this->thumbs && trim($row[$thumbsCol]))    {
522                         $iOut.=$this->addelement(4,'', Array($titleCol=>$this->thumbCode($row,$table,$thumbsCol)),$row_bgColor);
523                 }
524                 
525                         // Finally, return table row element:
526                 return $iOut;
527         }
528
529         /**
530          * Rendering the header row for a table
531          *
532          * @param       string          Table name
533          * @param       array           Array of the currectly displayed uids of the table
534          * @return      string          Header table row
535          * @access private
536          * @see getTable()
537          */
538         function renderListHeader($table,$currentIdList)        {
539                 global $TCA, $LANG;
540                 
541                         // Init:
542                 $theData = Array();
543
544                         // Traverse the fields:
545                 foreach($this->fieldArray as $fCol)     {
546                 
547                                 // Calculate users permissions to edit records in the table:
548                         $permsEdit = $this->calcPerms & ($table=='pages'?2:16);
549                         
550                         switch((string)$fCol)   {
551                                 case '_PATH_':                  // Path
552                                         $theData[$fCol]='<i>['.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels._PATH_',1).']</i>';
553                                 break;
554                                 case '_CLIPBOARD_':             // Clipboard:
555                                         $cells=array();
556                                         
557                                                 // If there are elements on the clipboard for this table, then display the "paste into" icon:
558                                         $elFromTable = $this->clipObj->elFromTable($table);
559                                         if (count($elFromTable))        {
560                                                 $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl($table,$this->id)).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg('pages',$this->pageRow,'into',$elFromTable)).'">'.
561                                                                 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_paste',1).'" alt="" />'.
562                                                                 '</a>';
563                                         }
564                                         
565                                                 // If the numeric clipboard pads are enabled, display the control icons for that:
566                                         if ($this->clipObj->current!='normal')  {
567                                                         
568                                                         // The "select" link:
569                                                 $cells[]=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg('','gfx/clip_copy.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_selectMarked',1).'" alt="" />',$table,'setCB');
570
571                                                         // The "edit marked" link:      
572                                                 $editIdList = implode(',',$currentIdList);
573                                                 $editIdList = "'+editList('".$table."','".$editIdList."')+'";
574                                                 $params='&edit['.$table.']['.$editIdList.']=edit&disHelp=1';
575                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
576                                                                 '<img'.t3lib_iconWorks::skinImg('','gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('clip_editMarked',1).'" alt="" />'.
577                                                                 '</a>';
578         
579                                                         // The "Delete marked" link:
580                                                 $cells[]=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg('','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'])));
581                                                 
582                                                         // The "Select all" link:
583                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('checkOffCB(\''.implode(',',$this->CBnames).'\'); return false;').'">'.
584                                                                 '<img'.t3lib_iconWorks::skinImg('','gfx/clip_select.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_markRecords',1).'" alt="" />'.
585                                                                 '</a>';
586                                         } else {
587                                                 $cells[]='';
588                                         }
589                                         $theData[$fCol]=implode('',$cells);
590                                 break;
591                                 case '_CONTROL_':               // Control panel:
592                                         if (!$TCA[$table]['ctrl']['readOnly'])  {
593
594                                                         // If new records can be created on this page, add links:
595                                                 if ($this->calcPerms&($table=='pages'?8:16) && $this->showNewRecLink($table))   {
596                                                         if ($table=="tt_content" && $this->newWizards)  {
597                                                                         //  If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
598                                                                 $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
599                                                                 $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
600                                                                 $newContentWizScriptPath = t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : (TYPO3_mainDir.'sysext/cms/layout/db_new_content_el.php');
601
602                                                                 $theData[$fCol]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\''.$newContentWizScriptPath.'?id='.$this->id.'\');').'">'.
603                                                                                                 '<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="" />'.
604                                                                                                 '</a>';
605                                                         } elseif ($table=='pages' && $this->newWizards) {
606                                                                 $theData[$fCol]='<a href="'.htmlspecialchars('db_new.php?id='.$this->id.'&pagesOnly=1returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
607                                                                                                 '<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="" />'.
608                                                                                                 '</a>';
609                                                         } else {
610                                                                 $params='&edit['.$table.']['.$this->id.']=new';
611                                                                 $theData[$fCol]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
612                                                                                                 '<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="" />'.
613                                                                                                 '</a>';
614                                                         }
615                                                 }
616                                                 
617                                                         // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
618                                                 if ($permsEdit && $this->table && is_array($currentIdList))     {
619                                                         $editIdList = implode(',',$currentIdList);
620                                                         if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
621                                                         $params='&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.implode(',',$this->fieldArray).'&disHelp=1';
622                                                         $theData[$fCol].='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
623                                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('editShownColumns',1).'" alt="" />'.
624                                                                                         '</a>';
625                                                 }
626                                         }
627                                 break;
628                                 default:                        // Regular fields header:
629                                         $theData[$fCol]='';
630                                         if ($this->table && is_array($currentIdList))   {
631                                                         
632                                                         // If the numeric clipboard pads are selected, show duplicate sorting link:
633                                                 if ($this->clipNumPane()) {
634                                                         $theData[$fCol].='<a href="'.htmlspecialchars($this->listURL('',-1).'&duplicateField='.$fCol).'">'.
635                                                                                         '<img'.t3lib_iconWorks::skinImg('','gfx/select_duplicates.gif','width="11" height="11"').' title="'.$LANG->getLL('clip_duplicates',1).'" alt="" />'.
636                                                                                         '</a>';
637                                                 }
638                                                 
639                                                         // If the table can be edited, add link for editing THIS field for all listed records:
640                                                 if (!$TCA[$table]['ctrl']['readOnly'] && $permsEdit && $TCA[$table]['columns'][$fCol])  {
641                                                         $editIdList = implode(',',$currentIdList);
642                                                         if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
643                                                         $params='&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.$fCol.'&disHelp=1';
644                                                         $iTitle = sprintf($LANG->getLL('editThisColumn'),ereg_replace(':$','',trim($LANG->sL(t3lib_BEfunc::getItemLabel($table,$fCol)))));
645                                                         $theData[$fCol].='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
646                                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.htmlspecialchars($iTitle).'" alt="" />'.
647                                                                                         '</a>';
648                                                 }
649                                         }
650                                         $theData[$fCol].=$this->addSortLink($LANG->sL(t3lib_BEfunc::getItemLabel($table,$fCol,'<i>[|]</i>')),$fCol,$table);
651                                 break;
652                         }
653                 }
654
655                         // Create and return header table row:
656                 return $this->addelement(1,'',$theData,' class="c-headLine"','');
657         }
658
659
660
661
662
663
664         /*********************************
665          *
666          * Rendering of various elements
667          *
668          *********************************/
669
670         /**
671          * Creates the control panel for a single record in the listing.
672          *
673          * @param       string          The table
674          * @param       array           The record for which to make the control panel.
675          * @return      string          HTML table with the control panel (unless disabled)
676          */
677         function makeControl($table,$row)       {
678                 global $TCA, $LANG, $SOBE;
679                 
680                         // Return blank, if disabled:
681                 if ($this->dontShowClipControlPanels)   return '';
682
683                         // Initialize:
684                 t3lib_div::loadTCA($table);
685                 $cells=array();
686
687                         // If the listed table is 'pages' we have to request the permission settings for each page:
688                 if ($table=='pages')    {
689                         $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid']));
690                 }
691                 
692                         // This expresses the edit permissions for this particular element:
693                 $permsEdit = ($table=='pages' && ($localCalcPerms&2)) || ($table!='pages' && ($this->calcPerms&16));
694                 
695                         // "Show" link (only pages and tt_content elements)
696                 if ($table=='pages' || $table=='tt_content')    {
697                         $params='&edit['.$table.']['.$row['uid'].']=edit';
698                         $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($table=='tt_content'?$this->id.'#'.$row['uid']:$row['uid'])).'">'.
699                                         '<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="" />'.
700                                         '</a>';
701                 }
702                 
703                         // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
704                 if ($permsEdit) {
705                         $params='&edit['.$table.']['.$row['uid'].']=edit';
706                         $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
707                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2'.(!$TCA[$table]['ctrl']['readOnly']?'':'_d').'.gif','width="11" height="12"').' title="'.$LANG->getLL('edit',1).'" alt="" />'.
708                                         '</a>';
709                 }
710
711                         // "Move" wizard link for pages/tt_content elements:            
712                 if (($table=="tt_content" && $permsEdit) || ($table=='pages'))  {
713                         $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'move_el.php?table='.$table.'&uid='.$row['uid'].'\');').'">'.
714                                         '<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="" />'.
715                                         '</a>';
716                 }
717
718                         // If the extended control panel is enabled OR if we are seeing a single table:         
719                 if ($SOBE->MOD_SETTINGS['bigControlPanel'] || $this->table)     {
720
721                                 // "Info": (All records)
722                         $cells[]='<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'">'.
723                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/zoom2.gif','width="12" height="12"').' title="'.$LANG->getLL('showInfo',1).'" alt="" />'.
724                                         '</a>';
725         
726                                 // If the table is NOT a read-only table, then show these links:
727                         if (!$TCA[$table]['ctrl']['readOnly'])  {
728
729                                         // "Revert" link (history/undo)
730                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'show_rechis.php?element='.rawurlencode($table.':'.$row['uid']).'\',\'#latest\');').'">'.
731                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/history2.gif','width="13" height="12"').' title="'.$LANG->getLL('history',1).'" alt="" />'.
732                                                 '</a>';
733
734                                         // "Edit Perms" link:
735                                 if ($table=='pages' && $GLOBALS['BE_USER']->check('modules','web_perm'))        {
736                                         $cells[]='<a href="'.htmlspecialchars('mod/web/perm/index.php?id='.$row['uid'].'&return_id='.$row['uid'].'&edit=1').'">'.
737                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/perm.gif','width="7" height="12"').' title="'.$LANG->getLL('permissions',1).'" alt="" />'.
738                                                         '</a>';
739                                 }
740         
741                                         // "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):
742                                 if ($TCA[$table]['ctrl']['sortby'] || $TCA[$table]['ctrl']['useColumnsForDefaultValues'])       {
743                                         if (
744                                                 ($table!='pages' && ($this->calcPerms&16)) ||   // For NON-pages, must have permission to edit content on this parent page
745                                                 ($table=='pages' && ($this->calcPerms&8))               // For pages, must have permission to create new pages here.
746                                                 )       {       
747                                                 if ($this->showNewRecLink($table))      {
748                                                         $params='&edit['.$table.']['.(-$row['uid']).']=new';
749                                                         $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
750                                                                         '<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="" />'.
751                                                                         '</a>';
752                                                 }
753                                         } 
754                                 }
755
756                                         // "Up/Down" links
757                                 if ($permsEdit && $TCA[$table]['ctrl']['sortby']  && !$this->sortField && !$this->searchLevels) {
758                                         if (isset($this->currentTable['prev'][$row['uid']]))    {       // Up
759                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prev'][$row['uid']];
760                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
761                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_up.gif','width="11" height="10"').' title="'.$LANG->getLL('moveUp',1).'" alt="" />'.
762                                                                 '</a>';
763                                         } else {
764                                                 $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_up.gif','width="11" height="10"',2).' alt="" />';
765                                         }
766                                         if ($this->currentTable['next'][$row['uid']])   {       // Down
767                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['next'][$row['uid']];
768                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
769                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_down.gif','width="11" height="10"').' title="'.$LANG->getLL('moveDown',1).'" alt="" />'.
770                                                                 '</a>';
771                                         } else {
772                                                 $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_down.gif','width="11" height="10"',2).' alt="" />';
773                                         }
774                                 }
775                 
776                                         // "Hide/Unhide" links:
777                                 $hiddenField = $TCA[$table]['ctrl']['enablecolumns']['disabled'];
778                                 if ($permsEdit && $hiddenField && $TCA[$table]['columns'][$hiddenField] && (!$TCA[$table]['columns'][$hiddenField]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$table.':'.$hiddenField)))     {
779                                         if ($row[$hiddenField]) {
780                                                 $params='&data['.$table.']['.$row['uid'].']['.$hiddenField.']=0';
781                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
782                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_unhide.gif','width="11" height="10"').' title="'.$LANG->getLL('unHide'.($table=='pages'?'Page':''),1).'" alt="" />'.
783                                                                 '</a>';
784                                         } else {
785                                                 $params='&data['.$table.']['.$row['uid'].']['.$hiddenField.']=1';
786                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
787                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_hide.gif','width="11" height="10"').' title="'.$LANG->getLL('hide'.($table=='pages'?'Page':''),1).'" alt="" />'.
788                                                                 '</a>';
789                                         }
790                                 }
791                 
792                                         // "Delete" link:
793                                 if (
794                                         ($table=='pages' && ($localCalcPerms&4)) || ($table!='pages' && ($this->calcPerms&16))
795                                         )       {
796                                         $params='&cmd['.$table.']['.$row['uid'].'][delete]=1';
797                                         $cells[]='<a href="#" onclick="'.htmlspecialchars('if (confirm('.$LANG->JScharCode($LANG->getLL('deleteWarning')).')) {jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');} return false;').'">'.
798                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/garbage.gif','width="11" height="12"').' title="'.$LANG->getLL('delete',1).'" alt="" />'.
799                                                         '</a>';
800                                 }
801                 
802                                         // "Levels" links: Moving pages into new levels...
803                                 if ($permsEdit && $table=='pages' && !$this->searchLevels)      {
804
805                                                 // Up (Paste as the page right after the current parent page)
806                                         if ($this->calcPerms&8) {
807                                                 $params='&cmd['.$table.']['.$row['uid'].'][move]='.-$this->id;
808                                                 $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
809                                                                 '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_left.gif','width="11" height="10"').' title="'.$LANG->getLL('prevLevel',1).'" alt="" />'.
810                                                                 '</a>';
811                                         }
812                                                 // Down (Paste as subpage to the page right above)
813                                         if ($this->currentTable['prevUid'][$row['uid']])        {
814                                                 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$this->currentTable['prevUid'][$row['uid']]));
815                                                 if ($localCalcPerms&8)  {
816                                                         $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prevUid'][$row['uid']];
817                                                         $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
818                                                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"').' title="'.$LANG->getLL('nextLevel',1).'" alt="" />'.
819                                                                         '</a>';
820                                                 } else {
821                                                         $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"',2).' alt="" />';
822                                                 }
823                                         } else {
824                                                 $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"',2).' alt="" />';
825                                         }
826                                 }
827                         }
828                 }
829                 
830                         // If the record is edit-locked by another user, we will show a little warning sign:
831                 if ($lockInfo=t3lib_BEfunc::isRecordLocked($table,$row['uid'])) {
832                         $cells[]='<a href="#" onclick="'.htmlspecialchars('alert('.$LANG->JScharCode($lockInfo['msg']).');return false;').'">'.
833                                         '<img'.t3lib_iconWorks::skinImg('','gfx/recordlock_warning3.gif','width="17" height="12"').' title="'.htmlspecialchars($lockInfo['msg']).'" alt="" />'.
834                                         '</a>';
835                 }
836                 
837
838                         // Compile items into a DIV-element:
839                 return '
840                                                                                         <!-- CONTROL PANEL: '.$table.':'.$row['uid'].' -->
841                                                                                         <div class="typo3-DBctrl">'.implode('',$cells).'</div>';
842         }
843
844         /**
845          * Creates the clipboard panel for a single record in the listing.
846          *
847          * @param       string          The table
848          * @param       array           The record for which to make the clipboard panel.
849          * @return      string          HTML table with the clipboard panel (unless disabled)
850          */
851         function makeClip($table,$row)  {
852                 global $TCA, $LANG;
853                 
854                         // Return blank, if disabled:
855                 if ($this->dontShowClipControlPanels)   return '';
856                 $cells=array();
857
858                         // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
859                 if ($this->clipObj->current=='normal')  {       // For the "Normal" pad:
860
861                                 // Show copy/cut icons:
862                         $isSel = (string)$this->clipObj->isSelected($table,$row['uid']);
863                         $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row['uid'],1,($isSel=='copy'),array('returnUrl'=>'')).'\');').'">'.
864                                         '<img'.t3lib_iconWorks::skinImg('','gfx/clip_copy'.($isSel=='copy'?'_h':'').'.gif','width="12" height="12"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:cm.copy',1).'" alt="" />'.
865                                         '</a>';
866                         $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row['uid'],0,($isSel=='cut'),array('returnUrl'=>'')).'\');').'">'.
867                                         '<img'.t3lib_iconWorks::skinImg('','gfx/clip_cut'.($isSel=='cut'?'_h':'').'.gif','width="12" height="12"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:cm.cut',1).'" alt="" />'.
868                                         '</a>';
869
870                 } else {        // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
871                 
872                                 // Setting name of the element in ->CBnames array:
873                         $n=$table.'|'.$row['uid'];
874                         $this->CBnames[]=$n;
875
876                                 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
877                         $checked = ($this->clipObj->isSelected($table,$row['uid'])?' checked="checked"':'');
878
879                                 // If the "duplicateField" value is set then select all elements which are duplicates...
880                         if ($this->duplicateField && isset($row[$this->duplicateField]))        {
881                                 $checked='';
882                                 if (in_array($row[$this->duplicateField], $this->duplicateStack))       {
883                                         $checked=' checked="checked"';
884                                 }
885                                 $this->duplicateStack[] = $row[$this->duplicateField];
886                         }
887                                 
888                                 // Adding the checkbox to the panel:                    
889                         $cells[]='<input type="hidden" name="CBH['.$n.']" value="0" /><input type="checkbox" name="CBC['.$n.']" value="1" class="smallCheckboxes"'.$checked.' />';
890                 }
891
892                         // Now, looking for selected elements from the current table:           
893                 $elFromTable = $this->clipObj->elFromTable($table);
894                 if (count($elFromTable) && $TCA[$table]['ctrl']['sortby'])      {       // IF elements are found and they can be individually ordered, then add a "paste after" icon:
895                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl($table,-$row['uid'])).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg($table,$row,'after',$elFromTable)).'">'.
896                                         '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_pasteAfter',1).'" alt="" />'.
897                                         '</a>';
898                 }
899
900                         // Now, looking for elements in general:
901                 $elFromTable = $this->clipObj->elFromTable('');
902                 if ($table=='pages' && count($elFromTable))     {
903                         $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('',$row['uid'])).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg($table,$row,'into',$elFromTable)).'">'.
904                                         '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteinto.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_pasteInto',1).'" alt="" />'.
905                                         '</a>';
906                 }
907
908                         // Compile items into a DIV-element:
909                 return '                                                        <!-- CLIPBOARD PANEL: '.$table.':'.$row['uid'].' -->
910                                                                                         <div class="typo3-clipCtrl">'.implode('',$cells).'</div>';
911         }
912
913         /**
914          * Create the selector box for selecting fields to display from a table:
915          *
916          * @param       string          Table name
917          * @param       boolean         If true, form-fields will be wrapped around the table.
918          * @return      string          HTML table with the selector box (name: displayFields['.$table.'][])
919          */
920         function fieldSelectBox($table,$formFields=1)   {
921                 global $TCA, $LANG;
922                 
923                         // Init:
924                 t3lib_div::loadTCA($table);
925                 $formElements=array('','');
926                 if ($formFields)        {
927                         $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>');
928                 }
929
930                         // Load already selected fields, if any:
931                 $setFields=is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
932
933                         // Request fields from table:
934                 $fields = $this->makeFieldList($table);
935
936                         // Add pseudo "control" fields
937                 $fields[]='_PATH_';
938                 $fields[]='_CONTROL_';
939                 $fields[]='_CLIPBOARD_';
940
941                         // Create an option for each field:
942                 $opt=array();
943                 $opt[] = '<option value=""></option>';
944                 foreach($fields as $fN) {
945                         $fL = is_array($TCA[$table]['columns'][$fN]) ? ereg_replace(':$','',$LANG->sL($TCA[$table]['columns'][$fN]['label'])) : '['.$fN.']';    // Field label
946                         $opt[] = '
947                                                                                         <option value="'.$fN.'"'.(in_array($fN,$setFields)?' selected="selected"':'').'>'.htmlspecialchars($fL).'</option>';
948                 }
949
950                         // Compile the options into a multiple selector box:
951                 $lMenu = '
952                                                                                 <select size='.t3lib_div::intInRange(count($fields)+1,3,20).' multiple="multiple" name="displayFields['.$table.'][]">'.implode('',$opt).'
953                                                                                 </select>
954                                 ';
955                 
956                         // Table with the field selector::
957                 $content.= '
958                         '.$formElements[0].'
959
960                                 <!--
961                                         Field selector for extended table view:
962                                 -->
963                                 <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-fieldSelect">
964                                         <tr>
965                                                 <td>'.$lMenu.'</td>
966                                                 <td><input type="submit" name="search" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.setFields',1).'" /></td>
967                                         </tr>
968                                 </table>                        
969                         '.$formElements[1];
970                 return $content;
971         }
972
973
974
975
976
977
978
979
980
981
982
983         /*********************************
984          *
985          * Helper functions
986          *
987          *********************************/
988
989         /**
990          * Creates a link around $string. The link contains an onclick action which submits the script with some clipboard action.
991          * Currently, this is used for setting elements / delete elements.
992          *
993          * @param       string          The HTML content to link (image/text)
994          * @param       string          Table name
995          * @param       string          Clipboard command (eg. "setCB" or "delete")
996          * @param       string          Warning text, if any ("delete" uses this for confirmation)
997          * @return      string          <a> tag wrapped link.
998          */
999         function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')       {
1000                 $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.cmd_table.value=\''.$table.'\';document.dblistForm.submit();';
1001                 if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
1002                 return '<a href="#" onclick="'.htmlspecialchars($onClickEvent.'return false;').'">'.$string.'</a>';
1003         }
1004
1005         /**
1006          * Returns true if a numeric clipboard pad is selected/active
1007          *
1008          * @return      boolean
1009          */
1010         function clipNumPane()  {
1011                 return in_Array('_CLIPBOARD_',$this->fieldArray) && $this->clipObj->current!='normal';
1012         }
1013
1014         /**
1015          * Creates a sort-by link on the input string ($code).
1016          * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
1017          * Also some fields will not be possible to sort (including if single-table-view is disabled).
1018          *
1019          * @param       string          The string to link (text)
1020          * @param       string          The fieldname represented by the title ($code)
1021          * @param       string          Table name
1022          * @return      string          Linked $code variable
1023          */
1024         function addSortLink($code,$field,$table)       {
1025                         
1026                         // Certain circumstances just return string right away (no links):
1027                 if ($field=='_CONTROL_' || $field=='_CLIPBOARD_' || $this->disableSingleTableView)      return $code;
1028                 
1029                         // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
1030                 if ($field=='_PATH_')   $field=pid;
1031                 
1032                         //       Create the sort link:
1033                 $sortUrl = $this->listURL('',-1,'sortField,sortRev,table').'&table='.$table.'&sortField='.$field.'&sortRev='.($this->sortRev || ($this->sortField!=$field)?0:1);
1034                 $sortArrow = ($this->sortField==$field?'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/red'.($this->sortRev?'up':'down').'.gif','width="7" height="4"').' alt="" />':'');
1035                 
1036                         // Return linked field:
1037                 return '<a href="'.htmlspecialchars($sortUrl).'">'.$code.
1038                                 $sortArrow.
1039                                 '</a>';
1040         }
1041
1042         /**
1043          * Returns the path for a certain pid
1044          * The result is cached internally for the session, thus you can call this function as much as you like without performance problems.
1045          *
1046          * @param       integer         The page id for which to get the path
1047          * @return      string          The path.
1048          */
1049         function recPath($pid)  {
1050                 if (!isset($this->recPath_cache[$pid])) {
1051                         $this->recPath_cache[$pid] = t3lib_BEfunc::getRecordPath($pid,$this->perms_clause,20);
1052                 }
1053                 return $this->recPath_cache[$pid];
1054         }
1055
1056         /**
1057          * Returns true if a link for creating new records should be displayed for $table
1058          *
1059          * @param       string          Table name
1060          * @return      boolean
1061          */
1062         function showNewRecLink($table) {
1063                 return !count($this->allowedNewTables) || in_array($table,$this->allowedNewTables);
1064         }
1065
1066         /**
1067          * 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.
1068          * Uses REQUEST_URI as value.
1069          *
1070          * @return      string
1071          */
1072         function makeReturnUrl()        {
1073                 return '&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
1074         }
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085         /************************************
1086          *
1087          * CSV related functions
1088          *
1089          ************************************/
1090          
1091         /**
1092          * Initializes internal csvLines array with the header of field names
1093          *
1094          * @return      void
1095          */
1096         function initCSV()      {
1097
1098                         // Reset:
1099                 $this->csvLines=array();
1100
1101                         // Getting header line with field names:                                        
1102                 $csvRow=array();
1103                 foreach($this->fieldArray as $fN)       {
1104                         $csvRow[]=$fN;
1105                 }
1106
1107                         // Set the header + an empty row:
1108                 $this->setCsvRow($csvRow);
1109                 $this->csvLines[]='';
1110         }
1111
1112         /**
1113          * Adds the content of input array $row to the CSV list:
1114          *
1115          * @param       array           Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
1116          * @return      void
1117          */
1118         function addToCSV($row) {
1119
1120                         // Traversing fields, adding values from $row:
1121                 $csvRow=array();
1122                 foreach($this->fieldArray as $fN)       {
1123                         if ($fN=='_PATH_')      {
1124                                 $csvRow[]=$this->recPath($row['pid']);
1125                         } else {
1126                                 $csvRow[]=$row[$fN];
1127                         }
1128                 }
1129                 
1130                         // Set the values in the CSV list
1131                 $this->setCsvRow($csvRow);
1132         }
1133
1134         /**
1135          * Adds input row of values to the internal csvLines array as a CSV formatted line
1136          *
1137          * @param       array           Array with values to be listed.
1138          * @return      void
1139          */
1140         function setCsvRow($csvRow)     {
1141                 $this->csvLines[] = t3lib_div::csvValues($csvRow);
1142         }
1143
1144         /**
1145          * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
1146          * This function exits!
1147          *
1148          * @param       string          Filename prefix:
1149          * @return      void            EXITS php execusion!
1150          */
1151         function outputCSV($prefix)     {
1152
1153                         // Setting filename:
1154                 $filename=$prefix.'_'.date('dmy-Hi').'.csv';
1155                 
1156                         // Creating output header:
1157                 $mimeType = 'application/octet-stream';
1158                 Header('Content-Type: '.$mimeType);
1159                 Header('Content-Disposition: attachment; filename='.$filename);
1160
1161                         // Printing the content of the CSV lines:
1162                 echo implode(chr(13).chr(10),$this->csvLines);
1163                 
1164                         // Exits:
1165                 exit;
1166         }
1167 }
1168
1169  
1170
1171 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc'])   {
1172         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc']);
1173 }
1174 ?>