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