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