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