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 08b2dad..ba4d577
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2008 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
@@ -119,6 +119,7 @@ class recordList extends t3lib_recordList {
        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
@@ -131,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
 
 
 
@@ -178,6 +179,14 @@ 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);
@@ -189,6 +198,24 @@ class recordList extends t3lib_recordList {
                        }
                }
 
+               // 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).')';
@@ -435,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'];
@@ -471,6 +505,19 @@ class recordList extends t3lib_recordList {
                        '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;
        }
@@ -483,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']
+               );
        }
 
        /**
@@ -513,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;
                                }
                        }
@@ -563,7 +608,7 @@ class recordList extends t3lib_recordList {
                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>';
                        }
@@ -649,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:'').
@@ -677,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:
@@ -701,8 +747,16 @@ 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'])       {
@@ -765,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);
                        }
                }
        }
@@ -777,4 +830,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']);
 }
 
-?>
\ No newline at end of file
+?>