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