[FEATURE] Add editlock for tt_content
[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->pageIsNotLockedForEditors();
504
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="multipart/form-data" 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 $whereClause = 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content');
763 if (!$this->getBackendUser()->user['admin']) {
764 $whereClause .= ' AND editlock = 0';
765 }
766 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
767 $colPos = NULL;
768 $first = 1;
769 // Page is the pid if no record to put this after.
770 $prev = $this->id;
771 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
772 BackendUtility::workspaceOL('tt_content', $cRow);
773 if (is_array($cRow)) {
774 if ($first) {
775 if (!$edit_record) {
776 $edit_record = 'tt_content:' . $cRow['uid'];
777 }
778 $first = 0;
779 }
780 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
781 $colPos = $cRow['colPos'];
782 $opt[] = '<option value=""></option>';
783 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
784 }
785 $inValue = 'tt_content:' . $cRow['uid'];
786 $is_selected += (int)$edit_record == $inValue;
787 $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>';
788 $prev = -$cRow['uid'];
789 }
790 }
791 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
792 if (!$edit_record) {
793 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
794 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
795 $is_selected += (int)$edit_record == $inValue;
796 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
797 }
798 // If none is yet selected...
799 if (!$is_selected) {
800 $opt[] = '<option value=""></option>';
801 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
802 }
803 // Splitting the edit-record cmd value into table/uid:
804 $this->eRParts = explode(':', $edit_record);
805 // Delete-button flag?
806 $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);
807 // If undo-button should be rendered (depends on available items in sys_history)
808 $this->undoButton = FALSE;
809 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($this->eRParts[0], 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
810 if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
811 $this->undoButton = TRUE;
812 }
813 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
814 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
815 $R_URL_getvars = GeneralUtility::_GET();
816 unset($R_URL_getvars['popView']);
817 unset($R_URL_getvars['new_unique_uid']);
818 $R_URL_getvars['edit_record'] = $edit_record;
819 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
820 // Setting close url/return url for exiting this script:
821 // Goes to 'Columns' view if close is pressed (default)
822 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
823 if ($this->returnUrl) {
824 $this->closeUrl = $this->returnUrl;
825 }
826 // Return-url for JavaScript:
827 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
828 // Drawing the edit record selectbox
829 $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(
830 BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record='
831 ) . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
832 $content = '';
833 // Creating editing form:
834 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)) {
835 // Splitting uid parts for special features, if new:
836 list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
837 // Convert $uidVal to workspace version if any:
838 if ($uidVal != 'new') {
839 if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $this->eRParts[0], $uidVal, 'uid')) {
840 $uidVal = $draftRecord['uid'];
841 }
842 }
843 // Initializing transfer-data object:
844 $trData = GeneralUtility::makeInstance(DataPreprocessor::class);
845 $trData->addRawData = TRUE;
846 $trData->defVals[$this->eRParts[0]] = array(
847 'colPos' => (int)$ex_colPos,
848 'sys_language_uid' => (int)$this->current_sys_language
849 );
850 $trData->lockRecords = 1;
851 // 'new'
852 $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
853 $new_unique_uid = '';
854 // Getting/Making the record:
855 reset($trData->regTableItems_data);
856 $rec = current($trData->regTableItems_data);
857 if ($uidVal == 'new') {
858 $new_unique_uid = uniqid('NEW', TRUE);
859 $rec['uid'] = $new_unique_uid;
860 $rec['pid'] = (int)$ex_pid ?: $this->id;
861 $recordAccess = TRUE;
862 } else {
863 $rec['uid'] = $uidVal;
864 // Checking internals access:
865 $recordAccess = $beUser->recordEditAccessInternals($this->eRParts[0], $uidVal);
866 }
867 if (!$recordAccess) {
868 // If no edit access, print error message:
869 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />' . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1);
870 } elseif (is_array($rec)) {
871 // If the record is an array (which it will always be... :-)
872 // Create instance of TCEforms, setting defaults:
873 $tceForms = GeneralUtility::makeInstance(FormEngine::class);
874 // Render form, wrap it:
875 $panel = '';
876 $panel .= $tceForms->getMainFields($this->eRParts[0], $rec);
877 $panel = $tceForms->wrapTotal($panel, $rec, $this->eRParts[0]);
878 // Add hidden fields:
879 $theCode = $panel;
880 if ($uidVal == 'new') {
881 $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
882 }
883 $theCode .= '
884 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
885 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
886 <input type="hidden" name="redirect" value="' . htmlspecialchars(($uidVal == 'new' ? BackendUtility::getModuleUrl(
887 'web_layout',
888 array(
889 'id' => $this->id,
890 'new_unique_uid' => $new_unique_uid,
891 'returnUrl' => $this->returnUrl
892 )
893 ) : $this->R_URI)) . '" />
894 ' . FormEngine::getHiddenTokenField('tceAction');
895 // Add JavaScript as needed around the form:
896 $theCode = $tceForms->printNeededJSFunctions_top() . $theCode . $tceForms->printNeededJSFunctions();
897 // Add warning sign if record was "locked":
898 if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
899 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
900 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
901 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
902 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
903 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
904 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
905 $defaultFlashMessageQueue->enqueue($flashMessage);
906 }
907 // Add whole form as a document section:
908 $content = $this->doc->section('', $theCode);
909 }
910 } else {
911 // If no edit access, print error message:
912 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
913 }
914 // Bottom controls (function menus):
915 $q_count = $this->getNumberOfHiddenElements();
916 if ($q_count) {
917 $h_func_b = '<div class="checkbox">' .
918 '<label for="checkTt_content_showHidden">' .
919 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') .
920 (!$q_count ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>') : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
921 '</label>' .
922 '</div>';
923
924 $content .= $this->doc->section('', $h_func_b, 0, 0);
925 $content .= $this->doc->spacer(10);
926 }
927
928 // Select element matrix:
929 if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
930 $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
931 $posMap->backPath = $GLOBALS['BACK_PATH'];
932 $posMap->cur_sys_language = $this->current_sys_language;
933 $HTMLcode = '';
934 // CSH:
935 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
936 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
937 $content .= $this->doc->spacer(20);
938 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
939 $content .= $this->doc->spacer(20);
940 }
941 return $content;
942 }
943
944 /**
945 * Rendering all other listings than QuickEdit
946 *
947 * @return string
948 */
949 public function renderListContent() {
950 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
951 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
952 $dbList->backPath = $GLOBALS['BACK_PATH'];
953 $dbList->thumbs = $this->imagemode;
954 $dbList->no_noWrap = 1;
955 $dbList->descrTable = $this->descrTable;
956 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
957 $dbList->script = BackendUtility::getModuleUrl('web_layout');
958 $dbList->showIcon = 0;
959 $dbList->setLMargin = 0;
960 $dbList->doEdit = $this->EDIT_CONTENT;
961 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
962 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
963 $dbList->id = $this->id;
964 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
965 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
966 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
967 if (!$dbList->nextThree) {
968 $dbList->nextThree = 1;
969 }
970 $dbList->externalTables = $this->externalTables;
971 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
972 // also fills $dbList->activeTables
973 $dbList->getTableMenu($this->id);
974 // Initialize other variables:
975 $h_func = '';
976 $tableOutput = array();
977 $tableJSOutput = array();
978 $CMcounter = 0;
979 // Traverse the list of table names which has records on this page (that array is populated
980 // by the $dblist object during the function getTableMenu()):
981 foreach ($dbList->activeTables as $table => $value) {
982 $h_func_b = '';
983 if (!isset($dbList->externalTables[$table])) {
984 $q_count = $this->getNumberOfHiddenElements();
985
986 if ($q_count > 0) {
987 $h_func_b =
988 '<div class="checkbox">'
989 . '<label for="checkTt_content_showHidden">'
990 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
991 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
992 . '</label>'
993 . '</div>';
994 }
995 // Boolean: Display up/down arrows and edit icons for tt_content records
996 $dbList->tt_contentConfig['showCommands'] = 1;
997 // Boolean: Display info-marks or not
998 $dbList->tt_contentConfig['showInfo'] = 1;
999 // Setting up the tt_content columns to show:
1000 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
1001 $colList = array();
1002 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
1003 foreach ($tcaItems as $temp) {
1004 $colList[] = $temp[1];
1005 }
1006 } else {
1007 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
1008 $colList = array('1', '0', '2', '3');
1009 }
1010 if ($this->colPosList !== '') {
1011 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
1012 }
1013 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
1014 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
1015 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
1016 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
1017 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
1018 // If the function menu is set to "Language":
1019 if ($this->MOD_SETTINGS['function'] == 2) {
1020 $dbList->tt_contentConfig['languageMode'] = 1;
1021 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
1022 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
1023 }
1024 } else {
1025 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1026 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
1027 } else {
1028 $h_func = '';
1029 }
1030 }
1031 // Start the dblist object:
1032 $dbList->itemsLimitSingleTable = 1000;
1033 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1034 $dbList->counter = $CMcounter;
1035 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1036 // Render versioning selector:
1037 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1038 // Generate the list of elements here:
1039 $dbList->generateList();
1040 // Adding the list content to the tableOutput variable:
1041 $tableOutput[$table] = ($h_func ? $h_func . '<br /><span style="width: 1px; height: 4px; display: inline-block;"></span><br />' : '') . $dbList->HTMLcode . ($h_func_b ? '<span style="width: 1px; height: 10px; display:inline-block;"></span><br />' . $h_func_b : '');
1042 // ... and any accumulated JavaScript goes the same way!
1043 $tableJSOutput[$table] = $dbList->JScode;
1044 // Increase global counter:
1045 $CMcounter += $dbList->counter;
1046 // Reset variables after operation:
1047 $dbList->HTMLcode = '';
1048 $dbList->JScode = '';
1049 $h_func = '';
1050 }
1051 // END: traverse tables
1052 // For Context Sensitive Menus:
1053 $this->doc->getContextMenuCode();
1054 // Init the content
1055 $content = '';
1056 // Additional header content
1057 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1058 if (is_array($headerContentHook)) {
1059 foreach ($headerContentHook as $hook) {
1060 $params = array();
1061 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1062 }
1063 }
1064 // Add the content for each table we have rendered (traversing $tableOutput variable)
1065 foreach ($tableOutput as $table => $output) {
1066 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1067 $content .= $this->doc->sectionEnd();
1068 }
1069 // Making search form:
1070 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1071 $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>';
1072 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1073 }
1074 // Additional footer content
1075 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1076 if (is_array($footerContentHook)) {
1077 foreach ($footerContentHook as $hook) {
1078 $params = array();
1079 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1080 }
1081 }
1082 return $content;
1083 }
1084
1085 /**
1086 * Print accumulated content of module
1087 *
1088 * @return void
1089 */
1090 public function printContent() {
1091 echo $this->content;
1092 }
1093
1094 /***************************
1095 *
1096 * Sub-content functions, rendering specific parts of the module content.
1097 *
1098 ***************************/
1099 /**
1100 * Create the panel of buttons for submitting the form or otherwise perform operations.
1101 *
1102 * @param string $function Identifier for function of module
1103 * @return array all available buttons as an assoc. array
1104 */
1105 protected function getButtons($function = '') {
1106 $lang = $this->getLanguageService();
1107 $buttons = array(
1108 'view' => '',
1109 'history_page' => '',
1110 'new_content' => '',
1111 'move_page' => '',
1112 'move_record' => '',
1113 'new_page' => '',
1114 'edit_page' => '',
1115 'edit_language' => '',
1116 'csh' => '',
1117 'shortcut' => '',
1118 'cache' => '',
1119 'savedok' => '',
1120 'save_close' => '',
1121 'savedokshow' => '',
1122 'closedok' => '',
1123 'deletedok' => '',
1124 'undo' => '',
1125 'history_record' => ''
1126 );
1127 // View page
1128 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1129 $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>';
1130 }
1131 // Shortcut
1132 if ($this->getBackendUser()->mayMakeShortcut()) {
1133 $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']);
1134 }
1135 // Cache
1136 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1137 $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>';
1138 }
1139 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1140 // Move record
1141 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1142 $urlParameters = [
1143 'table' => $this->eRParts[0],
1144 'uid' => $this->eRParts[1],
1145 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1146 ];
1147 $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>';
1148 }
1149
1150 // Edit page properties and page language overlay icons
1151 if ($this->pageIsNotLockedForEditors()) {
1152
1153 // Edit localized page_language_overlay only when one specific language is selected
1154 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1155 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1156 'uid',
1157 'pages_language_overlay',
1158 'pid = ' . (int)$this->id . ' ' .
1159 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1160 BackendUtility::deleteClause('pages_language_overlay') .
1161 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1162 '',
1163 '',
1164 '',
1165 'sys_language_uid'
1166 );
1167
1168 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1169 $buttons['edit_language'] = '<a href="#" ' .
1170 'onclick="' . $editLanguageOnClick . '"' .
1171 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1172 IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1173 '</a>';
1174 }
1175
1176
1177 // Edit page properties
1178 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1179 $buttons['edit_page'] = '<a href="#" ' .
1180 'onclick="' . $editPageOnClick . '"' .
1181 'title="' . $lang->getLL('editPageProperties', TRUE) . '">' .
1182 IconUtility::getSpriteIcon('actions-page-open') .
1183 '</a>';
1184 }
1185
1186 // Add CSH (Context Sensitive Help) icon to tool bar
1187 if ($function == 'quickEdit') {
1188 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1189 } else {
1190 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1191 }
1192 if ($function == 'quickEdit') {
1193 // Save record
1194 $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) . '" />'));
1195 // Save and close
1196 $buttons['save_close'] = IconUtility::getSpriteIcon('actions-document-save-close', array('html' => '<input type="image" class="c-inputButton" src="clear.gif" name="_saveandclosedok" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" />'));
1197 // Save record and show page
1198 $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>';
1199 // Close record
1200 $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>';
1201 // Delete record
1202 if ($this->deleteButton) {
1203 $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>';
1204 }
1205 if ($this->undoButton) {
1206 // Undo button
1207 $buttons['undo'] = '<a href="#"
1208 onclick="' . htmlspecialchars('window.location.href=' .
1209 GeneralUtility::quoteJSvalue(
1210 $GLOBALS['BACK_PATH'] .
1211 BackendUtility::getModuleUrl(
1212 'record_history',
1213 array(
1214 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1215 'revert' => 'ALL_FIELDS',
1216 'sumUp' => -1,
1217 'returnUrl' => $this->R_URI,
1218 )
1219 )
1220 ) . '; return false;') . '"
1221 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>';
1222 // History button
1223 $buttons['history_record'] = '<a href="#"
1224 onclick="' . htmlspecialchars('jumpToUrl(' .
1225 GeneralUtility::quoteJSvalue(
1226 $GLOBALS['BACK_PATH'] .
1227 BackendUtility::getModuleUrl(
1228 'record_history',
1229 array(
1230 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1231 'returnUrl' => $this->R_URI,
1232 )
1233 ) . '#latest'
1234 ) . ');return false;') . '"
1235 title="' . $lang->getLL('recordHistory', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1236 }
1237 }
1238 }
1239 return $buttons;
1240 }
1241
1242 /*******************************
1243 *
1244 * Other functions
1245 *
1246 ******************************/
1247 /**
1248 * Returns the number of hidden elements (including those hidden by start/end times)
1249 * on the current page (for the current sys_language)
1250 *
1251 * @return int
1252 */
1253 public function getNumberOfHiddenElements() {
1254 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1255 'uid',
1256 'tt_content',
1257 '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')
1258 );
1259 }
1260
1261 /**
1262 * Returns URL to the current script.
1263 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1264 *
1265 * @param array $params Parameters array, merged with global GET vars.
1266 * @return string URL
1267 */
1268 public function local_linkThisScript($params) {
1269 $params['popView'] = '';
1270 $params['new_unique_uid'] = '';
1271 return GeneralUtility::linkThisScript($params);
1272 }
1273
1274 /**
1275 * Returns a SQL query for selecting sys_language records.
1276 *
1277 * @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)
1278 * @return string Return query string.
1279 */
1280 public function exec_languageQuery($id) {
1281 if ($id) {
1282 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1283 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1284 return $this->getDatabaseConnection()->exec_SELECTquery(
1285 'sys_language.*',
1286 'pages_language_overlay,sys_language',
1287 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1288 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1289 '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',
1290 'sys_language.title'
1291 );
1292 } else {
1293 return $this->getDatabaseConnection()->exec_SELECTquery(
1294 'sys_language.*',
1295 'sys_language',
1296 'sys_language.hidden=0',
1297 '',
1298 'sys_language.title'
1299 );
1300 }
1301 }
1302
1303 /**
1304 * Check the editlock access
1305 *
1306 * @return bool
1307 */
1308 public function pageIsNotLockedForEditors() {
1309 return !($this->pageinfo['editlock'] && ($this->CALC_PERMS & Permission::PAGE_EDIT));
1310 }
1311
1312 /**
1313 * Returns LanguageService
1314 *
1315 * @return \TYPO3\CMS\Lang\LanguageService
1316 */
1317 protected function getLanguageService() {
1318 return $GLOBALS['LANG'];
1319 }
1320
1321 /**
1322 * Returns the current BE user.
1323 *
1324 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1325 */
1326 protected function getBackendUser() {
1327 return $GLOBALS['BE_USER'];
1328 }
1329
1330 /**
1331 * Returns the database connection
1332 *
1333 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1334 */
1335 protected function getDatabaseConnection() {
1336 return $GLOBALS['TYPO3_DB'];
1337 }
1338
1339 }