[BUGFIX] Followup 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 (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 $this->activeColPosList = implode(',', $this->activeColPosList);
553 }
554 $this->colPosList = implode(',', $this->colPosList);
555
556 // Page title
557 $body = $this->doc->header($this->getLocalizedPageTitle());
558 $body .= $this->getHeaderFlashMessagesForCurrentPid();
559 // Render the primary module content:
560 if ($this->MOD_SETTINGS['function'] == 0) {
561 // QuickEdit
562 $body .= $this->renderQuickEdit();
563 } else {
564 // All other listings
565 $body .= $this->renderListContent();
566 }
567 // Setting up the buttons and markers for docheader
568 $docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
569 $markers = array(
570 'CSH' => $docHeaderButtons['csh'],
571 'TOP_FUNCTION_MENU' => $this->topFuncMenu . $this->editSelect,
572 'LANGSELECTOR' => $this->languageMenu,
573 'CONTENT' => $body
574 );
575 // Build the <body> for the module
576 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
577 // Renders the module page
578 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
579 } else {
580 // If no access or id value, create empty document:
581 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
582 $this->doc->backPath = $GLOBALS['BACK_PATH'];
583 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
584 $this->doc->JScode = $this->doc->wrapScriptTags('
585 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
586 ');
587 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('clickAPage_content'), $GLOBALS['LANG']->getLL('clickAPage_header'), FlashMessage::INFO);
588 $body = $flashMessage->render();
589 // Setting up the buttons and markers for docheader
590 $docHeaderButtons = array(
591 'view' => '',
592 'history_page' => '',
593 'new_content' => '',
594 'move_page' => '',
595 'move_record' => '',
596 'new_page' => '',
597 'edit_page' => '',
598 'csh' => '',
599 'shortcut' => '',
600 'cache' => '',
601 'savedok' => '',
602 'savedokshow' => '',
603 'closedok' => '',
604 'deletedok' => '',
605 'undo' => '',
606 'history_record' => '',
607 'edit_language' => ''
608 );
609 $markers = array(
610 'CSH' => BackendUtility::cshItem($this->descrTable, '', $GLOBALS['BACK_PATH'], '', TRUE),
611 'TOP_FUNCTION_MENU' => '',
612 'LANGSELECTOR' => '',
613 'CONTENT' => $body
614 );
615 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
616 // Renders the module page
617 $this->content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $this->content);
618 }
619 }
620
621 /**
622 * Rendering the quick-edit view.
623 *
624 * @return void
625 * @todo Define visibility
626 */
627 public function renderQuickEdit() {
628 // Alternative template
629 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
630 // Alternative form tag; Quick Edit submits its content to tce_db.php.
631 $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);">';
632 // Setting up the context sensitive menu:
633 $this->doc->getContextMenuCode();
634 // Set the edit_record value for internal use in this function:
635 $edit_record = $this->edit_record;
636 // If a command to edit all records in a column is issue, then select all those elements, and redirect to alt_doc.php:
637 if (substr($edit_record, 0, 9) == '_EDIT_COL') {
638 $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');
639 $idListA = array();
640 while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
641 $idListA[] = $cRow['uid'];
642 }
643 $url = $GLOBALS['BACK_PATH'] . 'alt_doc.php?edit[tt_content][' . implode(',', $idListA) . ']=edit&returnUrl=' . rawurlencode($this->local_linkThisScript(array('edit_record' => '')));
644 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($url);
645 }
646 // If the former record edited was the creation of a NEW record, this will look up the created records uid:
647 if ($this->new_unique_uid) {
648 $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'));
649 $sys_log_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
650 if (is_array($sys_log_row)) {
651 $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
652 }
653 }
654 // Creating the selector box, allowing the user to select which element to edit:
655 $opt = array();
656 $is_selected = 0;
657 $languageOverlayRecord = '';
658 if ($this->current_sys_language) {
659 list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
660 }
661 if (is_array($languageOverlayRecord)) {
662 $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
663 $is_selected += (int)$edit_record == $inValue;
664 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('editLanguageHeader', TRUE) . ' ]</option>';
665 } else {
666 $inValue = 'pages:' . $this->id;
667 $is_selected += (int)$edit_record == $inValue;
668 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('editPageProperties', TRUE) . ' ]</option>';
669 }
670 // Selecting all content elements from this language and allowed colPos:
671 $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');
672 $colPos = NULL;
673 $first = 1;
674 // Page is the pid if no record to put this after.
675 $prev = $this->id;
676 while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
677 BackendUtility::workspaceOL('tt_content', $cRow);
678 if (is_array($cRow)) {
679 if ($first) {
680 if (!$edit_record) {
681 $edit_record = 'tt_content:' . $cRow['uid'];
682 }
683 $first = 0;
684 }
685 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
686 $colPos = $cRow['colPos'];
687 $opt[] = '<option value=""></option>';
688 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $GLOBALS['LANG']->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
689 }
690 $inValue = 'tt_content:' . $cRow['uid'];
691 $is_selected += (int)$edit_record == $inValue;
692 $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>';
693 $prev = -$cRow['uid'];
694 }
695 }
696 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
697 if (!$edit_record) {
698 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
699 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
700 $is_selected += (int)$edit_record == $inValue;
701 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $GLOBALS['LANG']->getLL('newLabel', 1) . ' ]</option>';
702 }
703 // If none is yet selected...
704 if (!$is_selected) {
705 $opt[] = '<option value=""></option>';
706 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $GLOBALS['LANG']->getLL('newLabel', TRUE) . ' ]</option>';
707 }
708 // Splitting the edit-record cmd value into table/uid:
709 $this->eRParts = explode(':', $edit_record);
710 // Delete-button flag?
711 $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($this->eRParts[0] != 'pages' && $this->EDIT_CONTENT || $this->eRParts[0] == 'pages' && $this->CALC_PERMS & 4);
712 // If undo-button should be rendered (depends on available items in sys_history)
713 $this->undoButton = 0;
714 $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');
715 if ($this->undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
716 $this->undoButton = 1;
717 }
718 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
719 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
720 $R_URL_getvars = GeneralUtility::_GET();
721 unset($R_URL_getvars['popView']);
722 unset($R_URL_getvars['new_unique_uid']);
723 $R_URL_getvars['edit_record'] = $edit_record;
724 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
725 // Setting close url/return url for exiting this script:
726 // Goes to 'Columns' view if close is pressed (default)
727 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
728 if ($this->returnUrl) {
729 $this->closeUrl = $this->returnUrl;
730 }
731 // Return-url for JavaScript:
732 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+\'' . rawurlencode($this->returnUrl) . '\'' : '';
733 // Drawing the edit record selectbox
734 $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>';
735 // Creating editing form:
736 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)) {
737 // Splitting uid parts for special features, if new:
738 list($uidVal, $ex_pid, $ex_colPos) = explode('/', $this->eRParts[1]);
739 // Convert $uidVal to workspace version if any:
740 if ($uidVal != 'new') {
741 if ($draftRecord = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $this->eRParts[0], $uidVal, 'uid')) {
742 $uidVal = $draftRecord['uid'];
743 }
744 }
745 // Initializing transfer-data object:
746 $trData = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
747 $trData->addRawData = TRUE;
748 $trData->defVals[$this->eRParts[0]] = array(
749 'colPos' => (int)$ex_colPos,
750 'sys_language_uid' => (int)$this->current_sys_language
751 );
752 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
753 $trData->lockRecords = 1;
754 // 'new'
755 $trData->fetchRecord($this->eRParts[0], $uidVal == 'new' ? $this->id : $uidVal, $uidVal);
756 // Getting/Making the record:
757 reset($trData->regTableItems_data);
758 $rec = current($trData->regTableItems_data);
759 if ($uidVal == 'new') {
760 $new_unique_uid = uniqid('NEW');
761 $rec['uid'] = $new_unique_uid;
762 $rec['pid'] = (int)$ex_pid ?: $this->id;
763 $recordAccess = TRUE;
764 } else {
765 $rec['uid'] = $uidVal;
766 // Checking internals access:
767 $recordAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($this->eRParts[0], $uidVal);
768 }
769 if (!$recordAccess) {
770 // If no edit access, print error message:
771 $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);
772 } elseif (is_array($rec)) {
773 // If the record is an array (which it will always be... :-)
774 // Create instance of TCEforms, setting defaults:
775 $tceforms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
776 $tceforms->backPath = $GLOBALS['BACK_PATH'];
777 $tceforms->initDefaultBEMode();
778 $tceforms->fieldOrder = $this->modTSconfig['properties']['tt_content.']['fieldOrder'];
779 $tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
780 $tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
781 $tceforms->enableClickMenu = TRUE;
782 // Clipboard is initialized:
783 // Start clipboard
784 $tceforms->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
785 // Initialize - reads the clipboard content from the user session
786 $tceforms->clipObj->initializeClipboard();
787 // Render form, wrap it:
788 $panel = '';
789 $panel .= $tceforms->getMainFields($this->eRParts[0], $rec);
790 $panel = $tceforms->wrapTotal($panel, $rec, $this->eRParts[0]);
791 // Add hidden fields:
792 $theCode = $panel;
793 if ($uidVal == 'new') {
794 $theCode .= '<input type="hidden" name="data[' . $this->eRParts[0] . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
795 }
796 $theCode .= '
797 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
798 <input type="hidden" name="_disableRTE" value="' . $tceforms->disableRTE . '" />
799 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
800 <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)) . '" />
801 ' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction');
802 // Add JavaScript as needed around the form:
803 $theCode = $tceforms->printNeededJSFunctions_top() . $theCode . $tceforms->printNeededJSFunctions();
804 // Add warning sign if record was "locked":
805 if ($lockInfo = BackendUtility::isRecordLocked($this->eRParts[0], $rec['uid'])) {
806 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
807 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
808 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
809 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
810 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
811 $defaultFlashMessageQueue->enqueue($flashMessage);
812 }
813 // Add whole form as a document section:
814 $content = $this->doc->section('', $theCode);
815 }
816 } else {
817 // If no edit access, print error message:
818 $content = $this->doc->section($GLOBALS['LANG']->getLL('noAccess'), $GLOBALS['LANG']->getLL('noAccess_msg') . '<br /><br />', 0, 1);
819 }
820 // Bottom controls (function menus):
821 $q_count = $this->getNumberOfHiddenElements();
822 $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>';
823 $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>';
824 if (ExtensionManagementUtility::isLoaded('context_help')) {
825 $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>';
826 }
827 if ($GLOBALS['BE_USER']->isRTE()) {
828 $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>';
829 }
830 // Add the function menus to bottom:
831 $content .= $this->doc->section('', $h_func_b, 0, 0);
832 $content .= $this->doc->spacer(10);
833 // Select element matrix:
834 if ($this->eRParts[0] == 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
835 $posMap = GeneralUtility::makeInstance('ext_posMap');
836 $posMap->backPath = $GLOBALS['BACK_PATH'];
837 $posMap->cur_sys_language = $this->current_sys_language;
838 $HTMLcode = '';
839 // CSH:
840 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', $GLOBALS['BACK_PATH'], '|<br />');
841 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
842 $content .= $this->doc->spacer(20);
843 $content .= $this->doc->section($GLOBALS['LANG']->getLL('CEonThisPage'), $HTMLcode, 0, 1);
844 $content .= $this->doc->spacer(20);
845 }
846 // Finally, if comments were generated in TCEforms object, print these as a HTML comment:
847 if (count($tceforms->commentMessages)) {
848 $content .= '
849 <!-- TCEFORM messages
850 ' . htmlspecialchars(implode(LF, $tceforms->commentMessages)) . '
851 -->
852 ';
853 }
854 return $content;
855 }
856
857 /**
858 * Rendering all other listings than QuickEdit
859 *
860 * @return void
861 * @todo Define visibility
862 */
863 public function renderListContent() {
864 // Initialize list object (see "class.db_layout.inc"):
865 /** @var $dblist \TYPO3\CMS\Backend\View\PageLayoutView */
866 $dblist = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\View\\PageLayoutView');
867 $dblist->backPath = $GLOBALS['BACK_PATH'];
868 $dblist->thumbs = $this->imagemode;
869 $dblist->no_noWrap = 1;
870 $dblist->descrTable = $this->descrTable;
871 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
872 $dblist->script = 'db_layout.php';
873 $dblist->showIcon = 0;
874 $dblist->setLMargin = 0;
875 $dblist->doEdit = $this->EDIT_CONTENT;
876 $dblist->ext_CALC_PERMS = $this->CALC_PERMS;
877 $dblist->agePrefixes = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
878 $dblist->id = $this->id;
879 $dblist->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
880 $dblist->option_showBigButtons = $this->modTSconfig['properties']['disableBigButtons'] === '0';
881 $dblist->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
882 $dblist->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
883 if (!$dblist->nextThree) {
884 $dblist->nextThree = 1;
885 }
886 $dblist->externalTables = $this->externalTables;
887 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
888 $h_menu = $dblist->getTableMenu($this->id);
889 // Initialize other variables:
890 $h_func = '';
891 $tableOutput = array();
892 $tableJSOutput = array();
893 $CMcounter = 0;
894 // Traverse the list of table names which has records on this page (that array is populated
895 // by the $dblist object during the function getTableMenu()):
896 foreach ($dblist->activeTables as $table => $value) {
897 if (!isset($dblist->externalTables[$table])) {
898 $q_count = $this->getNumberOfHiddenElements();
899 $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>';
900 // Boolean: Display up/down arrows and edit icons for tt_content records
901 $dblist->tt_contentConfig['showCommands'] = 1;
902 // Boolean: Display info-marks or not
903 $dblist->tt_contentConfig['showInfo'] = 1;
904 // Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol'] is shown
905 // in the total width of the page
906 $dblist->tt_contentConfig['single'] = 0;
907 if ($this->MOD_SETTINGS['function'] == 4) {
908 // Grid view
909 $dblist->tt_contentConfig['showAsGrid'] = 1;
910 }
911 // Setting up the tt_content columns to show:
912 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
913 $colList = array();
914 $tcaItems = GeneralUtility::callUserFunction('TYPO3\\CMS\\Backend\\View\\BackendLayoutView->getColPosListItemsParsed', $this->id, $this);
915 foreach ($tcaItems as $temp) {
916 $colList[] = $temp[1];
917 }
918 } else {
919 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
920 $colList = array('1', '0', '2', '3');
921 }
922 if ($this->colPosList !== '') {
923 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
924 }
925 // If only one column found, display the single-column view.
926 if (count($colList) === 1 && !$this->MOD_SETTINGS['function'] === 4) {
927 // Boolean: If set, the content of column(s) $this->tt_contentConfig['showSingleCol']
928 // is shown in the total width of the page
929 $dblist->tt_contentConfig['single'] = 1;
930 // The column(s) to show if single mode (under each other)
931 $dblist->tt_contentConfig['showSingleCol'] = current($colList);
932 }
933 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
934 $dblist->tt_contentConfig['cols'] = implode(',', $colList);
935 $dblist->tt_contentConfig['activeCols'] = $this->activeColPosList;
936 $dblist->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
937 $dblist->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
938 // If the function menu is set to "Language":
939 if ($this->MOD_SETTINGS['function'] == 2) {
940 $dblist->tt_contentConfig['single'] = 0;
941 $dblist->tt_contentConfig['languageMode'] = 1;
942 $dblist->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
943 $dblist->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
944 }
945 } else {
946 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
947 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], 'db_layout.php', '');
948 } else {
949 $h_func = '';
950 }
951 }
952 // Start the dblist object:
953 $dblist->itemsLimitSingleTable = 1000;
954 $dblist->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
955 $dblist->counter = $CMcounter;
956 $dblist->ext_function = $this->MOD_SETTINGS['function'];
957 // Render versioning selector:
958 $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
959 // Generate the list of elements here:
960 $dblist->generateList();
961 // Adding the list content to the tableOutput variable:
962 $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 : '');
963 // ... and any accumulated JavaScript goes the same way!
964 $tableJSOutput[$table] = $dblist->JScode;
965 // Increase global counter:
966 $CMcounter += $dblist->counter;
967 // Reset variables after operation:
968 $dblist->HTMLcode = '';
969 $dblist->JScode = '';
970 $h_func = '';
971 $h_func_b = '';
972 }
973 // END: traverse tables
974 // For Context Sensitive Menus:
975 $this->doc->getContextMenuCode();
976 // Init the content
977 $content = '';
978 // Additional header content
979 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
980 if (is_array($headerContentHook)) {
981 foreach ($headerContentHook as $hook) {
982 $params = array();
983 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
984 }
985 }
986 // Add the content for each table we have rendered (traversing $tableOutput variable)
987 foreach ($tableOutput as $table => $output) {
988 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
989 $content .= $this->doc->spacer(15);
990 $content .= $this->doc->sectionEnd();
991 }
992 // Making search form:
993 if (!$this->modTSconfig['properties']['disableSearchBox'] && count($tableOutput)) {
994 $sectionTitle = BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.search', TRUE));
995 $content .= $this->doc->section($sectionTitle, $dblist->getSearchBox(0), FALSE, TRUE, FALSE, TRUE);
996 }
997 // Additional footer content
998 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
999 if (is_array($footerContentHook)) {
1000 foreach ($footerContentHook as $hook) {
1001 $params = array();
1002 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1003 }
1004 }
1005 return $content;
1006 }
1007
1008 /**
1009 * Print accumulated content of module
1010 *
1011 * @return void
1012 * @todo Define visibility
1013 */
1014 public function printContent() {
1015 echo $this->content;
1016 }
1017
1018 /***************************
1019 *
1020 * Sub-content functions, rendering specific parts of the module content.
1021 *
1022 ***************************/
1023 /**
1024 * Create the panel of buttons for submitting the form or otherwise perform operations.
1025 *
1026 * @param string $function Identifier for function of module
1027 * @return array all available buttons as an assoc. array
1028 */
1029 protected function getButtons($function = '') {
1030 $buttons = array(
1031 'view' => '',
1032 'history_page' => '',
1033 'new_content' => '',
1034 'move_page' => '',
1035 'move_record' => '',
1036 'new_page' => '',
1037 'edit_page' => '',
1038 'edit_language' => '',
1039 'csh' => '',
1040 'shortcut' => '',
1041 'cache' => '',
1042 'savedok' => '',
1043 'save_close' => '',
1044 'savedokshow' => '',
1045 'closedok' => '',
1046 'deletedok' => '',
1047 'undo' => '',
1048 'history_record' => ''
1049 );
1050 // View page
1051 $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>';
1052 // Shortcut
1053 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
1054 $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']);
1055 }
1056 // Cache
1057 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1058 $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>';
1059 }
1060 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1061 // Move record
1062 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1063 $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>';
1064 }
1065
1066 // Edit page properties and page language overlay icons
1067 if ($this->CALC_PERMS & 2) {
1068
1069 // Edit localized page_language_overlay only when one specific language is selected
1070 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1071 $overlayRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
1072 'uid',
1073 'pages_language_overlay',
1074 'pid = ' . (int)$this->id . ' ' .
1075 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1076 BackendUtility::deleteClause('pages_language_overlay') .
1077 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1078 '',
1079 '',
1080 '',
1081 'sys_language_uid'
1082 );
1083
1084 $editLanguageOnClick = htmlspecialchars(
1085 BackendUtility::editOnClick(
1086 '&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit',
1087 $GLOBALS['BACK_PATH'])
1088 );
1089 $buttons['edit_language'] = '<a href="#" ' .
1090 'onclick="' . $editLanguageOnClick . '"' .
1091 'title="' . $GLOBALS['LANG']->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1092 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') .
1093 '</a>';
1094 }
1095
1096
1097 // Edit page properties
1098 $editPageOnClick = htmlspecialchars(
1099 BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit', $GLOBALS['BACK_PATH'])
1100 );
1101 $buttons['edit_page'] = '<a href="#" ' .
1102 'onclick="' . $editPageOnClick . '"' .
1103 'title="' . $GLOBALS['LANG']->getLL('editPageProperties', TRUE) . '">' .
1104 \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-page-open') .
1105 '</a>';
1106 }
1107
1108 // Add CSH (Context Sensitive Help) icon to tool bar
1109 if ($function == 'quickEdit') {
1110 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit', $GLOBALS['BACK_PATH'], '', TRUE, 'margin-top: 0px; margin-bottom: 0px;');
1111 } else {
1112 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function'], $GLOBALS['BACK_PATH'], '', TRUE, 'margin-top: 0px; margin-bottom: 0px;');
1113 }
1114 if ($function == 'quickEdit') {
1115 // Save record
1116 $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) . '" />'));
1117 // Save and close
1118 $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) . '" />'));
1119 // Save record and show page
1120 $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>';
1121 // Close record
1122 $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>';
1123 // Delete record
1124 if ($this->deleteButton) {
1125 $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>';
1126 }
1127 if ($this->undoButton) {
1128 // Undo button
1129 $buttons['undo'] = '<a href="#"
1130 onclick="' . htmlspecialchars('window.location.href=' .
1131 GeneralUtility::quoteJSvalue(
1132 $GLOBALS['BACK_PATH'] .
1133 BackendUtility::getModuleUrl(
1134 'record_history',
1135 array(
1136 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1137 'revert' => 'ALL_FIELDS',
1138 'sumUp' => -1,
1139 'returnUrl' => $this->R_URI,
1140 )
1141 )
1142 ) . '; return false;') . '"
1143 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>';
1144 // History button
1145 $buttons['history_record'] = '<a href="#"
1146 onclick="' . htmlspecialchars('jumpToUrl(' .
1147 GeneralUtility::quoteJSvalue(
1148 $GLOBALS['BACK_PATH'] .
1149 BackendUtility::getModuleUrl(
1150 'record_history',
1151 array(
1152 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1153 'returnUrl' => $this->R_URI,
1154 )
1155 ) . '#latest'
1156 ) . ');return false;') . '"
1157 title="' . $GLOBALS['LANG']->getLL('recordHistory', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
1158 }
1159 }
1160 }
1161 return $buttons;
1162 }
1163
1164 /*******************************
1165 *
1166 * Other functions
1167 *
1168 ******************************/
1169 /**
1170 * Returns the number of hidden elements (including those hidden by start/end times)
1171 * on the current page (for the current sys_language)
1172 *
1173 * @return int
1174 * @todo Define visibility
1175 */
1176 public function getNumberOfHiddenElements() {
1177 return $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
1178 'uid',
1179 'tt_content',
1180 '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')
1181 );
1182 }
1183
1184 /**
1185 * Returns URL to the current script.
1186 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1187 *
1188 * @param array $params Parameters array, merged with global GET vars.
1189 * @return string URL
1190 * @todo Define visibility
1191 */
1192 public function local_linkThisScript($params) {
1193 $params['popView'] = '';
1194 $params['new_unique_uid'] = '';
1195 return GeneralUtility::linkThisScript($params);
1196 }
1197
1198 /**
1199 * Returns a SQL query for selecting sys_language records.
1200 *
1201 * @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)
1202 * @return string Return query string.
1203 * @todo Define visibility
1204 */
1205 public function exec_languageQuery($id) {
1206 if ($id) {
1207 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1208 ($GLOBALS['BE_USER']->isAdmin() ? '' : ' AND sys_language.hidden=0');
1209 return $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1210 'sys_language.*',
1211 'pages_language_overlay,sys_language',
1212 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1213 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1214 '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',
1215 'sys_language.title'
1216 );
1217 } else {
1218 return $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1219 'sys_language.*',
1220 'sys_language',
1221 'sys_language.hidden=0',
1222 '',
1223 'sys_language.title'
1224 );
1225 }
1226 }
1227
1228 }