TYPO3 API  SVNRelease
class.db_list.inc
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2009 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Include file extending t3lib_recordList
00029  * Shared between Web>List (db_list.php) and Web>Page (sysext/cms/layout/db_layout.php)
00030  *
00031  * $Id: class.db_list.inc 9847 2010-12-17 23:26:59Z steffenk $
00032  * Revised for TYPO3 3.6 December/2003 by Kasper Skårhøj
00033  * XHTML compliant
00034  *
00035  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00036  */
00037 /**
00038  * [CLASS/FUNCTION INDEX of SCRIPT]
00039  *
00040  *
00041  *
00042  *   86: class recordList extends t3lib_recordList
00043  *  148:     function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)
00044  *  211:     function generateList()
00045  *  275:     function getSearchBox($formFields=1)
00046  *  319:     function showSysNotesForPage()
00047  *
00048  *              SECTION: Various helper functions
00049  *  396:     function setDispFields()
00050  *  421:     function thumbCode($row,$table,$field)
00051  *  434:     function makeQueryArray($table, $id, $addWhere="",$fieldList='*')
00052  *  481:     function setTotalItems($queryParts)
00053  *  497:     function makeSearchString($table)
00054  *  536:     function linkWrapTable($table,$code)
00055  *  553:     function linkWrapItems($table,$uid,$code,$row)
00056  *  617:     function linkUrlMail($code,$testString)
00057  *  644:     function listURL($altId='',$table=-1,$exclList='')
00058  *  663:     function requestUri()
00059  *  674:     function makeFieldList($table,$dontCheckUser=0)
00060  *  721:     function getTreeObject($id,$depth,$perms_clause)
00061  *  739:     function localizationRedirect($justLocalized)
00062  *
00063  * TOTAL FUNCTIONS: 17
00064  * (This index is automatically created/updated by the extension "extdeveval")
00065  *
00066  */
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 /**
00079  * Child class for rendering of Web > List (not the final class. see class.db_list_extra)
00080  *
00081  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00082  * @package TYPO3
00083  * @subpackage core
00084  * @see localRecordList
00085  */
00086 class recordList extends t3lib_recordList {
00087 
00088         // External, static:
00089     var $tableList='';              // Specify a list of tables which are the only ones allowed to be displayed.
00090     var $returnUrl='';              // Return URL
00091     var $thumbs = 0;                // Boolean. Thumbnails on records containing files (pictures)
00092     var $itemsLimitPerTable = 20;           // default Max items shown per table in "multi-table mode", may be overridden by tables.php
00093     var $itemsLimitSingleTable = 100;       // default Max items shown per table in "single-table mode", may be overridden by tables.php
00094     var $widthGif = '<img src="clear.gif" width="1" height="4" hspace="160" alt="" />';
00095     var $script = 'index.php';          // Current script name
00096     var $allFields=0;               // Indicates if all available fields for a user should be selected or not.
00097     var $localizationView=FALSE;            // Whether to show localization view or not.
00098 
00099         // Internal, static: GPvar:
00100     var $csvOutput=FALSE;               // If set, csvList is outputted.
00101     var $sortField;                 // Field, to sort list by
00102     var $sortRev;                   // Field, indicating to sort in reverse order.
00103     var $displayFields;             // Array, containing which fields to display in extended mode
00104     var $duplicateField;                // String, can contain the field name from a table which must have duplicate values marked.
00105 
00106         // Internal, static:
00107     var $id;                    // Page id
00108     var $table='';                  // Tablename if single-table mode
00109     var $listOnlyInSingleTableMode=FALSE;       // If true, records are listed only if a specific table is selected.
00110     var $firstElementNumber=0;          // Pointer for browsing list
00111     var $searchString='';               // Search string
00112     var $searchLevels='';               // Levels to search down.
00113     var $showLimit=0;               // Number of records to show
00114     var $pidSelect='';              // List of ids from which to select/search etc. (when search-levels are set high). See start()
00115     var $perms_clause='';               // Page select permissions
00116     var $calcPerms=0;               // Some permissions...
00117     var $clickTitleMode = '';           // Mode for what happens when a user clicks the title of a record.
00118     var $modSharedTSconfig = array();       // Shared module configuration, used by localization features
00119     var $pageRecord = array();      // Loaded with page record with version overlay if any.
00120     var $hideTables = '';           // Tables which should not get listed
00121     var $tableTSconfigOverTCA = array(); //TSconfig which overwrites TCA-Settings
00122     var $tablesCollapsed = array(); // Array of collapsed / uncollapsed tables in multi table view
00123 
00124         // Internal, dynamic:
00125     var $JScode = '';               // JavaScript code accumulation
00126     var $HTMLcode = '';             // HTML output
00127     var $iLimit=0;                  // "LIMIT " in SQL...
00128     var $eCounter=0;                // Counting the elements no matter what...
00129     var $totalItems='';             // Set to the total number of items for a table when selecting.
00130     var $recPath_cache=array();         // Cache for record path
00131     var $setFields=array();             // Fields to display for the current table
00132     var $currentTable = array();            // Used for tracking next/prev uids
00133     var $duplicateStack=array();            // Used for tracking duplicate values of fields
00134 
00135     var $modTSconfig;               // module configuratio
00136 
00137 
00138 
00139     /**
00140      * Initializes the list generation
00141      *
00142      * @param   integer     Page id for which the list is rendered. Must be >= 0
00143      * @param   string      Tablename - if extended mode where only one table is listed at a time.
00144      * @param   integer     Browsing pointer.
00145      * @param   string      Search word, if any
00146      * @param   integer     Number of levels to search down the page tree
00147      * @param   integer     Limit of records to be listed.
00148      * @return  void
00149      */
00150     function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)  {
00151         global $TCA;
00152 
00153             // Setting internal variables:
00154         $this->id=intval($id);                  // sets the parent id
00155         if ($TCA[$table])   $this->table=$table;        // Setting single table mode, if table exists:
00156         $this->firstElementNumber=$pointer;
00157         $this->searchString=trim($search);
00158         $this->searchLevels=trim($levels);
00159         $this->showLimit=t3lib_div::intInRange($showLimit,0,10000);
00160 
00161             // Setting GPvars:
00162         $this->csvOutput = t3lib_div::_GP('csv') ? TRUE : FALSE;
00163         $this->sortField = t3lib_div::_GP('sortField');
00164         $this->sortRev = t3lib_div::_GP('sortRev');
00165         $this->displayFields = t3lib_div::_GP('displayFields');
00166         $this->duplicateField = t3lib_div::_GP('duplicateField');
00167 
00168         if (t3lib_div::_GP('justLocalized'))    {
00169             $this->localizationRedirect(t3lib_div::_GP('justLocalized'));
00170         }
00171 
00172             // If thumbnails are disabled, set the "notfound" icon as default:
00173         if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
00174             $this->thumbScript='gfx/notfound_thumb.gif';
00175         }
00176 
00177             // Init dynamic vars:
00178         $this->counter=0;
00179         $this->JScode='';
00180         $this->HTMLcode='';
00181 
00182             // limits
00183         if(isset($this->modTSconfig['properties']['itemsLimitPerTable'])) {
00184             $this->itemsLimitPerTable = t3lib_div::intInRange(intval($this->modTSconfig['properties']['itemsLimitPerTable']), 1, 10000);
00185         }
00186         if(isset($this->modTSconfig['properties']['itemsLimitSingleTable'])) {
00187             $this->itemsLimitSingleTable = t3lib_div::intInRange(intval($this->modTSconfig['properties']['itemsLimitSingleTable']), 1, 10000);
00188         }
00189 
00190             // Set select levels:
00191         $sL=intval($this->searchLevels);
00192         $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
00193 
00194             // this will hide records from display - it has nothing todo with user rights!!
00195         if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
00196             if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
00197                 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
00198             }
00199         }
00200 
00201         // Get configuration of collapsed tables from user uc and merge with sanitized GP vars
00202         $this->tablesCollapsed = is_array($GLOBALS['BE_USER']->uc['moduleData']['list']) ? $GLOBALS['BE_USER']->uc['moduleData']['list'] : array();
00203         $collapseOverride = t3lib_div::_GP('collapse');
00204         if (is_array($collapseOverride)) {
00205             foreach($collapseOverride as $collapseTable => $collapseValue) {
00206                 if (is_array($GLOBALS['TCA'][$collapseTable]) && ($collapseValue == 0 || $collapseValue == 1)) {
00207                     $this->tablesCollapsed[$collapseTable] = $collapseValue;
00208                 }
00209             }
00210             // Save modified user uc
00211             $GLOBALS['BE_USER']->uc['moduleData']['list'] = $this->tablesCollapsed;
00212             $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
00213             if (t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'))) {
00214                 $location = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
00215                 t3lib_utility_Http::redirect($location);
00216             }
00217         }
00218 
00219         if ($sL>0)  {
00220             $tree = $this->getTreeObject($this->id, $sL, $this->perms_clause);
00221             $pidList = implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($tree->ids));
00222             $this->pidSelect = 'pid IN (' . $pidList . ')';
00223         } else {
00224             $this->pidSelect = 'pid='.intval($id);
00225         }
00226 
00227             // Initialize languages:
00228         if ($this->localizationView)    {
00229             $this->initializeLanguages();
00230         }
00231     }
00232 
00233     /**
00234      * Traverses the table(s) to be listed and renders the output code for each:
00235      * The HTML is accumulated in $this->HTMLcode
00236      * Finishes off with a stopper-gif
00237      *
00238      * @return  void
00239      */
00240     function generateList() {
00241         global $TCA;
00242 
00243             // Set page record in header
00244         $this->pageRecord = t3lib_BEfunc::getRecordWSOL('pages',$this->id);
00245 
00246             // Traverse the TCA table array:
00247         foreach ($TCA as $tableName => $value) {
00248 
00249                 // Checking if the table should be rendered:
00250             if ((!$this->table || $tableName==$this->table) && (!$this->tableList || t3lib_div::inList($this->tableList,$tableName)) && $GLOBALS['BE_USER']->check('tables_select',$tableName)) {       // Checks that we see only permitted/requested tables:
00251 
00252                     // Load full table definitions:
00253                 t3lib_div::loadTCA($tableName);
00254 
00255                     // Don't show table if hidden by TCA ctrl section
00256                 $hideTable = $GLOBALS['TCA'][$tableName]['ctrl']['hideTable'] ? TRUE : FALSE;
00257                     // Don't show table if hidden by pageTSconfig mod.web_list.hideTables
00258                 if (in_array($tableName, t3lib_div::trimExplode(',', $this->hideTables))) {
00259                     $hideTable = TRUE;
00260                 }
00261                     // Override previous selection if table is enabled or hidden by TSconfig TCA override mod.web_list.table
00262                 if (isset($this->tableTSconfigOverTCA[$tableName.'.']['hideTable'])) {
00263                     $hideTable = $this->tableTSconfigOverTCA[$tableName.'.']['hideTable'] ? TRUE : FALSE;
00264                 }
00265                 if ($hideTable) {
00266                     continue;
00267                 }
00268 
00269                     // iLimit is set depending on whether we're in single- or multi-table mode
00270                 if ($this->table)   {
00271                     $this->iLimit=(isset($TCA[$tableName]['interface']['maxSingleDBListItems'])?intval($TCA[$tableName]['interface']['maxSingleDBListItems']):$this->itemsLimitSingleTable);
00272                 } else {
00273                     $this->iLimit=(isset($TCA[$tableName]['interface']['maxDBListItems'])?intval($TCA[$tableName]['interface']['maxDBListItems']):$this->itemsLimitPerTable);
00274                 }
00275                 if ($this->showLimit)   $this->iLimit = $this->showLimit;
00276 
00277                     // Setting fields to select:
00278                 if ($this->allFields)   {
00279                     $fields = $this->makeFieldList($tableName);
00280                     $fields[]='tstamp';
00281                     $fields[]='crdate';
00282                     $fields[]='_PATH_';
00283                     $fields[]='_CONTROL_';
00284                     if (is_array($this->setFields[$tableName])) {
00285                         $fields = array_intersect($fields,$this->setFields[$tableName]);
00286                     } else {
00287                         $fields = array();
00288                     }
00289                 } else {
00290                     $fields = array();
00291                 }
00292 
00293                     // Find ID to use (might be different for "versioning_followPages" tables)
00294                 if (intval($this->searchLevels)==0) {
00295                     if ($TCA[$tableName]['ctrl']['versioning_followPages'] && $this->pageRecord['_ORIG_pid']==-1 && $this->pageRecord['t3ver_swapmode']==0) {
00296                         $this->pidSelect = 'pid='.intval($this->pageRecord['_ORIG_uid']);
00297                     } else {
00298                         $this->pidSelect = 'pid='.intval($this->id);
00299                     }
00300                 }
00301 #debug($this->pidSelect,$tableName);
00302                     // Finally, render the list:
00303                 $this->HTMLcode.=$this->getTable($tableName, $this->id, implode(',',$fields));
00304             }
00305         }
00306     }
00307 
00308     /**
00309      * Creates the search box
00310      *
00311      * @param   boolean     If true, the search box is wrapped in its own form-tags
00312      * @return  string      HTML for the search box
00313      */
00314     function getSearchBox($formFields=1)    {
00315 
00316             // Setting form-elements, if applicable:
00317         $formElements=array('','');
00318         if ($formFields)    {
00319             $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>');
00320         }
00321 
00322             // Make level selector:
00323         $opt=array();
00324         $parts = explode('|',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchLevels'));
00325         foreach ($parts as $kv => $label) {
00326             $opt[] = '<option value="'.$kv.'"'.($kv==intval($this->searchLevels)?' selected="selected"':'').'>'.htmlspecialchars($label).'</option>';
00327         }
00328         $lMenu = '<select name="search_levels">'.implode('',$opt).'</select>';
00329 
00330             // Table with the search box:
00331         $content.= '
00332             '.$formElements[0].'
00333 
00334                 <!--
00335                     Search box:
00336                 -->
00337                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-dblist-search">
00338                     <tr>
00339                         <td><label for="search_field">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchString', 1) . '</label><input type="text" name="search_field" id="search_field" value="' . htmlspecialchars($this->searchString) . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(10) . ' /></td>
00340                         <td>' . $lMenu . '</td>
00341                         <td><input type="submit" name="search" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.search', 1) . '" /></td>
00342                     </tr>
00343                     <tr>
00344                         <td colspan="3"><label for="showLimit">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showRecords', 1) . '</label>:<input type="text" name="showLimit" id="showLimit" value="' . htmlspecialchars($this->showLimit ? $this->showLimit : '') . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td>
00345                     </tr>
00346                 </table>
00347             '.$formElements[1];
00348         return $content;
00349     }
00350 
00351     /**
00352      * Creates the display of sys_notes for the page.
00353      * Relies on the "sys_note" extension to be loaded.
00354      *
00355      * @return  string      HTML for the sys-notes (if any)
00356      */
00357     function showSysNotesForPage()  {
00358         global $TCA;
00359 
00360         $out='';
00361 
00362             // Checking if extension is loaded:
00363         if (!t3lib_extMgm::isLoaded('sys_note'))    return '';
00364 
00365             // Create query for selecting the notes:
00366         $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'));
00367 
00368             // Executing query:
00369         $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
00370 
00371             // If some notes were found, render them:
00372         if ($dbCount)   {
00373             $cat = array();
00374 
00375                 // Load full table description:
00376             t3lib_div::loadTCA('sys_note');
00377 
00378                 // Traverse note-types and get labels:
00379             if ($TCA['sys_note'] && $TCA['sys_note']['columns']['category'] && is_array($TCA['sys_note']['columns']['category']['config']['items']))    {
00380                 foreach($TCA['sys_note']['columns']['category']['config']['items'] as $el)  {
00381                     $cat[$el[1]]=$GLOBALS['LANG']->sL($el[0]);
00382                 }
00383             }
00384 
00385                 // For each note found, make rendering:
00386             while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))    {
00387 
00388                     // Create content:
00389                 $iconImg = t3lib_iconWorks::getSpriteIconForRecord('sys_note', $row);
00390                 $subject = htmlspecialchars($row['subject']);
00391                 $fields = array();
00392                 $fields['Author:'] = htmlspecialchars($row['author'].($row['email'] && $row['author'] ? ', ':'').$row['email']);
00393                 $fields['Category:'] = htmlspecialchars($cat[$row['category']]);
00394                 $fields['Note:'] = nl2br(htmlspecialchars($row['message']));
00395 
00396                     // Compile content:
00397                 $out.='
00398 
00399 
00400                 <!--
00401                     Sys-notes for list module:
00402                 -->
00403                     <table border="0" cellpadding="1" cellspacing="1" id="typo3-dblist-sysnotes">
00404                         <tr><td colspan="2" class="bgColor2">'.$iconImg.'<strong>'.$subject.'</strong></td></tr>
00405                         <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.category',1).'</td><td class="bgColor4">'.$fields['Category:'].'</td></tr>
00406                         <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.author',1).'</td><td class="bgColor4">'.$fields['Author:'].'</td></tr>
00407                         <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.note',1).'</td><td class="bgColor4">'.$fields['Note:'].'</td></tr>
00408                     </table>
00409                 ';
00410             }
00411         }
00412         return $out;
00413     }
00414 
00415 
00416 
00417 
00418 
00419 
00420 
00421 
00422     /******************************
00423      *
00424      * Various helper functions
00425      *
00426      ******************************/
00427 
00428     /**
00429      * Setting the field names to display in extended list.
00430      * Sets the internal variable $this->setFields
00431      *
00432      * @return  void
00433      */
00434     function setDispFields()    {
00435 
00436             // Getting from session:
00437         $dispFields = $GLOBALS['BE_USER']->getModuleData('list/displayFields');
00438 
00439             // If fields has been inputted, then set those as the value and push it to session variable:
00440         if (is_array($this->displayFields)) {
00441             reset($this->displayFields);
00442             $tKey = key($this->displayFields);
00443             $dispFields[$tKey]=$this->displayFields[$tKey];
00444             $GLOBALS['BE_USER']->pushModuleData('list/displayFields',$dispFields);
00445         }
00446 
00447             // Setting result:
00448         $this->setFields=$dispFields;
00449     }
00450 
00451     /**
00452      * Create thumbnail code for record/field
00453      *
00454      * @param   array       Record array
00455      * @param   string      Table (record is from)
00456      * @param   string      Field name for which thumbsnail are to be rendered.
00457      * @return  string      HTML for thumbnails, if any.
00458      */
00459     function thumbCode($row,$table,$field)  {
00460         return t3lib_BEfunc::thumbCode($row,$table,$field,$this->backPath,$this->thumbScript);
00461     }
00462 
00463     /**
00464      * Returns the SQL-query array to select the records from a table $table with pid = $id
00465      *
00466      * @param   string      Table name
00467      * @param   integer     Page id (NOT USED! $this->pidSelect is used instead)
00468      * @param   string      Additional part for where clause
00469      * @param   string      Field list to select, * for all (for "SELECT [fieldlist] FROM ...")
00470      * @return  array       Returns query array
00471      */
00472     function makeQueryArray($table, $id, $addWhere='', $fieldList='*')  {
00473         global $TCA, $TYPO3_CONF_VARS;
00474 
00475         $hookObjectsArr = array();
00476         if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list.inc']['makeQueryArray'])) {
00477             foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['typo3/class.db_list.inc']['makeQueryArray'] as $classRef) {
00478                 $hookObjectsArr[] = t3lib_div::getUserObj($classRef);
00479             }
00480         }
00481 
00482             // Set ORDER BY:
00483         $orderBy = ($TCA[$table]['ctrl']['sortby']) ? 'ORDER BY '.$TCA[$table]['ctrl']['sortby'] : $TCA[$table]['ctrl']['default_sortby'];
00484         if ($this->sortField)   {
00485             if (in_array($this->sortField,$this->makeFieldList($table,1)))  {
00486                 $orderBy = 'ORDER BY '.$this->sortField;
00487                 if ($this->sortRev) $orderBy.=' DESC';
00488             }
00489         }
00490 
00491             // Set LIMIT:
00492         $limit = $this->iLimit ? ($this->firstElementNumber ? $this->firstElementNumber.',' : '').($this->iLimit+1) : '';
00493 
00494             // Filtering on displayable pages (permissions):
00495         $pC = ($table=='pages' && $this->perms_clause)?' AND '.$this->perms_clause:'';
00496 
00497             // Adding search constraints:
00498         $search = $this->makeSearchString($table);
00499 
00500             // Compiling query array:
00501         $queryParts = array(
00502             'SELECT' => $fieldList,
00503             'FROM' => $table,
00504             'WHERE' => $this->pidSelect.
00505                         ' '.$pC.
00506                         t3lib_BEfunc::deleteClause($table).
00507                         t3lib_BEfunc::versioningPlaceholderClause($table).
00508                         ' '.$addWhere.
00509                         ' '.$search,
00510             'GROUPBY' => '',
00511             'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
00512             'LIMIT' => $limit
00513         );
00514 
00515             // Apply hook as requested in http://bugs.typo3.org/view.php?id=4361
00516         foreach ($hookObjectsArr as $hookObj) {
00517             if (method_exists($hookObj, 'makeQueryArray_post')) {
00518                 $_params = array(
00519                     'orderBy' => $orderBy,
00520                     'limit' => $limit,
00521                     'pC' => $pC,
00522                     'search' => $search,
00523                 );
00524                 $hookObj->makeQueryArray_post($queryParts, $this, $table, $id, $addWhere, $fieldList, $_params);
00525             }
00526         }
00527 
00528             // Return query:
00529         return $queryParts;
00530     }
00531 
00532     /**
00533      * Based on input query array (query for selecting count(*) from a table) it will select the number of records and set the value in $this->totalItems
00534      *
00535      * @param   array       Query array
00536      * @return  void
00537      * @see makeQueryArray()
00538      */
00539     function setTotalItems($queryParts) {
00540         $this->totalItems = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
00541             '*',
00542             $queryParts['FROM'],
00543             $queryParts['WHERE']
00544         );
00545     }
00546 
00547     /**
00548      * Creates part of query for searching after a word ($this->searchString) fields in input table
00549      *
00550      * @param   string      Table, in which the fields are being searched.
00551      * @return  string      Returns part of WHERE-clause for searching, if applicable.
00552      */
00553     function makeSearchString($table)   {
00554         global $TCA;
00555 
00556             // Make query, only if table is valid and a search string is actually defined:
00557         if ($TCA[$table] && $this->searchString)    {
00558 
00559                 // Loading full table description - we need to traverse fields:
00560             t3lib_div::loadTCA($table);
00561 
00562                 // Initialize field array:
00563             $sfields=array();
00564             $sfields[]='uid';   // Adding "uid" by default.
00565 
00566                 // Traverse the configured columns and add all columns that can be searched:
00567             foreach($TCA[$table]['columns'] as $fieldName => $info) {
00568                 if ($info['config']['type']=='text' || ($info['config']['type']=='input' && !preg_match('/date|time|int/',$info['config']['eval'])))    {
00569                     $sfields[]=$fieldName;
00570                 }
00571             }
00572 
00573                 // If search-fields were defined (and there always are) we create the query:
00574             if (count($sfields))    {
00575                 $like = ' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table).'%\'';      // Free-text searching...
00576                 $queryPart = ' AND ('.implode($like.' OR ',$sfields).$like.')';
00577 
00578                     // Return query:
00579                 return $queryPart;
00580             }
00581         }
00582     }
00583 
00584     /**
00585      * Returns the title (based on $code) of a table ($table) with the proper link around. For headers over tables.
00586      * The link will cause the display of all extended mode or not for the table.
00587      *
00588      * @param   string      Table name
00589      * @param   string      Table label
00590      * @return  string      The linked table label
00591      */
00592     function linkWrapTable($table,$code)    {
00593         if ($this->table!=$table)   {
00594             return '<a href="'.htmlspecialchars($this->listURL('',$table)).'">'.$code.'</a>';
00595         } else {
00596             return '<a href="'.htmlspecialchars($this->listURL('','','sortField,sortRev,table')).'">'.$code.'</a>';
00597         }
00598     }
00599 
00600     /**
00601      * Returns the title (based on $code) of a record (from table $table) with the proper link around (that is for 'pages'-records a link to the level of that record...)
00602      *
00603      * @param   string      Table name
00604      * @param   integer     Item uid
00605      * @param   string      Item title (not htmlspecialchars()'ed yet)
00606      * @param   array       Item row
00607      * @return  string      The item title. Ready for HTML output (is htmlspecialchars()'ed)
00608      */
00609     function linkWrapItems($table,$uid,$code,$row)  {
00610         global $TCA, $LANG;
00611 
00612         $origCode = $code;
00613 
00614             // If the title is blank, make a "no title" label:
00615         if (!strcmp($code,'')) {
00616             $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']));
00617         } else {
00618             $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code, $this->fixedL));
00619             if ($code != htmlspecialchars($origCode)) {
00620                 $code = '<span title="'.htmlspecialchars($origCode).'">'.$code.'</span>';
00621             }
00622         }
00623 
00624         switch((string)$this->clickTitleMode)   {
00625             case 'edit':
00626                     // If the listed table is 'pages' we have to request the permission settings for each page:
00627                 if ($table=='pages')    {
00628                     $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid']));
00629                     $permsEdit = $localCalcPerms&2;
00630                 } else {
00631                     $permsEdit = $this->calcPerms&16;
00632                 }
00633 
00634                     // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
00635                 if ($permsEdit) {
00636                     $params='&edit['.$table.']['.$row['uid'].']=edit';
00637                     $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$this->backPath,-1)).'" title="'.$LANG->getLL('edit',1).'">'.
00638                             $code.
00639                             '</a>';
00640                 }
00641             break;
00642             case 'show':
00643                     // "Show" link (only pages and tt_content elements)
00644                 if ($table=='pages' || $table=='tt_content')    {
00645                     $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).'">'.
00646                             $code.
00647                             '</a>';
00648                 }
00649             break;
00650             case 'info':
00651                 // "Info": (All records)
00652                 $code = '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'" title="'.$LANG->getLL('showInfo',1).'">'.
00653                     $code.
00654                     '</a>';
00655             break;
00656             default:
00657                     // Output the label now:
00658                 if ($table=='pages')    {
00659                     $code = '<a href="'.htmlspecialchars($this->listURL($uid,'')).'" onclick="setHighlight('.$uid.')">'.$code.'</a>';
00660                 } else {
00661                     $code = $this->linkUrlMail($code,$origCode);
00662                 }
00663             break;
00664         }
00665 
00666         return $code;
00667     }
00668 
00669     /**
00670      * Wrapping input code in link to URL or email if $testString is either.
00671      *
00672      * @param   string      code to wrap
00673      * @param   string      String which is tested for being a URL or email and which will be used for the link if so.
00674      * @return  string      Link-Wrapped $code value, if $testString was URL or email.
00675      */
00676     function linkUrlMail($code,$testString) {
00677 
00678             // Check for URL:
00679         $schema = parse_url($testString);
00680         if ($schema['scheme'] && t3lib_div::inList('http,https,ftp',$schema['scheme'])) {
00681             return '<a href="'.htmlspecialchars($testString).'" target="_blank">'.$code.'</a>';
00682         }
00683 
00684             // Check for email:
00685         if (t3lib_div::validEmail($testString)) {
00686             return '<a href="mailto:'.htmlspecialchars($testString).'" target="_blank">'.$code.'</a>';
00687         }
00688 
00689             // Return if nothing else...
00690         return $code;
00691     }
00692 
00693     /**
00694      * Creates the URL to this script, including all relevant GPvars
00695      * Fixed GPvars are id, table, imagemode, returlUrl, search_field, search_levels and showLimit
00696      * The GPvars "sortField" and "sortRev" are also included UNLESS they are found in the $exclList variable.
00697      *
00698      * @param   string      Alternative id value. Enter blank string for the current id ($this->id)
00699      * @param   string      Tablename to display. Enter "-1" for the current table.
00700      * @param   string      Commalist of fields NOT to include ("sortField" or "sortRev")
00701      * @return  string      URL
00702      */
00703     function listURL($altId='',$table=-1,$exclList='')  {
00704         $urlParameters = array();
00705         if (strcmp($altId, '')) {
00706             $urlParameters['id'] = $altId;
00707         } else {
00708             $urlParameters['id'] = $this->id;
00709         }
00710         if ($table === -1) {
00711             $urlParameters['table'] = $this->table;
00712         } else {
00713             $urlParameters['table'] = $table;
00714         }
00715         if ($this->thumbs) {
00716             $urlParameters['imagemode'] = $this->thumbs;
00717         }
00718         if ($this->returnUrl) {
00719             $urlParameters['returnUrl'] = $this->returnUrl;
00720         }
00721         if ($this->searchString) {
00722             $urlParameters['search_field'] = $this->searchString;
00723         }
00724         if ($this->searchLevels) {
00725             $urlParameters['search_levels'] = $this->searchLevels;
00726         }
00727         if ($this->showLimit) {
00728             $urlParameters['showLimit'] = $this->showLimit;
00729         }
00730         if ($this->firstElementNumber) {
00731             $urlParameters['pointer'] = $this->firstElementNumber;
00732         }
00733         if ((!$exclList || !t3lib_div::inList($exclList, 'sortField')) && $this->sortField) {
00734             $urlParameters['sortField'] = $this->sortField;
00735         }
00736         if ((!$exclList || !t3lib_div::inList($exclList, 'sortRev')) && $this->sortRev) {
00737             $urlParameters['sortRev'] = $this->sortRev;
00738         }
00739 
00740         return t3lib_BEfunc::getModuleUrl('web_list', $urlParameters);
00741     }
00742 
00743     /**
00744      * Returns "requestUri" - which is basically listURL
00745      *
00746      * @return  string      Content of ->listURL()
00747      */
00748     function requestUri()   {
00749         return $this->listURL();
00750     }
00751 
00752     /**
00753      * Makes the list of fields to select for a table
00754      *
00755      * @param   string      Table name
00756      * @param   boolean     If set, users access to the field (non-exclude-fields) is NOT checked.
00757      * @param   boolean     If set, also adds crdate and tstamp fields (note: they will also be added if user is admin or dontCheckUser is set)
00758      * @return  array       Array, where values are fieldnames to include in query
00759      */
00760     function makeFieldList($table,$dontCheckUser=0,$addDateFields=0)    {
00761         global $TCA,$BE_USER;
00762 
00763             // Init fieldlist array:
00764         $fieldListArr = array();
00765 
00766             // Check table:
00767         if (is_array($TCA[$table])) {
00768             t3lib_div::loadTCA($table);
00769 
00770                 // Traverse configured columns and add them to field array, if available for user.
00771             foreach($TCA[$table]['columns'] as $fN => $fieldValue)  {
00772                 if ($dontCheckUser ||
00773                     ((!$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$fN)) && $fieldValue['config']['type']!='passthrough'))    {
00774                     $fieldListArr[]=$fN;
00775                 }
00776             }
00777 
00778                 // Add special fields:
00779             if ($dontCheckUser || $BE_USER->isAdmin())  {
00780                 $fieldListArr[]='uid';
00781                 $fieldListArr[]='pid';
00782             }
00783 
00784                 // Add date fields
00785             if ($dontCheckUser || $BE_USER->isAdmin() || $addDateFields)    {
00786                 if ($TCA[$table]['ctrl']['tstamp']) $fieldListArr[]=$TCA[$table]['ctrl']['tstamp'];
00787                 if ($TCA[$table]['ctrl']['crdate']) $fieldListArr[]=$TCA[$table]['ctrl']['crdate'];
00788             }
00789 
00790                 // Add more special fields:
00791             if ($dontCheckUser || $BE_USER->isAdmin())  {
00792                 if ($TCA[$table]['ctrl']['cruser_id'])  $fieldListArr[]=$TCA[$table]['ctrl']['cruser_id'];
00793                 if ($TCA[$table]['ctrl']['sortby']) $fieldListArr[]=$TCA[$table]['ctrl']['sortby'];
00794                 if ($TCA[$table]['ctrl']['versioningWS'])   {
00795                     $fieldListArr[]='t3ver_id';
00796                     $fieldListArr[]='t3ver_state';
00797                     $fieldListArr[]='t3ver_wsid';
00798                     if ($table==='pages')   {
00799                         $fieldListArr[]='t3ver_swapmode';
00800                     }
00801                 }
00802             }
00803         }
00804         return $fieldListArr;
00805     }
00806 
00807     /**
00808      * Creates an instance of t3lib_pageTree which will select a page tree to $depth and return the object. In that object we will find the ids of the tree.
00809      *
00810      * @param   integer     Page id.
00811      * @param   integer     Depth to go down.
00812      * @param   string      Select clause
00813      * @return  object      t3lib_pageTree instance with created list of ids.
00814      */
00815     function getTreeObject($id,$depth,$perms_clause)    {
00816         $tree = t3lib_div::makeInstance('t3lib_pageTree');
00817         $tree->init('AND '.$perms_clause);
00818         $tree->makeHTML=0;
00819         $tree->fieldArray = Array('uid','php_tree_stop');
00820         if ($depth) {
00821             $tree->getTree($id, $depth, '');
00822         }
00823         $tree->ids[]=$id;
00824         return $tree;
00825     }
00826 
00827     /**
00828      * Redirects to TCEforms (alt_doc) if a record is just localized.
00829      *
00830      * @param   string      string with table, orig uid and language separated by ":"
00831      * @return  void
00832      */
00833     function localizationRedirect($justLocalized)   {
00834         global $TCA;
00835 
00836         list($table,$orig_uid,$language) = explode(':',$justLocalized);
00837 
00838         if ($TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField']) {
00839             $localizedRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
00840                     'uid',
00841                     $table,
00842                     $TCA[$table]['ctrl']['languageField'].'='.intval($language).' AND '.
00843                         $TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($orig_uid).
00844                         t3lib_BEfunc::deleteClause($table).
00845                         t3lib_BEfunc::versioningPlaceholderClause($table)
00846                 );
00847 
00848             if (is_array($localizedRecord)) {
00849                     // Create parameters and finally run the classic page module for creating a new page translation
00850                 $url = substr($this->listURL(), strlen($this->backPath));
00851                 $params = '&edit['.$table.']['.$localizedRecord['uid'].']=edit';
00852                 $returnUrl = '&returnUrl='.rawurlencode($url);
00853                 $location = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$params.$returnUrl;
00854 
00855                 t3lib_utility_Http::redirect($location);
00856             }
00857         }
00858     }
00859 }
00860 
00861 
00862 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc'])) {
00863     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']);
00864 }
00865 
00866 ?>