Revert "[TASK] Remove usage of property $new_unique_uid"
[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
452 // override the default jumpToUrl
453 $this->doc->JScodeArray['jumpToUrl'] = '
454 function jumpToUrl(URL,formEl) {
455 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
456 if (!TBE_EDITOR.isFormChanged()) {
457 window.location.href = URL;
458 } else if (formEl) {
459 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
460 }
461 } else {
462 window.location.href = URL;
463 }
464 }
465 ';
466
467 $this->doc->JScode .= $this->doc->wrapScriptTags('
468 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
469 if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
470 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->id)) : '') . '
471
472 function deleteRecord(table,id,url) { //
473 if (confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('deleteWarning')) . ')) {
474 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";
475 }
476 return false;
477 }
478 ');
479 $this->doc->JScode .= $this->doc->wrapScriptTags('
480 var DTM_array = new Array();
481 var DTM_origClass = new String();
482
483 // if tabs are used in a popup window the array might not exists
484 if(!top.DTM_currentTabs) {
485 top.DTM_currentTabs = new Array();
486 }
487
488 function DTM_activate(idBase,index,doToogle) { //
489 // Hiding all:
490 if (DTM_array[idBase]) {
491 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
492 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
493 document.getElementById(DTM_array[idBase][cnt]+"-DIV").style.display = "none";
494 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
495 }
496 }
497 }
498
499 // Showing one:
500 if (document.getElementById(idBase+"-"+index+"-DIV")) {
501 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
502 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
503 if(DTM_origClass=="") {
504 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
505 } else {
506 DTM_origClass = "tab";
507 }
508 top.DTM_currentTabs[idBase] = -1;
509 } else {
510 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
511 if(DTM_origClass=="") {
512 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "active";
513 } else {
514 DTM_origClass = "active";
515 }
516 top.DTM_currentTabs[idBase] = index;
517 }
518 }
519 }
520 function DTM_toggle(idBase,index,isInit) { //
521 // Showing one:
522 if (document.getElementById(idBase+"-"+index+"-DIV")) {
523 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
524 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
525 if(isInit) {
526 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
527 } else {
528 DTM_origClass = "tab";
529 }
530 top.DTM_currentTabs[idBase+"-"+index] = 0;
531 } else {
532 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
533 if(isInit) {
534 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "active";
535 } else {
536 DTM_origClass = "active";
537 }
538 top.DTM_currentTabs[idBase+"-"+index] = 1;
539 }
540 }
541 }
542
543 function DTM_mouseOver(obj) { //
544 DTM_origClass = obj.attributes.getNamedItem(\'class\').nodeValue;
545 obj.attributes.getNamedItem(\'class\').nodeValue += "_over";
546 }
547
548 function DTM_mouseOut(obj) { //
549 obj.attributes.getNamedItem(\'class\').nodeValue = DTM_origClass;
550 DTM_origClass = "";
551 }
552 ');
553 // Setting doc-header
554 $this->doc->form = '<form action="' . htmlspecialchars(('db_layout.php?id=' . $this->id . '&imagemode=' . $this->imagemode)) . '" 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'], 'db_layout.php', '');
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'], 'db_layout.php', '') : '';
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('db_layout.php?id=' . $this->id . '&edit_record=') . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);')) . '">' . implode('', $opt) . '</select>';
758 // Creating editing form:
759 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)) {
760 // Splitting uid parts for special features, if new:
761 list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
762 // Convert $uidVal to workspace version if any:
763 if ($uidVal != 'new') {
764 if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->eRParts[0], $uidVal, 'uid')) {
765 $uidVal = $draftRecord['uid'];
766 }
767 }
768 // Initializing transfer-data object:
769 $trData = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\DataPreprocessor::class);
770 $trData->addRawData = TRUE;
771 $trData->defVals[$this->eRParts[0]] = array(
772 'colPos' => (int)$ex_colPos,
773 'sys_language_uid' => (int)$this->current_sys_language
774 );
775 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
776 $trData->lockRecords = 1;
777 // 'new'
778 $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
779 // Getting/Making the record:
780 reset($trData->regTableItems_data);
781 $rec = current($trData->regTableItems_data);
782 if ($uidVal == 'new') {
783 $new_unique_uid = uniqid('NEW', TRUE);
784 $rec['uid'] = $new_unique_uid;
785 $rec['pid'] = (int)$ex_pid ?: $this->id;
786 $recordAccess = TRUE;
787 } else {
788 $rec['uid'] = $uidVal;
789 // Checking internals access:
790 $recordAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($this->eRParts[0], $uidVal);
791 }
792 if (!$recordAccess) {
793 // If no edit access, print error message:
794 $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);
795 } elseif (is_array($rec)) {
796 // If the record is an array (which it will always be... :-)
797 // Create instance of TCEforms, setting defaults:
798 $tceforms = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Form\FormEngine::class);
799 $tceforms->backPath = $GLOBALS['BACK_PATH'];
800 $tceforms->initDefaultBEMode();
801 $tceforms->fieldOrder = $this->modTSconfig['properties']['tt_content.']['fieldOrder'];
802 $tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
803 $tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
804 $tceforms->enableClickMenu = TRUE;
805 $tceforms->enableTabMenu = TRUE;
806 // Clipboard is initialized:
807 // Start clipboard
808 $tceforms->clipObj = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
809 // Initialize - reads the clipboard content from the user session
810 $tceforms->clipObj->initializeClipboard();
811 // Render form, wrap it:
812 $panel = '';
813 $panel .= $tceforms->getMainFields($this->eRParts[0], $rec);
814 $panel = $tceforms->wrapTotal($panel, $rec, $this->eRParts[0]);
815 // Add hidden fields:
816 $theCode = $panel;
817 if ($uidVal == 'new') {
818 $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
819 }
820 $theCode .= '
821 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
822 <input type="hidden" name="_disableRTE" value="' . $tceforms->disableRTE . '" />
823 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
824 <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)) . '" />
825 ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
826 // Add JavaScript as needed around the form:
827 $theCode = $tceforms->printNeededJSFunctions_top() . $theCode . $tceforms->printNeededJSFunctions();
828 // Add warning sign if record was "locked":
829 if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
830 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
831 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
832 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
833 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
834 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
835 $defaultFlashMessageQueue->enqueue($flashMessage);
836 }
837 // Add whole form as a document section:
838 $content = $this->doc->section('', $theCode);
839 }
840 } else {
841 // If no edit access, print error message:
842 $content = $this->doc->section($GLOBALS['LANG']->getLL('noAccess'), $GLOBALS['LANG']->getLL('noAccess_msg') . '<br /><br />', 0, 1);
843 }
844 // Bottom controls (function menus):
845 $q_count = $this->getNumberOfHiddenElements();
846
847 $h_func_b = '<div class="checkbox">' .
848 '<label for="checkTt_content_showHidden">' .
849 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], 'db_layout.php', '', 'id="checkTt_content_showHidden"') .
850 (!$q_count ? ('<span class="text-muted">' . $GLOBALS['LANG']->getLL('hiddenCE', TRUE) . '</span>') : $GLOBALS['LANG']->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
851 '</label>' .
852 '</div>';
853
854 $h_func_b .= '<div class="checkbox">' .
855 '<label for="checkShowPalettes">' .
856 BackendUtility::getFuncCheck($this->id, 'SET[showPalettes]', $this->MOD_SETTINGS['showPalettes'], 'db_layout.php', '', 'id="checkShowPalettes"') .
857 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPalettes', TRUE) .
858 '</label>' .
859 '</div>';
860
861 if (ExtensionManagementUtility::isLoaded('context_help')) {
862 $h_func_b .= '<div class="checkbox">' .
863 '<label for="checkShowDescriptions">' .
864 BackendUtility::getFuncCheck($this->id, 'SET[showDescriptions]', $this->MOD_SETTINGS['showDescriptions'], 'db_layout.php', '', 'id="checkShowDescriptions"') .
865 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showDescriptions', TRUE) .
866 '</label>' .
867 '</div>';
868 }
869 if ($GLOBALS['BE_USER']->isRTE()) {
870 $h_func_b .= '<div class="checkbox">' .
871 '<label for="checkDisableRTE">' .
872 BackendUtility::getFuncCheck($this->id, 'SET[disableRTE]', $this->MOD_SETTINGS['disableRTE'], 'db_layout.php', '', 'id="checkDisableRTE"') .
873 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.disableRTE', TRUE) .
874 '</label>' .
875 '</div>';
876 }
877 // Add the function menus to bottom:
878 $content .= $this->doc->section('', $h_func_b, 0, 0);
879 $content .= $this->doc->spacer(10);
880 // Select element matrix:
881 if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
882 $posMap = GeneralUtility::makeInstance(\ext_posMap::class);
883 $posMap->backPath = $GLOBALS['BACK_PATH'];
884 $posMap->cur_sys_language = $this->current_sys_language;
885 $HTMLcode = '';
886 // CSH:
887 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
888 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
889 $content .= $this->doc->spacer(20);
890 $content .= $this->doc->section($GLOBALS['LANG']->getLL('CEonThisPage'), $HTMLcode, 0, 1);
891 $content .= $this->doc->spacer(20);
892 }
893 // Finally, if comments were generated in TCEforms object, print these as a HTML comment:
894 if (count($tceforms->commentMessages)) {
895 $content .= '
896 <!-- TCEFORM messages
897 ' . htmlspecialchars(implode(LF, $tceforms->commentMessages)) . '
898 -->
899 ';
900 }
901 return $content;
902 }
903
904 /**
905 * Rendering all other listings than QuickEdit
906 *
907 * @return void
908 */
909 public function renderListContent() {
910 // Initialize list object (see "class.db_layout.inc"):
911 /** @var $dblist \TYPO3\CMS\Backend\View\PageLayoutView */
912 $dblist = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\View\PageLayoutView::class);
913 $dblist->backPath = $GLOBALS['BACK_PATH'];
914 $dblist->thumbs = $this->imagemode;
915 $dblist->no_noWrap = 1;
916 $dblist->descrTable = $this->descrTable;
917 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
918 $dblist->script = 'db_layout.php';
919 $dblist->showIcon = 0;
920 $dblist->setLMargin = 0;
921 $dblist->doEdit = $this->EDIT_CONTENT;
922 $dblist->ext_CALC_PERMS = $this->CALC_PERMS;
923 $dblist->agePrefixes = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
924 $dblist->id = $this->id;
925 $dblist->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
926 $dblist->option_showBigButtons = $this->modTSconfig['properties']['disableBigButtons'] === '0';
927 $dblist->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
928 $dblist->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
929 if (!$dblist->nextThree) {
930 $dblist->nextThree = 1;
931 }
932 $dblist->externalTables = $this->externalTables;
933 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
934 $h_menu = $dblist->getTableMenu($this->id);
935 // Initialize other variables:
936 $h_func = '';
937 $tableOutput = array();
938 $tableJSOutput = array();
939 $CMcounter = 0;
940 // Traverse the list of table names which has records on this page (that array is populated
941 // by the $dblist object during the function getTableMenu()):
942 foreach ($dblist->activeTables as $table => $value) {
943 if (!isset($dblist->externalTables[$table])) {
944 $q_count = $this->getNumberOfHiddenElements();
945
946 $h_func_b = '<div class="checkbox">' .
947 '<label for="checkTt_content_showHidden">' .
948 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], 'db_layout.php', '', 'id="checkTt_content_showHidden"') .
949 (!$q_count ? ('<span class="text-muted">' . $GLOBALS['LANG']->getLL('hiddenCE') . '</span>') : $GLOBALS['LANG']->getLL('hiddenCE') . ' (' . $q_count . ')') .
950 '</label>' .
951 '</div>';
952
953 // Boolean: Display up/down arrows and edit icons for tt_content records
954 $dblist->tt_contentConfig['showCommands'] = 1;
955 // Boolean: Display info-marks or not
956 $dblist->tt_contentConfig['showInfo'] = 1;
957 // Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol'] is shown
958 // in the total width of the page
959 $dblist->tt_contentConfig['single'] = 0;
960 if ($this->MOD_SETTINGS['function'] == 4) {
961 // Grid view
962 $dblist->tt_contentConfig['showAsGrid'] = 1;
963 }
964 // Setting up the tt_content columns to show:
965 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
966 $colList = array();
967 $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
968 foreach ($tcaItems as $temp) {
969 $colList[] = $temp[1];
970 }
971 } else {
972 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
973 $colList = array('1', '0', '2', '3');
974 }
975 if ($this->colPosList !== '') {
976 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
977 }
978 // If only one column found, display the single-column view.
979 if (count($colList) === 1 && !$this->MOD_SETTINGS['function'] === 4) {
980 // Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol']
981 // is shown in the total width of the page
982 $dblist->tt_contentConfig['single'] = 1;
983 // The column(s) to show if single mode (under each other)
984 $dblist->tt_contentConfig['showSingleCol'] = current($colList);
985 }
986 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
987 $dblist->tt_contentConfig['cols'] = implode(',', $colList);
988 $dblist->tt_contentConfig['activeCols'] = $this->activeColPosList;
989 $dblist->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
990 $dblist->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
991 // If the function menu is set to "Language":
992 if ($this->MOD_SETTINGS['function'] == 2) {
993 $dblist->tt_contentConfig['single'] = 0;
994 $dblist->tt_contentConfig['languageMode'] = 1;
995 $dblist->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
996 $dblist->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
997 }
998 } else {
999 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1000 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], 'db_layout.php', '');
1001 } else {
1002 $h_func = '';
1003 }
1004 }
1005 // Start the dblist object:
1006 $dblist->itemsLimitSingleTable = 1000;
1007 $dblist->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1008 $dblist->counter = $CMcounter;
1009 $dblist->ext_function = $this->MOD_SETTINGS['function'];
1010 // Render versioning selector:
1011 $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
1012 // Generate the list of elements here:
1013 $dblist->generateList();
1014 // Adding the list content to the tableOutput variable:
1015 $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 : '');
1016 // ... and any accumulated JavaScript goes the same way!
1017 $tableJSOutput[$table] = $dblist->JScode;
1018 // Increase global counter:
1019 $CMcounter += $dblist->counter;
1020 // Reset variables after operation:
1021 $dblist->HTMLcode = '';
1022 $dblist->JScode = '';
1023 $h_func = '';
1024 $h_func_b = '';
1025 }
1026 // END: traverse tables
1027 // For Context Sensitive Menus:
1028 $this->doc->getContextMenuCode();
1029 // Init the content
1030 $content = '';
1031 // Additional header content
1032 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1033 if (is_array($headerContentHook)) {
1034 foreach ($headerContentHook as $hook) {
1035 $params = array();
1036 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1037 }
1038 }
1039 // Add the content for each table we have rendered (traversing $tableOutput variable)
1040 foreach ($tableOutput as $table => $output) {
1041 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1042 $content .= $this->doc->spacer(15);
1043 $content .= $this->doc->sectionEnd();
1044 }
1045 // Making search form:
1046 if (!$this->modTSconfig['properties']['disableSearchBox'] && count($tableOutput)) {
1047 $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>';
1048 $this->markers['SEARCHBOX'] = $dblist->getSearchBox(0);
1049 }
1050 // Additional footer content
1051 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1052 if (is_array($footerContentHook)) {
1053 foreach ($footerContentHook as $hook) {
1054 $params = array();
1055 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1056 }
1057 }
1058 return $content;
1059 }
1060
1061 /**
1062 * Print accumulated content of module
1063 *
1064 * @return void
1065 */
1066 public function printContent() {
1067 echo $this->content;
1068 }
1069
1070 /***************************
1071 *
1072 * Sub-content functions, rendering specific parts of the module content.
1073 *
1074 ***************************/
1075 /**
1076 * Create the panel of buttons for submitting the form or otherwise perform operations.
1077 *
1078 * @param string $function Identifier for function of module
1079 * @return array all available buttons as an assoc. array
1080 */
1081 protected function getButtons($function = '') {
1082 $buttons = array(
1083 'view' => '',
1084 'history_page' => '',
1085 'new_content' => '',
1086 'move_page' => '',
1087 'move_record' => '',
1088 'new_page' => '',
1089 'edit_page' => '',
1090 'edit_language' => '',
1091 'csh' => '',
1092 'shortcut' => '',
1093 'cache' => '',
1094 'savedok' => '',
1095 'save_close' => '',
1096 'savedokshow' => '',
1097 'closedok' => '',
1098 'deletedok' => '',
1099 'undo' => '',
1100 'history_record' => ''
1101 );
1102 // View page
1103 $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>';
1104 // Shortcut
1105 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
1106 $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']);
1107 }
1108 // Cache
1109 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1110 $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>';
1111 }
1112 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1113 // Move record
1114 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1115 $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>';
1116 }
1117
1118 // Edit page properties and page language overlay icons
1119 if ($this->CALC_PERMS & 2) {
1120
1121 // Edit localized page_language_overlay only when one specific language is selected
1122 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1123 $overlayRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
1124 'uid',
1125 'pages_language_overlay',
1126 'pid = ' . (int)$this->id . ' ' .
1127 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1128 BackendUtility::deleteClause('pages_language_overlay') .
1129 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1130 '',
1131 '',
1132 '',
1133 'sys_language_uid'
1134 );
1135
1136 $editLanguageOnClick = htmlspecialchars(
1137 BackendUtility::editOnClick(
1138 '&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit',
1139 $GLOBALS['BACK_PATH'])
1140 );
1141 $buttons['edit_language'] = '<a href="#" ' .
1142 'onclick="' . $editLanguageOnClick . '"' .
1143 'title="' . $GLOBALS['LANG']->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1144 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1145 '</a>';
1146 }
1147
1148
1149 // Edit page properties
1150 $editPageOnClick = htmlspecialchars(
1151 BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit', $GLOBALS['BACK_PATH'])
1152 );
1153 $buttons['edit_page'] = '<a href="#" ' .
1154 'onclick="' . $editPageOnClick . '"' .
1155 'title="' . $GLOBALS['LANG']->getLL('editPageProperties', TRUE) . '">' .
1156 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-page-open') .
1157 '</a>';
1158 }
1159
1160 // Add CSH (Context Sensitive Help) icon to tool bar
1161 if ($function == 'quickEdit') {
1162 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1163 } else {
1164 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1165 }
1166 if ($function == 'quickEdit') {
1167 // Save record
1168 $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) . '" />'));
1169 // Save and close
1170 $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) . '" />'));
1171 // Save record and show page
1172 $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>';
1173 // Close record
1174 $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>';
1175 // Delete record
1176 if ($this->deleteButton) {
1177 $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>';
1178 }
1179 if ($this->undoButton) {
1180 // Undo button
1181 $buttons['undo'] = '<a href="#"
1182 onclick="' . htmlspecialchars('window.location.href=' .
1183 GeneralUtility::quoteJSvalue(
1184 $GLOBALS['BACK_PATH'] .
1185 BackendUtility::getModuleUrl(
1186 'record_history',
1187 array(
1188 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1189 'revert' => 'ALL_FIELDS',
1190 'sumUp' => -1,
1191 'returnUrl' => $this->R_URI,
1192 )
1193 )
1194 ) . '; return false;') . '"
1195 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>';
1196 // History button
1197 $buttons['history_record'] = '<a href="#"
1198 onclick="' . htmlspecialchars('jumpToUrl(' .
1199 GeneralUtility::quoteJSvalue(
1200 $GLOBALS['BACK_PATH'] .
1201 BackendUtility::getModuleUrl(
1202 'record_history',
1203 array(
1204 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1205 'returnUrl' => $this->R_URI,
1206 )
1207 ) . '#latest'
1208 ) . ');return false;') . '"
1209 title="' . $GLOBALS['LANG']->getLL('recordHistory', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1210 }
1211 }
1212 }
1213 return $buttons;
1214 }
1215
1216 /*******************************
1217 *
1218 * Other functions
1219 *
1220 ******************************/
1221 /**
1222 * Returns the number of hidden elements (including those hidden by start/end times)
1223 * on the current page (for the current sys_language)
1224 *
1225 * @return int
1226 */
1227 public function getNumberOfHiddenElements() {
1228 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
1229 'uid',
1230 'tt_content',
1231 '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')
1232 );
1233 }
1234
1235 /**
1236 * Returns URL to the current script.
1237 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1238 *
1239 * @param array $params Parameters array, merged with global GET vars.
1240 * @return string URL
1241 */
1242 public function local_linkThisScript($params) {
1243 $params['popView'] = '';
1244 $params['new_unique_uid'] = '';
1245 return GeneralUtility::linkThisScript($params);
1246 }
1247
1248 /**
1249 * Returns a SQL query for selecting sys_language records.
1250 *
1251 * @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)
1252 * @return string Return query string.
1253 */
1254 public function exec_languageQuery($id) {
1255 if ($id) {
1256 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1257 ($GLOBALS['BE_USER']->isAdmin() ? '' : ' AND sys_language.hidden=0');
1258 return $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1259 'sys_language.*',
1260 'pages_language_overlay,sys_language',
1261 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1262 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1263 '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',
1264 'sys_language.title'
1265 );
1266 } else {
1267 return $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1268 'sys_language.*',
1269 'sys_language',
1270 'sys_language.hidden=0',
1271 '',
1272 'sys_language.title'
1273 );
1274 }
1275 }
1276
1277 }