[TASK] Show info in empty list module
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / RecordList.php
1 <?php
2 namespace TYPO3\CMS\Recordlist;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Messaging\FlashMessage;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20
21 /**
22 * Script Class for the Web > List module; rendering the listing of records on a page
23 *
24 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
25 */
26 class RecordList {
27
28 /**
29 * Page Id for which to make the listing
30 *
31 * @var int
32 */
33 public $id;
34
35 /**
36 * Pointer - for browsing list of records.
37 *
38 * @var int
39 */
40 public $pointer;
41
42 /**
43 * Thumbnails or not
44 *
45 * @var string
46 */
47 public $imagemode;
48
49 /**
50 * Which table to make extended listing for
51 *
52 * @var string
53 */
54 public $table;
55
56 /**
57 * Search-fields
58 *
59 * @var string
60 */
61 public $search_field;
62
63 /**
64 * Search-levels
65 *
66 * @var int
67 */
68 public $search_levels;
69
70 /**
71 * Show-limit
72 *
73 * @var int
74 */
75 public $showLimit;
76
77 /**
78 * Return URL
79 *
80 * @var string
81 */
82 public $returnUrl;
83
84 /**
85 * Clear-cache flag - if set, clears page cache for current id.
86 *
87 * @var bool
88 */
89 public $clear_cache;
90
91 /**
92 * Command: Eg. "delete" or "setCB" (for TCEmain / clipboard operations)
93 *
94 * @var string
95 */
96 public $cmd;
97
98 /**
99 * Table on which the cmd-action is performed.
100 *
101 * @var string
102 */
103 public $cmd_table;
104
105 /**
106 * Page select perms clause
107 *
108 * @var int
109 */
110 public $perms_clause;
111
112 /**
113 * Module TSconfig
114 *
115 * @var array
116 */
117 public $modTSconfig;
118
119 /**
120 * Current ids page record
121 *
122 * @var array
123 */
124 public $pageinfo;
125
126 /**
127 * Document template object
128 *
129 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
130 */
131 public $doc;
132
133 /**
134 * Module configuration
135 *
136 * @var array
137 * @deprecated since TYPO3 CMS 7, will be removed in CMS 8.
138 */
139 public $MCONF = array();
140
141 /**
142 * Menu configuration
143 *
144 * @var array
145 */
146 public $MOD_MENU = array();
147
148 /**
149 * Module settings (session variable)
150 *
151 * @var array
152 */
153 public $MOD_SETTINGS = array();
154
155 /**
156 * Module output accumulation
157 *
158 * @var string
159 */
160 public $content;
161
162 /**
163 * The name of the module
164 *
165 * @var string
166 */
167 protected $moduleName = 'web_list';
168
169 /**
170 * Constructor
171 */
172 public function __construct() {
173 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_mod_web_list.xlf');
174 }
175
176 /**
177 * Initializing the module
178 *
179 * @return void
180 */
181 public function init() {
182 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
183 // Get session data
184 $sessionData = $GLOBALS['BE_USER']->getSessionData(\TYPO3\CMS\Recordlist\RecordList::class);
185 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
186 // GPvars:
187 $this->id = (int)GeneralUtility::_GP('id');
188 $this->pointer = GeneralUtility::_GP('pointer');
189 $this->imagemode = GeneralUtility::_GP('imagemode');
190 $this->table = GeneralUtility::_GP('table');
191 if (!empty(GeneralUtility::_GP('search_field'))) {
192 $this->search_field = GeneralUtility::_GP('search_field');
193 $sessionData['search_field'] = $this->search_field;
194 }
195 $this->search_levels = (int)GeneralUtility::_GP('search_levels');
196 $this->showLimit = GeneralUtility::_GP('showLimit');
197 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
198 $this->clear_cache = GeneralUtility::_GP('clear_cache');
199 $this->cmd = GeneralUtility::_GP('cmd');
200 $this->cmd_table = GeneralUtility::_GP('cmd_table');
201 if (!empty(GeneralUtility::_GP('search')) && empty(GeneralUtility::_GP('search_field'))) {
202 $this->search_field = '';
203 $sessionData['search_field'] = $this->search_field;
204 }
205 // Initialize menu
206 $this->menuConfig();
207 // Store session data
208 $GLOBALS['BE_USER']->setAndSaveSessionData(\TYPO3\CMS\Recordlist\RecordList::class, $sessionData);
209 }
210
211 /**
212 * Initialize function menu array
213 *
214 * @return void
215 */
216 public function menuConfig() {
217 // MENU-ITEMS:
218 $this->MOD_MENU = array(
219 'bigControlPanel' => '',
220 'clipBoard' => '',
221 'localization' => ''
222 );
223 // Loading module configuration:
224 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
225 // Clean up settings:
226 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
227 }
228
229 /**
230 * Clears page cache for the current id, $this->id
231 *
232 * @return void
233 */
234 public function clearCache() {
235 if ($this->clear_cache) {
236 $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
237 $tce->stripslashes_values = 0;
238 $tce->start(array(), array());
239 $tce->clear_cacheCmd($this->id);
240 }
241 }
242
243 /**
244 * Main function, starting the rendering of the list.
245 *
246 * @return void
247 */
248 public function main() {
249 // Start document template object:
250 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
251 $this->doc->backPath = $GLOBALS['BACK_PATH'];
252 $this->doc->setModuleTemplate('EXT:recordlist/Resources/Private/Templates/db_list.html');
253 $this->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/AjaxDataHandler');
254 // Loading current page record and checking access:
255 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
256 $access = is_array($this->pageinfo) ? 1 : 0;
257
258 // Apply predefined values for hidden checkboxes
259 // Set predefined value for DisplayBigControlPanel:
260 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'activated') {
261 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
262 } elseif ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
263 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
264 }
265 // Set predefined value for Clipboard:
266 if ($this->modTSconfig['properties']['enableClipBoard'] === 'activated') {
267 $this->MOD_SETTINGS['clipBoard'] = TRUE;
268 } elseif ($this->modTSconfig['properties']['enableClipBoard'] === 'deactivated') {
269 $this->MOD_SETTINGS['clipBoard'] = FALSE;
270 }
271 // Set predefined value for LocalizationView:
272 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'activated') {
273 $this->MOD_SETTINGS['localization'] = TRUE;
274 } elseif ($this->modTSconfig['properties']['enableLocalizationView'] === 'deactivated') {
275 $this->MOD_SETTINGS['localization'] = FALSE;
276 }
277
278 // Initialize the dblist object:
279 /** @var $dblist \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */
280 $dblist = GeneralUtility::makeInstance(\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class);
281 $dblist->backPath = $GLOBALS['BACK_PATH'];
282 $dblist->script = BackendUtility::getModuleUrl('web_list', array(), '');
283 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageinfo);
284 $dblist->thumbs = $GLOBALS['BE_USER']->uc['thumbnailsByDefault'];
285 $dblist->returnUrl = $this->returnUrl;
286 $dblist->allFields = $this->MOD_SETTINGS['bigControlPanel'] || $this->table ? 1 : 0;
287 $dblist->localizationView = $this->MOD_SETTINGS['localization'];
288 $dblist->showClipboard = 1;
289 $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
290 $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
291 $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
292 $dblist->hideTranslations = $this->modTSconfig['properties']['hideTranslations'];
293 $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
294 $dblist->allowedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['allowedNewTables'], TRUE);
295 $dblist->deniedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['deniedNewTables'], TRUE);
296 $dblist->newWizards = $this->modTSconfig['properties']['newWizards'] ? 1 : 0;
297 $dblist->pageRow = $this->pageinfo;
298 $dblist->counter++;
299 $dblist->MOD_MENU = array('bigControlPanel' => '', 'clipBoard' => '', 'localization' => '');
300 $dblist->modTSconfig = $this->modTSconfig;
301 $clickTitleMode = trim($this->modTSconfig['properties']['clickTitleMode']);
302 $dblist->clickTitleMode = $clickTitleMode === '' ? 'edit' : $clickTitleMode;
303 // Clipboard is initialized:
304 // Start clipboard
305 $dblist->clipObj = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
306 // Initialize - reads the clipboard content from the user session
307 $dblist->clipObj->initializeClipboard();
308 // Clipboard actions are handled:
309 // CB is the clipboard command array
310 $CB = GeneralUtility::_GET('CB');
311 if ($this->cmd == 'setCB') {
312 // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked.
313 // By merging we get a full array of checked/unchecked elements
314 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
315 $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge((array)GeneralUtility::_POST('CBH'), (array)GeneralUtility::_POST('CBC')), $this->cmd_table);
316 }
317 if (!$this->MOD_SETTINGS['clipBoard']) {
318 // If the clipboard is NOT shown, set the pad to 'normal'.
319 $CB['setP'] = 'normal';
320 }
321 // Execute commands.
322 $dblist->clipObj->setCmd($CB);
323 // Clean up pad
324 $dblist->clipObj->cleanCurrent();
325 // Save the clipboard content
326 $dblist->clipObj->endClipboard();
327 // This flag will prevent the clipboard panel in being shown.
328 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
329 $dblist->dontShowClipControlPanels = (!$this->MOD_SETTINGS['bigControlPanel'] && $dblist->clipObj->current == 'normal' && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers']);
330 // 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:
331 if ($access || ($this->id === 0 && $this->search_levels > 0 && strlen($this->search_field) > 0)) {
332 // Deleting records...:
333 // 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.
334 if ($this->cmd == 'delete') {
335 $items = $dblist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), $this->cmd_table, 1);
336 if (count($items)) {
337 $cmd = array();
338 foreach ($items as $iK => $value) {
339 $iKParts = explode('|', $iK);
340 $cmd[$iKParts[0]][$iKParts[1]]['delete'] = 1;
341 }
342 $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
343 $tce->stripslashes_values = 0;
344 $tce->start(array(), $cmd);
345 $tce->process_cmdmap();
346 if (isset($cmd['pages'])) {
347 BackendUtility::setUpdateSignal('updatePageTree');
348 }
349 $tce->printLogErrorMessages(GeneralUtility::getIndpEnv('REQUEST_URI'));
350 }
351 }
352 // Initialize the listing object, dblist, for rendering the list:
353 $this->pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
354 $dblist->start($this->id, $this->table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
355 $dblist->setDispFields();
356 // Render versioning selector:
357 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('version')) {
358 $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
359 }
360 // Render the list of tables:
361 $dblist->generateList();
362 $listUrl = substr($dblist->listURL(), strlen($GLOBALS['BACK_PATH']));
363 // Add JavaScript functions to the page:
364 $this->doc->JScode = $this->doc->wrapScriptTags('
365 function jumpExt(URL,anchor) { //
366 var anc = anchor?anchor:"";
367 window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
368 return false;
369 }
370 function jumpSelf(URL) { //
371 window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
372 return false;
373 }
374
375 function setHighlight(id) { //
376 top.fsMod.recentIds["web"]=id;
377 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
378
379 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
380 top.content.nav_frame.refresh_nav();
381 }
382 }
383 ' . $this->doc->redirectUrls($listUrl) . '
384 ' . $dblist->CBfunctions() . '
385 function editRecords(table,idList,addParams,CBflag) { //
386 window.location.href="' . $GLOBALS['BACK_PATH'] . 'alt_doc.php?returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '&edit["+table+"]["+idList+"]=edit"+addParams;
387 }
388 function editList(table,idList) { //
389 var list="";
390
391 // Checking how many is checked, how many is not
392 var pointer=0;
393 var pos = idList.indexOf(",");
394 while (pos!=-1) {
395 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
396 list+=idList.substr(pointer,pos-pointer)+",";
397 }
398 pointer=pos+1;
399 pos = idList.indexOf(",",pointer);
400 }
401 if (cbValue(table+"|"+idList.substr(pointer))) {
402 list+=idList.substr(pointer)+",";
403 }
404
405 return list ? list : idList;
406 }
407
408 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
409 ');
410 // Setting up the context sensitive menu:
411 $this->doc->getContextMenuCode();
412 }
413 // access
414 // Begin to compile the whole page, starting out with page header:
415 if (!$this->id) {
416 $this->body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
417 } else {
418 $this->body = $this->doc->header($this->pageinfo['title']);
419 }
420
421 if (!empty($dblist->HTMLcode)) {
422 $output = $dblist->HTMLcode;
423 } else {
424 $output = $flashMessage = GeneralUtility::makeInstance(
425 FlashMessage::class,
426 $GLOBALS['LANG']->getLL('noRecordsOnThisPage'),
427 '',
428 FlashMessage::INFO
429 )->render();
430 }
431
432 $this->body .= '<form action="' . htmlspecialchars($dblist->listURL()) . '" method="post" name="dblistForm">';
433 $this->body .= $output;
434 $this->body .= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
435 // If a listing was produced, create the page footer with search form etc:
436 if ($dblist->HTMLcode) {
437 // Making field select box (when extended view for a single table is enabled):
438 if ($dblist->table) {
439 $this->body .= $dblist->fieldSelectBox($dblist->table);
440 }
441 // Adding checkbox options for extended listing and clipboard display:
442 $this->body .= '
443
444 <!--
445 Listing options for extended view, clipboard and localization view
446 -->
447 <div id="typo3-listOptions">
448 <form action="" method="post">';
449
450 // Add "display bigControlPanel" checkbox:
451 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
452 $this->body .= '<div class="checkbox">' .
453 '<label for="checkLargeControl">' .
454 BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLargeControl"') .
455 BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $GLOBALS['LANG']->getLL('largeControl', TRUE)) .
456 '</label>' .
457 '</div>';
458 }
459
460 // Add "clipboard" checkbox:
461 if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
462 if ($dblist->showClipboard) {
463 $this->body .= '<div class="checkbox">' .
464 '<label for="checkShowClipBoard">' .
465 BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', $this->table ? '&table=' . $this->table : '', 'id="checkShowClipBoard"') .
466 BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $GLOBALS['LANG']->getLL('showClipBoard', TRUE)) .
467 '</label>' .
468 '</div>';
469 }
470 }
471
472 // Add "localization view" checkbox:
473 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
474 $this->body .= '<div class="checkbox">' .
475 '<label for="checkLocalization">' .
476 BackendUtility::getFuncCheck($this->id, 'SET[localization]', $this->MOD_SETTINGS['localization'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLocalization"') .
477 BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $GLOBALS['LANG']->getLL('localization', TRUE)) .
478 '</label>' .
479 '</div>';
480 }
481
482 $this->body .= '
483 </form>
484 </div>';
485 }
486 // Printing clipboard if enabled
487 if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard && ($dblist->HTMLcode || $dblist->clipObj->hasElements())) {
488 $this->body .= '<div class="db_list-dashboard">' . $dblist->clipObj->printClipboard() . '</div>';
489 }
490 // Additional footer content
491 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/mod1/index.php']['drawFooterHook'];
492 if (is_array($footerContentHook)) {
493 foreach ($footerContentHook as $hook) {
494 $params = array();
495 $this->body .= GeneralUtility::callUserFunction($hook, $params, $this);
496 }
497 }
498 // Setting up the buttons and markers for docheader
499 $docHeaderButtons = $dblist->getButtons();
500 $markers = array(
501 'CSH' => $docHeaderButtons['csh'],
502 'CONTENT' => $this->body,
503 'EXTRACONTAINERCLASS' => $this->table ? 'singletable' : '',
504 'BUTTONLIST_ADDITIONAL' => '',
505 'SEARCHBOX' => '',
506 'BUTTONLIST_ADDITIONAL' => ''
507 );
508 // searchbox toolbar
509 if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dblist->HTMLcode || !empty($dblist->searchString))) {
510 $markers['SEARCHBOX'] = $dblist->getSearchBox();
511 $markers['BUTTONLIST_ADDITIONAL'] = '<a href="#" onclick="toggleSearchToolbox(); return false;" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', TRUE) . '">'.\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-toolbar-menu-search').'</a>';
512 }
513 // Build the <body> for the module
514 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
515 // Renders the module page
516 $this->content = $this->doc->render('DB list', $this->content);
517 }
518
519 /**
520 * Outputting the accumulated content to screen
521 *
522 * @return void
523 */
524 public function printContent() {
525 echo $this->content;
526 }
527
528 }