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