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