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