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