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