EditDocumentController.php 59.4 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller;

4
5
/**
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

Nicole Cordes's avatar
Nicole Cordes committed
17
18
19
20
21
22
23
24
use TYPO3\CMS\Backend\Form\FormEngine;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\Utility\IconUtility;
use TYPO3\CMS\Core\Html\HtmlParser;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

25
26
27
28
29
30
31
32
33
34
/**
 * Script Class: Drawing the editing form for editing records in TYPO3.
 * Notice: It does NOT use tce_db.php to submit data to, rather it handles submissions itself
 *
 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
 */
class EditDocumentController {

	// Internal, static: GPvars:
	// GPvar "edit": Is an array looking approx like [tablename][list-of-ids]=command, eg.
35
	// "&edit[pages][123]=edit". See \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick(). Value can be seen modified
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	// internally (converting NEW keyword to id, workspace/versioning etc).
	public $editconf;

	// Commalist of fieldnames to edit. The point is IF you specify this list, only those
	// fields will be rendered in the form. Otherwise all (available) fields in the record
	// is shown according to the types configuration in $GLOBALS['TCA']
	public $columnsOnly;

	// Default values for fields (array with tablenames, fields etc. as keys).
	// Can be seen modified internally.
	public $defVals;

	// Array of values to force being set (as hidden fields). Will be set as $this->defVals
	// IF defVals does not exist.
	public $overrideVals;

	// If set, this value will be set in $this->retUrl (which is used quite many places
	// as the return URL). If not set, "dummy.php" will be set in $this->retUrl
	public $returnUrl;

	// Close-document command. Not really sure of all options...
	public $closeDoc;

	// Quite simply, if this variable is set, then the processing of incoming data will be performed
	// - as if a save-button is pressed. Used in the forms as a hidden field which can be set through
	// JavaScript if the form is somehow submitted by JavaScript).
	public $doSave;

	// GPvar (for processing only) : The data array from which the data comes...
	public $data;

	// GPvar (for processing only) : ?
	public $mirror;

	// GPvar (for processing only) : Clear-cache cmd.
	public $cacheCmd;

	// GPvar (for processing only) : Redirect (not used???)
	public $redirect;

	// GPvar (for processing only) : Boolean: If set, then the GET var "&id=" will be added to the
	// retUrl string so that the NEW id of something is returned to the script calling the form.
	public $returnNewPageId;

	// GPvar (for processing only) : Verification code, internal stuff.
	public $vC;

	// GPvar : update BE_USER->uc
	public $uc;

	// GPvar (module) : ID for displaying the page in the frontend (used for SAVE/VIEW operations)
	public $popViewId;

	// GPvar (module) : Additional GET vars for the link, eg. "&L=xxx"
	public $popViewId_addParams;

	// GPvar (module) : Alternative URL for viewing the frontend pages.
	public $viewUrl;

	// If this is pointing to a page id it will automatically load all content elements
	// (NORMAL column/default language) from that page into the form!
	public $editRegularContentFromId;

	// Alternative title for the document handler.
	public $recTitle;

	// Disable help... ?
	public $disHelp;

	// If set, then no SAVE/VIEW button is printed
	public $noView;

	// If set, the $this->editconf array is returned to the calling script
	// (used by wizard_add.php for instance)
	public $returnEditConf;

	// GP var, localization mode for TCEforms (eg. "text")
	public $localizationMode;

115
116
117
118
119
120
121
	/**
	 * Workspace used for the editing action.
	 *
	 * @var NULL|integer
	 */
	protected $workspace;

122
123
124
125
	// Internal, static:
	/**
	 * document template object
	 *
126
	 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
	 */
	public $doc;

	// a static HTML template, usually in templates/alt_doc.html
	public $template;

	// Content accumulation
	public $content;

	// Return URL script, processed. This contains the script (if any) that we should
	// RETURN TO from the alt_doc.php script IF we press the close button. Thus this
	// variable is normally passed along from the calling script so we can properly return if needed.
	public $retUrl;

	// Contains the parts of the REQUEST_URI (current url). By parts we mean the result of resolving
	// REQUEST_URI (current url) by the parse_url() function. The result is an array where eg. "path"
	// is the script path and "query" is the parameters...
	public $R_URL_parts;

	// Contains the current GET vars array; More specifically this array is the foundation for creating
	// the R_URI internal var (which becomes the "url of this script" to which we submit the forms etc.)
	public $R_URL_getvars;

	// Set to the URL of this script including variables which is needed to re-display the form. See main()
	public $R_URI;

	// Is loaded with the "title" of the currently "open document" - this is used in the
	// Document Selector box. (see makeDocSel())
	public $storeTitle;

	// Contains an array with key/value pairs of GET parameters needed to reach the
	// current document displayed - used in the Document Selector box. (see compileStoreDat())
	public $storeArray;

	// Contains storeArray, but imploded into a GET parameter string (see compileStoreDat())
	public $storeUrl;

	// Hashed value of storeURL (see compileStoreDat())
	public $storeUrlMd5;

	// Module session data
	public $docDat;

	// An array of the "open documents" - keys are md5 hashes (see $storeUrlMd5) identifying
	// the various documents on the GET parameter list needed to open it. The values are
	// arrays with 0,1,2 keys with information about the document (see compileStoreDat()).
	// The docHandler variable is stored in the $docDat session data, key "0".
	public $docHandler;

	// Internal: Related to the form rendering:
	// Array of the elements to create edit forms for.
	public $elementsData;

	// Pointer to the first element in $elementsData
	public $firstEl;

	// Counter, used to count the number of errors (when users do not have edit permissions)
	public $errorC;

	// Counter, used to count the number of new record forms displayed
	public $newC;

	// Is set to the pid value of the last shown record - thus indicating which page to
	// show when clicking the SAVE/VIEW button
	public $viewId;

	// Is set to additional parameters (like "&L=xxx") if the record supports it.
	public $viewId_addParams;

	// Module TSconfig, loaded from main() based on the page id value of viewId
	public $modTSconfig;

	/**
	 * instance of TCEforms class
	 *
	 * @var \TYPO3\CMS\Backend\Form\FormEngine
	 */
	public $tceforms;

	// Contains the root-line path of the currently edited record(s) - for display.
	public $generalPathOfForm;

	// Internal, dynamic:
	// Used internally to disable the storage of the document reference (eg. new records)
	public $dontStoreDocumentRef;

213
214
215
216
217
	/**
	 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
	 */
	protected $signalSlotDispatcher;

218
219
220
221
222
223
224
225
	/**
	 * Constructor
	 */
	public function __construct() {
		$GLOBALS['SOBE'] = $this;
		$GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_alt_doc.xml');
	}

226
227
228
229
230
231
232
233
234
235
236
237
	/**
	 * Get the SignalSlot dispatcher
	 *
	 * @return \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
	 */
	protected function getSignalSlotDispatcher() {
		if (!isset($this->signalSlotDispatcher)) {
			$this->signalSlotDispatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
		}
		return $this->signalSlotDispatcher;
	}

238
239
240
241
242
243
244
245
246
	/**
	 * Emits a signal after a function was executed
	 *
	 * @param string $signalName
	 */
	protected function emitFunctionAfterSignal($signalName) {
		$this->getSignalSlotDispatcher()->dispatch(__CLASS__, $signalName . 'After', array($this));
	}

247
248
249
250
251
252
	/**
	 * First initialization.
	 *
	 * @return void
	 */
	public function preInit() {
Nicole Cordes's avatar
Nicole Cordes committed
253
254
		if (GeneralUtility::_GP('justLocalized')) {
			$this->localizationRedirect(GeneralUtility::_GP('justLocalized'));
255
256
		}
		// Setting GPvars:
Nicole Cordes's avatar
Nicole Cordes committed
257
258
259
260
261
262
263
264
265
		$this->editconf = GeneralUtility::_GP('edit');
		$this->defVals = GeneralUtility::_GP('defVals');
		$this->overrideVals = GeneralUtility::_GP('overrideVals');
		$this->columnsOnly = GeneralUtility::_GP('columnsOnly');
		$this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
		$this->closeDoc = GeneralUtility::_GP('closeDoc');
		$this->doSave = GeneralUtility::_GP('doSave');
		$this->returnEditConf = GeneralUtility::_GP('returnEditConf');
		$this->localizationMode = GeneralUtility::_GP('localizationMode');
266
		$this->workspace = GeneralUtility::_GP('workspace');
Nicole Cordes's avatar
Nicole Cordes committed
267
		$this->uc = GeneralUtility::_GP('uc');
268
269
270
271
272
		// Setting override values as default if defVals does not exist.
		if (!is_array($this->defVals) && is_array($this->overrideVals)) {
			$this->defVals = $this->overrideVals;
		}
		// Setting return URL
273
		$this->retUrl = $this->returnUrl ?: 'dummy.php';
274
275
276
		// Fix $this->editconf if versioning applies to any of the records
		$this->fixWSversioningInEditConf();
		// Make R_URL (request url) based on input GETvars:
Nicole Cordes's avatar
Nicole Cordes committed
277
278
		$this->R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
		$this->R_URL_getvars = GeneralUtility::_GET();
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
		$this->R_URL_getvars['edit'] = $this->editconf;
		// MAKE url for storing
		$this->compileStoreDat();
		// Initialize more variables.
		$this->dontStoreDocumentRef = 0;
		$this->storeTitle = '';
		// Get session data for the module:
		$this->docDat = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
		$this->docHandler = $this->docDat[0];
		// If a request for closing the document has been sent, act accordingly:
		if ($this->closeDoc > 0) {
			$this->closeDocument($this->closeDoc);
		}
		// If NO vars are sent to the script, try to read first document:
		// Added !is_array($this->editconf) because editConf must not be set either.
		// Anyways I can't figure out when this situation here will apply...
295
		if (is_array($this->R_URL_getvars) && count($this->R_URL_getvars) < 2 && !is_array($this->editconf)) {
296
297
			$this->setDocument($this->docDat[1]);
		}
298
299
300
301
302

		// Sets a temporary workspace, this request is based on
		if ($this->workspace !== NULL) {
			$this->getBackendUser()->setTemporaryWorkspace($this->workspace);
		}
303

304
		$this->emitFunctionAfterSignal(__FUNCTION__);
305
306
307
308
309
	}

	/**
	 * Detects, if a save command has been triggered.
	 *
310
	 * @return bool TRUE, then save the document (data submitted)
311
312
	 */
	public function doProcessData() {
313
		$out = $this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']) || isset($_POST['_translation_savedok_x']) || isset($_POST['_translation_savedokclear_x']);
314
315
316
317
318
319
320
321
322
323
		return $out;
	}

	/**
	 * Do processing of data, submitting it to TCEmain.
	 *
	 * @return void
	 */
	public function processData() {
		// GPvars specifically for processing:
Nicole Cordes's avatar
Nicole Cordes committed
324
325
326
327
328
329
330
331
		$control = GeneralUtility::_GP('control');
		$this->data = GeneralUtility::_GP('data');
		$this->cmd = GeneralUtility::_GP('cmd');
		$this->mirror = GeneralUtility::_GP('mirror');
		$this->cacheCmd = GeneralUtility::_GP('cacheCmd');
		$this->redirect = GeneralUtility::_GP('redirect');
		$this->returnNewPageId = GeneralUtility::_GP('returnNewPageId');
		$this->vC = GeneralUtility::_GP('vC');
332
333
		// See tce_db.php for relevate options here:
		// Only options related to $this->data submission are included here.
334
		/** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
Nicole Cordes's avatar
Nicole Cordes committed
335
		$tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
336
		$tce->stripslashes_values = 0;
337
338
339
340

		if (!empty($control)) {
			$tce->setControl($control);
		}
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
		if (isset($_POST['_translation_savedok_x'])) {
			$tce->updateModeL10NdiffData = 'FORCE_FFUPD';
		}
		if (isset($_POST['_translation_savedokclear_x'])) {
			$tce->updateModeL10NdiffData = 'FORCE_FFUPD';
			$tce->updateModeL10NdiffDataClear = TRUE;
		}
		// Setting default values specific for the user:
		$TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
		if (is_array($TCAdefaultOverride)) {
			$tce->setDefaultsFromUserTS($TCAdefaultOverride);
		}
		// Setting internal vars:
		if ($GLOBALS['BE_USER']->uc['neverHideAtCopy']) {
			$tce->neverHideAtCopy = 1;
		}
		$tce->debug = 0;
		$tce->disableRTE = !$GLOBALS['BE_USER']->isRTE();
		// Loading TCEmain with data:
		$tce->start($this->data, $this->cmd);
		if (is_array($this->mirror)) {
			$tce->setMirror($this->mirror);
		}
		// If pages are being edited, we set an instruction about updating the page tree after this operation.
		if (isset($this->data['pages']) || $GLOBALS['BE_USER']->workspace != 0 && count($this->data)) {
Nicole Cordes's avatar
Nicole Cordes committed
366
			BackendUtility::setUpdateSignal('updatePageTree');
367
368
		}
		// Checking referer / executing
Nicole Cordes's avatar
Nicole Cordes committed
369
370
		$refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
		$httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
371
		if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
			$tce->log('', 0, 0, 0, 1, 'Referer host \'%s\' and server host \'%s\' did not match and veriCode was not valid either!', 1, array($refInfo['host'], $httpHost));
			debug('Error: Referer host did not match with server host.');
		} else {
			// Perform the saving operation with TCEmain:
			$tce->process_uploads($_FILES);
			$tce->process_datamap();
			$tce->process_cmdmap();
			// If there was saved any new items, load them:
			if (count($tce->substNEWwithIDs_table)) {
				// save the expanded/collapsed states for new inline records, if any
				\TYPO3\CMS\Backend\Form\Element\InlineElement::updateInlineView($this->uc, $tce);
				$newEditConf = array();
				foreach ($this->editconf as $tableName => $tableCmds) {
					$keys = array_keys($tce->substNEWwithIDs_table, $tableName);
					if (count($keys) > 0) {
						foreach ($keys as $key) {
							$editId = $tce->substNEWwithIDs[$key];
							// Check if the $editId isn't a child record of an IRRE action
							if (!(is_array($tce->newRelatedIDs[$tableName]) && in_array($editId, $tce->newRelatedIDs[$tableName]))) {
								// Translate new id to the workspace version:
Nicole Cordes's avatar
Nicole Cordes committed
392
								if ($versionRec = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $tableName, $editId, 'uid')) {
393
394
395
396
397
									$editId = $versionRec['uid'];
								}
								$newEditConf[$tableName][$editId] = 'edit';
							}
							// Traverse all new records and forge the content of ->editconf so we can continue to EDIT these records!
398
							if ($tableName == 'pages' && $this->retUrl != 'dummy.php' && $this->returnNewPageId) {
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
								$this->retUrl .= '&id=' . $tce->substNEWwithIDs[$key];
							}
						}
					} else {
						$newEditConf[$tableName] = $tableCmds;
					}
				}
				// Resetting editconf if newEditConf has values:
				if (count($newEditConf)) {
					$this->editconf = $newEditConf;
				}
				// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
				$this->R_URL_getvars['edit'] = $this->editconf;
				// Unsetting default values since we don't need them anymore.
				unset($this->R_URL_getvars['defVals']);
				// Re-compile the store* values since editconf changed...
				$this->compileStoreDat();
			}
			// See if any records was auto-created as new versions?
			if (count($tce->autoVersionIdMap)) {
				$this->fixWSversioningInEditConf($tce->autoVersionIdMap);
			}
			// If a document is saved and a new one is created right after.
			if (isset($_POST['_savedoknew_x']) && is_array($this->editconf)) {
				// Finding the current table:
				reset($this->editconf);
				$nTable = key($this->editconf);
				// Finding the first id, getting the records pid+uid
				reset($this->editconf[$nTable]);
				$nUid = key($this->editconf[$nTable]);
Nicole Cordes's avatar
Nicole Cordes committed
429
				$nRec = BackendUtility::getRecord($nTable, $nUid, 'pid,uid');
430
431
432
433
434
435
436
437
438
439
440
441
				// Setting a blank editconf array for a new record:
				$this->editconf = array();
				if ($this->getNewIconMode($nTable) == 'top') {
					$this->editconf[$nTable][$nRec['pid']] = 'new';
				} else {
					$this->editconf[$nTable][-$nRec['uid']] = 'new';
				}
				// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
				$this->R_URL_getvars['edit'] = $this->editconf;
				// Re-compile the store* values since editconf changed...
				$this->compileStoreDat();
			}
Nicole Cordes's avatar
Nicole Cordes committed
442
			$tce->printLogErrorMessages(isset($_POST['_saveandclosedok_x']) || isset($_POST['_translation_savedok_x']) ? $this->retUrl : $this->R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $this->R_URL_getvars));
443
444
445
		}
		//  || count($tce->substNEWwithIDs)... If any new items has been save, the document is CLOSED
		// because if not, we just get that element re-listed as new. And we don't want that!
446
		if (isset($_POST['_saveandclosedok_x']) || isset($_POST['_translation_savedok_x']) || $this->closeDoc < 0) {
447
448
449
450
451
452
453
454
455
456
457
			$this->closeDocument(abs($this->closeDoc));
		}
	}

	/**
	 * Initialize the normal module operation
	 *
	 * @return void
	 */
	public function init() {
		// Setting more GPvars:
Nicole Cordes's avatar
Nicole Cordes committed
458
459
460
461
462
463
464
		$this->popViewId = GeneralUtility::_GP('popViewId');
		$this->popViewId_addParams = GeneralUtility::_GP('popViewId_addParams');
		$this->viewUrl = GeneralUtility::_GP('viewUrl');
		$this->editRegularContentFromId = GeneralUtility::_GP('editRegularContentFromId');
		$this->recTitle = GeneralUtility::_GP('recTitle');
		$this->disHelp = GeneralUtility::_GP('disHelp');
		$this->noView = GeneralUtility::_GP('noView');
465
466
467
		$this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
		// Set other internal variables:
		$this->R_URL_getvars['returnUrl'] = $this->retUrl;
Nicole Cordes's avatar
Nicole Cordes committed
468
		$this->R_URI = $this->R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $this->R_URL_getvars);
469
470
471
472
473
474
475
476
477
478
		// MENU-ITEMS:
		// If array, then it's a selector box menu
		// If empty string it's just a variable, that'll be saved.
		// Values NOT in this array will not be saved in the settings-array for the module.
		$this->MOD_MENU = array(
			'showPalettes' => ''
		);
		// Setting virtual document name
		$this->MCONF['name'] = 'xMOD_alt_doc.php';
		// CLEANSE SETTINGS
Nicole Cordes's avatar
Nicole Cordes committed
479
		$this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name']);
480
481
482
		// Create an instance of the document template object
		$this->doc = $GLOBALS['TBE_TEMPLATE'];
		$this->doc->backPath = $GLOBALS['BACK_PATH'];
483
		$this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_doc.html');
484
		$this->doc->form = '<form action="' . htmlspecialchars($this->R_URI) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="document.editform._scrollPosition.value=(document.documentElement.scrollTop || document.body.scrollTop); return TBE_EDITOR.checkSubmit(1);">';
485
		$this->doc->getPageRenderer()->loadPrototype();
486
487
488
		// override the default jumpToUrl
		$this->doc->JScodeArray['jumpToUrl'] = '
			function jumpToUrl(URL,formEl) {
489
490
491
492
493
494
				if (!TBE_EDITOR.isFormChanged()) {
					window.location.href = URL;
				} else if (formEl && formEl.type=="checkbox") {
					formEl.checked = formEl.checked ? 0 : 1;
				}
			}
495
496
';
		$this->doc->JScode = $this->doc->wrapScriptTags('
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
				// Object: TS:
				// passwordDummy and decimalSign are used by tbe_editor.js and have to be declared here as
				// TS object overwrites the object declared in tbe_editor.js
			function typoSetup() {	//
				this.uniqueID = "";
				this.passwordDummy = "********";
				this.PATH_typo3 = " ";
				this.decimalSign = ".";
			}
			var TS = new typoSetup();

				// Info view:
			function launchView(table,uid,bP) {	//
				var backPath= bP ? bP : "";
				var thePreviewWindow="";
				thePreviewWindow = window.open(backPath+"show_item.php?table="+encodeURIComponent(table)+"&uid="+encodeURIComponent(uid),"ShowItem"+TS.uniqueID,"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
				if (thePreviewWindow && thePreviewWindow.focus) {
					thePreviewWindow.focus();
				}
			}
			function deleteRecord(table,id,url) {	//
				if (
519
					' . ($GLOBALS['BE_USER']->jsConfirmation(4) ? 'confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('deleteWarning')) . ')' : '1==1') . '
520
				)	{
Nicole Cordes's avatar
Nicole Cordes committed
521
					window.location.href = "tce_db.php?cmd["+table+"]["+id+"][delete]=1' . BackendUtility::getUrlToken('tceAction') . '&redirect="+escape(url)+"&vC=' . $GLOBALS['BE_USER']->veriCode() . '&prErr=1&uPT=1";
522
523
524
				}
				return false;
			}
Nicole Cordes's avatar
Nicole Cordes committed
525
		' . (isset($_POST['_savedokview_x']) && $this->popViewId ? 'if (window.opener) { ' . BackendUtility::viewOnClick($this->popViewId, '', BackendUtility::BEgetRootLine($this->popViewId), '', $this->viewUrl, $this->popViewId_addParams, FALSE) . ' } else { ' . BackendUtility::viewOnClick($this->popViewId, '', BackendUtility::BEgetRootLine($this->popViewId), '', $this->viewUrl, $this->popViewId_addParams) . ' } ' : ''));
526
527
		// Setting up the context sensitive menu:
		$this->doc->getContextMenuCode();
Nicole Cordes's avatar
Nicole Cordes committed
528
		$this->doc->bodyTagAdditions = 'onload="window.scrollTo(0,' . MathUtility::forceIntegerInRange(GeneralUtility::_GP('_scrollPosition'), 0, 10000) . ');"';
529

530
		$this->emitFunctionAfterSignal(__FUNCTION__);
531
532
533
534
535
536
537
538
539
540
541
	}

	/**
	 * Main module operation
	 *
	 * @return void
	 */
	public function main() {
		// Begin edit:
		if (is_array($this->editconf)) {
			// Initialize TCEforms (rendering the forms)
Nicole Cordes's avatar
Nicole Cordes committed
542
			$this->tceforms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
543
544
			$this->tceforms->initDefaultBEMode();
			$this->tceforms->doSaveFieldName = 'doSave';
Nicole Cordes's avatar
Nicole Cordes committed
545
			$this->tceforms->localizationMode = GeneralUtility::inList('text,media', $this->localizationMode) ? $this->localizationMode : '';
546
547
548
549
550
551
552
553
			// text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
			$this->tceforms->returnUrl = $this->R_URI;
			$this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
			$this->tceforms->disableRTE = !$GLOBALS['BE_USER']->isRTE();
			$this->tceforms->enableClickMenu = TRUE;
			$this->tceforms->enableTabMenu = TRUE;
			// Clipboard is initialized:
			// Start clipboard
Nicole Cordes's avatar
Nicole Cordes committed
554
			$this->tceforms->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
555
556
557
558
559
560
561
562
563
564
565
566
			// Initialize - reads the clipboard content from the user session
			$this->tceforms->clipObj->initializeClipboard();
			// Setting external variables:
			$this->tceforms->edit_showFieldHelp = $GLOBALS['BE_USER']->uc['edit_showFieldHelp'];
			if ($this->editRegularContentFromId) {
				$this->editRegularContentFromId();
			}
			// Creating the editing form, wrap it with buttons, document selector etc.
			$editForm = $this->makeEditForm();
			if ($editForm) {
				$this->firstEl = reset($this->elementsData);
				// Checking if the currently open document is stored in the list of "open documents" - if not, then add it:
567
				if (($this->docDat[1] !== $this->storeUrlMd5 || !isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef) {
568
569
					$this->docHandler[$this->storeUrlMd5] = array($this->storeTitle, $this->storeArray, $this->storeUrl, $this->firstEl);
					$GLOBALS['BE_USER']->pushModuleData('alt_doc.php', array($this->docHandler, $this->storeUrlMd5));
Nicole Cordes's avatar
Nicole Cordes committed
570
					BackendUtility::setUpdateSignal('OpendocsController::updateNumber', count($this->docHandler));
571
572
				}
				// Module configuration
Nicole Cordes's avatar
Nicole Cordes committed
573
				$this->modTSconfig = $this->viewId ? BackendUtility::getModTSconfig($this->viewId, 'mod.xMOD_alt_doc') : array();
574
				$body = $this->tceforms->printNeededJSFunctions_top();
575
576
577
578
579
580
581
582
				$body .= $this->compileForm($editForm);
				$body .= $this->tceforms->printNeededJSFunctions();
				$body .= $this->functionMenus();
				$body .= $this->tceformMessages();
			}
		}
		// Access check...
		// The page will show only if there is a valid page and if this page may be viewed by the user
Nicole Cordes's avatar
Nicole Cordes committed
583
		$this->pageinfo = BackendUtility::readPageAccess($this->viewId, $this->perms_clause);
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
		// Setting up the buttons and markers for docheader
		$docHeaderButtons = $this->getButtons();
		$markers = array(
			'LANGSELECTOR' => $this->langSelector(),
			'EXTRAHEADER' => $this->extraFormHeaders(),
			'CSH' => $docHeaderButtons['csh'],
			'CONTENT' => $body
		);
		// Build the <body> for the module
		$this->content = $this->doc->startPage('TYPO3 Edit Document');
		$this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
		$this->content .= $this->doc->endPage();
		$this->content = $this->doc->insertStylesAndJS($this->content);
	}

	/**
	 * Outputting the accumulated content to screen
	 *
	 * @return void
	 */
	public function printContent() {
		echo $this->content;
	}

	/***************************
	 *
	 * Sub-content functions, rendering specific parts of the module content.
	 *
	 ***************************/
	/**
	 * Creates the editing form with TCEforms, based on the input from GPvars.
	 *
	 * @return string HTML form elements wrapped in tables
	 */
	public function makeEditForm() {
		// Initialize variables:
		$this->elementsData = array();
		$this->errorC = 0;
		$this->newC = 0;
		$thePrevUid = '';
		$editForm = '';
		$trData = NULL;
		// Traverse the GPvar edit array
		// Tables:
		foreach ($this->editconf as $table => $conf) {
629
			if (is_array($conf) && $GLOBALS['TCA'][$table] && $GLOBALS['BE_USER']->check('tables_modify', $table)) {
630
631
632
633
				// Traverse the keys/comments of each table (keys can be a commalist of uids)
				foreach ($conf as $cKey => $cmd) {
					if ($cmd == 'edit' || $cmd == 'new') {
						// Get the ids:
634
						$ids = GeneralUtility::trimExplode(',', $cKey, TRUE);
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
						// Traverse the ids:
						foreach ($ids as $theUid) {
							// Checking if the user has permissions? (Only working as a precaution,
							// because the final permission check is always down in TCE. But it's
							// good to notify the user on beforehand...)
							// First, resetting flags.
							$hasAccess = 1;
							$deniedAccessReason = '';
							$deleteAccess = 0;
							$this->viewId = 0;
							// If the command is to create a NEW record...:
							if ($cmd == 'new') {
								// NOTICE: the id values in this case points to the page uid onto which the
								// record should be create OR (if the id is negativ) to a record from the
								// same table AFTER which to create the record.
650
								if ((int)$theUid) {
651
652
653
									// Find parent page on which the new record reside
									// Less than zero - find parent page
									if ($theUid < 0) {
Nicole Cordes's avatar
Nicole Cordes committed
654
655
										$calcPRec = BackendUtility::getRecord($table, abs($theUid));
										$calcPRec = BackendUtility::getRecord('pages', $calcPRec['pid']);
656
657
									} else {
										// always a page
Nicole Cordes's avatar
Nicole Cordes committed
658
										$calcPRec = BackendUtility::getRecord('pages', abs($theUid));
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
									}
									// Now, calculate whether the user has access to creating new records on this position:
									if (is_array($calcPRec)) {
										// Permissions for the parent page
										$CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
										if ($table == 'pages') {
											// If pages:
											$hasAccess = $CALC_PERMS & 8 ? 1 : 0;
											$this->viewId = 0;
										} else {
											$hasAccess = $CALC_PERMS & 16 ? 1 : 0;
											$this->viewId = $calcPRec['uid'];
										}
									}
								}
								// Don't save this document title in the document selector if the document is new.
								$this->dontStoreDocumentRef = 1;
							} else {
								// Edit:
Nicole Cordes's avatar
Nicole Cordes committed
678
679
								$calcPRec = BackendUtility::getRecord($table, $theUid);
								BackendUtility::fixVersioningPid($table, $calcPRec);
680
								if (is_array($calcPRec)) {
681
									if ($table == 'pages') { // If pages:
682
683
684
685
686
687
										$CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
										$hasAccess = $CALC_PERMS & 2 ? 1 : 0;
										$deleteAccess = $CALC_PERMS & 4 ? 1 : 0;
										$this->viewId = $calcPRec['uid'];
									} else {
										// Fetching pid-record first
Nicole Cordes's avatar
Nicole Cordes committed
688
										$CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
689
690
691
692
693
694
695
696
697
										$hasAccess = $CALC_PERMS & 16 ? 1 : 0;
										$deleteAccess = $CALC_PERMS & 16 ? 1 : 0;
										$this->viewId = $calcPRec['pid'];
										// Adding "&L=xx" if the record being edited has a languageField with a value larger than zero!
										if ($GLOBALS['TCA'][$table]['ctrl']['languageField'] && $calcPRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
											$this->viewId_addParams = '&L=' . $calcPRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
										}
									}
									// Check internals regarding access:
Nicole Cordes's avatar
Nicole Cordes committed
698
									$isRootLevelRestrictionIgnored = BackendUtility::isRootLevelRestrictionIgnored($table);
699
									if ($hasAccess || (string) $calcPRec['pid'] === '0' && $isRootLevelRestrictionIgnored) {
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
										$hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
										$deniedAccessReason = $GLOBALS['BE_USER']->errorMsg;
									}
								} else {
									$hasAccess = 0;
								}
							}
							if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck'])) {
								foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck'] as $_funcRef) {
									$_params = array(
										'table' => $table,
										'uid' => $theUid,
										'cmd' => $cmd,
										'hasAccess' => $hasAccess
									);
Nicole Cordes's avatar
Nicole Cordes committed
715
									$hasAccess = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
716
717
718
719
720
721
								}
							}
							// AT THIS POINT we have checked the access status of the editing/creation of
							// records and we can now proceed with creating the form elements:
							if ($hasAccess) {
								$prevPageID = is_object($trData) ? $trData->prevPageID : '';
Nicole Cordes's avatar
Nicole Cordes committed
722
								$trData = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
723
724
725
726
727
728
729
730
								$trData->addRawData = TRUE;
								$trData->defVals = $this->defVals;
								$trData->lockRecords = 1;
								$trData->disableRTE = !$GLOBALS['BE_USER']->isRTE();
								$trData->prevPageID = $prevPageID;
								// 'new'
								$trData->fetchRecord($table, $theUid, $cmd == 'new' ? 'new' : '');
								$rec = reset($trData->regTableItems_data);
731
								$rec['uid'] = $cmd == 'new' ? uniqid('NEW', TRUE) : $theUid;
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
								if ($cmd == 'new') {
									$rec['pid'] = $theUid == 'prev' ? $thePrevUid : $theUid;
								}
								$this->elementsData[] = array(
									'table' => $table,
									'uid' => $rec['uid'],
									'pid' => $rec['pid'],
									'cmd' => $cmd,
									'deleteAccess' => $deleteAccess
								);
								// Now, render the form:
								if (is_array($rec)) {
									// Setting visual path / title of form:
									$this->generalPathOfForm = $this->tceforms->getRecordPath($table, $rec);
									if (!$this->storeTitle) {
Nicole Cordes's avatar
Nicole Cordes committed
747
										$this->storeTitle = $this->recTitle ? htmlspecialchars($this->recTitle) : BackendUtility::getRecordTitle($table, $rec, TRUE);
748
749
750
									}
									// Setting variables in TCEforms object:
									$this->tceforms->hiddenFieldList = '';
751
									$this->tceforms->globalShowHelp = !$this->disHelp;
752
									if (is_array($this->overrideVals) && is_array($this->overrideVals[$table])) {
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
										$this->tceforms->hiddenFieldListArr = array_keys($this->overrideVals[$table]);
									}
									// Register default language labels, if any:
									$this->tceforms->registerDefaultLanguageData($table, $rec);
									// Create form for the record (either specific list of fields or the whole record):
									$panel = '';
									if ($this->columnsOnly) {
										if (is_array($this->columnsOnly)) {
											$panel .= $this->tceforms->getListedFields($table, $rec, $this->columnsOnly[$table]);
										} else {
											$panel .= $this->tceforms->getListedFields($table, $rec, $this->columnsOnly);
										}
									} else {
										$panel .= $this->tceforms->getMainFields($table, $rec);
									}
									$panel = $this->tceforms->wrapTotal($panel, $rec, $table);
									// Setting the pid value for new records:
									if ($cmd == 'new') {
771
										$panel .= '<input type="hidden" name="data[' . $table . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
772
773
774
										$this->newC++;
									}
									// Display "is-locked" message:
Nicole Cordes's avatar
Nicole Cordes committed
775
776
									if ($lockInfo = BackendUtility::isRecordLocked($table, $rec['uid'])) {
										$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($lockInfo['msg']), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
777
										/** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
Nicole Cordes's avatar
Nicole Cordes committed
778
										$flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
779
780
781
										/** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
										$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
										$defaultFlashMessageQueue->enqueue($flashMessage);
782
783
784
785
786
787
788
									}
									// Combine it all:
									$editForm .= $panel;
								}
								$thePrevUid = $rec['uid'];
							} else {
								$this->errorC++;
789
								$editForm .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.noEditPermission', TRUE) . '<br /><br />' . ($deniedAccessReason ? 'Reason: ' . htmlspecialchars($deniedAccessReason) . '<br /><br />' : '');
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
							}
						}
					}
				}
			}
		}
		return $editForm;
	}

	/**
	 * Create the panel of buttons for submitting the form or otherwise perform operations.
	 *
	 * @return array All available buttons as an assoc. array
	 */
	protected function getButtons() {
		$buttons = array(
			'save' => '',
			'save_view' => '',
			'save_new' => '',
			'save_close' => '',
			'close' => '',
			'delete' => '',
			'undo' => '',
			'history' => '',
			'columns_only' => '',
			'csh' => '',
			'translation_save' => '',
			'translation_saveclear' => ''
		);
		// Render SAVE type buttons:
		// The action of each button is decided by its name attribute. (See doProcessData())
		if (!$this->errorC && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly']) {
			// SAVE button:
823
			$buttons['save'] = 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) . '" />'));
824
			// SAVE / VIEW button:
825
			if ($this->viewId && !$this->noView && $this->getNewIconMode($this->firstEl['table'], 'saveDocView')) {
826
				$buttons['save_view'] = IconUtility::getSpriteIcon('actions-document-save-view', array('html' => '<input onclick="window.open(\'\', \'newTYPO3frontendWindow\');" type="image" class="c-inputButton" name="_savedokview" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', TRUE) . '" />'));
827
828
829
			}
			// SAVE / NEW button:
			if (count($this->elementsData) == 1 && $this->getNewIconMode($this->firstEl['table'])) {
830
				$buttons['save_new'] = IconUtility::getSpriteIcon('actions-document-save-new', array('html' => '<input type="image" class="c-inputButton" name="_savedoknew" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveNewDoc', TRUE) . '" />'));
831
832
			}
			// SAVE / CLOSE
833
			$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) . '" />'));
834
835
			// FINISH TRANSLATION / SAVE / CLOSE
			if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation']) {
836
837
				$buttons['translation_save'] = '<input type="image" class="c-inputButton" name="_translation_savedok" src="' . IconUtility::skinImg($this->doc->backPath, 'gfx/translationsavedok.gif', '', 1) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.translationSaveDoc', TRUE) . '" />';
				$buttons['translation_saveclear'] = '<input type="image" class="c-inputButton" name="_translation_savedokclear" src="' . IconUtility::skinImg($this->doc->backPath, 'gfx/translationsavedok_clear.gif', '', 1) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.translationSaveDocClear', TRUE) . '" />';
838
839
840
			}
		}
		// CLOSE button:
Nicole Cordes's avatar
Nicole Cordes committed
841
		$buttons['close'] = '<a href="#" onclick="document.editform.closeDoc.value=1; document.editform.submit(); return false;" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
842
		// DELETE + UNDO buttons:
843
		if (!$this->errorC && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly'] && count($this->elementsData) == 1) {
Nicole Cordes's avatar
Nicole Cordes committed
844
			if ($this->firstEl['cmd'] != 'new' && MathUtility::canBeInterpretedAsInteger($this->firstEl['uid'])) {
845
				// Delete:
846
847
				if ($this->firstEl['deleteAccess'] && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly'] && !$this->getNewIconMode($this->firstEl['table'], 'disableDelete')) {
					$aOnClick = 'return deleteRecord(\'' . $this->firstEl['table'] . '\',\'' . $this->firstEl['uid'] . '\', unescape(\'' . rawurlencode($this->retUrl) . '\'));';
Nicole Cordes's avatar
Nicole Cordes committed
848
					$buttons['delete'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $GLOBALS['LANG']->getLL('deleteItem', TRUE) . '">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
849
850
				}
				// Undo:
851
				$undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->firstEl['table'], 'sys_history') . ' AND recuid=' . (int)$this->firstEl['uid'], '', 'tstamp DESC', '1');
852
				if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
853
854
855
856
857
858
859
860
861
862
863
864
					$aOnClick = 'window.location.href=' .
						GeneralUtility::quoteJSvalue(
							BackendUtility::getModuleUrl(
								'record_history',
								array(
									'element' => $this->firstEl['table'] . ':' . $this->firstEl['uid'],
									'revert' => 'ALL_FIELDS',
									'sumUp' => -1,
									'returnUrl' => $this->R_URI,
								)
							)
						) . '; return false;';
865
					$buttons['undo'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '"' . ' title="' . htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('undoLastChange'), BackendUtility::calcAge(($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . IconUtility::getSpriteIcon('actions-edit-undo') . '</a>';
866
867
				}
				if ($this->getNewIconMode($this->firstEl['table'], 'showHistory')) {
868
869
870
871
872
873
874
875
876
877
					$aOnClick = 'window.location.href=' .
						GeneralUtility::quoteJSvalue(
							BackendUtility::getModuleUrl(
								'record_history',
								array(
									'element' => $this->firstEl['table'] . ':' . $this->firstEl['uid'],
									'returnUrl' => $this->R_URI,
								)
							)
						) . '; return false;';
Nicole Cordes's avatar
Nicole Cordes committed
878
					$buttons['history'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
879
880
881
				}
				// If only SOME fields are shown in the form, this will link the user to the FULL form:
				if ($this->columnsOnly) {
Nicole Cordes's avatar
Nicole Cordes committed
882
					$buttons['columns_only'] = '<a href="' . htmlspecialchars(($this->R_URI . '&columnsOnly=')) . '" title="' . $GLOBALS['LANG']->getLL('editWholeRecord', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
883
884
885
886
				}
			}
		}
		// add the CSH icon
Nicole Cordes's avatar
Nicole Cordes committed
887
		$buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'TCEforms', $GLOBALS['BACK_PATH'], '', TRUE);
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
		$buttons['shortcut'] = $this->shortCutLink();
		$buttons['open_in_new_window'] = $this->openInNewWindowLink();
		return $buttons;
	}

	/**
	 * Returns the language switch/selector for editing,
	 * show only when a single record is edited
	 * - multiple records are too confusing
	 *
	 * @return string The HTML
	 */
	public function langSelector() {
		$langSelector = '';
		if (count($this->elementsData) == 1) {
			$langSelector = $this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']);
		}
		return $langSelector;
	}

	/**
	 * Compiles the extra form headers if the tceforms
	 *
	 * @return string The HTML
	 */
	public function extraFormHeaders() {
		$extraTemplate = '';
		if (is_array($this->tceforms->extraFormHeaders)) {
Nicole Cordes's avatar
Nicole Cordes committed
916
917
			$extraTemplate = HtmlParser::getSubpart($this->doc->moduleTemplate, '###DOCHEADER_EXTRAHEADER###');
			$extraTemplate = HtmlParser::substituteMarker($extraTemplate, '###EXTRAHEADER###', implode(LF, $this->tceforms->extraFormHeaders));
918
919
920
921
922
923
924
925
926
927
928
		}
		return $extraTemplate;
	}

	/**
	 * Put together the various elements (buttons, selectors, form) into a table
	 *
	 * @param string $editForm HTML form.
	 * @return string Composite HTML
	 */
	public function compileForm($editForm) {
929
		$formContent = '
930
			<!-- EDITING FORM -->
931
			' . $editForm . '
932

933
934
			<input type="hidden" name="returnUrl" value="' . htmlspecialchars($this->retUrl) . '" />
			<input type="hidden" name="viewUrl" value="' . htmlspecialchars($this->viewUrl) . '" />';
935
936
937
		if ($this->returnNewPageId) {
			$formContent .= '<input type="hidden" name="returnNewPageId" value="1" />';
		}
938
		$formContent .= '<input type="hidden" name="popViewId" value="' . htmlspecialchars($this->viewId) . '" />';
939
		if ($this->viewId_addParams) {
940
			$formContent .= '<input type="hidden" name="popViewId_addParams" value="' . htmlspecialchars($this->viewId_addParams) . '" />';
941
		}
942
		$formContent .= '
943
944
			<input type="hidden" name="closeDoc" value="0" />
			<input type="hidden" name="doSave" value="0" />
945
			<input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
Nicole Cordes's avatar
Nicole Cordes committed
946
			<input type="hidden" name="_scrollPosition" value="" />' . FormEngine::getHiddenTokenField('editRecord');
947
948
949
950
951
952
953
954
955
956
957
		return $formContent;
	}

	/**
	 * Create the checkbox buttons in the bottom of the pages.
	 *
	 * @return string HTML for function menus.
	 */
	public function functionMenus() {
		if ($GLOBALS['BE_USER']->getTSConfigVal('options.enableShowPalettes')) {
			// Show palettes:
958
959
960
961
962
963
964

			return '<div class="checkbox">' .
				'<label for="checkShowPalettes">' .
					BackendUtility::getFuncCheck('', 'SET[showPalettes]', $this->MOD_SETTINGS['showPalettes'], 'alt_doc.php', (GeneralUtility::implodeArrayForUrl('', array_merge($this->R_URL_getvars, array('SET' => ''))) . BackendUtility::getUrlToken('editRecord')), 'id="checkShowPalettes"') .
					$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPalettes', TRUE) .
				'</label>'.
			'</div>';
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
		} else {
			return '';
		}
	}

	/**
	 * Create shortcut icon
	 *
	 * @return string
	 */
	public function shortCutLink() {
		if ($this->returnUrl == 'close.html' || !$GLOBALS['BE_USER']->mayMakeShortcut()) {
			return '';
		}
		return $this->doc->makeShortcutIcon('returnUrl,edit,defVals,overrideVals,columnsOnly,returnNewPageId,editRegularContentFromId,disHelp,noView', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name'], 1);
	}

	/**
	 * Creates open-in-window link
	 *
	 * @return string
	 */
	public function openInNewWindowLink() {
		if ($this->returnUrl == 'close.html') {
			return '';
		}
991
		$aOnClick = 'vHWin=window.open(' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(array('returnUrl' => 'close.html'))) . ',\'' . md5($this->R_URI) . '\',\'width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
Nicole Cordes's avatar
Nicole Cordes committed
992
		return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.openInNewWindow', TRUE) . '">' . IconUtility::getSpriteIcon('actions-window-open') . '</a>';
993
994
995
996
997
998
999
1000
	}

	/**
	 * Reads comment messages from TCEforms and prints them in a HTML comment in the bottom of the page.
	 *
	 * @return void
	 */
	public function tceformMessages() {