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