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