Implemented versioning API, phase 1 (tcemain). See changelog
[Packages/TYPO3.CMS.git] / typo3 / class.db_list.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *
5 *  (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 *  All rights reserved
7 *
8 *  This script is part of the TYPO3 project. The TYPO3 project is
9 *  free software; you can redistribute it and/or modify
10 *  it under the terms of the GNU General Public License as published by
11 *  the Free Software Foundation; either version 2 of the License, or
12 *  (at your option) any later version.
13 *
14 *  The GNU General Public License can be found at
15 *  http://www.gnu.org/copyleft/gpl.html.
16 *  A copy is found in the textfile GPL.txt and important notices to the license
17 *  from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 *  This script is distributed in the hope that it will be useful,
21 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 *  GNU General Public License for more details.
24 *
25 *  This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28  * Include file extending t3lib_recordList
29  * Shared between Web>List (db_list.php) and Web>Page (sysext/cms/layout/db_layout.php)
30  *
31  * $Id$
32  * Revised for TYPO3 3.6 December/2003 by Kasper Skaarhoj
33  * XHTML compliant
34  *
35  * @author      Kasper Skaarhoj <kasper@typo3.com>
36  */
37 /**
38  * [CLASS/FUNCTION INDEX of SCRIPT]
39  *
40  *
41  *
42  *   84: class recordList extends t3lib_recordList
43  *  140:     function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)
44  *  186:     function generateList()
45  *  233:     function getSearchBox($formFields=1)
46  *  276:     function showSysNotesForPage()
47  *
48  *              SECTION: Various helper functions
49  *  353:     function setDispFields()
50  *  378:     function thumbCode($row,$table,$field)
51  *  391:     function makeQueryArray($table, $id, $addWhere="",$fieldList='*')
52  *  433:     function setTotalItems($queryParts)
53  *  449:     function makeSearchString($table)
54  *  488:     function linkWrapTable($table,$code)
55  *  505:     function linkWrapItems($table,$uid,$code,$row)
56  *  532:     function listURL($altId='',$table=-1,$exclList='')
57  *  551:     function requestUri()
58  *  562:     function makeFieldList($table,$dontCheckUser=0)
59  *  601:     function getTreeObject($id,$depth,$perms_clause)
60  *
61  * TOTAL FUNCTIONS: 15
62  * (This index is automatically created/updated by the extension "extdeveval")
63  *
64  */
65
66
67
68
69
70
71
72
73
74
75
76 /**
77  * Child class for rendering of Web > List (not the final class. see class.db_list_extra)
78  *
79  * @author      Kasper Skaarhoj <kasper@typo3.com>
80  * @package TYPO3
81  * @subpackage core
82  * @see localRecordList
83  */
84 class recordList extends t3lib_recordList {
85
86                 // External, static:
87         var $tableList='';                                              // Specify a list of tables which are the only ones allowed to be displayed.
88         var $returnUrl='';                                              // Return URL
89         var $thumbs = 0;                                                // Boolean. Thumbnails on records containing files (pictures)
90         var $itemsLimitPerTable = 20;                   // default Max items shown per table in "multi-table mode", may be overridden by tables.php
91         var $itemsLimitSingleTable = 100;               // default Max items shown per table in "single-table mode", may be overridden by tables.php
92         var $widthGif = '<img src="clear.gif" width="1" height="4" hspace="160" alt="" />';
93         var $script = 'db_list.php';                    // Current script name
94         var $allFields=0;                                               // Indicates if all available fields for a user should be selected or not.
95
96                 // Internal, static: GPvar:
97         var $csvOutput=FALSE;                   // If set, csvList is outputted.
98         var $sortField;                                 // Field, to sort list by
99         var $sortRev;                                   // Field, indicating to sort in reverse order.
100         var $displayFields;                             // Array, containing which fields to display in extended mode
101         var $duplicateField;                    // String, can contain the field name from a table which must have duplicate values marked.
102
103                 // Internal, static:
104         var $id;                                                // Page id
105         var $table='';                                  // Tablename if single-table mode
106         var $listOnlyInSingleTableMode=FALSE;   // If true, records are listed only if a specific table is selected.
107         var $firstElementNumber=0;              // Pointer for browsing list
108         var $searchString='';                   // Search string
109         var $searchLevels='';                   // Levels to search down.
110         var $showLimit=0;                               // Number of records to show
111         var $pidSelect='';                              // List of ids from which to select/search etc. (when search-levels are set high). See start()
112         var $perms_clause='';                   // Page select permissions
113         var $calcPerms=0;                               // Some permissions...
114         var $clickTitleMode = '';               // Mode for what happens when a user clicks the title of a record.
115
116                 // Internal, dynamic:
117         var $JScode = '';                               // JavaScript code accumulation
118         var $HTMLcode = '';                             // HTML output
119         var $iLimit=0;                                  // "LIMIT " in SQL...
120         var $eCounter=0;                                // Counting the elements no matter what...
121         var $totalItems='';                             // Set to the total number of items for a table when selecting.
122         var $recPath_cache=array();             // Cache for record path
123         var $setFields=array();                 // Fields to display for the current table
124         var $currentTable = array();    // Used for tracking next/prev uids
125         var $duplicateStack=array();    // Used for tracking duplicate values of fields
126
127
128
129
130
131         /**
132          * Initializes the list generation
133          *
134          * @param       integer         Page id for which the list is rendered. Must be >= 0
135          * @param       string          Tablename - if extended mode where only one table is listed at a time.
136          * @param       integer         Browsing pointer.
137          * @param       string          Search word, if any
138          * @param       integer         Number of levels to search down the page tree
139          * @param       integer         Limit of records to be listed.
140          * @return      void
141          */
142         function start($id,$table,$pointer,$search="",$levels="",$showLimit=0)  {
143                 global $TCA;
144
145                         // Setting internal variables:
146                 $this->id=intval($id);                                  // sets the parent id
147                 if ($TCA[$table])       $this->table=$table;            // Setting single table mode, if table exists:
148                 $this->firstElementNumber=$pointer;
149                 $this->searchString=trim($search);
150                 $this->searchLevels=trim($levels);
151                 $this->showLimit=t3lib_div::intInRange($showLimit,0,10000);
152
153                         // Setting GPvars:
154                 $this->csvOutput = t3lib_div::_GP('csv') ? TRUE : FALSE;
155                 $this->sortField = t3lib_div::_GP('sortField');
156                 $this->sortRev = t3lib_div::_GP('sortRev');
157                 $this->displayFields = t3lib_div::_GP('displayFields');
158                 $this->duplicateField = t3lib_div::_GP('duplicateField');
159
160                         // If thumbnails are disabled, set the "notfound" icon as default:
161                 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
162                         $this->thumbScript='gfx/notfound_thumb.gif';
163                 }
164
165                         // Init dynamic vars:
166                 $this->counter=0;
167                 $this->JScode='';
168                 $this->HTMLcode='';
169
170                         // Set select levels:
171                 $sL=intval($this->searchLevels);
172                 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
173                 if ($sL>0)      {
174                         $tree = $this->getTreeObject($id,$sL,$this->perms_clause);
175                         $this->pidSelect = 'pid IN ('.implode(',',$tree->ids).')';
176                 } else {
177                         $this->pidSelect = 'pid='.intval($id);
178                 }
179         }
180
181         /**
182          * Traverses the table(s) to be listed and renders the output code for each:
183          * The HTML is accumulated in $this->HTMLcode
184          * Finishes off with a stopper-gif
185          *
186          * @return      void
187          */
188         function generateList() {
189                 global $TCA;
190
191                         // Traverse the TCA table array:
192                 reset($TCA);
193                 while (list($tableName)=each($TCA))     {
194
195                                 // Checking if the table should be rendered:
196                         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:
197
198                                         // Load full table definitions:
199                                 t3lib_div::loadTCA($tableName);
200
201                                         // iLimit is set depending on whether we're in single- or multi-table mode
202                                 if ($this->table)       {
203                                         $this->iLimit=(isset($TCA[$tableName]['interface']['maxSingleDBListItems'])?intval($TCA[$tableName]['interface']['maxSingleDBListItems']):$this->itemsLimitSingleTable);
204                                 } else {
205                                         $this->iLimit=(isset($TCA[$tableName]['interface']['maxDBListItems'])?intval($TCA[$tableName]['interface']['maxDBListItems']):$this->itemsLimitPerTable);
206                                 }
207                                 if ($this->showLimit)   $this->iLimit = $this->showLimit;
208
209                                         // Setting fields to select:
210                                 if ($this->allFields)   {
211                                         $fields = $this->makeFieldList($tableName);
212                                         $fields[]='_PATH_';
213                                         $fields[]='_CONTROL_';
214                                         if (is_array($this->setFields[$tableName]))     {
215                                                 $fields = array_intersect($fields,$this->setFields[$tableName]);
216                                         } else {
217                                                 $fields = array();
218                                         }
219                                 } else {
220                                         $fields = array();
221                                 }
222
223                                         // Finally, render the list:
224                                 $this->HTMLcode.=$this->getTable($tableName, $this->id,implode(',',$fields));
225                         }
226                 }
227         }
228
229         /**
230          * Creates the search box
231          *
232          * @param       boolean         If true, the search box is wrapped in its own form-tags
233          * @return      string          HTML for the search box
234          */
235         function getSearchBox($formFields=1)    {
236
237                         // Setting form-elements, if applicable:
238                 $formElements=array('','');
239                 if ($formFields)        {
240                         $formElements=array('<form action="'.htmlspecialchars($this->listURL()).'" method="post">','</form>');
241                 }
242
243                         // Make level selector:
244                 $opt=array();
245                 $parts = explode('|',$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchLevels'));
246                 while(list($kv,$label)=each($parts))    {
247                         $opt[] = '<option value="'.$kv.'"'.($kv==intval($this->searchLevels)?' selected="selected"':'').'>'.htmlspecialchars($label).'</option>';
248                 }
249                 $lMenu = '<select name="search_levels">'.implode('',$opt).'</select>';
250
251                         // Table with the search box:
252                 $content.= '
253                         '.$formElements[0].'
254
255                                 <!--
256                                         Search box:
257                                 -->
258                                 <table border="0" cellpadding="0" cellspacing="0" class="bgColor4" id="typo3-dblist-search">
259                                         <tr>
260                                                 <td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.enterSearchString',1).'<input type="text" name="search_field" value="'.htmlspecialchars($this->searchString).'"'.$GLOBALS['TBE_TEMPLATE']->formWidth(10).' /></td>
261                                                 <td>'.$lMenu.'</td>
262                                                 <td><input type="submit" name="search" value="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.search',1).'" /></td>
263                                         </tr>
264                                         <tr>
265                                                 <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>
266                                         </tr>
267                                 </table>
268                         '.$formElements[1];
269                 $content.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['BACK_PATH'],'|<br/>');
270                 return $content;
271         }
272
273         /**
274          * Creates the display of sys_notes for the page.
275          * Relies on the "sys_note" extension to be loaded.
276          *
277          * @return      string          HTML for the sys-notes (if any)
278          */
279         function showSysNotesForPage()  {
280                 global $TCA;
281
282                 $out='';
283
284                         // Checking if extension is loaded:
285                 if (!t3lib_extMgm::isLoaded('sys_note'))        return '';
286
287                         // Create query for selecting the notes:
288                 $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'));
289
290                         // Executing query:
291                 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
292
293                         // If some notes were found, render them:
294                 if ($dbCount)   {
295                         $cat = array();
296
297                                 // Load full table description:
298                         t3lib_div::loadTCA('sys_note');
299
300                                 // Traverse note-types and get labels:
301                         if ($TCA['sys_note'] && $TCA['sys_note']['columns']['category'] && is_array($TCA['sys_note']['columns']['category']['config']['items']))        {
302                                 foreach($TCA['sys_note']['columns']['category']['config']['items'] as $el)      {
303                                         $cat[$el[1]]=$GLOBALS['LANG']->sL($el[0]);
304                                 }
305                         }
306
307                                 // For each note found, make rendering:
308                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result))    {
309
310                                         // Create content:
311                                 $iconImg = t3lib_iconWorks::getIconImage('sys_note',$row,$this->backPath,'');
312                                 $subject = htmlspecialchars($row['subject']);
313                                 $fields = array();
314                                 $fields['Author:'] = htmlspecialchars($row['author'].($row['email'] && $row['author'] ? ', ':'').$row['email']);
315                                 $fields['Category:'] = htmlspecialchars($cat[$row['category']]);
316                                 $fields['Note:'] = nl2br(htmlspecialchars($row['message']));
317
318                                         // Compile content:
319                                 $out.='
320
321
322                                 <!--
323                                         Sys-notes for the db_list.php:
324                                 -->
325                                         <table border="0" cellpadding="1" cellspacing="1" id="typo3-dblist-sysnotes">
326                                                 <tr><td colspan="2" class="bgColor2">'.$iconImg.'<strong>'.$subject.'</strong></td></tr>
327                                                 <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.category',1).'</td><td class="bgColor4">'.$fields['Category:'].'</td></tr>
328                                                 <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.author',1).'</td><td class="bgColor4">'.$fields['Author:'].'</td></tr>
329                                                 <tr><td class="bgColor4">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.note',1).'</td><td class="bgColor4">'.$fields['Note:'].'</td></tr>
330                                         </table>
331                                 ';
332                         }
333                 }
334                 return $out;
335         }
336
337
338
339
340
341
342
343
344         /******************************
345          *
346          * Various helper functions
347          *
348          ******************************/
349
350         /**
351          * Setting the field names to display in extended list.
352          * Sets the internal variable $this->setFields
353          *
354          * @return      void
355          */
356         function setDispFields()        {
357
358                         // Getting from session:
359                 $dispFields = $GLOBALS['BE_USER']->getModuleData('db_list.php/displayFields');
360
361                         // If fields has been inputted, then set those as the value and push it to session variable:
362                 if (is_array($this->displayFields))     {
363                         reset($this->displayFields);
364                         $tKey = key($this->displayFields);
365                         $dispFields[$tKey]=$this->displayFields[$tKey];
366                         $GLOBALS['BE_USER']->pushModuleData('db_list.php/displayFields',$dispFields);
367                 }
368
369                         // Setting result:
370                 $this->setFields=$dispFields;
371         }
372
373         /**
374          * Create thumbnail code for record/field
375          *
376          * @param       array           Record array
377          * @param       string          Table (record is from)
378          * @param       string          Field name for which thumbsnail are to be rendered.
379          * @return      string          HTML for thumbnails, if any.
380          */
381         function thumbCode($row,$table,$field)  {
382                 return t3lib_BEfunc::thumbCode($row,$table,$field,$this->backPath,$this->thumbScript);
383         }
384
385         /**
386          * Returns the SQL-query array to select the records from a table $table with pid = $id
387          *
388          * @param       string          Table name
389          * @param       integer         Page id (NOT USED! $this->pidSelect is used instead)
390          * @param       string          Additional part for where clause
391          * @param       string          Field list to select, * for all (for "SELECT [fieldlist] FROM ...")
392          * @return      array           Returns query array
393          */
394         function makeQueryArray($table, $id, $addWhere="",$fieldList='*')       {
395                 global $TCA;
396
397                         // Set ORDER BY:
398                 $orderBy = ($TCA[$table]['ctrl']['sortby']) ? 'ORDER BY '.$TCA[$table]['ctrl']['sortby'] : $TCA[$table]['ctrl']['default_sortby'];
399                 if ($this->sortField)   {
400                         if (in_array($this->sortField,$this->makeFieldList($table,1)))  {
401                                 $orderBy = 'ORDER BY '.$this->sortField;
402                                 if ($this->sortRev)     $orderBy.=' DESC';
403                         }
404                 }
405
406                         // Set LIMIT:
407                 $limit = $this->iLimit ? ($this->firstElementNumber ? $this->firstElementNumber.',' : '').($this->iLimit+1) : '';
408
409                         // Filtering on displayable pages (permissions):
410                 $pC = ($table=='pages' && $this->perms_clause)?' AND '.$this->perms_clause:'';
411
412                         // Adding search constraints:
413                 $search = $this->makeSearchString($table);
414
415                         // Compiling query array:
416                 $queryParts = array(
417                         'SELECT' => $fieldList,
418                         'FROM' => $table,
419                         'WHERE' => $this->pidSelect.' '.$pC.t3lib_BEfunc::deleteClause($table).' '.$addWhere.' '.$search,
420                         'GROUPBY' => '',
421                         'ORDERBY' => $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy),
422                         'LIMIT' => $limit
423                 );
424
425                         // Return query:
426                 return $queryParts;
427         }
428
429         /**
430          * 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
431          *
432          * @param       array           Query array
433          * @return      void
434          * @see makeQueryArray()
435          */
436         function setTotalItems($queryParts)     {
437                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
438                                         'count(*)',
439                                         $queryParts['FROM'],
440                                         $queryParts['WHERE']
441                                 );
442                 list($rCount) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
443                 $this->totalItems = $rCount;
444         }
445
446         /**
447          * Creates part of query for searching after a word ($this->searchString) fields in input table
448          *
449          * @param       string          Table, in which the fields are being searched.
450          * @return      string          Returns part of WHERE-clause for searching, if applicable.
451          */
452         function makeSearchString($table)       {
453                 global $TCA;
454
455                         // Make query, only if table is valid and a search string is actually defined:
456                 if ($TCA[$table] && $this->searchString)        {
457
458                                 // Loading full table description - we need to traverse fields:
459                         t3lib_div::loadTCA($table);
460
461                                 // Initialize field array:
462                         $sfields=array();
463                         $sfields[]='uid';       // Adding "uid" by default.
464
465                                 // Traverse the configured columns and add all columns that can be searched:
466                         foreach($TCA[$table]['columns'] as $fieldName => $info) {
467                                 if ($info['config']['type']=='text' || ($info['config']['type']=='input' && !ereg('date|time|int',$info['config']['eval'])))    {
468                                         $sfields[]=$fieldName;
469                                 }
470                         }
471
472                                 // If search-fields were defined (and there always are) we create the query:
473                         if (count($sfields))    {
474                                 $like=' LIKE "%'.$GLOBALS['TYPO3_DB']->quoteStr($this->searchString, $table).'%"';              // Free-text searching...
475                                 $queryPart = ' AND ('.implode($like.' OR ',$sfields).$like.')';
476
477                                         // Return query:
478                                 return $queryPart;
479                         }
480                 }
481         }
482
483         /**
484          * Returns the title (based on $code) of a table ($table) with the proper link around. For headers over tables.
485          * The link will cause the display of all extended mode or not for the table.
486          *
487          * @param       string          Table name
488          * @param       string          Table label
489          * @return      string          The linked table label
490          */
491         function linkWrapTable($table,$code)    {
492                 if ($this->table!=$table)       {
493                         return '<a href="'.htmlspecialchars($this->listURL('',$table)).'">'.$code.'</a>';
494                 } else {
495                         return '<a href="'.htmlspecialchars($this->listURL('','','sortField,sortRev,table')).'">'.$code.'</a>';
496                 }
497         }
498
499         /**
500          * 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...)
501          *
502          * @param       string          Table name
503          * @param       integer         Item uid
504          * @param       string          Item title (not htmlspecialchars()'ed yet)
505          * @param       array           Item row
506          * @return      string          The item title. Ready for HTML output (is htmlspecialchars()'ed)
507          */
508         function linkWrapItems($table,$uid,$code,$row)  {
509                 global $TCA, $LANG;
510
511                         // If the title is blank, make a "no title" label:
512                 if (!strcmp($code,'')) {
513                         $code = '<i>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</i> - '.htmlspecialchars(t3lib_BEfunc::getRecordTitle($table,$row));
514                 } else {
515                         $code = htmlspecialchars(t3lib_div::fixed_lgd_cs($code,$this->fixedL));
516                 }
517
518                 switch((string)$this->clickTitleMode)   {
519                         case 'edit':
520                                         // If the listed table is 'pages' we have to request the permission settings for each page:
521                                 if ($table=='pages')    {
522                                         $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$row['uid']));
523                                         $permsEdit = $localCalcPerms&2;
524                                 } else {
525                                         $permsEdit = $this->calcPerms&16;
526                                 }
527
528                                         // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
529                                 if ($permsEdit) {
530                                         $params='&edit['.$table.']['.$row['uid'].']=edit';
531                                         $code = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,'',-1)).'" title="'.$LANG->getLL('edit',1).'">'.
532                                                         $code.
533                                                         '</a>';
534                                 }
535                         break;
536                         case 'show':
537                                         // "Show" link (only pages and tt_content elements)
538                                 if ($table=='pages' || $table=='tt_content')    {
539                                         $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).'">'.
540                                                         $code.
541                                                         '</a>';
542                                 }
543                         break;
544                         case 'info':
545                                 // "Info": (All records)
546                                 $code = '<a href="#" onclick="'.htmlspecialchars('top.launchView(\''.$table.'\', \''.$row['uid'].'\'); return false;').'" title="'.$LANG->getLL('showInfo',1).'">'.
547                                         $code.
548                                         '</a>';
549                         break;
550                         default:
551                                         // Output the label now:
552                                 if ($table=='pages')    {
553                                         $code = '<a href="'.htmlspecialchars($this->listURL($uid,'')).'">'.$code.'</a>';
554                                 }
555                         break;
556                 }
557
558                 return $code;
559         }
560
561         /**
562          * Creates the URL to this script, including all relevant GPvars
563          * Fixed GPvars are id, table, imagemode, returlUrl, search_field, search_levels and showLimit
564          * The GPvars "sortField" and "sortRev" are also included UNLESS they are found in the $exclList variable.
565          *
566          * @param       string          Alternative id value. Enter blank string for the current id ($this->id)
567          * @param       string          Tablename to display. Enter "-1" for the current table.
568          * @param       string          Commalist of fields NOT to include ("sortField" or "sortRev")
569          * @return      string          URL
570          */
571         function listURL($altId='',$table=-1,$exclList='')      {
572                 return $this->script.
573                         '?id='.(strcmp($altId,'')?$altId:$this->id).
574                         '&table='.rawurlencode($table==-1?$this->table:$table).
575                         ($this->thumbs?'&imagemode='.$this->thumbs:'').
576                         ($this->returnUrl?'&returnUrl='.rawurlencode($this->returnUrl):'').
577                         ($this->searchString?'&search_field='.rawurlencode($this->searchString):'').
578                         ($this->searchLevels?'&search_levels='.rawurlencode($this->searchLevels):'').
579                         ($this->showLimit?'&showLimit='.rawurlencode($this->showLimit):'').
580                         ((!$exclList || !t3lib_div::inList($exclList,'sortField')) && $this->sortField?'&sortField='.rawurlencode($this->sortField):'').
581                         ((!$exclList || !t3lib_div::inList($exclList,'sortRev')) && $this->sortRev?'&sortRev='.rawurlencode($this->sortRev):'')
582                         ;
583         }
584
585         /**
586          * Returns "requestUri" - which is basically listURL
587          *
588          * @return      string          Content of ->listURL()
589          */
590         function requestUri()   {
591                 return $this->listURL();
592         }
593
594         /**
595          * Makes the list of fields to select for a table
596          *
597          * @param       string          Table name
598          * @param       boolean         If set, users access to the field (non-exclude-fields) is NOT checked.
599          * @return      array           Array, where values are fieldnames to include in query
600          */
601         function makeFieldList($table,$dontCheckUser=0) {
602                 global $TCA,$BE_USER;
603
604                         // Init fieldlist array:
605                 $fieldListArr = array();
606
607                         // Check table:
608                 if (is_array($TCA[$table]))     {
609                         t3lib_div::loadTCA($table);
610
611                                 // Traverse configured columns and add them to field array, if available for user.
612                         foreach($TCA[$table]['columns'] as $fN => $fieldValue)  {
613                                 if ($dontCheckUser ||
614                                         ((!$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$fN)) && $fieldValue['config']['type']!='passthrough'))    {
615                                         $fieldListArr[]=$fN;
616                                 }
617                         }
618
619                                 // Add special fields:
620                         if ($dontCheckUser || $BE_USER->isAdmin())      {
621                                 $fieldListArr[]='uid';
622                                 $fieldListArr[]='pid';
623                                 if ($TCA[$table]['ctrl']['tstamp'])     $fieldListArr[]=$TCA[$table]['ctrl']['tstamp'];
624                                 if ($TCA[$table]['ctrl']['crdate'])     $fieldListArr[]=$TCA[$table]['ctrl']['crdate'];
625                                 if ($TCA[$table]['ctrl']['cruser_id'])  $fieldListArr[]=$TCA[$table]['ctrl']['cruser_id'];
626                                 if ($TCA[$table]['ctrl']['sortby'])     $fieldListArr[]=$TCA[$table]['ctrl']['sortby'];
627                                 if ($TCA[$table]['ctrl']['versioning']) $fieldListArr[]='t3ver_id';
628                         }
629                 }
630                 return $fieldListArr;
631         }
632
633         /**
634          * 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.
635          *
636          * @param       integer         Page id.
637          * @param       integer         Depth to go down.
638          * @param       string          Select clause
639          * @return      object          t3lib_pageTree instance with created list of ids.
640          */
641         function getTreeObject($id,$depth,$perms_clause)        {
642                 $tree = t3lib_div::makeInstance('t3lib_pageTree');
643                 $tree->init('AND '.$perms_clause);
644                 $tree->makeHTML=0;
645                 $tree->fieldArray = Array('uid','php_tree_stop');
646                 if ($depth)     {
647                         $tree->getTree($id, $depth, '');
648                 }
649                 $tree->ids[]=$id;
650                 return $tree;
651         }
652
653 }
654
655
656 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']) {
657         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.db_list.inc']);
658 }
659 ?>