356bd027ba85aa4ed38b6cc2834f8cce02f9cf97
[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 * Initializing the module
295 *
296 * @return void
297 */
298 public function init() {
299 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
300
301 // Setting module configuration / page select clause
302 $this->MCONF = $GLOBALS['MCONF'];
303 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
304 $this->backPath = $GLOBALS['BACK_PATH'];
305 // Get session data
306 $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
307 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
308 // GPvars:
309 $this->id = (int)GeneralUtility::_GP('id');
310 $this->pointer = GeneralUtility::_GP('pointer');
311 $this->imagemode = GeneralUtility::_GP('imagemode');
312 $this->clear_cache = GeneralUtility::_GP('clear_cache');
313 $this->popView = GeneralUtility::_GP('popView');
314 $this->edit_record = GeneralUtility::_GP('edit_record');
315 $this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
316 $this->search_field = GeneralUtility::_GP('search_field');
317 $this->search_levels = GeneralUtility::_GP('search_levels');
318 $this->showLimit = GeneralUtility::_GP('showLimit');
319 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
320 $this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
321 $sessionData['search_field'] = $this->search_field;
322 // Store session data
323 $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
324 // Load page info array:
325 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
326 // Initialize menu
327 $this->menuConfig();
328 // Setting sys language from session var:
329 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
330 // CSH / Descriptions:
331 $this->descrTable = '_MOD_' . $this->MCONF['name'];
332
333 $this->markers['SEARCHBOX'] = '';
334 $this->markers['BUTTONLIST_ADDITIONAL'] = '';
335 }
336
337 /**
338 * Initialize menu array
339 *
340 * @return void
341 */
342 public function menuConfig() {
343 $lang = $this->getLanguageService();
344 // MENU-ITEMS:
345 $this->MOD_MENU = array(
346 'tt_content_showHidden' => '',
347 'function' => array(
348 0 => $lang->getLL('m_function_0'),
349 1 => $lang->getLL('m_function_1'),
350 2 => $lang->getLL('m_function_2')
351 ),
352 'language' => array(
353 0 => $lang->getLL('m_default')
354 )
355 );
356 // example settings:
357 // $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
358 // array ('default' => array(
359 // 'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
360 // 'fList' => 'title,description,image',
361 // 'icon' => TRUE));
362 if (is_array($this->externalTables)) {
363 foreach ($this->externalTables as $table => $tableSettings) {
364 // delete the default settings from above
365 if (is_array($this->MOD_MENU[$table])) {
366 unset($this->MOD_MENU[$table]);
367 }
368 if (is_array($tableSettings) && count($tableSettings) > 1) {
369 foreach ($tableSettings as $key => $settings) {
370 $this->MOD_MENU[$table][$key] = $lang->sL($settings['MENU']);
371 }
372 }
373 }
374 }
375 // 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.
376 $res = $this->exec_languageQuery($this->id);
377 while ($lRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
378 if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
379 $this->MOD_MENU['language'][$lRow['uid']] = $lRow['hidden'] ? '(' . $lRow['title'] . ')' : $lRow['title'];
380 }
381 }
382 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
383 $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', $this->getBackendUser()->isAdmin() ? '' : 'hidden=0');
384 if (!$count) {
385 unset($this->MOD_MENU['function']['2']);
386 }
387 // page/be_user TSconfig settings and blinding of menu-items
388 $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
389 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
390 if ($this->modTSconfig['properties']['QEisDefault']) {
391 ksort($this->MOD_MENU['function']);
392 }
393 $this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
394 // Remove QuickEdit as option if page type is not...
395 if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6', $this->pageinfo['doktype'])) {
396 unset($this->MOD_MENU['function'][0]);
397 }
398 // Setting alternative default label:
399 if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
400 $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
401 }
402 // Clean up settings
403 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), 'web_layout');
404 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
405 if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
406 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
407 }
408 }
409
410 /**
411 * Clears page cache for the current id, $this->id
412 *
413 * @return void
414 */
415 public function clearCache() {
416 if ($this->clear_cache) {
417 $tce = GeneralUtility::makeInstance(DataHandler::class);
418 $tce->stripslashes_values = FALSE;
419 $tce->start(array(), array());
420 $tce->clear_cacheCmd($this->id);
421 }
422 }
423
424 /**
425 * Generate the flashmessages for current pid
426 *
427 * @return string HTML content with flashmessages
428 */
429 protected function getHeaderFlashMessagesForCurrentPid() {
430 $content = '';
431 $lang = $this->getLanguageService();
432 // If page is a folder
433 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
434 // Access to list module
435 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
436 $moduleLoader->load($GLOBALS['TBE_MODULES']);
437 $modules = $moduleLoader->modules;
438 if (is_array($modules['web']['sub']['list'])) {
439 $title = $lang->getLL('goToListModule');
440 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
441 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
442
443 $view = GeneralUtility::makeInstance(StandaloneView::class);
444 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
445 $view->assignMultiple(array(
446 'title' => $title,
447 'message' => $message,
448 'state' => InfoboxViewHelper::STATE_INFO
449 ));
450 $content .= $view->render();
451 }
452 }
453 // If content from different pid is displayed
454 if ($this->pageinfo['content_from_pid']) {
455 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
456 $title = BackendUtility::getRecordTitle('pages', $contentPage);
457 $linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
458 $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
459 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, sprintf($lang->getLL('content_from_pid_title'), $link), '', FlashMessage::INFO);
460 $content .= $flashMessage->render();
461 }
462 return $content;
463 }
464
465 /**
466 *
467 * @return string $title
468 */
469 protected function getLocalizedPageTitle() {
470 if ($this->current_sys_language > 0) {
471 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
472 'title',
473 'pages_language_overlay',
474 'pid = ' . (int)$this->id .
475 ' AND sys_language_uid = ' . (int)$this->current_sys_language .
476 BackendUtility::deleteClause('pages_language_overlay') .
477 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
478 '',
479 '',
480 '',
481 'sys_language_uid'
482 );
483 return $overlayRecord['title'];
484 } else {
485 return $this->pageinfo['title'];
486 }
487 }
488
489 /**
490 * Main function.
491 * Creates some general objects and calls other functions for the main rendering of module content.
492 *
493 * @return void
494 */
495 public function main() {
496 $lang = $this->getLanguageService();
497 // Access check...
498 // The page will show only if there is a valid page and if this page may be viewed by the user
499 $access = is_array($this->pageinfo) ? 1 : 0;
500 if ($this->id && $access) {
501 // Initialize permission settings:
502 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
503 $this->EDIT_CONTENT = $this->CALC_PERMS & Permission::CONTENT_EDIT ? 1 : 0;
504 // Start document template object:
505 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
506 $this->doc->backPath = $GLOBALS['BACK_PATH'];
507 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
508
509 // override the default jumpToUrl
510 $this->doc->JScodeArray['jumpToUrl'] = '
511 function jumpToUrl(URL,formEl) {
512 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
513 if (!TBE_EDITOR.isFormChanged()) {
514 window.location.href = URL;
515 } else if (formEl) {
516 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
517 }
518 } else {
519 window.location.href = URL;
520 }
521 }
522 ';
523
524 $this->doc->JScode .= $this->doc->wrapScriptTags('
525 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
526 if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
527 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->id)) : '') . '
528
529 function deleteRecord(table,id,url) { //
530 if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
531 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";
532 }
533 return false;
534 }
535 ');
536 $this->doc->JScode .= $this->doc->wrapScriptTags('
537 var DTM_array = new Array();
538 var DTM_origClass = new String();
539
540 // if tabs are used in a popup window the array might not exists
541 if(!top.DTM_currentTabs) {
542 top.DTM_currentTabs = new Array();
543 }
544
545 function DTM_activate(idBase,index,doToogle) { //
546 // Hiding all:
547 if (DTM_array[idBase]) {
548 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
549 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
550 document.getElementById(DTM_array[idBase][cnt]+"-DIV").className = "tab-pane";
551 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").value = "tab";
552 }
553 }
554 }
555
556 // Showing one:
557 if (document.getElementById(idBase+"-"+index+"-DIV")) {
558 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").className === "tab-pane active") {
559 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane";
560 if(DTM_origClass=="") {
561 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "tab";
562 } else {
563 DTM_origClass = "tab";
564 }
565 top.DTM_currentTabs[idBase] = -1;
566 } else {
567 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane active";
568 if(DTM_origClass=="") {
569 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "active";
570 } else {
571 DTM_origClass = "active";
572 }
573 top.DTM_currentTabs[idBase] = index;
574 }
575 }
576 }
577 function DTM_toggle(idBase,index,isInit) { //
578 // Showing one:
579 if (document.getElementById(idBase+"-"+index+"-DIV")) {
580 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
581 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane";
582 if(isInit) {
583 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "tab";
584 } else {
585 DTM_origClass = "tab";
586 }
587 top.DTM_currentTabs[idBase+"-"+index] = 0;
588 } else {
589 document.getElementById(idBase+"-"+index+"-DIV").className = "tab-pane active";
590 if(isInit) {
591 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").value = "active";
592 } else {
593 DTM_origClass = "active";
594 }
595 top.DTM_currentTabs[idBase+"-"+index] = 1;
596 }
597 }
598 }
599 ');
600 // Setting doc-header
601 $this->doc->form = '<form action="' . htmlspecialchars(
602 BackendUtility::getModuleUrl(
603 'web_layout', array('id' => $this->id, 'imagemode' => $this->imagemode)
604 )) . '" method="post">';
605 // Creating the top function menu:
606 $this->topFuncMenu = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'], '', '');
607 $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'], '', '') : '';
608 // Find backend layout / coumns
609 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
610 if (!empty($backendLayout['__colPosList'])) {
611 $this->colPosList = implode(',', $backendLayout['__colPosList']);
612 }
613 // Removing duplicates, if any
614 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
615 // Accessible columns
616 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
617 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
618 // Match with the list which is present in the colPosList for the current page
619 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
620 $this->activeColPosList = array_unique(array_intersect(
621 $this->activeColPosList,
622 $this->colPosList
623 ));
624 }
625 } else {
626 $this->activeColPosList = $this->colPosList;
627 }
628 $this->activeColPosList = implode(',', $this->activeColPosList);
629 $this->colPosList = implode(',', $this->colPosList);
630
631 $body = '';
632 $body .= $this->getHeaderFlashMessagesForCurrentPid();
633 // Render the primary module content:
634 if ($this->MOD_SETTINGS['function'] == 0) {
635 // QuickEdit
636 $body .= $this->renderQuickEdit();
637 } else {
638 // Page title
639 $body .= $this->doc->header($this->getLocalizedPageTitle());
640 // All other listings
641 $body .= $this->renderListContent();
642 }
643 // Setting up the buttons and markers for docheader
644 $docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
645 $this->markers['CSH'] = $docHeaderButtons['csh'];
646 $this->markers['TOP_FUNCTION_MENU'] = $this->topFuncMenu . $this->editSelect;
647 $this->markers['LANGSELECTOR'] = $languageMenu;
648 $this->markers['CONTENT'] = $body;
649 // Build the <body> for the module
650 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
651 // Renders the module page
652 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
653 } else {
654 // If no access or id value, create empty document:
655 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
656 $this->doc->backPath = $GLOBALS['BACK_PATH'];
657 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
658 $this->doc->JScode = $this->doc->wrapScriptTags('
659 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
660 ');
661
662 $body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
663
664 $title = $lang->getLL('clickAPage_header');
665 $message = $lang->getLL('clickAPage_content');
666
667 $view = GeneralUtility::makeInstance(StandaloneView::class);
668 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
669 $view->assignMultiple(array(
670 'title' => $title,
671 'message' => $message,
672 'state' => InfoboxViewHelper::STATE_INFO
673 ));
674 $body .= $view->render();
675
676 // Setting up the buttons and markers for docheader
677 $docHeaderButtons = array(
678 'view' => '',
679 'history_page' => '',
680 'new_content' => '',
681 'move_page' => '',
682 'move_record' => '',
683 'new_page' => '',
684 'edit_page' => '',
685 'csh' => '',
686 'shortcut' => '',
687 'cache' => '',
688 'savedok' => '',
689 'savedokshow' => '',
690 'closedok' => '',
691 'deletedok' => '',
692 'undo' => '',
693 'history_record' => '',
694 'edit_language' => ''
695 );
696 $this->markers['CSH'] = '';
697 $this->markers['TOP_FUNCTION_MENU'] = '';
698 $this->markers['LANGSELECTOR'] = '';
699 $this->markers['CONTENT'] = $body;
700 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
701 // Renders the module page
702 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
703 }
704 }
705
706 /**
707 * Rendering the quick-edit view.
708 *
709 * @return string
710 */
711 public function renderQuickEdit() {
712 $databaseConnection = $this->getDatabaseConnection();
713 $beUser = $this->getBackendUser();
714 $lang = $this->getLanguageService();
715 // Alternative template
716 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
717 // Alternative form tag; Quick Edit submits its content to tce_db.php.
718 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
719 // Setting up the context sensitive menu:
720 $this->doc->getContextMenuCode();
721 // Set the edit_record value for internal use in this function:
722 $edit_record = $this->edit_record;
723 // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
724 if (substr($edit_record, 0, 9) == '_EDIT_COL') {
725 $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');
726 $idListA = array();
727 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
728 $idListA[] = $cRow['uid'];
729 }
730 $url = BackendUtility::getModuleUrl('record_edit', array(
731 'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
732 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
733 ));
734 HttpUtility::redirect($url);
735 }
736 // If the former record edited was the creation of a NEW record, this will look up the created records uid:
737 if ($this->new_unique_uid) {
738 $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
739 $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
740 if (is_array($sys_log_row)) {
741 $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
742 }
743 }
744 // Creating the selector box, allowing the user to select which element to edit:
745 $opt = array();
746 $is_selected = 0;
747 $languageOverlayRecord = '';
748 if ($this->current_sys_language) {
749 list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
750 }
751 if (is_array($languageOverlayRecord)) {
752 $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
753 $is_selected += (int)$edit_record == $inValue;
754 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editLanguageHeader', TRUE) . ' ]</option>';
755 } else {
756 $inValue = 'pages:' . $this->id;
757 $is_selected += (int)$edit_record == $inValue;
758 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editPageProperties', TRUE) . ' ]</option>';
759 }
760 // Selecting all content elements from this language and allowed colPos:
761 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', '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'), '', 'colPos,sorting');
762 $colPos = NULL;
763 $first = 1;
764 // Page is the pid if no record to put this after.
765 $prev = $this->id;
766 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
767 BackendUtility::workspaceOL('tt_content', $cRow);
768 if (is_array($cRow)) {
769 if ($first) {
770 if (!$edit_record) {
771 $edit_record = 'tt_content:' . $cRow['uid'];
772 }
773 $first = 0;
774 }
775 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
776 $colPos = $cRow['colPos'];
777 $opt[] = '<option value=""></option>';
778 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
779 }
780 $inValue = 'tt_content:' . $cRow['uid'];
781 $is_selected += (int)$edit_record == $inValue;
782 $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>';
783 $prev = -$cRow['uid'];
784 }
785 }
786 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
787 if (!$edit_record) {
788 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
789 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
790 $is_selected += (int)$edit_record == $inValue;
791 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
792 }
793 // If none is yet selected...
794 if (!$is_selected) {
795 $opt[] = '<option value=""></option>';
796 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
797 }
798 // Splitting the edit-record cmd value into table/uid:
799 $this->eRParts = explode(':', $edit_record);
800 // Delete-button flag?
801 $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);
802 // If undo-button should be rendered (depends on available items in sys_history)
803 $this->undoButton = FALSE;
804 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
805 if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
806 $this->undoButton = TRUE;
807 }
808 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
809 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
810 $R_URL_getvars = GeneralUtility::_GET();
811 unset($R_URL_getvars['popView']);
812 unset($R_URL_getvars['new_unique_uid']);
813 $R_URL_getvars['edit_record'] = $edit_record;
814 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
815 // Setting close url/return url for exiting this script:
816 // Goes to 'Columns' view if close is pressed (default)
817 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
818 if ($this->returnUrl) {
819 $this->closeUrl = $this->returnUrl;
820 }
821 // Return-url for JavaScript:
822 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
823 // Drawing the edit record selectbox
824 $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(
825 BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record='
826 ) . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
827 $content = '';
828 // Creating editing form:
829 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)) {
830 // Splitting uid parts for special features, if new:
831 list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
832 // Convert $uidVal to workspace version if any:
833 if ($uidVal != 'new') {
834 if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $this->eRParts[0], $uidVal, 'uid')) {
835 $uidVal = $draftRecord['uid'];
836 }
837 }
838 // Initializing transfer-data object:
839 $trData = GeneralUtility::makeInstance(DataPreprocessor::class);
840 $trData->addRawData = TRUE;
841 $trData->defVals[$this->eRParts[0]] = array(
842 'colPos' => (int)$ex_colPos,
843 'sys_language_uid' => (int)$this->current_sys_language
844 );
845 $trData->lockRecords = 1;
846 // 'new'
847 $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
848 $new_unique_uid = '';
849 // Getting/Making the record:
850 reset($trData->regTableItems_data);
851 $rec = current($trData->regTableItems_data);
852 if ($uidVal == 'new') {
853 $new_unique_uid = uniqid('NEW', TRUE);
854 $rec['uid'] = $new_unique_uid;
855 $rec['pid'] = (int)$ex_pid ?: $this->id;
856 $recordAccess = TRUE;
857 } else {
858 $rec['uid'] = $uidVal;
859 // Checking internals access:
860 $recordAccess = $beUser->recordEditAccessInternals($this->eRParts[0], $uidVal);
861 }
862 if (!$recordAccess) {
863 // If no edit access, print error message:
864 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1);
865 } elseif (is_array($rec)) {
866 // If the record is an array (which it will always be... :-)
867 // Create instance of TCEforms, setting defaults:
868 $tceForms = GeneralUtility::makeInstance(FormEngine::class);
869 // Render form, wrap it:
870 $panel = '';
871 $panel .= $tceForms->getMainFields($this->eRParts[0], $rec);
872 $panel = $tceForms->wrapTotal($panel, $rec, $this->eRParts[0]);
873 // Add hidden fields:
874 $theCode = $panel;
875 if ($uidVal == 'new') {
876 $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
877 }
878 $theCode .= '
879 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
880 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
881 <input type="hidden" name="redirect" value="' . htmlspecialchars(($uidVal == 'new' ? BackendUtility::getModuleUrl(
882 'web_layout',
883 array(
884 'id' => $this->id,
885 'new_unique_uid' => $new_unique_uid,
886 'returnUrl' => $this->returnUrl
887 )
888 ) : $this->R_URI)) . '" />
889 ' . FormEngine::getHiddenTokenField('tceAction');
890 // Add JavaScript as needed around the form:
891 $theCode = $tceForms->printNeededJSFunctions_top() . $theCode . $tceForms->printNeededJSFunctions();
892 // Add warning sign if record was "locked":
893 if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
894 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
895 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
896 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
897 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
898 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
899 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
900 $defaultFlashMessageQueue->enqueue($flashMessage);
901 }
902 // Add whole form as a document section:
903 $content = $this->doc->section('', $theCode);
904 }
905 } else {
906 // If no edit access, print error message:
907 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
908 }
909 // Bottom controls (function menus):
910 $q_count = $this->getNumberOfHiddenElements();
911 if ($q_count) {
912 $h_func_b = '<div class="checkbox">' .
913 '<label for="checkTt_content_showHidden">' .
914 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') .
915 (!$q_count ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>') : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
916 '</label>' .
917 '</div>';
918
919 $content .= $this->doc->section('', $h_func_b, 0, 0);
920 $content .= $this->doc->spacer(10);
921 }
922
923 // Select element matrix:
924 if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
925 $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
926 $posMap->backPath = $GLOBALS['BACK_PATH'];
927 $posMap->cur_sys_language = $this->current_sys_language;
928 $HTMLcode = '';
929 // CSH:
930 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
931 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
932 $content .= $this->doc->spacer(20);
933 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
934 $content .= $this->doc->spacer(20);
935 }
936 return $content;
937 }
938
939 /**
940 * Rendering all other listings than QuickEdit
941 *
942 * @return string
943 */
944 public function renderListContent() {
945 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
946 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
947 $dbList->backPath = $GLOBALS['BACK_PATH'];
948 $dbList->thumbs = $this->imagemode;
949 $dbList->no_noWrap = 1;
950 $dbList->descrTable = $this->descrTable;
951 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
952 $dbList->script = BackendUtility::getModuleUrl('web_layout');
953 $dbList->showIcon = 0;
954 $dbList->setLMargin = 0;
955 $dbList->doEdit = $this->EDIT_CONTENT;
956 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
957 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
958 $dbList->id = $this->id;
959 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
960 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
961 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
962 if (!$dbList->nextThree) {
963 $dbList->nextThree = 1;
964 }
965 $dbList->externalTables = $this->externalTables;
966 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
967 // also fills $dbList->activeTables
968 $dbList->getTableMenu($this->id);
969 // Initialize other variables:
970 $h_func = '';
971 $tableOutput = array();
972 $tableJSOutput = array();
973 $CMcounter = 0;
974 // Traverse the list of table names which has records on this page (that array is populated
975 // by the $dblist object during the function getTableMenu()):
976 foreach ($dbList->activeTables as $table => $value) {
977 $h_func_b = '';
978 if (!isset($dbList->externalTables[$table])) {
979 $q_count = $this->getNumberOfHiddenElements();
980
981 if ($q_count > 0) {
982 $h_func_b =
983 '<div class="checkbox">'
984 . '<label for="checkTt_content_showHidden">'
985 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
986 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
987 . '</label>'
988 . '</div>';
989 }
990 // Boolean: Display up/down arrows and edit icons for tt_content records
991 $dbList->tt_contentConfig['showCommands'] = 1;
992 // Boolean: Display info-marks or not
993 $dbList->tt_contentConfig['showInfo'] = 1;
994 // Setting up the tt_content columns to show:
995 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
996 $colList = array();
997 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
998 foreach ($tcaItems as $temp) {
999 $colList[] = $temp[1];
1000 }
1001 } else {
1002 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
1003 $colList = array('1', '0', '2', '3');
1004 }
1005 if ($this->colPosList !== '') {
1006 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
1007 }
1008 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
1009 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
1010 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
1011 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
1012 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
1013 // If the function menu is set to "Language":
1014 if ($this->MOD_SETTINGS['function'] == 2) {
1015 $dbList->tt_contentConfig['languageMode'] = 1;
1016 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
1017 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
1018 }
1019 } else {
1020 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1021 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
1022 } else {
1023 $h_func = '';
1024 }
1025 }
1026 // Start the dblist object:
1027 $dbList->itemsLimitSingleTable = 1000;
1028 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1029 $dbList->counter = $CMcounter;
1030 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1031 // Render versioning selector:
1032 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1033 // Generate the list of elements here:
1034 $dbList->generateList();
1035 // Adding the list content to the tableOutput variable:
1036 $tableOutput[$table] = ($h_func ? $h_func . '<br /><img src="clear.gif" width="1" height="4" alt="" /><br />' : '') . $dbList->HTMLcode . ($h_func_b ? '<img src="clear.gif" width="1" height="10" alt="" /><br />' . $h_func_b : '');
1037 // ... and any accumulated JavaScript goes the same way!
1038 $tableJSOutput[$table] = $dbList->JScode;
1039 // Increase global counter:
1040 $CMcounter += $dbList->counter;
1041 // Reset variables after operation:
1042 $dbList->HTMLcode = '';
1043 $dbList->JScode = '';
1044 $h_func = '';
1045 }
1046 // END: traverse tables
1047 // For Context Sensitive Menus:
1048 $this->doc->getContextMenuCode();
1049 // Init the content
1050 $content = '';
1051 // Additional header content
1052 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1053 if (is_array($headerContentHook)) {
1054 foreach ($headerContentHook as $hook) {
1055 $params = array();
1056 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1057 }
1058 }
1059 // Add the content for each table we have rendered (traversing $tableOutput variable)
1060 foreach ($tableOutput as $table => $output) {
1061 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1062 $content .= $this->doc->spacer(15);
1063 $content .= $this->doc->sectionEnd();
1064 }
1065 // Making search form:
1066 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1067 $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>';
1068 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1069 }
1070 // Additional footer content
1071 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1072 if (is_array($footerContentHook)) {
1073 foreach ($footerContentHook as $hook) {
1074 $params = array();
1075 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1076 }
1077 }
1078 return $content;
1079 }
1080
1081 /**
1082 * Print accumulated content of module
1083 *
1084 * @return void
1085 */
1086 public function printContent() {
1087 echo $this->content;
1088 }
1089
1090 /***************************
1091 *
1092 * Sub-content functions, rendering specific parts of the module content.
1093 *
1094 ***************************/
1095 /**
1096 * Create the panel of buttons for submitting the form or otherwise perform operations.
1097 *
1098 * @param string $function Identifier for function of module
1099 * @return array all available buttons as an assoc. array
1100 */
1101 protected function getButtons($function = '') {
1102 $lang = $this->getLanguageService();
1103 $buttons = array(
1104 'view' => '',
1105 'history_page' => '',
1106 'new_content' => '',
1107 'move_page' => '',
1108 'move_record' => '',
1109 'new_page' => '',
1110 'edit_page' => '',
1111 'edit_language' => '',
1112 'csh' => '',
1113 'shortcut' => '',
1114 'cache' => '',
1115 'savedok' => '',
1116 'save_close' => '',
1117 'savedokshow' => '',
1118 'closedok' => '',
1119 'deletedok' => '',
1120 'undo' => '',
1121 'history_record' => ''
1122 );
1123 // View page
1124 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1125 $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>';
1126 }
1127 // Shortcut
1128 if ($this->getBackendUser()->mayMakeShortcut()) {
1129 $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']);
1130 }
1131 // Cache
1132 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1133 $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>';
1134 }
1135 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1136 // Move record
1137 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1138 $urlParameters = [
1139 'table' => $this->eRParts[0],
1140 'uid' => $this->eRParts[1],
1141 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1142 ];
1143 $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>';
1144 }
1145
1146 // Edit page properties and page language overlay icons
1147 if ($this->CALC_PERMS & Permission::PAGE_EDIT) {
1148
1149 // Edit localized page_language_overlay only when one specific language is selected
1150 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1151 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1152 'uid',
1153 'pages_language_overlay',
1154 'pid = ' . (int)$this->id . ' ' .
1155 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1156 BackendUtility::deleteClause('pages_language_overlay') .
1157 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1158 '',
1159 '',
1160 '',
1161 'sys_language_uid'
1162 );
1163
1164 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1165 $buttons['edit_language'] = '<a href="#" ' .
1166 'onclick="' . $editLanguageOnClick . '"' .
1167 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1168 IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1169 '</a>';
1170 }
1171
1172
1173 // Edit page properties
1174 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1175 $buttons['edit_page'] = '<a href="#" ' .
1176 'onclick="' . $editPageOnClick . '"' .
1177 'title="' . $lang->getLL('editPageProperties', TRUE) . '">' .
1178 IconUtility::getSpriteIcon('actions-page-open') .
1179 '</a>';
1180 }
1181
1182 // Add CSH (Context Sensitive Help) icon to tool bar
1183 if ($function == 'quickEdit') {
1184 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1185 } else {
1186 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1187 }
1188 if ($function == 'quickEdit') {
1189 // Save record
1190 $buttons['savedok'] = IconUtility::getSpriteIcon('actions-document-save', array('html' => '<input type="image" name="_savedok" class="c-inputButton" src="clear.gif" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" />'));
1191 // Save and close
1192 $buttons['save_close'] = IconUtility::getSpriteIcon('actions-document-save-close', array('html' => '<input type="image" class="c-inputButton" name="_saveandclosedok" src="clear.gif" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" />'));
1193 // Save record and show page
1194 $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>';
1195 // Close record
1196 $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>';
1197 // Delete record
1198 if ($this->deleteButton) {
1199 $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>';
1200 }
1201 if ($this->undoButton) {
1202 // Undo button
1203 $buttons['undo'] = '<a href="#"
1204 onclick="' . htmlspecialchars('window.location.href=' .
1205 GeneralUtility::quoteJSvalue(
1206 $GLOBALS['BACK_PATH'] .
1207 BackendUtility::getModuleUrl(
1208 'record_history',
1209 array(
1210 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1211 'revert' => 'ALL_FIELDS',
1212 'sumUp' => -1,
1213 'returnUrl' => $this->R_URI,
1214 )
1215 )
1216 ) . '; return false;') . '"
1217 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>';
1218 // History button
1219 $buttons['history_record'] = '<a href="#"
1220 onclick="' . htmlspecialchars('jumpToUrl(' .
1221 GeneralUtility::quoteJSvalue(
1222 $GLOBALS['BACK_PATH'] .
1223 BackendUtility::getModuleUrl(
1224 'record_history',
1225 array(
1226 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1227 'returnUrl' => $this->R_URI,
1228 )
1229 ) . '#latest'
1230 ) . ');return false;') . '"
1231 title="' . $lang->getLL('recordHistory', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1232 }
1233 }
1234 }
1235 return $buttons;
1236 }
1237
1238 /*******************************
1239 *
1240 * Other functions
1241 *
1242 ******************************/
1243 /**
1244 * Returns the number of hidden elements (including those hidden by start/end times)
1245 * on the current page (for the current sys_language)
1246 *
1247 * @return int
1248 */
1249 public function getNumberOfHiddenElements() {
1250 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1251 'uid',
1252 'tt_content',
1253 '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')
1254 );
1255 }
1256
1257 /**
1258 * Returns URL to the current script.
1259 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1260 *
1261 * @param array $params Parameters array, merged with global GET vars.
1262 * @return string URL
1263 */
1264 public function local_linkThisScript($params) {
1265 $params['popView'] = '';
1266 $params['new_unique_uid'] = '';
1267 return GeneralUtility::linkThisScript($params);
1268 }
1269
1270 /**
1271 * Returns a SQL query for selecting sys_language records.
1272 *
1273 * @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)
1274 * @return string Return query string.
1275 */
1276 public function exec_languageQuery($id) {
1277 if ($id) {
1278 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1279 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1280 return $this->getDatabaseConnection()->exec_SELECTquery(
1281 'sys_language.*',
1282 'pages_language_overlay,sys_language',
1283 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1284 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1285 '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',
1286 'sys_language.title'
1287 );
1288 } else {
1289 return $this->getDatabaseConnection()->exec_SELECTquery(
1290 'sys_language.*',
1291 'sys_language',
1292 'sys_language.hidden=0',
1293 '',
1294 'sys_language.title'
1295 );
1296 }
1297 }
1298
1299 /**
1300 * Returns LanguageService
1301 *
1302 * @return \TYPO3\CMS\Lang\LanguageService
1303 */
1304 protected function getLanguageService() {
1305 return $GLOBALS['LANG'];
1306 }
1307
1308 /**
1309 * Returns the current BE user.
1310 *
1311 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1312 */
1313 protected function getBackendUser() {
1314 return $GLOBALS['BE_USER'];
1315 }
1316
1317 /**
1318 * Returns the database connection
1319 *
1320 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1321 */
1322 protected function getDatabaseConnection() {
1323 return $GLOBALS['TYPO3_DB'];
1324 }
1325
1326 }