Fixed bug #7896: Hide the page browser if not enough entries are available (Thanks...
[Packages/TYPO3.CMS.git] / typo3 / class.db_list.inc
old mode 100755 (executable)
new mode 100644 (file)
index ee8ad45..ba4d577
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *
  *
- *   84: class recordList extends t3lib_recordList
- *  144:     function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)
- *  195:     function generateList()
- *  242:     function getSearchBox($formFields=1)
- *  286:     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
- *  363:     function setDispFields()
- *  388:     function thumbCode($row,$table,$field)
- *  401:     function makeQueryArray($table, $id, $addWhere="",$fieldList='*')
- *  443:     function setTotalItems($queryParts)
- *  459:     function makeSearchString($table)
- *  498:     function linkWrapTable($table,$code)
- *  515:     function linkWrapItems($table,$uid,$code,$row)
- *  578:     function listURL($altId='',$table=-1,$exclList='')
- *  597:     function requestUri()
- *  608:     function makeFieldList($table,$dontCheckUser=0)
- *  648:     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")
  *
  */
@@ -115,6 +117,9 @@ class recordList extends t3lib_recordList {
        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
+       var $tablesCollapsed = array(); // Array of collapsed / uncollapsed tables in multi table view
 
                // Internal, dynamic:
        var $JScode = '';                               // JavaScript code accumulation
@@ -127,7 +132,7 @@ class recordList extends t3lib_recordList {
        var $currentTable = array();                    // Used for tracking next/prev uids
        var $duplicateStack=array();                    // Used for tracking duplicate values of fields
 
-
+       var $modTSconfig;                               // module configuratio
 
 
 
@@ -174,9 +179,43 @@ class recordList extends t3lib_recordList {
                $this->JScode='';
                $this->HTMLcode='';
 
+                       // limits
+               if(isset($this->modTSconfig['properties']['itemsLimitPerTable'])) {
+                       $this->itemsLimitPerTable = t3lib_div::intInRange(intval($this->modTSconfig['properties']['itemsLimitPerTable']), 1, 10000);
+               }
+               if(isset($this->modTSconfig['properties']['itemsLimitSingleTable'])) {
+                       $this->itemsLimitSingleTable = t3lib_div::intInRange(intval($this->modTSconfig['properties']['itemsLimitSingleTable']), 1, 10000);
+               }
+
                        // 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.')';
+                       }
+               }
+
+               // Get configuration of collapsed tables from user uc and merge with sanitized GP vars
+               $this->tablesCollapsed = is_array($GLOBALS['BE_USER']->uc['moduleData']['db_list.php']) ? $GLOBALS['BE_USER']->uc['moduleData']['db_list.php'] : array();
+               $collapseOverride = t3lib_div::_GP('collapse');
+               if (is_array($collapseOverride)) {
+                       foreach($collapseOverride as $collapseTable => $collapseValue) {
+                               if (is_array($GLOBALS['TCA'][$collapseTable]) && ($collapseValue == 0 || $collapseValue == 1)) {
+                                       $this->tablesCollapsed[$collapseTable] = $collapseValue;
+                               }
+                       }
+                       // Save modified user uc
+                       $GLOBALS['BE_USER']->uc['moduleData']['db_list.php'] = $this->tablesCollapsed;
+                       $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
+                       if (t3lib_div::_GP('returnUrl')) {
+                               $location = t3lib_div::_GP('returnUrl');
+                               t3lib_utility_Http::redirect($location);
+                       }
+               }
+
                if ($sL>0)      {
                        $tree = $this->getTreeObject($id,$sL,$this->perms_clause);
                        $this->pidSelect = 'pid IN ('.implode(',',$tree->ids).')';
@@ -201,8 +240,7 @@ class recordList extends t3lib_recordList {
                global $TCA;
 
                        // Set page record in header
-               $this->pageRecord = t3lib_BEfunc::getRecord('pages',$this->id);
-               t3lib_BEfunc::workspaceOL('pages',$this->pageRecord);
+               $this->pageRecord = t3lib_BEfunc::getRecordWSOL('pages',$this->id);
 
                        // Traverse the TCA table array:
                reset($TCA);
@@ -214,6 +252,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);
@@ -225,6 +269,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]))     {
@@ -287,7 +333,7 @@ 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];
@@ -310,7 +356,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=0 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);
@@ -416,8 +462,15 @@ class recordList extends t3lib_recordList {
         * @param       string          Field list to select, * for all (for "SELECT [fieldlist] FROM ...")
         * @return      array           Returns query array
         */
-       function makeQueryArray($table, $id, $addWhere="",$fieldList='*')       {
-               global $TCA;
+       function makeQueryArray($table, $id, $addWhere='', $fieldList='*')      {
+               global $TCA, $TYPO3_CONF_VARS;
+
+               $hookObjectsArr = array();
+               if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list.inc']['makeQueryArray'])) {
+                       foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list.inc']['makeQueryArray'] as $classRef) {
+                               $hookObjectsArr[] = t3lib_div::getUserObj($classRef);
+                       }
+               }
 
                        // Set ORDER BY:
                $orderBy = ($TCA[$table]['ctrl']['sortby']) ? 'ORDER BY '.$TCA[$table]['ctrl']['sortby'] : $TCA[$table]['ctrl']['default_sortby'];
@@ -441,12 +494,30 @@ 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
                );
 
+                       // Apply hook as requested in http://bugs.typo3.org/view.php?id=4361
+               foreach ($hookObjectsArr as $hookObj) {
+                       if (method_exists($hookObj, 'makeQueryArray_post')) {
+                               $_params = array(
+                                       'orderBy' => $orderBy,
+                                       'limit' => $limit,
+                                       'pC' => $pC,
+                                       'search' => $search,
+                               );
+                               $hookObj->makeQueryArray_post($queryParts, $this, $table, $id, $addWhere, $fieldList, $_params);
+                       }
+               }
+
                        // Return query:
                return $queryParts;
        }
@@ -459,13 +530,11 @@ class recordList extends t3lib_recordList {
         * @see makeQueryArray()
         */
        function setTotalItems($queryParts)     {
-               $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                       'count(*)',
-                                       $queryParts['FROM'],
-                                       $queryParts['WHERE']
-                               );
-               list($rCount) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
-               $this->totalItems = $rCount;
+               $this->totalItems = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
+                       '*',
+                       $queryParts['FROM'],
+                       $queryParts['WHERE']
+               );
        }
 
        /**
@@ -489,7 +558,7 @@ class recordList extends t3lib_recordList {
 
                                // Traverse the configured columns and add all columns that can be searched:
                        foreach($TCA[$table]['columns'] as $fieldName => $info) {
-                               if ($info['config']['type']=='text' || ($info['config']['type']=='input' && !ereg('date|time|int',$info['config']['eval'])))    {
+                               if ($info['config']['type']=='text' || ($info['config']['type']=='input' && !preg_match('/date|time|int/',$info['config']['eval'])))    {
                                        $sfields[]=$fieldName;
                                }
                        }
@@ -533,11 +602,16 @@ class recordList extends t3lib_recordList {
        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_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$row),$GLOBALS['BE_USER']->uc['titleLen']));
                } else {
-                       $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code,$this->fixedL));
+                       $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code, $this->fixedL));
+                       if ($code != htmlspecialchars($origCode)) {
+                               $code = '<span title="'.htmlspecialchars($origCode).'">'.$code.'</span>';
+                       }
                }
 
                switch((string)$this->clickTitleMode)   {
@@ -553,7 +627,7 @@ class recordList extends t3lib_recordList {
                                        // "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,'',-1)).'" title="'.$LANG->getLL('edit',1).'">'.
+                                       $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'" title="'.$LANG->getLL('edit',1).'">'.
                                                        $code.
                                                        '</a>';
                                }
@@ -575,7 +649,9 @@ class recordList extends t3lib_recordList {
                        default:
                                        // Output the label now:
                                if ($table=='pages')    {
-                                       $code = '<a href="'.htmlspecialchars($this->listURL($uid,'')).'">'.$code.'</a>';
+                                       $code = '<a href="'.htmlspecialchars($this->listURL($uid,'')).'" onclick="setHighlight('.$uid.')">'.$code.'</a>';
+                               } else {
+                                       $code = $this->linkUrlMail($code,$origCode);
                                }
                        break;
                }
@@ -584,6 +660,30 @@ class recordList extends t3lib_recordList {
        }
 
        /**
+        * 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;
+       }
+
+       /**
         * Creates the URL to this script, including all relevant GPvars
         * Fixed GPvars are id, table, imagemode, returlUrl, search_field, search_levels and showLimit
         * The GPvars "sortField" and "sortRev" are also included UNLESS they are found in the $exclList variable.
@@ -594,7 +694,7 @@ class recordList extends t3lib_recordList {
         * @return      string          URL
         */
        function listURL($altId='',$table=-1,$exclList='')      {
-               return $this->script.
+               return $GLOBALS['BACK_PATH'] . $this->script.
                        '?id='.(strcmp($altId,'')?$altId:$this->id).
                        '&table='.rawurlencode($table==-1?$this->table:$table).
                        ($this->thumbs?'&imagemode='.$this->thumbs:'').
@@ -602,6 +702,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):'')
                        ;
@@ -621,9 +722,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:
@@ -645,13 +747,22 @@ 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';
                                        }
@@ -681,6 +792,12 @@ 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;
 
@@ -692,7 +809,8 @@ class recordList extends t3lib_recordList {
                                        $table,
                                        $TCA[$table]['ctrl']['languageField'].'='.intval($language).' AND '.
                                                $TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($orig_uid).
-                                               t3lib_BEfunc::deleteClause($table)
+                                               t3lib_BEfunc::deleteClause($table).
+                                               t3lib_BEfunc::versioningPlaceholderClause($table)
                                );
 
                        if (is_array($localizedRecord)) {
@@ -701,8 +819,7 @@ class recordList extends t3lib_recordList {
                                $returnUrl = '&returnUrl='.rawurlencode($this->listURL());
                                $location = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$params.$returnUrl;
 
-                               header('Location: '.t3lib_div::locationHeaderUrl($location));
-                               exit;
+                               t3lib_utility_Http::redirect($location);
                        }
                }
        }
@@ -712,4 +829,5 @@ class recordList extends t3lib_recordList {
 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
+
+?>