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