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