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