2 namespace TYPO3\CMS\Recordlist
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Clipboard\Clipboard
;
18 use TYPO3\CMS\Backend\Template\DocumentTemplate
;
19 use TYPO3\CMS\Backend\Utility\BackendUtility
;
20 use TYPO3\CMS\Backend\Utility\IconUtility
;
21 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
22 use TYPO3\CMS\Core\DataHandling\DataHandler
;
23 use TYPO3\CMS\Core\Messaging\FlashMessage
;
24 use TYPO3\CMS\Core\Page\PageRenderer
;
25 use TYPO3\CMS\Core\Type\Bitmask\Permission
;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
27 use TYPO3\CMS\Core\Utility\GeneralUtility
;
28 use TYPO3\CMS\Core\Utility\MathUtility
;
29 use TYPO3\CMS\Extbase\Service\TypoScriptService
;
30 use TYPO3\CMS\Lang\LanguageService
;
33 * Script Class for the Web > List module; rendering the listing of records on a page
38 * Page Id for which to make the listing
45 * Pointer - for browsing list of records.
59 * Which table to make extended listing for
77 public $search_levels;
94 * Clear-cache flag - if set, clears page cache for current id.
101 * Command: Eg. "delete" or "setCB" (for TCEmain / clipboard operations)
108 * Table on which the cmd-action is performed.
115 * Page select perms clause
119 public $perms_clause;
129 * Current ids page record
136 * Document template object
138 * @var DocumentTemplate
143 * Module configuration
146 * @deprecated since TYPO3 CMS 7, will be removed in CMS 8.
148 public $MCONF = array();
155 public $MOD_MENU = array();
158 * Module settings (session variable)
162 public $MOD_SETTINGS = array();
165 * Module output accumulation
172 * The name of the module
176 protected $moduleName = 'web_list';
186 protected $pageRenderer = NULL
;
191 public function __construct() {
192 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_list.xlf');
196 * Initializing the module
200 public function init() {
201 $backendUser = $this->getBackendUserAuthentication();
202 $this->perms_clause
= $backendUser->getPagePermsClause(1);
204 $sessionData = $backendUser->getSessionData(__CLASS__
);
205 $this->search_field
= !empty($sessionData['search_field']) ?
$sessionData['search_field'] : '';
207 $this->id
= (int)GeneralUtility
::_GP('id');
208 $this->pointer
= GeneralUtility
::_GP('pointer');
209 $this->imagemode
= GeneralUtility
::_GP('imagemode');
210 $this->table
= GeneralUtility
::_GP('table');
211 $this->search_field
= GeneralUtility
::_GP('search_field');
212 $this->search_levels
= (int)GeneralUtility
::_GP('search_levels');
213 $this->showLimit
= GeneralUtility
::_GP('showLimit');
214 $this->returnUrl
= GeneralUtility
::sanitizeLocalUrl(GeneralUtility
::_GP('returnUrl'));
215 $this->clear_cache
= GeneralUtility
::_GP('clear_cache');
216 $this->cmd
= GeneralUtility
::_GP('cmd');
217 $this->cmd_table
= GeneralUtility
::_GP('cmd_table');
218 $sessionData['search_field'] = $this->search_field
;
221 // Store session data
222 $backendUser->setAndSaveSessionData(RecordList
::class, $sessionData);
223 $this->getPageRenderer()->addInlineLanguageLabelFile('EXT:lang/locallang_mod_web_list.xlf');
227 * Initialize function menu array
231 public function menuConfig() {
233 $this->MOD_MENU
= array(
234 'bigControlPanel' => '',
238 // Loading module configuration:
239 $this->modTSconfig
= BackendUtility
::getModTSconfig($this->id
, 'mod.' . $this->moduleName
);
240 // Clean up settings:
241 $this->MOD_SETTINGS
= BackendUtility
::getModuleData($this->MOD_MENU
, GeneralUtility
::_GP('SET'), $this->moduleName
);
245 * Clears page cache for the current id, $this->id
249 public function clearCache() {
250 if ($this->clear_cache
) {
251 $tce = GeneralUtility
::makeInstance(DataHandler
::class);
252 $tce->stripslashes_values
= 0;
253 $tce->start(array(), array());
254 $tce->clear_cacheCmd($this->id
);
259 * Main function, starting the rendering of the list.
263 public function main() {
264 $backendUser = $this->getBackendUserAuthentication();
265 $lang = $this->getLanguageService();
266 // Loading current page record and checking access:
267 $this->pageinfo
= BackendUtility
::readPageAccess($this->id
, $this->perms_clause
);
268 $access = is_array($this->pageinfo
) ?
1 : 0;
269 // Start document template object:
270 $this->doc
= GeneralUtility
::makeInstance(DocumentTemplate
::class);
271 $this->doc
->backPath
= $GLOBALS['BACK_PATH'];
272 $this->doc
->setModuleTemplate('EXT:recordlist/Resources/Private/Templates/db_list.html');
273 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/AjaxDataHandler');
274 $calcPerms = $backendUser->calcPerms($this->pageinfo
);
275 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
276 PageActions.setPageId(' . (int)$this->id
. ');
277 PageActions.setCanEditPage(' . ($calcPerms & Permission
::PAGE_EDIT
&& !empty($this->id
) ?
'true' : 'false') . ');
278 PageActions.initializePageTitleRenaming();
280 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Tooltip');
281 // Apply predefined values for hidden checkboxes
282 // Set predefined value for DisplayBigControlPanel:
283 if ($this->modTSconfig
['properties']['enableDisplayBigControlPanel'] === 'activated') {
284 $this->MOD_SETTINGS
['bigControlPanel'] = TRUE
;
285 } elseif ($this->modTSconfig
['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
286 $this->MOD_SETTINGS
['bigControlPanel'] = FALSE
;
288 // Set predefined value for Clipboard:
289 if ($this->modTSconfig
['properties']['enableClipBoard'] === 'activated') {
290 $this->MOD_SETTINGS
['clipBoard'] = TRUE
;
291 } elseif ($this->modTSconfig
['properties']['enableClipBoard'] === 'deactivated') {
292 $this->MOD_SETTINGS
['clipBoard'] = FALSE
;
294 if ($this->MOD_SETTINGS
['clipBoard'] === NULL
) {
295 $this->MOD_SETTINGS
['clipBoard'] = TRUE
;
298 // Set predefined value for LocalizationView:
299 if ($this->modTSconfig
['properties']['enableLocalizationView'] === 'activated') {
300 $this->MOD_SETTINGS
['localization'] = TRUE
;
301 } elseif ($this->modTSconfig
['properties']['enableLocalizationView'] === 'deactivated') {
302 $this->MOD_SETTINGS
['localization'] = FALSE
;
305 // Initialize the dblist object:
306 /** @var $dblist RecordList\DatabaseRecordList */
307 $dblist = GeneralUtility
::makeInstance(RecordList\DatabaseRecordList
::class);
308 $dblist->backPath
= $GLOBALS['BACK_PATH'];
309 $dblist->script
= BackendUtility
::getModuleUrl('web_list');
310 $dblist->calcPerms
= $calcPerms;
311 $dblist->thumbs
= $backendUser->uc
['thumbnailsByDefault'];
312 $dblist->returnUrl
= $this->returnUrl
;
313 $dblist->allFields
= $this->MOD_SETTINGS
['bigControlPanel'] ||
$this->table ?
1 : 0;
314 $dblist->localizationView
= $this->MOD_SETTINGS
['localization'];
315 $dblist->showClipboard
= 1;
316 $dblist->disableSingleTableView
= $this->modTSconfig
['properties']['disableSingleTableView'];
317 $dblist->listOnlyInSingleTableMode
= $this->modTSconfig
['properties']['listOnlyInSingleTableView'];
318 $dblist->hideTables
= $this->modTSconfig
['properties']['hideTables'];
319 $dblist->hideTranslations
= $this->modTSconfig
['properties']['hideTranslations'];
320 $dblist->tableTSconfigOverTCA
= $this->modTSconfig
['properties']['table.'];
321 $dblist->allowedNewTables
= GeneralUtility
::trimExplode(',', $this->modTSconfig
['properties']['allowedNewTables'], TRUE
);
322 $dblist->deniedNewTables
= GeneralUtility
::trimExplode(',', $this->modTSconfig
['properties']['deniedNewTables'], TRUE
);
323 $dblist->newWizards
= $this->modTSconfig
['properties']['newWizards'] ?
1 : 0;
324 $dblist->pageRow
= $this->pageinfo
;
326 $dblist->MOD_MENU
= array('bigControlPanel' => '', 'clipBoard' => '', 'localization' => '');
327 $dblist->modTSconfig
= $this->modTSconfig
;
328 $clickTitleMode = trim($this->modTSconfig
['properties']['clickTitleMode']);
329 $dblist->clickTitleMode
= $clickTitleMode === '' ?
'edit' : $clickTitleMode;
330 if (isset($this->modTSconfig
['properties']['tableDisplayOrder.'])) {
331 $typoScriptService = GeneralUtility
::makeInstance(TypoScriptService
::class);
332 $dblist->setTableDisplayOrder($typoScriptService->convertTypoScriptArrayToPlainArray($this->modTSconfig
['properties']['tableDisplayOrder.']));
334 // Clipboard is initialized:
336 $dblist->clipObj
= GeneralUtility
::makeInstance(Clipboard
::class);
337 // Initialize - reads the clipboard content from the user session
338 $dblist->clipObj
->initializeClipboard();
339 // Clipboard actions are handled:
340 // CB is the clipboard command array
341 $CB = GeneralUtility
::_GET('CB');
342 if ($this->cmd
== 'setCB') {
343 // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked.
344 // By merging we get a full array of checked/unchecked elements
345 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
346 $CB['el'] = $dblist->clipObj
->cleanUpCBC(array_merge(GeneralUtility
::_POST('CBH'), (array)GeneralUtility
::_POST('CBC')), $this->cmd_table
);
348 if (!$this->MOD_SETTINGS
['clipBoard']) {
349 // If the clipboard is NOT shown, set the pad to 'normal'.
350 $CB['setP'] = 'normal';
353 $dblist->clipObj
->setCmd($CB);
355 $dblist->clipObj
->cleanCurrent();
356 // Save the clipboard content
357 $dblist->clipObj
->endClipboard();
358 // This flag will prevent the clipboard panel in being shown.
359 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
360 $dblist->dontShowClipControlPanels
= ($dblist->clipObj
->current
== 'normal' && !$this->modTSconfig
['properties']['showClipControlPanelsDespiteOfCMlayers']);
361 // If there is access to the page or root page is used for searching, then render the list contents and set up the document template object:
362 if ($access ||
($this->id
=== 0 && $this->search_levels
> 0 && $this->search_field
!== '')) {
363 // Deleting records...:
364 // Has not to do with the clipboard but is simply the delete action. The clipboard object is used to clean up the submitted entries to only the selected table.
365 if ($this->cmd
== 'delete') {
366 $items = $dblist->clipObj
->cleanUpCBC(GeneralUtility
::_POST('CBC'), $this->cmd_table
, 1);
367 if (!empty($items)) {
369 foreach ($items as $iK => $value) {
370 $iKParts = explode('|', $iK);
371 $cmd[$iKParts[0]][$iKParts[1]]['delete'] = 1;
373 $tce = GeneralUtility
::makeInstance(DataHandler
::class);
374 $tce->stripslashes_values
= 0;
375 $tce->start(array(), $cmd);
376 $tce->process_cmdmap();
377 if (isset($cmd['pages'])) {
378 BackendUtility
::setUpdateSignal('updatePageTree');
380 $tce->printLogErrorMessages(GeneralUtility
::getIndpEnv('REQUEST_URI'));
383 // Initialize the listing object, dblist, for rendering the list:
384 $this->pointer
= MathUtility
::forceIntegerInRange($this->pointer
, 0, 100000);
385 $dblist->start($this->id
, $this->table
, $this->pointer
, $this->search_field
, $this->search_levels
, $this->showLimit
);
386 $dblist->setDispFields();
387 // Render versioning selector:
388 if (ExtensionManagementUtility
::isLoaded('version')) {
389 $dblist->HTMLcode
.= $this->doc
->getVersionSelector($this->id
);
391 // Render the list of tables:
392 $dblist->generateList();
393 $listUrl = substr($dblist->listURL(), strlen($GLOBALS['BACK_PATH']));
394 // Add JavaScript functions to the page:
395 $this->doc
->JScode
= $this->doc
->wrapScriptTags('
396 function jumpExt(URL,anchor) { //
397 var anc = anchor?anchor:"";
398 window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
401 function jumpSelf(URL) { //
402 window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
406 function setHighlight(id) { //
407 top.fsMod.recentIds["web"]=id;
408 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
410 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
411 top.content.nav_frame.refresh_nav();
414 ' . $this->doc
->redirectUrls($listUrl) . '
415 ' . $dblist->CBfunctions() . '
416 function editRecords(table,idList,addParams,CBflag) { //
417 window.location.href="' . BackendUtility
::getModuleUrl('record_edit', array('returnUrl' => GeneralUtility
::getIndpEnv('REQUEST_URI'))) . '&edit["+table+"]["+idList+"]=edit"+addParams;
419 function editList(table,idList) { //
422 // Checking how many is checked, how many is not
424 var pos = idList.indexOf(",");
426 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
427 list+=idList.substr(pointer,pos-pointer)+",";
430 pos = idList.indexOf(",",pointer);
432 if (cbValue(table+"|"+idList.substr(pointer))) {
433 list+=idList.substr(pointer)+",";
436 return list ? list : idList;
439 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id
. ';
441 // Setting up the context sensitive menu:
442 $this->doc
->getContextMenuCode();
445 // Begin to compile the whole page, starting out with page header:
447 $this->body
= $this->doc
->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
449 $this->body
= $this->doc
->header($this->pageinfo
['title']);
452 if (!empty($dblist->HTMLcode
)) {
453 $output = $dblist->HTMLcode
;
455 $output = $flashMessage = GeneralUtility
::makeInstance(
457 $lang->getLL('noRecordsOnThisPage'),
463 $this->body
.= '<form action="' . htmlspecialchars($dblist->listURL()) . '" method="post" name="dblistForm">';
464 $this->body
.= $output;
465 $this->body
.= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
466 // If a listing was produced, create the page footer with search form etc:
467 if ($dblist->HTMLcode
) {
468 // Making field select box (when extended view for a single table is enabled):
469 if ($dblist->table
) {
470 $this->body
.= $dblist->fieldSelectBox($dblist->table
);
472 // Adding checkbox options for extended listing and clipboard display:
476 Listing options for extended view, clipboard and localization view
478 <div class="typo3-listOptions">
479 <form action="" method="post">';
481 // Add "display bigControlPanel" checkbox:
482 if ($this->modTSconfig
['properties']['enableDisplayBigControlPanel'] === 'selectable') {
483 $this->body
.= '<div class="checkbox">' .
484 '<label for="checkLargeControl">' .
485 BackendUtility
::getFuncCheck($this->id
, 'SET[bigControlPanel]', $this->MOD_SETTINGS
['bigControlPanel'], '', $this->table ?
'&table=' . $this->table
: '', 'id="checkLargeControl"') .
486 BackendUtility
::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('largeControl', TRUE
)) .
491 // Add "clipboard" checkbox:
492 if ($this->modTSconfig
['properties']['enableClipBoard'] === 'selectable') {
493 if ($dblist->showClipboard
) {
494 $this->body
.= '<div class="checkbox">' .
495 '<label for="checkShowClipBoard">' .
496 BackendUtility
::getFuncCheck($this->id
, 'SET[clipBoard]', $this->MOD_SETTINGS
['clipBoard'], '', $this->table ?
'&table=' . $this->table
: '', 'id="checkShowClipBoard"') .
497 BackendUtility
::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('showClipBoard', TRUE
)) .
503 // Add "localization view" checkbox:
504 if ($this->modTSconfig
['properties']['enableLocalizationView'] === 'selectable') {
505 $this->body
.= '<div class="checkbox">' .
506 '<label for="checkLocalization">' .
507 BackendUtility
::getFuncCheck($this->id
, 'SET[localization]', $this->MOD_SETTINGS
['localization'], '', $this->table ?
'&table=' . $this->table
: '', 'id="checkLocalization"') .
508 BackendUtility
::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('localization', TRUE
)) .
517 // Printing clipboard if enabled
518 if ($this->MOD_SETTINGS
['clipBoard'] && $dblist->showClipboard
&& ($dblist->HTMLcode ||
$dblist->clipObj
->hasElements())) {
519 $this->body
.= '<div class="db_list-dashboard">' . $dblist->clipObj
->printClipboard() . '</div>';
521 // Additional footer content
522 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawFooterHook'];
523 if (is_array($footerContentHook)) {
524 foreach ($footerContentHook as $hook) {
526 $this->body
.= GeneralUtility
::callUserFunction($hook, $params, $this);
529 // Setting up the buttons and markers for docheader
530 $docHeaderButtons = $dblist->getButtons();
532 'CSH' => $docHeaderButtons['csh'],
533 'CONTENT' => $this->body
,
534 'EXTRACONTAINERCLASS' => $this->table ?
'singletable' : '',
535 'BUTTONLIST_ADDITIONAL' => '',
539 if (!$this->modTSconfig
['properties']['disableSearchBox'] && ($dblist->HTMLcode ||
!empty($dblist->searchString
))) {
540 $markers['SEARCHBOX'] = $dblist->getSearchBox();
541 $markers['BUTTONLIST_ADDITIONAL'] = '<a href="#" onclick="toggleSearchToolbox(); return false;" title="'
542 . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', TRUE
) . '">'
543 . IconUtility
::getSpriteIcon('apps-toolbar-menu-search').'</a>';
545 // Build the <body> for the module
546 $this->content
= $this->doc
->moduleBody($this->pageinfo
, $docHeaderButtons, $markers);
547 // Renders the module page
548 $this->content
= $this->doc
->render('DB list', $this->content
);
552 * Outputting the accumulated content to screen
556 public function printContent() {
561 * @return BackendUserAuthentication
563 protected function getBackendUserAuthentication() {
564 return $GLOBALS['BE_USER'];
568 * @return LanguageService
570 protected function getLanguageService() {
571 return $GLOBALS['LANG'];
575 * @return PageRenderer
577 protected function getPageRenderer() {
578 if ($this->pageRenderer
=== NULL
) {
579 $this->pageRenderer
= GeneralUtility
::makeInstance(PageRenderer
::class);
582 return $this->pageRenderer
;