[TASK] BACK_PATH DocumentTemplate
[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 * Back path of the module
161 *
162 * @var string
163 */
164 public $backPath;
165
166 /**
167 * "Pseudo" Description -table name
168 *
169 * @var string
170 */
171 public $descrTable;
172
173 /**
174 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
175 *
176 * @var string
177 */
178 public $colPosList;
179
180 /**
181 * Flag: If content can be edited or not.
182 *
183 * @var bool
184 */
185 public $EDIT_CONTENT;
186
187 /**
188 * Users permissions integer for this page.
189 *
190 * @var int
191 */
192 public $CALC_PERMS;
193
194 /**
195 * Currently selected language for editing content elements
196 *
197 * @var int
198 */
199 public $current_sys_language;
200
201 /**
202 * Module configuration
203 *
204 * @var array
205 */
206 public $MCONF = array();
207
208 /**
209 * Menu configuration
210 *
211 * @var array
212 */
213 public $MOD_MENU = array();
214
215 /**
216 * Module settings (session variable)
217 *
218 * @var array
219 */
220 public $MOD_SETTINGS = array();
221
222 /**
223 * Array of tables to be listed by the Web > Page module in addition to the default tables
224 *
225 * @var array
226 */
227 public $externalTables = array();
228
229 /**
230 * Module output accumulation
231 *
232 * @var string
233 */
234 public $content;
235
236 /**
237 * Function menu temporary storage
238 *
239 * @var string
240 */
241 public $topFuncMenu;
242
243 /**
244 * List of column-integers accessible to the current BE user.
245 * Is set from TSconfig, default is $colPosList
246 *
247 * @var string
248 */
249 public $activeColPosList;
250
251 /**
252 * Markers array
253 *
254 * @var array
255 */
256 protected $markers = array();
257
258 /**
259 * @var array
260 */
261 protected $eRParts = array();
262
263 /**
264 * @var string
265 */
266 protected $editSelect;
267
268 /**
269 * @var bool
270 */
271 protected $deleteButton;
272
273 /**
274 * @var bool
275 */
276 protected $undoButton;
277
278 /**
279 * @var array
280 */
281 protected $undoButtonR;
282
283 /**
284 * @var string
285 */
286 protected $R_URI;
287
288 /**
289 * @var string
290 */
291 protected $closeUrl;
292
293 /**
294 * Caches the available languages in a colPos
295 *
296 * @var array
297 */
298 protected $languagesInColumnCache = array();
299
300 /**
301 * Caches the amount of content elements as a matrix
302 *
303 * @var array
304 * @internal
305 */
306 public $contentElementCache = array();
307
308 /**
309 * Initializing the module
310 *
311 * @return void
312 */
313 public function init() {
314 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
315
316 // Setting module configuration / page select clause
317 $this->MCONF = $GLOBALS['MCONF'];
318 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
319 $this->backPath = $GLOBALS['BACK_PATH'];
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, $GLOBALS['BACK_PATH'], 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->backPath = $GLOBALS['BACK_PATH'];
945 $posMap->cur_sys_language = $this->current_sys_language;
946 $HTMLcode = '';
947 // CSH:
948 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
949 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
950 $content .= $this->doc->spacer(20);
951 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
952 $content .= $this->doc->spacer(20);
953 }
954 return $content;
955 }
956
957 /**
958 * Rendering all other listings than QuickEdit
959 *
960 * @return string
961 */
962 public function renderListContent() {
963 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
964 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
965 $dbList->backPath = $GLOBALS['BACK_PATH'];
966 $dbList->thumbs = $this->imagemode;
967 $dbList->no_noWrap = 1;
968 $dbList->descrTable = $this->descrTable;
969 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
970 $dbList->script = BackendUtility::getModuleUrl('web_layout');
971 $dbList->showIcon = 0;
972 $dbList->setLMargin = 0;
973 $dbList->doEdit = $this->EDIT_CONTENT;
974 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
975 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
976 $dbList->id = $this->id;
977 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
978 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
979 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
980 if (!$dbList->nextThree) {
981 $dbList->nextThree = 1;
982 }
983 $dbList->externalTables = $this->externalTables;
984 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
985 // also fills $dbList->activeTables
986 $dbList->getTableMenu($this->id);
987 // Initialize other variables:
988 $h_func = '';
989 $tableOutput = array();
990 $tableJSOutput = array();
991 $CMcounter = 0;
992 // Traverse the list of table names which has records on this page (that array is populated
993 // by the $dblist object during the function getTableMenu()):
994 foreach ($dbList->activeTables as $table => $value) {
995 $h_func_b = '';
996 if (!isset($dbList->externalTables[$table])) {
997 $q_count = $this->getNumberOfHiddenElements();
998
999 if ($q_count > 0) {
1000 $h_func_b =
1001 '<div class="checkbox">'
1002 . '<label for="checkTt_content_showHidden">'
1003 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
1004 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
1005 . '</label>'
1006 . '</div>';
1007 }
1008 // Boolean: Display up/down arrows and edit icons for tt_content records
1009 $dbList->tt_contentConfig['showCommands'] = 1;
1010 // Boolean: Display info-marks or not
1011 $dbList->tt_contentConfig['showInfo'] = 1;
1012 // Setting up the tt_content columns to show:
1013 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
1014 $colList = array();
1015 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
1016 foreach ($tcaItems as $temp) {
1017 $colList[] = $temp[1];
1018 }
1019 } else {
1020 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
1021 $colList = array('1', '0', '2', '3');
1022 }
1023 if ($this->colPosList !== '') {
1024 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
1025 }
1026 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
1027 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
1028 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
1029 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
1030 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
1031 // If the function menu is set to "Language":
1032 if ($this->MOD_SETTINGS['function'] == 2) {
1033 $dbList->tt_contentConfig['languageMode'] = 1;
1034 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
1035 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
1036 }
1037 } else {
1038 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1039 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
1040 } else {
1041 $h_func = '';
1042 }
1043 }
1044 // Start the dblist object:
1045 $dbList->itemsLimitSingleTable = 1000;
1046 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1047 $dbList->counter = $CMcounter;
1048 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1049 // Render versioning selector:
1050 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1051 // Generate the list of elements here:
1052 $dbList->generateList();
1053 // Adding the list content to the tableOutput variable:
1054 $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 : '');
1055 // ... and any accumulated JavaScript goes the same way!
1056 $tableJSOutput[$table] = $dbList->JScode;
1057 // Increase global counter:
1058 $CMcounter += $dbList->counter;
1059 // Reset variables after operation:
1060 $dbList->HTMLcode = '';
1061 $dbList->JScode = '';
1062 $h_func = '';
1063 }
1064 // END: traverse tables
1065 // For Context Sensitive Menus:
1066 $this->doc->getContextMenuCode();
1067 // Init the content
1068 $content = '';
1069 // Additional header content
1070 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1071 if (is_array($headerContentHook)) {
1072 foreach ($headerContentHook as $hook) {
1073 $params = array();
1074 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1075 }
1076 }
1077 // Add the content for each table we have rendered (traversing $tableOutput variable)
1078 foreach ($tableOutput as $table => $output) {
1079 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1080 $content .= $this->doc->sectionEnd();
1081 }
1082 // Making search form:
1083 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1084 $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>';
1085 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1086 }
1087 // Additional footer content
1088 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1089 if (is_array($footerContentHook)) {
1090 foreach ($footerContentHook as $hook) {
1091 $params = array();
1092 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1093 }
1094 }
1095 return $content;
1096 }
1097
1098 /**
1099 * Print accumulated content of module
1100 *
1101 * @return void
1102 */
1103 public function printContent() {
1104 echo $this->content;
1105 }
1106
1107 /***************************
1108 *
1109 * Sub-content functions, rendering specific parts of the module content.
1110 *
1111 ***************************/
1112 /**
1113 * Create the panel of buttons for submitting the form or otherwise perform operations.
1114 *
1115 * @param string $function Identifier for function of module
1116 * @return array all available buttons as an assoc. array
1117 */
1118 protected function getButtons($function = '') {
1119 $lang = $this->getLanguageService();
1120 $buttons = array(
1121 'view' => '',
1122 'history_page' => '',
1123 'new_content' => '',
1124 'move_page' => '',
1125 'move_record' => '',
1126 'new_page' => '',
1127 'edit_page' => '',
1128 'edit_language' => '',
1129 'csh' => '',
1130 'shortcut' => '',
1131 'cache' => '',
1132 'savedok' => '',
1133 'save_close' => '',
1134 'savedokshow' => '',
1135 'closedok' => '',
1136 'deletedok' => '',
1137 'undo' => '',
1138 'history_record' => ''
1139 );
1140 // View page
1141 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1142 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
1143 }
1144 // Shortcut
1145 if ($this->getBackendUser()->mayMakeShortcut()) {
1146 $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']);
1147 }
1148 // Cache
1149 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1150 $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>';
1151 }
1152 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1153 // Move record
1154 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1155 $urlParameters = [
1156 'table' => $this->eRParts[0],
1157 'uid' => $this->eRParts[1],
1158 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1159 ];
1160 $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>';
1161 }
1162
1163 // Edit page properties and page language overlay icons
1164 if ($this->pageIsNotLockedForEditors()) {
1165
1166 // Edit localized page_language_overlay only when one specific language is selected
1167 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1168 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1169 'uid',
1170 'pages_language_overlay',
1171 'pid = ' . (int)$this->id . ' ' .
1172 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1173 BackendUtility::deleteClause('pages_language_overlay') .
1174 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1175 '',
1176 '',
1177 '',
1178 'sys_language_uid'
1179 );
1180
1181 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1182 $buttons['edit_language'] = '<a href="#" ' .
1183 'onclick="' . $editLanguageOnClick . '"' .
1184 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1185 IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1186 '</a>';
1187 }
1188
1189
1190 // Edit page properties
1191 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1192 $buttons['edit_page'] = '<a href="#" ' .
1193 'onclick="' . $editPageOnClick . '"' .
1194 'title="' . $lang->getLL('editPageProperties', TRUE) . '">' .
1195 IconUtility::getSpriteIcon('actions-page-open') .
1196 '</a>';
1197 }
1198
1199 // Add CSH (Context Sensitive Help) icon to tool bar
1200 if ($function == 'quickEdit') {
1201 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1202 } else {
1203 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1204 }
1205 if ($function == 'quickEdit') {
1206 // Save record
1207 $buttons['savedok'] = '<button class="c-inputButton" name="_savedok_x">'
1208 . IconUtility::getSpriteIcon('actions-document-save', array('title' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE)))
1209 . '</button>';
1210 // Save and close
1211 $buttons['save_close'] = '<button class="c-inputButton" name="_saveandclosedok_x">'
1212 . IconUtility::getSpriteIcon('actions-document-save-close', array('title' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE)))
1213 . '</button>';
1214 // Save record and show page
1215 $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>';
1216 // Close record
1217 $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>';
1218 // Delete record
1219 if ($this->deleteButton) {
1220 $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>';
1221 }
1222 if ($this->undoButton) {
1223 // Undo button
1224 $buttons['undo'] = '<a href="#"
1225 onclick="' . htmlspecialchars('window.location.href=' .
1226 GeneralUtility::quoteJSvalue(
1227 $GLOBALS['BACK_PATH'] .
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')))) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
1239 // History button
1240 $buttons['history_record'] = '<a href="#"
1241 onclick="' . htmlspecialchars('jumpToUrl(' .
1242 GeneralUtility::quoteJSvalue(
1243 $GLOBALS['BACK_PATH'] .
1244 BackendUtility::getModuleUrl(
1245 'record_history',
1246 array(
1247 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1248 'returnUrl' => $this->R_URI,
1249 )
1250 ) . '#latest'
1251 ) . ');return false;') . '"
1252 title="' . $lang->getLL('recordHistory', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1253 }
1254 }
1255 }
1256 return $buttons;
1257 }
1258
1259 /*******************************
1260 *
1261 * Other functions
1262 *
1263 ******************************/
1264 /**
1265 * Returns the number of hidden elements (including those hidden by start/end times)
1266 * on the current page (for the current sys_language)
1267 *
1268 * @return int
1269 */
1270 public function getNumberOfHiddenElements() {
1271 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1272 'uid',
1273 'tt_content',
1274 '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')
1275 );
1276 }
1277
1278 /**
1279 * Returns URL to the current script.
1280 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1281 *
1282 * @param array $params Parameters array, merged with global GET vars.
1283 * @return string URL
1284 */
1285 public function local_linkThisScript($params) {
1286 $params['popView'] = '';
1287 $params['new_unique_uid'] = '';
1288 return GeneralUtility::linkThisScript($params);
1289 }
1290
1291 /**
1292 * Returns a SQL query for selecting sys_language records.
1293 *
1294 * @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)
1295 * @return string Return query string.
1296 */
1297 public function exec_languageQuery($id) {
1298 if ($id) {
1299 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1300 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1301 return $this->getDatabaseConnection()->exec_SELECTquery(
1302 'sys_language.*',
1303 'pages_language_overlay,sys_language',
1304 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1305 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1306 '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',
1307 'sys_language.title'
1308 );
1309 } else {
1310 return $this->getDatabaseConnection()->exec_SELECTquery(
1311 'sys_language.*',
1312 'sys_language',
1313 'sys_language.hidden=0',
1314 '',
1315 'sys_language.title'
1316 );
1317 }
1318 }
1319
1320 /**
1321 * Get used languages in a colPos of a page
1322 *
1323 * @param int $pageId
1324 * @param int $colPos
1325 * @return bool|\mysqli_result|object
1326 */
1327 public function getUsedLanguagesInPageAndColumn($pageId, $colPos) {
1328 if (!isset($languagesInColumnCache[$pageId])) {
1329 $languagesInColumnCache[$pageId] = array();
1330 }
1331 if (!isset($languagesInColumnCache[$pageId][$colPos])) {
1332 $languagesInColumnCache[$pageId][$colPos] = array();
1333 }
1334
1335 if (empty($languagesInColumnCache[$pageId][$colPos])) {
1336 $exQ = BackendUtility::deleteClause('tt_content') .
1337 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1338
1339 $databaseConnection = $this->getDatabaseConnection();
1340 $res = $databaseConnection->exec_SELECTquery(
1341 'sys_language.*',
1342 'tt_content,sys_language',
1343 'tt_content.sys_language_uid=sys_language.uid AND tt_content.colPos = ' . (int)$colPos . ' AND tt_content.pid=' . (int)$pageId . $exQ .
1344 BackendUtility::versioningPlaceholderClause('tt_content'),
1345 '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',
1346 'sys_language.title'
1347 );
1348 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1349 $languagesInColumnCache[$pageId][$colPos][$row['uid']] = $row;
1350 }
1351 $databaseConnection->sql_free_result($res);
1352 }
1353
1354 return $languagesInColumnCache[$pageId][$colPos];
1355 }
1356
1357 /**
1358 * Check if a column of a page for a language is empty. Translation records are ignored here!
1359 *
1360 * @param int $colPos
1361 * @param int $languageId
1362 * @return bool
1363 */
1364 public function isColumnEmpty($colPos, $languageId) {
1365 foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
1366 if ((int)$row['l18n_parent'] === 0) {
1367 return FALSE;
1368 }
1369 }
1370 return TRUE;
1371 }
1372
1373 /**
1374 * Get elements for a column and a language
1375 *
1376 * @param int $pageId
1377 * @param int $colPos
1378 * @param int $languageId
1379 * @return array
1380 */
1381 public function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId) {
1382 if (!isset($this->contentElementCache[$languageId][$colPos])) {
1383 $languageId = (int)$languageId;
1384 $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
1385 if ($languageId > 0) {
1386 $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1387 }
1388
1389 $databaseConnection = $this->getDatabaseConnection();
1390 $res = $databaseConnection->exec_SELECTquery(
1391 'tt_content.uid',
1392 'tt_content,sys_language',
1393 $whereClause
1394 );
1395 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1396 $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
1397 }
1398 $databaseConnection->sql_free_result($res);
1399 }
1400 if (is_array($this->contentElementCache[$languageId][$colPos])) {
1401 return array_keys($this->contentElementCache[$languageId][$colPos]);
1402 }
1403 return array();
1404 }
1405
1406 /**
1407 * Check the editlock access
1408 *
1409 * @return bool
1410 */
1411 public function pageIsNotLockedForEditors() {
1412 return !($this->pageinfo['editlock'] && ($this->CALC_PERMS & Permission::PAGE_EDIT));
1413 }
1414
1415 /**
1416 * Returns LanguageService
1417 *
1418 * @return \TYPO3\CMS\Lang\LanguageService
1419 */
1420 protected function getLanguageService() {
1421 return $GLOBALS['LANG'];
1422 }
1423
1424 /**
1425 * Returns the current BE user.
1426 *
1427 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1428 */
1429 protected function getBackendUser() {
1430 return $GLOBALS['BE_USER'];
1431 }
1432
1433 /**
1434 * Returns the database connection
1435 *
1436 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1437 */
1438 protected function getDatabaseConnection() {
1439 return $GLOBALS['TYPO3_DB'];
1440 }
1441
1442 }