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