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