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