[TASK] Add SVG Icons for document save actions
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageLayoutController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\Utility\IconUtility;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Page\PageRenderer;
22 use TYPO3\CMS\Core\Type\Bitmask\Permission;
23 use TYPO3\CMS\Core\Messaging\FlashMessage;
24 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\HttpUtility;
27 use TYPO3\CMS\Core\Utility\MathUtility;
28 use TYPO3\CMS\Fluid\View\StandaloneView;
29 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
30 use TYPO3\CMS\Recordlist\RecordList;
31 use TYPO3\CMS\Core\DataHandling\DataHandler;
32 use TYPO3\CMS\Frontend\Page\PageRepository;
33 use TYPO3\CMS\Backend\Module\ModuleLoader;
34 use TYPO3\CMS\Backend\Template\DocumentTemplate;
35 use TYPO3\CMS\Backend\View\BackendLayoutView;
36 use TYPO3\CMS\Backend\Form\DataPreprocessor;
37 use TYPO3\CMS\Backend\Form\FormEngine;
38 use TYPO3\CMS\Core\Messaging\FlashMessageService;
39 use TYPO3\CMS\Backend\View\PageLayoutView;
40 use TYPO3\CMS\Backend\Tree\View\ContentLayoutPagePositionMap;
41 use TYPO3\CMS\Core\Versioning\VersionState;
42
43 /**
44 * Script Class for Web > Layout module
45 */
46 class PageLayoutController {
47
48 /**
49 * Page Id for which to make the listing
50 *
51 * @var int
52 */
53 public $id;
54
55 /**
56 * Pointer - for browsing list of records.
57 *
58 * @var int
59 */
60 public $pointer;
61
62 /**
63 * Thumbnails or not
64 *
65 * @var string
66 */
67 public $imagemode;
68
69 /**
70 * Search-fields
71 *
72 * @var string
73 */
74 public $search_field;
75
76 /**
77 * Search-levels
78 *
79 * @var int
80 */
81 public $search_levels;
82
83 /**
84 * Show-limit
85 *
86 * @var int
87 */
88 public $showLimit;
89
90 /**
91 * Return URL
92 *
93 * @var string
94 */
95 public $returnUrl;
96
97 /**
98 * Clear-cache flag - if set, clears page cache for current id.
99 *
100 * @var bool
101 */
102 public $clear_cache;
103
104 /**
105 * PopView id - for opening a window with the page
106 *
107 * @var bool
108 */
109 public $popView;
110
111 /**
112 * QuickEdit: Variable, that tells quick edit what to show/edit etc.
113 * Format is [tablename]:[uid] with some exceptional values for both parameters (with special meanings).
114 *
115 * @var string
116 */
117 public $edit_record;
118
119 /**
120 * QuickEdit: If set, this variable tells quick edit that the last edited record had
121 * this value as UID and we should look up the new, real uid value in sys_log.
122 *
123 * @var string
124 */
125 public $new_unique_uid;
126
127 /**
128 * Page select perms clause
129 *
130 * @var string
131 */
132 public $perms_clause;
133
134 /**
135 * Module TSconfig
136 *
137 * @var array
138 */
139 public $modTSconfig;
140
141 /**
142 * Module shared TSconfig
143 *
144 * @var array
145 */
146 public $modSharedTSconfig;
147
148 /**
149 * Current ids page record
150 *
151 * @var array
152 */
153 public $pageinfo;
154
155 /**
156 * Document template object
157 *
158 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
159 */
160 public $doc;
161
162 /**
163 * "Pseudo" Description -table name
164 *
165 * @var string
166 */
167 public $descrTable;
168
169 /**
170 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
171 *
172 * @var string
173 */
174 public $colPosList;
175
176 /**
177 * Flag: If content can be edited or not.
178 *
179 * @var bool
180 */
181 public $EDIT_CONTENT;
182
183 /**
184 * Users permissions integer for this page.
185 *
186 * @var int
187 */
188 public $CALC_PERMS;
189
190 /**
191 * Currently selected language for editing content elements
192 *
193 * @var int
194 */
195 public $current_sys_language;
196
197 /**
198 * Module configuration
199 *
200 * @var array
201 */
202 public $MCONF = array();
203
204 /**
205 * Menu configuration
206 *
207 * @var array
208 */
209 public $MOD_MENU = array();
210
211 /**
212 * Module settings (session variable)
213 *
214 * @var array
215 */
216 public $MOD_SETTINGS = array();
217
218 /**
219 * Array of tables to be listed by the Web > Page module in addition to the default tables
220 *
221 * @var array
222 */
223 public $externalTables = array();
224
225 /**
226 * Module output accumulation
227 *
228 * @var string
229 */
230 public $content;
231
232 /**
233 * Function menu temporary storage
234 *
235 * @var string
236 */
237 public $topFuncMenu;
238
239 /**
240 * List of column-integers accessible to the current BE user.
241 * Is set from TSconfig, default is $colPosList
242 *
243 * @var string
244 */
245 public $activeColPosList;
246
247 /**
248 * Markers array
249 *
250 * @var array
251 */
252 protected $markers = array();
253
254 /**
255 * @var array
256 */
257 protected $eRParts = array();
258
259 /**
260 * @var string
261 */
262 protected $editSelect;
263
264 /**
265 * @var bool
266 */
267 protected $deleteButton;
268
269 /**
270 * @var bool
271 */
272 protected $undoButton;
273
274 /**
275 * @var array
276 */
277 protected $undoButtonR;
278
279 /**
280 * @var string
281 */
282 protected $R_URI;
283
284 /**
285 * @var string
286 */
287 protected $closeUrl;
288
289 /**
290 * Caches the available languages in a colPos
291 *
292 * @var array
293 */
294 protected $languagesInColumnCache = array();
295
296 /**
297 * Caches the amount of content elements as a matrix
298 *
299 * @var array
300 * @internal
301 */
302 public $contentElementCache = array();
303
304 /**
305 * @var IconFactory
306 */
307 protected $iconFactory;
308
309 /**
310 * Initializing the module
311 *
312 * @return void
313 */
314 public function init() {
315 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
316 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
317
318 // Setting module configuration / page select clause
319 $this->MCONF = $GLOBALS['MCONF'];
320 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
321 // Get session data
322 $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
323 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
324 // GPvars:
325 $this->id = (int)GeneralUtility::_GP('id');
326 $this->pointer = GeneralUtility::_GP('pointer');
327 $this->imagemode = GeneralUtility::_GP('imagemode');
328 $this->clear_cache = GeneralUtility::_GP('clear_cache');
329 $this->popView = GeneralUtility::_GP('popView');
330 $this->edit_record = GeneralUtility::_GP('edit_record');
331 $this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
332 $this->search_field = GeneralUtility::_GP('search_field');
333 $this->search_levels = GeneralUtility::_GP('search_levels');
334 $this->showLimit = GeneralUtility::_GP('showLimit');
335 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
336 $this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
337 $sessionData['search_field'] = $this->search_field;
338 // Store session data
339 $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
340 // Load page info array:
341 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
342 // Initialize menu
343 $this->menuConfig();
344 // Setting sys language from session var:
345 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
346 // CSH / Descriptions:
347 $this->descrTable = '_MOD_' . $this->MCONF['name'];
348
349 $this->markers['SEARCHBOX'] = '';
350 $this->markers['BUTTONLIST_ADDITIONAL'] = '';
351 }
352
353 /**
354 * Initialize menu array
355 *
356 * @return void
357 */
358 public function menuConfig() {
359 $lang = $this->getLanguageService();
360 // MENU-ITEMS:
361 $this->MOD_MENU = array(
362 'tt_content_showHidden' => '',
363 'function' => array(
364 0 => $lang->getLL('m_function_0'),
365 1 => $lang->getLL('m_function_1'),
366 2 => $lang->getLL('m_function_2')
367 ),
368 'language' => array(
369 0 => $lang->getLL('m_default')
370 )
371 );
372 // example settings:
373 // $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
374 // array ('default' => array(
375 // 'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
376 // 'fList' => 'title,description,image',
377 // 'icon' => TRUE));
378 if (is_array($this->externalTables)) {
379 foreach ($this->externalTables as $table => $tableSettings) {
380 // delete the default settings from above
381 if (is_array($this->MOD_MENU[$table])) {
382 unset($this->MOD_MENU[$table]);
383 }
384 if (is_array($tableSettings) && count($tableSettings) > 1) {
385 foreach ($tableSettings as $key => $settings) {
386 $this->MOD_MENU[$table][$key] = $lang->sL($settings['MENU']);
387 }
388 }
389 }
390 }
391 // First, select all pages_language_overlay records on the current page. Each represents a possibility for a language on the page. Add these to language selector.
392 $res = $this->exec_languageQuery($this->id);
393 while ($lRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
394 if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
395 $this->MOD_MENU['language'][$lRow['uid']] = $lRow['hidden'] ? '(' . $lRow['title'] . ')' : $lRow['title'];
396 }
397 }
398 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
399 $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', $this->getBackendUser()->isAdmin() ? '' : 'hidden=0');
400 if (!$count) {
401 unset($this->MOD_MENU['function']['2']);
402 }
403 // page/be_user TSconfig settings and blinding of menu-items
404 $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
405 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
406 if ($this->modTSconfig['properties']['QEisDefault']) {
407 ksort($this->MOD_MENU['function']);
408 }
409 $this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
410 // Remove QuickEdit as option if page type is not...
411 if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6', $this->pageinfo['doktype'])) {
412 unset($this->MOD_MENU['function'][0]);
413 }
414 // Setting alternative default label:
415 if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
416 $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
417 }
418 // Clean up settings
419 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), 'web_layout');
420 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
421 if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
422 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
423 }
424 }
425
426 /**
427 * Clears page cache for the current id, $this->id
428 *
429 * @return void
430 */
431 public function clearCache() {
432 if ($this->clear_cache) {
433 $tce = GeneralUtility::makeInstance(DataHandler::class);
434 $tce->stripslashes_values = FALSE;
435 $tce->start(array(), array());
436 $tce->clear_cacheCmd($this->id);
437 }
438 }
439
440 /**
441 * Generate the flashmessages for current pid
442 *
443 * @return string HTML content with flashmessages
444 */
445 protected function getHeaderFlashMessagesForCurrentPid() {
446 $content = '';
447 $lang = $this->getLanguageService();
448 // If page is a folder
449 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
450 // Access to list module
451 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
452 $moduleLoader->load($GLOBALS['TBE_MODULES']);
453 $modules = $moduleLoader->modules;
454 if (is_array($modules['web']['sub']['list'])) {
455 $title = $lang->getLL('goToListModule');
456 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
457 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
458
459 $view = GeneralUtility::makeInstance(StandaloneView::class);
460 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
461 $view->assignMultiple(array(
462 'title' => $title,
463 'message' => $message,
464 'state' => InfoboxViewHelper::STATE_INFO
465 ));
466 $content .= $view->render();
467 }
468 }
469 // If content from different pid is displayed
470 if ($this->pageinfo['content_from_pid']) {
471 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
472 $title = BackendUtility::getRecordTitle('pages', $contentPage);
473 $linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
474 $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
475 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, sprintf($lang->getLL('content_from_pid_title'), $link), '', FlashMessage::INFO);
476 $content .= $flashMessage->render();
477 }
478 return $content;
479 }
480
481 /**
482 *
483 * @return string $title
484 */
485 protected function getLocalizedPageTitle() {
486 if ($this->current_sys_language > 0) {
487 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
488 'title',
489 'pages_language_overlay',
490 'pid = ' . (int)$this->id .
491 ' AND sys_language_uid = ' . (int)$this->current_sys_language .
492 BackendUtility::deleteClause('pages_language_overlay') .
493 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
494 '',
495 '',
496 '',
497 'sys_language_uid'
498 );
499 return $overlayRecord['title'];
500 } else {
501 return $this->pageinfo['title'];
502 }
503 }
504
505 /**
506 * Main function.
507 * Creates some general objects and calls other functions for the main rendering of module content.
508 *
509 * @return void
510 */
511 public function main() {
512 $lang = $this->getLanguageService();
513 // Access check...
514 // The page will show only if there is a valid page and if this page may be viewed by the user
515 $access = is_array($this->pageinfo) ? 1 : 0;
516 if ($this->id && $access) {
517 // Initialize permission settings:
518 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
519 $this->EDIT_CONTENT = $this->pageIsNotLockedForEditors();
520
521 // Start document template object:
522 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
523 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
524
525 // override the default jumpToUrl
526 $this->doc->JScodeArray['jumpToUrl'] = '
527 function jumpToUrl(URL,formEl) {
528 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
529 if (!TBE_EDITOR.isFormChanged()) {
530 window.location.href = URL;
531 } else if (formEl) {
532 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
533 }
534 } else {
535 window.location.href = URL;
536 }
537 }
538 ';
539
540 $this->doc->JScode .= $this->doc->wrapScriptTags('
541 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
542 if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
543 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
544
545 function deleteRecord(table,id,url) { //
546 if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
547 window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC=' . $this->getBackendUser()->veriCode() . BackendUtility::getUrlToken('tceAction') . '&prErr=1&uPT=1";
548 }
549 return false;
550 }
551 ');
552 $this->doc->JScode .= $this->doc->wrapScriptTags('
553 var DTM_array = [];
554 var DTM_origClass = "";
555
556 // if tabs are used in a popup window the array might not exists
557 if(!top.DTM_currentTabs) {
558 top.DTM_currentTabs = [];
559 }
560
561 function DTM_activate(idBase,index,doToogle) { //
562 // Hiding all:
563 if (DTM_array[idBase]) {
564 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
565 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
566 document.getElementById(DTM_array[idBase][cnt]+"-DIV").className = "tab-pane";
567 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").value = "tab";
568 }
569 }
570 }
571
572 // Showing one:
573 if (document.getElementById(idBase+"-"+index+"-DIV")) {
574 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").className === "tab-pane active") {
575 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane";
576 if(DTM_origClass=="") {
577 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "tab";
578 } else {
579 DTM_origClass = "tab";
580 }
581 top.DTM_currentTabs[idBase] = -1;
582 } else {
583 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane active";
584 if(DTM_origClass=="") {
585 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "active";
586 } else {
587 DTM_origClass = "active";
588 }
589 top.DTM_currentTabs[idBase] = index;
590 }
591 }
592 }
593 function DTM_toggle(idBase,index,isInit) { //
594 // Showing one:
595 if (document.getElementById(idBase+"-"+index+"-DIV")) {
596 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
597 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane";
598 if(isInit) {
599 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "tab";
600 } else {
601 DTM_origClass = "tab";
602 }
603 top.DTM_currentTabs[idBase+"-"+index] = 0;
604 } else {
605 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane active";
606 if(isInit) {
607 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "active";
608 } else {
609 DTM_origClass = "active";
610 }
611 top.DTM_currentTabs[idBase+"-"+index] = 1;
612 }
613 }
614 }
615 ');
616 // Setting doc-header
617 $this->doc->form = '<form action="' . htmlspecialchars(
618 BackendUtility::getModuleUrl(
619 'web_layout', array('id' => $this->id, 'imagemode' => $this->imagemode)
620 )) . '" method="post">';
621 // Creating the top function menu:
622 $this->topFuncMenu = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'], '', '');
623 $languageMenu = count($this->MOD_MENU['language']) > 1 ? $lang->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', TRUE) . BackendUtility::getFuncMenu($this->id, 'SET[language]', $this->current_sys_language, $this->MOD_MENU['language'], '', '') : '';
624 // Find backend layout / coumns
625 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
626 if (!empty($backendLayout['__colPosList'])) {
627 $this->colPosList = implode(',', $backendLayout['__colPosList']);
628 }
629 // Removing duplicates, if any
630 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
631 // Accessible columns
632 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
633 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
634 // Match with the list which is present in the colPosList for the current page
635 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
636 $this->activeColPosList = array_unique(array_intersect(
637 $this->activeColPosList,
638 $this->colPosList
639 ));
640 }
641 } else {
642 $this->activeColPosList = $this->colPosList;
643 }
644 $this->activeColPosList = implode(',', $this->activeColPosList);
645 $this->colPosList = implode(',', $this->colPosList);
646
647 $body = '';
648 $body .= $this->getHeaderFlashMessagesForCurrentPid();
649 // Render the primary module content:
650 if ($this->MOD_SETTINGS['function'] == 0) {
651 // QuickEdit
652 $body .= $this->renderQuickEdit();
653 } else {
654 // Page title
655 $body .= $this->doc->header($this->getLocalizedPageTitle());
656 // All other listings
657 $body .= $this->renderListContent();
658 }
659 // Setting up the buttons and markers for docheader
660 $docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
661 $this->markers['CSH'] = $docHeaderButtons['csh'];
662 $this->markers['TOP_FUNCTION_MENU'] = $this->topFuncMenu . $this->editSelect;
663 $this->markers['LANGSELECTOR'] = $languageMenu;
664 $this->markers['CONTENT'] = $body;
665 // Build the <body> for the module
666 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
667 // Renders the module page
668 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
669 } else {
670 // If no access or id value, create empty document:
671 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
672 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
673 $this->doc->JScode = $this->doc->wrapScriptTags('
674 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
675 ');
676
677 $body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
678
679 $title = $lang->getLL('clickAPage_header');
680 $message = $lang->getLL('clickAPage_content');
681
682 $view = GeneralUtility::makeInstance(StandaloneView::class);
683 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
684 $view->assignMultiple(array(
685 'title' => $title,
686 'message' => $message,
687 'state' => InfoboxViewHelper::STATE_INFO
688 ));
689 $body .= $view->render();
690
691 // Setting up the buttons and markers for docheader
692 $docHeaderButtons = array(
693 'view' => '',
694 'history_page' => '',
695 'new_content' => '',
696 'move_page' => '',
697 'move_record' => '',
698 'new_page' => '',
699 'edit_page' => '',
700 'csh' => '',
701 'shortcut' => '',
702 'cache' => '',
703 'savedok' => '',
704 'savedokshow' => '',
705 'closedok' => '',
706 'deletedok' => '',
707 'undo' => '',
708 'history_record' => '',
709 'edit_language' => ''
710 );
711 $this->markers['CSH'] = '';
712 $this->markers['TOP_FUNCTION_MENU'] = '';
713 $this->markers['LANGSELECTOR'] = '';
714 $this->markers['CONTENT'] = $body;
715 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
716 // Renders the module page
717 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
718 }
719 }
720
721 /**
722 * Rendering the quick-edit view.
723 *
724 * @return string
725 */
726 public function renderQuickEdit() {
727 $databaseConnection = $this->getDatabaseConnection();
728 $beUser = $this->getBackendUser();
729 $lang = $this->getLanguageService();
730 // Alternative template
731 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
732 // Alternative form tag; Quick Edit submits its content to tce_db.php.
733 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="multipart/form-data" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
734 // Setting up the context sensitive menu:
735 $this->doc->getContextMenuCode();
736 // Set the edit_record value for internal use in this function:
737 $edit_record = $this->edit_record;
738 // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
739 if (substr($edit_record, 0, 9) == '_EDIT_COL') {
740 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int)$this->id . ' AND colPos=' . (int)substr($edit_record, 10) . ' AND sys_language_uid=' . (int)$this->current_sys_language . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
741 $idListA = array();
742 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
743 $idListA[] = $cRow['uid'];
744 }
745 $url = BackendUtility::getModuleUrl('record_edit', array(
746 'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
747 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
748 ));
749 HttpUtility::redirect($url);
750 }
751 // If the former record edited was the creation of a NEW record, this will look up the created records uid:
752 if ($this->new_unique_uid) {
753 $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
754 $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
755 if (is_array($sys_log_row)) {
756 $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
757 }
758 }
759 // Creating the selector box, allowing the user to select which element to edit:
760 $opt = array();
761 $is_selected = 0;
762 $languageOverlayRecord = '';
763 if ($this->current_sys_language) {
764 list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
765 }
766 if (is_array($languageOverlayRecord)) {
767 $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
768 $is_selected += (int)$edit_record == $inValue;
769 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editLanguageHeader', TRUE) . ' ]</option>';
770 } else {
771 $inValue = 'pages:' . $this->id;
772 $is_selected += (int)$edit_record == $inValue;
773 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editPageProperties', TRUE) . ' ]</option>';
774 }
775 // Selecting all content elements from this language and allowed colPos:
776 $whereClause = 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content');
777 if (!$this->getBackendUser()->user['admin']) {
778 $whereClause .= ' AND editlock = 0';
779 }
780 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
781 $colPos = NULL;
782 $first = 1;
783 // Page is the pid if no record to put this after.
784 $prev = $this->id;
785 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
786 BackendUtility::workspaceOL('tt_content', $cRow);
787 if (is_array($cRow)) {
788 if ($first) {
789 if (!$edit_record) {
790 $edit_record = 'tt_content:' . $cRow['uid'];
791 }
792 $first = 0;
793 }
794 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
795 $colPos = $cRow['colPos'];
796 $opt[] = '<option value=""></option>';
797 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
798 }
799 $inValue = 'tt_content:' . $cRow['uid'];
800 $is_selected += (int)$edit_record == $inValue;
801 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(($cRow['header'] ? $cRow['header'] : '[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title') . '] ' . strip_tags($cRow['bodytext'])), $beUser->uc['titleLen'])) . '</option>';
802 $prev = -$cRow['uid'];
803 }
804 }
805 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
806 if (!$edit_record) {
807 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
808 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
809 $is_selected += (int)$edit_record == $inValue;
810 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
811 }
812 // If none is yet selected...
813 if (!$is_selected) {
814 $opt[] = '<option value=""></option>';
815 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
816 }
817 // Splitting the edit-record cmd value into table/uid:
818 $this->eRParts = explode(':', $edit_record);
819 // Delete-button flag?
820 $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
821 // If undo-button should be rendered (depends on available items in sys_history)
822 $this->undoButton = FALSE;
823 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
824 if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
825 $this->undoButton = TRUE;
826 }
827 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
828 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
829 $R_URL_getvars = GeneralUtility::_GET();
830 unset($R_URL_getvars['popView']);
831 unset($R_URL_getvars['new_unique_uid']);
832 $R_URL_getvars['edit_record'] = $edit_record;
833 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
834 // Setting close url/return url for exiting this script:
835 // Goes to 'Columns' view if close is pressed (default)
836 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
837 if ($this->returnUrl) {
838 $this->closeUrl = $this->returnUrl;
839 }
840 // Return-url for JavaScript:
841 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
842 // Drawing the edit record selectbox
843 $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(
844 BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record='
845 ) . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
846 $content = '';
847 // Creating editing form:
848 if ($beUser->check('tables_modify', $this->eRParts[0]) && $edit_record && ($this->eRParts[0] !== 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] === 'pages' && $this->CALC_PERMS & Permission::PAGE_SHOW)) {
849 // Splitting uid parts for special features, if new:
850 list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
851 // Convert $uidVal to workspace version if any:
852 if ($uidVal != 'new') {
853 if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $this->eRParts[0], $uidVal, 'uid')) {
854 $uidVal = $draftRecord['uid'];
855 }
856 }
857 // Initializing transfer-data object:
858 $trData = GeneralUtility::makeInstance(DataPreprocessor::class);
859 $trData->addRawData = TRUE;
860 $trData->defVals[$this->eRParts[0]] = array(
861 'colPos' => (int)$ex_colPos,
862 'sys_language_uid' => (int)$this->current_sys_language
863 );
864 $trData->lockRecords = 1;
865 // 'new'
866 $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
867 $new_unique_uid = '';
868 // Getting/Making the record:
869 reset($trData->regTableItems_data);
870 $rec = current($trData->regTableItems_data);
871 if ($uidVal == 'new') {
872 $new_unique_uid = uniqid('NEW', TRUE);
873 $rec['uid'] = $new_unique_uid;
874 $rec['pid'] = (int)$ex_pid ?: $this->id;
875 $recordAccess = TRUE;
876 } else {
877 $rec['uid'] = $uidVal;
878 // Checking internals access:
879 $recordAccess = $beUser->recordEditAccessInternals($this->eRParts[0], $uidVal);
880 }
881 if (!$recordAccess) {
882 // If no edit access, print error message:
883 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1);
884 } elseif (is_array($rec)) {
885 // If the record is an array (which it will always be... :-)
886 // Create instance of TCEforms, setting defaults:
887 $tceForms = GeneralUtility::makeInstance(FormEngine::class);
888 // Render form, wrap it:
889 $panel = '';
890 $panel .= $tceForms->getMainFields($this->eRParts[0], $rec);
891 $panel = $tceForms->wrapTotal($panel, $rec, $this->eRParts[0]);
892 // Add hidden fields:
893 $theCode = $panel;
894 if ($uidVal == 'new') {
895 $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
896 }
897 $theCode .= '
898 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
899 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
900 <input type="hidden" name="redirect" value="' . htmlspecialchars(($uidVal == 'new' ? BackendUtility::getModuleUrl(
901 'web_layout',
902 array(
903 'id' => $this->id,
904 'new_unique_uid' => $new_unique_uid,
905 'returnUrl' => $this->returnUrl
906 )
907 ) : $this->R_URI)) . '" />
908 ' . FormEngine::getHiddenTokenField('tceAction');
909 // Add JavaScript as needed around the form:
910 $theCode = $tceForms->printNeededJSFunctions_top() . $theCode . $tceForms->printNeededJSFunctions();
911 // Add warning sign if record was "locked":
912 if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
913 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
914 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
915 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
916 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
917 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
918 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
919 $defaultFlashMessageQueue->enqueue($flashMessage);
920 }
921 // Add whole form as a document section:
922 $content = $this->doc->section('', $theCode);
923 }
924 } else {
925 // If no edit access, print error message:
926 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
927 }
928 // Bottom controls (function menus):
929 $q_count = $this->getNumberOfHiddenElements();
930 if ($q_count) {
931 $h_func_b = '<div class="checkbox">' .
932 '<label for="checkTt_content_showHidden">' .
933 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') .
934 (!$q_count ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>') : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
935 '</label>' .
936 '</div>';
937
938 $content .= $this->doc->section('', $h_func_b, 0, 0);
939 $content .= $this->doc->spacer(10);
940 }
941
942 // Select element matrix:
943 if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
944 $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
945 $posMap->cur_sys_language = $this->current_sys_language;
946 $HTMLcode = '';
947 // CSH:
948 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
949 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
950 $content .= $this->doc->spacer(20);
951 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
952 $content .= $this->doc->spacer(20);
953 }
954 return $content;
955 }
956
957 /**
958 * Rendering all other listings than QuickEdit
959 *
960 * @return string
961 */
962 public function renderListContent() {
963 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
964 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
965 $dbList->thumbs = $this->imagemode;
966 $dbList->no_noWrap = 1;
967 $dbList->descrTable = $this->descrTable;
968 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
969 $dbList->script = BackendUtility::getModuleUrl('web_layout');
970 $dbList->showIcon = 0;
971 $dbList->setLMargin = 0;
972 $dbList->doEdit = $this->EDIT_CONTENT;
973 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
974 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
975 $dbList->id = $this->id;
976 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
977 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
978 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
979 if (!$dbList->nextThree) {
980 $dbList->nextThree = 1;
981 }
982 $dbList->externalTables = $this->externalTables;
983 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
984 // also fills $dbList->activeTables
985 $dbList->getTableMenu($this->id);
986 // Initialize other variables:
987 $h_func = '';
988 $tableOutput = array();
989 $tableJSOutput = array();
990 $CMcounter = 0;
991 // Traverse the list of table names which has records on this page (that array is populated
992 // by the $dblist object during the function getTableMenu()):
993 foreach ($dbList->activeTables as $table => $value) {
994 $h_func_b = '';
995 if (!isset($dbList->externalTables[$table])) {
996 $q_count = $this->getNumberOfHiddenElements();
997
998 if ($q_count > 0) {
999 $h_func_b =
1000 '<div class="checkbox">'
1001 . '<label for="checkTt_content_showHidden">'
1002 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
1003 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
1004 . '</label>'
1005 . '</div>';
1006 }
1007 // Boolean: Display up/down arrows and edit icons for tt_content records
1008 $dbList->tt_contentConfig['showCommands'] = 1;
1009 // Boolean: Display info-marks or not
1010 $dbList->tt_contentConfig['showInfo'] = 1;
1011 // Setting up the tt_content columns to show:
1012 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
1013 $colList = array();
1014 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
1015 foreach ($tcaItems as $temp) {
1016 $colList[] = $temp[1];
1017 }
1018 } else {
1019 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
1020 $colList = array('1', '0', '2', '3');
1021 }
1022 if ($this->colPosList !== '') {
1023 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
1024 }
1025 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
1026 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
1027 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
1028 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
1029 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
1030 // If the function menu is set to "Language":
1031 if ($this->MOD_SETTINGS['function'] == 2) {
1032 $dbList->tt_contentConfig['languageMode'] = 1;
1033 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
1034 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
1035 }
1036 } else {
1037 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1038 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
1039 } else {
1040 $h_func = '';
1041 }
1042 }
1043 // Start the dblist object:
1044 $dbList->itemsLimitSingleTable = 1000;
1045 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1046 $dbList->counter = $CMcounter;
1047 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1048 // Render versioning selector:
1049 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1050 // Generate the list of elements here:
1051 $dbList->generateList();
1052 // Adding the list content to the tableOutput variable:
1053 $tableOutput[$table] = ($h_func ? $h_func . '<br /><span style="width: 1px; height: 4px; display: inline-block;"></span><br />' : '') . $dbList->HTMLcode . ($h_func_b ? '<span style="width: 1px; height: 10px; display:inline-block;"></span><br />' . $h_func_b : '');
1054 // ... and any accumulated JavaScript goes the same way!
1055 $tableJSOutput[$table] = $dbList->JScode;
1056 // Increase global counter:
1057 $CMcounter += $dbList->counter;
1058 // Reset variables after operation:
1059 $dbList->HTMLcode = '';
1060 $dbList->JScode = '';
1061 $h_func = '';
1062 }
1063 // END: traverse tables
1064 // For Context Sensitive Menus:
1065 $this->doc->getContextMenuCode();
1066 // Init the content
1067 $content = '';
1068 // Additional header content
1069 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1070 if (is_array($headerContentHook)) {
1071 foreach ($headerContentHook as $hook) {
1072 $params = array();
1073 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1074 }
1075 }
1076 // Add the content for each table we have rendered (traversing $tableOutput variable)
1077 foreach ($tableOutput as $table => $output) {
1078 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1079 $content .= $this->doc->sectionEnd();
1080 }
1081 // Making search form:
1082 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1083 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
1084 $this->markers['BUTTONLIST_ADDITIONAL'] = '<a href="#" class="t3js-toggle-search-toolbox" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', TRUE) . '">'.IconUtility::getSpriteIcon('apps-toolbar-menu-search') . '</a>';
1085 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1086 }
1087 // Additional footer content
1088 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1089 if (is_array($footerContentHook)) {
1090 foreach ($footerContentHook as $hook) {
1091 $params = array();
1092 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1093 }
1094 }
1095 return $content;
1096 }
1097
1098 /**
1099 * Print accumulated content of module
1100 *
1101 * @return void
1102 */
1103 public function printContent() {
1104 echo $this->content;
1105 }
1106
1107 /***************************
1108 *
1109 * Sub-content functions, rendering specific parts of the module content.
1110 *
1111 ***************************/
1112 /**
1113 * Create the panel of buttons for submitting the form or otherwise perform operations.
1114 *
1115 * @param string $function Identifier for function of module
1116 * @return array all available buttons as an assoc. array
1117 */
1118 protected function getButtons($function = '') {
1119 /** @var IconFactory $iconFactory */
1120 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
1121
1122 $lang = $this->getLanguageService();
1123 $buttons = array(
1124 'view' => '',
1125 'history_page' => '',
1126 'new_content' => '',
1127 'move_page' => '',
1128 'move_record' => '',
1129 'new_page' => '',
1130 'edit_page' => '',
1131 'edit_language' => '',
1132 'csh' => '',
1133 'shortcut' => '',
1134 'cache' => '',
1135 'savedok' => '',
1136 'save_close' => '',
1137 'savedokshow' => '',
1138 'closedok' => '',
1139 'deletedok' => '',
1140 'undo' => '',
1141 'history_record' => ''
1142 );
1143 // View page
1144 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1145 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL) . '</a>';
1146 }
1147 // Shortcut
1148 if ($this->getBackendUser()->mayMakeShortcut()) {
1149 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
1150 }
1151 // Cache
1152 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1153 $buttons['cache'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_layout', array('id' => $this->pageinfo['uid'], 'clear_cache' => '1'))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', TRUE) . '">' . IconUtility::getSpriteIcon('actions-system-cache-clear') . '</a>';
1154 }
1155 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1156 // Move record
1157 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1158 $urlParameters = [
1159 'table' => $this->eRParts[0],
1160 'uid' => $this->eRParts[1],
1161 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1162 ];
1163 $buttons['move_record'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('move_element', $urlParameters)) . '">' . IconUtility::getSpriteIcon(('actions-' . ($this->eRParts[0] == 'tt_content' ? 'document' : 'page') . '-move'), array('class' => 'c-inputButton', 'title' => $lang->getLL(('move_' . ($this->eRParts[0] == 'tt_content' ? 'record' : 'page')), TRUE))) . '</a>';
1164 }
1165
1166 // Edit page properties and page language overlay icons
1167 if ($this->pageIsNotLockedForEditors()) {
1168
1169 // Edit localized page_language_overlay only when one specific language is selected
1170 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1171 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1172 'uid',
1173 'pages_language_overlay',
1174 'pid = ' . (int)$this->id . ' ' .
1175 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1176 BackendUtility::deleteClause('pages_language_overlay') .
1177 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1178 '',
1179 '',
1180 '',
1181 'sys_language_uid'
1182 );
1183
1184 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1185 $buttons['edit_language'] = '<a href="#" ' .
1186 'onclick="' . $editLanguageOnClick . '"' .
1187 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1188 IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1189 '</a>';
1190 }
1191
1192
1193 // Edit page properties
1194 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1195 $buttons['edit_page'] = '<a href="#" ' .
1196 'onclick="' . $editPageOnClick . '"' .
1197 'title="' . $lang->getLL('editPageProperties', TRUE) . '">' .
1198 IconUtility::getSpriteIcon('actions-page-open') .
1199 '</a>';
1200 }
1201
1202 // Add CSH (Context Sensitive Help) icon to tool bar
1203 if ($function == 'quickEdit') {
1204 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1205 } else {
1206 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1207 }
1208 if ($function == 'quickEdit') {
1209 // Save record
1210 $buttons['savedok'] = '<button class="c-inputButton" name="_savedok_x" value="1" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '">'
1211 . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)
1212 . '</button>';
1213 // Save and close
1214 $buttons['save_close'] = '<button class="c-inputButton" name="_saveandclosedok_x" value="1" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '">'
1215 . $this->iconFactory->getIcon('actions-document-save-close', Icon::SIZE_SMALL)
1216 . '</button>';
1217 // Save record and show page
1218 $buttons['savedokshow'] = '<a href="#" onclick="' . htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR.checkAndDoSubmit(1); return false;') . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', TRUE) . '">'
1219 . $this->iconFactory->getIcon('actions-document-save-view', Icon::SIZE_SMALL)
1220 . '</a>';
1221 // Close record
1222 $buttons['closedok'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue($this->closeUrl) . '); return false;') . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">'
1223 . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)
1224 . '</a>';
1225 // Delete record
1226 if ($this->deleteButton) {
1227 $buttons['deletedok'] = '<a href="#" onclick="' . htmlspecialchars('return deleteRecord(' . GeneralUtility::quoteJSvalue($this->eRParts[0]) . ',' . GeneralUtility::quoteJSvalue($this->eRParts[1]) . ',' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?id=' . $this->id) . ');') . '" title="' . $lang->getLL('deleteItem', TRUE) . '">'
1228 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)
1229 . '</a>';
1230 }
1231 if ($this->undoButton) {
1232 // Undo button
1233 $buttons['undo'] = '<a href="#"
1234 onclick="' . htmlspecialchars('window.location.href=' .
1235 GeneralUtility::quoteJSvalue(
1236 BackendUtility::getModuleUrl(
1237 'record_history',
1238 array(
1239 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1240 'revert' => 'ALL_FIELDS',
1241 'sumUp' => -1,
1242 'returnUrl' => $this->R_URI,
1243 )
1244 )
1245 ) . '; return false;') . '"
1246 title="' . htmlspecialchars(sprintf($lang->getLL('undoLastChange'), BackendUtility::calcAge($GLOBALS['EXEC_TIME'] - $this->undoButtonR['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . $this->iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL) . '</a>';
1247 // History button
1248 $buttons['history_record'] = '<a href="#"
1249 onclick="' . htmlspecialchars('jumpToUrl(' .
1250 GeneralUtility::quoteJSvalue(
1251 BackendUtility::getModuleUrl(
1252 'record_history',
1253 array(
1254 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1255 'returnUrl' => $this->R_URI,
1256 )
1257 ) . '#latest'
1258 ) . ');return false;') . '"
1259 title="' . $lang->getLL('recordHistory', TRUE) . '">' . $iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL) . '</a>';
1260 }
1261 }
1262 }
1263 return $buttons;
1264 }
1265
1266 /*******************************
1267 *
1268 * Other functions
1269 *
1270 ******************************/
1271 /**
1272 * Returns the number of hidden elements (including those hidden by start/end times)
1273 * on the current page (for the current sys_language)
1274 *
1275 * @return int
1276 */
1277 public function getNumberOfHiddenElements() {
1278 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1279 'uid',
1280 'tt_content',
1281 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . BackendUtility::BEenableFields('tt_content', 1) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content')
1282 );
1283 }
1284
1285 /**
1286 * Returns URL to the current script.
1287 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1288 *
1289 * @param array $params Parameters array, merged with global GET vars.
1290 * @return string URL
1291 */
1292 public function local_linkThisScript($params) {
1293 $params['popView'] = '';
1294 $params['new_unique_uid'] = '';
1295 return GeneralUtility::linkThisScript($params);
1296 }
1297
1298 /**
1299 * Returns a SQL query for selecting sys_language records.
1300 *
1301 * @param int $id Page id: If zero, the query will select all sys_language records from root level which are NOT hidden. If set to another value, the query will select all sys_language records that has a pages_language_overlay record on that page (and is not hidden, unless you are admin user)
1302 * @return string Return query string.
1303 */
1304 public function exec_languageQuery($id) {
1305 if ($id) {
1306 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1307 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1308 return $this->getDatabaseConnection()->exec_SELECTquery(
1309 'sys_language.*',
1310 'pages_language_overlay,sys_language',
1311 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1312 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1313 'pages_language_overlay.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
1314 'sys_language.title'
1315 );
1316 } else {
1317 return $this->getDatabaseConnection()->exec_SELECTquery(
1318 'sys_language.*',
1319 'sys_language',
1320 'sys_language.hidden=0',
1321 '',
1322 'sys_language.title'
1323 );
1324 }
1325 }
1326
1327 /**
1328 * Get used languages in a colPos of a page
1329 *
1330 * @param int $pageId
1331 * @param int $colPos
1332 * @return bool|\mysqli_result|object
1333 */
1334 public function getUsedLanguagesInPageAndColumn($pageId, $colPos) {
1335 if (!isset($languagesInColumnCache[$pageId])) {
1336 $languagesInColumnCache[$pageId] = array();
1337 }
1338 if (!isset($languagesInColumnCache[$pageId][$colPos])) {
1339 $languagesInColumnCache[$pageId][$colPos] = array();
1340 }
1341
1342 if (empty($languagesInColumnCache[$pageId][$colPos])) {
1343 $exQ = BackendUtility::deleteClause('tt_content') .
1344 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1345
1346 $databaseConnection = $this->getDatabaseConnection();
1347 $res = $databaseConnection->exec_SELECTquery(
1348 'sys_language.*',
1349 'tt_content,sys_language',
1350 'tt_content.sys_language_uid=sys_language.uid AND tt_content.colPos = ' . (int)$colPos . ' AND tt_content.pid=' . (int)$pageId . $exQ .
1351 BackendUtility::versioningPlaceholderClause('tt_content'),
1352 'tt_content.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
1353 'sys_language.title'
1354 );
1355 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1356 $languagesInColumnCache[$pageId][$colPos][$row['uid']] = $row;
1357 }
1358 $databaseConnection->sql_free_result($res);
1359 }
1360
1361 return $languagesInColumnCache[$pageId][$colPos];
1362 }
1363
1364 /**
1365 * Check if a column of a page for a language is empty. Translation records are ignored here!
1366 *
1367 * @param int $colPos
1368 * @param int $languageId
1369 * @return bool
1370 */
1371 public function isColumnEmpty($colPos, $languageId) {
1372 foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
1373 if ((int)$row['l18n_parent'] === 0) {
1374 return FALSE;
1375 }
1376 }
1377 return TRUE;
1378 }
1379
1380 /**
1381 * Get elements for a column and a language
1382 *
1383 * @param int $pageId
1384 * @param int $colPos
1385 * @param int $languageId
1386 * @return array
1387 */
1388 public function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId) {
1389 if (!isset($this->contentElementCache[$languageId][$colPos])) {
1390 $languageId = (int)$languageId;
1391 $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
1392 if ($languageId > 0) {
1393 $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1394 }
1395
1396 $databaseConnection = $this->getDatabaseConnection();
1397 $res = $databaseConnection->exec_SELECTquery(
1398 'tt_content.uid',
1399 'tt_content,sys_language',
1400 $whereClause
1401 );
1402 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1403 $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
1404 }
1405 $databaseConnection->sql_free_result($res);
1406 }
1407 if (is_array($this->contentElementCache[$languageId][$colPos])) {
1408 return array_keys($this->contentElementCache[$languageId][$colPos]);
1409 }
1410 return array();
1411 }
1412
1413 /**
1414 * Check the editlock access
1415 *
1416 * @return bool
1417 */
1418 public function pageIsNotLockedForEditors() {
1419 return $this->getBackendUser()->isAdmin() || !($this->CALC_PERMS & Permission::PAGE_EDIT && $this->pageinfo['editlock']);
1420 }
1421
1422 /**
1423 * Returns LanguageService
1424 *
1425 * @return \TYPO3\CMS\Lang\LanguageService
1426 */
1427 protected function getLanguageService() {
1428 return $GLOBALS['LANG'];
1429 }
1430
1431 /**
1432 * Returns the current BE user.
1433 *
1434 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1435 */
1436 protected function getBackendUser() {
1437 return $GLOBALS['BE_USER'];
1438 }
1439
1440 /**
1441 * Returns the database connection
1442 *
1443 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1444 */
1445 protected function getDatabaseConnection() {
1446 return $GLOBALS['TYPO3_DB'];
1447 }
1448
1449 /**
1450 * Returns current PageRenderer
1451 *
1452 * @return PageRenderer
1453 */
1454 protected function getPageRenderer() {
1455 return GeneralUtility::makeInstance(PageRenderer::class);
1456 }
1457 }