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