[BUGFIX] Wrong colspan in DatabaseRecordList
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / RecordList / DatabaseRecordList.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\RecordList;
3
4 /*************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32 use TYPO3\CMS\Backend\Utility\BackendUtility;
33 use TYPO3\CMS\Backend\Utility\IconUtility;
34
35 /**
36 * Class for rendering of Web>List module
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 class DatabaseRecordList extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList {
41
42 // External:
43 // If TRUE, table rows in the list will alternate in background colors (and have background colors at all!)
44 /**
45 * @todo Define visibility
46 */
47 public $alternateBgColors = FALSE;
48
49 // Used to indicate which tables (values in the array) that can have a create-new-record link. If the array is empty, all tables are allowed.
50 /**
51 * @todo Define visibility
52 */
53 public $allowedNewTables = array();
54
55 // Used to indicate which tables (values in the array) that cannot have a create-new-record link. If the array is empty, all tables are allowed.
56 /**
57 * @todo Define visibility
58 */
59 public $deniedNewTables = array();
60
61 // If TRUE, the control panel will contain links to the create-new wizards for pages and tt_content elements (normally, the link goes to just creating a new element without the wizards!).
62 /**
63 * @todo Define visibility
64 */
65 public $newWizards = FALSE;
66
67 // If TRUE, will disable the rendering of clipboard + control panels.
68 /**
69 * @todo Define visibility
70 */
71 public $dontShowClipControlPanels = FALSE;
72
73 // If TRUE, will show the clipboard in the field list.
74 /**
75 * @todo Define visibility
76 */
77 public $showClipboard = FALSE;
78
79 // If TRUE, will DISABLE all control panels in lists. (Takes precedence)
80 /**
81 * @todo Define visibility
82 */
83 public $noControlPanels = FALSE;
84
85 // If TRUE, clickmenus will be rendered
86 /**
87 * @todo Define visibility
88 */
89 public $clickMenuEnabled = TRUE;
90
91 // Count of record rows in view
92 /**
93 * @todo Define visibility
94 */
95 public $totalRowCount;
96
97 // Space icon used for alignment
98 /**
99 * @todo Define visibility
100 */
101 public $spaceIcon;
102
103 // Internal:
104 // Set to the page record (see writeTop())
105 /**
106 * @todo Define visibility
107 */
108 public $pageRow = array();
109
110 // Used to accumulate CSV lines for CSV export.
111 protected $csvLines = array();
112
113 // If set, the listing is returned as CSV instead.
114 /**
115 * @todo Define visibility
116 */
117 public $csvOutput = FALSE;
118
119 /**
120 * Clipboard object
121 *
122 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
123 * @todo Define visibility
124 */
125 public $clipObj;
126
127 // Tracking names of elements (for clipboard use)
128 /**
129 * @todo Define visibility
130 */
131 public $CBnames = array();
132
133 // Used to track which elements has duplicates and how many
134 /**
135 * @todo Define visibility
136 */
137 public $duplicateStack = array();
138
139 /**
140 * [$tablename][$uid] = number of references to this record
141 *
142 * @var array
143 */
144 protected $referenceCount = array();
145
146 // Translations of the current record
147 /**
148 * @todo Define visibility
149 */
150 public $translations;
151
152 // select fields for the query which fetches the translations of the current record
153 /**
154 * @todo Define visibility
155 */
156 public $selFieldList;
157
158 public $disableSingleTableView = FALSE;
159
160 /**
161 * Create the panel of buttons for submitting the form or otherwise perform operations.
162 *
163 * @return array All available buttons as an assoc. array
164 */
165 public function getButtons() {
166 $buttons = array(
167 'csh' => '',
168 'view' => '',
169 'edit' => '',
170 'hide_unhide' => '',
171 'move' => '',
172 'new_record' => '',
173 'paste' => '',
174 'level_up' => '',
175 'cache' => '',
176 'reload' => '',
177 'shortcut' => '',
178 'back' => '',
179 'csv' => '',
180 'export' => ''
181 );
182 // Get users permissions for this page record:
183 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageRow);
184 // CSH
185 if (!strlen($this->id)) {
186 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_noId', $GLOBALS['BACK_PATH'], '', TRUE);
187 } elseif (!$this->id) {
188 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_root', $GLOBALS['BACK_PATH'], '', TRUE);
189 } else {
190 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module', $GLOBALS['BACK_PATH'], '', TRUE);
191 }
192 if (isset($this->id)) {
193 // View Exclude doktypes 254,255 Configuration: mod.web_list.noViewWithDokTypes = 254,255
194 if (isset($GLOBALS['SOBE']->modTSconfig['properties']['noViewWithDokTypes'])) {
195 $noViewDokTypes = GeneralUtility::trimExplode(',', $GLOBALS['SOBE']->modTSconfig['properties']['noViewWithDokTypes'], TRUE);
196 } else {
197 //default exclusion: doktype 254 (folder), 255 (recycler)
198 $noViewDokTypes = array(\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SYSFOLDER, \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER);
199 }
200 if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
201 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->id, $this->backPath, BackendUtility::BEgetRootLine($this->id))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
202 }
203 // New record
204 if (!$GLOBALS['SOBE']->modTSconfig['properties']['noCreateRecordsLink']) {
205 $buttons['new_record'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpExt(\'' . $this->backPath . 'db_new.php?id=' . $this->id . '\');')) . '" title="' . $GLOBALS['LANG']->getLL('newRecordGeneral', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
206 }
207 // If edit permissions are set, see \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
208 if ($localCalcPerms & 2 && !empty($this->id)) {
209 // Edit
210 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
211 $buttons['edit'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('editPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-page-open') . '</a>';
212 }
213 // Paste
214 if ($localCalcPerms & 8 || $localCalcPerms & 16) {
215 $elFromTable = $this->clipObj->elFromTable('');
216 if (count($elFromTable)) {
217 $buttons['paste'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('', $this->id)) . '" onclick="' . htmlspecialchars(('return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into', $elFromTable))) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
218 }
219 }
220 // Cache
221 $buttons['cache'] = '<a href="' . htmlspecialchars(($this->listURL() . '&clear_cache=1')) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-cache-clear') . '</a>';
222 if ($this->table && (!isset($GLOBALS['SOBE']->modTSconfig['properties']['noExportRecordsLinks'])
223 || (isset($GLOBALS['SOBE']->modTSconfig['properties']['noExportRecordsLinks']) && !$GLOBALS['SOBE']->modTSconfig['properties']['noExportRecordsLinks']))
224 ) {
225 // CSV
226 $buttons['csv'] = '<a href="' . htmlspecialchars(($this->listURL() . '&csv=1')) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.csv', TRUE) . '">' . IconUtility::getSpriteIcon('mimetypes-text-csv') . '</a>';
227 // Export
228 if (ExtensionManagementUtility::isLoaded('impexp')) {
229 $url = $this->backPath . ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export';
230 $buttons['export'] = '<a href="' . htmlspecialchars(($url . '&tx_impexp[list][]=' . rawurlencode(($this->table . ':' . $this->id)))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.export', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-export-t3d') . '</a>';
231 }
232 }
233 // Reload
234 $buttons['reload'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.reload', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
235 // Shortcut
236 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
237 $buttons['shortcut'] = $GLOBALS['TBE_TEMPLATE']->makeShortcutIcon('id, imagemode, pointer, table, search_field, search_levels, showLimit, sortField, sortRev', implode(',', array_keys($this->MOD_MENU)), 'web_list');
238 }
239 // Back
240 if ($this->returnUrl) {
241 $buttons['back'] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl, array('id' => $this->id))) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
242 }
243 }
244 return $buttons;
245 }
246
247 /**
248 * Creates the listing of records from a single table
249 *
250 * @param string $table Table name
251 * @param integer $id Page id
252 * @param string $rowlist List of fields to show in the listing. Pseudo fields will be added including the record header.
253 * @return string HTML table with the listing for the record.
254 * @todo Define visibility
255 */
256 public function getTable($table, $id, $rowlist) {
257 // Init
258 $addWhere = '';
259 $titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'];
260 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
261 $l10nEnabled = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'];
262 $tableCollapsed = (boolean)$this->tablesCollapsed[$table];
263 // prepare space icon
264 $this->spaceIcon = IconUtility::getSpriteIcon('empty-empty', array('style' => 'background-position: 0 10px;'));
265 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
266 $this->fieldArray = array();
267 // title Column
268 // Add title column
269 $this->fieldArray[] = $titleCol;
270 // Control-Panel
271 if (!GeneralUtility::inList($rowlist, '_CONTROL_')) {
272 $this->fieldArray[] = '_CONTROL_';
273 $this->fieldArray[] = '_AFTERCONTROL_';
274 }
275 // Clipboard
276 if ($this->showClipboard) {
277 $this->fieldArray[] = '_CLIPBOARD_';
278 }
279 // Ref
280 if (!$this->dontShowClipControlPanels) {
281 $this->fieldArray[] = '_REF_';
282 $this->fieldArray[] = '_AFTERREF_';
283 }
284 // Path
285 if ($this->searchLevels) {
286 $this->fieldArray[] = '_PATH_';
287 }
288 // Localization
289 if ($this->localizationView && $l10nEnabled) {
290 $this->fieldArray[] = '_LOCALIZATION_';
291 $this->fieldArray[] = '_LOCALIZATION_b';
292 $addWhere .= ' AND (
293 ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '<=0
294 OR
295 ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . ' = 0
296 )';
297 }
298 // Cleaning up:
299 $this->fieldArray = array_unique(array_merge($this->fieldArray, GeneralUtility::trimExplode(',', $rowlist, TRUE)));
300 if ($this->noControlPanels) {
301 $tempArray = array_flip($this->fieldArray);
302 unset($tempArray['_CONTROL_']);
303 unset($tempArray['_CLIPBOARD_']);
304 $this->fieldArray = array_keys($tempArray);
305 }
306 // Creating the list of fields to include in the SQL query:
307 $selectFields = $this->fieldArray;
308 $selectFields[] = 'uid';
309 $selectFields[] = 'pid';
310 // adding column for thumbnails
311 if ($thumbsCol) {
312 $selectFields[] = $thumbsCol;
313 }
314 if ($table == 'pages') {
315 if (ExtensionManagementUtility::isLoaded('cms')) {
316 $selectFields[] = 'module';
317 $selectFields[] = 'extendToSubpages';
318 $selectFields[] = 'nav_hide';
319 }
320 $selectFields[] = 'doktype';
321 }
322 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
323 $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
324 }
325 if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
326 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
327 }
328 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
329 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
330 }
331 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
332 $selectFields[] = 't3ver_id';
333 $selectFields[] = 't3ver_state';
334 $selectFields[] = 't3ver_wsid';
335 }
336 if ($l10nEnabled) {
337 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
338 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
339 }
340 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
341 $selectFields = array_merge($selectFields, GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], TRUE));
342 }
343 // Unique list!
344 $selectFields = array_unique($selectFields);
345 $fieldListFields = $this->makeFieldList($table, 1);
346 if (empty($fieldListFields) && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
347 $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:missingTcaColumnsMessage', TRUE), $table, $table);
348 $messageTitle = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:missingTcaColumnsMessageTitle', TRUE);
349 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $message, $messageTitle, \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, TRUE);
350 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
351 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
352 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
353 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
354 $defaultFlashMessageQueue->enqueue($flashMessage);
355 }
356 // Making sure that the fields in the field-list ARE in the field-list from TCA!
357 $selectFields = array_intersect($selectFields, $fieldListFields);
358 // Implode it into a list of fields for the SQL-statement.
359 $selFieldList = implode(',', $selectFields);
360 $this->selFieldList = $selFieldList;
361 /**
362 * @hook DB-List getTable
363 * @date 2007-11-16
364 * @request Malte Jansen <mail@maltejansen.de>
365 */
366 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'])) {
367 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'] as $classData) {
368 $hookObject = GeneralUtility::getUserObj($classData);
369 if (!$hookObject instanceof \TYPO3\CMS\Backend\RecordList\RecordListGetTableHookInterface) {
370 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\RecordList\\RecordListGetTableHookInterface', 1195114460);
371 }
372 $hookObject->getDBlistQuery($table, $id, $addWhere, $selFieldList, $this);
373 }
374 }
375 // Create the SQL query for selecting the elements in the listing:
376 // do not do paging when outputting as CSV
377 if ($this->csvOutput) {
378 $this->iLimit = 0;
379 }
380 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
381 // Get the two previous rows for sorting if displaying page > 1
382 $this->firstElementNumber = $this->firstElementNumber - 2;
383 $this->iLimit = $this->iLimit + 2;
384 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
385 $queryParts = $this->makeQueryArray($table, $id, $addWhere, $selFieldList);
386 $this->firstElementNumber = $this->firstElementNumber + 2;
387 $this->iLimit = $this->iLimit - 2;
388 } else {
389 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
390 $queryParts = $this->makeQueryArray($table, $id, $addWhere, $selFieldList);
391 }
392
393 // Finding the total amount of records on the page
394 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
395 $this->setTotalItems($queryParts);
396
397 // Init:
398 $dbCount = 0;
399 $out = '';
400 $listOnlyInSingleTableMode = $this->listOnlyInSingleTableMode && !$this->table;
401 // If the count query returned any number of records, we perform the real query, selecting records.
402 if ($this->totalItems) {
403 // Fetch records only if not in single table mode or if in multi table mode and not collapsed
404 if ($listOnlyInSingleTableMode || !$this->table && $tableCollapsed) {
405 $dbCount = $this->totalItems;
406 } else {
407 // Set the showLimit to the number of records when outputting as CSV
408 if ($this->csvOutput) {
409 $this->showLimit = $this->totalItems;
410 $this->iLimit = $this->totalItems;
411 }
412 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
413 $dbCount = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
414 }
415 }
416 // If any records was selected, render the list:
417 if ($dbCount) {
418 // Half line is drawn between tables:
419 if (!$listOnlyInSingleTableMode) {
420 $theData = array();
421 if (!$this->table && !$rowlist) {
422 $theData[$titleCol] = '<img src="clear.gif" width="' . ($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel'] ? '230' : '350') . '" height="1" alt="" />';
423 if (in_array('_CONTROL_', $this->fieldArray)) {
424 $theData['_CONTROL_'] = '';
425 }
426 if (in_array('_CLIPBOARD_', $this->fieldArray)) {
427 $theData['_CLIPBOARD_'] = '';
428 }
429 }
430 $out .= $this->addelement(0, '', $theData, 'class="c-table-row-spacer"', $this->leftMargin);
431 }
432 $tableTitle = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title'], TRUE);
433 if ($tableTitle === '') {
434 $tableTitle = $table;
435 }
436 // Header line is drawn
437 $theData = array();
438 if ($this->disableSingleTableView) {
439 $theData[$titleCol] = '<span class="c-table">' . BackendUtility::wrapInHelp($table, '', $tableTitle) . '</span> (' . $this->totalItems . ')';
440 } else {
441 $theData[$titleCol] = $this->linkWrapTable($table, '<span class="c-table">' . $tableTitle . '</span> (' . $this->totalItems . ') ' . ($this->table ? IconUtility::getSpriteIcon('actions-view-table-collapse', array('title' => $GLOBALS['LANG']->getLL('contractView', TRUE))) : IconUtility::getSpriteIcon('actions-view-table-expand', array('title' => $GLOBALS['LANG']->getLL('expandView', TRUE)))));
442 }
443 if ($listOnlyInSingleTableMode) {
444 $out .= '
445 <tr>
446 <td class="t3-row-header" style="width:95%;">' . BackendUtility::wrapInHelp($table, '', $theData[$titleCol]) . '</td>
447 </tr>';
448 } else {
449 // Render collapse button if in multi table mode
450 $collapseIcon = '';
451 if (!$this->table) {
452 $collapseIcon = '<a href="' . htmlspecialchars(($this->listURL() . '&collapse[' . $table . ']=' . ($tableCollapsed ? '0' : '1'))) . '" title="' . ($tableCollapsed ? $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.expandTable', TRUE) : $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.collapseTable', TRUE)) . '">' . ($tableCollapsed ? IconUtility::getSpriteIcon('actions-view-list-expand', array('class' => 'collapseIcon')) : IconUtility::getSpriteIcon('actions-view-list-collapse', array('class' => 'collapseIcon'))) . '</a>';
453 }
454 $out .= $this->addElement(1, $collapseIcon, $theData, ' class="t3-row-header"', '');
455 }
456 // Render table rows only if in multi table view and not collapsed or if in single table view
457 if (!$listOnlyInSingleTableMode && (!$tableCollapsed || $this->table)) {
458 // Fixing a order table for sortby tables
459 $this->currentTable = array();
460 $currentIdList = array();
461 $doSort = $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField;
462 $prevUid = 0;
463 $prevPrevUid = 0;
464 // Get first two rows and initialize prevPrevUid and prevUid if on page > 1
465 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
466 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
467 $prevPrevUid = -((int)$row['uid']);
468 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
469 $prevUid = $row['uid'];
470 }
471 $accRows = array();
472 // Accumulate rows here
473 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
474 if (!$this->isRowListingConditionFulfilled($table, $row)) {
475 continue;
476 }
477 // In offline workspace, look for alternative record:
478 BackendUtility::workspaceOL($table, $row, $GLOBALS['BE_USER']->workspace, TRUE);
479 if (is_array($row)) {
480 $accRows[] = $row;
481 $currentIdList[] = $row['uid'];
482 if ($doSort) {
483 if ($prevUid) {
484 $this->currentTable['prev'][$row['uid']] = $prevPrevUid;
485 $this->currentTable['next'][$prevUid] = '-' . $row['uid'];
486 $this->currentTable['prevUid'][$row['uid']] = $prevUid;
487 }
488 $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
489 $prevUid = $row['uid'];
490 }
491 }
492 }
493 $GLOBALS['TYPO3_DB']->sql_free_result($result);
494 $this->totalRowCount = count($accRows);
495 // CSV initiated
496 if ($this->csvOutput) {
497 $this->initCSV();
498 }
499 // Render items:
500 $this->CBnames = array();
501 $this->duplicateStack = array();
502 $this->eCounter = $this->firstElementNumber;
503 $iOut = '';
504 $cc = 0;
505 foreach ($accRows as $row) {
506 // Render item row if counter < limit
507 if ($cc < $this->iLimit) {
508 $cc++;
509 $this->translations = FALSE;
510 $iOut .= $this->renderListRow($table, $row, $cc, $titleCol, $thumbsCol);
511 // If localization view is enabled it means that the selected records are
512 // either default or All language and here we will not select translations
513 // which point to the main record:
514 if ($this->localizationView && $l10nEnabled) {
515 // For each available translation, render the record:
516 if (is_array($this->translations)) {
517 foreach ($this->translations as $lRow) {
518 // $lRow isn't always what we want - if record was moved we've to work with the
519 // placeholder records otherwise the list is messed up a bit
520 if ($row['_MOVE_PLH_uid'] && $row['_MOVE_PLH_pid']) {
521 $tmpRow = BackendUtility::getRecordRaw($table, 't3ver_move_id="' . (int)$lRow['uid'] . '" AND pid="' . $row['_MOVE_PLH_pid'] . '" AND t3ver_wsid=' . $row['t3ver_wsid'] . BackendUtility::deleteClause($table), $selFieldList);
522 $lRow = is_array($tmpRow) ? $tmpRow : $lRow;
523 }
524 // In offline workspace, look for alternative record:
525 BackendUtility::workspaceOL($table, $lRow, $GLOBALS['BE_USER']->workspace, TRUE);
526 if (is_array($lRow) && $GLOBALS['BE_USER']->checkLanguageAccess($lRow[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
527 $currentIdList[] = $lRow['uid'];
528 $iOut .= $this->renderListRow($table, $lRow, $cc, $titleCol, $thumbsCol, 18);
529 }
530 }
531 }
532 }
533 }
534 // Counter of total rows incremented:
535 $this->eCounter++;
536 }
537 // Record navigation is added to the beginning and end of the table if in single table mode
538 if ($this->table) {
539 $iOut = $this->renderListNavigation('top') . $iOut . $this->renderListNavigation('bottom');
540 } else {
541 // Show that there are more records than shown
542 if ($this->totalItems > $this->itemsLimitPerTable) {
543 $countOnFirstPage = $this->totalItems > $this->itemsLimitSingleTable ? $this->itemsLimitSingleTable : $this->totalItems;
544 $hasMore = $this->totalItems > $this->itemsLimitSingleTable;
545 $colspan = $this->showIcon ? count($this->fieldArray) + 1 : count($this->fieldArray);
546 $iOut .= '<tr><td colspan="' . $colspan . '" style="padding:5px;">
547 <a href="' . htmlspecialchars(($this->listURL() . '&table=' . rawurlencode($table))) . '">' . '<img' . IconUtility::skinImg($this->backPath, 'gfx/pildown.gif', 'width="14" height="14"') . ' alt="" />' . ' <i>[1 - ' . $countOnFirstPage . ($hasMore ? '+' : '') . ']</i></a>
548 </td></tr>';
549 }
550 }
551 // The header row for the table is now created:
552 $out .= $this->renderListHeader($table, $currentIdList);
553 }
554 // The list of records is added after the header:
555 $out .= $iOut;
556 unset($iOut);
557 // ... and it is all wrapped in a table:
558 $out = '
559
560
561
562 <!--
563 DB listing of elements: "' . htmlspecialchars($table) . '"
564 -->
565 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist' . ($listOnlyInSingleTableMode ? ' typo3-dblist-overview' : '') . '">
566 ' . $out . '
567 </table>';
568 // Output csv if...
569 // This ends the page with exit.
570 if ($this->csvOutput) {
571 $this->outputCSV($table);
572 }
573 }
574 // Return content:
575 return $out;
576 }
577
578 /**
579 * Check if all row listing conditions are fulfilled.
580 *
581 * This function serves as a dummy method to be overriden in extending classes.
582 *
583 * @param string $table Table name
584 * @param array $row Record
585 * @return boolean True, if all conditions are fulfilled.
586 */
587 protected function isRowListingConditionFulfilled($table, $row) {
588 return TRUE;
589 }
590
591 /**
592 * Rendering a single row for the list
593 *
594 * @param string $table Table name
595 * @param array $row Current record
596 * @param integer $cc Counter, counting for each time an element is rendered (used for alternating colors)
597 * @param string $titleCol Table field (column) where header value is found
598 * @param string $thumbsCol Table field (column) where (possible) thumbnails can be found
599 * @param integer $indent Indent from left.
600 * @return string Table row for the element
601 * @access private
602 * @see getTable()
603 * @todo Define visibility
604 */
605 public function renderListRow($table, $row, $cc, $titleCol, $thumbsCol, $indent = 0) {
606 $iOut = '';
607 // If in search mode, make sure the preview will show the correct page
608 if (strlen($this->searchString)) {
609 $id_orig = $this->id;
610 $this->id = $row['pid'];
611 }
612 if (is_array($row)) {
613 // Add special classes for first and last row
614 $rowSpecial = '';
615 if ($cc == 1 && $indent == 0) {
616 $rowSpecial .= ' firstcol';
617 }
618 if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
619 $rowSpecial .= ' lastcol';
620 }
621 // Background color, if any:
622 if ($this->alternateBgColors) {
623 $row_bgColor = $cc % 2 ? ' class="db_list_normal' . $rowSpecial . '"' : ' class="db_list_alt' . $rowSpecial . '"';
624 } else {
625 $row_bgColor = ' class="db_list_normal' . $rowSpecial . '"';
626 }
627 // Overriding with versions background color if any:
628 $row_bgColor = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : $row_bgColor;
629 // Incr. counter.
630 $this->counter++;
631 // The icon with link
632 $alttext = BackendUtility::getRecordIconAltText($row, $table);
633 $iconImg = IconUtility::getSpriteIconForRecord($table, $row, array('title' => htmlspecialchars($alttext), 'style' => $indent ? ' margin-left: ' . $indent . 'px;' : ''));
634 $theIcon = $this->clickMenuEnabled ? $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, $table, $row['uid']) : $iconImg;
635 // Preparing and getting the data-array
636 $theData = array();
637 foreach ($this->fieldArray as $fCol) {
638 if ($fCol == $titleCol) {
639 $recTitle = BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);
640 // If the record is edit-locked by another user, we will show a little warning sign:
641 if ($lockInfo = BackendUtility::isRecordLocked($table, $row['uid'])) {
642 $warning = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg']) . '); return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">' . IconUtility::getSpriteIcon('status-warning-in-use') . '</a>';
643 }
644 $theData[$fCol] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
645 // Render thumbnails, if:
646 // - a thumbnail column exists
647 // - there is content in it
648 // - the thumbnail column is visible for the current type
649 $typeColumn = $GLOBALS['TCA'][$table]['ctrl']['type'];
650 $type = $row[$typeColumn];
651 $visibleColumns = $GLOBALS['TCA'][$table]['types'][$type]['showitem'];
652
653 if ($this->thumbs &&
654 trim($row[$thumbsCol]) &&
655 preg_match('/(^|(.*(;|,)?))' . $thumbsCol . '(((;|,).*)|$)/', $visibleColumns) === 1
656 ) {
657 $theData[$fCol] .= '<br />' . $this->thumbCode($row, $table, $thumbsCol);
658 }
659 $localizationMarkerClass = '';
660 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField']) && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0 && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0) {
661 // It's a translated record with a language parent
662 $localizationMarkerClass = ' localization';
663 }
664 } elseif ($fCol == 'pid') {
665 $theData[$fCol] = $row[$fCol];
666 } elseif ($fCol == '_PATH_') {
667 $theData[$fCol] = $this->recPath($row['pid']);
668 } elseif ($fCol == '_REF_') {
669 $theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
670 } elseif ($fCol == '_CONTROL_') {
671 $theData[$fCol] = $this->makeControl($table, $row);
672 } elseif ($fCol == '_AFTERCONTROL_' || $fCol == '_AFTERREF_') {
673 $theData[$fCol] = '&nbsp;';
674 } elseif ($fCol == '_CLIPBOARD_') {
675 $theData[$fCol] = $this->makeClip($table, $row);
676 } elseif ($fCol == '_LOCALIZATION_') {
677 list($lC1, $lC2) = $this->makeLocalizationPanel($table, $row);
678 $theData[$fCol] = $lC1;
679 $theData[$fCol . 'b'] = $lC2;
680 } elseif ($fCol == '_LOCALIZATION_b') {
681
682 } else {
683 $tmpProc = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid']);
684 $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
685 if ($this->csvOutput) {
686 $row[$fCol] = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
687 }
688 }
689 }
690 // Reset the ID if it was overwritten
691 if (strlen($this->searchString)) {
692 $this->id = $id_orig;
693 }
694 // Add row to CSV list:
695 if ($this->csvOutput) {
696 $this->addToCSV($row, $table);
697 }
698 // Add classes to table cells
699 $this->addElement_tdCssClass[$titleCol] = 'col-title' . $localizationMarkerClass;
700 if (!$this->dontShowClipControlPanels) {
701 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
702 $this->addElement_tdCssClass['_AFTERCONTROL_'] = 'col-control-space';
703 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
704 }
705 $this->addElement_tdCssClass['_PATH_'] = 'col-path';
706 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
707 $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
708 // Create element in table cells:
709 $iOut .= $this->addelement(1, $theIcon, $theData, $row_bgColor);
710 // Finally, return table row element:
711 return $iOut;
712 }
713 }
714
715 /**
716 * Gets the number of records referencing the record with the UID $uid in
717 * the table $tableName.
718 *
719 * @param string $tableName
720 * @param integer $uid
721 * @return integer The number of references to record $uid in table
722 */
723 protected function getReferenceCount($tableName, $uid) {
724 if (!isset($this->referenceCount[$tableName][$uid])) {
725 $numberOfReferences = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex', 'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tableName, 'sys_refindex') . ' AND ref_uid = ' . $uid . ' AND deleted = 0');
726 $this->referenceCount[$tableName][$uid] = $numberOfReferences;
727 }
728 return $this->referenceCount[$tableName][$uid];
729 }
730
731 /**
732 * Rendering the header row for a table
733 *
734 * @param string $table Table name
735 * @param array $currentIdList Array of the currently displayed uids of the table
736 * @return string Header table row
737 * @access private
738 * @see getTable()
739 * @todo Define visibility
740 */
741 public function renderListHeader($table, $currentIdList) {
742 // Init:
743 $theData = array();
744 // Traverse the fields:
745 foreach ($this->fieldArray as $fCol) {
746 // Calculate users permissions to edit records in the table:
747 $permsEdit = $this->calcPerms & ($table == 'pages' ? 2 : 16);
748 switch ((string) $fCol) {
749 case '_PATH_':
750 // Path
751 $theData[$fCol] = '<i>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels._PATH_', TRUE) . ']</i>';
752 break;
753 case '_REF_':
754 // References
755 $theData[$fCol] = '<i>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:c__REF_', TRUE) . ']</i>';
756 break;
757 case '_LOCALIZATION_':
758 // Path
759 $theData[$fCol] = '<i>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels._LOCALIZATION_', TRUE) . ']</i>';
760 break;
761 case '_LOCALIZATION_b':
762 // Path
763 $theData[$fCol] = $GLOBALS['LANG']->getLL('Localize', TRUE);
764 break;
765 case '_CLIPBOARD_':
766 // Clipboard:
767 $cells = array();
768 // If there are elements on the clipboard for this table, then display the "paste into" icon:
769 $elFromTable = $this->clipObj->elFromTable($table);
770 if (count($elFromTable)) {
771 $cells['pasteAfter'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl($table, $this->id)) . '" onclick="' . htmlspecialchars(('return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into', $elFromTable))) . '" title="' . $GLOBALS['LANG']->getLL('clip_paste', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
772 }
773 // If the numeric clipboard pads are enabled, display the control icons for that:
774 if ($this->clipObj->current != 'normal') {
775 // The "select" link:
776 $cells['copyMarked'] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-copy', array('title' => $GLOBALS['LANG']->getLL('clip_selectMarked', TRUE))), $table, 'setCB');
777 // The "edit marked" link:
778 $editIdList = implode(',', $currentIdList);
779 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
780 $params = '&edit[' . $table . '][' . $editIdList . ']=edit&disHelp=1';
781 $cells['edit'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('clip_editMarked', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
782 // The "Delete marked" link:
783 $cells['delete'] = $this->linkClipboardHeaderIcon(IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['LANG']->getLL('clip_deleteMarked', TRUE))), $table, 'delete', sprintf($GLOBALS['LANG']->getLL('clip_deleteMarkedWarning'), $GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title'])));
784 // The "Select all" link:
785 $cells['markAll'] = '<a class="cbcCheckAll" rel="" href="#" onclick="' . htmlspecialchars(('checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;')) . '" title="' . $GLOBALS['LANG']->getLL('clip_markRecords', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-select') . '</a>';
786 } else {
787 $cells['empty'] = '';
788 }
789 /**
790 * @hook renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
791 * @date 2007-11-20
792 * @request Bernhard Kraft <krafbt@kraftb.at>
793 * @usage Above each listed table in Web>List a header row is shown. This hook allows to modify the icons responsible for the clipboard functions (shown above the clipboard checkboxes when a clipboard other than "Normal" is selected), or other "Action" functions which perform operations on the listed records.
794 */
795 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
796 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
797 $hookObject = GeneralUtility::getUserObj($classData);
798 if (!$hookObject instanceof \TYPO3\CMS\Recordlist\RecordList\RecordListHookInterface) {
799 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Recordlist\\RecordList\\RecordListHookInterface', 1195567850);
800 }
801 $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
802 }
803 }
804 $theData[$fCol] = implode('', $cells);
805 break;
806 case '_CONTROL_':
807 // Control panel:
808 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
809 // If new records can be created on this page, add links:
810 if ($this->calcPerms & ($table == 'pages' ? 8 : 16) && $this->showNewRecLink($table)) {
811 if ($table == 'tt_content' && $this->newWizards) {
812 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
813 $tmpTSc = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
814 $tmpTSc = $tmpTSc['properties']['newContentWiz.']['overrideWithExtension'];
815 $newContentWizScriptPath = $this->backPath . ExtensionManagementUtility::isLoaded($tmpTSc) ? ExtensionManagementUtility::extRelPath($tmpTSc) . 'mod1/db_new_content_el.php' : 'sysext/cms/layout/db_new_content_el.php';
816 $icon = '<a href="#" onclick="' . htmlspecialchars(('return jumpExt(\'' . $newContentWizScriptPath . '?id=' . $this->id . '\');')) . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">' . ($table == 'pages' ? IconUtility::getSpriteIcon('actions-page-new') : IconUtility::getSpriteIcon('actions-document-new')) . '</a>';
817 } elseif ($table == 'pages' && $this->newWizards) {
818 $icon = '<a href="' . htmlspecialchars(($this->backPath . 'db_new.php?id=' . $this->id . '&pagesOnly=1&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')))) . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">' . ($table == 'pages' ? IconUtility::getSpriteIcon('actions-page-new') : IconUtility::getSpriteIcon('actions-document-new')) . '</a>';
819 } else {
820 $params = '&edit[' . $table . '][' . $this->id . ']=new';
821 if ($table == 'pages_language_overlay') {
822 $params .= '&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageRow['doktype'];
823 }
824 $icon = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('new', TRUE) . '">' . ($table == 'pages' ? IconUtility::getSpriteIcon('actions-page-new') : IconUtility::getSpriteIcon('actions-document-new')) . '</a>';
825 }
826 }
827 // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
828 if ($permsEdit && $this->table && is_array($currentIdList)) {
829 $editIdList = implode(',', $currentIdList);
830 if ($this->clipNumPane()) {
831 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
832 }
833 $params = '&edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . implode(',', $this->fieldArray) . '&disHelp=1';
834 $icon .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('editShownColumns', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
835 }
836 // Add an empty entry, so column count fits again after moving this into $icon
837 $theData[$fCol] = '&nbsp;';
838 }
839 break;
840 case '_AFTERCONTROL_':
841
842 case '_AFTERREF_':
843 // space column
844 $theData[$fCol] = '&nbsp;';
845 break;
846 default:
847 // Regular fields header:
848 $theData[$fCol] = '';
849
850 // Check if $fCol is really a field and get the label and remove the colons at the end
851 $sortLabel = BackendUtility::getItemLabel($table, $fCol);
852 if ($sortLabel !== NULL) {
853 $sortLabel = $GLOBALS['LANG']->sL($sortLabel, TRUE);
854 $sortLabel = rtrim(trim($sortLabel), ':');
855 } else {
856 // No TCA field, only output the $fCol variable with square brackets []
857 $sortLabel = htmlspecialchars($fCol);
858 $sortLabel = '<i>[' . rtrim(trim($sortLabel), ':') . ']</i>';
859 }
860
861 if ($this->table && is_array($currentIdList)) {
862 // If the numeric clipboard pads are selected, show duplicate sorting link:
863 if ($this->clipNumPane()) {
864 $theData[$fCol] .= '<a href="' . htmlspecialchars(($this->listURL('', -1) . '&duplicateField=' . $fCol)) . '" title="' . $GLOBALS['LANG']->getLL('clip_duplicates', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-duplicates-select') . '</a>';
865 }
866 // If the table can be edited, add link for editing THIS field for all listed records:
867 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly'] && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
868 $editIdList = implode(',', $currentIdList);
869 if ($this->clipNumPane()) {
870 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
871 }
872 $params = '&edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . $fCol . '&disHelp=1';
873 $iTitle = sprintf($GLOBALS['LANG']->getLL('editThisColumn'), $sortLabel);
874 $theData[$fCol] .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . htmlspecialchars($iTitle) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
875 }
876 }
877 $theData[$fCol] .= $this->addSortLink($sortLabel, $fCol, $table);
878 }
879 }
880 /**
881 * @hook renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
882 * @date 2007-11-20
883 * @request Bernhard Kraft <krafbt@kraftb.at>
884 * @usage Above each listed table in Web>List a header row is shown. Containing the labels of all shown fields and additional icons to create new records for this table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
885 */
886 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
887 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
888 $hookObject = GeneralUtility::getUserObj($classData);
889 if (!$hookObject instanceof \TYPO3\CMS\Recordlist\RecordList\RecordListHookInterface) {
890 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Recordlist\\RecordList\\RecordListHookInterface', 1195567855);
891 }
892 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
893 }
894 }
895 // Create and return header table row:
896 return $this->addelement(1, $icon, $theData, ' class="c-headLine"', '');
897 }
898
899 /**
900 * Creates a page browser for tables with many records
901 *
902 * @param string $renderPart Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
903 * @return string Navigation HTML
904 */
905 protected function renderListNavigation($renderPart = 'top') {
906 $totalPages = ceil($this->totalItems / $this->iLimit);
907 $content = '';
908 $returnContent = '';
909 // Show page selector if not all records fit into one page
910 if ($totalPages > 1) {
911 $first = ($previous = ($next = ($last = ($reload = ''))));
912 $listURL = $this->listURL('', $this->table);
913 // 1 = first page
914 $currentPage = floor(($this->firstElementNumber + 1) / $this->iLimit) + 1;
915 // Compile first, previous, next, last and refresh buttons
916 if ($currentPage > 1) {
917 $labelFirst = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:first');
918 $first = '<a href="' . $listURL . '&pointer=0">' . IconUtility::getSpriteIcon('actions-view-paging-first', array('title' => $labelFirst)) . '</a>';
919 } else {
920 $first = IconUtility::getSpriteIcon('actions-view-paging-first-disabled');
921 }
922 if ($currentPage - 1 > 0) {
923 $labelPrevious = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:previous');
924 $previous = '<a href="' . $listURL . '&pointer=' . ($currentPage - 2) * $this->iLimit . '">' . IconUtility::getSpriteIcon('actions-view-paging-previous', array('title' => $labelPrevious)) . '</a>';
925 } else {
926 $previous = IconUtility::getSpriteIcon('actions-view-paging-previous-disabled');
927 }
928 if ($currentPage + 1 <= $totalPages) {
929 $labelNext = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:next');
930 $next = '<a href="' . $listURL . '&pointer=' . $currentPage * $this->iLimit . '">' . IconUtility::getSpriteIcon('actions-view-paging-next', array('title' => $labelNext)) . '</a>';
931 } else {
932 $next = IconUtility::getSpriteIcon('actions-view-paging-next-disabled');
933 }
934 if ($currentPage != $totalPages) {
935 $labelLast = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:last');
936 $last = '<a href="' . $listURL . '&pointer=' . ($totalPages - 1) * $this->iLimit . '">' . IconUtility::getSpriteIcon('actions-view-paging-last', array('title' => $labelLast)) . '</a>';
937 } else {
938 $last = IconUtility::getSpriteIcon('actions-view-paging-last-disabled');
939 }
940 $reload = '<a href="#" onclick="document.dblistForm.action=\'' . $listURL . '&pointer=\'+calculatePointer(document.getElementById(\'jumpPage-' . $renderPart . '\').value); document.dblistForm.submit(); return true;" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:reload', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
941 if ($renderPart === 'top') {
942 // Add js to traverse a page select input to a pointer value
943 $content = '
944 <script type="text/JavaScript">
945 /*<![CDATA[*/
946
947 function calculatePointer(page) {
948 if (page > ' . $totalPages . ') {
949 page = ' . $totalPages . ';
950 }
951
952 if (page < 1) {
953 page = 1;
954 }
955
956 pointer = (page - 1) * ' . $this->iLimit . ';
957
958 return pointer;
959 }
960
961 /*]]>*/
962 </script>
963 ';
964 }
965 $pageNumberInput = '<span>
966 <input type="text" value="' . $currentPage . '" size="3" id="jumpPage-' . $renderPart . '" name="jumpPage-' . $renderPart . '" onkeyup="if (event.keyCode == Event.KEY_RETURN) { document.dblistForm.action=\'' . $listURL . '&pointer=\'+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
967 </span>';
968 $pageIndicator = '<span class="pageIndicator">' . sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:pageIndicator'), $pageNumberInput, $totalPages) . '</span>';
969 if ($this->totalItems > $this->firstElementNumber + $this->iLimit) {
970 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
971 } else {
972 $lastElementNumber = $this->totalItems;
973 }
974 $rangeIndicator = '<span class="pageIndicator">' . sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:rangeIndicator'), ($this->firstElementNumber + 1), $lastElementNumber) . '</span>';
975 $content .= '<div id="typo3-dblist-pagination">' . $first . $previous . '<span class="bar">&nbsp;</span>' . $rangeIndicator . '<span class="bar">&nbsp;</span>' . $pageIndicator . '<span class="bar">&nbsp;</span>' . $next . $last . '<span class="bar">&nbsp;</span>' . $reload . '</div>';
976 $data = array();
977 $titleColumn = $this->fieldArray[0];
978 $data[$titleColumn] = $content;
979 $returnContent = $this->addElement(1, '', $data);
980 }
981 // end of if pages > 1
982 return $returnContent;
983 }
984
985 /*********************************
986 *
987 * Rendering of various elements
988 *
989 *********************************/
990 /**
991 * Creates the control panel for a single record in the listing.
992 *
993 * @param string $table The table
994 * @param array $row The record for which to make the control panel.
995 * @return string HTML table with the control panel (unless disabled)
996 * @todo Define visibility
997 */
998 public function makeControl($table, $row) {
999 if ($this->dontShowClipControlPanels) {
1000 return '';
1001 }
1002 $rowUid = $row['uid'];
1003 if (ExtensionManagementUtility::isLoaded('version') && isset($row['_ORIG_uid'])) {
1004 $rowUid = $row['_ORIG_uid'];
1005 }
1006 $cells = array();
1007 // If the listed table is 'pages' we have to request the permission settings for each page:
1008 if ($table == 'pages') {
1009 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1010 }
1011 // This expresses the edit permissions for this particular element:
1012 $permsEdit = $table == 'pages' && $localCalcPerms & 2 || $table != 'pages' && $this->calcPerms & 16;
1013 // "Show" link (only pages and tt_content elements)
1014 if ($table == 'pages' || $table == 'tt_content') {
1015 $cells['view'] = '<a href="#" onclick="'
1016 . htmlspecialchars(
1017 BackendUtility::viewOnClick(
1018 ($table === 'tt_content' ? $this->id : $row['uid']),
1019 $this->backPath,
1020 '',
1021 ($table === 'tt_content' ? '#' . $row['uid'] : '')
1022 )
1023 ) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
1024 . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
1025 } elseif (!$this->table) {
1026 $cells['view'] = $this->spaceIcon;
1027 }
1028 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1029 if ($permsEdit) {
1030 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1031 $cells['edit'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL('edit', TRUE) . '">' . ($GLOBALS['TCA'][$table]['ctrl']['readOnly'] ? IconUtility::getSpriteIcon('actions-document-open-read-only') : IconUtility::getSpriteIcon('actions-document-open')) . '</a>';
1032 } elseif (!$this->table) {
1033 $cells['edit'] = $this->spaceIcon;
1034 }
1035 // "Move" wizard link for pages/tt_content elements:
1036 if ($table == 'tt_content' && $permsEdit || $table == 'pages') {
1037 $cells['move'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpExt(\'' . $this->backPath . 'move_el.php?table=' . $table . '&uid=' . $row['uid'] . '\');')) . '" title="' . $GLOBALS['LANG']->getLL(('move_' . ($table == 'tt_content' ? 'record' : 'page')), TRUE) . '">' . ($table == 'tt_content' ? IconUtility::getSpriteIcon('actions-document-move') : IconUtility::getSpriteIcon('actions-page-move')) . '</a>';
1038 } elseif (!$this->table) {
1039 $cells['move'] = $this->spaceIcon;
1040 }
1041 // If the extended control panel is enabled OR if we are seeing a single table:
1042 if ($GLOBALS['SOBE']->MOD_SETTINGS['bigControlPanel'] || $this->table) {
1043 // "Info": (All records)
1044 $cells['viewBig'] = '<a href="#" onclick="' . htmlspecialchars(('top.launchView(\'' . $table . '\', \'' . $row['uid'] . '\'); return false;')) . '" title="' . $GLOBALS['LANG']->getLL('showInfo', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-info') . '</a>';
1045 // If the table is NOT a read-only table, then show these links:
1046 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
1047 // "Revert" link (history/undo)
1048 $cells['history'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpExt(\'' . $this->backPath . 'show_rechis.php?element=' . rawurlencode(($table . ':' . $row['uid'])) . '\',\'#latest\');')) . '" title="' . $GLOBALS['LANG']->getLL('history', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1049 // Versioning:
1050 if (ExtensionManagementUtility::isLoaded('version') && !ExtensionManagementUtility::isLoaded('workspaces')) {
1051 $vers = BackendUtility::selectVersionsOfRecord($table, $row['uid'], 'uid', $GLOBALS['BE_USER']->workspace, FALSE, $row);
1052 // If table can be versionized.
1053 if (is_array($vers)) {
1054 $versionIcon = 'no-version';
1055 if (count($vers) > 1) {
1056 $versionIcon = count($vers) - 1;
1057 }
1058 $cells['version'] = '<a href="' . htmlspecialchars(($this->backPath . ExtensionManagementUtility::extRelPath('version') . 'cm1/index.php?table=' . rawurlencode($table) . '&uid=' . rawurlencode($row['uid']))) . '" title="' . $GLOBALS['LANG']->getLL('displayVersions', TRUE) . '">' . IconUtility::getSpriteIcon(('status-version-' . $versionIcon)) . '</a>';
1059 } elseif (!$this->table) {
1060 $cells['version'] = $this->spaceIcon;
1061 }
1062 }
1063 // "Edit Perms" link:
1064 if ($table == 'pages' && $GLOBALS['BE_USER']->check('modules', 'web_perm') && ExtensionManagementUtility::isLoaded('perm')) {
1065 $cells['perms'] = '<a href="' . htmlspecialchars((BackendUtility::getModuleUrl('web_perm') . '&id=' . $row['uid'] . '&return_id=' . $row['uid'] . '&edit=1')) . '" title="' . $GLOBALS['LANG']->getLL('permissions', TRUE) . '">' . IconUtility::getSpriteIcon('status-status-locked') . '</a>';
1066 } elseif (!$this->table && $GLOBALS['BE_USER']->check('modules', 'web_perm')) {
1067 $cells['perms'] = $this->spaceIcon;
1068 }
1069 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row or if default values can depend on previous record):
1070 if ($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) {
1071 if ($table != 'pages' && $this->calcPerms & 16 || $table == 'pages' && $this->calcPerms & 8) {
1072 if ($this->showNewRecLink($table)) {
1073 $params = '&edit[' . $table . '][' . -($row['_MOVE_PLH'] ? $row['_MOVE_PLH_uid'] : $row['uid']) . ']=new';
1074 $cells['new'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, $this->backPath, -1)) . '" title="' . $GLOBALS['LANG']->getLL(('new' . ($table == 'pages ' ? 'Page' : 'Record')), TRUE) . '">' . ($table == 'pages' ? IconUtility::getSpriteIcon('actions-page-new') : IconUtility::getSpriteIcon('actions-document-new')) . '</a>';
1075 }
1076 }
1077 } elseif (!$this->table) {
1078 $cells['new'] = $this->spaceIcon;
1079 }
1080 // "Up/Down" links
1081 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField && !$this->searchLevels) {
1082 if (isset($this->currentTable['prev'][$row['uid']])) {
1083 // Up
1084 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
1085 $cells['moveUp'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');')) . '" title="' . $GLOBALS['LANG']->getLL('moveUp', TRUE) . '">' . IconUtility::getSpriteIcon('actions-move-up') . '</a>';
1086 } else {
1087 $cells['moveUp'] = $this->spaceIcon;
1088 }
1089 if ($this->currentTable['next'][$row['uid']]) {
1090 // Down
1091 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
1092 $cells['moveDown'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');')) . '" title="' . $GLOBALS['LANG']->getLL('moveDown', TRUE) . '">' . IconUtility::getSpriteIcon('actions-move-down') . '</a>';
1093 } else {
1094 $cells['moveDown'] = $this->spaceIcon;
1095 }
1096 } elseif (!$this->table) {
1097 $cells['moveUp'] = $this->spaceIcon;
1098 $cells['moveDown'] = $this->spaceIcon;
1099 }
1100 // "Hide/Unhide" links:
1101 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1102 if ($permsEdit && $hiddenField && $GLOBALS['TCA'][$table]['columns'][$hiddenField] && (!$GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields', $table . ':' . $hiddenField))) {
1103 if ($row[$hiddenField]) {
1104 $params = '&data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
1105 $cells['hide'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');')) . '" title="' . $GLOBALS['LANG']->getLL(('unHide' . ($table == 'pages' ? 'Page' : '')), TRUE) . '">' . IconUtility::getSpriteIcon('actions-edit-unhide') . '</a>';
1106 } else {
1107 $params = '&data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
1108 $cells['hide'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');')) . '" title="' . $GLOBALS['LANG']->getLL(('hide' . ($table == 'pages' ? 'Page' : '')), TRUE) . '">' . IconUtility::getSpriteIcon('actions-edit-hide') . '</a>';
1109 }
1110 } elseif (!$this->table) {
1111 $cells['hide'] = $this->spaceIcon;
1112 }
1113 // "Delete" link:
1114 if ($table == 'pages' && $localCalcPerms & 4 || $table != 'pages' && $this->calcPerms & 16) {
1115 // Check if the record version is in "deleted" state, because that will switch the action to "restore"
1116 if ($GLOBALS['BE_USER']->workspace > 0 && isset($row['t3ver_state']) && (int)$row['t3ver_state'] === 2) {
1117 $actionName = 'restore';
1118 $refCountMsg = '';
1119 } else {
1120 $actionName = 'delete';
1121 $refCountMsg = BackendUtility::referenceCount(
1122 $table,
1123 $row['uid'],
1124 ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToRecord'),
1125 $this->getReferenceCount($table, $row['uid'])) . BackendUtility::translationCount($table, $row['uid'],
1126 ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')
1127 );
1128 }
1129
1130 $titleOrig = BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);
1131 $title = GeneralUtility::slashJS(GeneralUtility::fixed_lgd_cs($titleOrig, $this->fixedL), 1);
1132 $warningText = GeneralUtility::quoteJSvalue(
1133 $GLOBALS['LANG']->getLL($actionName . 'Warning') . ' "' . $title . '" ' . $refCountMsg
1134 );
1135
1136 $params = '&cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
1137 $onClick = htmlspecialchars(
1138 ('if (confirm(' . $warningText . ')) {jumpToUrl(\''
1139 . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');} return false;')
1140 );
1141
1142 $icon = IconUtility::getSpriteIcon('actions-edit-' . $actionName);
1143 $linkTitle = $GLOBALS['LANG']->getLL($actionName, TRUE);
1144 $cells['delete'] = '<a href="#" onclick="' . $onClick . '" title="' . $linkTitle . '">' . $icon . '</a>';
1145 } elseif (!$this->table) {
1146 $cells['delete'] = $this->spaceIcon;
1147 }
1148 // "Levels" links: Moving pages into new levels...
1149 if ($permsEdit && $table == 'pages' && !$this->searchLevels) {
1150 // Up (Paste as the page right after the current parent page)
1151 if ($this->calcPerms & 8) {
1152 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
1153 $cells['moveLeft'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');')) . '" title="' . $GLOBALS['LANG']->getLL('prevLevel', TRUE) . '">' . IconUtility::getSpriteIcon('actions-move-left') . '</a>';
1154 }
1155 // Down (Paste as subpage to the page right above)
1156 if ($this->currentTable['prevUid'][$row['uid']]) {
1157 $localCalcPerms = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
1158 if ($localCalcPerms & 8) {
1159 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
1160 $cells['moveRight'] = '<a href="#" onclick="' . htmlspecialchars(('return jumpToUrl(\'' . $GLOBALS['SOBE']->doc->issueCommand($params, -1) . '\');')) . '" title="' . $GLOBALS['LANG']->getLL('nextLevel', TRUE) . '">' . IconUtility::getSpriteIcon('actions-move-right') . '</a>';
1161 } else {
1162 $cells['moveRight'] = $this->spaceIcon;
1163 }
1164 } else {
1165 $cells['moveRight'] = $this->spaceIcon;
1166 }
1167 } elseif (!$this->table) {
1168 $cells['moveLeft'] = $this->spaceIcon;
1169 $cells['moveRight'] = $this->spaceIcon;
1170 }
1171 }
1172 }
1173 /**
1174 * @hook recStatInfoHooks: Allows to insert HTML before record icons on various places
1175 * @date 2007-09-22
1176 * @request Kasper Skårhøj <kasper2007@typo3.com>
1177 */
1178 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1179 $stat = '';
1180 $_params = array($table, $row['uid']);
1181 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1182 $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1183 }
1184 $cells['stat'] = $stat;
1185 }
1186 /**
1187 * @hook makeControl: Allows to change control icons of records in list-module
1188 * @date 2007-11-20
1189 * @request Bernhard Kraft <krafbt@kraftb.at>
1190 * @usage This hook method gets passed the current $cells array as third parameter. This array contains values for the icons/actions generated for each record in Web>List. Each array entry is accessible by an index-key. The order of the icons is dependend on the order of those array entries.
1191 */
1192 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1193 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1194 $hookObject = GeneralUtility::getUserObj($classData);
1195 if (!$hookObject instanceof \TYPO3\CMS\Recordlist\RecordList\RecordListHookInterface) {
1196 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Recordlist\\RecordList\\RecordListHookInterface', 1195567840);
1197 }
1198 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1199 }
1200 }
1201 // Compile items into a DIV-element:
1202 return '
1203 <!-- CONTROL PANEL: ' . $table . ':' . $row['uid'] . ' -->
1204 <div class="typo3-DBctrl">' . implode('', $cells) . '</div>';
1205 }
1206
1207 /**
1208 * Creates the clipboard panel for a single record in the listing.
1209 *
1210 * @param string $table The table
1211 * @param array $row The record for which to make the clipboard panel.
1212 * @return string HTML table with the clipboard panel (unless disabled)
1213 * @todo Define visibility
1214 */
1215 public function makeClip($table, $row) {
1216 // Return blank, if disabled:
1217 if ($this->dontShowClipControlPanels) {
1218 return '';
1219 }
1220 $cells = array();
1221 $cells['pasteAfter'] = ($cells['pasteInto'] = $this->spaceIcon);
1222 //enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
1223 $isL10nOverlay = $this->localizationView && $table != 'pages_language_overlay' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1224 // Return blank, if disabled:
1225 // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1226 // For the "Normal" pad:
1227 if ($this->clipObj->current == 'normal') {
1228 // Show copy/cut icons:
1229 $isSel = (string) $this->clipObj->isSelected($table, $row['uid']);
1230 $cells['copy'] = $isL10nOverlay ? $this->spaceIcon : '<a href="#" onclick="' . htmlspecialchars(('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel == 'copy'), array('returnUrl' => '')) . '\');')) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', TRUE) . '">' . (!$isSel == 'copy' ? IconUtility::getSpriteIcon('actions-edit-copy') : IconUtility::getSpriteIcon('actions-edit-copy-release')) . '</a>';
1231 $cells['cut'] = $isL10nOverlay ? $this->spaceIcon : '<a href="#" onclick="' . htmlspecialchars(('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel == 'cut'), array('returnUrl' => '')) . '\');')) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', TRUE) . '">' . (!$isSel == 'cut' ? IconUtility::getSpriteIcon('actions-edit-cut') : IconUtility::getSpriteIcon('actions-edit-cut-release')) . '</a>';
1232 } else {
1233 // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1234 // Setting name of the element in ->CBnames array:
1235 $n = $table . '|' . $row['uid'];
1236 $this->CBnames[] = $n;
1237 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1238 $checked = $this->clipObj->isSelected($table, $row['uid']) ? ' checked="checked"' : '';
1239 // If the "duplicateField" value is set then select all elements which are duplicates...
1240 if ($this->duplicateField && isset($row[$this->duplicateField])) {
1241 $checked = '';
1242 if (in_array($row[$this->duplicateField], $this->duplicateStack)) {
1243 $checked = ' checked="checked"';
1244 }
1245 $this->duplicateStack[] = $row[$this->duplicateField];
1246 }
1247 // Adding the checkbox to the panel:
1248 $cells['select'] = $isL10nOverlay ? $this->spaceIcon : '<input type="hidden" name="CBH[' . $n . ']" value="0" /><input type="checkbox" name="CBC[' . $n . ']" value="1" class="smallCheckboxes"' . $checked . ' />';
1249 }
1250 // Now, looking for selected elements from the current table:
1251 $elFromTable = $this->clipObj->elFromTable($table);
1252 if (count($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1253 // IF elements are found and they can be individually ordered, then add a "paste after" icon:
1254 $cells['pasteAfter'] = $isL10nOverlay ? $this->spaceIcon : '<a href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '" onclick="' . htmlspecialchars(('return ' . $this->clipObj->confirmMsg($table, $row, 'after', $elFromTable))) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteAfter', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
1255 }
1256 // Now, looking for elements in general:
1257 $elFromTable = $this->clipObj->elFromTable('');
1258 if ($table == 'pages' && count($elFromTable)) {
1259 $cells['pasteInto'] = '<a href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid'])) . '" onclick="' . htmlspecialchars(('return ' . $this->clipObj->confirmMsg($table, $row, 'into', $elFromTable))) . '" title="' . $GLOBALS['LANG']->getLL('clip_pasteInto', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-paste-into') . '</a>';
1260 }
1261 /**
1262 * @hook makeClip: Allows to change clip-icons of records in list-module
1263 * @date 2007-11-20
1264 * @request Bernhard Kraft <krafbt@kraftb.at>
1265 * @usage This hook method gets passed the current $cells array as third parameter. This array contains values for the clipboard icons generated for each record in Web>List. Each array entry is accessible by an index-key. The order of the icons is dependend on the order of those array entries.
1266 */
1267 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1268 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1269 $hookObject = GeneralUtility::getUserObj($classData);
1270 if (!$hookObject instanceof \TYPO3\CMS\Recordlist\RecordList\RecordListHookInterface) {
1271 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Recordlist\\RecordList\\RecordListHookInterface', 1195567845);
1272 }
1273 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1274 }
1275 }
1276 // Compile items into a DIV-element:
1277 return ' <!-- CLIPBOARD PANEL: ' . $table . ':' . $row['uid'] . ' -->
1278 <div class="typo3-clipCtrl">' . implode('', $cells) . '</div>';
1279 }
1280
1281 /**
1282 * Creates the HTML for a reference count for the record with the UID $uid
1283 * in the table $tableName.
1284 *
1285 * @param string $tableName
1286 * @param integer $uid
1287 * @return string HTML of reference a link, will be empty if there are no
1288 */
1289 protected function createReferenceHtml($tableName, $uid) {
1290 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
1291 'tablename, recuid, field',
1292 'sys_refindex',
1293 'ref_table = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($tableName, 'sys_refindex') .
1294 ' AND ref_uid = ' . $uid . ' AND deleted = 0'
1295 );
1296 return $this->generateReferenceToolTip($rows, '\'' . $tableName . '\', \'' . $uid . '\'');
1297 }
1298
1299 /**
1300 * Creates the localization panel
1301 *
1302 * @param string $table The table
1303 * @param array $row The record for which to make the localization panel.
1304 * @return array Array with key 0/1 with content for column 1 and 2
1305 * @todo Define visibility
1306 */
1307 public function makeLocalizationPanel($table, $row) {
1308 $out = array(
1309 0 => '',
1310 1 => ''
1311 );
1312 // Reset translations
1313 $this->translations = array();
1314 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
1315 // Language title and icon:
1316 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
1317 if (is_array($translations)) {
1318 $this->translations = $translations['translations'];
1319 // Traverse page translations and add icon for each language that does NOT yet exist:
1320 $lNew = '';
1321 foreach ($this->pageOverlays as $lUid_OnPage => $lsysRec) {
1322 if (!isset($translations['translations'][$lUid_OnPage]) && $GLOBALS['BE_USER']->checkLanguageAccess($lUid_OnPage)) {
1323 $url = substr($this->listURL(), strlen($this->backPath));
1324 $href = $GLOBALS['SOBE']->doc->issueCommand('&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage, $url . '&justLocalized=' . rawurlencode(($table . ':' . $row['uid'] . ':' . $lUid_OnPage)));
1325 $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title');
1326 if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
1327 $lC = IconUtility::getSpriteIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon']);
1328 } else {
1329 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
1330 }
1331 $lC = '<a href="' . htmlspecialchars($href) . '" title="' . htmlspecialchars($language['title']) . '">' . $lC . '</a> ';
1332 $lNew .= $lC;
1333 }
1334 }
1335 if ($lNew) {
1336 $out[1] .= $lNew;
1337 }
1338 } elseif ($row['l18n_parent']) {
1339 $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $out[0];
1340 }
1341 return $out;
1342 }
1343
1344 /**
1345 * Create the selector box for selecting fields to display from a table:
1346 *
1347 * @param string $table Table name
1348 * @param boolean $formFields If TRUE, form-fields will be wrapped around the table.
1349 * @return string HTML table with the selector box (name: displayFields['.$table.'][])
1350 * @todo Define visibility
1351 */
1352 public function fieldSelectBox($table, $formFields = 1) {
1353 // Init:
1354 $formElements = array('', '');
1355 if ($formFields) {
1356 $formElements = array('<form action="' . htmlspecialchars($this->listURL()) . '" method="post">', '</form>');
1357 }
1358 // Load already selected fields, if any:
1359 $setFields = is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
1360 // Request fields from table:
1361 $fields = $this->makeFieldList($table, FALSE, TRUE);
1362 // Add pseudo "control" fields
1363 $fields[] = '_PATH_';
1364 $fields[] = '_REF_';
1365 $fields[] = '_LOCALIZATION_';
1366 $fields[] = '_CONTROL_';
1367 $fields[] = '_CLIPBOARD_';
1368 // Create an option for each field:
1369 $opt = array();
1370 $opt[] = '<option value=""></option>';
1371 foreach ($fields as $fN) {
1372 // Field label
1373 $fL = is_array($GLOBALS['TCA'][$table]['columns'][$fN]) ? rtrim($GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label']), ':') : '[' . $fN . ']';
1374 $opt[] = '
1375 <option value="' . $fN . '"' . (in_array($fN, $setFields) ? ' selected="selected"' : '') . '>' . htmlspecialchars($fL) . '</option>';
1376 }
1377 // Compile the options into a multiple selector box:
1378 $lMenu = '
1379 <select size="' . \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((count($fields) + 1), 3, 20) . '" multiple="multiple" name="displayFields[' . $table . '][]">' . implode('', $opt) . '
1380 </select>
1381 ';
1382 // Table with the field selector::
1383 $content = $formElements[0] . '
1384
1385 <!--
1386 Field selector for extended table view:
1387 -->
1388 <table border="0" cellpadding="0" cellspacing="0" id="typo3-dblist-fieldSelect">
1389 <tr>
1390 <td>' . $lMenu . '</td>
1391 <td><input type="submit" name="search" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.setFields', TRUE) . '" /></td>
1392 </tr>
1393 </table>
1394 ' . $formElements[1];
1395 return '<div class="db_list-fieldSelect">' . $content . '</div>';
1396 }
1397
1398 /*********************************
1399 *
1400 * Helper functions
1401 *
1402 *********************************/
1403 /**
1404 * Creates a link around $string. The link contains an onclick action which submits the script with some clipboard action.
1405 * Currently, this is used for setting elements / delete elements.
1406 *
1407 * @param string $string The HTML content to link (image/text)
1408 * @param string $table Table name
1409 * @param string $cmd Clipboard command (eg. "setCB" or "delete")
1410 * @param string $warning Warning text, if any ("delete" uses this for confirmation)
1411 * @return string <a> tag wrapped link.
1412 * @todo Define visibility
1413 */
1414 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
1415 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.cmd_table.value=\'' . $table . '\';document.dblistForm.submit();';
1416 if ($warning) {
1417 $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
1418 }
1419 return '<a href="#" onclick="' . htmlspecialchars(($onClickEvent . 'return false;')) . '">' . $string . '</a>';
1420 }
1421
1422 /**
1423 * Returns TRUE if a numeric clipboard pad is selected/active
1424 *
1425 * @return boolean
1426 * @todo Define visibility
1427 */
1428 public function clipNumPane() {
1429 return in_Array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current != 'normal';
1430 }
1431
1432 /**
1433 * Creates a sort-by link on the input string ($code).
1434 * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
1435 * Also some fields will not be possible to sort (including if single-table-view is disabled).
1436 *
1437 * @param string $code The string to link (text)
1438 * @param string $field The fieldname represented by the title ($code)
1439 * @param string $table Table name
1440 * @return string Linked $code variable
1441 * @todo Define visibility
1442 */
1443 public function addSortLink($code, $field, $table) {
1444 // Certain circumstances just return string right away (no links):
1445 if ($field == '_CONTROL_' || $field == '_LOCALIZATION_' || $field == '_CLIPBOARD_' || $field == '_REF_' || $this->disableSingleTableView) {
1446 return $code;
1447 }
1448 // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
1449 if ($field == '_PATH_') {
1450 $field = 'pid';
1451 }
1452 // Create the sort link:
1453 $sortUrl = $this->listURL('', -1, 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || $this->sortField != $field ? 0 : 1);
1454 $sortArrow = $this->sortField === $field ? IconUtility::getSpriteIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc')) : '';
1455 // Return linked field:
1456 return '<a href="' . htmlspecialchars($sortUrl) . '">' . $code . $sortArrow . '</a>';
1457 }
1458
1459 /**
1460 * Returns the path for a certain pid
1461 * The result is cached internally for the session, thus you can call this function as much as you like without performance problems.
1462 *
1463 * @param integer $pid The page id for which to get the path
1464 * @return string The path.
1465 * @todo Define visibility
1466 */
1467 public function recPath($pid) {
1468 if (!isset($this->recPath_cache[$pid])) {
1469 $this->recPath_cache[$pid] = BackendUtility::getRecordPath($pid, $this->perms_clause, 20);
1470 }
1471 return $this->recPath_cache[$pid];
1472 }
1473
1474 /**
1475 * Returns TRUE if a link for creating new records should be displayed for $table
1476 *
1477 * @param string $table Table name
1478 * @return boolean Returns TRUE if a link for creating new records should be displayed for $table
1479 * @see SC_db_new::showNewRecLink
1480 * @todo Define visibility
1481 */
1482 public function showNewRecLink($table) {
1483 // No deny/allow tables are set:
1484 if (!count($this->allowedNewTables) && !count($this->deniedNewTables)) {
1485 return TRUE;
1486 } elseif (!in_array($table, $this->deniedNewTables) && (!count($this->allowedNewTables) || in_array($table, $this->allowedNewTables))) {
1487 return TRUE;
1488 } else {
1489 return FALSE;
1490 }
1491 }
1492
1493 /**
1494 * Creates the "&returnUrl" parameter for links - this is used when the script links to other scripts and passes its own URL with the link so other scripts can return to the listing again.
1495 * Uses REQUEST_URI as value.
1496 *
1497 * @return string
1498 * @todo Define visibility
1499 */
1500 public function makeReturnUrl() {
1501 return '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1502 }
1503
1504 /************************************
1505 *
1506 * CSV related functions
1507 *
1508 ************************************/
1509 /**
1510 * Initializes internal csvLines array with the header of field names
1511 *
1512 * @return void
1513 */
1514 protected function initCSV() {
1515 $this->addHeaderRowToCSV();
1516 }
1517
1518 /**
1519 * Add header line with field names as CSV line
1520 *
1521 * @return void
1522 */
1523 protected function addHeaderRowToCSV() {
1524 // Add header row, control fields will be reduced inside addToCSV()
1525 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
1526 }
1527
1528 /**
1529 * Adds selected columns of one table row as CSV line.
1530 *
1531 * @param array $row Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
1532 * @return void
1533 */
1534 protected function addToCSV(array $row = array()) {
1535 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
1536 $rowReducedToSelectedColumns = array_intersect_key($rowReducedByControlFields, array_flip($this->fieldArray));
1537 $this->setCsvRow($rowReducedToSelectedColumns);
1538 }
1539
1540 /**
1541 * Remove control fields from row for CSV export
1542 *
1543 * @param array $row fieldNames => fieldValues
1544 * @return array Input array reduces by control fields
1545 */
1546 static protected function removeControlFieldsFromFieldRow(array $row = array()) {
1547 // Possible control fields in a list row
1548 $controlFields = array(
1549 '_PATH_',
1550 '_REF_',
1551 '_CONTROL_',
1552 '_AFTERCONTROL_',
1553 '_AFTERREF_',
1554 '_CLIPBOARD_',
1555 '_LOCALIZATION_',
1556 '_LOCALIZATION_b'
1557 );
1558 return array_diff_key($row, array_flip($controlFields));
1559 }
1560
1561 /**
1562 * Adds input row of values to the internal csvLines array as a CSV formatted line
1563 *
1564 * @param array $csvRow Array with values to be listed.
1565 * @return void
1566 * @todo Define visibility
1567 */
1568 public function setCsvRow($csvRow) {
1569 $this->csvLines[] = GeneralUtility::csvValues($csvRow);
1570 }
1571
1572 /**
1573 * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
1574 * This function exits!
1575 *
1576 * @param string $prefix Filename prefix:
1577 * @return void EXITS php execusion!
1578 * @todo Define visibility
1579 */
1580 public function outputCSV($prefix) {
1581 // Setting filename:
1582 $filename = $prefix . '_' . date('dmy-Hi') . '.csv';
1583 // Creating output header:
1584 $mimeType = 'application/octet-stream';
1585 header('Content-Type: ' . $mimeType);
1586 header('Content-Disposition: attachment; filename=' . $filename);
1587 // Printing the content of the CSV lines:
1588 echo implode(chr(13) . chr(10), $this->csvLines);
1589 // Exits:
1590 die;
1591 }
1592
1593 }