11c5502fbe8512842eee89651534f72cc6447c70
[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->backPath = $GLOBALS['BACK_PATH'];
523 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
524
525 // override the default jumpToUrl
526 $this->doc->JScodeArray['jumpToUrl'] = '
527 function jumpToUrl(URL,formEl) {
528 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
529 if (!TBE_EDITOR.isFormChanged()) {
530 window.location.href = URL;
531 } else if (formEl) {
532 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
533 }
534 } else {
535 window.location.href = URL;
536 }
537 }
538 ';
539
540 $this->doc->JScode .= $this->doc->wrapScriptTags('
541 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
542 if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
543 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->id)) : '') . '
544
545 function deleteRecord(table,id,url) { //
546 if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
547 window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC=' . $this->getBackendUser()->veriCode() . BackendUtility::getUrlToken('tceAction') . '&prErr=1&uPT=1";
548 }
549 return false;
550 }
551 ');
552 $this->doc->JScode .= $this->doc->wrapScriptTags('
553 var DTM_array = new Array();
554 var DTM_origClass = new String();
555
556 // if tabs are used in a popup window the array might not exists
557 if(!top.DTM_currentTabs) {
558 top.DTM_currentTabs = new Array();
559 }
560
561 function DTM_activate(idBase,index,doToogle) { //
562 // Hiding all:
563 if (DTM_array[idBase]) {
564 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
565 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
566 document.getElementById(DTM_array[idBase][cnt]+"-DIV").className = "tab-pane";
567 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").value = "tab";
568 }
569 }
570 }
571
572 // Showing one:
573 if (document.getElementById(idBase+"-"+index+"-DIV")) {
574 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").className === "tab-pane active") {
575 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane";
576 if(DTM_origClass=="") {
577 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "tab";
578 } else {
579 DTM_origClass = "tab";
580 }
581 top.DTM_currentTabs[idBase] = -1;
582 } else {
583 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane active";
584 if(DTM_origClass=="") {
585 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "active";
586 } else {
587 DTM_origClass = "active";
588 }
589 top.DTM_currentTabs[idBase] = index;
590 }
591 }
592 }
593 function DTM_toggle(idBase,index,isInit) { //
594 // Showing one:
595 if (document.getElementById(idBase+"-"+index+"-DIV")) {
596 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
597 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane";
598 if(isInit) {
599 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "tab";
600 } else {
601 DTM_origClass = "tab";
602 }
603 top.DTM_currentTabs[idBase+"-"+index] = 0;
604 } else {
605 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane active";
606 if(isInit) {
607 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "active";
608 } else {
609 DTM_origClass = "active";
610 }
611 top.DTM_currentTabs[idBase+"-"+index] = 1;
612 }
613 }
614 }
615 ');
616 // Setting doc-header
617 $this->doc->form = '<form action="' . htmlspecialchars(
618 BackendUtility::getModuleUrl(
619 'web_layout', array('id' => $this->id, 'imagemode' => $this->imagemode)
620 )) . '" method="post">';
621 // Creating the top function menu:
622 $this->topFuncMenu = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'], '', '');
623 $languageMenu = count($this->MOD_MENU['language']) > 1 ? $lang->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', TRUE) . BackendUtility::getFuncMenu($this->id, 'SET[language]', $this->current_sys_language, $this->MOD_MENU['language'], '', '') : '';
624 // Find backend layout / coumns
625 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
626 if (!empty($backendLayout['__colPosList'])) {
627 $this->colPosList = implode(',', $backendLayout['__colPosList']);
628 }
629 // Removing duplicates, if any
630 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
631 // Accessible columns
632 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
633 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
634 // Match with the list which is present in the colPosList for the current page
635 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
636 $this->activeColPosList = array_unique(array_intersect(
637 $this->activeColPosList,
638 $this->colPosList
639 ));
640 }
641 } else {
642 $this->activeColPosList = $this->colPosList;
643 }
644 $this->activeColPosList = implode(',', $this->activeColPosList);
645 $this->colPosList = implode(',', $this->colPosList);
646
647 $body = '';
648 $body .= $this->getHeaderFlashMessagesForCurrentPid();
649 // Render the primary module content:
650 if ($this->MOD_SETTINGS['function'] == 0) {
651 // QuickEdit
652 $body .= $this->renderQuickEdit();
653 } else {
654 // Page title
655 $body .= $this->doc->header($this->getLocalizedPageTitle());
656 // All other listings
657 $body .= $this->renderListContent();
658 }
659 // Setting up the buttons and markers for docheader
660 $docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
661 $this->markers['CSH'] = $docHeaderButtons['csh'];
662 $this->markers['TOP_FUNCTION_MENU'] = $this->topFuncMenu . $this->editSelect;
663 $this->markers['LANGSELECTOR'] = $languageMenu;
664 $this->markers['CONTENT'] = $body;
665 // Build the <body> for the module
666 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
667 // Renders the module page
668 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
669 } else {
670 // If no access or id value, create empty document:
671 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
672 $this->doc->backPath = $GLOBALS['BACK_PATH'];
673 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
674 $this->doc->JScode = $this->doc->wrapScriptTags('
675 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
676 ');
677
678 $body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
679
680 $title = $lang->getLL('clickAPage_header');
681 $message = $lang->getLL('clickAPage_content');
682
683 $view = GeneralUtility::makeInstance(StandaloneView::class);
684 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
685 $view->assignMultiple(array(
686 'title' => $title,
687 'message' => $message,
688 'state' => InfoboxViewHelper::STATE_INFO
689 ));
690 $body .= $view->render();
691
692 // Setting up the buttons and markers for docheader
693 $docHeaderButtons = array(
694 'view' => '',
695 'history_page' => '',
696 'new_content' => '',
697 'move_page' => '',
698 'move_record' => '',
699 'new_page' => '',
700 'edit_page' => '',
701 'csh' => '',
702 'shortcut' => '',
703 'cache' => '',
704 'savedok' => '',
705 'savedokshow' => '',
706 'closedok' => '',
707 'deletedok' => '',
708 'undo' => '',
709 'history_record' => '',
710 'edit_language' => ''
711 );
712 $this->markers['CSH'] = '';
713 $this->markers['TOP_FUNCTION_MENU'] = '';
714 $this->markers['LANGSELECTOR'] = '';
715 $this->markers['CONTENT'] = $body;
716 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
717 // Renders the module page
718 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
719 }
720 }
721
722 /**
723 * Rendering the quick-edit view.
724 *
725 * @return string
726 */
727 public function renderQuickEdit() {
728 $databaseConnection = $this->getDatabaseConnection();
729 $beUser = $this->getBackendUser();
730 $lang = $this->getLanguageService();
731 // Alternative template
732 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
733 // Alternative form tag; Quick Edit submits its content to tce_db.php.
734 $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);">';
735 // Setting up the context sensitive menu:
736 $this->doc->getContextMenuCode();
737 // Set the edit_record value for internal use in this function:
738 $edit_record = $this->edit_record;
739 // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
740 if (substr($edit_record, 0, 9) == '_EDIT_COL') {
741 $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');
742 $idListA = array();
743 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
744 $idListA[] = $cRow['uid'];
745 }
746 $url = BackendUtility::getModuleUrl('record_edit', array(
747 'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
748 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
749 ));
750 HttpUtility::redirect($url);
751 }
752 // If the former record edited was the creation of a NEW record, this will look up the created records uid:
753 if ($this->new_unique_uid) {
754 $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
755 $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
756 if (is_array($sys_log_row)) {
757 $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
758 }
759 }
760 // Creating the selector box, allowing the user to select which element to edit:
761 $opt = array();
762 $is_selected = 0;
763 $languageOverlayRecord = '';
764 if ($this->current_sys_language) {
765 list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
766 }
767 if (is_array($languageOverlayRecord)) {
768 $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
769 $is_selected += (int)$edit_record == $inValue;
770 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editLanguageHeader', TRUE) . ' ]</option>';
771 } else {
772 $inValue = 'pages:' . $this->id;
773 $is_selected += (int)$edit_record == $inValue;
774 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editPageProperties', TRUE) . ' ]</option>';
775 }
776 // Selecting all content elements from this language and allowed colPos:
777 $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');
778 if (!$this->getBackendUser()->user['admin']) {
779 $whereClause .= ' AND editlock = 0';
780 }
781 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
782 $colPos = NULL;
783 $first = 1;
784 // Page is the pid if no record to put this after.
785 $prev = $this->id;
786 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
787 BackendUtility::workspaceOL('tt_content', $cRow);
788 if (is_array($cRow)) {
789 if ($first) {
790 if (!$edit_record) {
791 $edit_record = 'tt_content:' . $cRow['uid'];
792 }
793 $first = 0;
794 }
795 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
796 $colPos = $cRow['colPos'];
797 $opt[] = '<option value=""></option>';
798 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
799 }
800 $inValue = 'tt_content:' . $cRow['uid'];
801 $is_selected += (int)$edit_record == $inValue;
802 $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>';
803 $prev = -$cRow['uid'];
804 }
805 }
806 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
807 if (!$edit_record) {
808 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
809 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
810 $is_selected += (int)$edit_record == $inValue;
811 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
812 }
813 // If none is yet selected...
814 if (!$is_selected) {
815 $opt[] = '<option value=""></option>';
816 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
817 }
818 // Splitting the edit-record cmd value into table/uid:
819 $this->eRParts = explode(':', $edit_record);
820 // Delete-button flag?
821 $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);
822 // If undo-button should be rendered (depends on available items in sys_history)
823 $this->undoButton = FALSE;
824 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
825 if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
826 $this->undoButton = TRUE;
827 }
828 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
829 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
830 $R_URL_getvars = GeneralUtility::_GET();
831 unset($R_URL_getvars['popView']);
832 unset($R_URL_getvars['new_unique_uid']);
833 $R_URL_getvars['edit_record'] = $edit_record;
834 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
835 // Setting close url/return url for exiting this script:
836 // Goes to 'Columns' view if close is pressed (default)
837 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
838 if ($this->returnUrl) {
839 $this->closeUrl = $this->returnUrl;
840 }
841 // Return-url for JavaScript:
842 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
843 // Drawing the edit record selectbox
844 $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(
845 BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record='
846 ) . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
847 $content = '';
848 // Creating editing form:
849 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)) {
850 // Splitting uid parts for special features, if new:
851 list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
852 // Convert $uidVal to workspace version if any:
853 if ($uidVal != 'new') {
854 if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $this->eRParts[0], $uidVal, 'uid')) {
855 $uidVal = $draftRecord['uid'];
856 }
857 }
858 // Initializing transfer-data object:
859 $trData = GeneralUtility::makeInstance(DataPreprocessor::class);
860 $trData->addRawData = TRUE;
861 $trData->defVals[$this->eRParts[0]] = array(
862 'colPos' => (int)$ex_colPos,
863 'sys_language_uid' => (int)$this->current_sys_language
864 );
865 $trData->lockRecords = 1;
866 // 'new'
867 $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
868 $new_unique_uid = '';
869 // Getting/Making the record:
870 reset($trData->regTableItems_data);
871 $rec = current($trData->regTableItems_data);
872 if ($uidVal == 'new') {
873 $new_unique_uid = uniqid('NEW', TRUE);
874 $rec['uid'] = $new_unique_uid;
875 $rec['pid'] = (int)$ex_pid ?: $this->id;
876 $recordAccess = TRUE;
877 } else {
878 $rec['uid'] = $uidVal;
879 // Checking internals access:
880 $recordAccess = $beUser->recordEditAccessInternals($this->eRParts[0], $uidVal);
881 }
882 if (!$recordAccess) {
883 // If no edit access, print error message:
884 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1);
885 } elseif (is_array($rec)) {
886 // If the record is an array (which it will always be... :-)
887 // Create instance of TCEforms, setting defaults:
888 $tceForms = GeneralUtility::makeInstance(FormEngine::class);
889 // Render form, wrap it:
890 $panel = '';
891 $panel .= $tceForms->getMainFields($this->eRParts[0], $rec);
892 $panel = $tceForms->wrapTotal($panel, $rec, $this->eRParts[0]);
893 // Add hidden fields:
894 $theCode = $panel;
895 if ($uidVal == 'new') {
896 $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
897 }
898 $theCode .= '
899 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
900 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
901 <input type="hidden" name="redirect" value="' . htmlspecialchars(($uidVal == 'new' ? BackendUtility::getModuleUrl(
902 'web_layout',
903 array(
904 'id' => $this->id,
905 'new_unique_uid' => $new_unique_uid,
906 'returnUrl' => $this->returnUrl
907 )
908 ) : $this->R_URI)) . '" />
909 ' . FormEngine::getHiddenTokenField('tceAction');
910 // Add JavaScript as needed around the form:
911 $theCode = $tceForms->printNeededJSFunctions_top() . $theCode . $tceForms->printNeededJSFunctions();
912 // Add warning sign if record was "locked":
913 if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
914 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
915 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
916 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
917 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
918 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
919 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
920 $defaultFlashMessageQueue->enqueue($flashMessage);
921 }
922 // Add whole form as a document section:
923 $content = $this->doc->section('', $theCode);
924 }
925 } else {
926 // If no edit access, print error message:
927 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
928 }
929 // Bottom controls (function menus):
930 $q_count = $this->getNumberOfHiddenElements();
931 if ($q_count) {
932 $h_func_b = '<div class="checkbox">' .
933 '<label for="checkTt_content_showHidden">' .
934 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') .
935 (!$q_count ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>') : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
936 '</label>' .
937 '</div>';
938
939 $content .= $this->doc->section('', $h_func_b, 0, 0);
940 $content .= $this->doc->spacer(10);
941 }
942
943 // Select element matrix:
944 if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
945 $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
946 $posMap->backPath = $GLOBALS['BACK_PATH'];
947 $posMap->cur_sys_language = $this->current_sys_language;
948 $HTMLcode = '';
949 // CSH:
950 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
951 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
952 $content .= $this->doc->spacer(20);
953 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
954 $content .= $this->doc->spacer(20);
955 }
956 return $content;
957 }
958
959 /**
960 * Rendering all other listings than QuickEdit
961 *
962 * @return string
963 */
964 public function renderListContent() {
965 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
966 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
967 $dbList->backPath = $GLOBALS['BACK_PATH'];
968 $dbList->thumbs = $this->imagemode;
969 $dbList->no_noWrap = 1;
970 $dbList->descrTable = $this->descrTable;
971 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
972 $dbList->script = BackendUtility::getModuleUrl('web_layout');
973 $dbList->showIcon = 0;
974 $dbList->setLMargin = 0;
975 $dbList->doEdit = $this->EDIT_CONTENT;
976 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
977 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
978 $dbList->id = $this->id;
979 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
980 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
981 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
982 if (!$dbList->nextThree) {
983 $dbList->nextThree = 1;
984 }
985 $dbList->externalTables = $this->externalTables;
986 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
987 // also fills $dbList->activeTables
988 $dbList->getTableMenu($this->id);
989 // Initialize other variables:
990 $h_func = '';
991 $tableOutput = array();
992 $tableJSOutput = array();
993 $CMcounter = 0;
994 // Traverse the list of table names which has records on this page (that array is populated
995 // by the $dblist object during the function getTableMenu()):
996 foreach ($dbList->activeTables as $table => $value) {
997 $h_func_b = '';
998 if (!isset($dbList->externalTables[$table])) {
999 $q_count = $this->getNumberOfHiddenElements();
1000
1001 if ($q_count > 0) {
1002 $h_func_b =
1003 '<div class="checkbox">'
1004 . '<label for="checkTt_content_showHidden">'
1005 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
1006 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
1007 . '</label>'
1008 . '</div>';
1009 }
1010 // Boolean: Display up/down arrows and edit icons for tt_content records
1011 $dbList->tt_contentConfig['showCommands'] = 1;
1012 // Boolean: Display info-marks or not
1013 $dbList->tt_contentConfig['showInfo'] = 1;
1014 // Setting up the tt_content columns to show:
1015 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
1016 $colList = array();
1017 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
1018 foreach ($tcaItems as $temp) {
1019 $colList[] = $temp[1];
1020 }
1021 } else {
1022 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
1023 $colList = array('1', '0', '2', '3');
1024 }
1025 if ($this->colPosList !== '') {
1026 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
1027 }
1028 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
1029 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
1030 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
1031 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
1032 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
1033 // If the function menu is set to "Language":
1034 if ($this->MOD_SETTINGS['function'] == 2) {
1035 $dbList->tt_contentConfig['languageMode'] = 1;
1036 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
1037 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
1038 }
1039 } else {
1040 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1041 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
1042 } else {
1043 $h_func = '';
1044 }
1045 }
1046 // Start the dblist object:
1047 $dbList->itemsLimitSingleTable = 1000;
1048 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1049 $dbList->counter = $CMcounter;
1050 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1051 // Render versioning selector:
1052 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1053 // Generate the list of elements here:
1054 $dbList->generateList();
1055 // Adding the list content to the tableOutput variable:
1056 $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 : '');
1057 // ... and any accumulated JavaScript goes the same way!
1058 $tableJSOutput[$table] = $dbList->JScode;
1059 // Increase global counter:
1060 $CMcounter += $dbList->counter;
1061 // Reset variables after operation:
1062 $dbList->HTMLcode = '';
1063 $dbList->JScode = '';
1064 $h_func = '';
1065 }
1066 // END: traverse tables
1067 // For Context Sensitive Menus:
1068 $this->doc->getContextMenuCode();
1069 // Init the content
1070 $content = '';
1071 // Additional header content
1072 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1073 if (is_array($headerContentHook)) {
1074 foreach ($headerContentHook as $hook) {
1075 $params = array();
1076 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1077 }
1078 }
1079 // Add the content for each table we have rendered (traversing $tableOutput variable)
1080 foreach ($tableOutput as $table => $output) {
1081 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1082 $content .= $this->doc->sectionEnd();
1083 }
1084 // Making search form:
1085 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1086 $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>';
1087 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1088 }
1089 // Additional footer content
1090 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1091 if (is_array($footerContentHook)) {
1092 foreach ($footerContentHook as $hook) {
1093 $params = array();
1094 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1095 }
1096 }
1097 return $content;
1098 }
1099
1100 /**
1101 * Print accumulated content of module
1102 *
1103 * @return void
1104 */
1105 public function printContent() {
1106 echo $this->content;
1107 }
1108
1109 /***************************
1110 *
1111 * Sub-content functions, rendering specific parts of the module content.
1112 *
1113 ***************************/
1114 /**
1115 * Create the panel of buttons for submitting the form or otherwise perform operations.
1116 *
1117 * @param string $function Identifier for function of module
1118 * @return array all available buttons as an assoc. array
1119 */
1120 protected function getButtons($function = '') {
1121 $lang = $this->getLanguageService();
1122 $buttons = array(
1123 'view' => '',
1124 'history_page' => '',
1125 'new_content' => '',
1126 'move_page' => '',
1127 'move_record' => '',
1128 'new_page' => '',
1129 'edit_page' => '',
1130 'edit_language' => '',
1131 'csh' => '',
1132 'shortcut' => '',
1133 'cache' => '',
1134 'savedok' => '',
1135 'save_close' => '',
1136 'savedokshow' => '',
1137 'closedok' => '',
1138 'deletedok' => '',
1139 'undo' => '',
1140 'history_record' => ''
1141 );
1142 // View page
1143 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1144 $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>';
1145 }
1146 // Shortcut
1147 if ($this->getBackendUser()->mayMakeShortcut()) {
1148 $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']);
1149 }
1150 // Cache
1151 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1152 $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>';
1153 }
1154 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1155 // Move record
1156 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1157 $urlParameters = [
1158 'table' => $this->eRParts[0],
1159 'uid' => $this->eRParts[1],
1160 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1161 ];
1162 $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>';
1163 }
1164
1165 // Edit page properties and page language overlay icons
1166 if ($this->pageIsNotLockedForEditors()) {
1167
1168 // Edit localized page_language_overlay only when one specific language is selected
1169 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1170 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1171 'uid',
1172 'pages_language_overlay',
1173 'pid = ' . (int)$this->id . ' ' .
1174 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1175 BackendUtility::deleteClause('pages_language_overlay') .
1176 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1177 '',
1178 '',
1179 '',
1180 'sys_language_uid'
1181 );
1182
1183 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1184 $buttons['edit_language'] = '<a href="#" ' .
1185 'onclick="' . $editLanguageOnClick . '"' .
1186 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1187 IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1188 '</a>';
1189 }
1190
1191
1192 // Edit page properties
1193 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1194 $buttons['edit_page'] = '<a href="#" ' .
1195 'onclick="' . $editPageOnClick . '"' .
1196 'title="' . $lang->getLL('editPageProperties', TRUE) . '">' .
1197 IconUtility::getSpriteIcon('actions-page-open') .
1198 '</a>';
1199 }
1200
1201 // Add CSH (Context Sensitive Help) icon to tool bar
1202 if ($function == 'quickEdit') {
1203 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1204 } else {
1205 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1206 }
1207 if ($function == 'quickEdit') {
1208 // Save record
1209 $buttons['savedok'] = '<button class="c-inputButton" name="_savedok_x">'
1210 . IconUtility::getSpriteIcon('actions-document-save', array('title' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE)))
1211 . '</button>';
1212 // Save and close
1213 $buttons['save_close'] = '<button class="c-inputButton" name="_saveandclosedok_x">'
1214 . IconUtility::getSpriteIcon('actions-document-save-close', array('title' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE)))
1215 . '</button>';
1216 // Save record and show page
1217 $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>';
1218 // Close record
1219 $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>';
1220 // Delete record
1221 if ($this->deleteButton) {
1222 $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>';
1223 }
1224 if ($this->undoButton) {
1225 // Undo button
1226 $buttons['undo'] = '<a href="#"
1227 onclick="' . htmlspecialchars('window.location.href=' .
1228 GeneralUtility::quoteJSvalue(
1229 $GLOBALS['BACK_PATH'] .
1230 BackendUtility::getModuleUrl(
1231 'record_history',
1232 array(
1233 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1234 'revert' => 'ALL_FIELDS',
1235 'sumUp' => -1,
1236 'returnUrl' => $this->R_URI,
1237 )
1238 )
1239 ) . '; return false;') . '"
1240 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>';
1241 // History button
1242 $buttons['history_record'] = '<a href="#"
1243 onclick="' . htmlspecialchars('jumpToUrl(' .
1244 GeneralUtility::quoteJSvalue(
1245 $GLOBALS['BACK_PATH'] .
1246 BackendUtility::getModuleUrl(
1247 'record_history',
1248 array(
1249 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1250 'returnUrl' => $this->R_URI,
1251 )
1252 ) . '#latest'
1253 ) . ');return false;') . '"
1254 title="' . $lang->getLL('recordHistory', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1255 }
1256 }
1257 }
1258 return $buttons;
1259 }
1260
1261 /*******************************
1262 *
1263 * Other functions
1264 *
1265 ******************************/
1266 /**
1267 * Returns the number of hidden elements (including those hidden by start/end times)
1268 * on the current page (for the current sys_language)
1269 *
1270 * @return int
1271 */
1272 public function getNumberOfHiddenElements() {
1273 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1274 'uid',
1275 'tt_content',
1276 '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')
1277 );
1278 }
1279
1280 /**
1281 * Returns URL to the current script.
1282 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1283 *
1284 * @param array $params Parameters array, merged with global GET vars.
1285 * @return string URL
1286 */
1287 public function local_linkThisScript($params) {
1288 $params['popView'] = '';
1289 $params['new_unique_uid'] = '';
1290 return GeneralUtility::linkThisScript($params);
1291 }
1292
1293 /**
1294 * Returns a SQL query for selecting sys_language records.
1295 *
1296 * @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)
1297 * @return string Return query string.
1298 */
1299 public function exec_languageQuery($id) {
1300 if ($id) {
1301 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1302 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1303 return $this->getDatabaseConnection()->exec_SELECTquery(
1304 'sys_language.*',
1305 'pages_language_overlay,sys_language',
1306 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1307 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1308 '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',
1309 'sys_language.title'
1310 );
1311 } else {
1312 return $this->getDatabaseConnection()->exec_SELECTquery(
1313 'sys_language.*',
1314 'sys_language',
1315 'sys_language.hidden=0',
1316 '',
1317 'sys_language.title'
1318 );
1319 }
1320 }
1321
1322 /**
1323 * Get used languages in a colPos of a page
1324 *
1325 * @param int $pageId
1326 * @param int $colPos
1327 * @return bool|\mysqli_result|object
1328 */
1329 public function getUsedLanguagesInPageAndColumn($pageId, $colPos) {
1330 if (!isset($languagesInColumnCache[$pageId])) {
1331 $languagesInColumnCache[$pageId] = array();
1332 }
1333 if (!isset($languagesInColumnCache[$pageId][$colPos])) {
1334 $languagesInColumnCache[$pageId][$colPos] = array();
1335 }
1336
1337 if (empty($languagesInColumnCache[$pageId][$colPos])) {
1338 $exQ = BackendUtility::deleteClause('tt_content') .
1339 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1340
1341 $databaseConnection = $this->getDatabaseConnection();
1342 $res = $databaseConnection->exec_SELECTquery(
1343 'sys_language.*',
1344 'tt_content,sys_language',
1345 'tt_content.sys_language_uid=sys_language.uid AND tt_content.colPos = ' . (int)$colPos . ' AND tt_content.pid=' . (int)$pageId . $exQ .
1346 BackendUtility::versioningPlaceholderClause('tt_content'),
1347 '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',
1348 'sys_language.title'
1349 );
1350 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1351 $languagesInColumnCache[$pageId][$colPos][$row['uid']] = $row;
1352 }
1353 $databaseConnection->sql_free_result($res);
1354 }
1355
1356 return $languagesInColumnCache[$pageId][$colPos];
1357 }
1358
1359 /**
1360 * Check if a column of a page for a language is empty. Translation records are ignored here!
1361 *
1362 * @param int $colPos
1363 * @param int $languageId
1364 * @return bool
1365 */
1366 public function isColumnEmpty($colPos, $languageId) {
1367 foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
1368 if ((int)$row['l18n_parent'] === 0) {
1369 return FALSE;
1370 }
1371 }
1372 return TRUE;
1373 }
1374
1375 /**
1376 * Get elements for a column and a language
1377 *
1378 * @param int $pageId
1379 * @param int $colPos
1380 * @param int $languageId
1381 * @return array
1382 */
1383 public function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId) {
1384 if (!isset($this->contentElementCache[$languageId][$colPos])) {
1385 $languageId = (int)$languageId;
1386 $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
1387 if ($languageId > 0) {
1388 $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1389 }
1390
1391 $databaseConnection = $this->getDatabaseConnection();
1392 $res = $databaseConnection->exec_SELECTquery(
1393 'tt_content.uid',
1394 'tt_content,sys_language',
1395 $whereClause
1396 );
1397 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1398 $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
1399 }
1400 $databaseConnection->sql_free_result($res);
1401 }
1402 if (is_array($this->contentElementCache[$languageId][$colPos])) {
1403 return array_keys($this->contentElementCache[$languageId][$colPos]);
1404 }
1405 return array();
1406 }
1407
1408 /**
1409 * Check the editlock access
1410 *
1411 * @return bool
1412 */
1413 public function pageIsNotLockedForEditors() {
1414 return !($this->pageinfo['editlock'] && ($this->CALC_PERMS & Permission::PAGE_EDIT));
1415 }
1416
1417 /**
1418 * Returns LanguageService
1419 *
1420 * @return \TYPO3\CMS\Lang\LanguageService
1421 */
1422 protected function getLanguageService() {
1423 return $GLOBALS['LANG'];
1424 }
1425
1426 /**
1427 * Returns the current BE user.
1428 *
1429 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1430 */
1431 protected function getBackendUser() {
1432 return $GLOBALS['BE_USER'];
1433 }
1434
1435 /**
1436 * Returns the database connection
1437 *
1438 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1439 */
1440 protected function getDatabaseConnection() {
1441 return $GLOBALS['TYPO3_DB'];
1442 }
1443
1444 }