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