PageLayoutController.php 53.3 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller;

4
5
6
7
8
9
10
11
12
13
14
15
16
17
/***************************************************************
 *  Copyright notice
 *
 *  (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *  A copy is found in the text file GPL.txt and important notices to the license
19
20
21
22
23
24
25
26
27
28
29
 *  from the author is found in LICENSE.txt distributed with these scripts.
 *
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

Nicole Cordes's avatar
Nicole Cordes committed
30
31
32
33
34
35
36
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\Utility\IconUtility;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
 * Script Class for Web > Layout module
 *
 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
 */
class PageLayoutController {

	// Internal, GPvars:
	// Page Id for which to make the listing
	/**
	 * @todo Define visibility
	 */
	public $id;

	// Pointer - for browsing list of records.
	/**
	 * @todo Define visibility
	 */
	public $pointer;

	// Thumbnails or not
	/**
	 * @todo Define visibility
	 */
	public $imagemode;

	// Search-fields
	/**
	 * @todo Define visibility
	 */
	public $search_field;

	// Search-levels
	/**
	 * @todo Define visibility
	 */
	public $search_levels;

	// Show-limit
	/**
	 * @todo Define visibility
	 */
	public $showLimit;

	// Return URL
	/**
	 * @todo Define visibility
	 */
	public $returnUrl;

	// Clear-cache flag - if set, clears page cache for current id.
	/**
	 * @todo Define visibility
	 */
	public $clear_cache;

	// PopView id - for opening a window with the page
	/**
	 * @todo Define visibility
	 */
	public $popView;

	// QuickEdit: Variable, that tells quick edit what to show/edit etc. Format is [tablename]:[uid] with some exceptional values for both parameters (with special meanings).
	/**
	 * @todo Define visibility
	 */
	public $edit_record;

	// QuickEdit: If set, this variable tells quick edit that the last edited record had this value as UID and we should look up the new, real uid value in sys_log.
	/**
	 * @todo Define visibility
	 */
	public $new_unique_uid;

	// Internal, static:
	// Page select perms clause
	/**
	 * @todo Define visibility
	 */
	public $perms_clause;

	// Module TSconfig
	/**
	 * @todo Define visibility
	 */
	public $modTSconfig;

	// Current ids page record
	/**
	 * @todo Define visibility
	 */
	public $pageinfo;

	/**
	 * Document template object
	 *
133
	 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
	 * @todo Define visibility
	 */
	public $doc;

	// Back path of the module
	/**
	 * @todo Define visibility
	 */
	public $backPath;

	// "Pseudo" Description -table name
	/**
	 * @todo Define visibility
	 */
	public $descrTable;

	// List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
	/**
	 * @todo Define visibility
	 */
	public $colPosList;

	// Flag: If content can be edited or not.
	/**
	 * @todo Define visibility
	 */
	public $EDIT_CONTENT;

	// Users permissions integer for this page.
	/**
	 * @todo Define visibility
	 */
	public $CALC_PERMS;

	// Currently selected language for editing content elements
	/**
	 * @todo Define visibility
	 */
	public $current_sys_language;

	// Module configuration
	/**
	 * @todo Define visibility
	 */
	public $MCONF = array();

	// Menu configuration
	/**
	 * @todo Define visibility
	 */
	public $MOD_MENU = array();

	// Module settings (session variable)
	/**
	 * @todo Define visibility
	 */
	public $MOD_SETTINGS = array();

	// Array, where files to include is accumulated in the init() function
	/**
	 * @todo Define visibility
	 */
	public $include_once = array();

	// Array of tables to be listed by the Web > Page module in addition to the default tables
	/**
	 * @todo Define visibility
	 */
	public $externalTables = array();

	// Internal, dynamic:
	// Module output accumulation
	/**
	 * @todo Define visibility
	 */
	public $content;

	// Function menu temporary storage
	/**
	 * @todo Define visibility
	 */
	public $topFuncMenu;

	// Temporary storage for page edit icon
	/**
	 * @todo Define visibility
	 */
	public $editIcon;

	/**
	 * Initializing the module
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function init() {
		// Setting module configuration / page select clause
		$this->MCONF = $GLOBALS['MCONF'];
		$this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
		$this->backPath = $GLOBALS['BACK_PATH'];
		// GPvars:
235
		$this->id = (int)GeneralUtility::_GP('id');
Nicole Cordes's avatar
Nicole Cordes committed
236
237
238
239
240
241
242
243
244
245
		$this->pointer = GeneralUtility::_GP('pointer');
		$this->imagemode = GeneralUtility::_GP('imagemode');
		$this->clear_cache = GeneralUtility::_GP('clear_cache');
		$this->popView = GeneralUtility::_GP('popView');
		$this->edit_record = GeneralUtility::_GP('edit_record');
		$this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
		$this->search_field = GeneralUtility::_GP('search_field');
		$this->search_levels = GeneralUtility::_GP('search_levels');
		$this->showLimit = GeneralUtility::_GP('showLimit');
		$this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
246
247
		$this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
		// Load page info array:
Nicole Cordes's avatar
Nicole Cordes committed
248
		$this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
249
250
251
		// Initialize menu
		$this->menuConfig();
		// Setting sys language from session var:
252
		$this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
		// CSH / Descriptions:
		$this->descrTable = '_MOD_' . $this->MCONF['name'];
	}

	/**
	 * Initialize menu array
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function menuConfig() {
		// MENU-ITEMS:
		$this->MOD_MENU = array(
			'tt_content_showHidden' => '',
			'showPalettes' => '',
			'showDescriptions' => '',
			'disableRTE' => '',
			'function' => array(
				0 => $GLOBALS['LANG']->getLL('m_function_0'),
				1 => $GLOBALS['LANG']->getLL('m_function_1'),
				2 => $GLOBALS['LANG']->getLL('m_function_2')
			),
			'language' => array(
				0 => $GLOBALS['LANG']->getLL('m_default')
			)
		);
		// example settings:
		// 	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
		//		array ('default' => array(
282
		//				'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
		//				'fList' =>  'title,description,image',
		//				'icon' => TRUE));
		if (is_array($this->externalTables)) {
			foreach ($this->externalTables as $table => $tableSettings) {
				// delete the default settings from above
				if (is_array($this->MOD_MENU[$table])) {
					unset($this->MOD_MENU[$table]);
				}
				if (is_array($tableSettings) && count($tableSettings) > 1) {
					foreach ($tableSettings as $key => $settings) {
						$this->MOD_MENU[$table][$key] = $GLOBALS['LANG']->sL($settings['MENU']);
					}
				}
			}
		}
		// 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.
		$res = $this->exec_languageQuery($this->id);
		while ($lrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			if ($GLOBALS['BE_USER']->checkLanguageAccess($lrow['uid'])) {
302
				$this->MOD_MENU['language'][$lrow['uid']] = $lrow['hidden'] ? '(' . $lrow['title'] . ')' : $lrow['title'];
303
304
305
306
307
308
309
310
			}
		}
		// Find if there are ANY languages at all (and if not, remove the language option from function menu).
		$count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'sys_language', $GLOBALS['BE_USER']->isAdmin() ? '' : 'hidden=0');
		if (!$count) {
			unset($this->MOD_MENU['function']['2']);
		}
		// page/be_user TSconfig settings and blinding of menu-items
Nicole Cordes's avatar
Nicole Cordes committed
311
312
		$this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
		$this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
313
314
315
		if ($this->modTSconfig['properties']['QEisDefault']) {
			ksort($this->MOD_MENU['function']);
		}
Nicole Cordes's avatar
Nicole Cordes committed
316
		$this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
317
		// Remove QuickEdit as option if page type is not...
Nicole Cordes's avatar
Nicole Cordes committed
318
		if (!GeneralUtility::inList(($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6'), $this->pageinfo['doktype'])) {
319
320
321
322
323
324
325
			unset($this->MOD_MENU['function'][0]);
		}
		// Setting alternative default label:
		if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
			$this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
		}
		// Clean up settings
Nicole Cordes's avatar
Nicole Cordes committed
326
		$this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name']);
327
328
329
330
331
332
333
334
335
336
337
338
339
340
		// For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
		if ($GLOBALS['BE_USER']->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
			$this->MOD_SETTINGS['tt_content_showHidden'] = 1;
		}
	}

	/**
	 * Clears page cache for the current id, $this->id
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function clearCache() {
		if ($this->clear_cache) {
Nicole Cordes's avatar
Nicole Cordes committed
341
			$tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
			$tce->stripslashes_values = 0;
			$tce->start(array(), array());
			$tce->clear_cacheCmd($this->id);
		}
	}

	/**
	 * Generate the flashmessages for current pid
	 *
	 * @return string HTML content with flashmessages
	 */
	protected function getHeaderFlashMessagesForCurrentPid() {
		$content = '';
		// If page is a folder
		if ($this->pageinfo['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SYSFOLDER) {
			// Access to list module
Nicole Cordes's avatar
Nicole Cordes committed
358
			$moduleLoader = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
359
360
361
			$moduleLoader->load($GLOBALS['TBE_MODULES']);
			$modules = $moduleLoader->modules;
			if (is_array($modules['web']['sub']['list'])) {
Nicole Cordes's avatar
Nicole Cordes committed
362
				$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '<p>' . $GLOBALS['LANG']->getLL('goToListModuleMessage') . '</p>
363
					<br />
Nicole Cordes's avatar
Nicole Cordes committed
364
					<p>' . IconUtility::getSpriteIcon('actions-system-list-open') . '<a href="javascript:top.goToModule( \'web_list\',1);">' . $GLOBALS['LANG']->getLL('goToListModule') . '
365
						</a>
Nicole Cordes's avatar
Nicole Cordes committed
366
					</p>', '', FlashMessage::INFO);
367
368
369
370
371
				$content .= $flashMessage->render();
			}
		}
		// If content from different pid is displayed
		if ($this->pageinfo['content_from_pid']) {
372
			$contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
Nicole Cordes's avatar
Nicole Cordes committed
373
			$title = BackendUtility::getRecordTitle('pages', $contentPage);
374
			$linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
375
			$link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
Nicole Cordes's avatar
Nicole Cordes committed
376
			$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('content_from_pid_title'), $link), '', FlashMessage::INFO);
377
378
379
380
381
			$content .= $flashMessage->render();
		}
		return $content;
	}

382
383
384
385
386
387
388
389
390
	/**
	 *
	 * @return string $title
	 */
	protected function getLocalizedPageTitle() {
		if ($this->current_sys_language > 0) {
			$overlayRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
				'title',
				'pages_language_overlay',
391
392
				'pid = ' . (int)$this->id .
						' AND sys_language_uid = ' . (int)$this->current_sys_language .
Nicole Cordes's avatar
Nicole Cordes committed
393
394
						BackendUtility::deleteClause('pages_language_overlay') .
						BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
395
396
397
398
399
400
401
402
403
404
405
				'',
				'',
				'',
				'sys_language_uid'
			);
			return $overlayRecord['title'];
		} else {
			return $this->pageinfo['title'];
		}
	}

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
	/**
	 * Main function.
	 * Creates some general objects and calls other functions for the main rendering of module content.
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function main() {
		// Access check...
		// The page will show only if there is a valid page and if this page may be viewed by the user
		$access = is_array($this->pageinfo) ? 1 : 0;
		if ($this->id && $access) {
			// Initialize permission settings:
			$this->CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($this->pageinfo);
			$this->EDIT_CONTENT = $this->CALC_PERMS & 16 ? 1 : 0;
			// Start document template object:
Nicole Cordes's avatar
Nicole Cordes committed
422
			$this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
423
			$this->doc->backPath = $GLOBALS['BACK_PATH'];
424
			$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
425
			// JavaScript:
426
			$this->doc->JScode = '<script type="text/javascript" ' . 'src="' . GeneralUtility::createVersionNumberedFilename(($GLOBALS['BACK_PATH'] . 'js/jsfunc.updateform.js')) . '">' . '</script>';
427
			$this->doc->JScode .= $this->doc->wrapScriptTags('
428
429
				if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
				if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
430
431
432
433
434
435
436
437
438
				function jumpToUrl(URL,formEl) {	//
					if (document.editform && TBE_EDITOR.isFormChanged)	{	// Check if the function exists... (works in all browsers?)
						if (!TBE_EDITOR.isFormChanged())	{	//
							window.location.href = URL;
						} else if (formEl) {
							if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
						}
					} else window.location.href = URL;
				}
Nicole Cordes's avatar
Nicole Cordes committed
439
			' . ($this->popView ? BackendUtility::viewOnClick($this->id, $GLOBALS['BACK_PATH'], BackendUtility::BEgetRootLine($this->id)) : '') . '
440
441

				function deleteRecord(table,id,url) {	//
442
					if (confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('deleteWarning')) . ')) {
Nicole Cordes's avatar
Nicole Cordes committed
443
						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";
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
					}
					return false;
				}
			');
			$this->doc->JScode .= $this->doc->wrapScriptTags('
				var DTM_array = new Array();
				var DTM_origClass = new String();

					// if tabs are used in a popup window the array might not exists
				if(!top.DTM_currentTabs) {
					top.DTM_currentTabs = new Array();
				}

				function DTM_activate(idBase,index,doToogle) {	//
						// Hiding all:
					if (DTM_array[idBase]) {
						for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
							if (DTM_array[idBase][cnt] != idBase+"-"+index) {
								document.getElementById(DTM_array[idBase][cnt]+"-DIV").style.display = "none";
								document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
							}
						}
					}

						// Showing one:
					if (document.getElementById(idBase+"-"+index+"-DIV")) {
						if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
							document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
							if(DTM_origClass=="") {
								document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
							} else {
								DTM_origClass = "tab";
							}
							top.DTM_currentTabs[idBase] = -1;
						} else {
							document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
							if(DTM_origClass=="") {
								document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
							} else {
								DTM_origClass = "tabact";
							}
							top.DTM_currentTabs[idBase] = index;
						}
					}
				}
				function DTM_toggle(idBase,index,isInit) {	//
						// Showing one:
					if (document.getElementById(idBase+"-"+index+"-DIV")) {
						if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
							document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
							if(isInit) {
								document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
							} else {
								DTM_origClass = "tab";
							}
							top.DTM_currentTabs[idBase+"-"+index] = 0;
						} else {
							document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
							if(isInit) {
								document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
							} else {
								DTM_origClass = "tabact";
							}
							top.DTM_currentTabs[idBase+"-"+index] = 1;
						}
					}
				}

				function DTM_mouseOver(obj) {	//
						DTM_origClass = obj.attributes.getNamedItem(\'class\').nodeValue;
						obj.attributes.getNamedItem(\'class\').nodeValue += "_over";
				}

				function DTM_mouseOut(obj) {	//
						obj.attributes.getNamedItem(\'class\').nodeValue = DTM_origClass;
						DTM_origClass = "";
				}
			');
			// Setting doc-header
523
			$this->doc->form = '<form action="' . htmlspecialchars(('db_layout.php?id=' . $this->id . '&imagemode=' . $this->imagemode)) . '" method="post">';
524
			// Creating the top function menu:
Nicole Cordes's avatar
Nicole Cordes committed
525
			$this->topFuncMenu = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'], 'db_layout.php', '');
526
			$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', '') : '';
527
			// Find backend layout / coumns
Nicole Cordes's avatar
Nicole Cordes committed
528
			$backendLayout = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getSelectedBackendLayout', $this->id, $this);
529
530
531
532
			if (count($backendLayout['__colPosList'])) {
				$this->colPosList = implode(',', $backendLayout['__colPosList']);
			}
			// Removing duplicates, if any
Nicole Cordes's avatar
Nicole Cordes committed
533
			$this->colPosList = implode(',', array_unique(GeneralUtility::intExplode(',', $this->colPosList)));
534
			// Page title
535
			$body = $this->doc->header($this->getLocalizedPageTitle());
536
537
538
539
540
541
542
543
544
545
546
547
548
			$body .= $this->getHeaderFlashMessagesForCurrentPid();
			// Render the primary module content:
			if ($this->MOD_SETTINGS['function'] == 0) {
				// QuickEdit
				$body .= $this->renderQuickEdit();
			} else {
				// All other listings
				$body .= $this->renderListContent();
			}
			// Setting up the buttons and markers for docheader
			$docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
			$markers = array(
				'CSH' => $docHeaderButtons['csh'],
549
				'TOP_FUNCTION_MENU' => $this->topFuncMenu . $this->editSelect,
550
551
552
553
554
555
556
557
558
				'LANGSELECTOR' => $this->languageMenu,
				'CONTENT' => $body
			);
			// Build the <body> for the module
			$this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
			// Renders the module page
			$this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
		} else {
			// If no access or id value, create empty document:
Nicole Cordes's avatar
Nicole Cordes committed
559
			$this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
560
			$this->doc->backPath = $GLOBALS['BACK_PATH'];
561
			$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
562
			$this->doc->JScode = $this->doc->wrapScriptTags('
563
				if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
564
			');
Nicole Cordes's avatar
Nicole Cordes committed
565
			$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('clickAPage_content'), $GLOBALS['LANG']->getLL('clickAPage_header'), FlashMessage::INFO);
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
			$body = $flashMessage->render();
			// Setting up the buttons and markers for docheader
			$docHeaderButtons = array(
				'view' => '',
				'history_page' => '',
				'new_content' => '',
				'move_page' => '',
				'move_record' => '',
				'new_page' => '',
				'edit_page' => '',
				'csh' => '',
				'shortcut' => '',
				'cache' => '',
				'savedok' => '',
				'savedokshow' => '',
				'closedok' => '',
				'deletedok' => '',
				'undo' => '',
584
585
				'history_record' => '',
				'edit_language' => ''
586
587
			);
			$markers = array(
Nicole Cordes's avatar
Nicole Cordes committed
588
				'CSH' => BackendUtility::cshItem($this->descrTable, '', $GLOBALS['BACK_PATH'], '', TRUE),
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
				'TOP_FUNCTION_MENU' => '',
				'LANGSELECTOR' => '',
				'CONTENT' => $body
			);
			$this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
			// Renders the module page
			$this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
		}
	}

	/**
	 * Rendering the quick-edit view.
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function renderQuickEdit() {
		// Alternative template
607
		$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
608
		// Alternative form tag; Quick Edit submits its content to tce_db.php.
609
		$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);">';
610
611
612
613
614
615
		// Setting up the context sensitive menu:
		$this->doc->getContextMenuCode();
		// Set the edit_record value for internal use in this function:
		$edit_record = $this->edit_record;
		// If a command to edit all records in a column is issue, then select all those elements, and redirect to alt_doc.php:
		if (substr($edit_record, 0, 9) == '_EDIT_COL') {
616
			$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');
617
618
619
620
			$idListA = array();
			while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
				$idListA[] = $cRow['uid'];
			}
621
			$url = $GLOBALS['BACK_PATH'] . 'alt_doc.php?edit[tt_content][' . implode(',', $idListA) . ']=edit&returnUrl=' . rawurlencode($this->local_linkThisScript(array('edit_record' => '')));
622
623
624
625
			\TYPO3\CMS\Core\Utility\HttpUtility::redirect($url);
		}
		// If the former record edited was the creation of a NEW record, this will look up the created records uid:
		if ($this->new_unique_uid) {
626
			$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'));
627
628
			$sys_log_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
			if (is_array($sys_log_row)) {
629
				$edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
630
631
632
633
634
635
636
			}
		}
		// Creating the selector box, allowing the user to select which element to edit:
		$opt = array();
		$is_selected = 0;
		$languageOverlayRecord = '';
		if ($this->current_sys_language) {
637
			list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
638
639
640
		}
		if (is_array($languageOverlayRecord)) {
			$inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
641
			$is_selected += (int)$edit_record == $inValue;
642
			$opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('editLanguageHeader', TRUE) . ' ]</option>';
643
644
		} else {
			$inValue = 'pages:' . $this->id;
645
			$is_selected += (int)$edit_record == $inValue;
646
			$opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('editPageProperties', TRUE) . ' ]</option>';
647
648
		}
		// Selecting all content elements from this language and allowed colPos:
649
		$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');
650
		$colPos = NULL;
651
652
653
654
		$first = 1;
		// Page is the pid if no record to put this after.
		$prev = $this->id;
		while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
Nicole Cordes's avatar
Nicole Cordes committed
655
			BackendUtility::workspaceOL('tt_content', $cRow);
656
657
658
659
660
661
662
			if (is_array($cRow)) {
				if ($first) {
					if (!$edit_record) {
						$edit_record = 'tt_content:' . $cRow['uid'];
					}
					$first = 0;
				}
663
				if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
664
665
					$colPos = $cRow['colPos'];
					$opt[] = '<option value=""></option>';
666
					$opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $GLOBALS['LANG']->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
667
668
				}
				$inValue = 'tt_content:' . $cRow['uid'];
669
				$is_selected += (int)$edit_record == $inValue;
Nicole Cordes's avatar
Nicole Cordes committed
670
				$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>';
671
672
673
674
675
				$prev = -$cRow['uid'];
			}
		}
		// If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
		if (!$edit_record) {
676
677
			$edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
			$inValue = 'tt_content:new/' . $prev . '/' . $colPos;
678
			$is_selected += (int)$edit_record == $inValue;
679
			$opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('newLabel', 1) . ' ]</option>';
680
681
682
683
		}
		// If none is yet selected...
		if (!$is_selected) {
			$opt[] = '<option value=""></option>';
684
			$opt[] = '<option value="' . $edit_record . '"  selected="selected">[ ' . $GLOBALS['LANG']->getLL('newLabel', TRUE) . ' ]</option>';
685
686
687
688
		}
		// Splitting the edit-record cmd value into table/uid:
		$this->eRParts = explode(':', $edit_record);
		// Delete-button flag?
Nicole Cordes's avatar
Nicole Cordes committed
689
		$this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & 4);
690
691
		// If undo-button should be rendered (depends on available items in sys_history)
		$this->undoButton = 0;
692
		$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');
693
694
695
696
		if ($this->undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
			$this->undoButton = 1;
		}
		// Setting up the Return URL for coming back to THIS script (if links take the user to another script)
Nicole Cordes's avatar
Nicole Cordes committed
697
698
		$R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
		$R_URL_getvars = GeneralUtility::_GET();
699
700
701
		unset($R_URL_getvars['popView']);
		unset($R_URL_getvars['new_unique_uid']);
		$R_URL_getvars['edit_record'] = $edit_record;
Nicole Cordes's avatar
Nicole Cordes committed
702
		$this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
703
704
705
706
707
708
709
		// Setting close url/return url for exiting this script:
		// Goes to 'Columns' view if close is pressed (default)
		$this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
		if ($this->returnUrl) {
			$this->closeUrl = $this->returnUrl;
		}
		// Return-url for JavaScript:
710
		$retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+\'' . rawurlencode($this->returnUrl) . '\'' : '';
711
		// Drawing the edit record selectbox
712
		$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>';
713
		// Creating editing form:
714
		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)) {
715
716
717
718
			// Splitting uid parts for special features, if new:
			list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
			// Convert $uidVal to workspace version if any:
			if ($uidVal != 'new') {
Nicole Cordes's avatar
Nicole Cordes committed
719
				if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->eRParts[0], $uidVal, 'uid')) {
720
721
722
723
					$uidVal = $draftRecord['uid'];
				}
			}
			// Initializing transfer-data object:
Nicole Cordes's avatar
Nicole Cordes committed
724
			$trData = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
725
726
			$trData->addRawData = TRUE;
			$trData->defVals[$this->eRParts[0]] = array(
727
728
				'colPos' => (int)$ex_colPos,
				'sys_language_uid' => (int)$this->current_sys_language
729
730
731
732
733
734
735
736
737
738
739
			);
			$trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
			$trData->lockRecords = 1;
			// 'new'
			$trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
			// Getting/Making the record:
			reset($trData->regTableItems_data);
			$rec = current($trData->regTableItems_data);
			if ($uidVal == 'new') {
				$new_unique_uid = uniqid('NEW');
				$rec['uid'] = $new_unique_uid;
740
				$rec['pid'] = (int)$ex_pid ?: $this->id;
741
742
743
744
745
746
747
748
				$recordAccess = TRUE;
			} else {
				$rec['uid'] = $uidVal;
				// Checking internals access:
				$recordAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($this->eRParts[0], $uidVal);
			}
			if (!$recordAccess) {
				// If no edit access, print error message:
749
				$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);
750
751
752
			} elseif (is_array($rec)) {
				// If the record is an array (which it will always be... :-)
				// Create instance of TCEforms, setting defaults:
Nicole Cordes's avatar
Nicole Cordes committed
753
				$tceforms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
754
755
756
757
758
759
760
761
				$tceforms->backPath = $GLOBALS['BACK_PATH'];
				$tceforms->initDefaultBEMode();
				$tceforms->fieldOrder = $this->modTSconfig['properties']['tt_content.']['fieldOrder'];
				$tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
				$tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
				$tceforms->enableClickMenu = TRUE;
				// Clipboard is initialized:
				// Start clipboard
Nicole Cordes's avatar
Nicole Cordes committed
762
				$tceforms->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
763
764
765
766
767
768
769
770
771
				// Initialize - reads the clipboard content from the user session
				$tceforms->clipObj->initializeClipboard();
				// Render form, wrap it:
				$panel = '';
				$panel .= $tceforms->getMainFields($this->eRParts[0], $rec);
				$panel = $tceforms->wrapTotal($panel, $rec, $this->eRParts[0]);
				// Add hidden fields:
				$theCode = $panel;
				if ($uidVal == 'new') {
772
					$theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
773
				}
774
775
776
777
				$theCode .= '
					<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
					<input type="hidden" name="_disableRTE" value="' . $tceforms->disableRTE . '" />
					<input type="hidden" name="edit_record" value="' . $edit_record . '" />
Nicole Cordes's avatar
Nicole Cordes committed
778
					<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)) . '" />
779
					' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
780
				// Add JavaScript as needed around the form:
781
				$theCode = $tceforms->printNeededJSFunctions_top() . $theCode . $tceforms->printNeededJSFunctions();
782
				// Add warning sign if record was "locked":
Nicole Cordes's avatar
Nicole Cordes committed
783
784
				if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
					$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
785
					/** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
Nicole Cordes's avatar
Nicole Cordes committed
786
					$flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
787
788
789
					/** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
					$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
					$defaultFlashMessageQueue->enqueue($flashMessage);
790
791
				}
				// Add whole form as a document section:
792
				$content = $this->doc->section('', $theCode);
793
794
795
			}
		} else {
			// If no edit access, print error message:
796
			$content = $this->doc->section($GLOBALS['LANG']->getLL('noAccess'), $GLOBALS['LANG']->getLL('noAccess_msg') . '<br /><br />', 0, 1);
797
798
799
		}
		// Bottom controls (function menus):
		$q_count = $this->getNumberOfHiddenElements();
800
		$h_func_b = BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], 'db_layout.php', '', 'id="checkTt_content_showHidden"') . '<label for="checkTt_content_showHidden">' . (!$q_count ? $GLOBALS['TBE_TEMPLATE']->dfw($GLOBALS['LANG']->getLL('hiddenCE', TRUE)) : $GLOBALS['LANG']->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') . '</label>';
801
		$h_func_b .= '<br />' . BackendUtility::getFuncCheck($this->id, 'SET[showPalettes]', $this->MOD_SETTINGS['showPalettes'], 'db_layout.php', '', 'id="checkShowPalettes"') . '<label for="checkShowPalettes">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPalettes', TRUE) . '</label>';
Nicole Cordes's avatar
Nicole Cordes committed
802
		if (ExtensionManagementUtility::isLoaded('context_help')) {
803
			$h_func_b .= '<br />' . BackendUtility::getFuncCheck($this->id, 'SET[showDescriptions]', $this->MOD_SETTINGS['showDescriptions'], 'db_layout.php', '', 'id="checkShowDescriptions"') . '<label for="checkShowDescriptions">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showDescriptions', TRUE) . '</label>';
804
805
		}
		if ($GLOBALS['BE_USER']->isRTE()) {
806
			$h_func_b .= '<br />' . BackendUtility::getFuncCheck($this->id, 'SET[disableRTE]', $this->MOD_SETTINGS['disableRTE'], 'db_layout.php', '', 'id="checkDisableRTE"') . '<label for="checkDisableRTE">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.disableRTE', TRUE) . '</label>';
807
808
809
810
811
		}
		// Add the function menus to bottom:
		$content .= $this->doc->section('', $h_func_b, 0, 0);
		$content .= $this->doc->spacer(10);
		// Select element matrix:
Nicole Cordes's avatar
Nicole Cordes committed
812
813
		if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
			$posMap = GeneralUtility::makeInstance('ext_posMap');
814
815
816
817
			$posMap->backPath = $GLOBALS['BACK_PATH'];
			$posMap->cur_sys_language = $this->current_sys_language;
			$HTMLcode = '';
			// CSH:
Nicole Cordes's avatar
Nicole Cordes committed
818
			$HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', $GLOBALS['BACK_PATH'], '|<br />');
819
820
821
822
823
824
825
			$HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
			$content .= $this->doc->spacer(20);
			$content .= $this->doc->section($GLOBALS['LANG']->getLL('CEonThisPage'), $HTMLcode, 0, 1);
			$content .= $this->doc->spacer(20);
		}
		// Finally, if comments were generated in TCEforms object, print these as a HTML comment:
		if (count($tceforms->commentMessages)) {
826
			$content .= '
827
	<!-- TCEFORM messages
828
	' . htmlspecialchars(implode(LF, $tceforms->commentMessages)) . '
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
	-->
	';
		}
		return $content;
	}

	/**
	 * Rendering all other listings than QuickEdit
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function renderListContent() {
		// Initialize list object (see "class.db_layout.inc"):
		/** @var $dblist \TYPO3\CMS\Backend\View\PageLayoutView */
Nicole Cordes's avatar
Nicole Cordes committed
844
		$dblist = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\PageLayoutView');
845
846
847
848
		$dblist->backPath = $GLOBALS['BACK_PATH'];
		$dblist->thumbs = $this->imagemode;
		$dblist->no_noWrap = 1;
		$dblist->descrTable = $this->descrTable;
Nicole Cordes's avatar
Nicole Cordes committed
849
		$this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
850
851
852
853
854
		$dblist->script = 'db_layout.php';
		$dblist->showIcon = 0;
		$dblist->setLMargin = 0;
		$dblist->doEdit = $this->EDIT_CONTENT;
		$dblist->ext_CALC_PERMS = $this->CALC_PERMS;
855
		$dblist->agePrefixes = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
856
		$dblist->id = $this->id;
Nicole Cordes's avatar
Nicole Cordes committed
857
		$dblist->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
		$dblist->option_showBigButtons = $this->modTSconfig['properties']['disableBigButtons'] === '0';
		$dblist->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
		$dblist->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
		if (!$dblist->nextThree) {
			$dblist->nextThree = 1;
		}
		$dblist->externalTables = $this->externalTables;
		// Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
		$h_menu = $dblist->getTableMenu($this->id);
		// Initialize other variables:
		$h_func = '';
		$tableOutput = array();
		$tableJSOutput = array();
		$CMcounter = 0;
		// Traverse the list of table names which has records on this page (that array is populated
		// by the $dblist object during the function getTableMenu()):
		foreach ($dblist->activeTables as $table => $value) {
			if (!isset($dblist->externalTables[$table])) {
				$q_count = $this->getNumberOfHiddenElements();
Nicole Cordes's avatar
Nicole Cordes committed
877
				$h_func_b = BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], 'db_layout.php', '', 'id="checkTt_content_showHidden"') . '<label for="checkTt_content_showHidden">' . (!$q_count ? $GLOBALS['TBE_TEMPLATE']->dfw($GLOBALS['LANG']->getLL('hiddenCE')) : $GLOBALS['LANG']->getLL('hiddenCE') . ' (' . $q_count . ')') . '</label>';
878
879
880
881
882
883
884
885
886
887
888
889
890
891
				// Boolean: Display up/down arrows and edit icons for tt_content records
				$dblist->tt_contentConfig['showCommands'] = 1;
				// Boolean: Display info-marks or not
				$dblist->tt_contentConfig['showInfo'] = 1;
				// Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol'] is shown
				// in the total width of the page
				$dblist->tt_contentConfig['single'] = 0;
				if ($this->MOD_SETTINGS['function'] == 4) {
					// Grid view
					$dblist->tt_contentConfig['showAsGrid'] = 1;
				}
				// Setting up the tt_content columns to show:
				if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
					$colList = array();
Nicole Cordes's avatar
Nicole Cordes committed
892
					$tcaItems = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getColPosListItemsParsed', $this->id, $this);
893
894
895
896
897
898
899
					foreach ($tcaItems as $temp) {
						$colList[] = $temp[1];
					}
				} else {
					// ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
					$colList = array('1', '0', '2', '3');
				}
900
				if ($this->colPosList !== '') {
Nicole Cordes's avatar
Nicole Cordes committed
901
					$colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
902
903
904
905
906
907
908
909
910
911
912
913
				}
				// If only one column found, display the single-column view.
				if (count($colList) === 1 && !$this->MOD_SETTINGS['function'] === 4) {
					// Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol']
					// is shown in the total width of the page
					$dblist->tt_contentConfig['single'] = 1;
					// The column(s) to show if single mode (under each other)
					$dblist->tt_contentConfig['showSingleCol'] = current($colList);
				}
				// The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
				$dblist->tt_contentConfig['cols'] = implode(',', $colList);
				$dblist->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
914
				$dblist->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
915
916
917
918
919
920
921
922
923
				// If the function menu is set to "Language":
				if ($this->MOD_SETTINGS['function'] == 2) {
					$dblist->tt_contentConfig['single'] = 0;
					$dblist->tt_contentConfig['languageMode'] = 1;
					$dblist->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
					$dblist->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
				}
			} else {
				if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
Nicole Cordes's avatar
Nicole Cordes committed
924
					$h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], 'db_layout.php', '');
925
926
927
928
929
930
931
932
933
934
935
936
937
938
				} else {
					$h_func = '';
				}
			}
			// Start the dblist object:
			$dblist->itemsLimitSingleTable = 1000;
			$dblist->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
			$dblist->counter = $CMcounter;
			$dblist->ext_function = $this->MOD_SETTINGS['function'];
			// Render versioning selector:
			$dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
			// Generate the list of elements here:
			$dblist->generateList();
			// Adding the list content to the tableOutput variable:
939
			$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 : '');
940
941
942
943
944
945
946
947
948
949
950
951
952
			// ... and any accumulated JavaScript goes the same way!
			$tableJSOutput[$table] = $dblist->JScode;
			// Increase global counter:
			$CMcounter += $dblist->counter;
			// Reset variables after operation:
			$dblist->HTMLcode = '';
			$dblist->JScode = '';
			$h_func = '';
			$h_func_b = '';
		}
		// END: traverse tables
		// For Context Sensitive Menus:
		$this->doc->getContextMenuCode();
953
954
955
956
957
958
959
960
961
962
		// Init the content
		$content = '';
		// Additional header content
		$headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
		if (is_array($headerContentHook)) {
			foreach ($headerContentHook as $hook) {
				$params = array();
				$content .= GeneralUtility::callUserFunction($hook, $params, $this);
			}
		}
963
964
965
966
967
968
969
970
		// Add the content for each table we have rendered (traversing $tableOutput variable)
		foreach ($tableOutput as $table => $output) {
			$content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
			$content .= $this->doc->spacer(15);
			$content .= $this->doc->sectionEnd();
		}
		// Making search form:
		if (!$this->modTSconfig['properties']['disableSearchBox'] && count($tableOutput)) {
Nicole Cordes's avatar
Nicole Cordes committed
971
			$sectionTitle = BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.search', TRUE));
972
973
974
975
976
977
978
			$content .= $this->doc->section($sectionTitle, $dblist->getSearchBox(0), FALSE, TRUE, FALSE, TRUE);
		}
		// Additional footer content
		$footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
		if (is_array($footerContentHook)) {
			foreach ($footerContentHook as $hook) {
				$params = array();
Nicole Cordes's avatar
Nicole Cordes committed
979
				$content .= GeneralUtility::callUserFunction($hook, $params, $this);
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
			}
		}
		return $content;
	}

	/**
	 * Print accumulated content of module
	 *
	 * @return void
	 * @todo Define visibility
	 */
	public function printContent() {
		echo $this->content;
	}

	/***************************
	 *
	 * Sub-content functions, rendering specific parts of the module content.
	 *
	 ***************************/
	/**