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