Added $Id$ keywords, cleaned up comment tags
[Packages/TYPO3.CMS.git] / typo3 / alt_doc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@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 *
30 * By sending certain parameters to this script you can bring up a form
31 * which allows the user to edit the content of one or more database records.
32 *
33 * @author Kasper Skaarhoj <kasper@typo3.com>
34 * @package TYPO3
35 * @subpackage core
36 *
37 */
38
39 require ("init.php");
40 require ("template.php");
41 include ("sysext/lang/locallang_alt_doc.php");
42 require_once (PATH_t3lib."class.t3lib_tceforms.php");
43
44 t3lib_BEfunc::lockRecords();
45 t3lib_div::setGPvars("defVals,overrideVals,columnsOnly",1);
46
47
48
49 // ***************************
50 // Script Classes
51 // ***************************
52 class SC_alt_doc {
53 var $viewId;
54 var $generalPathOfForm;
55 var $tceforms;
56 var $content;
57 var $editconf;
58 var $defVals;
59 var $overrideVals;
60 var $columnsOnly;
61 var $retUrl;
62 var $R_URL_parts;
63 var $R_URL_getvars;
64 var $storeArray;
65 var $storeUrl;
66 var $storeUrlMd5;
67 var $dontStoreDocumentRef;
68 var $storeTitle;
69 var $JSrefreshCode;
70 var $docDat;
71 var $docHandler;
72 var $data;
73 var $mirror;
74 var $cacheCmd;
75 var $redirect;
76 var $R_URI;
77 var $modTSconfig;
78 var $elementsData;
79 var $errorC;
80 var $newC;
81 var $firstEl;
82 var $doc;
83
84 function preInit() {
85 global $BE_USER,$LANG,$BACK_PATH,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
86
87 $this->editconf = t3lib_div::GPvar("edit");
88
89 $this->defVals=$GLOBALS["defVals"];
90 $this->overrideVals=$GLOBALS["overrideVals"];
91 $this->columnsOnly=$GLOBALS["columnsOnly"];
92
93 if (!is_array($this->defVals) && is_array($this->overrideVals)) {
94 $this->defVals = $this->overrideVals; // Setting override values as default if defVals does not exist.
95 }
96 $this->retUrl = t3lib_div::GPvar("returnUrl")?t3lib_div::GPvar("returnUrl"):"dummy.php";
97
98 // Make R_URL (request url)
99 $this->R_URL_parts = parse_url(t3lib_div::getIndpEnv("REQUEST_URI"));
100 $this->R_URL_getvars = $HTTP_GET_VARS;
101
102
103 // MAKE url for storing
104 $this->compileStoreDat();
105
106 $this->dontStoreDocumentRef=0;
107 $this->storeTitle="";
108 $this->JSrefreshCode="";
109
110 $this->docDat = $BE_USER->getModuleData("alt_doc.php","ses");
111 $this->docHandler = $this->docDat[0];
112
113 if (t3lib_div::GPvar("closeDoc")>0) {
114 $this->closeDocument(t3lib_div::GPvar("closeDoc"));
115 }
116 // If NO vars are send to the script, try to read first document:
117 if (is_array($HTTP_GET_VARS) && count($HTTP_GET_VARS)<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...
118 $this->setDocument($this->docDat[1]);
119 }
120 }
121 function doProcessData() {
122 global $HTTP_POST_VARS;
123 #debug(array($HTTP_POST_VARS,$GLOBALS["HTTP_GET_VARS"]));
124 /* debug(array(
125 "_savedok_x" => isset($HTTP_POST_VARS["_savedok_x"]),
126 "_saveandclosedok_x" => isset($HTTP_POST_VARS["_saveandclosedok_x"]),
127 "_savedokview_x" => isset($HTTP_POST_VARS["_savedokview_x"]),
128 "_savedoknew_x" => isset($HTTP_POST_VARS["_savedoknew_x"]),
129 "doSave" => t3lib_div::GPvar("doSave"),
130 ));
131 */
132
133 $out = t3lib_div::GPvar("doSave") || isset($HTTP_POST_VARS["_savedok_x"]) || isset($HTTP_POST_VARS["_saveandclosedok_x"]) || isset($HTTP_POST_VARS["_savedokview_x"]) || isset($HTTP_POST_VARS["_savedoknew_x"]);
134 return $out;
135 }
136 function processData() {
137 global $BE_USER,$LANG,$BACK_PATH,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
138 t3lib_div::setGPvars("data,mirror,cacheCmd,redirect");
139
140 $this->data=$GLOBALS["data"];
141 $this->mirror=$GLOBALS["mirror"];
142 $this->cacheCmd=$GLOBALS["cacheCmd"];
143 $this->redirect=$GLOBALS["redirect"];
144
145
146 // See tce_db.php for relevate options here:
147 // Only options related to $this->data submission are included here.
148 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
149
150 if ($BE_USER->uc["neverHideAtCopy"]) {
151 $tce->neverHideAtCopy = 1;
152 }
153
154 $TCAdefaultOverride = $BE_USER->getTSConfigProp("TCAdefaults");
155 if (is_array($TCAdefaultOverride)) {
156 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
157 }
158
159 $tce->debug=0;
160 $tce->disableRTE=t3lib_div::GPvar("_disableRTE");
161 $tce->start($this->data,array());
162 if (is_array($this->mirror)) {$tce->setMirror($this->mirror);}
163
164 if (isset($this->data["pages"])) {
165 t3lib_BEfunc::getSetUpdateSignal("updatePageTree");
166 }
167
168 // ***************************
169 // Checking referer / executing
170 // ***************************
171 $refInfo=parse_url(t3lib_div::getIndpEnv("HTTP_REFERER"));
172 $httpHost = t3lib_div::getIndpEnv("TYPO3_HOST_ONLY");
173 if ($httpHost!=$refInfo["host"] && t3lib_div::GPvar("vC")!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS["SYS"]["doNotCheckReferer"]) {
174 $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));
175 debug("Error: Referer host did not match with server host.");
176 } else {
177 $tce->process_uploads($GLOBALS["HTTP_POST_FILES"]);
178 $tce->process_datamap();
179
180 // If there was saved any new items, load them:
181 if (count($tce->substNEWwithIDs_table)) {
182 $this->editconf = array();
183 reset($tce->substNEWwithIDs_table);
184 while(list($nKey,$nTable)=each($tce->substNEWwithIDs_table)) {
185 $this->editconf[$nTable][$tce->substNEWwithIDs[$nKey]]="edit";
186 if ($nTable=="pages" && $this->retUrl!="dummy.php" && t3lib_div::GPvar("returnNewPageId")) {
187 $this->retUrl.="&id=".$tce->substNEWwithIDs[$nKey];
188 }
189 }
190 $this->R_URL_getvars["edit"]=$this->editconf;
191 $HTTP_GET_VARS["edit"]=$this->editconf;
192 unset($HTTP_GET_VARS["defVals"]);
193 $this->compileStoreDat();
194 }
195 if (isset($HTTP_POST_VARS["_savedoknew_x"]) && is_array($this->editconf)) {
196
197 reset($this->editconf);
198 $nTable=key($this->editconf);
199 reset($this->editconf[$nTable]);
200 $nUid=key($this->editconf[$nTable]);
201 $nRec = t3lib_BEfunc::getRecord($nTable,$nUid,"pid,uid");
202
203 $this->editconf=array();
204 if ($this->getNewIconMode($nTable)=="top") {
205 $this->editconf[$nTable][$nRec["pid"]]="new";
206 } else {
207 $this->editconf[$nTable][-$nRec["uid"]]="new";
208 }
209 }
210
211 if($tce->debug) {
212 echo "<b>GET-vars:<br></b>";
213 t3lib_div::print_array($HTTP_GET_VARS);
214
215 echo "<BR><b>POST-vars:<br></b>";
216 t3lib_div::print_array($HTTP_POST_VARS);
217
218 echo "<BR><b>Cookies:</b><br>";
219 t3lib_div::print_array($GLOBALS["HTTP_COOKIE_VARS"]);
220 }
221
222 $tce->printLogErrorMessages(
223 isset($HTTP_POST_VARS["_saveandclosedok_x"]) ?
224 $this->retUrl :
225 $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?
226 );
227 }
228 if (isset($HTTP_POST_VARS["_saveandclosedok_x"]) || t3lib_div::GPvar("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!
229 $this->closeDocument(abs(t3lib_div::GPvar("closeDoc")));
230 }
231 }
232
233
234 function init() {
235 global $BE_USER,$LANG,$BACK_PATH,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
236
237 $this->R_URL_getvars["returnUrl"]=$this->retUrl;
238 $this->R_URI = $this->R_URL_parts["path"]."?".t3lib_div::implodeArrayForUrl("",$this->R_URL_getvars);
239
240 // MENU-ITEMS:
241 // If array, then it's a selector box menu
242 // If empty string it's just a variable, that'll be saved.
243 // Values NOT in this array will not be saved in the settings-array for the module.
244 $this->MOD_MENU = array(
245 "showPalettes" => "",
246 "showDescriptions" => "",
247 "disableRTE" => ""
248 );
249
250 $this->MCONF["name"]="xMOD_alt_doc.php";
251
252 // CLEANSE SETTINGS
253 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::GPvar("SET"), $this->MCONF["name"]);
254
255
256 // ***************************
257 // Main:
258 // ***************************
259 $this->doc = t3lib_div::makeInstance("bigDoc");
260 $this->doc->bodyTagMargins["x"]=5;
261 $this->doc->bodyTagMargins["y"]=5;
262 $this->doc->backPath = $BACK_PATH;
263 # $debugThing="alert();";
264 //$debugThing = "alert('In form: '+document.editform['data[tt_content][83][bodytext]'].value);";
265 $this->doc->form='<form action="'.$this->R_URI.'" method="post" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'" name="editform" onSubmit="'.$debugThing.'return TBE_EDITOR_checkSubmit(1);" autocomplete="off">';
266 $this->doc->JScode = '
267 <script language="javascript" type="text/javascript">
268 function jumpToUrl(URL,formEl) {
269 if (!TBE_EDITOR_isFormChanged()) {
270 document.location = URL;
271 } else if (formEl && formEl.type=="checkbox") {
272 formEl.checked = formEl.checked ? 0 : 1;
273 }
274 }
275
276 // Object: TS:
277 function typoSetup () {
278 this.uniqueID = "";
279 }
280 var TS = new typoSetup();
281
282 // Info view:
283 function launchView(table,uid,bP) {
284 var backPath= bP ? bP : "";
285 var thePreviewWindow="";
286 thePreviewWindow = window.open(backPath+"show_item.php?table="+escape(table)+"&uid="+escape(uid),"ShowItem"+TS.uniqueID,"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
287 if (thePreviewWindow && thePreviewWindow.focus) {
288 thePreviewWindow.focus();
289 }
290 }
291
292 function deleteRecord(table,id,url) {
293 if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL("deleteWarning")).')) {
294 document.location = "tce_db.php?cmd["+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC='.$BE_USER->veriCode().'&prErr=1&uPT=1";
295 }
296 return false;
297 }
298
299 '.(isset($HTTP_POST_VARS["_savedokview_x"])&&t3lib_div::GPVar("popViewId") ? t3lib_BEfunc::viewOnClick(t3lib_div::GPVar("popViewId"),"",t3lib_BEfunc::BEgetRootLine(t3lib_div::GPVar("popViewId")),"",t3lib_div::GPvar("viewUrl")) : '').'
300 </script>
301 '.$this->JSrefreshCode;
302 }
303 function main() {
304 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
305
306 $this->content="";
307 $this->content.=$this->doc->startPage("TYPO3 Edit Document");
308
309
310 // Begin edit:
311 if (is_array($this->editconf)) {
312 $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
313 $this->tceforms->initDefaultBEMode();
314 $this->tceforms->doSaveFieldName='doSave';
315 $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
316 $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
317
318 if ($BE_USER->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions']) $this->tceforms->edit_showFieldHelp='text';
319
320 if (t3lib_div::GPvar('editRegularContentFromId')) {
321 $this->editRegularContentFromId();
322 }
323
324
325 $editForm = $this->makeEditForm();
326 if ($editForm) {
327 reset($this->elementsData);
328 $this->firstEl = current($this->elementsData);
329
330 if ($this->viewId) {
331 // Module configuration:
332 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->viewId,"mod.xMOD_alt_doc");
333 } else $this->modTSconfig=array();
334
335 $panel = $this->makeButtonPanel();
336 $docSel = $this->makeDocSel();
337 $cMenu = $this->makeCmenu();
338
339 $formContent = $this->compileForm($panel,$docSel,$cMenu,$editForm);
340
341 $this->content.=$this->tceforms->printNeededJSFunctions_top().$formContent.$this->tceforms->printNeededJSFunctions();
342 $this->content.=$this->functionMenus();
343 $this->content.=$this->shortCutLink();
344
345 $this->tceformMessages();
346 }
347 }
348 }
349 function printContent() {
350 global $SOBE;
351
352 //debug(array($this->content));
353 echo $this->content.$this->doc->endPage();
354 }
355 function editRegularContentFromId() {
356 if (t3lib_extMgm::isLoaded("cms")) {
357 $query="SELECT uid FROM tt_content WHERE pid=".intval(t3lib_div::GPvar("editRegularContentFromId")).
358 t3lib_BEfunc::deleteClause("tt_content").
359 " AND colPos=0 AND sys_language_uid=0".
360 " ORDER BY sorting";
361 $res = mysql(TYPO3_db,$query);
362 if (mysql_num_rows($res)) {
363 $ecUids=array();
364 while($ecRec=mysql_fetch_assoc($res)) {
365 $ecUids[]=$ecRec["uid"];
366 }
367 $this->editconf["tt_content"][implode(",",$ecUids)]="edit";
368 }
369 }
370 }
371 function makeEditForm() {
372 global $BE_USER,$LANG,$BACK_PATH,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
373
374 $this->elementsData=array();
375 $this->errorC=0;
376 $this->newC=0;
377 $thePrevUid="";
378 $editForm="";
379
380 reset($this->editconf);
381 while(list($table,$conf)=each($this->editconf)) {
382 if (is_array($conf) && $TCA[$table] && $BE_USER->check("tables_modify",$table)) {
383 reset($conf);
384 while(list($cKey,$cmd)=each($conf)) {
385 if ($cmd=="edit" || $cmd=="new") {
386 $ids = t3lib_div::trimExplode(",",$cKey,1);
387 reset($ids);
388 while(list(,$theUid)=each($ids)) {
389 // 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...)
390 $hasAccess = 1;
391 $deleteAccess=0;
392 $this->viewId=0;
393 if ($cmd=="new") { //
394 if (intval($theUid)) {
395 if ($theUid<0) { // Less than zero - find parent page
396 $calcPRec=t3lib_BEfunc::getRecord($table,abs($theUid));
397 $calcPRec=t3lib_BEfunc::getRecord("pages",$calcPRec["pid"]);
398 } else { // always a page
399 $calcPRec=t3lib_BEfunc::getRecord("pages",abs($theUid));
400 }
401 if (is_array($calcPRec)) {
402 $CALC_PERMS = $BE_USER->calcPerms($calcPRec); // Permissions for the parent page
403 if ($table=="pages") { // If pages:
404 $hasAccess = $CALC_PERMS&8 ? 1 : 0;
405 $this->viewId = $calcPRec["pid"];
406 } else {
407 $hasAccess = $CALC_PERMS&16 ? 1 : 0;
408 $this->viewId = $calcPRec["uid"];
409 }
410 }
411 }
412 $this->dontStoreDocumentRef=1;
413 } else { // Edit:
414 $calcPRec=t3lib_BEfunc::getRecord($table,$theUid);
415 if (is_array($calcPRec)) {
416 if ($table=="pages") { // If pages:
417 $CALC_PERMS = $BE_USER->calcPerms($calcPRec);
418 $hasAccess = $CALC_PERMS&2 ? 1 : 0;
419 $deleteAccess = $CALC_PERMS&4 ? 1 : 0;
420 $this->viewId = $calcPRec["uid"];
421 } else {
422 $CALC_PERMS = $BE_USER->calcPerms(t3lib_BEfunc::getRecord("pages",$calcPRec["pid"])); // Fetching pid-record first.
423 $hasAccess = $CALC_PERMS&16 ? 1 : 0;
424 $deleteAccess = $CALC_PERMS&16 ? 1 : 0;
425 $this->viewId = $calcPRec["pid"];
426 }
427 } else $hasAccess=0;
428 }
429 // debug($this->viewId);
430
431 if ($hasAccess) {
432 $prevPageID = is_object($trData)?$trData->prevPageID:"";
433 $trData = t3lib_div::makeInstance("t3lib_transferData");
434 $trData->defVals = $this->defVals;
435 $trData->lockRecords=1;
436 $trData->disableRTE = $this->MOD_SETTINGS["disableRTE"];
437 $trData->prevPageID = $prevPageID;
438 $trData->fetchRecord($table,$theUid,$cmd=="new"?"new":""); // "new"
439 reset($trData->regTableItems_data);
440 $rec = current($trData->regTableItems_data);
441 $rec["uid"] = $cmd=="new"?uniqid("NEW"):$theUid;
442 $this->elementsData[]=array(
443 "table" => $table,
444 "uid" => $rec["uid"],
445 "cmd" => $cmd,
446 "deleteAccess" => $deleteAccess
447 );
448 if ($cmd=="new") {
449 $rec["pid"] = $theUid=="prev"?$thePrevUid:$theUid;
450 }
451
452 // Now, render the form:
453
454 if (is_array($rec)) {
455 $this->generalPathOfForm = $this->tceforms->getRecordPath($table,$rec);
456
457 if (!$this->storeTitle) $this->storeTitle=t3lib_div::GPvar("recTitle")?t3lib_div::GPvar("recTitle"):t3lib_BEfunc::getRecordTitle($table,$rec,1);
458 $panel="";
459 // debug($rec);
460 $this->tceforms->hiddenFieldList = "";
461 $this->tceforms->globalShowHelp = t3lib_div::GPvar("disHelp")?0:1;
462 if (is_array($this->overrideVals[$table])) {
463 $this->tceforms->hiddenFieldListArr=array_keys($this->overrideVals[$table]);
464 }
465 if ($this->columnsOnly) {
466 $panel.=$this->tceforms->getListedFields($table,$rec,$this->columnsOnly);
467 } else {
468 $panel.=$this->tceforms->getMainFields($table,$rec);
469 }
470 $panel=$this->tceforms->wrapTotal($panel,$rec,$table);
471 // debug($this->tceforms->hiddenFieldAccum);
472
473 if ($cmd=="new") {
474 $panel.='<input type="hidden" name="data['.$table.']['.$rec["uid"].'][pid]" value="'.$rec["pid"].'">';
475 $this->newC++;
476 }
477
478 if ($lockInfo=t3lib_BEfunc::isRecordLocked($table,$rec["uid"])) {
479 $lockIcon='<BR><table align="center" border=0 cellpadding=4 cellspacing=0 bgcolor="yellow" style="border:solid 2px black;"><tr><td>
480 <img src="gfx/recordlock_warning3.gif" width="17" height="12" vspace=2 hspace=10 border="0" align=top></td><td><strong>'.htmlspecialchars($lockInfo["msg"]).'</strong>
481 </td></tr></table><BR><BR>
482 ';
483 } else $lockIcon="";
484
485 $editForm.=$lockIcon.$panel;
486 }
487
488 // debug(($theUid=="prev"?$thePrevUid:$theUid));
489 // debug($theUid);
490 // debug($thePrevUid,1);
491 $thePrevUid = $rec["uid"];
492 // debug($thePrevUid);
493 } else {
494 $this->errorC++;
495 $editForm.=$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.noEditPermission")."<BR><BR>";
496 }
497 }
498 }
499 }
500 }
501 }
502 return $editForm;
503 }
504 function makeButtonPanel() {
505 global $TCA,$LANG;
506 $panel="";
507 if (!$this->errorC && !$TCA[$this->firstEl["table"]]["ctrl"]["readOnly"]) {
508 // if (!$this->newC) ...
509 $panel.= '<input type="image" border=0 name="_savedok" src="gfx/savedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.saveDoc",1)).'>';
510 if ($this->viewId && !t3lib_div::GPvar("noView") && t3lib_extMgm::isLoaded("cms")) $panel.= '<input type="image" border=0 name="_savedokview" src="gfx/savedokshow.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.saveDocShow",1)).'>';
511 if (count($this->elementsData)==1 && $this->getNewIconMode($this->firstEl["table"])) $panel.= '<input type="image" border=0 name="_savedoknew" src="gfx/savedoknew.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.saveNewDoc",1)).'>';
512 $panel.= '<input type="image" border=0 name="_saveandclosedok" src="gfx/saveandclosedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc",1)).'>';
513 }
514 $panel.= '<a href="#" onClick="document.editform.closeDoc.value=1; document.editform.submit(); return false;"><img border=0 src="gfx/closedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:rm.closeDoc"),1).'></a>';
515
516 if (!$this->errorC && !$TCA[$this->firstEl["table"]]["ctrl"]["readOnly"] && count($this->elementsData)==1) {
517 if ($this->firstEl["cmd"]!="new" && t3lib_div::testInt($this->firstEl["uid"])) {
518 // Delete:
519 if ($this->firstEl["deleteAccess"] && !$TCA[$this->firstEl["table"]]["ctrl"]["readOnly"] && !$this->getNewIconMode($this->firstEl["table"],"disableDelete")) {
520 $panel.= '<a href="#" onClick="return deleteRecord(\''.$this->firstEl["table"].'\',\''.$this->firstEl["uid"].'\',unescape(\''.rawurlencode($this->retUrl).'\'));"><img border=0 src="gfx/deletedok.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib($LANG->getLL("deleteItem"),1).' align=top></a>';
521 }
522
523 // Undo:
524 $undoButton=0;
525 $undoQuery="SELECT tstamp FROM sys_history WHERE tablename='".$this->firstEl["table"]."' AND recuid='".$this->firstEl["uid"]."' ORDER BY tstamp DESC LIMIT 1";
526 $undoRes = mysql(TYPO3_db,$undoQuery);
527 if ($undoButtonR = mysql_fetch_assoc($undoRes)) {
528 $undoButton=1;
529 }
530 if ($undoButton) {
531 $panel.= '<a href="#" onClick="document.location=\'show_rechis.php?element='.rawurlencode($this->firstEl["table"].':'.$this->firstEl["uid"]).'&revert=ALL_FIELDS&sumUp=-1&returnUrl='.rawurlencode($this->R_URI).'\'; return false;"><img border=0 src="gfx/undo.gif" hspace=2 width="21" height="16"'.t3lib_BEfunc::titleAttrib(htmlspecialchars(sprintf($LANG->getLL("undoLastChange"),t3lib_BEfunc::calcAge(time()-$undoButtonR["tstamp"],$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears"))))).' align=top></a>';
532 }
533 if ($this->getNewIconMode($this->firstEl["table"],"showHistory")) {
534 $panel.= '<a href="#" onClick="document.location=\'show_rechis.php?element='.rawurlencode($this->firstEl["table"].':'.$this->firstEl["uid"]).'&returnUrl='.rawurlencode($this->R_URI).'\'; return false;"><img border=0 src="gfx/history2.gif" hspace=2 vspace=2 width="13" height="12"'.t3lib_BEfunc::titleAttrib("").' align=top></a>';
535 }
536
537 // columnsOnly to all:
538 if ($this->columnsOnly) {
539 $panel.= '<a href="'.$this->R_URI.'&columnsOnly="><img src="gfx/edit2.gif" width="11" height="12" hspace=5 border="0"'.t3lib_BEfunc::titleAttrib(htmlspecialchars($LANG->getLL("editWholeRecord"))).'></a>';
540 }
541 }
542 }
543 return $panel;
544 }
545 function makeDocSel() {
546 global $BE_USER,$LANG;
547 // DOC-handler
548 if (!$this->modTSconfig["properties"]["disableDocSelector"]) {
549 if ((strcmp($this->docDat[1],$this->storeUrlMd5)||!isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef) {
550 //debug("stored");
551 //debug($this->storeUrl);
552 $this->docHandler[$this->storeUrlMd5]=array($this->storeTitle,$this->storeArray,$this->storeUrl);
553 $BE_USER->pushModuleData("alt_doc.php",array($this->docHandler,$this->storeUrlMd5));
554 }
555 $docSel="";
556 if (is_array($this->docHandler)) {
557 reset($this->docHandler);
558 $opt=array();
559 $opt[]='<option>[ '.$LANG->getLL("openDocs").': ]</option>';
560 while(list($md5k,$setupArr)=each($this->docHandler)) {
561 $opt[]='<option value="alt_doc.php?'.htmlspecialchars($setupArr[2]."&returnUrl=".rawurlencode($this->retUrl)).'"'.(!strcmp($md5k,$this->storeUrlMd5)?" SELECTED":"").'>'.$setupArr[0].'</option>';
562 }
563 $docSel='<select name="_docSelector" onChange="if(this.options[this.selectedIndex].value && !TBE_EDITOR_isFormChanged()){document.location=(this.options[this.selectedIndex].value);}">'.implode("",$opt).'</select>';
564 }
565 } else $docSel="";
566 return $docSel;
567 }
568 function makeCmenu() {
569 global $SOBE;
570
571 if (!$this->modTSconfig["properties"]["disableCacheSelector"]) { //$this->viewId &&
572 $cMenu = $this->doc->clearCacheMenu(intval($this->viewId),!$this->modTSconfig["properties"]["disableDocSelector"]);
573 } else $cMenu ="";
574 return $cMenu;
575 }
576 function compileForm($panel,$docSel,$cMenu,$editForm) {
577 global $LANG;
578
579 $formContent="";
580 $formContent.='<table border=0 cellpadding=0 cellspacing=1 width=470>
581 <tr><td nowrap valign=top>'.$panel.'</td><td nowrap valign=top align=right>'.$docSel.$cMenu.'</td></tr>
582 <tr><td colspan=2>'.$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.path").': '.htmlspecialchars($this->generalPathOfForm).'</td></tr>
583 </table><img src=clear.gif width=1 height=4><BR>'.
584 $editForm.
585 $panel.
586 '<input type="hidden" name="returnUrl" value="'.htmlspecialchars($this->retUrl).'">
587 <input type="hidden" name="viewUrl" value="'.htmlspecialchars(t3lib_div::GPvar("viewUrl")).'">';
588
589 if (t3lib_div::GPvar("returnNewPageId")) {
590 $formContent.='<input type="hidden" name="returnNewPageId" value="1">';
591 }
592 $formContent.='<input type="hidden" name="popViewId" value="'.$this->viewId.'">';
593 $formContent.='<input type="hidden" name="closeDoc" value="0">';
594 $formContent.='<input type="hidden" name="doSave" value="0">';
595 $formContent.='<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'">';
596 $formContent.='<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'">';
597
598 return $formContent;
599 }
600 function compileStoreDat() {
601 global $HTTP_GET_VARS;
602 $this->storeArray = t3lib_div::compileSelectedGetVarsFromArray("edit,defVals,overrideVals,columnsOnly,disHelp,noView,editRegularContentFromId",$HTTP_GET_VARS);
603 $this->storeUrl = t3lib_div::implodeArrayForUrl("",$this->storeArray);
604 $this->storeUrlMd5 = md5($this->storeUrl);
605 }
606 function functionMenus() {
607 global $BE_USER,$LANG;
608
609 // show palettes
610 $funcMenus = "";
611 $funcMenus.= "<BR><BR>".t3lib_BEfunc::getFuncCheck("","SET[showPalettes]",$this->MOD_SETTINGS["showPalettes"],"alt_doc.php",t3lib_div::implodeArrayForUrl("",array_merge($this->R_URL_getvars,array("SET"=>"")))).$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.showPalettes"); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
612
613 if ($BE_USER->uc["edit_showFieldHelp"]!="text") $funcMenus.= "<BR>".t3lib_BEfunc::getFuncCheck("","SET[showDescriptions]",$this->MOD_SETTINGS["showDescriptions"],"alt_doc.php",t3lib_div::implodeArrayForUrl("",array_merge($this->R_URL_getvars,array("SET"=>"")))).$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.showDescriptions"); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
614 if ($BE_USER->isRTE()) $funcMenus.= "<BR>".t3lib_BEfunc::getFuncCheck("","SET[disableRTE]",$this->MOD_SETTINGS["disableRTE"],"alt_doc.php",t3lib_div::implodeArrayForUrl("",array_merge($this->R_URL_getvars,array("SET"=>"")))).$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.disableRTE");
615 return $funcMenus;
616 }
617 function shortCutLink() {
618 global $SOBE,$BE_USER,$LANG;
619 // ShortCut
620 if (t3lib_div::GPvar("returnUrl")!="close.html") {
621 $content.="<BR><BR>";
622 if ($BE_USER->mayMakeShortcut()) {
623 $content.=$this->doc->makeShortcutIcon("returnUrl,edit,defVals,overrideVals,columnsOnly,popViewId,returnNewPageId,editRegularContentFromId,disHelp,noView",implode(",",array_keys($this->MOD_MENU)),$this->MCONF["name"],1);
624 }
625 $content.='<a href="#" onClick="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;"><img src="gfx/open_in_new_window.gif" width="19" height="14" hspace=4 border="0"'.t3lib_BEfunc::titleAttrib($LANG->sL("LLL:EXT:lang/locallang_core.php:labels.openInNewWindow")).'></a>';
626 }
627 return $content;
628 }
629 function tceformMessages() {
630 if (count($this->tceforms->commentMessages)) {
631 $this->content.='
632
633 <!-- TCEFORM messages
634 '.implode(chr(10),$this->tceforms->commentMessages).'
635 -->
636
637 ';
638 }
639 }
640
641
642 // ***************************
643 // OTHER FUNCTIONS:
644 // ***************************
645 function getNewIconMode($table,$key="saveDocNew") {
646 global $BE_USER;
647 $TSconfig = $BE_USER->getTSConfig("options.".$key);
648 $output = trim(isset($TSconfig["properties"][$table]) ? $TSconfig["properties"][$table] : $TSconfig["value"]);
649 return $output;
650 }
651 function closeDocument($code=0) {
652 global $BE_USER;
653 if (isset($this->docHandler[$this->storeUrlMd5])) {
654 unset($this->docHandler[$this->storeUrlMd5]);
655 if ($code=="3") $this->docHandler=array();
656 $BE_USER->pushModuleData("alt_doc.php",array($this->docHandler,$this->docDat[1]));
657 }
658
659 if (t3lib_div::GPvar("returnEditConf") && $this->retUrl!="dummy.php") {
660 $this->retUrl.="&returnEditConf=".rawurlencode(serialize($this->editconf));
661 }
662
663 if (!$code || $code==1) {
664 Header("Location: ".t3lib_div::locationHeaderUrl($this->retUrl));
665 exit;
666 } else {
667 $this->setDocument("",$this->retUrl);
668 }
669 }
670 function setDocument($currentDocFromHandlerMD5="",$retUrl="alt_doc_nodoc.php") {
671 if (!t3lib_extMgm::isLoaded("cms") && !strcmp($retUrl,"alt_doc_nodoc.php")) return;
672
673 if (!$this->modTSconfig["properties"]["disableDocSelector"] && is_array($this->docHandler) && count($this->docHandler)) {
674 if (isset($this->docHandler[$currentDocFromHandlerMD5])) {
675 $setupArr=$this->docHandler[$currentDocFromHandlerMD5];
676 } else {
677 reset($this->docHandler);
678 $setupArr=current($this->docHandler);
679 }
680 if ($setupArr[2]) {
681 $sParts = parse_url(t3lib_div::getIndpEnv("REQUEST_URI"));
682 $retUrl = $sParts["path"].'?'.$setupArr[2]."&returnUrl=".rawurlencode($retUrl);
683 }
684 }
685 Header("Location: ".t3lib_div::locationHeaderUrl($retUrl));
686 exit;
687 }
688 }
689
690 // Include extension?
691 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/alt_doc.php"]) {
692 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/alt_doc.php"]);
693 }
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710 // Make instance:
711 $SOBE = t3lib_div::makeInstance("SC_alt_doc");
712
713 // Preprocessing, storing data if submitted to
714 $SOBE->preInit();
715 if ($SOBE->doProcessData()) {
716 require_once (PATH_t3lib."class.t3lib_tcemain.php");
717 $SOBE->processData();
718 } else {
719 require_once (PATH_t3lib."class.t3lib_loaddbgroup.php");
720 $BACK_PATH="";
721 }
722 require_once (PATH_t3lib."class.t3lib_transferdata.php");
723
724
725 // Main:
726 $SOBE->init();
727 $SOBE->main();
728 $SOBE->printContent();
729 ?>