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