PageRenderTime 64ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/typo3/class.db_list.inc

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