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