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