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