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