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