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