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