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