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