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