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