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