[TASK] Cleanup entry classes in typo3/ part2
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / EditDocumentController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Form\FormEngine;
31 use TYPO3\CMS\Backend\Utility\BackendUtility;
32 use TYPO3\CMS\Backend\Utility\IconUtility;
33 use TYPO3\CMS\Core\Html\HtmlParser;
34 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
35 use TYPO3\CMS\Core\Utility\GeneralUtility;
36 use TYPO3\CMS\Core\Utility\HttpUtility;
37 use TYPO3\CMS\Core\Utility\MathUtility;
38
39 /**
40 * Script Class: Drawing the editing form for editing records in TYPO3.
41 * Notice: It does NOT use tce_db.php to submit data to, rather it handles submissions itself
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 */
45 class EditDocumentController {
46
47 // Internal, static: GPvars:
48 // GPvar "edit": Is an array looking approx like [tablename][list-of-ids]=command, eg.
49 // "&edit[pages][123]=edit". See \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick(). Value can be seen modified
50 // internally (converting NEW keyword to id, workspace/versioning etc).
51 /**
52 * @todo Define visibility
53 */
54 public $editconf;
55
56 // Commalist of fieldnames to edit. The point is IF you specify this list, only those
57 // fields will be rendered in the form. Otherwise all (available) fields in the record
58 // is shown according to the types configuration in $GLOBALS['TCA']
59 /**
60 * @todo Define visibility
61 */
62 public $columnsOnly;
63
64 // Default values for fields (array with tablenames, fields etc. as keys).
65 // Can be seen modified internally.
66 /**
67 * @todo Define visibility
68 */
69 public $defVals;
70
71 // Array of values to force being set (as hidden fields). Will be set as $this->defVals
72 // IF defVals does not exist.
73 /**
74 * @todo Define visibility
75 */
76 public $overrideVals;
77
78 // If set, this value will be set in $this->retUrl (which is used quite many places
79 // as the return URL). If not set, "dummy.php" will be set in $this->retUrl
80 /**
81 * @todo Define visibility
82 */
83 public $returnUrl;
84
85 // Close-document command. Not really sure of all options...
86 /**
87 * @todo Define visibility
88 */
89 public $closeDoc;
90
91 // Quite simply, if this variable is set, then the processing of incoming data will be performed
92 // - as if a save-button is pressed. Used in the forms as a hidden field which can be set through
93 // JavaScript if the form is somehow submitted by JavaScript).
94 /**
95 * @todo Define visibility
96 */
97 public $doSave;
98
99 // GPvar (for processing only) : The data array from which the data comes...
100 /**
101 * @todo Define visibility
102 */
103 public $data;
104
105 // GPvar (for processing only) : ?
106 /**
107 * @todo Define visibility
108 */
109 public $mirror;
110
111 // GPvar (for processing only) : Clear-cache cmd.
112 /**
113 * @todo Define visibility
114 */
115 public $cacheCmd;
116
117 // GPvar (for processing only) : Redirect (not used???)
118 /**
119 * @todo Define visibility
120 */
121 public $redirect;
122
123 // GPvar (for processing only) : Boolean: If set, then the GET var "&id=" will be added to the
124 // retUrl string so that the NEW id of something is returned to the script calling the form.
125 /**
126 * @todo Define visibility
127 */
128 public $returnNewPageId;
129
130 // GPvar (for processing only) : Verification code, internal stuff.
131 /**
132 * @todo Define visibility
133 */
134 public $vC;
135
136 // GPvar : update BE_USER->uc
137 /**
138 * @todo Define visibility
139 */
140 public $uc;
141
142 // GPvar (module) : ID for displaying the page in the frontend (used for SAVE/VIEW operations)
143 /**
144 * @todo Define visibility
145 */
146 public $popViewId;
147
148 // GPvar (module) : Additional GET vars for the link, eg. "&L=xxx"
149 /**
150 * @todo Define visibility
151 */
152 public $popViewId_addParams;
153
154 // GPvar (module) : Alternative URL for viewing the frontend pages.
155 /**
156 * @todo Define visibility
157 */
158 public $viewUrl;
159
160 // If this is pointing to a page id it will automatically load all content elements
161 // (NORMAL column/default language) from that page into the form!
162 /**
163 * @todo Define visibility
164 */
165 public $editRegularContentFromId;
166
167 // Alternative title for the document handler.
168 /**
169 * @todo Define visibility
170 */
171 public $recTitle;
172
173 // Disable help... ?
174 /**
175 * @todo Define visibility
176 */
177 public $disHelp;
178
179 // If set, then no SAVE/VIEW button is printed
180 /**
181 * @todo Define visibility
182 */
183 public $noView;
184
185 // If set, the $this->editconf array is returned to the calling script
186 // (used by wizard_add.php for instance)
187 /**
188 * @todo Define visibility
189 */
190 public $returnEditConf;
191
192 // GP var, localization mode for TCEforms (eg. "text")
193 /**
194 * @todo Define visibility
195 */
196 public $localizationMode;
197
198 // Internal, static:
199 /**
200 * document template object
201 *
202 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
203 * @todo Define visibility
204 */
205 public $doc;
206
207 // a static HTML template, usually in templates/alt_doc.html
208 /**
209 * @todo Define visibility
210 */
211 public $template;
212
213 // Content accumulation
214 /**
215 * @todo Define visibility
216 */
217 public $content;
218
219 // Return URL script, processed. This contains the script (if any) that we should
220 // RETURN TO from the alt_doc.php script IF we press the close button. Thus this
221 // variable is normally passed along from the calling script so we can properly return if needed.
222 /**
223 * @todo Define visibility
224 */
225 public $retUrl;
226
227 // Contains the parts of the REQUEST_URI (current url). By parts we mean the result of resolving
228 // REQUEST_URI (current url) by the parse_url() function. The result is an array where eg. "path"
229 // is the script path and "query" is the parameters...
230 /**
231 * @todo Define visibility
232 */
233 public $R_URL_parts;
234
235 // Contains the current GET vars array; More specifically this array is the foundation for creating
236 // the R_URI internal var (which becomes the "url of this script" to which we submit the forms etc.)
237 /**
238 * @todo Define visibility
239 */
240 public $R_URL_getvars;
241
242 // Set to the URL of this script including variables which is needed to re-display the form. See main()
243 /**
244 * @todo Define visibility
245 */
246 public $R_URI;
247
248 // Is loaded with the "title" of the currently "open document" - this is used in the
249 // Document Selector box. (see makeDocSel())
250 /**
251 * @todo Define visibility
252 */
253 public $storeTitle;
254
255 // Contains an array with key/value pairs of GET parameters needed to reach the
256 // current document displayed - used in the Document Selector box. (see compileStoreDat())
257 /**
258 * @todo Define visibility
259 */
260 public $storeArray;
261
262 // Contains storeArray, but imploded into a GET parameter string (see compileStoreDat())
263 /**
264 * @todo Define visibility
265 */
266 public $storeUrl;
267
268 // Hashed value of storeURL (see compileStoreDat())
269 /**
270 * @todo Define visibility
271 */
272 public $storeUrlMd5;
273
274 // Module session data
275 /**
276 * @todo Define visibility
277 */
278 public $docDat;
279
280 // An array of the "open documents" - keys are md5 hashes (see $storeUrlMd5) identifying
281 // the various documents on the GET parameter list needed to open it. The values are
282 // arrays with 0,1,2 keys with information about the document (see compileStoreDat()).
283 // The docHandler variable is stored in the $docDat session data, key "0".
284 /**
285 * @todo Define visibility
286 */
287 public $docHandler;
288
289 // Internal: Related to the form rendering:
290 // Array of the elements to create edit forms for.
291 /**
292 * @todo Define visibility
293 */
294 public $elementsData;
295
296 // Pointer to the first element in $elementsData
297 /**
298 * @todo Define visibility
299 */
300 public $firstEl;
301
302 // Counter, used to count the number of errors (when users do not have edit permissions)
303 /**
304 * @todo Define visibility
305 */
306 public $errorC;
307
308 // Counter, used to count the number of new record forms displayed
309 /**
310 * @todo Define visibility
311 */
312 public $newC;
313
314 // Is set to the pid value of the last shown record - thus indicating which page to
315 // show when clicking the SAVE/VIEW button
316 /**
317 * @todo Define visibility
318 */
319 public $viewId;
320
321 // Is set to additional parameters (like "&L=xxx") if the record supports it.
322 /**
323 * @todo Define visibility
324 */
325 public $viewId_addParams;
326
327 // Module TSconfig, loaded from main() based on the page id value of viewId
328 /**
329 * @todo Define visibility
330 */
331 public $modTSconfig;
332
333 /**
334 * instance of TCEforms class
335 *
336 * @var \TYPO3\CMS\Backend\Form\FormEngine
337 * @todo Define visibility
338 */
339 public $tceforms;
340
341 // Contains the root-line path of the currently edited record(s) - for display.
342 /**
343 * @todo Define visibility
344 */
345 public $generalPathOfForm;
346
347 // Internal, dynamic:
348 // Used internally to disable the storage of the document reference (eg. new records)
349 /**
350 * @todo Define visibility
351 */
352 public $dontStoreDocumentRef;
353
354 /**
355 * Constructor
356 */
357 public function __construct() {
358 $GLOBALS['SOBE'] = $this;
359 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_alt_doc.xml');
360 }
361
362 /**
363 * First initialization.
364 *
365 * @return void
366 */
367 public function preInit() {
368 if (GeneralUtility::_GP('justLocalized')) {
369 $this->localizationRedirect(GeneralUtility::_GP('justLocalized'));
370 }
371 // Setting GPvars:
372 $this->editconf = GeneralUtility::_GP('edit');
373 $this->defVals = GeneralUtility::_GP('defVals');
374 $this->overrideVals = GeneralUtility::_GP('overrideVals');
375 $this->columnsOnly = GeneralUtility::_GP('columnsOnly');
376 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
377 $this->closeDoc = GeneralUtility::_GP('closeDoc');
378 $this->doSave = GeneralUtility::_GP('doSave');
379 $this->returnEditConf = GeneralUtility::_GP('returnEditConf');
380 $this->localizationMode = GeneralUtility::_GP('localizationMode');
381 $this->uc = GeneralUtility::_GP('uc');
382 // Setting override values as default if defVals does not exist.
383 if (!is_array($this->defVals) && is_array($this->overrideVals)) {
384 $this->defVals = $this->overrideVals;
385 }
386 // Setting return URL
387 $this->retUrl = $this->returnUrl ? $this->returnUrl : 'dummy.php';
388 // Fix $this->editconf if versioning applies to any of the records
389 $this->fixWSversioningInEditConf();
390 // Make R_URL (request url) based on input GETvars:
391 $this->R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
392 $this->R_URL_getvars = GeneralUtility::_GET();
393 $this->R_URL_getvars['edit'] = $this->editconf;
394 // MAKE url for storing
395 $this->compileStoreDat();
396 // Initialize more variables.
397 $this->dontStoreDocumentRef = 0;
398 $this->storeTitle = '';
399 // Get session data for the module:
400 $this->docDat = $GLOBALS['BE_USER']->getModuleData('alt_doc.php', 'ses');
401 $this->docHandler = $this->docDat[0];
402 // If a request for closing the document has been sent, act accordingly:
403 if ($this->closeDoc > 0) {
404 $this->closeDocument($this->closeDoc);
405 }
406 // If NO vars are sent to the script, try to read first document:
407 // Added !is_array($this->editconf) because editConf must not be set either.
408 // Anyways I can't figure out when this situation here will apply...
409 if (is_array($this->R_URL_getvars) && count($this->R_URL_getvars) < 2 && !is_array($this->editconf)) {
410 $this->setDocument($this->docDat[1]);
411 }
412 }
413
414 /**
415 * Detects, if a save command has been triggered.
416 *
417 * @return boolean TRUE, then save the document (data submitted)
418 */
419 public function doProcessData() {
420 $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']);
421 return $out;
422 }
423
424 /**
425 * Do processing of data, submitting it to TCEmain.
426 *
427 * @return void
428 */
429 public function processData() {
430 // GPvars specifically for processing:
431 $control = GeneralUtility::_GP('control');
432 $this->data = GeneralUtility::_GP('data');
433 $this->cmd = GeneralUtility::_GP('cmd');
434 $this->mirror = GeneralUtility::_GP('mirror');
435 $this->cacheCmd = GeneralUtility::_GP('cacheCmd');
436 $this->redirect = GeneralUtility::_GP('redirect');
437 $this->returnNewPageId = GeneralUtility::_GP('returnNewPageId');
438 $this->vC = GeneralUtility::_GP('vC');
439 // See tce_db.php for relevate options here:
440 // Only options related to $this->data submission are included here.
441 /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
442 $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
443 $tce->stripslashes_values = 0;
444
445 if (!empty($control)) {
446 $tce->setControl($control);
447 }
448 if (isset($_POST['_translation_savedok_x'])) {
449 $tce->updateModeL10NdiffData = 'FORCE_FFUPD';
450 }
451 if (isset($_POST['_translation_savedokclear_x'])) {
452 $tce->updateModeL10NdiffData = 'FORCE_FFUPD';
453 $tce->updateModeL10NdiffDataClear = TRUE;
454 }
455 // Setting default values specific for the user:
456 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
457 if (is_array($TCAdefaultOverride)) {
458 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
459 }
460 // Setting internal vars:
461 if ($GLOBALS['BE_USER']->uc['neverHideAtCopy']) {
462 $tce->neverHideAtCopy = 1;
463 }
464 $tce->debug = 0;
465 $tce->disableRTE = !$GLOBALS['BE_USER']->isRTE();
466 // Loading TCEmain with data:
467 $tce->start($this->data, $this->cmd);
468 if (is_array($this->mirror)) {
469 $tce->setMirror($this->mirror);
470 }
471 // If pages are being edited, we set an instruction about updating the page tree after this operation.
472 if (isset($this->data['pages']) || $GLOBALS['BE_USER']->workspace != 0 && count($this->data)) {
473 BackendUtility::setUpdateSignal('updatePageTree');
474 }
475 // Checking referer / executing
476 $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER'));
477 $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
478 if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) {
479 $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));
480 debug('Error: Referer host did not match with server host.');
481 } else {
482 // Perform the saving operation with TCEmain:
483 $tce->process_uploads($_FILES);
484 $tce->process_datamap();
485 $tce->process_cmdmap();
486 // If there was saved any new items, load them:
487 if (count($tce->substNEWwithIDs_table)) {
488 // save the expanded/collapsed states for new inline records, if any
489 \TYPO3\CMS\Backend\Form\Element\InlineElement::updateInlineView($this->uc, $tce);
490 $newEditConf = array();
491 foreach ($this->editconf as $tableName => $tableCmds) {
492 $keys = array_keys($tce->substNEWwithIDs_table, $tableName);
493 if (count($keys) > 0) {
494 foreach ($keys as $key) {
495 $editId = $tce->substNEWwithIDs[$key];
496 // Check if the $editId isn't a child record of an IRRE action
497 if (!(is_array($tce->newRelatedIDs[$tableName]) && in_array($editId, $tce->newRelatedIDs[$tableName]))) {
498 // Translate new id to the workspace version:
499 if ($versionRec = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $tableName, $editId, 'uid')) {
500 $editId = $versionRec['uid'];
501 }
502 $newEditConf[$tableName][$editId] = 'edit';
503 }
504 // Traverse all new records and forge the content of ->editconf so we can continue to EDIT these records!
505 if ($tableName == 'pages' && $this->retUrl != 'dummy.php' && $this->returnNewPageId) {
506 $this->retUrl .= '&id=' . $tce->substNEWwithIDs[$key];
507 }
508 }
509 } else {
510 $newEditConf[$tableName] = $tableCmds;
511 }
512 }
513 // Resetting editconf if newEditConf has values:
514 if (count($newEditConf)) {
515 $this->editconf = $newEditConf;
516 }
517 // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
518 $this->R_URL_getvars['edit'] = $this->editconf;
519 // Unsetting default values since we don't need them anymore.
520 unset($this->R_URL_getvars['defVals']);
521 // Re-compile the store* values since editconf changed...
522 $this->compileStoreDat();
523 }
524 // See if any records was auto-created as new versions?
525 if (count($tce->autoVersionIdMap)) {
526 $this->fixWSversioningInEditConf($tce->autoVersionIdMap);
527 }
528 // If a document is saved and a new one is created right after.
529 if (isset($_POST['_savedoknew_x']) && is_array($this->editconf)) {
530 // Finding the current table:
531 reset($this->editconf);
532 $nTable = key($this->editconf);
533 // Finding the first id, getting the records pid+uid
534 reset($this->editconf[$nTable]);
535 $nUid = key($this->editconf[$nTable]);
536 $nRec = BackendUtility::getRecord($nTable, $nUid, 'pid,uid');
537 // Setting a blank editconf array for a new record:
538 $this->editconf = array();
539 if ($this->getNewIconMode($nTable) == 'top') {
540 $this->editconf[$nTable][$nRec['pid']] = 'new';
541 } else {
542 $this->editconf[$nTable][-$nRec['uid']] = 'new';
543 }
544 // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
545 $this->R_URL_getvars['edit'] = $this->editconf;
546 // Re-compile the store* values since editconf changed...
547 $this->compileStoreDat();
548 }
549 $tce->printLogErrorMessages(isset($_POST['_saveandclosedok_x']) || isset($_POST['_translation_savedok_x']) ? $this->retUrl : $this->R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $this->R_URL_getvars));
550 }
551 // || count($tce->substNEWwithIDs)... If any new items has been save, the document is CLOSED
552 // because if not, we just get that element re-listed as new. And we don't want that!
553 if (isset($_POST['_saveandclosedok_x']) || isset($_POST['_translation_savedok_x']) || $this->closeDoc < 0) {
554 $this->closeDocument(abs($this->closeDoc));
555 }
556 }
557
558 /**
559 * Initialize the normal module operation
560 *
561 * @return void
562 */
563 public function init() {
564 // Setting more GPvars:
565 $this->popViewId = GeneralUtility::_GP('popViewId');
566 $this->popViewId_addParams = GeneralUtility::_GP('popViewId_addParams');
567 $this->viewUrl = GeneralUtility::_GP('viewUrl');
568 $this->editRegularContentFromId = GeneralUtility::_GP('editRegularContentFromId');
569 $this->recTitle = GeneralUtility::_GP('recTitle');
570 $this->disHelp = GeneralUtility::_GP('disHelp');
571 $this->noView = GeneralUtility::_GP('noView');
572 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
573 // Set other internal variables:
574 $this->R_URL_getvars['returnUrl'] = $this->retUrl;
575 $this->R_URI = $this->R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $this->R_URL_getvars);
576 // MENU-ITEMS:
577 // If array, then it's a selector box menu
578 // If empty string it's just a variable, that'll be saved.
579 // Values NOT in this array will not be saved in the settings-array for the module.
580 $this->MOD_MENU = array(
581 'showPalettes' => ''
582 );
583 // Setting virtual document name
584 $this->MCONF['name'] = 'xMOD_alt_doc.php';
585 // CLEANSE SETTINGS
586 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name']);
587 // Create an instance of the document template object
588 $this->doc = $GLOBALS['TBE_TEMPLATE'];
589 $this->doc->backPath = $GLOBALS['BACK_PATH'];
590 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_doc.html');
591 $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);">';
592 $this->doc->getPageRenderer()->loadPrototype();
593 $this->doc->JScode = $this->doc->wrapScriptTags('
594 function jumpToUrl(URL,formEl) { //
595 if (!TBE_EDITOR.isFormChanged()) {
596 window.location.href = URL;
597 } else if (formEl && formEl.type=="checkbox") {
598 formEl.checked = formEl.checked ? 0 : 1;
599 }
600 }
601 // Object: TS:
602 // passwordDummy and decimalSign are used by tbe_editor.js and have to be declared here as
603 // TS object overwrites the object declared in tbe_editor.js
604 function typoSetup() { //
605 this.uniqueID = "";
606 this.passwordDummy = "********";
607 this.PATH_typo3 = " ";
608 this.decimalSign = ".";
609 }
610 var TS = new typoSetup();
611
612 // Info view:
613 function launchView(table,uid,bP) { //
614 var backPath= bP ? bP : "";
615 var thePreviewWindow="";
616 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");
617 if (thePreviewWindow && thePreviewWindow.focus) {
618 thePreviewWindow.focus();
619 }
620 }
621 function deleteRecord(table,id,url) { //
622 if (
623 ' . ($GLOBALS['BE_USER']->jsConfirmation(4) ? 'confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('deleteWarning')) . ')' : '1==1') . '
624 ) {
625 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";
626 }
627 return false;
628 }
629 ' . (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) . ' } ' : ''));
630 // Setting up the context sensitive menu:
631 $this->doc->getContextMenuCode();
632 $this->doc->bodyTagAdditions = 'onload="window.scrollTo(0,' . MathUtility::forceIntegerInRange(GeneralUtility::_GP('_scrollPosition'), 0, 10000) . ');"';
633 }
634
635 /**
636 * Main module operation
637 *
638 * @return void
639 */
640 public function main() {
641 // Begin edit:
642 if (is_array($this->editconf)) {
643 // Initialize TCEforms (rendering the forms)
644 $this->tceforms = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FormEngine');
645 $this->tceforms->initDefaultBEMode();
646 $this->tceforms->doSaveFieldName = 'doSave';
647 $this->tceforms->localizationMode = GeneralUtility::inList('text,media', $this->localizationMode) ? $this->localizationMode : '';
648 // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
649 $this->tceforms->returnUrl = $this->R_URI;
650 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
651 $this->tceforms->disableRTE = !$GLOBALS['BE_USER']->isRTE();
652 $this->tceforms->enableClickMenu = TRUE;
653 $this->tceforms->enableTabMenu = TRUE;
654 // Clipboard is initialized:
655 // Start clipboard
656 $this->tceforms->clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
657 // Initialize - reads the clipboard content from the user session
658 $this->tceforms->clipObj->initializeClipboard();
659 // Setting external variables:
660 $this->tceforms->edit_showFieldHelp = $GLOBALS['BE_USER']->uc['edit_showFieldHelp'];
661 if ($this->editRegularContentFromId) {
662 $this->editRegularContentFromId();
663 }
664 // Creating the editing form, wrap it with buttons, document selector etc.
665 $editForm = $this->makeEditForm();
666 if ($editForm) {
667 $this->firstEl = reset($this->elementsData);
668 // Checking if the currently open document is stored in the list of "open documents" - if not, then add it:
669 if ((strcmp($this->docDat[1], $this->storeUrlMd5) || !isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef) {
670 $this->docHandler[$this->storeUrlMd5] = array($this->storeTitle, $this->storeArray, $this->storeUrl, $this->firstEl);
671 $GLOBALS['BE_USER']->pushModuleData('alt_doc.php', array($this->docHandler, $this->storeUrlMd5));
672 BackendUtility::setUpdateSignal('OpendocsController::updateNumber', count($this->docHandler));
673 }
674 // Module configuration
675 $this->modTSconfig = $this->viewId ? BackendUtility::getModTSconfig($this->viewId, 'mod.xMOD_alt_doc') : array();
676 $body .= $this->tceforms->printNeededJSFunctions_top();
677 $body .= $this->compileForm($editForm);
678 $body .= $this->tceforms->printNeededJSFunctions();
679 $body .= $this->functionMenus();
680 $body .= $this->tceformMessages();
681 }
682 }
683 // Access check...
684 // The page will show only if there is a valid page and if this page may be viewed by the user
685 $this->pageinfo = BackendUtility::readPageAccess($this->viewId, $this->perms_clause);
686 // Setting up the buttons and markers for docheader
687 $docHeaderButtons = $this->getButtons();
688 $markers = array(
689 'LANGSELECTOR' => $this->langSelector(),
690 'EXTRAHEADER' => $this->extraFormHeaders(),
691 'CSH' => $docHeaderButtons['csh'],
692 'CONTENT' => $body
693 );
694 // Build the <body> for the module
695 $this->content = $this->doc->startPage('TYPO3 Edit Document');
696 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
697 $this->content .= $this->doc->endPage();
698 $this->content = $this->doc->insertStylesAndJS($this->content);
699 }
700
701 /**
702 * Outputting the accumulated content to screen
703 *
704 * @return void
705 */
706 public function printContent() {
707 echo $this->content;
708 }
709
710 /***************************
711 *
712 * Sub-content functions, rendering specific parts of the module content.
713 *
714 ***************************/
715 /**
716 * Creates the editing form with TCEforms, based on the input from GPvars.
717 *
718 * @return string HTML form elements wrapped in tables
719 * @todo Define visibility
720 */
721 public function makeEditForm() {
722 // Initialize variables:
723 $this->elementsData = array();
724 $this->errorC = 0;
725 $this->newC = 0;
726 $thePrevUid = '';
727 $editForm = '';
728 $trData = NULL;
729 // Traverse the GPvar edit array
730 // Tables:
731 foreach ($this->editconf as $table => $conf) {
732 if (is_array($conf) && $GLOBALS['TCA'][$table] && $GLOBALS['BE_USER']->check('tables_modify', $table)) {
733 // Traverse the keys/comments of each table (keys can be a commalist of uids)
734 foreach ($conf as $cKey => $cmd) {
735 if ($cmd == 'edit' || $cmd == 'new') {
736 // Get the ids:
737 $ids = GeneralUtility::trimExplode(',', $cKey, 1);
738 // Traverse the ids:
739 foreach ($ids as $theUid) {
740 // Checking if the user has permissions? (Only working as a precaution,
741 // because the final permission check is always down in TCE. But it's
742 // good to notify the user on beforehand...)
743 // First, resetting flags.
744 $hasAccess = 1;
745 $deniedAccessReason = '';
746 $deleteAccess = 0;
747 $this->viewId = 0;
748 // If the command is to create a NEW record...:
749 if ($cmd == 'new') {
750 // NOTICE: the id values in this case points to the page uid onto which the
751 // record should be create OR (if the id is negativ) to a record from the
752 // same table AFTER which to create the record.
753 if (intval($theUid)) {
754 // Find parent page on which the new record reside
755 // Less than zero - find parent page
756 if ($theUid < 0) {
757 $calcPRec = BackendUtility::getRecord($table, abs($theUid));
758 $calcPRec = BackendUtility::getRecord('pages', $calcPRec['pid']);
759 } else {
760 // always a page
761 $calcPRec = BackendUtility::getRecord('pages', abs($theUid));
762 }
763 // Now, calculate whether the user has access to creating new records on this position:
764 if (is_array($calcPRec)) {
765 // Permissions for the parent page
766 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
767 if ($table == 'pages') {
768 // If pages:
769 $hasAccess = $CALC_PERMS & 8 ? 1 : 0;
770 $this->viewId = 0;
771 } else {
772 $hasAccess = $CALC_PERMS & 16 ? 1 : 0;
773 $this->viewId = $calcPRec['uid'];
774 }
775 }
776 }
777 // Don't save this document title in the document selector if the document is new.
778 $this->dontStoreDocumentRef = 1;
779 } else {
780 // Edit:
781 $calcPRec = BackendUtility::getRecord($table, $theUid);
782 BackendUtility::fixVersioningPid($table, $calcPRec);
783 if (is_array($calcPRec)) {
784 if ($table == 'pages') { // If pages:
785 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
786 $hasAccess = $CALC_PERMS & 2 ? 1 : 0;
787 $deleteAccess = $CALC_PERMS & 4 ? 1 : 0;
788 $this->viewId = $calcPRec['uid'];
789 } else {
790 // Fetching pid-record first
791 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid']));
792 $hasAccess = $CALC_PERMS & 16 ? 1 : 0;
793 $deleteAccess = $CALC_PERMS & 16 ? 1 : 0;
794 $this->viewId = $calcPRec['pid'];
795 // Adding "&L=xx" if the record being edited has a languageField with a value larger than zero!
796 if ($GLOBALS['TCA'][$table]['ctrl']['languageField'] && $calcPRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
797 $this->viewId_addParams = '&L=' . $calcPRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
798 }
799 }
800 // Check internals regarding access:
801 $isRootLevelRestrictionIgnored = BackendUtility::isRootLevelRestrictionIgnored($table);
802 if ($hasAccess || (string) $calcPRec['pid'] === '0' && $isRootLevelRestrictionIgnored) {
803 $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
804 $deniedAccessReason = $GLOBALS['BE_USER']->errorMsg;
805 }
806 } else {
807 $hasAccess = 0;
808 }
809 }
810 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck'])) {
811 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck'] as $_funcRef) {
812 $_params = array(
813 'table' => $table,
814 'uid' => $theUid,
815 'cmd' => $cmd,
816 'hasAccess' => $hasAccess
817 );
818 $hasAccess = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
819 }
820 }
821 // AT THIS POINT we have checked the access status of the editing/creation of
822 // records and we can now proceed with creating the form elements:
823 if ($hasAccess) {
824 $prevPageID = is_object($trData) ? $trData->prevPageID : '';
825 $trData = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
826 $trData->addRawData = TRUE;
827 $trData->defVals = $this->defVals;
828 $trData->lockRecords = 1;
829 $trData->disableRTE = !$GLOBALS['BE_USER']->isRTE();
830 $trData->prevPageID = $prevPageID;
831 // 'new'
832 $trData->fetchRecord($table, $theUid, $cmd == 'new' ? 'new' : '');
833 $rec = reset($trData->regTableItems_data);
834 $rec['uid'] = $cmd == 'new' ? uniqid('NEW') : $theUid;
835 if ($cmd == 'new') {
836 $rec['pid'] = $theUid == 'prev' ? $thePrevUid : $theUid;
837 }
838 $this->elementsData[] = array(
839 'table' => $table,
840 'uid' => $rec['uid'],
841 'pid' => $rec['pid'],
842 'cmd' => $cmd,
843 'deleteAccess' => $deleteAccess
844 );
845 // Now, render the form:
846 if (is_array($rec)) {
847 // Setting visual path / title of form:
848 $this->generalPathOfForm = $this->tceforms->getRecordPath($table, $rec);
849 if (!$this->storeTitle) {
850 $this->storeTitle = $this->recTitle ? htmlspecialchars($this->recTitle) : BackendUtility::getRecordTitle($table, $rec, TRUE);
851 }
852 // Setting variables in TCEforms object:
853 $this->tceforms->hiddenFieldList = '';
854 $this->tceforms->globalShowHelp = $this->disHelp ? 0 : 1;
855 if (is_array($this->overrideVals) && is_array($this->overrideVals[$table])) {
856 $this->tceforms->hiddenFieldListArr = array_keys($this->overrideVals[$table]);
857 }
858 // Register default language labels, if any:
859 $this->tceforms->registerDefaultLanguageData($table, $rec);
860 // Create form for the record (either specific list of fields or the whole record):
861 $panel = '';
862 if ($this->columnsOnly) {
863 if (is_array($this->columnsOnly)) {
864 $panel .= $this->tceforms->getListedFields($table, $rec, $this->columnsOnly[$table]);
865 } else {
866 $panel .= $this->tceforms->getListedFields($table, $rec, $this->columnsOnly);
867 }
868 } else {
869 $panel .= $this->tceforms->getMainFields($table, $rec);
870 }
871 $panel = $this->tceforms->wrapTotal($panel, $rec, $table);
872 // Setting the pid value for new records:
873 if ($cmd == 'new') {
874 $panel .= '<input type="hidden" name="data[' . $table . '][' . $rec['uid'] . '][pid]" value="' . $rec['pid'] . '" />';
875 $this->newC++;
876 }
877 // Display "is-locked" message:
878 if ($lockInfo = BackendUtility::isRecordLocked($table, $rec['uid'])) {
879 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($lockInfo['msg']), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
880 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
881 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
882 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
883 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
884 $defaultFlashMessageQueue->enqueue($flashMessage);
885 }
886 // Combine it all:
887 $editForm .= $panel;
888 }
889 $thePrevUid = $rec['uid'];
890 } else {
891 $this->errorC++;
892 $editForm .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.noEditPermission', 1) . '<br /><br />' . ($deniedAccessReason ? 'Reason: ' . htmlspecialchars($deniedAccessReason) . '<br /><br />' : '');
893 }
894 }
895 }
896 }
897 }
898 }
899 return $editForm;
900 }
901
902 /**
903 * Create the panel of buttons for submitting the form or otherwise perform operations.
904 *
905 * @return array All available buttons as an assoc. array
906 */
907 protected function getButtons() {
908 $buttons = array(
909 'save' => '',
910 'save_view' => '',
911 'save_new' => '',
912 'save_close' => '',
913 'close' => '',
914 'delete' => '',
915 'undo' => '',
916 'history' => '',
917 'columns_only' => '',
918 'csh' => '',
919 'translation_save' => '',
920 'translation_saveclear' => ''
921 );
922 // Render SAVE type buttons:
923 // The action of each button is decided by its name attribute. (See doProcessData())
924 if (!$this->errorC && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly']) {
925 // SAVE button:
926 $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', 1) . '" />'));
927 // SAVE / VIEW button:
928 if ($this->viewId && !$this->noView && ExtensionManagementUtility::isLoaded('cms') && $this->getNewIconMode($this->firstEl['table'], 'saveDocView')) {
929 $buttons['save_view'] = IconUtility::getSpriteIcon('actions-document-save-view', array('html' => '<input type="image" class="c-inputButton" name="_savedokview" src="clear.gif" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', 1) . '" />'));
930 }
931 // SAVE / NEW button:
932 if (count($this->elementsData) == 1 && $this->getNewIconMode($this->firstEl['table'])) {
933 $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', 1) . '" />'));
934 }
935 // SAVE / CLOSE
936 $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', 1) . '" />'));
937 // FINISH TRANSLATION / SAVE / CLOSE
938 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation']) {
939 $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', 1) . '" />';
940 $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', 1) . '" />';
941 }
942 }
943 // CLOSE button:
944 $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>';
945 // DELETE + UNDO buttons:
946 if (!$this->errorC && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly'] && count($this->elementsData) == 1) {
947 if ($this->firstEl['cmd'] != 'new' && MathUtility::canBeInterpretedAsInteger($this->firstEl['uid'])) {
948 // Delete:
949 if ($this->firstEl['deleteAccess'] && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly'] && !$this->getNewIconMode($this->firstEl['table'], 'disableDelete')) {
950 $aOnClick = 'return deleteRecord(\'' . $this->firstEl['table'] . '\',\'' . $this->firstEl['uid'] . '\', unescape(\'' . rawurlencode($this->retUrl) . '\'));';
951 $buttons['delete'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '" title="' . $GLOBALS['LANG']->getLL('deleteItem', TRUE) . '">' . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
952 }
953 // Undo:
954 $undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->firstEl['table'], 'sys_history') . ' AND recuid=' . intval($this->firstEl['uid']), '', 'tstamp DESC', '1');
955 if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
956 $aOnClick = 'window.location.href=\'show_rechis.php?element=' . rawurlencode(($this->firstEl['table'] . ':' . $this->firstEl['uid'])) . '&revert=ALL_FIELDS&sumUp=-1&returnUrl=' . rawurlencode($this->R_URI) . '\'; return false;';
957 $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>';
958 }
959 if ($this->getNewIconMode($this->firstEl['table'], 'showHistory')) {
960 $aOnClick = 'window.location.href=\'show_rechis.php?element=' . rawurlencode(($this->firstEl['table'] . ':' . $this->firstEl['uid'])) . '&returnUrl=' . rawurlencode($this->R_URI) . '\'; return false;';
961 $buttons['history'] = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . IconUtility::getSpriteIcon('actions-document-history-open') . '</a>';
962 }
963 // If only SOME fields are shown in the form, this will link the user to the FULL form:
964 if ($this->columnsOnly) {
965 $buttons['columns_only'] = '<a href="' . htmlspecialchars(($this->R_URI . '&columnsOnly=')) . '" title="' . $GLOBALS['LANG']->getLL('editWholeRecord', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
966 }
967 }
968 }
969 // add the CSH icon
970 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'TCEforms', $GLOBALS['BACK_PATH'], '', TRUE);
971 $buttons['shortcut'] = $this->shortCutLink();
972 $buttons['open_in_new_window'] = $this->openInNewWindowLink();
973 return $buttons;
974 }
975
976 /**
977 * Returns the language switch/selector for editing,
978 * show only when a single record is edited
979 * - multiple records are too confusing
980 *
981 * @return string The HTML
982 * @todo Define visibility
983 */
984 public function langSelector() {
985 $langSelector = '';
986 if (count($this->elementsData) == 1) {
987 $langSelector = $this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']);
988 }
989 return $langSelector;
990 }
991
992 /**
993 * Compiles the extra form headers if the tceforms
994 *
995 * @return string The HTML
996 * @todo Define visibility
997 */
998 public function extraFormHeaders() {
999 $extraTemplate = '';
1000 if (is_array($this->tceforms->extraFormHeaders)) {
1001 $extraTemplate = HtmlParser::getSubpart($this->doc->moduleTemplate, '###DOCHEADER_EXTRAHEADER###');
1002 $extraTemplate = HtmlParser::substituteMarker($extraTemplate, '###EXTRAHEADER###', implode(LF, $this->tceforms->extraFormHeaders));
1003 }
1004 return $extraTemplate;
1005 }
1006
1007 /**
1008 * Put together the various elements (buttons, selectors, form) into a table
1009 *
1010 * @param string $editForm HTML form.
1011 * @return string Composite HTML
1012 * @todo Define visibility
1013 */
1014 public function compileForm($editForm) {
1015 $formContent = '
1016 <!-- EDITING FORM -->
1017 ' . $editForm . '
1018
1019 <input type="hidden" name="returnUrl" value="' . htmlspecialchars($this->retUrl) . '" />
1020 <input type="hidden" name="viewUrl" value="' . htmlspecialchars($this->viewUrl) . '" />';
1021 if ($this->returnNewPageId) {
1022 $formContent .= '<input type="hidden" name="returnNewPageId" value="1" />';
1023 }
1024 $formContent .= '<input type="hidden" name="popViewId" value="' . htmlspecialchars($this->viewId) . '" />';
1025 if ($this->viewId_addParams) {
1026 $formContent .= '<input type="hidden" name="popViewId_addParams" value="' . htmlspecialchars($this->viewId_addParams) . '" />';
1027 }
1028 $formContent .= '
1029 <input type="hidden" name="closeDoc" value="0" />
1030 <input type="hidden" name="doSave" value="0" />
1031 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
1032 <input type="hidden" name="_scrollPosition" value="" />' . FormEngine::getHiddenTokenField('editRecord');
1033 return $formContent;
1034 }
1035
1036 /**
1037 * Create the checkbox buttons in the bottom of the pages.
1038 *
1039 * @return string HTML for function menus.
1040 * @todo Define visibility
1041 */
1042 public function functionMenus() {
1043 if ($GLOBALS['BE_USER']->getTSConfigVal('options.enableShowPalettes')) {
1044 // Show palettes:
1045 return '
1046 <!-- Function menu (checkbox for showing all palettes): -->
1047 <br />' . 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"') . '<label for="checkShowPalettes">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPalettes', 1) . '</label>';
1048 } else {
1049 return '';
1050 }
1051 }
1052
1053 /**
1054 * Create shortcut icon
1055 *
1056 * @return string
1057 * @todo Define visibility
1058 */
1059 public function shortCutLink() {
1060 if ($this->returnUrl == 'close.html' || !$GLOBALS['BE_USER']->mayMakeShortcut()) {
1061 return '';
1062 }
1063 return $this->doc->makeShortcutIcon('returnUrl,edit,defVals,overrideVals,columnsOnly,returnNewPageId,editRegularContentFromId,disHelp,noView', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name'], 1);
1064 }
1065
1066 /**
1067 * Creates open-in-window link
1068 *
1069 * @return string
1070 * @todo Define visibility
1071 */
1072 public function openInNewWindowLink() {
1073 if ($this->returnUrl == 'close.html') {
1074 return '';
1075 }
1076 $aOnClick = 'vHWin=window.open(\'' . 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;';
1077 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>';
1078 }
1079
1080 /**
1081 * Reads comment messages from TCEforms and prints them in a HTML comment in the bottom of the page.
1082 *
1083 * @return void
1084 * @todo Define visibility
1085 */
1086 public function tceformMessages() {
1087 if (count($this->tceforms->commentMessages)) {
1088 $tceformMessages = '
1089 <!-- TCEFORM messages
1090 ' . htmlspecialchars(implode(LF, $this->tceforms->commentMessages)) . '
1091 -->
1092 ';
1093 }
1094 return $tceformMessages;
1095 }
1096
1097 /***************************
1098 *
1099 * Localization stuff
1100 *
1101 ***************************/
1102 /**
1103 * Make selector box for creating new translation for a record or switching to edit the record in an existing language.
1104 * Displays only languages which are available for the current page.
1105 *
1106 * @param string $table Table name
1107 * @param integer $uid Uid for which to create a new language
1108 * @param integer $pid Pid of the record
1109 * @return string <select> HTML element (if there were items for the box anyways...)
1110 * @todo Define visibility
1111 */
1112 public function languageSwitch($table, $uid, $pid = NULL) {
1113 $content = '';
1114 $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
1115 $transOrigPointerField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
1116 // Table editable and activated for languages?
1117 if ($GLOBALS['BE_USER']->check('tables_modify', $table) && $languageField && $transOrigPointerField && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) {
1118 if (is_null($pid)) {
1119 $row = BackendUtility::getRecord($table, $uid, 'pid');
1120 $pid = $row['pid'];
1121 }
1122 // Get all avalibale languages for the page
1123 $langRows = $this->getLanguages($pid);
1124 // Page available in other languages than default language?
1125 if (is_array($langRows) && count($langRows) > 1) {
1126 $rowsByLang = array();
1127 $fetchFields = 'uid,' . $languageField . ',' . $transOrigPointerField;
1128 // Get record in current language
1129 $rowCurrent = BackendUtility::getLiveVersionOfRecord($table, $uid, $fetchFields);
1130 if (!is_array($rowCurrent)) {
1131 $rowCurrent = BackendUtility::getRecord($table, $uid, $fetchFields);
1132 }
1133 $currentLanguage = $rowCurrent[$languageField];
1134 // Disabled for records with [all] language!
1135 if ($currentLanguage > -1) {
1136 // Get record in default language if needed
1137 if ($currentLanguage && $rowCurrent[$transOrigPointerField]) {
1138 $rowsByLang[0] = BackendUtility::getLiveVersionOfRecord($table, $rowCurrent[$transOrigPointerField], $fetchFields);
1139 if (!is_array($rowsByLang[0])) {
1140 $rowsByLang[0] = BackendUtility::getRecord($table, $rowCurrent[$transOrigPointerField], $fetchFields);
1141 }
1142 } else {
1143 $rowsByLang[$rowCurrent[$languageField]] = $rowCurrent;
1144 }
1145 if ($rowCurrent[$transOrigPointerField] || $currentLanguage === '0') {
1146 // Get record in other languages to see what's already available
1147 $translations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fetchFields, $table, 'pid=' . intval($pid) . ' AND ' . $languageField . '>0' . ' AND ' . $transOrigPointerField . '=' . intval($rowsByLang[0]['uid']) . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table));
1148 foreach ($translations as $row) {
1149 $rowsByLang[$row[$languageField]] = $row;
1150 }
1151 }
1152 $langSelItems = array();
1153 foreach ($langRows as $lang) {
1154 if ($GLOBALS['BE_USER']->checkLanguageAccess($lang['uid'])) {
1155 $newTranslation = isset($rowsByLang[$lang['uid']]) ? '' : ' [' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.new', 1) . ']';
1156 // Create url for creating a localized record
1157 if ($newTranslation) {
1158 $href = $this->doc->issueCommand('&cmd[' . $table . '][' . $rowsByLang[0]['uid'] . '][localize]=' . $lang['uid'], $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode(($table . ':' . $rowsByLang[0]['uid'] . ':' . $lang['uid'])) . '&returnUrl=' . rawurlencode($this->retUrl) . BackendUtility::getUrlToken('editRecord'));
1159 } else {
1160 $href = $this->backPath . 'alt_doc.php?';
1161 $href .= '&edit[' . $table . '][' . $rowsByLang[$lang['uid']]['uid'] . ']=edit';
1162 $href .= '&returnUrl=' . rawurlencode($this->retUrl) . BackendUtility::getUrlToken('editRecord');
1163 }
1164 $langSelItems[$lang['uid']] = '
1165 <option value="' . htmlspecialchars($href) . '"' . ($currentLanguage == $lang['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars(($lang['title'] . $newTranslation)) . '</option>';
1166 }
1167 }
1168 // If any languages are left, make selector:
1169 if (count($langSelItems) > 1) {
1170 $onChange = 'if(this.options[this.selectedIndex].value){window.location.href=(this.options[this.selectedIndex].value);}';
1171 $content = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', 1) . ' <select name="_langSelector" onchange="' . htmlspecialchars($onChange) . '">
1172 ' . implode('', $langSelItems) . '
1173 </select>';
1174 }
1175 }
1176 }
1177 }
1178 return $content;
1179 }
1180
1181 /**
1182 * Redirects to alt_doc with new parameters to edit a just created localized record
1183 *
1184 * @param string $justLocalized String passed by GET &justLocalized=
1185 * @return void
1186 * @todo Define visibility
1187 */
1188 public function localizationRedirect($justLocalized) {
1189 list($table, $orig_uid, $language) = explode(':', $justLocalized);
1190 if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']) {
1191 $localizedRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid', $table, $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '=' . intval($language) . ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . intval($orig_uid) . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table));
1192 if (is_array($localizedRecord)) {
1193 // Create parameters and finally run the classic page module for creating a new page translation
1194 $params = '&edit[' . $table . '][' . $localizedRecord['uid'] . ']=edit';
1195 $returnUrl = '&returnUrl=' . rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl')));
1196 $location = $GLOBALS['BACK_PATH'] . 'alt_doc.php?' . $params . $returnUrl . BackendUtility::getUrlToken('editRecord');
1197 HttpUtility::redirect($location);
1198 }
1199 }
1200 }
1201
1202 /**
1203 * Returns sys_language records available for record translations on given page.
1204 *
1205 * @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)
1206 * @return array Language records including faked record for default language
1207 * @todo Define visibility
1208 */
1209 public function getLanguages($id) {
1210 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
1211 // Fallback non sprite-configuration
1212 if (preg_match('/\\.gif$/', $modSharedTSconfig['properties']['defaultLanguageFlag'])) {
1213 $modSharedTSconfig['properties']['defaultLanguageFlag'] = str_replace('.gif', '', $modSharedTSconfig['properties']['defaultLanguageFlag']);
1214 }
1215 $languages = array(
1216 0 => array(
1217 'uid' => 0,
1218 'pid' => 0,
1219 'hidden' => 0,
1220 'title' => strlen($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'] . ' (' . $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage') . ')' : $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage'),
1221 'flag' => $modSharedTSconfig['properties']['defaultLanguageFlag']
1222 )
1223 );
1224 $exQ = $GLOBALS['BE_USER']->isAdmin() ? '' : ' AND sys_language.hidden=0';
1225 if ($id) {
1226 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('sys_language.*', 'pages_language_overlay,sys_language', 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . intval($id) . BackendUtility::deleteClause('pages_language_overlay') . $exQ, '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', 'sys_language.title');
1227 } else {
1228 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('sys_language.*', 'sys_language', 'sys_language.hidden=0', '', 'sys_language.title');
1229 }
1230 if ($rows) {
1231 foreach ($rows as $row) {
1232 $languages[$row['uid']] = $row;
1233 }
1234 }
1235 return $languages;
1236 }
1237
1238 /***************************
1239 *
1240 * Other functions
1241 *
1242 ***************************/
1243 /**
1244 * Fix $this->editconf if versioning applies to any of the records
1245 *
1246 * @param array $mapArray Mapping between old and new ids if auto-versioning has been performed.
1247 * @return void
1248 * @todo Define visibility
1249 */
1250 public function fixWSversioningInEditConf($mapArray = FALSE) {
1251 // Traverse the editConf array
1252 if (is_array($this->editconf)) {
1253 // Tables:
1254 foreach ($this->editconf as $table => $conf) {
1255 if (is_array($conf) && $GLOBALS['TCA'][$table]) {
1256 // Traverse the keys/comments of each table (keys can be a commalist of uids)
1257 $newConf = array();
1258 foreach ($conf as $cKey => $cmd) {
1259 if ($cmd == 'edit') {
1260 // Traverse the ids:
1261 $ids = GeneralUtility::trimExplode(',', $cKey, 1);
1262 foreach ($ids as $idKey => $theUid) {
1263 if (is_array($mapArray)) {
1264 if ($mapArray[$table][$theUid]) {
1265 $ids[$idKey] = $mapArray[$table][$theUid];
1266 }
1267 } else {
1268 // Default, look for versions in workspace for record:
1269 $calcPRec = $this->getRecordForEdit($table, $theUid);
1270 if (is_array($calcPRec)) {
1271 // Setting UID again if it had changed, eg. due to workspace versioning.
1272 $ids[$idKey] = $calcPRec['uid'];
1273 }
1274 }
1275 }
1276 // Add the possibly manipulated IDs to the new-build newConf array:
1277 $newConf[implode(',', $ids)] = $cmd;
1278 } else {
1279 $newConf[$cKey] = $cmd;
1280 }
1281 }
1282 // Store the new conf array:
1283 $this->editconf[$table] = $newConf;
1284 }
1285 }
1286 }
1287 }
1288
1289 /**
1290 * Get record for editing.
1291 *
1292 * @param string $table Table name
1293 * @param integer $theUid Record UID
1294 * @return array Returns record to edit, FALSE if none
1295 * @todo Define visibility
1296 */
1297 public function getRecordForEdit($table, $theUid) {
1298 // Fetch requested record:
1299 $reqRecord = BackendUtility::getRecord($table, $theUid, 'uid,pid');
1300 if (is_array($reqRecord)) {
1301 // If workspace is OFFLINE:
1302 if ($GLOBALS['BE_USER']->workspace != 0) {
1303 // Check for versioning support of the table:
1304 if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1305 // If the record is already a version of "something" pass it by.
1306 if ($reqRecord['pid'] == -1) {
1307 // (If it turns out not to be a version of the current workspace there will be trouble, but that is handled inside TCEmain then and in the interface it would clearly be an error of links if the user accesses such a scenario)
1308 return $reqRecord;
1309 } else {
1310 // The input record was online and an offline version must be found or made:
1311 // Look for version of this workspace:
1312 $versionRec = BackendUtility::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $reqRecord['uid'], 'uid,pid,t3ver_oid');
1313 return is_array($versionRec) ? $versionRec : $reqRecord;
1314 }
1315 } else {
1316 // This means that editing cannot occur on this record because it was not supporting versioning which is required inside an offline workspace.
1317 return FALSE;
1318 }
1319 } else {
1320 // In ONLINE workspace, just return the originally requested record:
1321 return $reqRecord;
1322 }
1323 } else {
1324 // Return FALSE because the table/uid was not found anyway.
1325 return FALSE;
1326 }
1327 }
1328
1329 /**
1330 * Function, which populates the internal editconf array with editing commands for all tt_content elements from the normal column in normal language from the page pointed to by $this->editRegularContentFromId
1331 *
1332 * @return void
1333 * @todo Define visibility
1334 */
1335 public function editRegularContentFromId() {
1336 if (ExtensionManagementUtility::isLoaded('cms')) {
1337 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tt_content', 'pid=' . intval($this->editRegularContentFromId) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content') . ' AND colPos=0 AND sys_language_uid=0', '', 'sorting');
1338 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
1339 $ecUids = array();
1340 while ($ecRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1341 $ecUids[] = $ecRec['uid'];
1342 }
1343 $this->editconf['tt_content'][implode(',', $ecUids)] = 'edit';
1344 }
1345 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1346 }
1347 }
1348
1349 /**
1350 * Populates the variables $this->storeArray, $this->storeUrl, $this->storeUrlMd5
1351 *
1352 * @return void
1353 * @see makeDocSel()
1354 * @todo Define visibility
1355 */
1356 public function compileStoreDat() {
1357 $this->storeArray = GeneralUtility::compileSelectedGetVarsFromArray('edit,defVals,overrideVals,columnsOnly,disHelp,noView,editRegularContentFromId', $this->R_URL_getvars);
1358 $this->storeUrl = GeneralUtility::implodeArrayForUrl('', $this->storeArray);
1359 $this->storeUrlMd5 = md5($this->storeUrl);
1360 }
1361
1362 /**
1363 * Function used to look for configuration of buttons in the form: Fx. disabling buttons or showing them at various positions.
1364 *
1365 * @param string $table The table for which the configuration may be specific
1366 * @param string $key The option for look for. Default is checking if the saveDocNew button should be displayed.
1367 * @return string Return value fetched from USER TSconfig
1368 * @todo Define visibility
1369 */
1370 public function getNewIconMode($table, $key = 'saveDocNew') {
1371 $TSconfig = $GLOBALS['BE_USER']->getTSConfig('options.' . $key);
1372 $output = trim(isset($TSconfig['properties'][$table]) ? $TSconfig['properties'][$table] : $TSconfig['value']);
1373 return $output;
1374 }
1375
1376 /**
1377 * Handling the closing of a document
1378 *
1379 * @param integer $code Close code: 0/1 will redirect to $this->retUrl, 3 will clear the docHandler (thus closing all documents) and otehr values will call setDocument with ->retUrl
1380 * @return void
1381 * @todo Define visibility
1382 */
1383 public function closeDocument($code = 0) {
1384 // If current document is found in docHandler,
1385 // then unset it, possibly unset it ALL and finally, write it to the session data
1386 if (isset($this->docHandler[$this->storeUrlMd5])) {
1387 // add the closing document to the recent documents
1388 $recentDocs = $GLOBALS['BE_USER']->getModuleData('opendocs::recent');
1389 if (!is_array($recentDocs)) {
1390 $recentDocs = array();
1391 }
1392 $closedDoc = $this->docHandler[$this->storeUrlMd5];
1393 $recentDocs = array_merge(array($this->storeUrlMd5 => $closedDoc), $recentDocs);
1394 if (count($recentDocs) > 8) {
1395 $recentDocs = array_slice($recentDocs, 0, 8);
1396 }
1397 // remove it from the list of the open documents
1398 unset($this->docHandler[$this->storeUrlMd5]);
1399 if ($code == '3') {
1400 $recentDocs = array_merge($this->docHandler, $recentDocs);
1401 $this->docHandler = array();
1402 }
1403 $GLOBALS['BE_USER']->pushModuleData('opendocs::recent', $recentDocs);
1404 $GLOBALS['BE_USER']->pushModuleData('alt_doc.php', array($this->docHandler, $this->docDat[1]));
1405 BackendUtility::setUpdateSignal('OpendocsController::updateNumber', count($this->docHandler));
1406 }
1407 // If ->returnEditConf is set, then add the current content of editconf to the ->retUrl variable: (used by other scripts, like wizard_add, to know which records was created or so...)
1408 if ($this->returnEditConf && $this->retUrl != 'dummy.php') {
1409 $this->retUrl .= '&returnEditConf=' . rawurlencode(serialize($this->editconf));
1410 }
1411 // If code is NOT set OR set to 1, then make a header location redirect to $this->retUrl
1412 if (!$code || $code == 1) {
1413 HttpUtility::redirect($this->retUrl);
1414 } else {
1415 $this->setDocument('', $this->retUrl);
1416 }
1417 }
1418
1419 /**
1420 * Redirects to the document pointed to by $currentDocFromHandlerMD5 OR $retUrl (depending on some internal calculations).
1421 * Most likely you will get a header-location redirect from this function.
1422 *
1423 * @param string $currentDocFromHandlerMD5 Pointer to the document in the docHandler array
1424 * @param string $retUrl Alternative/Default retUrl
1425 * @return void
1426 * @todo Define visibility
1427 */
1428 public function setDocument($currentDocFromHandlerMD5 = '', $retUrl = 'alt_doc_nodoc.php') {
1429 if (!ExtensionManagementUtility::isLoaded('cms') && !strcmp($retUrl, 'alt_doc_nodoc.php')) {
1430 return;
1431 }
1432 if (!$this->modTSconfig['properties']['disableDocSelector'] && is_array($this->docHandler) && count($this->docHandler)) {
1433 if (isset($this->docHandler[$currentDocFromHandlerMD5])) {
1434 $setupArr = $this->docHandler[$currentDocFromHandlerMD5];
1435 } else {
1436 $setupArr = reset($this->docHandler);
1437 }
1438 if ($setupArr[2]) {
1439 $sParts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
1440 $retUrl = $sParts['path'] . '?' . $setupArr[2] . '&returnUrl=' . rawurlencode($retUrl);
1441 }
1442 }
1443 HttpUtility::redirect($retUrl);
1444 }
1445
1446 }
1447
1448 ?>