*** empty log message ***
[Packages/TYPO3.CMS.git] / typo3 / alt_doc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Main form rendering script
29 * By sending certain parameters to this script you can bring up a form
30 * which allows the user to edit the content of one or more database records.
31 *
32 * $Id$
33 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
34 * XHTML compliant
35 *
36 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
37 */
38 /**
39 * [CLASS/FUNCTION INDEX of SCRIPT]
40 *
41 *
42 *
43 * 100: class SC_alt_doc
44 * 174: function preInit()
45 * 232: function doProcessData()
46 * 242: function processData()
47 * 370: function init()
48 * 462: function main()
49 * 531: function printContent()
50 *
51 * SECTION: Sub-content functions, rendering specific parts of the module content.
52 * 566: function makeEditForm()
53 * 749: function makeButtonPanel()
54 * 828: function makeDocSel()
55 * 870: function makeCmenu()
56 * 891: function compileForm($panel,$docSel,$cMenu,$editForm)
57 * 953: function functionMenus()
58 * 984: function shortCutLink()
59 * 1015: function tceformMessages()
60 *
61 * SECTION: Other functions
62 * 1054: function fixWSversioningInEditConf($mapArray=FALSE)
63 * 1103: function getRecordForEdit($table,$theUid)
64 * 1138: function editRegularContentFromId()
65 * 1165: function compileStoreDat()
66 * 1178: function getNewIconMode($table,$key='saveDocNew')
67 * 1191: function closeDocument($code=0)
68 * 1223: function setDocument($currentDocFromHandlerMD5='',$retUrl='alt_doc_nodoc.php')
69 *
70 * TOTAL FUNCTIONS: 21
71 * (This index is automatically created/updated by the extension "extdeveval")
72 *
73 */
74
75
76 require('init.php');
77 require('template.php');
78 $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
79 require_once (PATH_t3lib.'class.t3lib_tceforms.php');
80 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
81
82 require_once (PATH_t3lib.'class.t3lib_tcemain.php');
83 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
84 require_once (PATH_t3lib.'class.t3lib_transferdata.php');
85
86
87 t3lib_BEfunc::lockRecords();
88
89
90
91
92 /**
93 * Script Class: Drawing the editing form for editing records in TYPO3.
94 * Notice: It does NOT use tce_db.php to submit data to, rather it handles submissions itself
95 *
96 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
97 * @package TYPO3
98 * @subpackage core
99 */
100 class SC_alt_doc {
101
102 // Internal, static: GPvars:
103 var $editconf; // GPvar "edit": Is an array looking approx like [tablename][list-of-ids]=command, eg. "&edit[pages][123]=edit". See t3lib_BEfunc::editOnClick(). Value can be seen modified internally (converting NEW keyword to id, workspace/versioning etc).
104 var $columnsOnly; // 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 $TCA
105 var $defVals; // Default values for fields (array with tablenames, fields etc. as keys). Can be seen modified internally.
106 var $overrideVals; // Array of values to force being set (as hidden fields). Will be set as $this->defVals IF defVals does not exist.
107 var $returnUrl; // 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
108 var $closeDoc; // Close-document command. Not really sure of all options...
109 var $doSave; // 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).
110
111 var $data; // GPvar (for processing only) : The data array from which the data comes...
112 var $mirror; // GPvar (for processing only) : ?
113 var $cacheCmd; // GPvar (for processing only) : Clear-cache cmd.
114 var $redirect; // GPvar (for processing only) : Redirect (not used???)
115 var $disableRTE; // GPvar (for processing only) : If set, the rich text editor is disabled in the forms.
116 var $returnNewPageId; // 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.
117 var $vC; // GPvar (for processing only) : Verification code, internal stuff.
118
119 var $popViewId; // GPvar (module) : ID for displaying the page in the frontend (used for SAVE/VIEW operations)
120 var $popViewId_addParams; // GPvar (module) : Additional GET vars for the link, eg. "&L=xxx"
121 var $viewUrl; // GPvar (module) : Alternative URL for viewing the frontend pages.
122 var $editRegularContentFromId; // 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!
123 var $recTitle; // Alternative title for the document handler.
124 var $disHelp; // Disable help... ?
125 var $noView; // If set, then no SAVE/VIEW button is printed
126 var $returnEditConf; // If set, the $this->editconf array is returned to the calling script (used by wizard_add.php for instance)
127 var $localizationMode; // GP var, localization mode for TCEforms (eg. "text")
128
129
130 // Internal, static:
131 var $doc; // Document template object
132 var $content; // Content accumulation
133
134 var $retUrl; // 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.
135 var $R_URL_parts; // 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...
136 var $R_URL_getvars; // 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.)
137 var $R_URI; // Set to the URL of this script including variables which is needed to re-display the form. See main()
138
139 var $storeTitle; // Is loaded with the "title" of the currently "open document" - this is used in the Document Selector box. (see makeDocSel())
140 var $storeArray; // 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())
141 var $storeUrl; // Contains storeArray, but imploded into a GET parameter string (see compileStoreDat())
142 var $storeUrlMd5; // Hashed value of storeURL (see compileStoreDat())
143
144 var $docDat; // Module session data
145 var $docHandler; // 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".
146
147
148 // Internal: Related to the form rendering:
149 var $elementsData; // Array of the elements to create edit forms for.
150 var $firstEl; // Pointer to the first element in $elementsData
151 var $errorC; // Counter, used to count the number of errors (when users do not have edit permissions)
152 var $newC; // Counter, used to count the number of new record forms displayed
153 var $viewId; // Is set to the pid value of the last shown record - thus indicating which page to show when clicking the SAVE/VIEW button
154 var $viewId_addParams; // Is set to additional parameters (like "&L=xxx") if the record supports it.
155 var $modTSconfig; // Module TSconfig, loaded from main() based on the page id value of viewId
156 var $tceforms; // Contains the instance of TCEforms class.
157 var $generalPathOfForm; // Contains the root-line path of the currently edited record(s) - for display.
158
159
160 // Internal, dynamic:
161 var $dontStoreDocumentRef; // Used internally to disable the storage of the document reference (eg. new records)
162
163
164
165
166
167
168
169 /**
170 * First initialization.
171 *
172 * @return void
173 */
174 function preInit() {
175 global $BE_USER;
176
177 // Setting GPvars:
178 $this->editconf = t3lib_div::_GP('edit');
179 $this->defVals = t3lib_div::_GP('defVals');
180 $this->overrideVals = t3lib_div::_GP('overrideVals');
181 $this->columnsOnly = t3lib_div::_GP('columnsOnly');
182 $this->returnUrl = t3lib_div::_GP('returnUrl');
183 $this->closeDoc = t3lib_div::_GP('closeDoc');
184 $this->doSave = t3lib_div::_GP('doSave');
185 $this->returnEditConf = t3lib_div::_GP('returnEditConf');
186 $this->localizationMode = t3lib_div::_GP('localizationMode');
187
188
189 // Setting override values as default if defVals does not exist.
190 if (!is_array($this->defVals) && is_array($this->overrideVals)) {
191 $this->defVals = $this->overrideVals;
192 }
193
194 // Setting return URL
195 $this->retUrl = $this->returnUrl ? $this->returnUrl : 'dummy.php';
196
197 // Fix $this->editconf if versioning applies to any of the records
198 $this->fixWSversioningInEditConf();
199
200 // Make R_URL (request url) based on input GETvars:
201 $this->R_URL_parts = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
202 $this->R_URL_getvars = t3lib_div::_GET();
203 $this->R_URL_getvars['edit'] = $this->editconf;
204
205 // MAKE url for storing
206 $this->compileStoreDat();
207
208 // Initialize more variables.
209 $this->dontStoreDocumentRef=0;
210 $this->storeTitle='';
211
212 // Get session data for the module:
213 $this->docDat = $BE_USER->getModuleData('alt_doc.php','ses');
214 $this->docHandler = $this->docDat[0];
215
216 // If a request for closing the document has been sent, act accordingly:
217 if ($this->closeDoc>0) {
218 $this->closeDocument($this->closeDoc);
219 }
220
221 // If NO vars are sent to the script, try to read first document:
222 if (is_array($this->R_URL_getvars) && count($this->R_URL_getvars)<2 && !is_array($this->editconf)) { // Added !is_array($this->editconf) because editConf must not be set either. Anyways I can't figure out when this situation here will apply...
223 $this->setDocument($this->docDat[1]);
224 }
225 }
226
227 /**
228 * Detects, if a save command has been triggered.
229 *
230 * @return boolean True, then save the document (data submitted)
231 */
232 function doProcessData() {
233 $out = $this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']);
234 return $out;
235 }
236
237 /**
238 * Do processing of data, submitting it to TCEmain.
239 *
240 * @return void
241 */
242 function processData() {
243 global $BE_USER,$TYPO3_CONF_VARS;
244
245 // GPvars specifically for processing:
246 $this->data = t3lib_div::_GP('data');
247 $this->mirror = t3lib_div::_GP('mirror');
248 $this->cacheCmd = t3lib_div::_GP('cacheCmd');
249 $this->redirect = t3lib_div::_GP('redirect');
250 $this->disableRTE = t3lib_div::_GP('_disableRTE');
251 $this->returnNewPageId = t3lib_div::_GP('returnNewPageId');
252 $this->vC = t3lib_div::_GP('vC');
253
254 // See tce_db.php for relevate options here:
255 // Only options related to $this->data submission are included here.
256 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
257 $tce->stripslashes_values=0;
258
259 // Setting default values specific for the user:
260 $TCAdefaultOverride = $BE_USER->getTSConfigProp('TCAdefaults');
261 if (is_array($TCAdefaultOverride)) {
262 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
263 }
264
265 // Setting internal vars:
266 if ($BE_USER->uc['neverHideAtCopy']) { $tce->neverHideAtCopy = 1; }
267 $tce->debug=0;
268 $tce->disableRTE = $this->disableRTE;
269
270 // Loading TCEmain with data:
271 $tce->start($this->data,array());
272 if (is_array($this->mirror)) { $tce->setMirror($this->mirror); }
273
274 // If pages are being edited, we set an instruction about updating the page tree after this operation.
275 if (isset($this->data['pages'])) {
276 t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
277 }
278
279
280 // Checking referer / executing
281 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
282 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
283 if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
284 $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));
285 debug('Error: Referer host did not match with server host.');
286 } else {
287
288 // Perform the saving operation with TCEmain:
289 $tce->process_uploads($_FILES);
290 $tce->process_datamap();
291
292 // If there was saved any new items, load them:
293 if (count($tce->substNEWwithIDs_table)) {
294
295 // Resetting editconf:
296 $this->editconf = array();
297
298 // Traverse all new records and forge the content of ->editconf so we can continue to EDIT these records!
299 foreach($tce->substNEWwithIDs_table as $nKey => $nTable) {
300 $editId = $tce->substNEWwithIDs[$nKey];
301 // translate new id to the workspace version:
302 if ($versionRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $nTable, $editId,'uid')) {
303 $editId = $versionRec['uid'];
304 }
305
306 $this->editconf[$nTable][$editId]='edit';
307 if ($nTable=='pages' && $this->retUrl!='dummy.php' && $this->returnNewPageId) {
308 $this->retUrl.='&id='.$tce->substNEWwithIDs[$nKey];
309 }
310 }
311
312 // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
313 $this->R_URL_getvars['edit']=$this->editconf;
314
315 // Unsetting default values since we don't need them anymore.
316 unset($this->R_URL_getvars['defVals']);
317
318 // Re-compile the store* values since editconf changed...
319 $this->compileStoreDat();
320 }
321
322 // See if any records was auto-created as new versions?
323 if (count($tce->autoVersionIdMap)) {
324 $this->fixWSversioningInEditConf($tce->autoVersionIdMap);
325 }
326
327 // If a document is saved and a new one is created right after.
328 if (isset($_POST['_savedoknew_x']) && is_array($this->editconf)) {
329
330 // Finding the current table:
331 reset($this->editconf);
332 $nTable=key($this->editconf);
333
334 // Finding the first id, getting the records pid+uid
335 reset($this->editconf[$nTable]);
336 $nUid=key($this->editconf[$nTable]);
337 $nRec = t3lib_BEfunc::getRecord($nTable,$nUid,'pid,uid');
338
339 // Setting a blank editconf array for a new record:
340 $this->editconf=array();
341 if ($this->getNewIconMode($nTable)=='top') {
342 $this->editconf[$nTable][$nRec['pid']]='new';
343 } else {
344 $this->editconf[$nTable][-$nRec['uid']]='new';
345 }
346
347 // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
348 $this->R_URL_getvars['edit']=$this->editconf;
349
350 // Re-compile the store* values since editconf changed...
351 $this->compileStoreDat();
352 }
353
354 $tce->printLogErrorMessages(
355 isset($_POST['_saveandclosedok_x']) ?
356 $this->retUrl :
357 $this->R_URL_parts['path'].'?'.t3lib_div::implodeArrayForUrl('',$this->R_URL_getvars) // popView will not be invoked here, because the information from the submit button for save/view will be lost .... But does it matter if there is an error anyways?
358 );
359 }
360 if (isset($_POST['_saveandclosedok_x']) || $this->closeDoc<0) { // || 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!
361 $this->closeDocument(abs($this->closeDoc));
362 }
363 }
364
365 /**
366 * Initialize the normal module operation
367 *
368 * @return void
369 */
370 function init() {
371 global $BE_USER,$LANG,$BACK_PATH;
372
373 // Setting more GPvars:
374 $this->popViewId = t3lib_div::_GP('popViewId');
375 $this->popViewId_addParams = t3lib_div::_GP('popViewId_addParams');
376 $this->viewUrl = t3lib_div::_GP('viewUrl');
377 $this->editRegularContentFromId = t3lib_div::_GP('editRegularContentFromId');
378 $this->recTitle = t3lib_div::_GP('recTitle');
379 $this->disHelp = t3lib_div::_GP('disHelp');
380 $this->noView = t3lib_div::_GP('noView');
381
382 // Set other internal variables:
383 $this->R_URL_getvars['returnUrl']=$this->retUrl;
384 $this->R_URI = $this->R_URL_parts['path'].'?'.t3lib_div::implodeArrayForUrl('',$this->R_URL_getvars);
385
386 // MENU-ITEMS:
387 // If array, then it's a selector box menu
388 // If empty string it's just a variable, that'll be saved.
389 // Values NOT in this array will not be saved in the settings-array for the module.
390 $this->MOD_MENU = array(
391 'showPalettes' => '',
392 'showDescriptions' => '',
393 'disableRTE' => ''
394 );
395
396 // Setting virtual document name
397 $this->MCONF['name']='xMOD_alt_doc.php';
398
399 // CLEANSE SETTINGS
400 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
401
402 // Create an instance of the document template object
403 $this->doc = t3lib_div::makeInstance('mediumDoc');
404 $this->doc->bodyTagMargins['x']=5;
405 $this->doc->bodyTagMargins['y']=5;
406 $this->doc->backPath = $BACK_PATH;
407 $this->doc->docType = 'xhtml_trans';
408
409 $this->doc->form='<form action="'.htmlspecialchars($this->R_URI).'" method="post" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'" name="editform" onsubmit="return TBE_EDITOR_checkSubmit(1);">';
410
411 $this->doc->JScode = $this->doc->wrapScriptTags('
412 function jumpToUrl(URL,formEl) { //
413 if (!TBE_EDITOR_isFormChanged()) {
414 document.location = URL;
415 } else if (formEl && formEl.type=="checkbox") {
416 formEl.checked = formEl.checked ? 0 : 1;
417 }
418 }
419
420 // Object: TS:
421 function typoSetup () { //
422 this.uniqueID = "";
423 }
424 var TS = new typoSetup();
425
426 // Info view:
427 function launchView(table,uid,bP) { //
428 var backPath= bP ? bP : "";
429 var thePreviewWindow="";
430 thePreviewWindow = window.open(backPath+"show_item.php?table="+escape(table)+"&uid="+escape(uid),"ShowItem"+TS.uniqueID,"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
431 if (thePreviewWindow && thePreviewWindow.focus) {
432 thePreviewWindow.focus();
433 }
434 }
435 function deleteRecord(table,id,url) { //
436 if (confirm('.$LANG->JScharCode($LANG->getLL('deleteWarning')).')) {
437 document.location = "tce_db.php?cmd["+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC='.$BE_USER->veriCode().'&prErr=1&uPT=1";
438 }
439 return false;
440 }
441 '.(isset($_POST['_savedokview_x']) && $this->popViewId ?
442 'if (window.opener) { '.
443 t3lib_BEfunc::viewOnClick($this->popViewId,'',t3lib_BEfunc::BEgetRootLine($this->popViewId),'',$this->viewUrl,$this->popViewId_addParams,FALSE).
444 ' } else { '.
445 t3lib_BEfunc::viewOnClick($this->popViewId,'',t3lib_BEfunc::BEgetRootLine($this->popViewId),'',$this->viewUrl,$this->popViewId_addParams).
446 ' } '
447 : '')
448 ).$this->doc->getDynTabMenuJScode();
449
450 // Setting up the context sensitive menu:
451 $CMparts = $this->doc->getContextMenuCode();
452 $this->doc->JScode.= $CMparts[0];
453 $this->doc->bodyTagAdditions = $CMparts[1];
454 $this->doc->postCode.= $CMparts[2];
455 }
456
457 /**
458 * Main module operation
459 *
460 * @return void
461 */
462 function main() {
463 global $BE_USER,$LANG;
464
465 // Starting content accumulation:
466 $this->content='';
467 $this->content.=$this->doc->startPage('TYPO3 Edit Document');
468
469 // Begin edit:
470 if (is_array($this->editconf)) {
471
472 // Initialize TCEforms (rendering the forms)
473 $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
474 $this->tceforms->initDefaultBEMode();
475 $this->tceforms->doSaveFieldName = 'doSave';
476 $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : ''; // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
477 $this->tceforms->returnUrl = $this->R_URI;
478 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
479 $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
480 $this->tceforms->enableClickMenu = TRUE;
481 $this->tceforms->enableTabMenu = TRUE;
482
483 // Clipboard is initialized:
484 $this->tceforms->clipObj = t3lib_div::makeInstance('t3lib_clipboard'); // Start clipboard
485 $this->tceforms->clipObj->initializeClipboard(); // Initialize - reads the clipboard content from the user session
486
487 // Setting external variables:
488 if ($BE_USER->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions']) $this->tceforms->edit_showFieldHelp='text';
489
490 if ($this->editRegularContentFromId) {
491 $this->editRegularContentFromId();
492 }
493
494 // Creating the editing form, wrap it with buttons, document selector etc.
495 $editForm = $this->makeEditForm();
496 if ($editForm) {
497 reset($this->elementsData);
498 $this->firstEl = current($this->elementsData);
499
500 if ($this->viewId) {
501 // Module configuration:
502 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->viewId,'mod.xMOD_alt_doc');
503 } else $this->modTSconfig=array();
504
505 $panel = $this->makeButtonPanel();
506 $docSel = $this->makeDocSel();
507 $cMenu = $this->makeCmenu();
508
509 $formContent = $this->compileForm($panel,$docSel,$cMenu,$editForm);
510
511 $this->content.= $this->tceforms->printNeededJSFunctions_top().
512 $formContent.
513 $this->tceforms->printNeededJSFunctions();
514 $this->content.= $this->functionMenus();
515
516 // Add CSH:
517 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms', $GLOBALS['BACK_PATH'],'<br/>|',FALSE,'margin-top: 20px;');
518
519 $this->content.= $this->shortCutLink();
520
521 $this->tceformMessages();
522 }
523 }
524 }
525
526 /**
527 * Outputting the accumulated content to screen
528 *
529 * @return void
530 */
531 function printContent() {
532
533 echo $this->content.$this->doc->endPage();
534 }
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 /***************************
556 *
557 * Sub-content functions, rendering specific parts of the module content.
558 *
559 ***************************/
560
561 /**
562 * Creates the editing form with TCEforms, based on the input from GPvars.
563 *
564 * @return string HTML form elements wrapped in tables
565 */
566 function makeEditForm() {
567 global $BE_USER,$LANG,$TCA;
568
569 // Initialize variables:
570 $this->elementsData=array();
571 $this->errorC=0;
572 $this->newC=0;
573 $thePrevUid='';
574 $editForm='';
575
576 // Traverse the GPvar edit array
577 foreach($this->editconf as $table => $conf) { // Tables:
578 if (is_array($conf) && $TCA[$table] && $BE_USER->check('tables_modify',$table)) {
579
580 // Traverse the keys/comments of each table (keys can be a commalist of uids)
581 foreach($conf as $cKey => $cmd) {
582 if ($cmd=='edit' || $cmd=='new') {
583
584 // Get the ids:
585 $ids = t3lib_div::trimExplode(',',$cKey,1);
586
587 // Traverse the ids:
588 foreach($ids as $theUid) {
589
590 // 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...)
591 // First, resetting flags.
592 $hasAccess = 1;
593 $deniedAccessReason = '';
594 $deleteAccess = 0;
595 $this->viewId = 0;
596
597 // If the command is to create a NEW record...:
598 if ($cmd=='new') {
599 if (intval($theUid)) { // 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.
600
601 // Find parent page on which the new record reside
602 if ($theUid<0) { // Less than zero - find parent page
603 $calcPRec=t3lib_BEfunc::getRecord($table,abs($theUid));
604 $calcPRec=t3lib_BEfunc::getRecord('pages',$calcPRec['pid']);
605 } else { // always a page
606 $calcPRec=t3lib_BEfunc::getRecord('pages',abs($theUid));
607 }
608
609 // Now, calculate whether the user has access to creating new records on this position:
610 if (is_array($calcPRec)) {
611 $CALC_PERMS = $BE_USER->calcPerms($calcPRec); // Permissions for the parent page
612 if ($table=='pages') { // If pages:
613 $hasAccess = $CALC_PERMS&8 ? 1 : 0;
614 $this->viewId = $calcPRec['pid'];
615 } else {
616 $hasAccess = $CALC_PERMS&16 ? 1 : 0;
617 $this->viewId = $calcPRec['uid'];
618 }
619 }
620 }
621 $this->dontStoreDocumentRef=1; // Don't save this document title in the document selector if the document is new.
622 } else { // Edit:
623 $calcPRec = t3lib_BEfunc::getRecord($table,$theUid);
624 t3lib_BEfunc::fixVersioningPid($table,$calcPRec);
625 if (is_array($calcPRec)) {
626 if ($table=='pages') { // If pages:
627 $CALC_PERMS = $BE_USER->calcPerms($calcPRec);
628 $hasAccess = $CALC_PERMS&2 ? 1 : 0;
629 $deleteAccess = $CALC_PERMS&4 ? 1 : 0;
630 $this->viewId = $calcPRec['uid'];
631 } else {
632 $CALC_PERMS = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',$calcPRec['pid'])); // Fetching pid-record first.
633 $hasAccess = $CALC_PERMS&16 ? 1 : 0;
634 $deleteAccess = $CALC_PERMS&16 ? 1 : 0;
635 $this->viewId = $calcPRec['pid'];
636
637 // Adding "&L=xx" if the record being edited has a languageField with a value larger than zero!
638 if ($TCA[$table]['ctrl']['languageField'] && $calcPRec[$TCA[$table]['ctrl']['languageField']]>0) {
639 $this->viewId_addParams = '&L='.$calcPRec[$TCA[$table]['ctrl']['languageField']];
640 }
641 }
642
643 // Check internals regarding access:
644 if ($hasAccess) {
645 $hasAccess = $BE_USER->recordEditAccessInternals($table, $calcPRec);
646 $deniedAccessReason = $BE_USER->errorMsg;
647 }
648 } else $hasAccess = 0;
649 }
650
651 // 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:
652
653 if ($hasAccess) {
654 $prevPageID = is_object($trData)?$trData->prevPageID:'';
655 $trData = t3lib_div::makeInstance('t3lib_transferData');
656 $trData->addRawData = TRUE;
657 $trData->defVals = $this->defVals;
658 $trData->lockRecords=1;
659 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
660 $trData->prevPageID = $prevPageID;
661 $trData->fetchRecord($table,$theUid,$cmd=='new'?'new':''); // 'new'
662 reset($trData->regTableItems_data);
663 $rec = current($trData->regTableItems_data);
664 $rec['uid'] = $cmd=='new' ? uniqid('NEW') : $theUid;
665 $this->elementsData[]=array(
666 'table' => $table,
667 'uid' => $rec['uid'],
668 'cmd' => $cmd,
669 'deleteAccess' => $deleteAccess
670 );
671 if ($cmd=='new') {
672 $rec['pid'] = $theUid=='prev'?$thePrevUid:$theUid;
673 }
674
675 // Now, render the form:
676 if (is_array($rec)) {
677
678 // Setting visual path / title of form:
679 $this->generalPathOfForm = $this->tceforms->getRecordPath($table,$rec);
680 if (!$this->storeTitle) {
681 $this->storeTitle = $this->recTitle ? htmlspecialchars($this->recTitle) : t3lib_BEfunc::getRecordTitle($table,$rec,1);
682 }
683
684 // Setting variables in TCEforms object:
685 $this->tceforms->hiddenFieldList = '';
686 $this->tceforms->globalShowHelp = $this->disHelp ? 0 : 1;
687 if (is_array($this->overrideVals[$table])) {
688 $this->tceforms->hiddenFieldListArr = array_keys($this->overrideVals[$table]);
689 }
690
691 // Register default language labels, if any:
692 $this->tceforms->registerDefaultLanguageData($table,$rec);
693
694 // Create form for the record (either specific list of fields or the whole record):
695 $panel = '';
696 if ($this->columnsOnly) {
697 $panel.= $this->tceforms->getListedFields($table,$rec,$this->columnsOnly);
698 } else {
699 $panel.= $this->tceforms->getMainFields($table,$rec);
700 }
701 $panel = $this->tceforms->wrapTotal($panel,$rec,$table);
702
703 // Setting the pid value for new records:
704 if ($cmd=='new') {
705 $panel.= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
706 $this->newC++;
707 }
708
709 // Display "is-locked" message:
710 if ($lockInfo = t3lib_BEfunc::isRecordLocked($table,$rec['uid'])) {
711 $lockIcon = '
712
713 <!--
714 Warning box:
715 -->
716 <table border="0" cellpadding="0" cellspacing="0" class="warningbox">
717 <tr>
718 <td><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/recordlock_warning3.gif','width="17" height="12"').' alt="" /></td>
719 <td>'.htmlspecialchars($lockInfo['msg']).'</td>
720 </tr>
721 </table>
722 ';
723 } else $lockIcon = '';
724
725 // Combine it all:
726 $editForm.= $lockIcon.$panel;
727 }
728
729 $thePrevUid = $rec['uid'];
730 } else {
731 $this->errorC++;
732 $editForm.=$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.noEditPermission',1).'<br /><br />'.
733 ($deniedAccessReason ? 'Reason: '.htmlspecialchars($deniedAccessReason).'<br/><br/>' : '');
734 }
735 }
736 }
737 }
738 }
739 }
740
741 return $editForm;
742 }
743
744 /**
745 * Create the panel of buttons for submitting the form or otherwise perform operations.
746 *
747 * @return string HTML code, comprised of images linked to various actions.
748 */
749 function makeButtonPanel() {
750 global $TCA,$LANG;
751
752 $panel='';
753
754 // Render SAVE type buttons:
755 // The action of each button is decided by its name attribute. (See doProcessData())
756 if (!$this->errorC && !$TCA[$this->firstEl['table']]['ctrl']['readOnly']) {
757
758 // SAVE button:
759 $panel.= '<input type="image" class="c-inputButton" name="_savedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" />';
760
761 // SAVE / VIEW button:
762 if ($this->viewId && !$this->noView && t3lib_extMgm::isLoaded('cms')) {
763 $panel.= '<input type="image" class="c-inputButton" name="_savedokview"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedokshow.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDocShow',1).'" />';
764 }
765
766 // SAVE / NEW button:
767 if (count($this->elementsData)==1 && $this->getNewIconMode($this->firstEl['table'])) {
768 $panel.= '<input type="image" class="c-inputButton" name="_savedoknew"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedoknew.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveNewDoc',1).'" />';
769 }
770
771 // SAVE / CLOSE
772 $panel.= '<input type="image" class="c-inputButton" name="_saveandclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc',1).'" />';
773 }
774
775 // CLOSE button:
776 $panel.= '<a href="#" onclick="document.editform.closeDoc.value=1; document.editform.submit(); return false;">'.
777 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" />'.
778 '</a>';
779
780 // DELETE + UNDO buttons:
781 if (!$this->errorC && !$TCA[$this->firstEl['table']]['ctrl']['readOnly'] && count($this->elementsData)==1) {
782 if ($this->firstEl['cmd']!='new' && t3lib_div::testInt($this->firstEl['uid'])) {
783
784 // Delete:
785 if ($this->firstEl['deleteAccess'] && !$TCA[$this->firstEl['table']]['ctrl']['readOnly'] && !$this->getNewIconMode($this->firstEl['table'],'disableDelete')) {
786 $aOnClick = 'return deleteRecord(\''.$this->firstEl['table'].'\',\''.$this->firstEl['uid'].'\',unescape(\''.rawurlencode($this->retUrl).'\'));';
787 $panel.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
788 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/deletedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->getLL('deleteItem',1).'" alt="" />'.
789 '</a>';
790 }
791
792 // Undo:
793 $undoButton = 0;
794 $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');
795 if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes)) {
796 $undoButton = 1;
797 }
798 if ($undoButton) {
799 $aOnClick = 'document.location=\'show_rechis.php?element='.rawurlencode($this->firstEl['table'].':'.$this->firstEl['uid']).'&revert=ALL_FIELDS&sumUp=-1&returnUrl='.rawurlencode($this->R_URI).'\'; return false;';
800 $panel.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
801 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/undo.gif','width="21" height="16"').' class="c-inputButton" title="'.htmlspecialchars(sprintf($LANG->getLL('undoLastChange'),t3lib_BEfunc::calcAge(time()-$undoButtonR['tstamp'],$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')))).'" alt="" />'.
802 '</a>';
803 }
804 if ($this->getNewIconMode($this->firstEl['table'],'showHistory')) {
805 $aOnClick = 'document.location=\'show_rechis.php?element='.rawurlencode($this->firstEl['table'].':'.$this->firstEl['uid']).'&returnUrl='.rawurlencode($this->R_URI).'\'; return false;';
806 $panel.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
807 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/history2.gif','width="13" height="12"').' class="c-inputButton" alt="" />'.
808 '</a>';
809 }
810
811 // If only SOME fields are shown in the form, this will link the user to the FULL form:
812 if ($this->columnsOnly) {
813 $panel.= '<a href="'.htmlspecialchars($this->R_URI.'&columnsOnly=').'">'.
814 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' class="c-inputButton" title="'.$LANG->getLL('editWholeRecord',1).'" alt="" />'.
815 '</a>';
816 }
817 }
818 }
819 return $panel;
820 }
821
822 /**
823 * Create the selector box form element which allows to select between open documents.
824 * Can be disabled through Page TSconfig.
825 *
826 * @return string HTML <select> element (if applicable)
827 */
828 function makeDocSel() {
829 global $BE_USER,$LANG;
830
831 // Render the selector ONLY if it has not been disabled:
832 if (!$this->modTSconfig['properties']['disableDocSelector']) {
833
834 // Checking if the currently open document is stored in the list of "open documents" - if not, then add it:
835 if ((strcmp($this->docDat[1],$this->storeUrlMd5)||!isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef) {
836 $this->docHandler[$this->storeUrlMd5]=array($this->storeTitle,$this->storeArray,$this->storeUrl);
837 $BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->storeUrlMd5));
838 }
839
840 // Now, create the document selector box:
841 $docSel='';
842 if (is_array($this->docHandler)) {
843 $opt = array();
844 $opt[] = '<option>[ '.$LANG->getLL('openDocs',1).': ]</option>';
845
846 // Traverse the list of open documents:
847 foreach($this->docHandler as $md5k => $setupArr) {
848 $theValue = 'alt_doc.php?'.$setupArr[2].'&returnUrl='.rawurlencode($this->retUrl);
849 $opt[]='<option value="'.htmlspecialchars($theValue).'"'.(!strcmp($md5k,$this->storeUrlMd5)?' selected="selected"':'').'>'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($setupArr[0]))).'</option>';
850 }
851
852 // Compile the selector box finally:
853 $onChange = 'if(this.options[this.selectedIndex].value && !TBE_EDITOR_isFormChanged()){document.location=(this.options[this.selectedIndex].value);}';
854 $docSel='<select name="_docSelector" onchange="'.htmlspecialchars($onChange).'">'.implode('',$opt).'</select>';
855
856 // Add CSH:
857 $docSel.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms_docSelector', $GLOBALS['BACK_PATH'],'', TRUE);
858 }
859 } else $docSel='';
860 return $docSel;
861 }
862
863 /**
864 * Create the selector box form element which allows to select a clear-cache operation.
865 * Can be disabled through Page TSconfig.
866 *
867 * @return string HTML <select> element (if applicable)
868 * @see template::clearCacheMenu()
869 */
870 function makeCmenu() {
871
872 // Generate the menu if NOT disabled:
873 if (!$this->modTSconfig['properties']['disableCacheSelector']) {
874 $cMenu = $this->doc->clearCacheMenu(intval($this->viewId),!$this->modTSconfig['properties']['disableDocSelector']);
875
876 // Add CSH:
877 $cMenu.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms_cacheSelector', $GLOBALS['BACK_PATH'],'', TRUE);
878 } else $cMenu ='';
879 return $cMenu;
880 }
881
882 /**
883 * Put together the various elements (buttons, selectors, form) into a table
884 *
885 * @param string The button panel HTML
886 * @param string Document selector HTML
887 * @param string Clear-cache menu HTML
888 * @param string HTML form.
889 * @return string Composite HTML
890 */
891 function compileForm($panel,$docSel,$cMenu,$editForm) {
892 global $LANG;
893
894
895 $formContent='';
896 $formContent.='
897
898 <!--
899 Header of the editing page.
900 Contains the buttons for saving/closing, the document selector and menu selector.
901 Shows the path of the editing operation as well.
902 -->
903 <table border="0" cellpadding="0" cellspacing="1" width="470" id="typo3-altdoc-header">
904 <tr>
905 <td nowrap="nowrap" valign="top">'.$panel.'</td>
906 <td nowrap="nowrap" valign="top" align="right">'.$docSel.$cMenu.'</td>
907 </tr>
908 <tr>
909 <td colspan="2">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path',1).': '.htmlspecialchars($this->generalPathOfForm).'</td>
910 </tr>
911 </table>
912 <img src="clear.gif" width="1" height="4" alt="" /><br />
913
914
915
916
917 <!--
918 EDITING FORM:
919 -->
920
921 '.$editForm.'
922
923
924
925 <!--
926 Saving buttons (same as in top)
927 -->
928
929 '.$panel.
930 '<input type="hidden" name="returnUrl" value="'.htmlspecialchars($this->retUrl).'" />
931 <input type="hidden" name="viewUrl" value="'.htmlspecialchars($this->viewUrl).'" />';
932
933 if ($this->returnNewPageId) {
934 $formContent.='<input type="hidden" name="returnNewPageId" value="1" />';
935 }
936 $formContent.='<input type="hidden" name="popViewId" value="'.htmlspecialchars($this->viewId).'" />';
937 if ($this->viewId_addParams) {
938 $formContent.='<input type="hidden" name="popViewId_addParams" value="'.htmlspecialchars($this->viewId_addParams).'" />';
939 }
940 $formContent.='<input type="hidden" name="closeDoc" value="0" />';
941 $formContent.='<input type="hidden" name="doSave" value="0" />';
942 $formContent.='<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
943 $formContent.='<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';
944
945 return $formContent;
946 }
947
948 /**
949 * Create the checkbox buttons in the bottom of the pages.
950 *
951 * @return string HTML for function menus.
952 */
953 function functionMenus() {
954 global $BE_USER,$LANG;
955
956 $funcMenus = '';
957
958 // Show palettes:
959 $funcMenus.= '<br /><br />'.t3lib_BEfunc::getFuncCheck('','SET[showPalettes]',$this->MOD_SETTINGS['showPalettes'],'alt_doc.php',t3lib_div::implodeArrayForUrl('',array_merge($this->R_URL_getvars,array('SET'=>'')))).$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPalettes',1);
960
961 // Show descriptions/help texts:
962 if ($BE_USER->uc['edit_showFieldHelp']!='text') {
963 $funcMenus.= '<br />'.t3lib_BEfunc::getFuncCheck('','SET[showDescriptions]',$this->MOD_SETTINGS['showDescriptions'],'alt_doc.php',t3lib_div::implodeArrayForUrl('',array_merge($this->R_URL_getvars,array('SET'=>'')))).$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showDescriptions',1);
964 }
965
966 // Show disable RTE checkbox:
967 if ($BE_USER->isRTE()) {
968 $funcMenus.= '<br />'.t3lib_BEfunc::getFuncCheck('','SET[disableRTE]',$this->MOD_SETTINGS['disableRTE'],'alt_doc.php',t3lib_div::implodeArrayForUrl('',array_merge($this->R_URL_getvars,array('SET'=>'')))).$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.disableRTE',1);
969 }
970
971 return '
972
973 <!--
974 Function menus (checkboxes for selecting options):
975 -->
976 '.$funcMenus;
977 }
978
979 /**
980 * Create shortcut and open-in-window link in the bottom of the page
981 *
982 * @return string
983 */
984 function shortCutLink() {
985 global $BE_USER,$LANG;
986
987 // ShortCut
988 if ($this->returnUrl!='close.html') {
989 $content.='<br /><br />';
990
991 // Shortcut:
992 if ($BE_USER->mayMakeShortcut()) {
993 $content.=$this->doc->makeShortcutIcon('returnUrl,edit,defVals,overrideVals,columnsOnly,returnNewPageId,editRegularContentFromId,disHelp,noView',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name'],1);
994 }
995
996 // Open in new window:
997 $aOnClick = 'vHWin=window.open(\''.t3lib_div::linkThisScript(array('returnUrl'=>'close.html')).'\',\''.md5($this->R_URI).'\',\''.($BE_USER->uc['edit_wideDocument']?'width=670,height=500':'width=600,height=400').',status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
998 $content.='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
999 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/open_in_new_window.gif','width="19" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.openInNewWindow',1).'" alt="" />'.
1000 '</a>';
1001 }
1002 return '
1003
1004 <!--
1005 Shortcut link:
1006 -->
1007 '.$content;
1008 }
1009
1010 /**
1011 * Reads comment messages from TCEforms and prints them in a HTML comment in the buttom of the page.
1012 *
1013 * @return void
1014 */
1015 function tceformMessages() {
1016 if (count($this->tceforms->commentMessages)) {
1017 $this->content.='
1018
1019 <!-- TCEFORM messages
1020 '.htmlspecialchars(implode(chr(10),$this->tceforms->commentMessages)).'
1021 -->
1022
1023 ';
1024 }
1025 }
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042 /***************************
1043 *
1044 * Other functions
1045 *
1046 ***************************/
1047
1048 /**
1049 * Fix $this->editconf if versioning applies to any of the records
1050 *
1051 * @param array Mapping between old and new ids if auto-versioning has been performed.
1052 * @return void
1053 */
1054 function fixWSversioningInEditConf($mapArray=FALSE) {
1055 global $TCA,$BE_USER;
1056
1057 // Traverse the editConf array
1058 if (is_array($this->editconf)) {
1059 foreach($this->editconf as $table => $conf) { // Tables:
1060 if (is_array($conf) && $TCA[$table]) {
1061
1062 // Traverse the keys/comments of each table (keys can be a commalist of uids)
1063 $newConf = array();
1064 foreach($conf as $cKey => $cmd) {
1065 if ($cmd=='edit') {
1066 // Traverse the ids:
1067 $ids = t3lib_div::trimExplode(',', $cKey, 1);
1068 foreach($ids as $idKey => $theUid) {
1069 if (is_array($mapArray)) {
1070 if ($mapArray[$table][$theUid]) {
1071 $ids[$idKey] = $mapArray[$table][$theUid];
1072 }
1073 } else { // Default, look for versions in workspace for record:
1074 $calcPRec = $this->getRecordForEdit($table,$theUid);
1075 if (is_array($calcPRec)) {
1076 // Setting UID again if it had changed, eg. due to workspace versioning.
1077 $ids[$idKey] = $calcPRec['uid'];
1078 }
1079 }
1080 #else unset($ids[$idKey]);
1081 }
1082
1083 // Add the possibly manipulated IDs to the new-build newConf array:
1084 $newConf[implode(',',$ids)] = $cmd;
1085 } else {
1086 $newConf[$cKey] = $cmd;
1087 }
1088 }
1089 // Store the new conf array:
1090 $this->editconf[$table] = $newConf;
1091 }
1092 }
1093 }
1094 }
1095
1096 /**
1097 * Get record for editing.
1098 *
1099 * @param string Table name
1100 * @param integer Record UID
1101 * @return array Returns record to edit, false if none
1102 */
1103 function getRecordForEdit($table,$theUid) {
1104 global $TCA;
1105
1106 // Fetch requested record:
1107 $reqRecord = t3lib_BEfunc::getRecord($table,$theUid,'uid,pid');
1108
1109 if (is_array($reqRecord)) {
1110 // If workspace is OFFLINE:
1111 if ($GLOBALS['BE_USER']->workspace!=0) {
1112
1113 // Check for versioning support of the table:
1114 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) {
1115
1116 // If the record is already a version of "something" pass it by.
1117 if ($reqRecord['pid']==-1) {
1118
1119 // (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)
1120 return $reqRecord;
1121 } else { // The input record was online and an offline version must be found or made:
1122
1123 // Look for version of this workspace:
1124 $versionRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $reqRecord['uid'],'uid,pid,t3ver_oid');
1125 return is_array($versionRec) ? $versionRec : $reqRecord;
1126 }
1127 } else return FALSE; // This means that editing cannot occur on this record because it was not supporting versioning which is required inside an offline workspace.
1128 } else return $reqRecord; // In ONLINE workspace, just return the originally requested record:
1129 } else return FALSE; // Return false because the table/uid was not found anyway.
1130 }
1131
1132 /**
1133 * 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
1134 *
1135 * @return void
1136 */
1137 function editRegularContentFromId() {
1138 if (t3lib_extMgm::isLoaded('cms')) {
1139 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1140 'uid',
1141 'tt_content',
1142 'pid='.intval($this->editRegularContentFromId).
1143 t3lib_BEfunc::deleteClause('tt_content').
1144 t3lib_BEfunc::versioningPlaceholderClause('tt_content').
1145 ' AND colPos=0 AND sys_language_uid=0',
1146 '',
1147 'sorting'
1148 );
1149 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
1150 $ecUids=array();
1151 while($ecRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1152 $ecUids[]=$ecRec['uid'];
1153 }
1154 $this->editconf['tt_content'][implode(',',$ecUids)]='edit';
1155 }
1156 }
1157 }
1158
1159 /**
1160 * Populates the variables $this->storeArray, $this->storeUrl, $this->storeUrlMd5
1161 *
1162 * @return void
1163 * @see makeDocSel()
1164 */
1165 function compileStoreDat() {
1166 $this->storeArray = t3lib_div::compileSelectedGetVarsFromArray('edit,defVals,overrideVals,columnsOnly,disHelp,noView,editRegularContentFromId',$this->R_URL_getvars);
1167 $this->storeUrl = t3lib_div::implodeArrayForUrl('',$this->storeArray);
1168 $this->storeUrlMd5 = md5($this->storeUrl);
1169 }
1170
1171 /**
1172 * Function used to look for configuration of buttons in the form: Fx. disabling buttons or showing them at various positions.
1173 *
1174 * @param string The table for which the configuration may be specific
1175 * @param string The option for look for. Default is checking if the saveDocNew button should be displayed.
1176 * @return string Return value fetched from USER TSconfig
1177 */
1178 function getNewIconMode($table,$key='saveDocNew') {
1179 global $BE_USER;
1180 $TSconfig = $BE_USER->getTSConfig('options.'.$key);
1181 $output = trim(isset($TSconfig['properties'][$table]) ? $TSconfig['properties'][$table] : $TSconfig['value']);
1182 return $output;
1183 }
1184
1185 /**
1186 * Handling the closing of a document
1187 *
1188 * @param integer 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
1189 * @return void
1190 */
1191 function closeDocument($code=0) {
1192 global $BE_USER;
1193
1194 // If current document is found in docHandler, then unset it, possibly unset it ALL and finally, write it to the session data:
1195 if (isset($this->docHandler[$this->storeUrlMd5])) {
1196 unset($this->docHandler[$this->storeUrlMd5]);
1197 if ($code=='3') $this->docHandler=array();
1198 $BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->docDat[1]));
1199 }
1200
1201 // 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...)
1202 if ($this->returnEditConf && $this->retUrl!='dummy.php') {
1203 $this->retUrl.='&returnEditConf='.rawurlencode(serialize($this->editconf));
1204 }
1205
1206 // If code is NOT set OR set to 1, then make a header location redirect to $this->retUrl
1207 if (!$code || $code==1) {
1208 Header('Location: '.t3lib_div::locationHeaderUrl($this->retUrl));
1209 exit;
1210 } else {
1211 $this->setDocument('',$this->retUrl);
1212 }
1213 }
1214
1215 /**
1216 * Redirects to the document pointed to by $currentDocFromHandlerMD5 OR $retUrl (depending on some internal calculations).
1217 * Most likely you will get a header-location redirect from this function.
1218 *
1219 * @param string Pointer to the document in the docHandler array
1220 * @param string Alternative/Default retUrl
1221 * @return void
1222 */
1223 function setDocument($currentDocFromHandlerMD5='',$retUrl='alt_doc_nodoc.php') {
1224 if (!t3lib_extMgm::isLoaded('cms') && !strcmp($retUrl,'alt_doc_nodoc.php')) return;
1225
1226 if (!$this->modTSconfig['properties']['disableDocSelector'] && is_array($this->docHandler) && count($this->docHandler)) {
1227 if (isset($this->docHandler[$currentDocFromHandlerMD5])) {
1228 $setupArr=$this->docHandler[$currentDocFromHandlerMD5];
1229 } else {
1230 reset($this->docHandler);
1231 $setupArr=current($this->docHandler);
1232 }
1233 if ($setupArr[2]) {
1234 $sParts = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
1235 $retUrl = $sParts['path'].'?'.$setupArr[2].'&returnUrl='.rawurlencode($retUrl);
1236 }
1237 }
1238 Header('Location: '.t3lib_div::locationHeaderUrl($retUrl));
1239 exit;
1240 }
1241 }
1242
1243 // Include extension?
1244 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_doc.php']) {
1245 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_doc.php']);
1246 }
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263 // Make instance:
1264 $SOBE = t3lib_div::makeInstance('SC_alt_doc');
1265
1266 // Preprocessing, storing data if submitted to
1267 $SOBE->preInit();
1268 if ($SOBE->doProcessData()) { // Checks, if a save button has been clicked (or the doSave variable is sent)
1269 $SOBE->processData();
1270 }
1271
1272
1273 // Main:
1274 $SOBE->init();
1275 $SOBE->main();
1276 $SOBE->printContent();
1277 ?>