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