8561 Checkboxes and labels are aligned badly if in one line
[Packages/TYPO3.CMS.git] / typo3 / class.db_list.inc
index faa3b0e..aeb9362 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
+*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * Revised for TYPO3 3.6 December/2003 by Kasper Skaarhoj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *
- *   84: class recordList extends t3lib_recordList
- *  140:     function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)
- *  186:     function generateList()
- *  233:     function getSearchBox($formFields=1)
- *  276:     function showSysNotesForPage()
+ *   86: class recordList extends t3lib_recordList
+ *  148:     function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)
+ *  211:     function generateList()
+ *  275:     function getSearchBox($formFields=1)
+ *  319:     function showSysNotesForPage()
  *
  *              SECTION: Various helper functions
- *  353:     function setDispFields()
- *  378:     function thumbCode($row,$table,$field)
- *  391:     function makeQueryArray($table, $id, $addWhere="",$fieldList='*')
- *  433:     function setTotalItems($queryParts)
- *  449:     function makeSearchString($table)
- *  488:     function linkWrapTable($table,$code)
- *  505:     function linkWrapItems($table,$uid,$code,$row)
- *  532:     function listURL($altId='',$table=-1,$exclList='')
- *  551:     function requestUri()
- *  562:     function makeFieldList($table,$dontCheckUser=0)
- *  601:     function getTreeObject($id,$depth,$perms_clause)
+ *  396:     function setDispFields()
+ *  421:     function thumbCode($row,$table,$field)
+ *  434:     function makeQueryArray($table, $id, $addWhere="",$fieldList='*')
+ *  481:     function setTotalItems($queryParts)
+ *  497:     function makeSearchString($table)
+ *  536:     function linkWrapTable($table,$code)
+ *  553:     function linkWrapItems($table,$uid,$code,$row)
+ *  617:     function linkUrlMail($code,$testString)
+ *  644:     function listURL($altId='',$table=-1,$exclList='')
+ *  663:     function requestUri()
+ *  674:     function makeFieldList($table,$dontCheckUser=0)
+ *  721:     function getTreeObject($id,$depth,$perms_clause)
+ *  739:     function localizationRedirect($justLocalized)
  *
- * TOTAL FUNCTIONS: 15
+ * TOTAL FUNCTIONS: 17
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
@@ -76,7 +78,7 @@
 /**
  * Child class for rendering of Web > List (not the final class. see class.db_list_extra)
  *
- * @author     Kasper Skaarhoj <kasper@typo3.com>
+ * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  * @see localRecordList
 class recordList extends t3lib_recordList {
 
                // External, static:
-       var $tableList='';                                              // Specify a list of tables which are the only ones allowed to be displayed.
-       var $returnUrl='';                                              // Return URL
-       var $thumbs = 0;                                                // Boolean. Thumbnails on records containing files (pictures)
+       var $tableList='';                              // Specify a list of tables which are the only ones allowed to be displayed.
+       var $returnUrl='';                              // Return URL
+       var $thumbs = 0;                                // Boolean. Thumbnails on records containing files (pictures)
        var $itemsLimitPerTable = 20;                   // default Max items shown per table in "multi-table mode", may be overridden by tables.php
        var $itemsLimitSingleTable = 100;               // default Max items shown per table in "single-table mode", may be overridden by tables.php
        var $widthGif = '<img src="clear.gif" width="1" height="4" hspace="160" alt="" />';
        var $script = 'db_list.php';                    // Current script name
-       var $allFields=0;                                               // Indicates if all available fields for a user should be selected or not.
+       var $allFields=0;                               // Indicates if all available fields for a user should be selected or not.
+       var $localizationView=FALSE;                    // Whether to show localization view or not.
 
                // Internal, static: GPvar:
-       var $csvOutput=FALSE;                   // If set, csvList is outputted.
+       var $csvOutput=FALSE;                           // If set, csvList is outputted.
        var $sortField;                                 // Field, to sort list by
        var $sortRev;                                   // Field, indicating to sort in reverse order.
        var $displayFields;                             // Array, containing which fields to display in extended mode
-       var $duplicateField;                    // String, can contain the field name from a table which must have duplicate values marked.
+       var $duplicateField;                            // String, can contain the field name from a table which must have duplicate values marked.
 
                // Internal, static:
-       var $id;                                                // Page id
+       var $id;                                        // Page id
        var $table='';                                  // Tablename if single-table mode
-       var $firstElementNumber=0;              // Pointer for browsing list
-       var $searchString='';                   // Search string
-       var $searchLevels='';                   // Levels to search down.
+       var $listOnlyInSingleTableMode=FALSE;           // If true, records are listed only if a specific table is selected.
+       var $firstElementNumber=0;                      // Pointer for browsing list
+       var $searchString='';                           // Search string
+       var $searchLevels='';                           // Levels to search down.
        var $showLimit=0;                               // Number of records to show
        var $pidSelect='';                              // List of ids from which to select/search etc. (when search-levels are set high). See start()
-       var $perms_clause='';                   // Page select permissions
+       var $perms_clause='';                           // Page select permissions
        var $calcPerms=0;                               // Some permissions...
+       var $clickTitleMode = '';                       // Mode for what happens when a user clicks the title of a record.
+       var $modSharedTSconfig = array();               // Shared module configuration, used by localization features
+       var $pageRecord = array();              // Loaded with page record with version overlay if any.
+       var $hideTables = '';                   // Tables which should not get listed
+       var $tableTSconfigOverTCA = array(); //TSconfig which overwrites TCA-Settings
 
                // Internal, dynamic:
        var $JScode = '';                               // JavaScript code accumulation
@@ -117,10 +126,10 @@ class recordList extends t3lib_recordList {
        var $iLimit=0;                                  // "LIMIT " in SQL...
        var $eCounter=0;                                // Counting the elements no matter what...
        var $totalItems='';                             // Set to the total number of items for a table when selecting.
-       var $recPath_cache=array();             // Cache for record path
-       var $setFields=array();                 // Fields to display for the current table
-       var $currentTable = array();    // Used for tracking next/prev uids
-       var $duplicateStack=array();    // Used for tracking duplicate values of fields
+       var $recPath_cache=array();                     // Cache for record path
+       var $setFields=array();                         // Fields to display for the current table
+       var $currentTable = array();                    // Used for tracking next/prev uids
+       var $duplicateStack=array();                    // Used for tracking duplicate values of fields
 
 
 
@@ -155,6 +164,10 @@ class recordList extends t3lib_recordList {
                $this->displayFields = t3lib_div::_GP('displayFields');
                $this->duplicateField = t3lib_div::_GP('duplicateField');
 
+               if (t3lib_div::_GP('justLocalized'))    {
+                       $this->localizationRedirect(t3lib_div::_GP('justLocalized'));
+               }
+
                        // If thumbnails are disabled, set the "notfound" icon as default:
                if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
                        $this->thumbScript='gfx/notfound_thumb.gif';
@@ -168,12 +181,25 @@ class recordList extends t3lib_recordList {
                        // Set select levels:
                $sL=intval($this->searchLevels);
                $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
+
+                       // this will hide records from display - it has nothing todo with user rights!!
+               if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
+                       if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
+                               $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
+                       }
+               }
+
                if ($sL>0)      {
                        $tree = $this->getTreeObject($id,$sL,$this->perms_clause);
-                       $this->pidSelect = 'pid IN ('.implode($tree->ids,',').')';
+                       $this->pidSelect = 'pid IN ('.implode(',',$tree->ids).')';
                } else {
                        $this->pidSelect = 'pid='.intval($id);
                }
+
+                       // Initialize languages:
+               if ($this->localizationView)    {
+                       $this->initializeLanguages();
+               }
        }
 
        /**
@@ -186,6 +212,9 @@ class recordList extends t3lib_recordList {
        function generateList() {
                global $TCA;
 
+                       // Set page record in header
+               $this->pageRecord = t3lib_BEfunc::getRecordWSOL('pages',$this->id);
+
                        // Traverse the TCA table array:
                reset($TCA);
                while (list($tableName)=each($TCA))     {
@@ -196,6 +225,12 @@ class recordList extends t3lib_recordList {
                                        // Load full table definitions:
                                t3lib_div::loadTCA($tableName);
 
+                                       // Hide tables which are configured via TSConfig not to be shown (also works for admins):
+                               if (isset($this->tableTSconfigOverTCA[$tableName.'.']['hideTable']) ? $this->tableTSconfigOverTCA[$tableName.'.']['hideTable'] :
+                                               (t3lib_div::inList($this->hideTables, $tableName) ? true : $GLOBALS['TCA'][$tableName]['ctrl']['hideTable'])) {
+                                       continue;
+                               }
+
                                        // iLimit is set depending on whether we're in single- or multi-table mode
                                if ($this->table)       {
                                        $this->iLimit=(isset($TCA[$tableName]['interface']['maxSingleDBListItems'])?intval($TCA[$tableName]['interface']['maxSingleDBListItems']):$this->itemsLimitSingleTable);
@@ -207,6 +242,8 @@ class recordList extends t3lib_recordList {
                                        // Setting fields to select:
                                if ($this->allFields)   {
                                        $fields = $this->makeFieldList($tableName);
+                                       $fields[]='tstamp';
+                                       $fields[]='crdate';
                                        $fields[]='_PATH_';
                                        $fields[]='_CONTROL_';
                                        if (is_array($this->setFields[$tableName]))     {
@@ -218,8 +255,17 @@ class recordList extends t3lib_recordList {
                                        $fields = array();
                                }
 
+                                       // Find ID to use (might be different for "versioning_followPages" tables)
+                               if (intval($this->searchLevels)==0)     {
+                                       if ($TCA[$tableName]['ctrl']['versioning_followPages'] && $this->pageRecord['_ORIG_pid']==-1 && $this->pageRecord['t3ver_swapmode']==0) {
+                                               $this->pidSelect = 'pid='.intval($this->pageRecord['_ORIG_uid']);
+                                       } else {
+                                               $this->pidSelect = 'pid='.intval($this->id);
+                                       }
+                               }
+#debug($this->pidSelect,$tableName);
                                        // Finally, render the list:
-                               $this->HTMLcode.=$this->getTable($tableName, $this->id,implode(',',$fields));
+                               $this->HTMLcode.=$this->getTable($tableName, $this->id, implode(',',$fields));
                        }
                }
        }
@@ -260,10 +306,11 @@ class recordList extends t3lib_recordList {
                                                <td><input type="submit" name="search" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.search',1).'" /></td>
                                        </tr>
                                        <tr>
-                                               <td colspan="3">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showRecords',1).':<input type="text" name="showLimit" value="'.htmlspecialchars($this->showLimit?$this->showLimit:'').'"'.$GLOBALS['SOBE']->doc->formWidth(4).' /></td>
+                                               <td colspan="3">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showRecords',1).':<input type="text" name="showLimit" value="'.htmlspecialchars($this->showLimit?$this->showLimit:'').'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td>
                                        </tr>
                                </table>
                        '.$formElements[1];
+               $content.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['BACK_PATH'],'|<br/>');
                return $content;
        }
 
@@ -282,7 +329,7 @@ class recordList extends t3lib_recordList {
                if (!t3lib_extMgm::isLoaded('sys_note'))        return '';
 
                        // Create query for selecting the notes:
-               $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','sys_note','pid IN ('.$this->id.') AND (!personal OR cruser="'.intval($GLOBALS['BE_USER']->user['uid']).'")'.t3lib_BEfunc::deleteClause('sys_note'));
+               $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','sys_note','pid IN ('.$this->id.') AND (personal=0 OR cruser='.intval($GLOBALS['BE_USER']->user['uid']).')'.t3lib_BEfunc::deleteClause('sys_note').t3lib_BEfunc::versioningPlaceholderClause('sys_note'));
 
                        // Executing query:
                $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
@@ -413,7 +460,12 @@ class recordList extends t3lib_recordList {
                $queryParts = array(
                        'SELECT' => $fieldList,
                        'FROM' => $table,
-                       'WHERE' => $this->pidSelect.' '.$pC.t3lib_BEfunc::deleteClause($table).' '.$addWhere.' '.$search,
+                       'WHERE' => $this->pidSelect.
+                                               ' '.$pC.
+                                               t3lib_BEfunc::deleteClause($table).
+                                               t3lib_BEfunc::versioningPlaceholderClause($table).
+                                               ' '.$addWhere.
+                                               ' '.$search,
                        'GROUPBY' => '',
                        'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
                        'LIMIT' => $limit
@@ -468,7 +520,7 @@ class recordList extends t3lib_recordList {
 
                                // If search-fields were defined (and there always are) we create the query:
                        if (count($sfields))    {
-                               $like=' LIKE "%'.$GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table).'%"';              // Free-text searching...
+                               $like = ' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table).'%\'';          // Free-text searching...
                                $queryPart = ' AND ('.implode($like.' OR ',$sfields).$like.')';
 
                                        // Return query:
@@ -503,20 +555,87 @@ class recordList extends t3lib_recordList {
         * @return      string          The item title. Ready for HTML output (is htmlspecialchars()'ed)
         */
        function linkWrapItems($table,$uid,$code,$row)  {
+               global $TCA, $LANG;
+
+               $origCode = $code;
 
                        // If the title is blank, make a "no title" label:
                if (!strcmp($code,'')) {
-                       $code='<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i> - '.htmlspecialchars(t3lib_BEfunc::getRecordTitle($table,$row));
+                       $code = '<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i> - '.htmlspecialchars(t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$row),$GLOBALS['BE_USER']->uc['titleLen']));
                } else {
-                       $code=htmlspecialchars(t3lib_div::fixed_lgd($code,$this->fixedL));
+                       $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code,$this->fixedL));
+                       if ($code != htmlspecialchars($origCode)) {
+                               $code = '<span title="'.htmlspecialchars($origCode).'">'.$code.'</span>';
+                       }
                }
 
-                       // Output the label now:
-               if ($table=='pages')    {
-                       return '<a href="'.htmlspecialchars($this->listURL($uid,'')).'">'.$code.'</a>';
-               } else {
-                       return $code;
+               switch((string)$this->clickTitleMode)   {
+                       case 'edit':
+                                       // 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 = $localCalcPerms&2;
+                               } else {
+                                       $permsEdit = $this->calcPerms&16;
+                               }
+
+                                       // "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';
+                                       $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'" title="'.$LANG->getLL('edit',1).'">'.
+                                                       $code.
+                                                       '</a>';
+                               }
+                       break;
+                       case 'show':
+                                       // "Show" link (only pages and tt_content elements)
+                               if ($table=='pages' || $table=='tt_content')    {
+                                       $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($table=='tt_content'?$this->id.'#'.$row['uid']:$row['uid'])).'" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPage',1).'">'.
+                                                       $code.
+                                                       '</a>';
+                               }
+                       break;
+                       case 'info':
+                               // "Info": (All records)
+                               $code = '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'" title="'.$LANG->getLL('showInfo',1).'">'.
+                                       $code.
+                                       '</a>';
+                       break;
+                       default:
+                                       // Output the label now:
+                               if ($table=='pages')    {
+                                       $code = '<a href="'.htmlspecialchars($this->listURL($uid,'')).'" onclick="setHighlight('.$uid.')">'.$code.'</a>';
+                               } else {
+                                       $code = $this->linkUrlMail($code,$origCode);
+                               }
+                       break;
+               }
+
+               return $code;
+       }
+
+       /**
+        * Wrapping input code in link to URL or email if $testString is either.
+        *
+        * @param       string          code to wrap
+        * @param       string          String which is tested for being a URL or email and which will be used for the link if so.
+        * @return      string          Link-Wrapped $code value, if $testString was URL or email.
+        */
+       function linkUrlMail($code,$testString) {
+
+                       // Check for URL:
+               $schema = parse_url($testString);
+               if ($schema['scheme'] && t3lib_div::inList('http,https,ftp',$schema['scheme'])) {
+                       return '<a href="'.htmlspecialchars($testString).'" target="_blank">'.$code.'</a>';
                }
+
+                       // Check for email:
+               if (t3lib_div::validEmail($testString)) {
+                       return '<a href="mailto:'.htmlspecialchars($testString).'" target="_blank">'.$code.'</a>';
+               }
+
+                       // Return if nothing else...
+               return $code;
        }
 
        /**
@@ -538,6 +657,7 @@ class recordList extends t3lib_recordList {
                        ($this->searchString?'&search_field='.rawurlencode($this->searchString):'').
                        ($this->searchLevels?'&search_levels='.rawurlencode($this->searchLevels):'').
                        ($this->showLimit?'&showLimit='.rawurlencode($this->showLimit):'').
+                       ($this->firstElementNumber?'&pointer='.rawurlencode($this->firstElementNumber):'').
                        ((!$exclList || !t3lib_div::inList($exclList,'sortField')) && $this->sortField?'&sortField='.rawurlencode($this->sortField):'').
                        ((!$exclList || !t3lib_div::inList($exclList,'sortRev')) && $this->sortRev?'&sortRev='.rawurlencode($this->sortRev):'')
                        ;
@@ -557,9 +677,10 @@ class recordList extends t3lib_recordList {
         *
         * @param       string          Table name
         * @param       boolean         If set, users access to the field (non-exclude-fields) is NOT checked.
+        * @param       boolean         If set, also adds crdate and tstamp fields (note: they will also be added if user is admin or dontCheckUser is set)
         * @return      array           Array, where values are fieldnames to include in query
         */
-       function makeFieldList($table,$dontCheckUser=0) {
+       function makeFieldList($table,$dontCheckUser=0,$addDateFields=0)        {
                global $TCA,$BE_USER;
 
                        // Init fieldlist array:
@@ -581,10 +702,26 @@ class recordList extends t3lib_recordList {
                        if ($dontCheckUser || $BE_USER->isAdmin())      {
                                $fieldListArr[]='uid';
                                $fieldListArr[]='pid';
+                       }
+
+                               // Add date fields
+                       if ($dontCheckUser || $BE_USER->isAdmin() || $addDateFields)    {
                                if ($TCA[$table]['ctrl']['tstamp'])     $fieldListArr[]=$TCA[$table]['ctrl']['tstamp'];
                                if ($TCA[$table]['ctrl']['crdate'])     $fieldListArr[]=$TCA[$table]['ctrl']['crdate'];
+                       }
+
+                               // Add more special fields:
+                       if ($dontCheckUser || $BE_USER->isAdmin())      {
                                if ($TCA[$table]['ctrl']['cruser_id'])  $fieldListArr[]=$TCA[$table]['ctrl']['cruser_id'];
                                if ($TCA[$table]['ctrl']['sortby'])     $fieldListArr[]=$TCA[$table]['ctrl']['sortby'];
+                               if ($TCA[$table]['ctrl']['versioningWS'])       {
+                                       $fieldListArr[]='t3ver_id';
+                                       $fieldListArr[]='t3ver_state';
+                                       $fieldListArr[]='t3ver_wsid';
+                                       if ($table==='pages')   {
+                                               $fieldListArr[]='t3ver_swapmode';
+                                       }
+                               }
                        }
                }
                return $fieldListArr;
@@ -610,10 +747,43 @@ class recordList extends t3lib_recordList {
                return $tree;
        }
 
+       /**
+        * Redirects to TCEforms (alt_doc) if a record is just localized.
+        *
+        * @param       string          string with table, orig uid and language separated by ":"
+        * @return      void
+        */
+       function localizationRedirect($justLocalized)   {
+               global $TCA;
+
+               list($table,$orig_uid,$language) = explode(':',$justLocalized);
+
+               if ($TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])     {
+                       list($localizedRecord) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                                       'uid',
+                                       $table,
+                                       $TCA[$table]['ctrl']['languageField'].'='.intval($language).' AND '.
+                                               $TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($orig_uid).
+                                               t3lib_BEfunc::deleteClause($table).
+                                               t3lib_BEfunc::versioningPlaceholderClause($table)
+                               );
+
+                       if (is_array($localizedRecord)) {
+                                       // Create parameters and finally run the classic page module for creating a new page translation
+                               $params = '&edit['.$table.']['.$localizedRecord['uid'].']=edit';
+                               $returnUrl = '&returnUrl='.rawurlencode($this->listURL());
+                               $location = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$params.$returnUrl;
+
+                               header('Location: '.t3lib_div::locationHeaderUrl($location));
+                               exit;
+                       }
+               }
+       }
 }
 
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc'])        {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']);
 }
+
 ?>
\ No newline at end of file