[CLEANUP] Replace count with empty in multiple extensions, part II
[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, '', -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 (!empty($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))) . '" class="btn btn-default">'
627 . '<span class="t3-icon fa fa-chevron-down"></span> <i>[1 - ' . $countOnFirstPage . ($hasMore ? '+' : '') . ']</i></a>
628 </td></tr>';
629 }
630 }
631 // The header row for the table is now created:
632 $out .= $this->renderListHeader($table, $currentIdList);
633 }
634 // The list of records is added after the header:
635 $out .= $rowOutput;
636 // ... and it is all wrapped in a table:
637 $out = '
638
639
640
641 <!--
642 DB listing of elements: "' . htmlspecialchars($table) . '"
643 -->
644 <div class="panel panel-space panel-default">
645 <div class="panel-heading">
646 ' . $tableHeader . '
647 </div>
648 <div class="table-fit">
649 <table data-table="' . htmlspecialchars($table) . '" class="table table-striped table-hover' . ($listOnlyInSingleTableMode ? ' typo3-dblist-overview' : '') . '">
650 ' . $out . '
651 </table>
652 </div>
653 </div>
654 ';
655 // Output csv if...
656 // This ends the page with exit.
657 if ($this->csvOutput) {
658 $this->outputCSV($table);
659 }
660 }
661 // Return content:
662 return $out;
663 }
664
665 /**
666 * Check if all row listing conditions are fulfilled.
667 *
668 * This function serves as a dummy method to be overriden in extending classes.
669 *
670 * @param string $table Table name
671 * @param string[] $row Record
672 * @return bool True, if all conditions are fulfilled.
673 */
674 protected function isRowListingConditionFulfilled($table, $row) {
675 return TRUE;
676 }
677
678 /**
679 * Rendering a single row for the list
680 *
681 * @param string $table Table name
682 * @param mixed[] $row Current record
683 * @param int $cc Counter, counting for each time an element is rendered (used for alternating colors)
684 * @param string $titleCol Table field (column) where header value is found
685 * @param string $thumbsCol Table field (column) where (possible) thumbnails can be found
686 * @param int $indent Indent from left.
687 * @return string Table row for the element
688 * @access private
689 * @see getTable()
690 */
691 public function renderListRow($table, $row, $cc, $titleCol, $thumbsCol, $indent = 0) {
692 if (!is_array($row)) {
693 return '';
694 }
695 $rowOutput = '';
696 $id_orig = NULL;
697 // If in search mode, make sure the preview will show the correct page
698 if ((string)$this->searchString !== '') {
699 $id_orig = $this->id;
700 $this->id = $row['pid'];
701 }
702 // Add special classes for first and last row
703 $rowSpecial = '';
704 if ($cc == 1 && $indent == 0) {
705 $rowSpecial .= ' firstcol';
706 }
707 if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
708 $rowSpecial .= ' lastcol';
709 }
710
711 $row_bgColor = ' class="' . $rowSpecial . '"';
712
713 // Overriding with versions background color if any:
714 $row_bgColor = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : $row_bgColor;
715 // Incr. counter.
716 $this->counter++;
717 // The icon with link
718 $altText = htmlspecialchars(BackendUtility::getRecordIconAltText($row, $table));
719 $iconImg = IconUtility::getSpriteIconForRecord(
720 $table,
721 $row,
722 array('title' => $altText, 'style' => $indent ? ' margin-left: ' . $indent . 'px;' : '')
723 );
724 $theIcon = $this->clickMenuEnabled ? $this->getModule()->doc->wrapClickMenuOnIcon($iconImg, $table, $row['uid']) : $iconImg;
725 // Preparing and getting the data-array
726 $theData = array();
727 $localizationMarkerClass = '';
728 foreach ($this->fieldArray as $fCol) {
729 if ($fCol == $titleCol) {
730 $recTitle = BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);
731 $warning = '';
732 // If the record is edit-locked by another user, we will show a little warning sign:
733 $lockInfo = BackendUtility::isRecordLocked($table, $row['uid']);
734 if ($lockInfo) {
735 $warning = '<a href="#" onclick="alert('
736 . GeneralUtility::quoteJSvalue($lockInfo['msg']) . '); return false;" title="'
737 . htmlspecialchars($lockInfo['msg']) . '">'
738 . IconUtility::getSpriteIcon('status-warning-in-use') . '</a>';
739 }
740 $theData[$fCol] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
741 // Render thumbnails, if:
742 // - a thumbnail column exists
743 // - there is content in it
744 // - the thumbnail column is visible for the current type
745 $type = 0;
746 if (isset($GLOBALS['TCA'][$table]['ctrl']['type'])) {
747 $typeColumn = $GLOBALS['TCA'][$table]['ctrl']['type'];
748 $type = $row[$typeColumn];
749 }
750 // If current type doesn't exist, set it to 0 (or to 1 for historical reasons,
751 // if 0 doesn't exist)
752 if (!isset($GLOBALS['TCA'][$table]['types'][$type])) {
753 $type = isset($GLOBALS['TCA'][$table]['types'][0]) ? 0 : 1;
754 }
755 $visibleColumns = $GLOBALS['TCA'][$table]['types'][$type]['showitem'];
756
757 if ($this->thumbs &&
758 trim($row[$thumbsCol]) &&
759 preg_match('/(^|(.*(;|,)?))' . $thumbsCol . '(((;|,).*)|$)/', $visibleColumns) === 1
760 ) {
761 $theData[$fCol] .= '<br />' . $this->thumbCode($row, $table, $thumbsCol);
762 }
763 if (
764 isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
765 && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0
766 && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0
767 ) {
768 // It's a translated record with a language parent
769 $localizationMarkerClass = ' localization';
770 }
771 } elseif ($fCol == 'pid') {
772 $theData[$fCol] = $row[$fCol];
773 } elseif ($fCol == '_PATH_') {
774 $theData[$fCol] = $this->recPath($row['pid']);
775 } elseif ($fCol == '_REF_') {
776 $theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
777 } elseif ($fCol == '_CONTROL_') {
778 $theData[$fCol] = $this->makeControl($table, $row);
779 } elseif ($fCol == '_CLIPBOARD_') {
780 $theData[$fCol] = $this->makeClip($table, $row);
781 } elseif ($fCol == '_LOCALIZATION_') {
782 list($lC1, $lC2) = $this->makeLocalizationPanel($table, $row);
783 $theData[$fCol] = $lC1;
784 $theData[$fCol . 'b'] = $lC2;
785 } elseif ($fCol == '_LOCALIZATION_b') {
786 // deliberately empty
787 } else {
788 $tmpProc = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid']);
789 $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
790 if ($this->csvOutput) {
791 $row[$fCol] = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
792 }
793 }
794 }
795 // Reset the ID if it was overwritten
796 if ((string)$this->searchString !== '') {
797 $this->id = $id_orig;
798 }
799 // Add row to CSV list:
800 if ($this->csvOutput) {
801 $this->addToCSV($row, $table);
802 }
803 // Add classes to table cells
804 $this->addElement_tdCssClass[$titleCol] = 'col-title' . $localizationMarkerClass;
805 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
806 if ($this->getModule()->MOD_SETTINGS['clipBoard']) {
807 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
808 }
809 $this->addElement_tdCssClass['_PATH_'] = 'col-path';
810 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
811 $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
812 // Create element in table cells:
813 $theData['uid'] = $row['uid'];
814 $rowOutput .= $this->addelement(1, $theIcon, $theData, $row_bgColor);
815 // Finally, return table row element:
816 return $rowOutput;
817 }
818
819 /**
820 * Gets the number of records referencing the record with the UID $uid in
821 * the table $tableName.
822 *
823 * @param string $tableName
824 * @param int $uid
825 * @return int The number of references to record $uid in table
826 */
827 protected function getReferenceCount($tableName, $uid) {
828 $db = $this->getDatabaseConnection();
829 if (!isset($this->referenceCount[$tableName][$uid])) {
830 $where = 'ref_table = ' . $db->fullQuoteStr($tableName, 'sys_refindex')
831 . ' AND ref_uid = ' . $uid . ' AND deleted = 0';
832 $numberOfReferences = $db->exec_SELECTcountRows('*', 'sys_refindex', $where);
833 $this->referenceCount[$tableName][$uid] = $numberOfReferences;
834 }
835 return $this->referenceCount[$tableName][$uid];
836 }
837
838 /**
839 * Rendering the header row for a table
840 *
841 * @param string $table Table name
842 * @param int[] $currentIdList Array of the currently displayed uids of the table
843 * @throws \UnexpectedValueException
844 * @return string Header table row
845 * @access private
846 * @see getTable()
847 */
848 public function renderListHeader($table, $currentIdList) {
849 $lang = $this->getLanguageService();
850 // Init:
851 $theData = array();
852 $icon = '';
853 // Traverse the fields:
854 foreach ($this->fieldArray as $fCol) {
855 // Calculate users permissions to edit records in the table:
856 $permsEdit = $this->calcPerms & ($table == 'pages' ? 2 : 16);
857 switch ((string)$fCol) {
858 case '_PATH_':
859 // Path
860 $theData[$fCol] = '<i>[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels._PATH_', TRUE) . ']</i>';
861 break;
862 case '_REF_':
863 // References
864 $theData[$fCol] = '<i>[' . $lang->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:c__REF_', TRUE) . ']</i>';
865 break;
866 case '_LOCALIZATION_':
867 // Path
868 $theData[$fCol] = '<i>[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels._LOCALIZATION_', TRUE) . ']</i>';
869 break;
870 case '_LOCALIZATION_b':
871 // Path
872 $theData[$fCol] = $lang->getLL('Localize', TRUE);
873 break;
874 case '_CLIPBOARD_':
875 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
876 break;
877 }
878 // Clipboard:
879 $cells = array();
880 // If there are elements on the clipboard for this table, then display the
881 // "paste into" icon:
882 $elFromTable = $this->clipObj->elFromTable($table);
883 if (!empty($elFromTable)) {
884 $href = htmlspecialchars($this->clipObj->pasteUrl($table, $this->id));
885 $onClick = htmlspecialchars('return ' . $this->clipObj->confirmMsg('pages', $this->pageRow, 'into', $elFromTable));
886 $cells['pasteAfter'] = '<a class="btn btn-default" href="' . $href . '" onclick="' . $onClick
887 . '" title="' . $lang->getLL('clip_paste', TRUE) . '">'
888 . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
889 }
890 // If the numeric clipboard pads are enabled, display the control icons for that:
891 if ($this->clipObj->current != 'normal') {
892 // The "select" link:
893 $spriteIcon = IconUtility::getSpriteIcon('actions-edit-copy', array('title' => $lang->getLL('clip_selectMarked', TRUE)));
894 $cells['copyMarked'] = $this->linkClipboardHeaderIcon($spriteIcon, $table, 'setCB');
895 // The "edit marked" link:
896 $editIdList = implode(',', $currentIdList);
897 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
898 $params = '&edit[' . $table . '][' . $editIdList . ']=edit';
899 $onClick = htmlspecialchars(BackendUtility::editOnClick($params, '', -1));
900 $cells['edit'] = '<a class="btn btn-default" href="#" onclick="' . $onClick . '" title="'
901 . $lang->getLL('clip_editMarked', TRUE) . '">'
902 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
903 // The "Delete marked" link:
904 $cells['delete'] = $this->linkClipboardHeaderIcon(
905 IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $lang->getLL('clip_deleteMarked', TRUE))),
906 $table,
907 'delete',
908 sprintf($lang->getLL('clip_deleteMarkedWarning'), $lang->sL($GLOBALS['TCA'][$table]['ctrl']['title']))
909 );
910 // The "Select all" link:
911 $onClick = htmlspecialchars(('checkOffCB(\'' . implode(',', $this->CBnames) . '\', this); return false;'));
912 $cells['markAll'] = '<a class="btn btn-default" rel="" href="#" onclick="' . $onClick . '" title="'
913 . $lang->getLL('clip_markRecords', TRUE) . '">'
914 . IconUtility::getSpriteIcon('actions-document-select') . '</a>';
915 } else {
916 $cells['empty'] = '';
917 }
918 /**
919 * @hook renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
920 * @usage Above each listed table in Web>List a header row is shown.
921 * This hook allows to modify the icons responsible for the clipboard functions
922 * (shown above the clipboard checkboxes when a clipboard other than "Normal" is selected),
923 * or other "Action" functions which perform operations on the listed records.
924 */
925 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
926 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
927 $hookObject = GeneralUtility::getUserObj($classData);
928 if (!$hookObject instanceof RecordListHookInterface) {
929 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567850);
930 }
931 $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
932 }
933 }
934 $theData[$fCol] = '<div class="btn-group" role="group">' . implode('', $cells) . '</div>';
935 break;
936 case '_CONTROL_':
937 // Control panel:
938 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
939 // If new records can be created on this page, add links:
940 $permsAdditional = ($table === 'pages' ? 8 : 16);
941 if ($this->calcPerms & $permsAdditional && $this->showNewRecLink($table)) {
942 $spriteIcon = $table === 'pages'
943 ? IconUtility::getSpriteIcon('actions-page-new')
944 : IconUtility::getSpriteIcon('actions-document-new');
945 if ($table === 'tt_content' && $this->newWizards) {
946 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
947 $tmpTSc = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
948 $tmpTSc = $tmpTSc['properties']['newContentWiz.']['overrideWithExtension'];
949 $newContentWizScriptPath = ExtensionManagementUtility::isLoaded($tmpTSc)
950 ? $this->backPath . ExtensionManagementUtility::extRelPath($tmpTSc) . 'mod1/db_new_content_el.php?id=' . $this->id
951 : BackendUtility::getModuleUrl('new_content_element', array('id' => $this->id));
952
953 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($newContentWizScriptPath) . ');';
954 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
955 . $lang->getLL('new', TRUE) . '">' . $spriteIcon . '</a>';
956 } elseif ($table == 'pages' && $this->newWizards) {
957 $parameters = ['id' => $this->id, 'pagesOnly' => 1, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')];
958 $href = BackendUtility::getModuleUrl('db_new', $parameters);
959 $icon = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="' . $lang->getLL('new', TRUE) . '">'
960 . $spriteIcon . '</a>';
961 } else {
962 $params = '&edit[' . $table . '][' . $this->id . ']=new';
963 if ($table == 'pages_language_overlay') {
964 $params .= '&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageRow['doktype'];
965 }
966 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
967 . '" title="' . $lang->getLL('new', TRUE) . '">' . $spriteIcon . '</a>';
968 }
969 }
970 // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
971 if ($permsEdit && $this->table && is_array($currentIdList)) {
972 $editIdList = implode(',', $currentIdList);
973 if ($this->clipNumPane()) {
974 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
975 }
976 $params = '&edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . implode(',', $this->fieldArray);
977 $icon .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
978 . '" title="' . $lang->getLL('editShownColumns', TRUE) . '">'
979 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
980 $icon = '<div class="btn-group" role="group">' . $icon . '</div>';
981 }
982 // Add an empty entry, so column count fits again after moving this into $icon
983 $theData[$fCol] = '&nbsp;';
984 }
985 break;
986 default:
987 // Regular fields header:
988 $theData[$fCol] = '';
989
990 // Check if $fCol is really a field and get the label and remove the colons
991 // at the end
992 $sortLabel = BackendUtility::getItemLabel($table, $fCol);
993 if ($sortLabel !== NULL) {
994 $sortLabel = $lang->sL($sortLabel, TRUE);
995 $sortLabel = rtrim(trim($sortLabel), ':');
996 } else {
997 // No TCA field, only output the $fCol variable with square brackets []
998 $sortLabel = htmlspecialchars($fCol);
999 $sortLabel = '<i>[' . rtrim(trim($sortLabel), ':') . ']</i>';
1000 }
1001
1002 if ($this->table && is_array($currentIdList)) {
1003 // If the numeric clipboard pads are selected, show duplicate sorting link:
1004 if ($this->clipNumPane()) {
1005 $theData[$fCol] .= '<a class="btn btn-default" href="' . htmlspecialchars($this->listURL('', -1) . '&duplicateField=' . $fCol)
1006 . '" title="' . $lang->getLL('clip_duplicates', TRUE) . '">'
1007 . IconUtility::getSpriteIcon('actions-document-duplicates-select') . '</a>';
1008 }
1009 // If the table can be edited, add link for editing THIS field for all
1010 // listed records:
1011 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly'] && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
1012 $editIdList = implode(',', $currentIdList);
1013 if ($this->clipNumPane()) {
1014 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
1015 }
1016 $params = '&edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . $fCol;
1017 $iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
1018 $theData[$fCol] .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1019 . '" title="' . htmlspecialchars($iTitle) . '">'
1020 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1021 }
1022 if(strlen($theData[$fCol]) > 0){
1023 $theData[$fCol] = '<div class="btn-group" role="group">' . $theData[$fCol] . '</div> ';
1024 }
1025 }
1026 $theData[$fCol] .= $this->addSortLink($sortLabel, $fCol, $table);
1027 }
1028 }
1029 /**
1030 * @hook renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
1031 * @usage Above each listed table in Web>List a header row is shown.
1032 * Containing the labels of all shown fields and additional icons to create new records for this
1033 * table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
1034 */
1035 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1036 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1037 $hookObject = GeneralUtility::getUserObj($classData);
1038 if (!$hookObject instanceof RecordListHookInterface) {
1039 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567855);
1040 }
1041 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
1042 }
1043 }
1044
1045
1046 // Create and return header table row:
1047 return '<thead>' . $this->addelement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
1048 }
1049
1050 /**
1051 * Get pointer for first element on the page
1052 *
1053 * @param int $page Page number starting with 1
1054 * @return int Pointer to first element on the page (starting with 0)
1055 */
1056 protected function getPointerForPage($page) {
1057 return ($page - 1) * $this->iLimit;
1058 }
1059
1060 /**
1061 * Creates a page browser for tables with many records
1062 *
1063 * @param string $renderPart Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
1064 * @return string Navigation HTML
1065 */
1066 protected function renderListNavigation($renderPart = 'top') {
1067 $totalPages = ceil($this->totalItems / $this->iLimit);
1068 // Show page selector if not all records fit into one page
1069 if ($totalPages <= 1) {
1070 return '';
1071 }
1072 $content = '';
1073 $listURL = $this->listURL('', $this->table);
1074 // 1 = first page
1075 // 0 = first element
1076 $currentPage = floor($this->firstElementNumber / $this->iLimit) + 1;
1077 // Compile first, previous, next, last and refresh buttons
1078 if ($currentPage > 1) {
1079 $labelFirst = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:first');
1080 $labelPrevious = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:previous');
1081 $first = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage(1) . '">'
1082 . IconUtility::getSpriteIcon('actions-view-paging-first', array('title' => $labelFirst)) . '</a></li>';
1083 $previous = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage - 1) . '">'
1084 . IconUtility::getSpriteIcon('actions-view-paging-previous', array('title' => $labelPrevious)) . '</a></li>';
1085 } else {
1086 $first = '<li class="disabled"><span>' . IconUtility::getSpriteIcon('actions-view-paging-first') . '</span></li>';
1087 $previous = '<li class="disabled"><span>' . IconUtility::getSpriteIcon('actions-view-paging-previous') . '</span></li>';
1088 }
1089 if ($currentPage < $totalPages) {
1090 $labelNext = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:next');
1091 $labelLast = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:last');
1092 $next = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage + 1) . '">'
1093 . IconUtility::getSpriteIcon('actions-view-paging-next', array('title' => $labelNext)) . '</a></li>';
1094 $last = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($totalPages) . '">'
1095 . IconUtility::getSpriteIcon('actions-view-paging-last', array('title' => $labelLast)) . '</a></li>';
1096 } else {
1097 $next = '<li class="disabled"><span>' . IconUtility::getSpriteIcon('actions-view-paging-next') . '</span></li>';
1098 $last = '<li class="disabled"><span>' . IconUtility::getSpriteIcon('actions-view-paging-last') . '</span></li>';
1099 }
1100 $reload = '<li><a href="#" onclick="document.dblistForm.action=\'' . $listURL
1101 . '&pointer=\'+calculatePointer(document.getElementById(\'jumpPage-' . $renderPart
1102 . '\').value); document.dblistForm.submit(); return true;" title="'
1103 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:reload', TRUE) . '">'
1104 . IconUtility::getSpriteIcon('actions-system-refresh') . '</a></li>';
1105 if ($renderPart === 'top') {
1106 // Add js to traverse a page select input to a pointer value
1107 $content = '
1108 <script type="text/javascript">
1109 /*<![CDATA[*/
1110 function calculatePointer(page) {
1111 if (page > ' . $totalPages . ') {
1112 page = ' . $totalPages . ';
1113 }
1114 if (page < 1) {
1115 page = 1;
1116 }
1117 return (page - 1) * ' . $this->iLimit . ';
1118 }
1119 /*]]>*/
1120 </script>
1121 ';
1122 }
1123 $pageNumberInput = '
1124 <input type="text" value="' . $currentPage . '" size="3" class="form-control input-sm paginator-input" id="jumpPage-' . $renderPart . '" name="jumpPage-'
1125 . $renderPart . '" onkeyup="if (event.keyCode == 13) { document.dblistForm.action=\'' . $listURL
1126 . '&pointer=\'+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
1127 ';
1128 $pageIndicatorText = sprintf(
1129 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:pageIndicator'),
1130 $pageNumberInput,
1131 $totalPages
1132 );
1133 $pageIndicator = '<li><span>' . $pageIndicatorText . '</span></li>';
1134 if ($this->totalItems > $this->firstElementNumber + $this->iLimit) {
1135 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
1136 } else {
1137 $lastElementNumber = $this->totalItems;
1138 }
1139 $rangeIndicator = '<li><span>' . sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:rangeIndicator'), ($this->firstElementNumber + 1), $lastElementNumber) . '</span></li>';
1140
1141 $titleColumn = $this->fieldArray[0];
1142 $data = array(
1143 $titleColumn => $content . '
1144 <nav class="pagination-wrap">
1145 <ul class="pagination pagination-block">
1146 ' . $first . '
1147 ' . $previous . '
1148 ' . $rangeIndicator . '
1149 ' . $pageIndicator . '
1150 ' . $next . '
1151 ' . $last . '
1152 ' . $reload . '
1153 </ul>
1154 </nav>
1155 '
1156 );
1157 return $this->addElement(1, '', $data);
1158 }
1159
1160 /*********************************
1161 *
1162 * Rendering of various elements
1163 *
1164 *********************************/
1165
1166 /**
1167 * Creates the control panel for a single record in the listing.
1168 *
1169 * @param string $table The table
1170 * @param mixed[] $row The record for which to make the control panel.
1171 * @throws \UnexpectedValueException
1172 * @return string HTML table with the control panel (unless disabled)
1173 */
1174 public function makeControl($table, $row) {
1175 $module = $this->getModule();
1176 $rowUid = $row['uid'];
1177 if (ExtensionManagementUtility::isLoaded('version') && isset($row['_ORIG_uid'])) {
1178 $rowUid = $row['_ORIG_uid'];
1179 }
1180 $cells = array(
1181 'primary' => array(),
1182 'secondary' => array()
1183 );
1184 // If the listed table is 'pages' we have to request the permission settings for each page:
1185 $localCalcPerms = 0;
1186 if ($table == 'pages') {
1187 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1188 }
1189 // This expresses the edit permissions for this particular element:
1190 $permsEdit = $table === 'pages' && $localCalcPerms & Permission::PAGE_EDIT || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT;
1191 // "Show" link (only pages and tt_content elements)
1192 if ($table == 'pages' || $table == 'tt_content') {
1193 $viewAction = '<a class="btn btn-default" href="#" onclick="'
1194 . htmlspecialchars(
1195 BackendUtility::viewOnClick(
1196 ($table === 'tt_content' ? $this->id : $row['uid']),
1197 $this->backPath,
1198 '',
1199 ($table === 'tt_content' ? '#' . $row['uid'] : '')
1200 )
1201 ) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
1202 . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
1203 $this->addActionToCellGroup($cells, $viewAction, 'view');
1204 }
1205 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1206 if ($permsEdit) {
1207 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1208 $spriteIcon = ($GLOBALS['TCA'][$table]['ctrl']['readOnly'] ? 'actions-document-open-read-only' : 'actions-document-open');
1209 $editAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1210 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">' . IconUtility::getSpriteIcon($spriteIcon) . '</a>';
1211 $this->addActionToCellGroup($cells, $editAction, 'edit');
1212 }
1213 // "Info": (All records)
1214 $onClick = 'top.launchView(\'' . $table . '\', \'' . $row['uid'] . '\'); return false;';
1215 $viewBigAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->getLL('showInfo', TRUE) . '">'
1216 . IconUtility::getSpriteIcon('actions-document-info') . '</a>';
1217 $this->addActionToCellGroup($cells, $viewBigAction, 'viewBig');
1218 // "Move" wizard link for pages/tt_content elements:
1219 if ($table === 'tt_content' && $permsEdit || $table === 'pages') {
1220 $onClick = 'return jumpExt(\'' . $this->backPath . BackendUtility::getModuleUrl('move_element') . '&table=' . $table . '&uid=' . $row['uid'] . '\');';
1221 $linkTitleLL = $this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page'), TRUE);
1222 $spriteIcon = $table === 'tt_content' ? 'actions-document-move' : 'actions-page-move';
1223 $moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . IconUtility::getSpriteIcon($spriteIcon) . '</a>';
1224 $this->addActionToCellGroup($cells, $moveAction, 'move');
1225 }
1226 // If the table is NOT a read-only table, then show these links:
1227 if (!$GLOBALS['TCA'][$table]['ctrl']['readOnly']) {
1228 // "Revert" link (history/undo)
1229 $moduleUrl = BackendUtility::getModuleUrl('record_history', array('element' => $table . ':' . $row['uid']));
1230 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($this->backPath . $moduleUrl) . ',\'#latest\');';
1231 $historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1232 . $this->getLanguageService()->getLL('history', TRUE) . '">'
1233 . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1234 $this->addActionToCellGroup($cells, $historyAction, 'history');
1235 // Versioning:
1236 if (ExtensionManagementUtility::isLoaded('version') && !ExtensionManagementUtility::isLoaded('workspaces')) {
1237 $vers = BackendUtility::selectVersionsOfRecord($table, $row['uid'], 'uid', $this->getBackendUserAuthentication()->workspace, FALSE, $row);
1238 // If table can be versionized.
1239 if (is_array($vers)) {
1240 $versionIcon = 'no-version';
1241 if (count($vers) > 1) {
1242 $versionIcon = count($vers) - 1;
1243 }
1244 $href = $this->backPath . BackendUtility::getModuleUrl('web_txversionM1', array(
1245 'table' => $table, 'uid' => $row['uid']
1246 ));
1247 $versionAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1248 . $this->getLanguageService()->getLL('displayVersions', TRUE) . '">'
1249 . IconUtility::getSpriteIcon(('status-version-' . $versionIcon)) . '</a>';
1250 $this->addActionToCellGroup($cells, $versionAction, 'version');
1251 }
1252 }
1253 // "Edit Perms" link:
1254 if ($table === 'pages' && $this->getBackendUserAuthentication()->check('modules', 'system_BeuserTxPermission') && ExtensionManagementUtility::isLoaded('beuser')) {
1255 $href = BackendUtility::getModuleUrl('system_BeuserTxPermission') . '&id=' . $row['uid'] . '&return_id=' . $row['uid'] . '&edit=1';
1256 $permsAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1257 . $this->getLanguageService()->getLL('permissions', TRUE) . '">'
1258 . IconUtility::getSpriteIcon('status-status-locked') . '</a>';
1259 $this->addActionToCellGroup($cells, $permsAction, 'perms');
1260 }
1261 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row
1262 // or if default values can depend on previous record):
1263 if ($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) {
1264 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT || $table === 'pages' && $this->calcPerms & Permission::PAGE_NEW) {
1265 if ($this->showNewRecLink($table)) {
1266 $params = '&edit[' . $table . '][' . -($row['_MOVE_PLH'] ? $row['_MOVE_PLH_uid'] : $row['uid']) . ']=new';
1267 $newAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1268 . '" title="' . $this->getLanguageService()->getLL('new' . ($table == 'pages ' ? 'Page' : 'Record'), TRUE) . '">'
1269 . ($table == 'pages' ? IconUtility::getSpriteIcon('actions-page-new') : IconUtility::getSpriteIcon('actions-document-new')) . '</a>';
1270 $this->addActionToCellGroup($cells, $newAction, 'new');
1271 }
1272 }
1273 }
1274 // "Up/Down" links
1275 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField && !$this->searchLevels) {
1276 if (isset($this->currentTable['prev'][$row['uid']])) {
1277 // Up
1278 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
1279 $moveUpAction = '<a class="btn btn-default" href="#" onclick="'
1280 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1281 . '" title="' . $this->getLanguageService()->getLL('moveUp', TRUE) . '">'
1282 . IconUtility::getSpriteIcon('actions-move-up') . '</a>';
1283 } else {
1284 $moveUpAction = $this->spaceIcon;
1285 }
1286 $this->addActionToCellGroup($cells, $moveUpAction, 'moveUp');
1287
1288 if ($this->currentTable['next'][$row['uid']]) {
1289 // Down
1290 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
1291 $moveDownAction = '<a class="btn btn-default" href="#" onclick="'
1292 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1293 . '" title="' . $this->getLanguageService()->getLL('moveDown', TRUE) . '">'
1294 . IconUtility::getSpriteIcon('actions-move-down') . '</a>';
1295 } else {
1296 $moveDownAction = $this->spaceIcon;
1297 }
1298 $this->addActionToCellGroup($cells, $moveDownAction, 'moveDown');
1299 }
1300 // "Hide/Unhide" links:
1301 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1302 if (
1303 $permsEdit && $hiddenField && $GLOBALS['TCA'][$table]['columns'][$hiddenField]
1304 && (!$GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude']
1305 || $this->getBackendUserAuthentication()->check('non_exclude_fields', $table . ':' . $hiddenField))
1306 ) {
1307 if ($this->isRecordCurrentBackendUser($table, $row)) {
1308 $hideAction = '<span class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</span>';
1309 } else {
1310 if ($row[$hiddenField]) {
1311 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
1312 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="hidden" href="#"'
1313 . ' data-params="' . htmlspecialchars($params) . '"'
1314 . ' title="' . $this->getLanguageService()->getLL(('unHide' . ($table == 'pages' ? 'Page' : '')), TRUE) . '">'
1315 . IconUtility::getSpriteIcon('actions-edit-unhide') . '</a>';
1316 } else {
1317 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
1318 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="visible" href="#"'
1319 . ' data-params="' . htmlspecialchars($params) . '"'
1320 . ' title="' . $this->getLanguageService()->getLL(('hide' . ($table == 'pages' ? 'Page' : '')), TRUE) . '">'
1321 . IconUtility::getSpriteIcon('actions-edit-hide') . '</a>';
1322 }
1323 }
1324 $this->addActionToCellGroup($cells, $hideAction, 'hide');
1325 }
1326 // "Delete" link:
1327 if ($table === 'pages' && $localCalcPerms & Permission::PAGE_DELETE || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT) {
1328 // Check if the record version is in "deleted" state, because that will switch the action to "restore"
1329 if ($this->getBackendUserAuthentication()->workspace > 0 && isset($row['t3ver_state']) && (int)$row['t3ver_state'] === 2) {
1330 $actionName = 'restore';
1331 $refCountMsg = '';
1332 } else {
1333 $actionName = 'delete';
1334 $refCountMsg = BackendUtility::referenceCount(
1335 $table,
1336 $row['uid'],
1337 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToRecord'),
1338 $this->getReferenceCount($table, $row['uid'])) . BackendUtility::translationCount($table, $row['uid'],
1339 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')
1340 );
1341 }
1342
1343 if ($this->isRecordCurrentBackendUser($table, $row)) {
1344 $deleteAction = '<span class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</span>';
1345 } else {
1346 $titleOrig = BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);
1347 $title = GeneralUtility::slashJS(GeneralUtility::fixed_lgd_cs($titleOrig, $this->fixedL), TRUE);
1348 $warningText = $this->getLanguageService()->getLL($actionName . 'Warning') . ' "' . $title . '" ' . '[' . $table . ':' . $row['uid'] . ']' . $refCountMsg;
1349
1350 $params = 'cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
1351 $icon = IconUtility::getSpriteIcon('actions-edit-' . $actionName);
1352 $linkTitle = $this->getLanguageService()->getLL($actionName, TRUE);
1353 $deleteAction = '<a class="btn btn-default t3js-record-delete" href="#" '
1354 . ' data-l10parent="' . htmlspecialchars($row['l10n_parent']) . '"'
1355 . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($titleOrig) . '"'
1356 . ' data-message="' . htmlspecialchars($warningText) . '" title="' . $linkTitle . '"'
1357 . '>' . $icon . '</a>';
1358 }
1359 $this->addActionToCellGroup($cells, $deleteAction, 'delete');
1360 }
1361 // "Levels" links: Moving pages into new levels...
1362 if ($permsEdit && $table == 'pages' && !$this->searchLevels) {
1363 // Up (Paste as the page right after the current parent page)
1364 if ($this->calcPerms & Permission::PAGE_NEW) {
1365 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
1366 $moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
1367 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1368 . '" title="' . $this->getLanguageService()->getLL('prevLevel', TRUE) . '">'
1369 . IconUtility::getSpriteIcon('actions-move-left') . '</a>';
1370 $this->addActionToCellGroup($cells, $moveLeftAction, 'moveLeft');
1371 }
1372 // Down (Paste as subpage to the page right above)
1373 if ($this->currentTable['prevUid'][$row['uid']]) {
1374 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
1375 if ($localCalcPerms & Permission::PAGE_NEW) {
1376 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
1377 $moveRightAction = '<a class="btn btn-default" href="#" onclick="'
1378 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1379 . '" title="' . $this->getLanguageService()->getLL('nextLevel', TRUE) . '">'
1380 . IconUtility::getSpriteIcon('actions-move-right') . '</a>';
1381 } else {
1382 $moveRightAction = $this->spaceIcon;
1383 }
1384 } else {
1385 $moveRightAction = $this->spaceIcon;
1386 }
1387 $this->addActionToCellGroup($cells, $moveRightAction, 'moveRight');
1388 }
1389 }
1390 /**
1391 * @hook recStatInfoHooks: Allows to insert HTML before record icons on various places
1392 */
1393 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1394 $stat = '';
1395 $_params = array($table, $row['uid']);
1396 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1397 $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1398 }
1399 $this->addActionToCellGroup($cells, $stat, 'stat');
1400 }
1401 /**
1402 * @hook makeControl: Allows to change control icons of records in list-module
1403 * @usage This hook method gets passed the current $cells array as third parameter.
1404 * This array contains values for the icons/actions generated for each record in Web>List.
1405 * Each array entry is accessible by an index-key.
1406 * The order of the icons is depending on the order of those array entries.
1407 */
1408 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1409 // for compatibility reason, we move all icons to the rootlevel
1410 // before calling the hooks
1411 foreach ($cells as $section => $actions) {
1412 foreach ($actions as $actionKey => $action) {
1413 $cells[$actionKey] = $action;
1414 }
1415 }
1416 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1417 $hookObject = GeneralUtility::getUserObj($classData);
1418 if (!$hookObject instanceof RecordListHookInterface) {
1419 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567840);
1420 }
1421 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1422 }
1423 // now sort icons again into primary and secondary sections
1424 // after all hooks are processed
1425 $hookCells = $cells;
1426 foreach ($hookCells as $key => $value) {
1427 if ($key === 'primary' || $key === 'secondary') {
1428 continue;
1429 }
1430 $this->addActionToCellGroup($cells, $value, $key);
1431 }
1432 }
1433 $output = '<!-- CONTROL PANEL: ' . $table . ':' . $row['uid'] . ' -->';
1434 foreach($cells as $classification => $actions) {
1435 $visibilityClass = ($classification !== 'primary' && !$module->MOD_SETTINGS['bigControlPanel'] ? 'collapsed' : 'expanded');
1436 if ($visibilityClass === 'collapsed') {
1437 $cellOutput = '';
1438 foreach ($actions as $action) {
1439 $cellOutput .= $action;
1440 }
1441 $output .= ' <div class="btn-group">' .
1442 '<span id="actions_' . $table . '_' . $row['uid'] . '" class="btn-group collapse collapse-horizontal width">' . $cellOutput . '</span>' .
1443 '<a href="#actions_' . $table . '_' . $row['uid'] . '" class="btn btn-default collapsed" data-toggle="collapse" aria-expanded="false"><span class="t3-icon fa fa-ellipsis-h"></span></a>' .
1444 '</div>';
1445 } else {
1446 $output .= ' <div class="btn-group" role="group">' . implode('', $actions) . '</div>';
1447 }
1448 }
1449 return $output;
1450 }
1451
1452 /**
1453 * Creates the clipboard panel for a single record in the listing.
1454 *
1455 * @param string $table The table
1456 * @param mixed[] $row The record for which to make the clipboard panel.
1457 * @throws \UnexpectedValueException
1458 * @return string HTML table with the clipboard panel (unless disabled)
1459 */
1460 public function makeClip($table, $row) {
1461 // Return blank, if disabled:
1462 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1463 return '';
1464 }
1465 $cells = array();
1466 $cells['pasteAfter'] = ($cells['pasteInto'] = $this->spaceIcon);
1467 //enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
1468 $isL10nOverlay = $this->localizationView && $table != 'pages_language_overlay' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1469 // Return blank, if disabled:
1470 // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1471 // For the "Normal" pad:
1472 if ($this->clipObj->current == 'normal') {
1473 // Show copy/cut icons:
1474 $isSel = (string)$this->clipObj->isSelected($table, $row['uid']);
1475 if ($isL10nOverlay) {
1476 $cells['copy'] = $this->spaceIcon;
1477 $cells['cut'] = $this->spaceIcon;
1478 } else {
1479 $cells['copy'] = '<a class="btn btn-default" href="#" onclick="'
1480 . htmlspecialchars('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel == 'copy'), array('returnUrl' => '')) . '\');')
1481 . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', TRUE) . '">'
1482 . (!$isSel == 'copy' ? IconUtility::getSpriteIcon('actions-edit-copy') : IconUtility::getSpriteIcon('actions-edit-copy-release')) . '</a>';
1483 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
1484 . htmlspecialchars('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel == 'cut'), array('returnUrl' => '')) . '\');')
1485 . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', TRUE) . '">'
1486 . (!$isSel == 'cut' ? IconUtility::getSpriteIcon('actions-edit-cut') : IconUtility::getSpriteIcon('actions-edit-cut-release')) . '</a>';
1487 }
1488 } else {
1489 // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1490 // Setting name of the element in ->CBnames array:
1491 $n = $table . '|' . $row['uid'];
1492 $this->CBnames[] = $n;
1493 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1494 $checked = $this->clipObj->isSelected($table, $row['uid']) ? 'checked="checked" ' : '';
1495 // If the "duplicateField" value is set then select all elements which are duplicates...
1496 if ($this->duplicateField && isset($row[$this->duplicateField])) {
1497 $checked = '';
1498 if (in_array($row[$this->duplicateField], $this->duplicateStack)) {
1499 $checked = 'checked="checked" ';
1500 }
1501 $this->duplicateStack[] = $row[$this->duplicateField];
1502 }
1503 // Adding the checkbox to the panel:
1504 $cells['select'] = $isL10nOverlay
1505 ? $this->spaceIcon
1506 : '<label class="btn btn-default btn-checkbox"><input type="hidden" name="CBH[' . $n . ']" value="0" /><input type="checkbox"'
1507 . ' name="CBC[' . $n . ']" value="1" ' . $checked . '/><span class="t3-icon fa"></span></label>';
1508 }
1509 // Now, looking for selected elements from the current table:
1510 $elFromTable = $this->clipObj->elFromTable($table);
1511 if (!empty($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1512 // IF elements are found and they can be individually ordered, then add a "paste after" icon:
1513 $cells['pasteAfter'] = $isL10nOverlay
1514 ? $this->spaceIcon
1515 : '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '" onclick="'
1516 . htmlspecialchars(('return ' . $this->clipObj->confirmMsg($table, $row, 'after', $elFromTable)))
1517 . '" title="' . $this->getLanguageService()->getLL('clip_pasteAfter', TRUE) . '">'
1518 . IconUtility::getSpriteIcon('actions-document-paste-after') . '</a>';
1519 }
1520 // Now, looking for elements in general:
1521 $elFromTable = $this->clipObj->elFromTable('');
1522 if ($table == 'pages' && !empty($elFromTable)) {
1523 $cells['pasteInto'] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid']))
1524 . '" onclick="' . htmlspecialchars('return ' . $this->clipObj->confirmMsg($table, $row, 'into', $elFromTable))
1525 . '" title="' . $this->getLanguageService()->getLL('clip_pasteInto', TRUE) . '">'
1526 . IconUtility::getSpriteIcon('actions-document-paste-into') . '</a>';
1527 }
1528 /**
1529 * @hook makeClip: Allows to change clip-icons of records in list-module
1530 * @usage This hook method gets passed the current $cells array as third parameter.
1531 * This array contains values for the clipboard icons generated for each record in Web>List.
1532 * Each array entry is accessible by an index-key.
1533 * The order of the icons is depending on the order of those array entries.
1534 */
1535 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1536 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1537 $hookObject = GeneralUtility::getUserObj($classData);
1538 if (!$hookObject instanceof RecordListHookInterface) {
1539 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567845);
1540 }
1541 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1542 }
1543 }
1544 // Compile items into a DIV-element:
1545 return '<!-- CLIPBOARD PANEL: ' . $table . ':' . $row['uid'] . ' -->
1546 <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1547 }
1548
1549 /**
1550 * Creates the HTML for a reference count for the record with the UID $uid
1551 * in the table $tableName.
1552 *
1553 * @param string $tableName
1554 * @param int $uid
1555 * @return string HTML of reference a link, will be empty if there are no
1556 */
1557 protected function createReferenceHtml($tableName, $uid) {
1558 $db = $this->getDatabaseConnection();
1559 $referenceCount = $db->exec_SELECTcountRows(
1560 '*',
1561 'sys_refindex',
1562 'ref_table = ' . $db->fullQuoteStr($tableName, 'sys_refindex') .
1563 ' AND ref_uid = ' . $uid . ' AND deleted = 0'
1564 );
1565 return $this->generateReferenceToolTip($referenceCount, '\'' . $tableName . '\', \'' . $uid . '\'');
1566 }
1567
1568 /**
1569 * Creates the localization panel
1570 *
1571 * @param string $table The table
1572 * @param mixed[] $row The record for which to make the localization panel.
1573 * @return string[] Array with key 0/1 with content for column 1 and 2
1574 */
1575 public function makeLocalizationPanel($table, $row) {
1576 $out = array(
1577 0 => '',
1578 1 => ''
1579 );
1580 // Reset translations
1581 $this->translations = array();
1582 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
1583 // Language title and icon:
1584 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
1585 if (is_array($translations)) {
1586 $this->translations = $translations['translations'];
1587 // Traverse page translations and add icon for each language that does NOT yet exist:
1588 $lNew = '';
1589 foreach ($this->pageOverlays as $lUid_OnPage => $lsysRec) {
1590 if (!isset($translations['translations'][$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage)) {
1591 $url = substr($this->listURL(), strlen($this->backPath));
1592 $href = $this->getModule()->doc->issueCommand(
1593 '&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage,
1594 $url . '&justLocalized=' . rawurlencode($table . ':' . $row['uid'] . ':' . $lUid_OnPage)
1595 );
1596 $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title');
1597 if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
1598 $lC = IconUtility::getSpriteIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon']);
1599 } else {
1600 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
1601 }
1602 $lC = '<a href="' . htmlspecialchars($href) . '" title="'
1603 . htmlspecialchars($language['title']) . '">' . $lC . '</a> ';
1604 $lNew .= $lC;
1605 }
1606 }
1607 if ($lNew) {
1608 $out[1] .= $lNew;
1609 }
1610 } elseif ($row['l18n_parent']) {
1611 $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $out[0];
1612 }
1613 return $out;
1614 }
1615
1616 /**
1617 * Create the selector box for selecting fields to display from a table:
1618 *
1619 * @param string $table Table name
1620 * @param bool $formFields If TRUE, form-fields will be wrapped around the table.
1621 * @return string HTML table with the selector box (name: displayFields['.$table.'][])
1622 */
1623 public function fieldSelectBox($table, $formFields = TRUE) {
1624 $lang = $this->getLanguageService();
1625 // Init:
1626 $formElements = array('', '');
1627 if ($formFields) {
1628 $formElements = array('<form action="' . htmlspecialchars($this->listURL()) . '" method="post">', '</form>');
1629 }
1630 // Load already selected fields, if any:
1631 $setFields = is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
1632 // Request fields from table:
1633 $fields = $this->makeFieldList($table, FALSE, TRUE);
1634 // Add pseudo "control" fields
1635 $fields[] = '_PATH_';
1636 $fields[] = '_REF_';
1637 $fields[] = '_LOCALIZATION_';
1638 $fields[] = '_CONTROL_';
1639 $fields[] = '_CLIPBOARD_';
1640 // Create an option for each field:
1641 $opt = array();
1642 $opt[] = '<option value=""></option>';
1643 foreach ($fields as $fN) {
1644 // Field label
1645 $fL = is_array($GLOBALS['TCA'][$table]['columns'][$fN])
1646 ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fN]['label']), ':')
1647 : '[' . $fN . ']';
1648 $opt[] = '<option value="' . $fN . '"' . (in_array($fN, $setFields) ? ' selected="selected"' : '') . '>'
1649 . htmlspecialchars($fL) . '</option>';
1650 }
1651 // Compile the options into a multiple selector box:
1652 $lMenu = '<select size="' . MathUtility::forceIntegerInRange(count($fields) + 1, 3, 20)
1653 . '" multiple="multiple" name="displayFields[' . $table . '][]">' . implode('', $opt) . '</select>';
1654 // Table with the field selector::
1655 $content = $formElements[0] . '
1656 <!--
1657 Field selector for extended table view:
1658 -->
1659 <table border="0" cellpadding="0" cellspacing="0" id="typo3-dblist-fieldSelect">
1660 <tr>
1661 <td>
1662 ' . $lMenu . '
1663 </td>
1664 <td>
1665 <input class="btn btn-default" type="submit" name="search" value="'
1666 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.setFields', TRUE) . '" />
1667 </td>
1668 </tr>
1669 </table>
1670 ' . $formElements[1];
1671 return '<div class="db_list-fieldSelect">' . $content . '</div>';
1672 }
1673
1674 /*********************************
1675 *
1676 * Helper functions
1677 *
1678 *********************************/
1679 /**
1680 * Creates a link around $string. The link contains an onclick action
1681 * which submits the script with some clipboard action.
1682 * Currently, this is used for setting elements / delete elements.
1683 *
1684 * @param string $string The HTML content to link (image/text)
1685 * @param string $table Table name
1686 * @param string $cmd Clipboard command (eg. "setCB" or "delete")
1687 * @param string $warning Warning text, if any ("delete" uses this for confirmation)
1688 * @return string <a> tag wrapped link.
1689 */
1690 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
1691 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.cmd_table.value=\''
1692 . $table . '\';document.dblistForm.submit();';
1693 if ($warning) {
1694 $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
1695 }
1696 return '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(($onClickEvent . 'return false;')) . '">' . $string . '</a>';
1697 }
1698
1699 /**
1700 * Returns TRUE if a numeric clipboard pad is selected/active
1701 *
1702 * @return bool
1703 */
1704 public function clipNumPane() {
1705 return in_Array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current != 'normal';
1706 }
1707
1708 /**
1709 * Creates a sort-by link on the input string ($code).
1710 * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
1711 * Also some fields will not be possible to sort (including if single-table-view is disabled).
1712 *
1713 * @param string $code The string to link (text)
1714 * @param string $field The fieldname represented by the title ($code)
1715 * @param string $table Table name
1716 * @return string Linked $code variable
1717 */
1718 public function addSortLink($code, $field, $table) {
1719 // Certain circumstances just return string right away (no links):
1720 if ($field == '_CONTROL_' || $field == '_LOCALIZATION_' || $field == '_CLIPBOARD_' || $field == '_REF_' || $this->disableSingleTableView) {
1721 return $code;
1722 }
1723 // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
1724 if ($field == '_PATH_') {
1725 $field = 'pid';
1726 }
1727 // Create the sort link:
1728 $sortUrl = $this->listURL('', -1, 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table
1729 . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || $this->sortField != $field ? 0 : 1);
1730 $sortArrow = $this->sortField === $field
1731 ? IconUtility::getSpriteIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc'))
1732 : '';
1733 // Return linked field:
1734 return '<a href="' . htmlspecialchars($sortUrl) . '">' . $code . $sortArrow . '</a>';
1735 }
1736
1737 /**
1738 * Returns the path for a certain pid
1739 * The result is cached internally for the session, thus you can call
1740 * this function as much as you like without performance problems.
1741 *
1742 * @param int $pid The page id for which to get the path
1743 * @return mixed[] The path.
1744 */
1745 public function recPath($pid) {
1746 if (!isset($this->recPath_cache[$pid])) {
1747 $this->recPath_cache[$pid] = BackendUtility::getRecordPath($pid, $this->perms_clause, 20);
1748 }
1749 return $this->recPath_cache[$pid];
1750 }
1751
1752 /**
1753 * Returns TRUE if a link for creating new records should be displayed for $table
1754 *
1755 * @param string $table Table name
1756 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
1757 * @see \TYPO3\CMS\Backend\Controller\NewRecordController::showNewRecLink
1758 */
1759 public function showNewRecLink($table) {
1760 // No deny/allow tables are set:
1761 if (empty($this->allowedNewTables) && empty($this->deniedNewTables)) {
1762 return TRUE;
1763 }
1764 return !in_array($table, $this->deniedNewTables)
1765 && (empty($this->allowedNewTables) || in_array($table, $this->allowedNewTables));
1766 }
1767
1768 /**
1769 * Creates the "&returnUrl" parameter for links - this is used when the script links
1770 * to other scripts and passes its own URL with the link so other scripts can return to the listing again.
1771 * Uses REQUEST_URI as value.
1772 *
1773 * @return string
1774 */
1775 public function makeReturnUrl() {
1776 return '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1777 }
1778
1779 /************************************
1780 *
1781 * CSV related functions
1782 *
1783 ************************************/
1784 /**
1785 * Initializes internal csvLines array with the header of field names
1786 *
1787 * @return void
1788 */
1789 protected function initCSV() {
1790 $this->addHeaderRowToCSV();
1791 }
1792
1793 /**
1794 * Add header line with field names as CSV line
1795 *
1796 * @return void
1797 */
1798 protected function addHeaderRowToCSV() {
1799 // Add header row, control fields will be reduced inside addToCSV()
1800 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
1801 }
1802
1803 /**
1804 * Adds selected columns of one table row as CSV line.
1805 *
1806 * @param mixed[] $row Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
1807 * @return void
1808 */
1809 protected function addToCSV(array $row = array()) {
1810 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
1811 $rowReducedToSelectedColumns = array_intersect_key($rowReducedByControlFields, array_flip($this->fieldArray));
1812 $this->setCsvRow($rowReducedToSelectedColumns);
1813 }
1814
1815 /**
1816 * Remove control fields from row for CSV export
1817 *
1818 * @param mixed[] $row fieldNames => fieldValues
1819 * @return mixed[] Input array reduces by control fields
1820 */
1821 static protected function removeControlFieldsFromFieldRow(array $row = array()) {
1822 // Possible control fields in a list row
1823 $controlFields = array(
1824 '_PATH_',
1825 '_REF_',
1826 '_CONTROL_',
1827 '_CLIPBOARD_',
1828 '_LOCALIZATION_',
1829 '_LOCALIZATION_b'
1830 );
1831 return array_diff_key($row, array_flip($controlFields));
1832 }
1833
1834 /**
1835 * Adds input row of values to the internal csvLines array as a CSV formatted line
1836 *
1837 * @param mixed[] $csvRow Array with values to be listed.
1838 * @return void
1839 */
1840 public function setCsvRow($csvRow) {
1841 $this->csvLines[] = GeneralUtility::csvValues($csvRow);
1842 }
1843
1844 /**
1845 * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
1846 * This function exits!
1847 *
1848 * @param string $prefix Filename prefix:
1849 * @return void EXITS php execution!
1850 */
1851 public function outputCSV($prefix) {
1852 // Setting filename:
1853 $filename = $prefix . '_' . date('dmy-Hi') . '.csv';
1854 // Creating output header:
1855 header('Content-Type: application/octet-stream');
1856 header('Content-Disposition: attachment; filename=' . $filename);
1857 // Cache-Control header is needed here to solve an issue with browser IE and
1858 // versions lower than 9. See for more information: http://support.microsoft.com/kb/323308
1859 header("Cache-Control: ''");
1860 // Printing the content of the CSV lines:
1861 echo implode(CRLF, $this->csvLines);
1862 // Exits:
1863 die;
1864 }
1865
1866 /**
1867 * add action into correct section
1868 *
1869 * @param array $cells
1870 * @param string $action
1871 * @param string $actionKey
1872 */
1873 public function addActionToCellGroup(&$cells, $action, $actionKey) {
1874 $cellsMap = array(
1875 'primary' => array(
1876 'view', 'edit', 'hide', 'delete', 'stat'
1877 ),
1878 'secondary' => array(
1879 'viewBig', 'history', 'perms', 'new', 'move', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'version'
1880 )
1881 );
1882 $classification = in_array($actionKey, $cellsMap['primary']) ? 'primary' : 'secondary';
1883 $cells[$classification][$actionKey] = $action;
1884 unset($cells[$actionKey]);
1885 }
1886
1887 /**
1888 * Check if the record represents the current backend user
1889 *
1890 * @param string $table
1891 * @param array $row
1892 * @return bool
1893 */
1894 protected function isRecordCurrentBackendUser($table, $row) {
1895 return $table === 'be_users' && (int)$row['uid'] === $this->getBackendUserAuthentication()->user['uid'];
1896 }
1897
1898 /**
1899 * @return DatabaseConnection
1900 */
1901 protected function getDatabaseConnection() {
1902 return $GLOBALS['TYPO3_DB'];
1903 }
1904
1905 /**
1906 * @return BaseScriptClass
1907 */
1908 protected function getModule() {
1909 return $GLOBALS['SOBE'];
1910 }
1911
1912 /**
1913 * @return DocumentTemplate
1914 */
1915 protected function getDocumentTemplate() {
1916 return $GLOBALS['TBE_TEMPLATE'];
1917 }
1918
1919 }