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