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