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