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