Implemented versioning API, phase 1 (tcemain). See changelog
[Packages/TYPO3.CMS.git] / typo3 / class.db_list_extra.inc
index e764488..dfa1f49 100755 (executable)
@@ -1,22 +1,22 @@
 <?php
 /***************************************************************
 *  Copyright notice
-*  
-*  (c) 1999-2003 Kasper Skårhøj (kasper@typo3.com)
+*
+*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
 *  All rights reserved
 *
-*  This script is part of the TYPO3 project. The TYPO3 project is 
+*  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
-* 
+*
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
-*  A copy is found in the textfile GPL.txt and important notices to the license 
+*  A copy is found in the textfile GPL.txt and important notices to the license
 *  from the author is found in LICENSE.txt distributed with these scripts.
 *
-* 
+*
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
-/** 
+/**
  * Include file extending recordList which extended t3lib_recordList
+ * Used specifically for the Web>List module (db_list.php)
+ *
+ * $Id$
+ * Revised for TYPO3 3.6 December/2003 by Kasper Skaarhoj
+ * XHTML compliant
+ *
+ * @author     Kasper Skaarhoj <kasper@typo3.com>
+ */
+/**
+ * [CLASS/FUNCTION INDEX of SCRIPT]
+ *
+ *
+ *
+ *   89: class localRecordList extends recordList
+ *  121:     function writeTop($row,$path)
+ *  295:     function getTable($table,$id,$rowlist)
+ *  476:     function renderListRow($table,$row,$cc,$titleCol,$thumbsCol)
+ *  539:     function renderListHeader($table,$currentIdList)
  *
- * @author     Kasper Skårhøj <kasper@typo3.com>
+ *              SECTION: Rendering of various elements
+ *  678:     function makeControl($table,$row)
+ *  852:     function makeClip($table,$row)
+ *  921:     function fieldSelectBox($table,$formFields=1)
+ *
+ *              SECTION: Helper functions
+ * 1000:     function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')
+ * 1011:     function clipNumPane()
+ * 1025:     function addSortLink($code,$field,$table)
+ * 1050:     function recPath($pid)
+ * 1063:     function showNewRecLink($table)
+ * 1073:     function makeReturnUrl()
+ *
+ *              SECTION: CSV related functions
+ * 1097:     function initCSV()
+ * 1119:     function addToCSV($row)
+ * 1141:     function setCsvRow($csvRow)
+ * 1152:     function outputCSV($prefix)
+ *
+ * TOTAL FUNCTIONS: 17
+ * (This index is automatically created/updated by the extension "extdeveval")
+ *
+ */
+
+
+
+
+
+
+
+
+
+
+
+/**
+ * Class for rendering of Web>List module
+ *
+ * @author     Kasper Skaarhoj <kasper@typo3.com>
  * @package TYPO3
  * @subpackage core
- *
  */
+class localRecordList extends recordList {
+
+               // External:
+       var $alternateBgColors=FALSE;                   // If true, table rows in the list will alternate in background colors (and have background colors at all!)
+       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.
+       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!).
+
+       var $dontShowClipControlPanels=FALSE;   // If true, will disable the rendering of clipboard + control panels.
+       var $showClipboard=FALSE;                               // If true, will show the clipboard in the field list.
+       var $noControlPanels = FALSE;                   // If true, will DISABLE all control panels in lists. (Takes precedence)
+
+
+
+
+               // Internal:
+       var $pageRow=array();                                   // Set to the page record (see writeTop())
+
+       var $csvLines=array();                                  // Used to accumulate CSV lines in for CSV export.
+       var $csvOutput=FALSE;                                   // If set, the listing is returned as CSV instead.
+
+       var $clipObj;                                                   // Clipboard object
+       var $CBnames=array();                                   // Tracking names of elements (for clipboard use)
+       var $duplicateStack=array();                    // Used to track which elements has duplicates and how many
 
- class localRecordList extends recordList {
-       var $noControlPanels = 0;
-       var $showClipboard=0;
-       var $clipObj;
-       var $CBnames=array();
-       var $pageRow=array();
-       var $alternateBgColors=0;
-       var $allowedNewTables=array();
-       var $newWizards=0;
-       var $dontShowClipControlPanels=0;
-       
-       function writeTop($row,$path)   {
+
+       /**
+        * Writes the top of the full listing
+        *
+        * @param       array           Current page record
+        * @return      void            (Adds content to internal variable, $this->HTMLcode)
+        */
+       function writeTop($row) {
                global $LANG;
-               
+
                        // Makes the code for the pageicon in the top
-               $this->pageRow=$row;
+               $this->pageRow = $row;
                $this->counter++;
-               $iconfile = t3lib_iconWorks::getIcon("pages",$row);
-               $alttext = t3lib_BEfunc::getRecordIconAltText($row,"pages");
-               $titleCol="test";
-               $this->fieldArray = Array($titleCol,"up");
-               
-               $out="<table border=0 cellpadding=0 cellspacing=0>";
+               $alttext = t3lib_BEfunc::getRecordIconAltText($row,'pages');
+               $iconImg = t3lib_iconWorks::getIconImage('pages',$row,$this->backPath,'title="'.htmlspecialchars($alttext).'"');
+               $titleCol = 'test';     // pseudo title column name
+               $this->fieldArray = Array($titleCol,'up');              // Setting the fields to display in the list (this is of course "pseudo fields" since this is the top!)
+
 
+                       // Filling in the pseudo data array:
                $theData = Array();
                $theData[$titleCol] = $this->widthGif;
 
-                       // Edit         
-               $localCalcPerms = $GLOBALS["BE_USER"]->calcPerms($row);
-               
-               $theData["up"]=array();
+                       // Get users permissions for this row:
+               $localCalcPerms = $GLOBALS['BE_USER']->calcPerms($row);
+
+               $theData['up']=array();
+
+                       // Initialize control panel for currect page ($this->id):
+                       // Some of the controls are added only if $this->id is set - since they make sense only on a real page, not root level.
                $theCtrlPanel =array();
-               
-               $theCtrlPanel[]='<a HREF="#" onClick="'.t3lib_BEfunc::viewOnClick($this->id,"",t3lib_BEfunc::BEgetRootLine($this->id)).'"><img src="'.$this->backPath.'gfx/zoom.gif" width="12" height="12" vspace=1 border="0" align=top'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.showPage")).'></a>';
 
-//             debug($localCalcPerms);
+                       // "View page" icon is added:
+               $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($this->id,'',t3lib_BEfunc::BEgetRootLine($this->id))).'">'.
+                                               '<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="" />'.
+                                               '</a>';
+
+                       // If edit permissions are set (see class.t3lib_userauthgroup.php)
                if ($localCalcPerms&2)  {
+
+                               // Adding "Edit page" icon:
                        if ($this->id)  {
-                               $params="&edit[pages][".$row["uid"]."]=edit";
-                               $theCtrlPanel[]='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="'.$this->backPath.'gfx/edit2.gif" width=11 height=12 vspace=2 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("editPage")).'></a>';
+                               $params='&edit[pages]['.$row['uid'].']=edit';
+                               $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('editPage',1).'" alt="" />'.
+                                                               '</a>';
                        }
-                       if (!$GLOBALS["SOBE"]->modTSconfig["properties"]["noCreateRecordsLink"])        {
-                               $theCtrlPanel[]='<a href="#" onClick="return jumpExt(\'db_new.php?id='.$this->id.'\');"><img src="gfx/new_el.gif" width="11" height="12" border="0" align=top'.t3lib_BEfunc::titleAttrib($LANG->getLL("newRecordGeneral"),1).'></a>';
+
+                               // Adding "New record" icon:
+                       if (!$GLOBALS['SOBE']->modTSconfig['properties']['noCreateRecordsLink'])        {
+                               $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'db_new.php?id='.$this->id.'\');').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg('','gfx/new_el.gif','width="11" height="12"').' title="'.$LANG->getLL('newRecordGeneral',1).'" alt="" />'.
+                                                               '</a>';
                        }
 
+                               // Adding "Hide/Unhide" icon:
                        if ($this->id)  {
-                               if ($row["hidden"])     {
-                                       $params="&data[pages][".$row["uid"]."][hidden]=0";
-                                       $theCtrlPanel[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_unhide.gif" width=11 height=10 vspace=2 hspace=2 border=0'.t3lib_BEfunc::titleAttrib($LANG->getLL("unHidePage")).' align="top"></a>';
+                               if ($row['hidden'])     {
+                                       $params='&data[pages]['.$row['uid'].'][hidden]=0';
+                                       $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$GLOBALS['SOBE']->doc->issueCommand($params,-1).'\');').'">'.
+                                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_unhide.gif','width="11" height="10"').' title="'.$LANG->getLL('unHidePage',1).'" alt="" />'.
+                                                                       '</a>';
                                } else {
-                                       $params="&data[pages][".$row["uid"]."][hidden]=1";
-                                       $theCtrlPanel[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_hide.gif" width=11 height=10 vspace=2 hspace=2 border=0'.t3lib_BEfunc::titleAttrib($LANG->getLL("hidePage")).' align="top"></a>';
+                                       $params='&data[pages]['.$row['uid'].'][hidden]=1';
+                                       $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$GLOBALS['SOBE']->doc->issueCommand($params,-1).'\');').'">'.
+                                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_hide.gif','width="11" height="10"').' title="'.$LANG->getLL('hidePage',1).'" alt="" />'.
+                                                                       '</a>';
                                }
                        }
+
+                               // Adding "move page" button:
                        if ($this->id)  {
-                               $theCtrlPanel[]='<A HREF="#" onClick="return jumpExt(\'move_el.php?table=pages&uid='.$row["uid"].'\');"><img src="'.$this->backPath.'gfx/move_'.($table=="tt_content"?"record":"page").'.gif" width=11 height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("move_page")).'></a>';
+                               $theCtrlPanel[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'move_el.php?table=pages&uid='.$row['uid'].'\');').'">'.
+                                                               '<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="" />'.
+                                                               '</a>';
                        }
                }
+
+                       // "Paste into page" link:
                if (($localCalcPerms&8) || ($localCalcPerms&16))        {
-                       $elFromTable = $this->clipObj->elFromTable("");
+                       $elFromTable = $this->clipObj->elFromTable('');
                        if (count($elFromTable))        {
-                               $theCtrlPanel[]='<a href="'.$this->clipObj->pasteUrl("",$this->id).'" onClick="return '.$this->clipObj->confirmMsg("pages",$this->pageRow,"into",$elFromTable).'"><img src="gfx/clip_pasteafter.gif" width="12" height="12" vspace=2 hspace=2 border="0"'.t3lib_BEfunc::titleAttrib($LANG->getLL("clip_paste")).' align="top"></a>';
+                               $theCtrlPanel[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('',$this->id)).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg('pages',$this->pageRow,'into',$elFromTable)).'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_paste',1).'" alt="" />'.
+                                                               '</a>';
                        }
                }
+
+                       // Finally, compile all elements of the control panel into table cells:
                if (count($theCtrlPanel))       {
-                       $theData["up"][]='<table border=0 cellpadding=0 cellspacing=0 bgColor="'.$GLOBALS["SOBE"]->doc->bgColor4.'"><tr><td>'.implode('</td><td>',$theCtrlPanel).'</td></tr></table>';
+                       $theData['up'][]='
+
+                               <!--
+                                       Control panel for page
+                               -->
+                               <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-ctrltop">
+                                       <tr>
+                                               <td>'.implode('</td>
+                                               <td>',$theCtrlPanel).'</td>
+                                       </tr>
+                               </table>';
                }
-               
 
 
-               $theData["up"][]='<A href="'.$this->listURL().'&clear_cache=1"><img src="'.$this->backPath.'gfx/clear_cache.gif" width=14 hspace=2 height=14 vspace=1 border=0'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.clear_cache")).' align="top"></a>';
+                       // Add "clear-cache" link:
+               $theData['up'][]='<a href="'.htmlspecialchars($this->listURL().'&clear_cache=1').'">'.
+                                               '<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="" />'.
+                                               '</a>';
 
+                       // Add "CSV" link, if a specific table is shown:
                if ($this->table)       {
-                       $theData["up"][]='<A href="'.$this->listURL().'&csv=1"><img src="'.$this->backPath.'gfx/csv.gif" width=27 hspace=2 height=14 vspace=1 border=0'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.csv")).' align="top"></a>';
+                       $theData['up'][]='<a href="'.htmlspecialchars($this->listURL().'&csv=1').'">'.
+                                                       '<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="" />'.
+                                                       '</a>';
                }
 
+                       // Add "refresh" link:
+               $theData['up'][]='<a href="'.htmlspecialchars($this->listURL()).'">'.
+                                               '<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="" />'.
+                                               '</a>';
+
+
+                       // Add icon with clickmenu, etc:
+               if ($this->id)  {       // If there IS a real page...:
+
+                               // Setting title of page + the "Go up" link:
+                       $theData[$titleCol].='<br /><span title="'.htmlspecialchars($row['_thePathFull']).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['_thePath'],-$this->fixedL)).'</span>';
+                       $theData['up'][]='<a href="'.htmlspecialchars($this->listURL($row['pid'])).'">'.
+                                                       '<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="" />'.
+                                                       '</a>';
+
+                               // Make Icon:
+                       $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,'pages',$this->id);
+               } else {        // On root-level of page tree:
 
-               $theData["up"][]='<A href="'.$this->listURL().'"><img src="'.$this->backPath.'gfx/refresh_n.gif" width=14 hspace=2 height=14 vspace=1 border=0'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.reload")).' align="top"></a>';
-               if ($row["uid"])        {
-                       $theIcon = '<img src="'.$this->backPath.$iconfile.'" width=18 height=16 border=0'.t3lib_BEfunc::titleAttrib($alttext).'">';
-                       $theIcon = $GLOBALS["SOBE"]->doc->wrapClickMenuOnIcon($theIcon,"pages",$this->id);
+                               // Setting title of root (sitename):
+                       $theData[$titleCol].='<br />'.htmlspecialchars(t3lib_div::fixed_lgd_cs($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],-$this->fixedL));
 
-                       $theData[$titleCol].="<BR>".t3lib_div::fixed_lgd_pre($path,$this->fixedL);
-                       $theData["up"][]='<A href="'.$this->listURL($row["pid"]).'"><img src="'.$this->backPath.'gfx/i/pages_up.gif" width=18 height=16 border=0'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.upOneLevel")).' align="top"></a>';
-               } else {        
-                               // root:0
-                       $theIcon='<img src="'.$this->backPath.'gfx/i/_icon_website.gif" width=18 height=16 border=0>';
-                       $theData[$titleCol].="<BR>".t3lib_div::fixed_lgd_pre($GLOBALS["TYPO3_CONF_VARS"]["SYS"]["sitename"],$this->fixedL);
+                               // Make Icon:
+                       $theIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif','width="18" height="16"').' alt="" />';
                }
 
+                       // If there is a returnUrl given, add a back-link:
                if ($this->returnUrl)   {
-                       $theData["up"][]='<A href="'.t3lib_div::linkThisUrl($this->returnUrl,array("id"=>$this->id)).'" class="typo3-goBack"><img src="'.$this->backPath.'gfx/goback.gif" width=14 hspace=2 height=14 vspace=1 border=0'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.goBack")).' align="top"></a>';
-               }
-               
-               $theData["up"]='<table border=0 cellpadding=0 cellspacing=0><tr><td>'.implode("</td><td>",$theData["up"]).'</td></tr></table>';
-               $out.=$this->addelement(1,'',$theData,'',$this->leftMargin,$theIcon);
-//debug($theData);
-               $out.="</table>";
-               $this->HTMLcode.=$out;
-       }
-       function linkClipboardHeaderIcon($string,$table,$cmd,$warning="")       {
-               $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.cmd_table.value=\''.$table.'\';document.dblistForm.submit();';
-               if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
-               return '<a href="#" onClick="'.$onClickEvent.'return false;">'.$string.'</a>';
+                       $theData['up'][]='<a href="'.htmlspecialchars(t3lib_div::linkThisUrl($this->returnUrl,array('id'=>$this->id))).'" class="typo3-goBack">'.
+                                                       '<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="" />'.
+                                                       '</a>';
+               }
+
+                       // Finally, the "up" pseudo field is compiled into a table - has been accumulated in an array:
+               $theData['up']='
+                       <table border="0" cellpadding="0" cellspacing="0">
+                               <tr>
+                                       <td>'.implode('</td>
+                                       <td>',$theData['up']).'</td>
+                               </tr>
+                       </table>';
+
+                       // ... and the element row is created:
+               $out.=$this->addelement(1,'',$theData,'',$this->leftMargin, $theIcon);
+
+                       // ... and wrapped into a table and added to the internal ->HTMLcode variable:
+               $this->HTMLcode.='
+
+
+               <!--
+                       Page header for db_list:
+               -->
+                       <table border="0" cellpadding="0" cellspacing="0" id="typo3-dblist-top">
+                               '.$out.'
+                       </table>';
        }
+
+       /**
+        * Creates the listing of records from a single table
+        *
+        * @param       string          Table name
+        * @param       integer         Page id
+        * @param       string          List of fields to show in the listing. Pseudo fields will be added including the record header.
+        * @return      string          HTML table with the listing for the record.
+        */
        function getTable($table,$id,$rowlist)  {
-                       // Adds the code of a single table
                global $TCA;
+
+                       // Loading all TCA details for this table:
                t3lib_div::loadTCA($table);
-       //      echo $this->makeQuery($table, $id)."<BR>";
 
                        // Init
-               $titleCol = $TCA[$table]["ctrl"]["label"];
-               $thumbsCol = $TCA[$table]["ctrl"]["thumbnail"];
-
-               if (!$this->table && !$rowlist) {
-//                     $this->addElement_tdParams[$titleCol]=' width="'.($GLOBALS["SOBE"]->MOD_SETTINGS["bigControlPanel"]?"230":"350").'"';
-               }
+               $titleCol = $TCA[$table]['ctrl']['label'];
+               $thumbsCol = $TCA[$table]['ctrl']['thumbnail'];
 
                        // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
                $this->fieldArray=array();
-               $this->fieldArray[] = $titleCol;
-               if (!t3lib_div::inList($rowlist,"_CONTROL_"))   {
-                       $this->fieldArray[] = "_CONTROL_";
+               $this->fieldArray[] = $titleCol;        // Add title column
+               if (!t3lib_div::inList($rowlist,'_CONTROL_'))   {
+                       $this->fieldArray[] = '_CONTROL_';
                }
                if ($this->showClipboard)       {
-                       $this->fieldArray[] = "_CLIPBOARD_";
+                       $this->fieldArray[] = '_CLIPBOARD_';
                }
                if ($this->searchLevels)        {
-                       $this->fieldArray[]="_PATH_";
+                       $this->fieldArray[]='_PATH_';
                }
-               $this->fieldArray=array_unique(array_merge($this->fieldArray,t3lib_div::trimExplode(",",$rowlist,1)));
+                       // Cleaning up:
+               $this->fieldArray=array_unique(array_merge($this->fieldArray,t3lib_div::trimExplode(',',$rowlist,1)));
                if ($this->noControlPanels)     {
                        $tempArray = array_flip($this->fieldArray);
-                       unset($tempArray["_CONTROL_"]);
-                       unset($tempArray["_CLIPBOARD_"]);
+                       unset($tempArray['_CONTROL_']);
+                       unset($tempArray['_CLIPBOARD_']);
                        $this->fieldArray = array_keys($tempArray);
                }
-               
-                       // Select fields:
+
+                       // Creating the list of fields to include in the SQL query:
                $selectFields = $this->fieldArray;
-               $selectFields[] = "uid";
-               $selectFields[] = "pid";
+               $selectFields[] = 'uid';
+               $selectFields[] = 'pid';
                if ($thumbsCol) $selectFields[] = $thumbsCol;   // adding column for thumbnails
-               if ($table=="pages")    {
-                       if (t3lib_extMgm::isLoaded("cms"))      {
-                               $selectFields[] = "module";
-                               $selectFields[] = "extendToSubpages";
+               if ($table=='pages')    {
+                       if (t3lib_extMgm::isLoaded('cms'))      {
+                               $selectFields[] = 'module';
+                               $selectFields[] = 'extendToSubpages';
                        }
-                       $selectFields[] = "doktype";
+                       $selectFields[] = 'doktype';
+               }
+               if (is_array($TCA[$table]['ctrl']['enablecolumns']))    {
+                       $selectFields = array_merge($selectFields,$TCA[$table]['ctrl']['enablecolumns']);
                }
-               if (is_array($TCA[$table]["ctrl"]["enablecolumns"]))    {
-                       $selectFields = array_merge($selectFields,$TCA[$table]["ctrl"]["enablecolumns"]);
+               if ($TCA[$table]['ctrl']['type'])       {
+                       $selectFields[] = $TCA[$table]['ctrl']['type'];
                }
-               if ($TCA[$table]["ctrl"]["type"])       {
-                       $selectFields[] = $TCA[$table]["ctrl"]["type"];
+               if ($TCA[$table]['ctrl']['typeicon_column'])    {
+                       $selectFields[] = $TCA[$table]['ctrl']['typeicon_column'];
                }
-               if ($TCA[$table]["ctrl"]["typeicon_column"])    {
-                       $selectFields[] = $TCA[$table]["ctrl"]["typeicon_column"];
+               if ($TCA[$table]['ctrl']['versioning']) {
+                       $selectFields[] = 't3ver_id';
                }
-               if ($TCA[$table]["ctrl"]["label_alt"])  {
-                       $selectFields = array_merge($selectFields,t3lib_div::trimExplode(",",$TCA[$table]["ctrl"]["label_alt"],1));
+               if ($TCA[$table]['ctrl']['label_alt'])  {
+                       $selectFields = array_merge($selectFields,t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1));
                }
                $selectFields = array_unique($selectFields);            // Unique list!
                $selectFields = array_intersect($selectFields,$this->makeFieldList($table,1));          // Making sure that the fields in the field-list ARE in the field-list from TCA!
-               $selFieldList = implode(",",$selectFields);             // implode it into a list of fields for the SQL-statement.
+               $selFieldList = implode(',',$selectFields);             // implode it into a list of fields for the SQL-statement.
+
+                       // Create the SQL query for selecting the elements in the listing:
+               $queryParts = $this->makeQueryArray($table, $id,'',$selFieldList);      // (API function from class.db_list.inc)
+               $this->setTotalItems($queryParts);              // Finding the total amount of records on the page (API function from class.db_list.inc)
+
+                       // Init:
+               $dbCount = 0;
+               $out = '';
 
-                       // Query:               
-               $query = $this->makeQuery($table, $id,"",$selFieldList);
-               $this->setTotalItems();
-               $dbCount=0;
-               
+                       // If the count query returned any number of records, we perform the real query, selecting records.
                if ($this->totalItems)  {
-#$pt=t3lib_div::milliseconds();                
-                       $result = mysql(TYPO3_db,$query);
-                       if (mysql_error()) {echo mysql_error(); debug($query);}
-                       $dbCount = mysql_num_rows($result);
-#debug(array(t3lib_div::milliseconds()-$pt,$table));
+                       $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
+                       $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
                }
-               $out="";
+
+               $LOISmode = $this->listOnlyInSingleTableMode && !$this->table;
+
+                       // If any records was selected, render the list:
                if ($dbCount)   {
-                               // Start table:
-                       $out.='<table border=0 cellpadding=0 cellspacing=0>';
 
-                               // half line is drawn
-                       $theData = Array();
-                       if (!$this->table && !$rowlist) {
-//                             $theData[$titleCol] = $this->widthGif;  // 
-                               $theData[$titleCol] = '<img src=clear.gif width="'.($GLOBALS["SOBE"]->MOD_SETTINGS["bigControlPanel"]?"230":"350").'" height=1>';
-                               if (in_array("_CONTROL_",$this->fieldArray))    $theData["_CONTROL_"]="";
-                               if (in_array("_CLIPBOARD_",$this->fieldArray))  $theData["_CLIPBOARD_"]="";
+                               // Half line is drawn between tables:
+                       if (!$LOISmode) {
+                               $theData = Array();
+                               if (!$this->table && !$rowlist) {
+                                       $theData[$titleCol] = '<img src="clear.gif" width="'.($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel']?'230':'350').'" height="1" alt="" />';
+                                       if (in_array('_CONTROL_',$this->fieldArray))    $theData['_CONTROL_']='';
+                                       if (in_array('_CLIPBOARD_',$this->fieldArray))  $theData['_CLIPBOARD_']='';
+                               }
+                               $out.=$this->addelement(0,'',$theData,'',$this->leftMargin);
                        }
-                       $out.=$this->addelement(0,'',$theData,'',$this->leftMargin);
 
-                               // header line is drawn
+                               // Header line is drawn
                        $theData = Array();
                        if ($this->disableSingleTableView)      {
-                               $theData[$titleCol] = '<b>'.$GLOBALS["LANG"]->sL($TCA[$table]["ctrl"]["title"]).'</b> ('.$this->totalItems.')';
-                       } else $theData[$titleCol] = '<b>'.$this->linkWrapTable($table,$GLOBALS["LANG"]->sL($TCA[$table]["ctrl"]["title"]).'</b> ('.$this->totalItems.') <img src="'.$this->backPath.'gfx/'.($this->table?"minus":"plus").'bullet_list.gif" width="18" hspace=10 vspace=2 height="12" border="0" align="absmiddle"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL((!$this->table?"expandView":"contractView"))).'>');
-                       $theUpIcon = ($table=="pages"&&$this->id&&isset($this->pageRow["pid"])) ? '<A href="'.$this->listURL($this->pageRow["pid"]).'"><img src="gfx/i/pages_up.gif" width="18" height="16" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.upOneLevel")).' align="top"></a>':'';
-
-                       $out.=$this->addelement(1,$theUpIcon,$theData,' bgcolor="'.$this->headLineCol.'"','');
-
-                               // Fixing a order table for sortby tables
-                       $this->currentTable=array();
-                       $currentIdList=array();
-                       $doSort = ($TCA[$table]["ctrl"]["sortby"] && !$this->sortField);
-#                      if ($this->table || $doSort)    {
-                               $prevUid=0;
-                               $prevPrevUid=0;
-                               while ($row = mysql_fetch_assoc($result))       {
-                                       $currentIdList[] = $row["uid"];
+                               $theData[$titleCol] = '<span class="c-table">'.$GLOBALS['LANG']->sL($TCA[$table]['ctrl']['title'],1).'</span> ('.$this->totalItems.')';
+                       } else {
+                               $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="" />');
+                       }
+
+                               // CSH:
+                       $theData[$titleCol].= t3lib_BEfunc::cshItem($table,'',$this->backPath,'',FALSE,'margin-bottom:0px; white-space: normal;');
+
+                       if ($LOISmode)  {
+                               $out.='
+                                       <tr>
+                                               <td class="c-headLineTable" style="width:95%;">'.$theData[$titleCol].'</td>
+                                       </tr>';
+
+                               if ($GLOBALS['BE_USER']->uc["edit_showFieldHelp"])      {
+                                       $GLOBALS['LANG']->loadSingleTableDescription($table);
+                                       if (isset($GLOBALS['TCA_DESCR'][$table]['columns']['']))        {
+                                               $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$table.'.\',\'viewFieldHelp\',\'height=400,width=600,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
+                                               $out.='
+                                       <tr>
+                                               <td class="c-tableDescription">'.t3lib_BEfunc::helpTextIcon($table,'',$this->backPath,TRUE).$GLOBALS['TCA_DESCR'][$table]['columns']['']['description'].'</td>
+                                       </tr>';
+                                       }
+                               }
+                       } else {
+                               $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>':'';
+                               $out.=$this->addelement(1,$theUpIcon,$theData,' class="c-headLineTable"','');
+                       }
+
+                       If (!$LOISmode) {
+                                       // Fixing a order table for sortby tables
+                               $this->currentTable = array();
+                               $currentIdList = array();
+                               $doSort = ($TCA[$table]['ctrl']['sortby'] && !$this->sortField);
+
+                               $prevUid = 0;
+                               $prevPrevUid = 0;
+                               $accRows = array();     // Accumulate rows here
+                               while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))    {
+                                       $accRows[] = $row;
+                                       $currentIdList[] = $row['uid'];
                                        if ($doSort)    {
                                                if ($prevUid)   {
-                                                       $this->currentTable["prev"][$row["uid"]]=$prevPrevUid;
-                                                       $this->currentTable["next"][$prevUid]="-".$row["uid"];
-                                                       $this->currentTable["prevUid"][$row["uid"]]=$prevUid;
+                                                       $this->currentTable['prev'][$row['uid']] = $prevPrevUid;
+                                                       $this->currentTable['next'][$prevUid] = '-'.$row['uid'];
+                                                       $this->currentTable['prevUid'][$row['uid']] = $prevUid;
                                                }
-                                               $prevPrevUid = isset($this->currentTable["prev"][$row["uid"]]) ? -$prevUid : $row["pid"];
-                                               $prevUid=$row["uid"];
+                                               $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
+                                               $prevUid=$row['uid'];
                                        }
                                }
-                               mysql_data_seek($result,0);
-#                      }
-//                     debug($this->currentTable);
-
-                               // CSV initiated
-                       if ($this->csvOutput) $this->initCSV();
-
-                               // items
-                       $iOut="";
-                       $this->CBnames=array();
-                       $this->duplicateStack=array();
-                       $this->eCounter=$this->firstElementNumber;
-                       $cc=0;
-                       while ($row = mysql_fetch_assoc($result))       {
-                               list($flag,$code) = $this->fwd_rwd_nav($table);
-                               $iOut.=$code;
-                               if ($flag)      {
-                                       $cc++;
-                                       $row_bgColor=
-                                               $this->alternateBgColors ? 
-                                               (($cc%2)?'' :' bgColor="'.t3lib_div::modifyHTMLColor($GLOBALS["SOBE"]->doc->bgColor4,+10,+10,+10).'"') :
-                                               '';
-
-                                               // Initialization
-                                       $iconfile = t3lib_iconWorks::getIcon($table,$row);
-                                       $alttext = t3lib_BEfunc::getRecordIconAltText($row,$table);
-//                                     $recTitle = strip_tags($row[$titleCol]);                // commented out 300700
-//                                     $recTitle = htmlspecialchars($row[$titleCol]);
-                                       $recTitle = t3lib_BEfunc::getRecordTitle($table,$row,1);
-                                       
-                                       $this->counter++;
-
-                                               // The icon with link   
-                                       $theIcon = '<img src="'.$this->backPath.$iconfile.'" width=18 height=16 border=0'.t3lib_BEfunc::titleAttrib($alttext).'>';
-                                       $theIcon = $GLOBALS["SOBE"]->doc->wrapClickMenuOnIcon($theIcon,$table,$row["uid"]);
-
-                                               //      Preparing and getting the data-array
-                                       $theData = Array();
-                                       reset($this->fieldArray);
-                                       while(list(,$fCol)=each($this->fieldArray))     {
-                                               if ($fCol==$titleCol)   {
-                                                       $theData[$fCol] = $this->linkWrapItems($table,$row["uid"],$recTitle,$row)."&nbsp;";
-                                               } elseif ($fCol=="pid") {
-                                                       $theData[$fCol]=$row[$fCol];
-                                               } elseif ($fCol=="_PATH_") {
-                                                       $theData[$fCol]="&nbsp;".$this->recPath($row["pid"]);
-                                               } elseif ($fCol=="_CONTROL_") {
-                                                       $theData[$fCol]=$this->makeControl($table,$row);
-                                               } elseif ($fCol=="_CLIPBOARD_") {
-                                                       $theData[$fCol]=$this->makeClip($table,$row);
-                                               } else {
-                                                       $theData[$fCol]="&nbsp;".t3lib_BEfunc::getProcessedValueExtra($table,$fCol,$row[$fCol],100);
-                                               }
-                                       }
+                               $GLOBALS['TYPO3_DB']->sql_free_result($result);
+
+                                       // CSV initiated
+                               if ($this->csvOutput) $this->initCSV();
+
+                                       // Render items:
+                               $this->CBnames=array();
+                               $this->duplicateStack=array();
+                               $this->eCounter=$this->firstElementNumber;
+
+                               $iOut = '';
+                               $cc = 0;
+                               foreach($accRows as $row)       {
 
-                                       if ($this->csvOutput) $this->addToCSV($row);
-                                       $iOut.=$this->addelement(1,$theIcon,$theData,$row_bgColor);
-                                       
-                                               // Thumbsnails?
-                                       if ($this->thumbs && trim($row[$thumbsCol]))    {
-                                               $iOut.=$this->addelement(4,"", Array($titleCol=>$this->thumbCode($row,$table,$thumbsCol)),$row_bgColor);
+                                               // Forward/Backwards navigation links:
+                                       list($flag,$code) = $this->fwd_rwd_nav($table);
+                                       $iOut.=$code;
+
+                                               // If render item, increment counter and call function
+                                       if ($flag)      {
+                                               $cc++;
+                                               $iOut.=$this->renderListRow($table,$row,$cc,$titleCol,$thumbsCol);
                                        }
+
+                                               // Counter of total rows incremented:
+                                       $this->eCounter++;
                                }
-                               $this->eCounter++;      
+
+                                       // The header row for the table is now created:
+                               $out.=$this->renderListHeader($table,$currentIdList);
                        }
 
-                               // field header line is drawn:
-                       $theData = Array();
-                       reset($this->fieldArray);
-                       while(list(,$fCol)=each($this->fieldArray))     {
-                               $permsEdit = $this->calcPerms&($table=="pages"?2:16);
-                               if ($fCol=="_PATH_")    {
-                                       $theData[$fCol]="&nbsp;<i>[".$GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels._PATH_")."]</i>&nbsp;";
-                               } elseif ($fCol=="_CLIPBOARD_") {
+                               // The list of records is added after the header:
+                       $out.=$iOut;
+
+                               // ... and it is all wrapped in a table:
+                       $out='
+
+
+
+                       <!--
+                               DB listing of elements: "'.htmlspecialchars($table).'"
+                       -->
+                               <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist'.($LOISmode?' typo3-dblist-overview':'').'">
+                                       '.$out.'
+                               </table>';
+
+                               // Output csv if...
+                       if ($this->csvOutput)   $this->outputCSV($table);       // This ends the page with exit.
+               }
+
+                       // Return content:
+               return $out;
+       }
+
+       /**
+        * Rendering a single row for the list
+        *
+        * @param       string          Table name
+        * @param       array           Current record
+        * @param       integer         Counter, counting for each time an element is rendered (used for alternating colors)
+        * @param       string          Table field (column) where header value is found
+        * @param       string          Table field (column) where (possible) thumbnails can be found
+        * @return      string          Table row for the element
+        * @access private
+        * @see getTable()
+        */
+       function renderListRow($table,$row,$cc,$titleCol,$thumbsCol)    {
+               $iOut = '';
+
+                       // Background color, if any:
+               $row_bgColor=
+                       $this->alternateBgColors ?
+                       (($cc%2)?'' :' bgcolor="'.t3lib_div::modifyHTMLColor($GLOBALS['SOBE']->doc->bgColor4,+10,+10,+10).'"') :
+                       '';
+
+                       // Initialization
+               $alttext = t3lib_BEfunc::getRecordIconAltText($row,$table);
+               $recTitle = t3lib_BEfunc::getRecordTitle($table,$row);
+
+                       // Incr. counter.
+               $this->counter++;
+
+                       // The icon with link
+               $iconImg = t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'title="'.htmlspecialchars($alttext).'"');
+               $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg,$table,$row['uid']);
+
+                       // Preparing and getting the data-array
+               $theData = Array();
+               foreach($this->fieldArray as $fCol)     {
+                       if ($fCol==$titleCol)   {
+                               $theData[$fCol] = $this->linkWrapItems($table,$row['uid'],$recTitle,$row);
+                       } elseif ($fCol=='pid') {
+                               $theData[$fCol]=$row[$fCol];
+                       } elseif ($fCol=='_PATH_') {
+                               $theData[$fCol]=$this->recPath($row['pid']);
+                       } elseif ($fCol=='_CONTROL_') {
+                               $theData[$fCol]=$this->makeControl($table,$row);
+                       } elseif ($fCol=='_CLIPBOARD_') {
+                               $theData[$fCol]=$this->makeClip($table,$row);
+                       } else {
+                               $theData[$fCol]=htmlspecialchars(t3lib_BEfunc::getProcessedValueExtra($table,$fCol,$row[$fCol],100));
+                       }
+               }
+
+                       // Add row to CSV list:
+               if ($this->csvOutput) $this->addToCSV($row);
+
+                       // Create element in table cells:
+               $iOut.=$this->addelement(1,$theIcon,$theData,$row_bgColor);
+
+                       // Render thumbsnails if a thumbnail column exists and there is content in it:
+               if ($this->thumbs && trim($row[$thumbsCol]))    {
+                       $iOut.=$this->addelement(4,'', Array($titleCol=>$this->thumbCode($row,$table,$thumbsCol)),$row_bgColor);
+               }
+
+                       // Finally, return table row element:
+               return $iOut;
+       }
+
+       /**
+        * Rendering the header row for a table
+        *
+        * @param       string          Table name
+        * @param       array           Array of the currectly displayed uids of the table
+        * @return      string          Header table row
+        * @access private
+        * @see getTable()
+        */
+       function renderListHeader($table,$currentIdList)        {
+               global $TCA, $LANG;
+
+                       // Init:
+               $theData = Array();
+
+                       // Traverse the fields:
+               foreach($this->fieldArray as $fCol)     {
+
+                               // Calculate users permissions to edit records in the table:
+                       $permsEdit = $this->calcPerms & ($table=='pages'?2:16);
+
+                       switch((string)$fCol)   {
+                               case '_PATH_':                  // Path
+                                       $theData[$fCol]='<i>['.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels._PATH_',1).']</i>';
+                               break;
+                               case '_CLIPBOARD_':             // Clipboard:
                                        $cells=array();
+
+                                               // If there are elements on the clipboard for this table, then display the "paste into" icon:
                                        $elFromTable = $this->clipObj->elFromTable($table);
                                        if (count($elFromTable))        {
-                                               $cells[]='<a href="'.$this->clipObj->pasteUrl($table,$this->id).'" onClick="return '.$this->clipObj->confirmMsg("pages",$this->pageRow,"into",$elFromTable).'"><img src="gfx/clip_pasteafter.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_paste")).'></a><img src=clear.gif width=2 height=1>';
+                                               $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl($table,$this->id)).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg('pages',$this->pageRow,'into',$elFromTable)).'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_paste',1).'" alt="" />'.
+                                                               '</a>';
                                        }
-                                       if ($this->clipObj->current!="normal")  {
-                                               $cells[]=$this->linkClipboardHeaderIcon('<img src="gfx/clip_copy.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_selectMarked")).'>',$table,"setCB");
 
-                                               $editIdList = implode(",",$currentIdList);
-#debug(array($editIdList,$table));
+                                               // If the numeric clipboard pads are enabled, display the control icons for that:
+                                       if ($this->clipObj->current!='normal')  {
+
+                                                       // The "select" link:
+                                               $cells[]=$this->linkClipboardHeaderIcon('<img'.t3lib_iconWorks::skinImg('','gfx/clip_copy.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_selectMarked',1).'" alt="" />',$table,'setCB');
+
+                                                       // The "edit marked" link:
+                                               $editIdList = implode(',',$currentIdList);
                                                $editIdList = "'+editList('".$table."','".$editIdList."')+'";
-                                               $params="&edit[".$table."][".$editIdList."]=edit&disHelp=1";
-                                               $cells[]='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="gfx/edit2.gif" width="11" height="12" hspace=2 border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_editMarked")).'></a>';
+                                               $params='&edit['.$table.']['.$editIdList.']=edit&disHelp=1';
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg('','gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('clip_editMarked',1).'" alt="" />'.
+                                                               '</a>';
 
-                                               $cells[]=$this->linkClipboardHeaderIcon('<img src="gfx/garbage.gif" width="11" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_deleteMarked")).'>',$table,"delete",sprintf($GLOBALS["LANG"]->getLL("clip_deleteMarkedWarning"),$GLOBALS["LANG"]->sL($TCA[$table]["ctrl"]["title"])));
-                                               $cells[]='<img src=clear.gif width=6 height=1>';
-                                               $cells[]='<a href="#" onClick="checkOffCB(\''.implode(",",$this->CBnames).'\'); return false;"><img src="gfx/clip_select.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_markRecords")).'></a>';
+                                                       // The "Delete marked" link:
+                                               $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'])));
+
+                                                       // The "Select all" link:
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars('checkOffCB(\''.implode(',',$this->CBnames).'\'); return false;').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg('','gfx/clip_select.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_markRecords',1).'" alt="" />'.
+                                                               '</a>';
                                        } else {
-                                               $cells[]="&nbsp;";
+                                               $cells[]='';
                                        }
-                                       $theData[$fCol]=implode("",$cells);
-                               } elseif ($fCol=="_CONTROL_") {
-                                       if (!$TCA[$table]["ctrl"]["readOnly"])  {
-                                               if ($this->calcPerms&($table=="pages"?8:16) && $this->showNewRecLink($table))   {
+                                       $theData[$fCol]=implode('',$cells);
+                               break;
+                               case '_CONTROL_':               // Control panel:
+                                       if (!$TCA[$table]['ctrl']['readOnly'])  {
+
+                                                       // If new records can be created on this page, add links:
+                                               if ($this->calcPerms&($table=='pages'?8:16) && $this->showNewRecLink($table))   {
                                                        if ($table=="tt_content" && $this->newWizards)  {
-                                                               $theData[$fCol]='<A HREF="#" onClick="return jumpExt(\'db_new_content_el.php?id='.$this->id.'\');"><img src="'.$this->backPath.'gfx/new_'.($table=="pages"?"page":"el").'.gif" width='.($table=="pages"?13:11).' height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("new")).'></a>';
-                                                       } elseif ($table=="pages" && $this->newWizards) {
-                                                               $theData[$fCol]='<A HREF="db_new.php?id='.$this->id.'&pagesOnly=1returnUrl='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI")).'"><img src="'.$this->backPath.'gfx/new_'.($table=="pages"?"page":"el").'.gif" width='.($table=="pages"?13:11).' height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("new")).'></a>';
+                                                                       //  If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
+                                                               $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
+                                                               $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
+                                                               $newContentWizScriptPath = t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
+
+                                                               $theData[$fCol]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\''.$newContentWizScriptPath.'?id='.$this->id.'\');').'">'.
+                                                                                               '<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="" />'.
+                                                                                               '</a>';
+                                                       } elseif ($table=='pages' && $this->newWizards) {
+                                                               $theData[$fCol]='<a href="'.htmlspecialchars('db_new.php?id='.$this->id.'&pagesOnly=1returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'">'.
+                                                                                               '<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="" />'.
+                                                                                               '</a>';
                                                        } else {
-                                                               $params="&edit[".$table."][".$this->id."]=new";
-                                                               $theData[$fCol]='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="'.$this->backPath.'gfx/new_'.($table=="pages"?"page":"el").'.gif" width='.($table=="pages"?13:11).' height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("new")).'></a>';
+                                                               $params='&edit['.$table.']['.$this->id.']=new';
+                                                               $theData[$fCol]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                                                                               '<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="" />'.
+                                                                                               '</a>';
                                                        }
                                                }
+
+                                                       // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
                                                if ($permsEdit && $this->table && is_array($currentIdList))     {
-                                                       $editIdList = implode(",",$currentIdList);
+                                                       $editIdList = implode(',',$currentIdList);
                                                        if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
-                                                       $params="&edit[".$table."][".$editIdList."]=edit&columnsOnly=".implode(",",$this->fieldArray)."&disHelp=1";
-                                                       $theData[$fCol].='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="'.$this->backPath.'gfx/edit2.gif" width=11 height=12 vspace=2 border=0 align="top"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("editShownColumns")).'></a>';
+                                                       $params='&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.implode(',',$this->fieldArray).'&disHelp=1';
+                                                       $theData[$fCol].='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('editShownColumns',1).'" alt="" />'.
+                                                                                       '</a>';
                                                }
                                        }
-                               } else {
-                                       $theData[$fCol]="";
-                                       $theData[$fCol].='&nbsp;';
+                               break;
+                               default:                        // Regular fields header:
+                                       $theData[$fCol]='';
                                        if ($this->table && is_array($currentIdList))   {
-                                               if ($this->clipNumPane()) $theData[$fCol].='<A HREF="'.$this->listURL("",-1).'&duplicateField='.$fCol.'"><img src="gfx/select_duplicates.gif" width="11" height="11" vspace=2 border="0" align=top'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_duplicates")).'></a>';
-                                               if (!$TCA[$table]["ctrl"]["readOnly"] && $permsEdit && $TCA[$table]["columns"][$fCol])  {
-                                                       $editIdList = implode(",",$currentIdList);
+
+                                                       // If the numeric clipboard pads are selected, show duplicate sorting link:
+                                               if ($this->clipNumPane()) {
+                                                       $theData[$fCol].='<a href="'.htmlspecialchars($this->listURL('',-1).'&duplicateField='.$fCol).'">'.
+                                                                                       '<img'.t3lib_iconWorks::skinImg('','gfx/select_duplicates.gif','width="11" height="11"').' title="'.$LANG->getLL('clip_duplicates',1).'" alt="" />'.
+                                                                                       '</a>';
+                                               }
+
+                                                       // If the table can be edited, add link for editing THIS field for all listed records:
+                                               if (!$TCA[$table]['ctrl']['readOnly'] && $permsEdit && $TCA[$table]['columns'][$fCol])  {
+                                                       $editIdList = implode(',',$currentIdList);
                                                        if ($this->clipNumPane()) $editIdList = "'+editList('".$table."','".$editIdList."')+'";
-                                                       $params="&edit[".$table."][".$editIdList."]=edit&columnsOnly=".$fCol."&disHelp=1";
-                                                       $theData[$fCol].='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="'.$this->backPath.'gfx/edit2.gif" width=11 height=12 vspace=2 border=0 align="top"'.t3lib_BEfunc::titleAttrib(sprintf($GLOBALS["LANG"]->getLL("editThisColumn"),ereg_replace(":$","",trim($GLOBALS["LANG"]->sL(t3lib_BEfunc::getItemLabel($table,$fCol)))))).'></a>';
+                                                       $params='&edit['.$table.']['.$editIdList.']=edit&columnsOnly='.$fCol.'&disHelp=1';
+                                                       $iTitle = sprintf($LANG->getLL('editThisColumn'),ereg_replace(':$','',trim($LANG->sL(t3lib_BEfunc::getItemLabel($table,$fCol)))));
+                                                       $theData[$fCol].='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2.gif','width="11" height="12"').' title="'.htmlspecialchars($iTitle).'" alt="" />'.
+                                                                                       '</a>';
                                                }
-                                       } else {
-//                                             $theData[$fCol].='&nbsp;';
                                        }
-                                       $theData[$fCol].=$this->addSortLink($GLOBALS["LANG"]->sL(t3lib_BEfunc::getItemLabel($table,$fCol,"&nbsp;<i>[|]</i>&nbsp;")),$fCol,$table);;
-                               }
+                                       $theData[$fCol].=$this->addSortLink($LANG->sL(t3lib_BEfunc::getItemLabel($table,$fCol,'<i>[|]</i>')),$fCol,$table);
+                               break;
                        }
-                       $out.=$this->addelement(1,'',$theData,' bgcolor="'.$this->subHeadLineCol.'"','');
-                               // finish
-                       $out.=$iOut;
-                       $out.="</table>";       
-
-
-                       
-                               // Output csv if...
-                       if ($this->csvOutput)   $this->outputCSV($table);       // This ends the page with exit.
                }
-               return $out;
-       }
-       function clipNumPane()  {
-               return in_Array("_CLIPBOARD_",$this->fieldArray) && $this->clipObj->current!="normal";
-       }
-       function addSortLink($code,$field,$table)       {
-               if ($field=="_CONTROL_")        return $code;
-               if ($field=="_CLIPBOARD_")      return $code;
-               if ($this->disableSingleTableView)      return $code;
-               if ($field=="_PATH_")   $field=pid;
-               return '<A HREF="'.$this->listURL("",-1,"sortField,sortRev,table").'&table='.$table.'&sortField='.$field.'&sortRev='.($this->sortRev || ($this->sortField!=$field)?0:1).'">'.$code.
-               ($this->sortField==$field?'<img src="gfx/red'.($this->sortRev?"up":"down").'.gif" hspace=2 width="7" height="4" border="0">':'').
-               '</a>';
+
+                       // Create and return header table row:
+               return $this->addelement(1,'',$theData,' class="c-headLine"','');
        }
+
+
+
+
+
+
+       /*********************************
+        *
+        * Rendering of various elements
+        *
+        *********************************/
+
+       /**
+        * Creates the control panel for a single record in the listing.
+        *
+        * @param       string          The table
+        * @param       array           The record for which to make the control panel.
+        * @return      string          HTML table with the control panel (unless disabled)
+        */
        function makeControl($table,$row)       {
-               global $TCA, $LANG;
-               if ($this->dontShowClipControlPanels)   return "";
+               global $TCA, $LANG, $SOBE;
 
+                       // Return blank, if disabled:
+               if ($this->dontShowClipControlPanels)   return '';
+
+                       // Initialize:
                t3lib_div::loadTCA($table);
                $cells=array();
 
-               if ($table=="pages")    {
-                       $localCalcPerms = $GLOBALS["BE_USER"]->calcPerms(t3lib_BEfunc::getRecord("pages",$row["uid"]));
+                       // If the listed table is 'pages' we have to request the permission settings for each page:
+               if ($table=='pages')    {
+                       $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid']));
                }
-               $permsEdit = ($table=="pages" && ($localCalcPerms&2)) || ($table!="pages" && ($this->calcPerms&16));
-               
-               
-                       // Show (only pages and tt_content elements)
-               if ($table=="pages" || $table=="tt_content")    {
-                       $params="&edit[".$table."][".$row["uid"]."]=edit";
-                       $cells[]='<a href="#" onClick="'.t3lib_BEfunc::viewOnClick($table=="tt_content"?$this->id."#".$row["uid"]:$row["uid"]).'"><img src="'.$this->backPath.'gfx/zoom.gif" width=12 height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.showPage")).'></a>';
+
+                       // This expresses the edit permissions for this particular element:
+               $permsEdit = ($table=='pages' && ($localCalcPerms&2)) || ($table!='pages' && ($this->calcPerms&16));
+
+                       // "Show" link (only pages and tt_content elements)
+               if ($table=='pages' || $table=='tt_content')    {
+                       $params='&edit['.$table.']['.$row['uid'].']=edit';
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($table=='tt_content'?$this->id.'#'.$row['uid']:$row['uid'])).'">'.
+                                       '<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="" />'.
+                                       '</a>';
                }
-               
-                       // Edit: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
+
+                       // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
                if ($permsEdit) {
-                       $params="&edit[".$table."][".$row["uid"]."]=edit";
-                       $cells[]='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="'.$this->backPath.'gfx/edit2'.(!$TCA[$table]["ctrl"]["readOnly"]?"":"_d").'.gif" width=11 height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("edit")).'></a>';
-               }
-               
-               if (($table=="tt_content" && $permsEdit) || ($table=="pages"))  {
-                       $cells[]='<A HREF="#" onClick="return jumpExt(\'move_el.php?table='.$table.'&uid='.$row["uid"].'\');"><img src="'.$this->backPath.'gfx/move_'.($table=="tt_content"?"record":"page").'.gif" width=11 height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("move_".($table=="tt_content"?"record":"page"))).'></a>';
-               }
-               
-               if ($GLOBALS["SOBE"]->MOD_SETTINGS["bigControlPanel"] || $this->table)  {
-                               // Info: (All records)
-                       $cells[]='<A HREF="#" onClick="top.launchView(\''.$table.'\', \''.$row["uid"].'\'); return false;"><img src="'.$this->backPath.'gfx/zoom2.gif" width=12 height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("showInfo")).'></a>';
-       
-                       if (!$TCA[$table]["ctrl"]["readOnly"])  {
-                                       // Revert
-                               $cells[]='<A HREF="#" onClick="return jumpExt(\'show_rechis.php?element='.rawurlencode($table.":".$row["uid"]).'\',\'#latest\');"><img src="'.$this->backPath.'gfx/history2.gif"  width="13" height="12" border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("history")).' align="top"></a>';
-
-                                       // Perms
-                               if ($table=="pages" && $GLOBALS["BE_USER"]->check("modules","web_perm"))        {
-                                       $cells[]='<A HREF="mod/web/perm/index.php?id='.$row["uid"].'&return_id='.$row["uid"].'&edit=1"><img src="'.$this->backPath.'gfx/perm.gif" width="7" hspace=2 height="12" border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("permissions")).' align="top"></a>';
+                       $params='&edit['.$table.']['.$row['uid'].']=edit';
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/edit2'.(!$TCA[$table]['ctrl']['readOnly']?'':'_d').'.gif','width="11" height="12"').' title="'.$LANG->getLL('edit',1).'" alt="" />'.
+                                       '</a>';
+               }
+
+                       // "Move" wizard link for pages/tt_content elements:
+               if (($table=="tt_content" && $permsEdit) || ($table=='pages'))  {
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'move_el.php?table='.$table.'&uid='.$row['uid'].'\');').'">'.
+                                       '<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="" />'.
+                                       '</a>';
+               }
+
+                       // If the extended control panel is enabled OR if we are seeing a single table:
+               if ($SOBE->MOD_SETTINGS['bigControlPanel'] || $this->table)     {
+
+                               // "Info": (All records)
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'">'.
+                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/zoom2.gif','width="12" height="12"').' title="'.$LANG->getLL('showInfo',1).'" alt="" />'.
+                                       '</a>';
+
+                               // If the table is NOT a read-only table, then show these links:
+                       if (!$TCA[$table]['ctrl']['readOnly'])  {
+
+                                       // "Revert" link (history/undo)
+                               $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpExt(\'show_rechis.php?element='.rawurlencode($table.':'.$row['uid']).'\',\'#latest\');').'">'.
+                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/history2.gif','width="13" height="12"').' title="'.$LANG->getLL('history',1).'" alt="" />'.
+                                               '</a>';
+
+                                       // "Edit Perms" link:
+                               if ($table=='pages' && $GLOBALS['BE_USER']->check('modules','web_perm'))        {
+                                       $cells[]='<a href="'.htmlspecialchars('mod/web/perm/index.php?id='.$row['uid'].'&return_id='.$row['uid'].'&edit=1').'">'.
+                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/perm.gif','width="7" height="12"').' title="'.$LANG->getLL('permissions',1).'" alt="" />'.
+                                                       '</a>';
                                }
-       
-                                       // New :
-                               if ($TCA[$table]["ctrl"]["sortby"] || $TCA[$table]["ctrl"]["useColumnsForDefaultValues"])       {       // ONLY if the records in the table are sorted by a "sortby"-row
+
+                                       // "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):
+                               if ($TCA[$table]['ctrl']['sortby'] || $TCA[$table]['ctrl']['useColumnsForDefaultValues'])       {
                                        if (
-                                               ($table!="pages" && ($this->calcPerms&16)) ||   // For NON-pages, must have permission to edit content on this parent page
-                                               ($table=="pages" && ($this->calcPerms&8))               // For pages, must have permission to create new pages here.
-                                               )       {       
+                                               ($table!='pages' && ($this->calcPerms&16)) ||   // For NON-pages, must have permission to edit content on this parent page
+                                               ($table=='pages' && ($this->calcPerms&8))               // For pages, must have permission to create new pages here.
+                                               )       {
                                                if ($this->showNewRecLink($table))      {
-                                                       $params="&edit[".$table."][".(-$row["uid"])."]=new";
-                                                       $cells[]='<A HREF="#" onClick="'.t3lib_BEfunc::editOnClick($params,"",-1).'"><img src="'.$this->backPath.'gfx/new_'.($table=="pages"?"page":"el").'.gif" width='.($table=="pages"?13:11).' height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("new".($table=="pages"?"Page":"Record"))).'></a>';
+                                                       $params='&edit['.$table.']['.(-$row['uid']).']=new';
+                                                       $cells[]='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'">'.
+                                                                       '<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="" />'.
+                                                                       '</a>';
                                                }
-                                       } 
+                                       }
                                }
 
-                                       // Up/Down
-                               if ($permsEdit && $TCA[$table]["ctrl"]["sortby"]  && !$this->sortField && !$this->searchLevels) {       //
-                                       if (isset($this->currentTable["prev"][$row["uid"]]))    {       // Up
-                                               $params="&cmd[".$table."][".$row["uid"]."][move]=".$this->currentTable["prev"][$row["uid"]];
-                                               $cells[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_up.gif" width=11 height=10 border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("moveUp")).' align="top"></a>';
+                                       // "Up/Down" links
+                               if ($permsEdit && $TCA[$table]['ctrl']['sortby']  && !$this->sortField && !$this->searchLevels) {
+                                       if (isset($this->currentTable['prev'][$row['uid']]))    {       // Up
+                                               $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prev'][$row['uid']];
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_up.gif','width="11" height="10"').' title="'.$LANG->getLL('moveUp',1).'" alt="" />'.
+                                                               '</a>';
                                        } else {
-                                               $cells[]='<img src="clear.gif" width=11 height=10 align="top">';
+                                               $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_up.gif','width="11" height="10"',2).' alt="" />';
                                        }
-                                       if ($this->currentTable["next"][$row["uid"]])   {       // Down
-                                               $params="&cmd[".$table."][".$row["uid"]."][move]=".$this->currentTable["next"][$row["uid"]];
-                                               $cells[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_down.gif" width=11 height=10 border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("moveDown")).' align="top"></a>';
+                                       if ($this->currentTable['next'][$row['uid']])   {       // Down
+                                               $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['next'][$row['uid']];
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_down.gif','width="11" height="10"').' title="'.$LANG->getLL('moveDown',1).'" alt="" />'.
+                                                               '</a>';
                                        } else {
-                                               $cells[]='<img src="clear.gif" width=11 height=10 align="top">';
+                                               $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_down.gif','width="11" height="10"',2).' alt="" />';
                                        }
                                }
-               
-                                       // Hide
-                               $hiddenField = $TCA[$table]["ctrl"]["enablecolumns"]["disabled"];
-                               if ($permsEdit && $hiddenField && $TCA[$table]["columns"][$hiddenField] && (!$TCA[$table]["columns"][$hiddenField]["exclude"] || $GLOBALS["BE_USER"]->check("non_exclude_fields",$table.":".$hiddenField)))     {
+
+                                       // "Hide/Unhide" links:
+                               $hiddenField = $TCA[$table]['ctrl']['enablecolumns']['disabled'];
+                               if ($permsEdit && $hiddenField && $TCA[$table]['columns'][$hiddenField] && (!$TCA[$table]['columns'][$hiddenField]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$table.':'.$hiddenField)))     {
                                        if ($row[$hiddenField]) {
-                                               $params="&data[".$table."][".$row["uid"]."][".$hiddenField."]=0";
-                                               $cells[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_unhide.gif" width=11 height=10 border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("unHide".($table=="pages"?"Page":""))).' align="top"></a>';
+                                               $params='&data['.$table.']['.$row['uid'].']['.$hiddenField.']=0';
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_unhide.gif','width="11" height="10"').' title="'.$LANG->getLL('unHide'.($table=='pages'?'Page':''),1).'" alt="" />'.
+                                                               '</a>';
                                        } else {
-                                               $params="&data[".$table."][".$row["uid"]."][".$hiddenField."]=1";
-                                               $cells[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_hide.gif" width=11 height=10 border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("hide".($table=="pages"?"Page":""))).' align="top"></a>';
+                                               $params='&data['.$table.']['.$row['uid'].']['.$hiddenField.']=1';
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_hide.gif','width="11" height="10"').' title="'.$LANG->getLL('hide'.($table=='pages'?'Page':''),1).'" alt="" />'.
+                                                               '</a>';
                                        }
                                }
-               
-                                       // Delete
+
+                                       // "Delete" link:
                                if (
-                                       ($table=="pages" && ($localCalcPerms&4)) || ($table!="pages" && ($this->calcPerms&16))
+                                       ($table=='pages' && ($localCalcPerms&4)) || ($table!='pages' && ($this->calcPerms&16))
                                        )       {
-                                       $params="&cmd[".$table."][".$row["uid"]."][delete]=1";
-                                       $cells[]='<A HREF="#" onClick="if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL("deleteWarning")).')) {jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');} return false;"><img src="'.$this->backPath.'gfx/garbage.gif" width=11 height=12 border=0 align="top"'.t3lib_BEfunc::titleAttrib($LANG->getLL("delete")).'></a>';
+                                       $params='&cmd['.$table.']['.$row['uid'].'][delete]=1';
+                                       $cells[]='<a href="#" onclick="'.htmlspecialchars('if (confirm('.$LANG->JScharCode($LANG->getLL('deleteWarning')).')) {jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');} return false;').'">'.
+                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/garbage.gif','width="11" height="12"').' title="'.$LANG->getLL('delete',1).'" alt="" />'.
+                                                       '</a>';
                                }
-               
-                                       // Levels
-                               if ($permsEdit && $table=="pages" && !$this->searchLevels)      {
+
+                                       // "Levels" links: Moving pages into new levels...
+                               if ($permsEdit && $table=='pages' && !$this->searchLevels)      {
+
+                                               // Up (Paste as the page right after the current parent page)
                                        if ($this->calcPerms&8) {
-                                               $params="&cmd[".$table."][".$row["uid"]."][move]=".-$this->id;
-                                               $cells[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_left.gif" width=11 height=10 border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("prevLevel")).' align="top"></a>';
+                                               $params='&cmd['.$table.']['.$row['uid'].'][move]='.-$this->id;
+                                               $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_left.gif','width="11" height="10"').' title="'.$LANG->getLL('prevLevel',1).'" alt="" />'.
+                                                               '</a>';
                                        }
-                                               // Down
-                                       if ($this->currentTable["prevUid"][$row["uid"]])        {
-                                               $localCalcPerms = $GLOBALS["BE_USER"]->calcPerms(t3lib_BEfunc::getRecord("pages",$this->currentTable["prevUid"][$row["uid"]]));
+                                               // Down (Paste as subpage to the page right above)
+                                       if ($this->currentTable['prevUid'][$row['uid']])        {
+                                               $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$this->currentTable['prevUid'][$row['uid']]));
                                                if ($localCalcPerms&8)  {
-                                                       $params="&cmd[".$table."][".$row["uid"]."][move]=".$this->currentTable["prevUid"][$row["uid"]];
-                                                       $cells[]='<A HREF="#" onClick="return jumpToUrl(\''.$GLOBALS["SOBE"]->doc->issueCommand($params,-1).'\');"><img src="'.$this->backPath.'gfx/button_right.gif" width=11 height=10 border=0'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("nextLevel")).' align="top"></a>';
+                                                       $params='&cmd['.$table.']['.$row['uid'].'][move]='.$this->currentTable['prevUid'][$row['uid']];
+                                                       $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpToUrl(\''.$SOBE->doc->issueCommand($params,-1).'\');').'">'.
+                                                                       '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"').' title="'.$LANG->getLL('nextLevel',1).'" alt="" />'.
+                                                                       '</a>';
                                                } else {
-                                                       $cells[]='<img src="clear.gif" width=11 height=10 align="top">';
+                                                       $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"',2).' alt="" />';
                                                }
                                        } else {
-                                               $cells[]='<img src="clear.gif" width=11 height=10 align="top">';
+                                               $cells[]='<img src="clear.gif" '.t3lib_iconWorks::skinImg($this->backPath,'gfx/button_right.gif','width="11" height="10"',2).' alt="" />';
                                        }
                                }
                        }
                }
-               
-               if ($lockInfo=t3lib_BEfunc::isRecordLocked($table,$row["uid"])) {
-//                     debug($lockInfo);
-                       $cells[]='<a href="#" onClick="alert('.$GLOBALS['LANG']->JScharCode($lockInfo["msg"]).');return false;"><img src="gfx/recordlock_warning3.gif" width="17" height="12" border="0"'.t3lib_BEfunc::titleAttrib($lockInfo["msg"]).'></a>';
+
+                       // If the record is edit-locked by another user, we will show a little warning sign:
+               if ($lockInfo=t3lib_BEfunc::isRecordLocked($table,$row['uid'])) {
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars('alert('.$LANG->JScharCode($lockInfo['msg']).');return false;').'">'.
+                                       '<img'.t3lib_iconWorks::skinImg('','gfx/recordlock_warning3.gif','width="17" height="12"').' title="'.htmlspecialchars($lockInfo['msg']).'" alt="" />'.
+                                       '</a>';
                }
-               
-               return '<table border=0 cellpadding=1 cellspacing=0 bgColor="'.$GLOBALS["SOBE"]->doc->bgColor4.'"><tr><td>'.implode("</td><td>",$cells).'</td></tr></table>';
+
+
+                       // Compile items into a DIV-element:
+               return '
+                                                                                       <!-- CONTROL PANEL: '.$table.':'.$row['uid'].' -->
+                                                                                       <div class="typo3-DBctrl">'.implode('',$cells).'</div>';
        }
+
+       /**
+        * Creates the clipboard panel for a single record in the listing.
+        *
+        * @param       string          The table
+        * @param       array           The record for which to make the clipboard panel.
+        * @return      string          HTML table with the clipboard panel (unless disabled)
+        */
        function makeClip($table,$row)  {
-               global $TCA;
-               if ($this->dontShowClipControlPanels)   return "";
+               global $TCA, $LANG;
+
+                       // Return blank, if disabled:
+               if ($this->dontShowClipControlPanels)   return '';
                $cells=array();
 
-               if ($this->clipObj->current=="normal")  {
-                       $isSel = (string)$this->clipObj->isSelected($table,$row["uid"]);
-                       $cells[]='<a href="#" onClick="return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row["uid"],1,($isSel=="copy"),array("returnUrl"=>"")).'\');"><img src="gfx/clip_copy'.($isSel=="copy"?"_h":"").'.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:cm.copy")).'></a>';
-                       $cells[]='<a href="#" onClick="return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row["uid"],0,($isSel=="cut"),array("returnUrl"=>"")).'\');"><img src="gfx/clip_cut'.($isSel=="cut"?"_h":"").'.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:cm.cut")).'></a>';
-               } else {
-                       $n=$table."|".$row["uid"];
+                       // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
+               if ($this->clipObj->current=='normal')  {       // For the "Normal" pad:
+
+                               // Show copy/cut icons:
+                       $isSel = (string)$this->clipObj->isSelected($table,$row['uid']);
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row['uid'],1,($isSel=='copy'),array('returnUrl'=>'')).'\');').'">'.
+                                       '<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="" />'.
+                                       '</a>';
+                       $cells[]='<a href="#" onclick="'.htmlspecialchars('return jumpSelf(\''.$this->clipObj->selUrlDB($table,$row['uid'],0,($isSel=='cut'),array('returnUrl'=>'')).'\');').'">'.
+                                       '<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="" />'.
+                                       '</a>';
+
+               } else {        // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
+
+                               // Setting name of the element in ->CBnames array:
+                       $n=$table.'|'.$row['uid'];
                        $this->CBnames[]=$n;
 
-                       $checked = ($this->clipObj->isSelected($table,$row["uid"])?" checked":"");
+                               // Check if the current element is selected and if so, prepare to set the checkbox as selected:
+                       $checked = ($this->clipObj->isSelected($table,$row['uid'])?' checked="checked"':'');
 
-                       $duplField = t3lib_div::GPvar("duplicateField");
-                       if ($duplField && isset($row[$duplField]))      {
-                               $checked="";
-                               if (in_array($row[$duplField], $this->duplicateStack))  {
-                                       $checked=" checked";
+                               // If the "duplicateField" value is set then select all elements which are duplicates...
+                       if ($this->duplicateField && isset($row[$this->duplicateField]))        {
+                               $checked='';
+                               if (in_array($row[$this->duplicateField], $this->duplicateStack))       {
+                                       $checked=' checked="checked"';
                                }
-                               $this->duplicateStack[] = $row[$duplField];
+                               $this->duplicateStack[] = $row[$this->duplicateField];
                        }
-                       
-                       $cells[]='<input type="hidden" name="CBH['.$n.']" value="0"><input type="checkbox" name="CBC['.$n.']" value="1" style="width:12;height:12;margin:0 0 0 0;"'.$checked.'>';
-                       $cells[]='<img src=clear.gif width=10 height=1>';
+
+                               // Adding the checkbox to the panel:
+                       $cells[]='<input type="hidden" name="CBH['.$n.']" value="0" /><input type="checkbox" name="CBC['.$n.']" value="1" class="smallCheckboxes"'.$checked.' />';
                }
-               
+
+                       // Now, looking for selected elements from the current table:
                $elFromTable = $this->clipObj->elFromTable($table);
-               if (count($elFromTable) && $TCA[$table]["ctrl"]["sortby"])      {
-                       $cells[]='<a href="'.$this->clipObj->pasteUrl($table,-$row["uid"]).'" onClick="return '.$this->clipObj->confirmMsg($table,$row,"after",$elFromTable).'"><img src="gfx/clip_pasteafter.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_pasteAfter")).'></a>';
-               }
-               $elFromTable = $this->clipObj->elFromTable("");
-               if ($table=="pages" && $elFromTable)    {
-                       $cells[]='<a href="'.$this->clipObj->pasteUrl("",$row["uid"]).'" onClick="return '.$this->clipObj->confirmMsg($table,$row,"into",$elFromTable).'"><img src="gfx/clip_pasteinto.gif" width="12" height="12" border="0"'.t3lib_BEfunc::titleAttrib($GLOBALS["LANG"]->getLL("clip_pasteInto")).'></a>';
+               if (count($elFromTable) && $TCA[$table]['ctrl']['sortby'])      {       // IF elements are found and they can be individually ordered, then add a "paste after" icon:
+                       $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl($table,-$row['uid'])).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg($table,$row,'after',$elFromTable)).'">'.
+                                       '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteafter.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_pasteAfter',1).'" alt="" />'.
+                                       '</a>';
                }
 
-               if ($GLOBALS["CLIENT"]["BROWSER"]=="net" && $GLOBALS["CLIENT"]["VERSION"]<5)    {
-                       $w100 = '';
-                       $w40 = '';
-               } else {
-                       $w100 = ' width="100%"';
-                       $w40 = ' width="40%"';
+                       // Now, looking for elements in general:
+               $elFromTable = $this->clipObj->elFromTable('');
+               if ($table=='pages' && count($elFromTable))     {
+                       $cells[]='<a href="'.htmlspecialchars($this->clipObj->pasteUrl('',$row['uid'])).'" onclick="'.htmlspecialchars('return '.$this->clipObj->confirmMsg($table,$row,'into',$elFromTable)).'">'.
+                                       '<img'.t3lib_iconWorks::skinImg('','gfx/clip_pasteinto.gif','width="12" height="12"').' title="'.$LANG->getLL('clip_pasteInto',1).'" alt="" />'.
+                                       '</a>';
                }
-               return '<table border=0 cellpadding=1 cellspacing=0 bgColor="'.$GLOBALS["SOBE"]->doc->bgColor5.'"'.$w100.'><tr><td'.$w40.'>&nbsp;</td><td align=center>'.implode("</td><td>",$cells).'</td><td'.$w40.'>&nbsp;</td></tr></table>';
+
+                       // Compile items into a DIV-element:
+               return '                                                        <!-- CLIPBOARD PANEL: '.$table.':'.$row['uid'].' -->
+                                                                                       <div class="typo3-clipCtrl">'.implode('',$cells).'</div>';
        }
+
+       /**
+        * Create the selector box for selecting fields to display from a table:
+        *
+        * @param       string          Table name
+        * @param       boolean         If true, form-fields will be wrapped around the table.
+        * @return      string          HTML table with the selector box (name: displayFields['.$table.'][])
+        */
        function fieldSelectBox($table,$formFields=1)   {
-               global $TCA;
+               global $TCA, $LANG;
+
+                       // Init:
                t3lib_div::loadTCA($table);
-               $formElements=array("","");
+               $formElements=array('','');
                if ($formFields)        {
-                       $formElements=array('<form action="'.$this->listURL().'" method="POST">','</form>');
+                       $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>');
                }
 
+                       // Load already selected fields, if any:
                $setFields=is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
-                       // Make level selector:
+
+                       // Request fields from table:
                $fields = $this->makeFieldList($table);
-               $fields[]="_PATH_";
-               $fields[]="_CONTROL_";
-               $fields[]="_CLIPBOARD_";
+
+                       // Add pseudo "control" fields
+               $fields[]='_PATH_';
+               $fields[]='_CONTROL_';
+               $fields[]='_CLIPBOARD_';
+
+                       // Create an option for each field:
                $opt=array();
-               reset($fields);
                $opt[] = '<option value=""></option>';
-               while(list(,$fN)=each($fields)) {
-                       $fL = is_array($TCA[$table]["columns"][$fN]) ? ereg_replace(":$","",$GLOBALS["LANG"]->sL($TCA[$table]["columns"][$fN]["label"])) : "[".$fN."]";
-                       $opt[] = '<option value="'.$fN.'"'.(in_array($fN,$setFields)?" selected":"").'>'.htmlspecialchars($fL).'</option>';
+               foreach($fields as $fN) {
+                       $fL = is_array($TCA[$table]['columns'][$fN]) ? ereg_replace(':$','',$LANG->sL($TCA[$table]['columns'][$fN]['label'])) : '['.$fN.']';    // Field label
+                       $opt[] = '
+                                                                                       <option value="'.$fN.'"'.(in_array($fN,$setFields)?' selected="selected"':'').'>'.htmlspecialchars($fL).'</option>';
                }
-               $lMenu = '<select size='.t3lib_div::intInRange(count($fields)+1,3,20).' multiple name="displayFields['.$table.'][]">'.implode("",$opt).'</select>';
-               
-                       // Table with the search box:
+
+                       // Compile the options into a multiple selector box:
+               $lMenu = '
+                                                                               <select size="'.t3lib_div::intInRange(count($fields)+1,3,20).'" multiple="multiple" name="displayFields['.$table.'][]">'.implode('',$opt).'
+                                                                               </select>
+                               ';
+
+                       // Table with the field selector::
                $content.= '
-               <table border=0 cellpadding=1 cellspacing=0>
-               '.$formElements[0].'
-                       <tr>
-                               <td><img src=clear.gif width='.$this->spaceSearchBoxFromLeft.' height=1></td>
-                               <td bgcolor="#9BA1A8">
-                                       <table border=0 cellpadding=0 cellspacing=0 bgcolor="'.$GLOBALS["TBE_TEMPLATE"]->bgColor4.'">
+                       '.$formElements[0].'
+
+                               <!--
+                                       Field selector for extended table view:
+                               -->
+                               <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-fieldSelect">
                                        <tr>
                                                <td>'.$lMenu.'</td>
-                                               <td><input type="Submit" name="search" value="'.$GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.setFields").'"></td>
+                                               <td><input type="submit" name="search" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.setFields',1).'" /></td>
                                        </tr>
-                                       </table>                        
-                               </td>
-                       </tr>'.$formElements[1].'
-               </table>
-               ';
+                               </table>
+                       '.$formElements[1];
                return $content;
        }
+
+
+
+
+
+
+
+
+
+
+
+       /*********************************
+        *
+        * Helper functions
+        *
+        *********************************/
+
+       /**
+        * Creates a link around $string. The link contains an onclick action which submits the script with some clipboard action.
+        * Currently, this is used for setting elements / delete elements.
+        *
+        * @param       string          The HTML content to link (image/text)
+        * @param       string          Table name
+        * @param       string          Clipboard command (eg. "setCB" or "delete")
+        * @param       string          Warning text, if any ("delete" uses this for confirmation)
+        * @return      string          <a> tag wrapped link.
+        */
+       function linkClipboardHeaderIcon($string,$table,$cmd,$warning='')       {
+               $onClickEvent = 'document.dblistForm.cmd.value=\''.$cmd.'\';document.dblistForm.cmd_table.value=\''.$table.'\';document.dblistForm.submit();';
+               if ($warning)   $onClickEvent = 'if (confirm('.$GLOBALS['LANG']->JScharCode($warning).')){'.$onClickEvent.'}';
+               return '<a href="#" onclick="'.htmlspecialchars($onClickEvent.'return false;').'">'.$string.'</a>';
+       }
+
+       /**
+        * Returns true if a numeric clipboard pad is selected/active
+        *
+        * @return      boolean
+        */
+       function clipNumPane()  {
+               return in_Array('_CLIPBOARD_',$this->fieldArray) && $this->clipObj->current!='normal';
+       }
+
+       /**
+        * Creates a sort-by link on the input string ($code).
+        * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
+        * Also some fields will not be possible to sort (including if single-table-view is disabled).
+        *
+        * @param       string          The string to link (text)
+        * @param       string          The fieldname represented by the title ($code)
+        * @param       string          Table name
+        * @return      string          Linked $code variable
+        */
+       function addSortLink($code,$field,$table)       {
+
+                       // Certain circumstances just return string right away (no links):
+               if ($field=='_CONTROL_' || $field=='_CLIPBOARD_' || $this->disableSingleTableView)      return $code;
+
+                       // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
+               if ($field=='_PATH_')   $field=pid;
+
+                       //       Create the sort link:
+               $sortUrl = $this->listURL('',-1,'sortField,sortRev,table').'&table='.$table.'&sortField='.$field.'&sortRev='.($this->sortRev || ($this->sortField!=$field)?0:1);
+               $sortArrow = ($this->sortField==$field?'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/red'.($this->sortRev?'up':'down').'.gif','width="7" height="4"').' alt="" />':'');
+
+                       // Return linked field:
+               return '<a href="'.htmlspecialchars($sortUrl).'">'.$code.
+                               $sortArrow.
+                               '</a>';
+       }
+
+       /**
+        * Returns the path for a certain pid
+        * The result is cached internally for the session, thus you can call this function as much as you like without performance problems.
+        *
+        * @param       integer         The page id for which to get the path
+        * @return      string          The path.
+        */
+       function recPath($pid)  {
+               if (!isset($this->recPath_cache[$pid])) {
+                       $this->recPath_cache[$pid] = t3lib_BEfunc::getRecordPath($pid,$this->perms_clause,20);
+               }
+               return $this->recPath_cache[$pid];
+       }
+
+       /**
+        * Returns true if a link for creating new records should be displayed for $table
+        *
+        * @param       string          Table name
+        * @return      boolean
+        */
+       function showNewRecLink($table) {
+               return !count($this->allowedNewTables) || in_array($table,$this->allowedNewTables);
+       }
+
+       /**
+        * 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.
+        * Uses REQUEST_URI as value.
+        *
+        * @return      string
+        */
+       function makeReturnUrl()        {
+               return '&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
+       }
+
+
+
+
+
+
+
+
+
+
+       /************************************
+        *
+        * CSV related functions
+        *
+        ************************************/
+
+       /**
+        * Initializes internal csvLines array with the header of field names
+        *
+        * @return      void
+        */
        function initCSV()      {
+
+                       // Reset:
                $this->csvLines=array();
-               
-               reset($this->fieldArray);
+
+                       // Getting header line with field names:
                $csvRow=array();
-               while(list(,$fN)=each($this->fieldArray))       {
+               foreach($this->fieldArray as $fN)       {
                        $csvRow[]=$fN;
                }
+
+                       // Set the header + an empty row:
                $this->setCsvRow($csvRow);
-               $this->csvLines[]="";
+               $this->csvLines[]='';
        }
+
+       /**
+        * Adds the content of input array $row to the CSV list:
+        *
+        * @param       array           Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
+        * @return      void
+        */
        function addToCSV($row) {
-               reset($this->fieldArray);
+
+                       // Traversing fields, adding values from $row:
                $csvRow=array();
-               while(list(,$fN)=each($this->fieldArray))       {
-                       if ($fN=="_PATH_")      {
-                               $csvRow[]=$this->recPath($row["pid"]);
+               foreach($this->fieldArray as $fN)       {
+                       if ($fN=='_PATH_')      {
+                               $csvRow[]=$this->recPath($row['pid']);
                        } else {
                                $csvRow[]=$row[$fN];
                        }
                }
+
+                       // Set the values in the CSV list
                $this->setCsvRow($csvRow);
        }
+
+       /**
+        * Adds input row of values to the internal csvLines array as a CSV formatted line
+        *
+        * @param       array           Array with values to be listed.
+        * @return      void
+        */
        function setCsvRow($csvRow)     {
                $this->csvLines[] = t3lib_div::csvValues($csvRow);
        }
+
+       /**
+        * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
+        * This function exits!
+        *
+        * @param       string          Filename prefix:
+        * @return      void            EXITS php execusion!
+        */
        function outputCSV($prefix)     {
-               $filename=$prefix."_".date("dmy-Hi").".csv";
-               $mimeType = "application/octet-stream";
-               Header("Content-Type: ".$mimeType);
-               Header("Content-Disposition: attachment; filename=".$filename);
+
+                       // Setting filename:
+               $filename=$prefix.'_'.date('dmy-Hi').'.csv';
+
+                       // Creating output header:
+               $mimeType = 'application/octet-stream';
+               Header('Content-Type: '.$mimeType);
+               Header('Content-Disposition: attachment; filename='.$filename);
+
+                       // Printing the content of the CSV lines:
                echo implode(chr(13).chr(10),$this->csvLines);
+
+                       // Exits:
                exit;
        }
-       function recPath($pid)  {
-               if (!isset($this->recPath_cache[$pid])) {
-                       $this->recPath_cache[$pid] = t3lib_BEfunc::getRecordPath ($pid,$this->perms_clause,20);
-               }
-               return $this->recPath_cache[$pid];
-       }
-       function showNewRecLink($table) {
-               return !count($this->allowedNewTables) || in_array($table,$this->allowedNewTables);
-       }
-       function makeReturnUrl()        {
-               return '&returnUrl='.rawurlencode(t3lib_div::getIndpEnv("REQUEST_URI"));
-       }
 }
 
 
-if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/class.db_list_extra.inc"])  {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/class.db_list_extra.inc"]);
-}
 
-?>
\ No newline at end of file
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc'])  {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list_extra.inc']);
+}
+?>