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