[!!!][FEATURE] ElementBrowser refactoring, LinkBrowser API - Part 1
[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);
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 // we need to build this uri differently, otherwise GeneralUtility::quoteJSvalue messes up the edit list function
1013 $onClick = BackendUtility::editOnClick('', '', -1);
1014 $onClickArray = explode('?', $onClick, 2);
1015 $lastElement = array_pop($onClickArray);
1016 array_push($onClickArray, $params . '&' . $lastElement);
1017 $onClick = implode('?', $onClickArray);
1018 $icon .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick)
1019 . '" title="' . $lang->getLL('editShownColumns', TRUE) . '">'
1020 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1021 $icon = '<div class="btn-group" role="group">' . $icon . '</div>';
1022 }
1023 // Add an empty entry, so column count fits again after moving this into $icon
1024 $theData[$fCol] = '&nbsp;';
1025 }
1026 break;
1027 default:
1028 // Regular fields header:
1029 $theData[$fCol] = '';
1030
1031 // Check if $fCol is really a field and get the label and remove the colons
1032 // at the end
1033 $sortLabel = BackendUtility::getItemLabel($table, $fCol);
1034 if ($sortLabel !== NULL) {
1035 $sortLabel = $lang->sL($sortLabel, TRUE);
1036 $sortLabel = rtrim(trim($sortLabel), ':');
1037 } else {
1038 // No TCA field, only output the $fCol variable with square brackets []
1039 $sortLabel = htmlspecialchars($fCol);
1040 $sortLabel = '<i>[' . rtrim(trim($sortLabel), ':') . ']</i>';
1041 }
1042
1043 if ($this->table && is_array($currentIdList)) {
1044 // If the numeric clipboard pads are selected, show duplicate sorting link:
1045 if ($this->clipNumPane()) {
1046 $theData[$fCol] .= '<a class="btn btn-default" href="' . htmlspecialchars($this->listURL('', -1) . '&duplicateField=' . $fCol)
1047 . '" title="' . $lang->getLL('clip_duplicates', TRUE) . '">'
1048 . $this->iconFactory->getIcon('actions-document-duplicates-select', Icon::SIZE_SMALL)->render() . '</a>';
1049 }
1050 // If the table can be edited, add link for editing THIS field for all
1051 // listed records:
1052 if ($this->isEditable($table) && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
1053 $editIdList = implode(',', $currentIdList);
1054 if ($this->clipNumPane()) {
1055 $editIdList = '\'+editList(\'' . $table . '\',\'' . $editIdList . '\')+\'';
1056 }
1057 $params = 'edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . $fCol;
1058 // we need to build this uri differently, otherwise GeneralUtility::quoteJSvalue messes up the edit list function
1059 $onClick = BackendUtility::editOnClick('', '', -1);
1060 $onClickArray = explode('?', $onClick, 2);
1061 $lastElement = array_pop($onClickArray);
1062 array_push($onClickArray, $params . '&' . $lastElement);
1063 $onClick = implode('?', $onClickArray);
1064 $iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
1065 $theData[$fCol] .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick)
1066 . '" title="' . htmlspecialchars($iTitle) . '">'
1067 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1068 }
1069 if(strlen($theData[$fCol]) > 0){
1070 $theData[$fCol] = '<div class="btn-group" role="group">' . $theData[$fCol] . '</div> ';
1071 }
1072 }
1073 $theData[$fCol] .= $this->addSortLink($sortLabel, $fCol, $table);
1074 }
1075 }
1076 /**
1077 * @hook renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
1078 * @usage Above each listed table in Web>List a header row is shown.
1079 * Containing the labels of all shown fields and additional icons to create new records for this
1080 * table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
1081 */
1082 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1083 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1084 $hookObject = GeneralUtility::getUserObj($classData);
1085 if (!$hookObject instanceof RecordListHookInterface) {
1086 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567855);
1087 }
1088 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
1089 }
1090 }
1091
1092
1093 // Create and return header table row:
1094 return '<thead>' . $this->addelement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
1095 }
1096
1097 /**
1098 * Get pointer for first element on the page
1099 *
1100 * @param int $page Page number starting with 1
1101 * @return int Pointer to first element on the page (starting with 0)
1102 */
1103 protected function getPointerForPage($page) {
1104 return ($page - 1) * $this->iLimit;
1105 }
1106
1107 /**
1108 * Creates a page browser for tables with many records
1109 *
1110 * @param string $renderPart Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
1111 * @return string Navigation HTML
1112 */
1113 protected function renderListNavigation($renderPart = 'top') {
1114 $totalPages = ceil($this->totalItems / $this->iLimit);
1115 // Show page selector if not all records fit into one page
1116 if ($totalPages <= 1) {
1117 return '';
1118 }
1119 $content = '';
1120 $listURL = $this->listURL('', $this->table);
1121 // 1 = first page
1122 // 0 = first element
1123 $currentPage = floor($this->firstElementNumber / $this->iLimit) + 1;
1124 // Compile first, previous, next, last and refresh buttons
1125 if ($currentPage > 1) {
1126 $labelFirst = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:first', TRUE);
1127 $labelPrevious = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:previous', TRUE);
1128 $first = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage(1) . '" title="' . $labelFirst . '">'
1129 . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</a></li>';
1130 $previous = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage - 1) . '" title="' . $labelPrevious . '">'
1131 . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</a></li>';
1132 } else {
1133 $first = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</span></li>';
1134 $previous = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</span></li>';
1135 }
1136 if ($currentPage < $totalPages) {
1137 $labelNext = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:next', TRUE);
1138 $labelLast = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:last', TRUE);
1139 $next = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage + 1) . '" title="' . $labelNext . '">'
1140 . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</a></li>';
1141 $last = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($totalPages) . '" title="' . $labelLast . '">'
1142 . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</a></li>';
1143 } else {
1144 $next = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</span></li>';
1145 $last = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</span></li>';
1146 }
1147 $reload = '<li><a href="#" onclick="document.dblistForm.action=\'' . $listURL
1148 . '&pointer=\'+calculatePointer(document.getElementById(\'jumpPage-' . $renderPart
1149 . '\').value); document.dblistForm.submit(); return true;" title="'
1150 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:reload', TRUE) . '">'
1151 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a></li>';
1152 if ($renderPart === 'top') {
1153 // Add js to traverse a page select input to a pointer value
1154 $content = '
1155 <script type="text/javascript">
1156 /*<![CDATA[*/
1157 function calculatePointer(page) {
1158 if (page > ' . $totalPages . ') {
1159 page = ' . $totalPages . ';
1160 }
1161 if (page < 1) {
1162 page = 1;
1163 }
1164 return (page - 1) * ' . $this->iLimit . ';
1165 }
1166 /*]]>*/
1167 </script>
1168 ';
1169 }
1170 $pageNumberInput = '
1171 <input type="text" value="' . $currentPage . '" size="3" class="form-control input-sm paginator-input" id="jumpPage-' . $renderPart . '" name="jumpPage-'
1172 . $renderPart . '" onkeyup="if (event.keyCode == 13) { document.dblistForm.action=\'' . $listURL
1173 . '&pointer=\'+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
1174 ';
1175 $pageIndicatorText = sprintf(
1176 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:pageIndicator'),
1177 $pageNumberInput,
1178 $totalPages
1179 );
1180 $pageIndicator = '<li><span>' . $pageIndicatorText . '</span></li>';
1181 if ($this->totalItems > $this->firstElementNumber + $this->iLimit) {
1182 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
1183 } else {
1184 $lastElementNumber = $this->totalItems;
1185 }
1186 $rangeIndicator = '<li><span>' . sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:rangeIndicator'), ($this->firstElementNumber + 1), $lastElementNumber) . '</span></li>';
1187
1188 $titleColumn = $this->fieldArray[0];
1189 $data = array(
1190 $titleColumn => $content . '
1191 <nav class="pagination-wrap">
1192 <ul class="pagination pagination-block">
1193 ' . $first . '
1194 ' . $previous . '
1195 ' . $rangeIndicator . '
1196 ' . $pageIndicator . '
1197 ' . $next . '
1198 ' . $last . '
1199 ' . $reload . '
1200 </ul>
1201 </nav>
1202 '
1203 );
1204 return $this->addElement(1, '', $data);
1205 }
1206
1207 /*********************************
1208 *
1209 * Rendering of various elements
1210 *
1211 *********************************/
1212
1213 /**
1214 * Creates the control panel for a single record in the listing.
1215 *
1216 * @param string $table The table
1217 * @param mixed[] $row The record for which to make the control panel.
1218 * @throws \UnexpectedValueException
1219 * @return string HTML table with the control panel (unless disabled)
1220 */
1221 public function makeControl($table, $row) {
1222 $module = $this->getModule();
1223 $rowUid = $row['uid'];
1224 if (ExtensionManagementUtility::isLoaded('version') && isset($row['_ORIG_uid'])) {
1225 $rowUid = $row['_ORIG_uid'];
1226 }
1227 $cells = array(
1228 'primary' => array(),
1229 'secondary' => array()
1230 );
1231 // If the listed table is 'pages' we have to request the permission settings for each page:
1232 $localCalcPerms = 0;
1233 if ($table == 'pages') {
1234 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1235 }
1236 $permsEdit = $table === 'pages' && $localCalcPerms & Permission::PAGE_EDIT || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT;
1237 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
1238 // "Show" link (only pages and tt_content elements)
1239 if ($table == 'pages' || $table == 'tt_content') {
1240 $viewAction = '<a class="btn btn-default" href="#" onclick="'
1241 . htmlspecialchars(
1242 BackendUtility::viewOnClick(
1243 ($table === 'tt_content' ? $this->id : $row['uid']),
1244 '',
1245 '',
1246 ($table === 'tt_content' ? '#' . $row['uid'] : '')
1247 )
1248 ) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">'
1249 . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
1250 $this->addActionToCellGroup($cells, $viewAction, 'view');
1251 }
1252 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1253 if ($permsEdit) {
1254 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1255 $iconIdentifier = 'actions-document-open';
1256 $overlayIdentifier = !$this->isEditable($table) ? 'overlay-readonly' : NULL;
1257 $editAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1258 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL, $overlayIdentifier)->render() . '</a>';
1259 } else {
1260 $editAction = $this->spaceIcon;
1261 }
1262 $this->addActionToCellGroup($cells, $editAction, 'edit');
1263 // "Info": (All records)
1264 $onClick = 'top.launchView(\'' . $table . '\', \'' . $row['uid'] . '\'); return false;';
1265 $viewBigAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->getLL('showInfo', TRUE) . '">'
1266 . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
1267 $this->addActionToCellGroup($cells, $viewBigAction, 'viewBig');
1268 // "Move" wizard link for pages/tt_content elements:
1269 if ($permsEdit && ($table === 'tt_content' || $table === 'pages')) {
1270 $onClick = 'return jumpExt(\'' . BackendUtility::getModuleUrl('move_element') . '&table=' . $table . '&uid=' . $row['uid'] . '\');';
1271 $linkTitleLL = $this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page'), TRUE);
1272 $icon = ($table == 'pages' ? $this->iconFactory->getIcon('actions-page-move', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL));
1273 $moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
1274 $this->addActionToCellGroup($cells, $moveAction, 'move');
1275 }
1276 // If the table is NOT a read-only table, then show these links:
1277 if ($this->isEditable($table)) {
1278 // "Revert" link (history/undo)
1279 $moduleUrl = BackendUtility::getModuleUrl('record_history', array('element' => $table . ':' . $row['uid']));
1280 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
1281 $historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1282 . $this->getLanguageService()->getLL('history', TRUE) . '">'
1283 . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
1284 $this->addActionToCellGroup($cells, $historyAction, 'history');
1285 // Versioning:
1286 if (ExtensionManagementUtility::isLoaded('version') && !ExtensionManagementUtility::isLoaded('workspaces')) {
1287 $vers = BackendUtility::selectVersionsOfRecord($table, $row['uid'], 'uid', $this->getBackendUserAuthentication()->workspace, FALSE, $row);
1288 // If table can be versionized.
1289 if (is_array($vers)) {
1290 $href = BackendUtility::getModuleUrl('web_txversionM1', array(
1291 'table' => $table, 'uid' => $row['uid']
1292 ));
1293 $versionAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1294 . $this->getLanguageService()->getLL('displayVersions', TRUE) . '">'
1295 . $this->iconFactory->getIcon('actions-version-open', Icon::SIZE_SMALL)->render() . '</a>';
1296 $this->addActionToCellGroup($cells, $versionAction, 'version');
1297 }
1298 }
1299 // "Edit Perms" link:
1300 if ($table === 'pages' && $this->getBackendUserAuthentication()->check('modules', 'system_BeuserTxPermission') && ExtensionManagementUtility::isLoaded('beuser')) {
1301 $href = BackendUtility::getModuleUrl('system_BeuserTxPermission') . '&id=' . $row['uid'] . '&return_id=' . $row['uid'] . '&edit=1';
1302 $permsAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1303 . $this->getLanguageService()->getLL('permissions', TRUE) . '">'
1304 . $this->iconFactory->getIcon('status-status-locked', Icon::SIZE_SMALL)->render() . '</a>';
1305 $this->addActionToCellGroup($cells, $permsAction, 'perms');
1306 }
1307 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row
1308 // or if default values can depend on previous record):
1309 if (($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) && $permsEdit) {
1310 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT || $table === 'pages' && $this->calcPerms & Permission::PAGE_NEW) {
1311 if ($this->showNewRecLink($table)) {
1312 $params = '&edit[' . $table . '][' . -($row['_MOVE_PLH'] ? $row['_MOVE_PLH_uid'] : $row['uid']) . ']=new';
1313 $icon = ($table == 'pages' ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL));
1314 $newAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1315 . '" title="' . $this->getLanguageService()->getLL('new' . ($table == 'pages ' ? 'Page' : 'Record'), TRUE) . '">'
1316 . $icon->render() . '</a>';
1317 $this->addActionToCellGroup($cells, $newAction, 'new');
1318 }
1319 }
1320 }
1321 // "Up/Down" links
1322 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField && !$this->searchLevels) {
1323 if (isset($this->currentTable['prev'][$row['uid']])) {
1324 // Up
1325 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
1326 $moveUpAction = '<a class="btn btn-default" href="#" onclick="'
1327 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1328 . '" title="' . $this->getLanguageService()->getLL('moveUp', TRUE) . '">'
1329 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1330 } else {
1331 $moveUpAction = $this->spaceIcon;
1332 }
1333 $this->addActionToCellGroup($cells, $moveUpAction, 'moveUp');
1334
1335 if ($this->currentTable['next'][$row['uid']]) {
1336 // Down
1337 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
1338 $moveDownAction = '<a class="btn btn-default" href="#" onclick="'
1339 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1340 . '" title="' . $this->getLanguageService()->getLL('moveDown', TRUE) . '">'
1341 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1342 } else {
1343 $moveDownAction = $this->spaceIcon;
1344 }
1345 $this->addActionToCellGroup($cells, $moveDownAction, 'moveDown');
1346 }
1347 // "Hide/Unhide" links:
1348 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1349
1350 if (
1351 $permsEdit && $hiddenField && $GLOBALS['TCA'][$table]['columns'][$hiddenField]
1352 && (!$GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude']
1353 || $this->getBackendUserAuthentication()->check('non_exclude_fields', $table . ':' . $hiddenField))
1354 ) {
1355 if ($this->isRecordCurrentBackendUser($table, $row)) {
1356 $hideAction = $this->spaceIcon;
1357 } else {
1358 $hideTitle = $this->getLanguageService()->getLL('hide' . ($table == 'pages' ? 'Page' : ''), TRUE);
1359 $unhideTitle = $this->getLanguageService()->getLL('unHide' . ($table == 'pages' ? 'Page' : ''), TRUE);
1360 if ($row[$hiddenField]) {
1361 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
1362 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="hidden" href="#"'
1363 . ' data-params="' . htmlspecialchars($params) . '"'
1364 . ' title="' . $unhideTitle . '"'
1365 . ' data-toggle-title="' . $hideTitle . '">'
1366 . $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '</a>';
1367 } else {
1368 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
1369 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="visible" href="#"'
1370 . ' data-params="' . htmlspecialchars($params) . '"'
1371 . ' title="' . $hideTitle . '"'
1372 . ' data-toggle-title="' . $unhideTitle . '">'
1373 . $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '</a>';
1374 }
1375 }
1376 $this->addActionToCellGroup($cells, $hideAction, 'hide');
1377 }
1378 // "Delete" link:
1379 if ($permsEdit && ($table === 'pages' && $localCalcPerms & Permission::PAGE_DELETE || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT)) {
1380 // Check if the record version is in "deleted" state, because that will switch the action to "restore"
1381 if ($this->getBackendUserAuthentication()->workspace > 0 && isset($row['t3ver_state']) && (int)$row['t3ver_state'] === 2) {
1382 $actionName = 'restore';
1383 $refCountMsg = '';
1384 } else {
1385 $actionName = 'delete';
1386 $refCountMsg = BackendUtility::referenceCount(
1387 $table,
1388 $row['uid'],
1389 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.referencesToRecord'),
1390 $this->getReferenceCount($table, $row['uid'])) . BackendUtility::translationCount($table, $row['uid'],
1391 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')
1392 );
1393 }
1394
1395 if ($this->isRecordCurrentBackendUser($table, $row)) {
1396 $deleteAction = $this->spaceIcon;
1397 } else {
1398 $titleOrig = BackendUtility::getRecordTitle($table, $row, FALSE, TRUE);
1399 $title = GeneralUtility::slashJS(GeneralUtility::fixed_lgd_cs($titleOrig, $this->fixedL), TRUE);
1400 $warningText = $this->getLanguageService()->getLL($actionName . 'Warning') . ' "' . $title . '" ' . '[' . $table . ':' . $row['uid'] . ']' . $refCountMsg;
1401
1402 $params = 'cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
1403 $icon = $this->iconFactory->getIcon('actions-edit-' . $actionName, Icon::SIZE_SMALL)->render();
1404 $linkTitle = $this->getLanguageService()->getLL($actionName, TRUE);
1405 $deleteAction = '<a class="btn btn-default t3js-record-delete" href="#" '
1406 . ' data-l10parent="' . htmlspecialchars($row['l10n_parent']) . '"'
1407 . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($titleOrig) . '"'
1408 . ' data-message="' . htmlspecialchars($warningText) . '" title="' . $linkTitle . '"'
1409 . '>' . $icon . '</a>';
1410 }
1411 } else {
1412 $deleteAction = $this->spaceIcon;
1413 }
1414 $this->addActionToCellGroup($cells, $deleteAction, 'delete');
1415 // "Levels" links: Moving pages into new levels...
1416 if ($permsEdit && $table == 'pages' && !$this->searchLevels) {
1417 // Up (Paste as the page right after the current parent page)
1418 if ($this->calcPerms & Permission::PAGE_NEW) {
1419 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
1420 $moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
1421 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1422 . '" title="' . $this->getLanguageService()->getLL('prevLevel', TRUE) . '">'
1423 . $this->iconFactory->getIcon('actions-move-left', Icon::SIZE_SMALL)->render() . '</a>';
1424 $this->addActionToCellGroup($cells, $moveLeftAction, 'moveLeft');
1425 }
1426 // Down (Paste as subpage to the page right above)
1427 if ($this->currentTable['prevUid'][$row['uid']]) {
1428 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
1429 if ($localCalcPerms & Permission::PAGE_NEW) {
1430 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
1431 $moveRightAction = '<a class="btn btn-default" href="#" onclick="'
1432 . htmlspecialchars('return jumpToUrl(' . $module->doc->issueCommand($params, -1) . ');')
1433 . '" title="' . $this->getLanguageService()->getLL('nextLevel', TRUE) . '">'
1434 . $this->iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render() . '</a>';
1435 } else {
1436 $moveRightAction = $this->spaceIcon;
1437 }
1438 } else {
1439 $moveRightAction = $this->spaceIcon;
1440 }
1441 $this->addActionToCellGroup($cells, $moveRightAction, 'moveRight');
1442 }
1443 }
1444 /**
1445 * @hook recStatInfoHooks: Allows to insert HTML before record icons on various places
1446 */
1447 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1448 $stat = '';
1449 $_params = array($table, $row['uid']);
1450 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1451 $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1452 }
1453 $this->addActionToCellGroup($cells, $stat, 'stat');
1454 }
1455 /**
1456 * @hook makeControl: Allows to change control icons of records in list-module
1457 * @usage This hook method gets passed the current $cells array as third parameter.
1458 * This array contains values for the icons/actions generated for each record in Web>List.
1459 * Each array entry is accessible by an index-key.
1460 * The order of the icons is depending on the order of those array entries.
1461 */
1462 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1463 // for compatibility reason, we move all icons to the rootlevel
1464 // before calling the hooks
1465 foreach ($cells as $section => $actions) {
1466 foreach ($actions as $actionKey => $action) {
1467 $cells[$actionKey] = $action;
1468 }
1469 }
1470 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1471 $hookObject = GeneralUtility::getUserObj($classData);
1472 if (!$hookObject instanceof RecordListHookInterface) {
1473 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567840);
1474 }
1475 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1476 }
1477 // now sort icons again into primary and secondary sections
1478 // after all hooks are processed
1479 $hookCells = $cells;
1480 foreach ($hookCells as $key => $value) {
1481 if ($key === 'primary' || $key === 'secondary') {
1482 continue;
1483 }
1484 $this->addActionToCellGroup($cells, $value, $key);
1485 }
1486 }
1487 $output = '<!-- CONTROL PANEL: ' . $table . ':' . $row['uid'] . ' -->';
1488 foreach($cells as $classification => $actions) {
1489 $visibilityClass = ($classification !== 'primary' && !$module->MOD_SETTINGS['bigControlPanel'] ? 'collapsed' : 'expanded');
1490 if ($visibilityClass === 'collapsed') {
1491 $cellOutput = '';
1492 foreach ($actions as $action) {
1493 $cellOutput .= $action;
1494 }
1495 $output .= ' <div class="btn-group">' .
1496 '<span id="actions_' . $table . '_' . $row['uid'] . '" class="btn-group collapse collapse-horizontal width">' . $cellOutput . '</span>' .
1497 '<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>' .
1498 '</div>';
1499 } else {
1500 $output .= ' <div class="btn-group" role="group">' . implode('', $actions) . '</div>';
1501 }
1502 }
1503 return $output;
1504 }
1505
1506 /**
1507 * Creates the clipboard panel for a single record in the listing.
1508 *
1509 * @param string $table The table
1510 * @param mixed[] $row The record for which to make the clipboard panel.
1511 * @throws \UnexpectedValueException
1512 * @return string HTML table with the clipboard panel (unless disabled)
1513 */
1514 public function makeClip($table, $row) {
1515 // Return blank, if disabled:
1516 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1517 return '';
1518 }
1519 $cells = array();
1520 $cells['pasteAfter'] = ($cells['pasteInto'] = $this->spaceIcon);
1521 //enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
1522 $isL10nOverlay = $this->localizationView && $table != 'pages_language_overlay' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1523 // Return blank, if disabled:
1524 // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1525 // For the "Normal" pad:
1526 if ($this->clipObj->current === 'normal') {
1527 // Show copy/cut icons:
1528 $isSel = (string)$this->clipObj->isSelected($table, $row['uid']);
1529 if ($isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)) {
1530 $cells['copy'] = $this->spaceIcon;
1531 $cells['cut'] = $this->spaceIcon;
1532 } else {
1533 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL);
1534 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL);
1535
1536 if ($isSel === 'copy') {
1537 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL);
1538 } elseif ($isSel === 'cut') {
1539 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL);
1540 }
1541
1542 $cells['copy'] = '<a class="btn btn-default" href="#" onclick="'
1543 . htmlspecialchars('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel === 'copy'), array('returnUrl' => '')) . '\');')
1544 . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.copy', TRUE) . '">'
1545 . $copyIcon->render() . '</a>';
1546 if (TRUE) {
1547 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
1548 . htmlspecialchars('return jumpSelf(\'' . $this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), array('returnUrl' => '')) . '\');')
1549 . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.cut', TRUE) . '">'
1550 . $cutIcon->render() . '</a>';
1551 } else {
1552 $cells['cut'] = $this->spaceIcon;
1553 }
1554 }
1555 } else {
1556 // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1557 // Setting name of the element in ->CBnames array:
1558 $n = $table . '|' . $row['uid'];
1559 $this->CBnames[] = $n;
1560 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1561 $checked = $this->clipObj->isSelected($table, $row['uid']) ? 'checked="checked" ' : '';
1562 // If the "duplicateField" value is set then select all elements which are duplicates...
1563 if ($this->duplicateField && isset($row[$this->duplicateField])) {
1564 $checked = '';
1565 if (in_array($row[$this->duplicateField], $this->duplicateStack)) {
1566 $checked = 'checked="checked" ';
1567 }
1568 $this->duplicateStack[] = $row[$this->duplicateField];
1569 }
1570 // Adding the checkbox to the panel:
1571 $cells['select'] = $isL10nOverlay
1572 ? $this->spaceIcon
1573 : '<input type="hidden" name="CBH[' . $n . ']" value="0" /><label class="btn btn-default btn-checkbox"><input type="checkbox"'
1574 . ' name="CBC[' . $n . ']" value="1" ' . $checked . '/><span class="t3-icon fa"></span></label>';
1575 }
1576 // Now, looking for selected elements from the current table:
1577 $elFromTable = $this->clipObj->elFromTable($table);
1578 if (!empty($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1579 // IF elements are found, they can be individually ordered and are not locked by editlock, then add a "paste after" icon:
1580 $cells['pasteAfter'] = $isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)
1581 ? $this->spaceIcon
1582 : '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '" onclick="'
1583 . htmlspecialchars(('return ' . $this->clipObj->confirmMsg($table, $row, 'after', $elFromTable)))
1584 . '" title="' . $this->getLanguageService()->getLL('clip_pasteAfter', TRUE) . '">'
1585 . $this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)->render() . '</a>';
1586 }
1587 // Now, looking for elements in general:
1588 $elFromTable = $this->clipObj->elFromTable('');
1589 if ($table == 'pages' && !empty($elFromTable)) {
1590 $cells['pasteInto'] = '<a class="btn btn-default" href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid']))
1591 . '" onclick="' . htmlspecialchars('return ' . $this->clipObj->confirmMsg($table, $row, 'into', $elFromTable))
1592 . '" title="' . $this->getLanguageService()->getLL('clip_pasteInto', TRUE) . '">'
1593 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
1594 }
1595 /**
1596 * @hook makeClip: Allows to change clip-icons of records in list-module
1597 * @usage This hook method gets passed the current $cells array as third parameter.
1598 * This array contains values for the clipboard icons generated for each record in Web>List.
1599 * Each array entry is accessible by an index-key.
1600 * The order of the icons is depending on the order of those array entries.
1601 */
1602 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1603 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1604 $hookObject = GeneralUtility::getUserObj($classData);
1605 if (!$hookObject instanceof RecordListHookInterface) {
1606 throw new \UnexpectedValueException('$hookObject must implement interface ' . RecordListHookInterface::class, 1195567845);
1607 }
1608 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1609 }
1610 }
1611 // Compile items into a DIV-element:
1612 return '<!-- CLIPBOARD PANEL: ' . $table . ':' . $row['uid'] . ' -->
1613 <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1614 }
1615
1616 /**
1617 * Creates the HTML for a reference count for the record with the UID $uid
1618 * in the table $tableName.
1619 *
1620 * @param string $tableName
1621 * @param int $uid
1622 * @return string HTML of reference a link, will be empty if there are no
1623 */
1624 protected function createReferenceHtml($tableName, $uid) {
1625 $db = $this->getDatabaseConnection();
1626 $referenceCount = $db->exec_SELECTcountRows(
1627 '*',
1628 'sys_refindex',
1629 'ref_table = ' . $db->fullQuoteStr($tableName, 'sys_refindex') .
1630 ' AND ref_uid = ' . $uid . ' AND deleted = 0'
1631 );
1632 return $this->generateReferenceToolTip($referenceCount, '\'' . $tableName . '\', \'' . $uid . '\'');
1633 }
1634
1635 /**
1636 * Creates the localization panel
1637 *
1638 * @param string $table The table
1639 * @param mixed[] $row The record for which to make the localization panel.
1640 * @return string[] Array with key 0/1 with content for column 1 and 2
1641 */
1642 public function makeLocalizationPanel($table, $row) {
1643 $out = array(
1644 0 => '',
1645 1 => ''
1646 );
1647 // Reset translations
1648 $this->translations = array();
1649
1650 // Language title and icon:
1651 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
1652
1653 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
1654 if (is_array($translations)) {
1655 $this->translations = $translations['translations'];
1656 // Traverse page translations and add icon for each language that does NOT yet exist:
1657 $lNew = '';
1658 foreach ($this->pageOverlays as $lUid_OnPage => $lsysRec) {
1659 if ($this->isEditable($table) && !isset($translations['translations'][$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage)) {
1660 $url = $this->listURL();
1661 $href = $this->getModule()->doc->issueCommand(
1662 '&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage,
1663 $url . '&justLocalized=' . rawurlencode($table . ':' . $row['uid'] . ':' . $lUid_OnPage)
1664 );
1665 $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title');
1666 if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
1667 $lC = $this->iconFactory->getIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon'], Icon::SIZE_SMALL)->render();
1668 } else {
1669 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
1670 }
1671 $lC = '<a href="' . htmlspecialchars($href) . '" title="'
1672 . htmlspecialchars($language['title']) . '">' . $lC . '</a> ';
1673 $lNew .= $lC;
1674 }
1675 }
1676 if ($lNew) {
1677 $out[1] .= $lNew;
1678 }
1679 } elseif ($row['l18n_parent']) {
1680 $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $out[0];
1681 }
1682 return $out;
1683 }
1684
1685 /**
1686 * Creates a checkbox list for selecting fields to display from a table:
1687 *
1688 * @param string $table Table name
1689 * @param bool $formFields If TRUE, form-fields will be wrapped around the table.
1690 * @return string HTML table with the selector check box (name: displayFields['.$table.'][])
1691 */
1692 public function fieldSelectBox($table, $formFields = TRUE) {
1693 $lang = $this->getLanguageService();
1694 // Init:
1695 $formElements = array('', '');
1696 if ($formFields) {
1697 $formElements = array('<form action="' . htmlspecialchars($this->listURL()) . '" method="post" name="fieldSelectBox">', '</form>');
1698 }
1699 // Load already selected fields, if any:
1700 $setFields = is_array($this->setFields[$table]) ? $this->setFields[$table] : array();
1701 // Request fields from table:
1702 $fields = $this->makeFieldList($table, FALSE, TRUE);
1703 // Add pseudo "control" fields
1704 $fields[] = '_PATH_';
1705 $fields[] = '_REF_';
1706 $fields[] = '_LOCALIZATION_';
1707 $fields[] = '_CONTROL_';
1708 $fields[] = '_CLIPBOARD_';
1709 // Create a checkbox for each field:
1710 $checkboxes = array();
1711 $checkAllChecked = TRUE;
1712 foreach ($fields as $fieldName) {
1713 // Determine, if checkbox should be checked
1714 if (in_array($fieldName, $setFields, TRUE) || $fieldName === $this->fieldArray[0]) {
1715 $checked = ' checked="checked"';
1716 } else {
1717 $checkAllChecked = FALSE;
1718 $checked = '';
1719 }
1720 // Field label
1721 $fieldLabel = is_array($GLOBALS['TCA'][$table]['columns'][$fieldName])
1722 ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']), ':')
1723 : '';
1724 $checkboxes[] = '<tr><td class="col-checkbox"><input type="checkbox" id="check-' . $fieldName . '" name="displayFields['
1725 . $table . '][]" value="' . $fieldName . '"' . $checked
1726 . ($fieldName === $this->fieldArray[0] ? ' disabled="disabled"' : '') . '></td><td class="col-title">'
1727 . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($fieldLabel) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
1728 }
1729 // Table with the field selector::
1730 $content = $formElements[0] . '
1731 <input type="hidden" name="displayFields[' . $table . '][]" value="">
1732 <div class="table-fit table-scrollable">
1733 <table border="0" cellpadding="0" cellspacing="0" class="table table-transparent table-hover">
1734 <thead>
1735 <tr>
1736 <th class="col-checkbox" colspan="2">
1737 <input type="checkbox" class="checkbox checkAll" ' . ($checkAllChecked ? ' checked="checked"' : '') .'>
1738 </th>
1739 </tr>
1740 </thead>
1741 <tbody>
1742 ' . implode('', $checkboxes) . '
1743 </tbody>
1744 </table>
1745 </div>
1746 <input type="submit" name="search" class="btn btn-default" value="'
1747 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.setFields', TRUE) . '"/>
1748 ' . $formElements[1];
1749 return '<div class="fieldSelectBox">' . $content . '</div>';
1750 }
1751
1752 /*********************************
1753 *
1754 * Helper functions
1755 *
1756 *********************************/
1757 /**
1758 * Creates a link around $string. The link contains an onclick action
1759 * which submits the script with some clipboard action.
1760 * Currently, this is used for setting elements / delete elements.
1761 *
1762 * @param string $string The HTML content to link (image/text)
1763 * @param string $table Table name
1764 * @param string $cmd Clipboard command (eg. "setCB" or "delete")
1765 * @param string $warning Warning text, if any ("delete" uses this for confirmation)
1766 * @return string <a> tag wrapped link.
1767 */
1768 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
1769 $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.cmd_table.value=\''
1770 . $table . '\';document.dblistForm.submit();';
1771 if ($warning) {
1772 $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
1773 }
1774 return '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(($onClickEvent . 'return false;')) . '">' . $string . '</a>';
1775 }
1776
1777 /**
1778 * Returns TRUE if a numeric clipboard pad is selected/active
1779 *
1780 * @return bool
1781 */
1782 public function clipNumPane() {
1783 return in_Array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current != 'normal';
1784 }
1785
1786 /**
1787 * Creates a sort-by link on the input string ($code).
1788 * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
1789 * Also some fields will not be possible to sort (including if single-table-view is disabled).
1790 *
1791 * @param string $code The string to link (text)
1792 * @param string $field The fieldname represented by the title ($code)
1793 * @param string $table Table name
1794 * @return string Linked $code variable
1795 */
1796 public function addSortLink($code, $field, $table) {
1797 // Certain circumstances just return string right away (no links):
1798 if ($field == '_CONTROL_' || $field == '_LOCALIZATION_' || $field == '_CLIPBOARD_' || $field == '_REF_' || $this->disableSingleTableView) {
1799 return $code;
1800 }
1801 // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
1802 if ($field == '_PATH_') {
1803 $field = 'pid';
1804 }
1805 // Create the sort link:
1806 $sortUrl = $this->listURL('', -1, 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table
1807 . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || $this->sortField != $field ? 0 : 1);
1808 $sortArrow = $this->sortField === $field
1809 ? $this->iconFactory->getIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render()
1810 : '';
1811 // Return linked field:
1812 return '<a href="' . htmlspecialchars($sortUrl) . '">' . $code . $sortArrow . '</a>';
1813 }
1814
1815 /**
1816 * Returns the path for a certain pid
1817 * The result is cached internally for the session, thus you can call
1818 * this function as much as you like without performance problems.
1819 *
1820 * @param int $pid The page id for which to get the path
1821 * @return mixed[] The path.
1822 */
1823 public function recPath($pid) {
1824 if (!isset($this->recPath_cache[$pid])) {
1825 $this->recPath_cache[$pid] = BackendUtility::getRecordPath($pid, $this->perms_clause, 20);
1826 }
1827 return $this->recPath_cache[$pid];
1828 }
1829
1830 /**
1831 * Returns TRUE if a link for creating new records should be displayed for $table
1832 *
1833 * @param string $table Table name
1834 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
1835 * @see \TYPO3\CMS\Backend\Controller\NewRecordController::showNewRecLink
1836 */
1837 public function showNewRecLink($table) {
1838 // No deny/allow tables are set:
1839 if (empty($this->allowedNewTables) && empty($this->deniedNewTables)) {
1840 return TRUE;
1841 }
1842 return !in_array($table, $this->deniedNewTables)
1843 && (empty($this->allowedNewTables) || in_array($table, $this->allowedNewTables));
1844 }
1845
1846 /**
1847 * Creates the "&returnUrl" parameter for links - this is used when the script links
1848 * to other scripts and passes its own URL with the link so other scripts can return to the listing again.
1849 * Uses REQUEST_URI as value.
1850 *
1851 * @return string
1852 */
1853 public function makeReturnUrl() {
1854 return '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
1855 }
1856
1857 /************************************
1858 *
1859 * CSV related functions
1860 *
1861 ************************************/
1862 /**
1863 * Initializes internal csvLines array with the header of field names
1864 *
1865 * @return void
1866 */
1867 protected function initCSV() {
1868 $this->addHeaderRowToCSV();
1869 }
1870
1871 /**
1872 * Add header line with field names as CSV line
1873 *
1874 * @return void
1875 */
1876 protected function addHeaderRowToCSV() {
1877 // Add header row, control fields will be reduced inside addToCSV()
1878 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
1879 }
1880
1881 /**
1882 * Adds selected columns of one table row as CSV line.
1883 *
1884 * @param mixed[] $row Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
1885 * @return void
1886 */
1887 protected function addToCSV(array $row = array()) {
1888 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
1889 $rowReducedToSelectedColumns = array_intersect_key($rowReducedByControlFields, array_flip($this->fieldArray));
1890 $this->setCsvRow($rowReducedToSelectedColumns);
1891 }
1892
1893 /**
1894 * Remove control fields from row for CSV export
1895 *
1896 * @param mixed[] $row fieldNames => fieldValues
1897 * @return mixed[] Input array reduces by control fields
1898 */
1899 static protected function removeControlFieldsFromFieldRow(array $row = array()) {
1900 // Possible control fields in a list row
1901 $controlFields = array(
1902 '_PATH_',
1903 '_REF_',
1904 '_CONTROL_',
1905 '_CLIPBOARD_',
1906 '_LOCALIZATION_',
1907 '_LOCALIZATION_b'
1908 );
1909 return array_diff_key($row, array_flip($controlFields));
1910 }
1911
1912 /**
1913 * Adds input row of values to the internal csvLines array as a CSV formatted line
1914 *
1915 * @param mixed[] $csvRow Array with values to be listed.
1916 * @return void
1917 */
1918 public function setCsvRow($csvRow) {
1919 $this->csvLines[] = GeneralUtility::csvValues($csvRow);
1920 }
1921
1922 /**
1923 * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
1924 * This function exits!
1925 *
1926 * @param string $prefix Filename prefix:
1927 * @return void EXITS php execution!
1928 */
1929 public function outputCSV($prefix) {
1930 // Setting filename:
1931 $filename = $prefix . '_' . date('dmy-Hi') . '.csv';
1932 // Creating output header:
1933 header('Content-Type: application/octet-stream');
1934 header('Content-Disposition: attachment; filename=' . $filename);
1935 // Cache-Control header is needed here to solve an issue with browser IE and
1936 // versions lower than 9. See for more information: http://support.microsoft.com/kb/323308
1937 header("Cache-Control: ''");
1938 // Printing the content of the CSV lines:
1939 echo implode(CRLF, $this->csvLines);
1940 // Exits:
1941 die;
1942 }
1943
1944 /**
1945 * add action into correct section
1946 *
1947 * @param array $cells
1948 * @param string $action
1949 * @param string $actionKey
1950 */
1951 public function addActionToCellGroup(&$cells, $action, $actionKey) {
1952 $cellsMap = array(
1953 'primary' => array(
1954 'view', 'edit', 'hide', 'delete', 'stat'
1955 ),
1956 'secondary' => array(
1957 'viewBig', 'history', 'perms', 'new', 'move', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'version'
1958 )
1959 );
1960 $classification = in_array($actionKey, $cellsMap['primary']) ? 'primary' : 'secondary';
1961 $cells[$classification][$actionKey] = $action;
1962 unset($cells[$actionKey]);
1963 }
1964
1965 /**
1966 * Check if the record represents the current backend user
1967 *
1968 * @param string $table
1969 * @param array $row
1970 * @return bool
1971 */
1972 protected function isRecordCurrentBackendUser($table, $row) {
1973 return $table === 'be_users' && (int)$row['uid'] === $this->getBackendUserAuthentication()->user['uid'];
1974 }
1975
1976 /**
1977 * @param bool $isEditable
1978 */
1979 public function setIsEditable($isEditable) {
1980 $this->editable = $isEditable;
1981 }
1982
1983 /**
1984 * Check if the table is readonly or editable
1985 * @param string $table
1986 * @return bool
1987 */
1988 public function isEditable($table) {
1989 return $GLOBALS['TCA'][$table]['ctrl']['readOnly'] || $this->editable;
1990 }
1991
1992 /**
1993 * Check if the current record is locked by editlock. Pages are locked if their editlock flag is set,
1994 * records are if they are locked themselves or if the page they are on is locked (a page’s editlock
1995 * is transitive for its content elements).
1996 *
1997 * @param string $table
1998 * @param array $row
1999 * @param bool $editPermission
2000 * @return bool
2001 */
2002 protected function overlayEditLockPermissions($table, $row = array(), $editPermission = TRUE) {
2003 if ($editPermission && !$this->getBackendUserAuthentication()->isAdmin()) {
2004 // If no $row is submitted we only check for general edit lock of current page (except for table "pages")
2005 if (empty($row)) {
2006 return $table === 'pages' ? TRUE : !$this->pageRow['editlock'];
2007 }
2008 if (($table === 'pages' && $row['editlock']) || ($table !== 'pages' && $this->pageRow['editlock'])) {
2009 $editPermission = FALSE;
2010 } elseif (isset($GLOBALS['TCA'][$table]['ctrl']['editlock']) && $row[$GLOBALS['TCA'][$table]['ctrl']['editlock']]) {
2011 $editPermission = FALSE;
2012 }
2013 }
2014 return $editPermission;
2015 }
2016
2017 /**
2018 * Check whether or not the current backend user is an admin or the current page is
2019 * locked by editlock.
2020 *
2021 * @return bool
2022 */
2023 protected function editLockPermissions() {
2024 return $this->getBackendUserAuthentication()->isAdmin() || !$this->pageRow['editlock'];
2025 }
2026
2027 /**
2028 * @return DatabaseConnection
2029 */
2030 protected function getDatabaseConnection() {
2031 return $GLOBALS['TYPO3_DB'];
2032 }
2033
2034 /**
2035 * @return BaseScriptClass
2036 */
2037 protected function getModule() {
2038 return $GLOBALS['SOBE'];
2039 }
2040
2041 /**
2042 * @return DocumentTemplate
2043 */
2044 protected function getDocumentTemplate() {
2045 return $GLOBALS['TBE_TEMPLATE'];
2046 }
2047
2048 }