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