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