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