Fixed bug #7896: Hide the page browser if not enough entries are available (Thanks...
[Packages/TYPO3.CMS.git] / typo3 / alt_doc.php
old mode 100755 (executable)
new mode 100644 (file)
index feb08e7..4541eae
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 require('init.php');
 require('template.php');
 $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
-require_once (PATH_t3lib.'class.t3lib_tceforms.php');
-require_once (PATH_t3lib.'class.t3lib_clipboard.php');
-
-require_once (PATH_t3lib.'class.t3lib_tcemain.php');
-require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
-require_once (PATH_t3lib.'class.t3lib_transferdata.php');
-
 
 t3lib_BEfunc::lockRecords();
 
@@ -120,7 +113,7 @@ class SC_alt_doc {
        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.
        var $vC;                                // GPvar (for processing only) : Verification code, internal stuff.
        var $uc;                                // GPvar : update BE_USER->uc
-       
+
        var $popViewId;                 // GPvar (module) : ID for displaying the page in the frontend (used for SAVE/VIEW operations)
        var $popViewId_addParams;       // GPvar (module) : Additional GET vars for the link, eg. "&L=xxx"
        var $viewUrl;                   // GPvar (module) : Alternative URL for viewing the frontend pages.
@@ -139,6 +132,7 @@ class SC_alt_doc {
         * @var mediumDoc
         */
        var $doc;
+       var $template;                  // a static HTML template, usually in templates/alt_doc.html
        var $content;                   // Content accumulation
 
        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.
@@ -252,7 +246,7 @@ class SC_alt_doc {
         * @return      boolean         True, then save the document (data submitted)
         */
        function doProcessData()        {
-               $out = $this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']);
+               $out = $this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']) || isset($_POST['_translation_savedok_x']) || isset($_POST['_translation_savedokclear_x']);
                return $out;
        }
 
@@ -279,6 +273,14 @@ class SC_alt_doc {
                $tce = t3lib_div::makeInstance('t3lib_TCEmain');
                $tce->stripslashes_values=0;
 
+               if (isset($_POST['_translation_savedok_x']))    {
+                       $tce->updateModeL10NdiffData = 'FORCE_FFUPD';
+               }
+               if (isset($_POST['_translation_savedokclear_x']))       {
+                       $tce->updateModeL10NdiffData = 'FORCE_FFUPD';
+                       $tce->updateModeL10NdiffDataClear = TRUE;
+               }
+
                        // Setting default values specific for the user:
                $TCAdefaultOverride = $BE_USER->getTSConfigProp('TCAdefaults');
                if (is_array($TCAdefaultOverride))      {
@@ -300,7 +302,7 @@ class SC_alt_doc {
 
                        // If pages are being edited, we set an instruction about updating the page tree after this operation.
                if (isset($this->data['pages']))        {
-                       t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
+                       t3lib_BEfunc::setUpdateSignal('updatePageTree');
                }
 
 
@@ -337,7 +339,7 @@ class SC_alt_doc {
                                                                }
                                                                $newEditConf[$tableName][$editId] = 'edit';
                                                        }
-       
+
                                                                // Traverse all new records and forge the content of ->editconf so we can continue to EDIT these records!
                                                        if ($tableName=='pages' && $this->retUrl!='dummy.php' && $this->returnNewPageId)        {
                                                                $this->retUrl.='&id='.$tce->substNEWwithIDs[$key];
@@ -352,7 +354,7 @@ class SC_alt_doc {
                                if (count($newEditConf)) {
                                        $this->editconf = $newEditConf;
                                }
-                               
+
                                        // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
                                $this->R_URL_getvars['edit']=$this->editconf;
 
@@ -396,12 +398,12 @@ class SC_alt_doc {
                        }
 
                        $tce->printLogErrorMessages(
-                               isset($_POST['_saveandclosedok_x']) ?
+                               (isset($_POST['_saveandclosedok_x']) || isset($_POST['_translation_savedok_x'])) ?
                                $this->retUrl :
                                $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?
                        );
                }
-               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!
+               if ((isset($_POST['_saveandclosedok_x']) || isset($_POST['_translation_savedok_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!
                        $this->closeDocument(abs($this->closeDoc));
                }
        }
@@ -423,6 +425,8 @@ class SC_alt_doc {
                $this->disHelp = t3lib_div::_GP('disHelp');
                $this->noView = t3lib_div::_GP('noView');
 
+               $this->perms_clause = $BE_USER->getPagePermsClause(1);
+
                        // Set other internal variables:
                $this->R_URL_getvars['returnUrl']=$this->retUrl;
                $this->R_URI = $this->R_URL_parts['path'].'?'.t3lib_div::implodeArrayForUrl('',$this->R_URL_getvars);
@@ -442,15 +446,12 @@ class SC_alt_doc {
                $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
 
                        // Create an instance of the document template object
-               $this->doc = t3lib_div::makeInstance('template');
-               $this->doc->divClass = 'typo3-fullDoc';
+               $this->doc = $GLOBALS['TBE_TEMPLATE'];
                $this->doc->backPath = $BACK_PATH;
-               $this->doc->docType = 'xhtml_trans';
-               $this->doc->inDocStylesArray[] = 'html { overflow: hidden; }';
-
-               $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);">';
+               $this->doc->setModuleTemplate('templates/alt_doc.html');
+               $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);">';
 
-               $this->doc->loadJavascriptLib('contrib/prototype/prototype.js');
+               $this->doc->getPageRenderer()->loadPrototype();
                $this->doc->JScode = $this->doc->wrapScriptTags('
                        function jumpToUrl(URL,formEl)  {       //
                                if (!TBE_EDITOR.isFormChanged())        {
@@ -459,19 +460,13 @@ class SC_alt_doc {
                                        formEl.checked = formEl.checked ? 0 : 1;
                                }
                        }
-
-                               // workaround since IE6 cannot deal with relative height for scrolling elements
-                       function resizeDocBody()        {
-                               $("typo3-docbody").style.height = (document.body.offsetHeight - parseInt($("typo3-docheader").getStyle("height")));
-                       }
-                       if (/MSIE 6/.test(navigator.userAgent)) {
-                               Event.observe(window, "resize", resizeDocBody, false);
-                               Event.observe(document, "load", resizeDocBody, false);
-                       }
-
                                // Object: TS:
+                               // passwordDummy and decimalSign are used by tbe_editor.js and have to be declared here as
+                               // TS object overwrites the object declared in tbe_editor.js
                        function typoSetup      ()      {       //
                                this.uniqueID = "";
+                               this.passwordDummy = "********";
+                               this.decimalSign = ".";
                        }
                        var TS = new typoSetup();
 
@@ -514,13 +509,9 @@ class SC_alt_doc {
        function main() {
                global $BE_USER,$LANG;
 
-                       // Starting content accumulation:
-               $this->content='';
-               $this->content.=$this->doc->startPage('TYPO3 Edit Document');
-
                        // Begin edit:
                if (is_array($this->editconf))  {
-                       
+
                                // Initialize TCEforms (rendering the forms)
                        $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
                        $this->tceforms->initDefaultBEMode();
@@ -528,7 +519,7 @@ class SC_alt_doc {
                        $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : '';     // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
                        $this->tceforms->returnUrl = $this->R_URI;
                        $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
-                       $this->tceforms->disableRTE = !$BE_USER->isRTE(); 
+                       $this->tceforms->disableRTE = !$BE_USER->isRTE();
                        $this->tceforms->enableClickMenu = TRUE;
                        $this->tceforms->enableTabMenu = TRUE;
 
@@ -543,34 +534,50 @@ class SC_alt_doc {
                                $this->editRegularContentFromId();
                        }
 
+
                                // Creating the editing form, wrap it with buttons, document selector etc.
                        $editForm = $this->makeEditForm();
 
                        if ($editForm)  {
                                $this->firstEl = reset($this->elementsData);
 
+                                       // Checking if the currently open document is stored in the list of "open documents" - if not, then add it:
+                               if ((strcmp($this->docDat[1], $this->storeUrlMd5) || !isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef) {
+                                               $this->docHandler[$this->storeUrlMd5] = array($this->storeTitle, $this->storeArray, $this->storeUrl, $this->firstEl);
+                                               $BE_USER->pushModuleData('alt_doc.php', array($this->docHandler, $this->storeUrlMd5));
+                                               t3lib_BEfunc::setUpdateSignal('tx_opendocs::updateNumber', count($this->docHandler));
+                               }
+
+
                                        // Module configuration
                                $this->modTSconfig = ($this->viewId ? t3lib_BEfunc::getModTSconfig($this->viewId,'mod.xMOD_alt_doc') : array());
 
-                               $this->content .= 
-                                       $this->tceforms->printNeededJSFunctions_top().
-                                       $this->compileHeader().'
-       <div id="typo3-docbody">'.
-                                       $this->extraFormHeaders.
-                                       $this->compileForm($editForm).
-                                       $this->tceforms->printNeededJSFunctions().
-                                       $this->functionMenus().
-
-                                       // Add CSH:
-                                       t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms', $GLOBALS['BACK_PATH'],'<br/>|',FALSE,'margin-top: 20px;').
-                                       '<br /><br />'.
-                                       $this->shortCutLink().
-                                       $this->openInNewWindowLink().'
-       </div>';
-
-                               $this->tceformMessages();
+                               $body.= $this->tceforms->printNeededJSFunctions_top();
+                               $body.= $this->compileForm($editForm);
+                               $body.= $this->tceforms->printNeededJSFunctions();
+                               $body.= $this->functionMenus();
+                               $body.= $this->tceformMessages();
                        }
                }
+
+               // Access check...
+               // The page will show only if there is a valid page and if this page may be viewed by the user
+               $this->pageinfo = t3lib_BEfunc::readPageAccess($this->viewId, $this->perms_clause);
+
+                       // Setting up the buttons and markers for docheader
+               $docHeaderButtons = $this->getButtons();
+               $markers = array(
+                       'LANGSELECTOR' => $this->langSelector(),
+                       'EXTRAHEADER' => $this->extraFormHeaders(),
+                       'CSH' => $docHeaderButtons['csh'],
+                       'CONTENT' => $body
+               );
+
+                       // Build the <body> for the module
+               $this->content = $this->doc->startPage('TYPO3 Edit Document');
+               $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
+               $this->content.= $this->doc->endPage();
+               $this->content = $this->doc->insertStylesAndJS($this->content);
        }
 
 
@@ -580,8 +587,6 @@ class SC_alt_doc {
         * @return      void
         */
        function printContent() {
-               $this->content.= $this->doc->endPage();
-               $this->content = $this->doc->insertStylesAndJS($this->content);
                echo $this->content;
        }
 
@@ -663,7 +668,8 @@ class SC_alt_doc {
                                                                                $CALC_PERMS = $BE_USER->calcPerms($calcPRec);   // Permissions for the parent page
                                                                                if ($table=='pages')    {       // If pages:
                                                                                        $hasAccess = $CALC_PERMS&8 ? 1 : 0;
-                                                                                       $this->viewId = $calcPRec['pid'];
+                                                                                       #$this->viewId = $calcPRec['pid'];
+                                                                                       $this->viewId = 0;
                                                                                } else {
                                                                                        $hasAccess = $CALC_PERMS&16 ? 1 : 0;
                                                                                        $this->viewId = $calcPRec['uid'];
@@ -764,28 +770,25 @@ class SC_alt_doc {
                                                                        }
 
                                                                                // Display "is-locked" message:
-                                                                       if ($lockInfo = t3lib_BEfunc::isRecordLocked($table,$rec['uid']))       {
-                                                                               $lockIcon = '
-
-                                                                                       <!-- Warning box: -->
-                                                                                       <table border="0" cellpadding="0" cellspacing="0" class="warningbox">
-                                                                                               <tr>
-                                                                                                       <td><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/recordlock_warning3.gif','width="17" height="12"').' alt="" /></td>
-                                                                                                       <td>'.htmlspecialchars($lockInfo['msg']).'</td>
-                                                                                               </tr>
-                                                                                       </table>
-                                                                               ';
-                                                                       } else $lockIcon = '';
+                                                                       if ($lockInfo = t3lib_BEfunc::isRecordLocked($table, $rec['uid'])) {
+                                                                               $lockedMessage = t3lib_div::makeInstance(
+                                                                                       't3lib_FlashMessage',
+                                                                                       htmlspecialchars($lockInfo['msg']),
+                                                                                       '',
+                                                                                       t3lib_FlashMessage::WARNING
+                                                                               );
+                                                                               t3lib_FlashMessageQueue::addMessage($lockedMessage);
+                                                                       }
 
                                                                                // Combine it all:
-                                                                       $editForm.= $lockIcon.$panel;
+                                                                       $editForm .= $panel;
                                                                }
 
                                                                $thePrevUid = $rec['uid'];
                                                        } else {
                                                                $this->errorC++;
                                                                $editForm.=$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.noEditPermission',1).'<br /><br />'.
-                                                                                       ($deniedAccessReason ? 'Reason: '.htmlspecialchars($deniedAccessReason).'<br/><br/>' : '');
+                                                                       ($deniedAccessReason ? 'Reason: ' . htmlspecialchars($deniedAccessReason) . '<br /><br />' : '');
                                                        }
                                                }
                                        }
@@ -796,47 +799,53 @@ class SC_alt_doc {
                return $editForm;
        }
 
-
-       /**
-        * Create the panel of buttons for submitting the form or otherwise perform operations.
-        *
-        * @return      string          HTML code, comprised of images linked to various actions.
-        */
-       function makeButtonPanel()      {
-               $btns = $this->getButtons();
-               unset($btns['shortcut']);
-               return implode('', $btns);
-       }
-
-
        /**
         * Create the panel of buttons for submitting the form or otherwise perform operations.
         *
         * @return      array   all available buttons as an assoc. array
         */
-       function getButtons()   {
+       protected function getButtons() {
                global $TCA,$LANG;
-               $buttons = array();
+               $buttons = array(
+                       'save' => '',
+                       'save_view' => '',
+                       'save_new' => '',
+                       'save_close' => '',
+                       'close' => '',
+                       'delete' => '',
+                       'undo' => '',
+                       'history' => '',
+                       'columns_only' => '',
+                       'csh' => '',
+                       'translation_save' => '',
+                       'translation_saveclear' => ''
+               );
 
                        // Render SAVE type buttons:
                        // The action of each button is decided by its name attribute. (See doProcessData())
                if (!$this->errorC && !$TCA[$this->firstEl['table']]['ctrl']['readOnly'])       {
 
                                // SAVE button:
-                       $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).'" />';
+                       $buttons['save'] = '<input type="image" class="c-inputButton" name="_savedok" src="' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/savedok.gif', '', 1) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', 1) . '" />';
 
                                // SAVE / VIEW button:
-                       if ($this->viewId && !$this->noView && t3lib_extMgm::isLoaded('cms')) {
-                               $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).'" />';
+                       if ($this->viewId && !$this->noView && t3lib_extMgm::isLoaded('cms') && $this->getNewIconMode($this->firstEl['table'], 'saveDocView')) {
+                               $buttons['save_view'] = '<input type="image" class="c-inputButton" name="_savedokview" src="' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/savedokshow.gif', '', 1) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDocShow', 1) . '" />';
                        }
 
                                // SAVE / NEW button:
                        if (count($this->elementsData)==1 && $this->getNewIconMode($this->firstEl['table'])) {
-                               $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).'" />';
+                               $buttons['save_new'] = '<input type="image" class="c-inputButton" name="_savedoknew" src="' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/savedoknew.gif', '', 1) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveNewDoc', 1) . '" />';
                        }
 
                                // SAVE / CLOSE
-                       $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).'" />';
+                       $buttons['save_close'] = '<input type="image" class="c-inputButton" name="_saveandclosedok" src="' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/saveandclosedok.gif', '', 1) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', 1) . '" />';
+
+                               // FINISH TRANSLATION / SAVE / CLOSE
+                       if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'])     {
+                               $buttons['translation_save'] = '<input type="image" class="c-inputButton" name="_translation_savedok" src="' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/translationsavedok.gif', '', 1) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.translationSaveDoc', 1) . '" />';
+                               $buttons['translation_saveclear'] = '<input type="image" class="c-inputButton" name="_translation_savedokclear" src="' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/translationsavedok_clear.gif', '', 1) . '" title="' . $LANG->sL('LLL:EXT:lang/locallang_core.php:rm.translationSaveDocClear', 1) . '" />';
+                       }
                }
 
                        // CLOSE button:
@@ -862,8 +871,12 @@ class SC_alt_doc {
                                if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes))     {
                                        $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;';
                                        $buttons['undo'] = '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
-                                                       '<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="" />'.
-                                                       '</a>';
+                                               '<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($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp'], $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')))) .
+                                                       '" alt="" />' .
+                                               '</a>';
                                }
                                if ($this->getNewIconMode($this->firstEl['table'],'showHistory'))       {
                                        $aOnClick = 'window.location.href=\'show_rechis.php?element='.rawurlencode($this->firstEl['table'].':'.$this->firstEl['uid']).'&returnUrl='.rawurlencode($this->R_URI).'\'; return false;';
@@ -880,113 +893,42 @@ class SC_alt_doc {
                                }
                        }
                }
+
+                       // add the CSH icon
+               $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms', $GLOBALS['BACK_PATH'], '', TRUE);
                $buttons['shortcut'] = $this->shortCutLink();
+               $buttons['open_in_new_window'] = $this->openInNewWindowLink();
                return $buttons;
        }
 
-
        /**
-        * Create the selector box form element which allows to select between open documents.
-        * Can be disabled through Page TSconfig.
-        *
-        * @return      string          HTML <select> element  (if applicable)
+        * Returns the language switch/selector for editing,
+        * show only when a single record is edited
+        * - multiple records are too confusing
+        * @return      string          the HTML
         */
-       function makeDocSel()   {
-               global $BE_USER,$LANG;
-
-               $docSel = '';
-                       // Render the selector ONLY if it has not been disabled:
-               if (!$this->modTSconfig['properties']['disableDocSelector'])    {
-
-                               // Checking if the currently open document is stored in the list of "open documents" - if not, then add it:
-                       if ((strcmp($this->docDat[1],$this->storeUrlMd5)||!isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef)       {
-                               $this->docHandler[$this->storeUrlMd5]=array($this->storeTitle,$this->storeArray,$this->storeUrl);
-                               $BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->storeUrlMd5));
-                       }
-
-                               // Now, create the document selector box:
-                       if (is_array($this->docHandler))        {
-                               $opt = array();
-                               $opt[] = '<option value="">[ '.$LANG->getLL('openDocs',1).': ]</option>';
-
-                                       // Traverse the list of open documents:
-                               foreach($this->docHandler as $md5k => $setupArr)        {
-                                       $theValue = 'alt_doc.php?'.$setupArr[2].'&returnUrl='.rawurlencode($this->retUrl);
-                                       $opt[]='<option value="'.htmlspecialchars($theValue).'"'.(!strcmp($md5k,$this->storeUrlMd5)?' selected="selected"':'').'>'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($setupArr[0]))).'</option>';
-                               }
-
-                                       // Compile the selector box finally:
-                               $onChange = 'if(this.options[this.selectedIndex].value && !TBE_EDITOR.isFormChanged()){window.location.href=(this.options[this.selectedIndex].value);}';
-                               $docSel='<select name="_docSelector" onchange="'.htmlspecialchars($onChange).'">'.implode('',$opt).'</select>';
-
-                                       // Add CSH:
-                               $docSel.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms_docSelector', $GLOBALS['BACK_PATH'],'', TRUE);
-                       }
-               }
-               return $docSel;
-       }
-
-       /**
-        * Create the selector box form element which allows to select a clear-cache operation.
-        * Can be disabled through Page TSconfig.
-        *
-        * @return      string          HTML <select> element (if applicable)
-        * @see template::clearCacheMenu()
-        */
-       function makeCmenu()    {
-               $cMenu = '';
-
-                       // Generate the menu if NOT disabled:
-               if (!$this->modTSconfig['properties']['disableCacheSelector'])  {
-                       $cMenu = $this->doc->clearCacheMenu(intval($this->viewId),!$this->modTSconfig['properties']['disableDocSelector']);
-
-                               // Add CSH:
-                       $cMenu.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms_cacheSelector', $GLOBALS['BACK_PATH'],'', TRUE);
+       function langSelector() {
+               $langSelector = '';
+               if (count($this->elementsData) == 1) {
+                       $langSelector = $this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']);
                }
-               return $cMenu;
+               return $langSelector;
        }
 
 
        /**
-        * Put together the various elements for the header
+        * Compiles the extra form headers if the tceforms
         *
-        * @return      string          Composite HTML
+        * @return      string          the HTML
         */
-       function compileHeader()        {
-               global $LANG;
-
-               $btns = $this->getButtons();
-               $docSel = $this->makeDocSel();
-               $cMenu = $this->makeCmenu();
-
-               $content = '
-       <!-- Page header with buttons for saving & closing and path details -->
-       <div id="typo3-docheader">
-               <div id="typo3-docheader-row1">
-                       <div class="buttonsleft">'.$btns['save'].$btns['save_view'].$btns['save_close'].$btns['save_new'].'</div>
-                       <div class="buttonsright">'.$docSel.$cMenu.$btns['delete'].$btns['shortcut'].$btns['history'].$buttons['columns_only'].$btns['undo'].$btns['close'].'</div>
-               </div>
-               ';
-
-               if (is_array($this->tceforms->extraFormHeaders))        {
-                       $this->extraFormHeaders = '<div id="typo3-docheader-rowextra">'.implode(chr(10), $this->tceforms->extraFormHeaders).'</div>';
-               }
-
+       function extraFormHeaders() {
+               $extraTemplate = '';
 
-                       // language switch/selector for editing
-                       // show only when a single record is edited - multiple records are too confusing
-               if (count($this->elementsData) == 1) {
-                       $langSelector = '<div class="langselector">'.$this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']).'</div>';
+               if (is_array($this->tceforms->extraFormHeaders)) {
+                       $extraTemplate = t3lib_parsehtml::getSubpart($this->doc->moduleTemplate, '###DOCHEADER_EXTRAHEADER###');
+                       $extraTemplate = t3lib_parsehtml::substituteMarker($extraTemplate, '###EXTRAHEADER###', implode(chr(10), $this->tceforms->extraFormHeaders));
                }
-
-               
-               $content.='
-               <div id="typo3-docheader-row2">
-                       <div class="pagepath">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path',1).': '.htmlspecialchars($this->generalPathOfForm).'</div>
-                       <div class="infooptions">'.$langSelector.'</div>
-               </div>
-       </div>';
-               return $content;
+               return $extraTemplate;
        }
 
 
@@ -999,16 +941,10 @@ class SC_alt_doc {
        function compileForm($editForm) {
                global $LANG;
 
-               $panel = $this->makeButtonPanel();
-               
                $formContent = '
-
                        <!-- EDITING FORM -->
                        '.$editForm.'
 
-                       <!-- Saving buttons (same as in top) -->
-
-                       '.$panel.'
                        <input type="hidden" name="returnUrl" value="'.htmlspecialchars($this->retUrl).'" />
                        <input type="hidden" name="viewUrl" value="'.htmlspecialchars($this->viewUrl).'" />';
 
@@ -1039,7 +975,7 @@ class SC_alt_doc {
                        // Show palettes:
                return '
                                <!-- Function menus (checkboxes for selecting options): -->
-                               <br /><br />'.t3lib_BEfunc::getFuncCheck('','SET[showPalettes]',$this->MOD_SETTINGS['showPalettes'],'alt_doc.php',t3lib_div::implodeArrayForUrl('',array_merge($this->R_URL_getvars,array('SET'=>''))),'id="checkShowPalettes"').'<label for="checkShowPalettes">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPalettes',1).'</label>';
+                               <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>';
        }
 
 
@@ -1064,11 +1000,11 @@ class SC_alt_doc {
         * @return      string
         */
        function openInNewWindowLink()  {
-               global $BE_USER,$LANG;
+               global $BE_USER, $LANG;
                if ($this->returnUrl == 'close.html') {
                        return '';
                }
-               $aOnClick = 'vHWin=window.open(\''.t3lib_div::linkThisScript(array('returnUrl'=>'close.html')).'\',\''.md5($this->R_URI).'\',\''.($BE_USER->uc['edit_wideDocument']?'width=670,height=500':'width=600,height=400').',status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
+               $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;';
                return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
                                '<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>';
        }
@@ -1081,14 +1017,13 @@ class SC_alt_doc {
         */
        function tceformMessages()      {
                if (count($this->tceforms->commentMessages))    {
-                       $this->content.='
-
-<!-- TCEFORM messages
-'.htmlspecialchars(implode(chr(10),$this->tceforms->commentMessages)).'
--->
-
-';
+                       $tceformMessages = '
+                               <!-- TCEFORM messages
+                               '.htmlspecialchars(implode(chr(10),$this->tceforms->commentMessages)).'
+                               -->
+                       ';
                }
+               return $tceformMessages;
        }
 
 
@@ -1235,8 +1170,7 @@ class SC_alt_doc {
                                $returnUrl = '&returnUrl='.rawurlencode(t3lib_div::_GP('returnUrl'));
                                $location = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$params.$returnUrl;
 
-                               header('Location: '.t3lib_div::locationHeaderUrl($location));
-                               exit;
+                               t3lib_utility_Http::redirect($location);
                        }
                }
        }
@@ -1434,9 +1368,8 @@ class SC_alt_doc {
         * @param       string          The option for look for. Default is checking if the saveDocNew button should be displayed.
         * @return      string          Return value fetched from USER TSconfig
         */
-       function getNewIconMode($table,$key='saveDocNew')       {
-               global $BE_USER;
-               $TSconfig = $BE_USER->getTSConfig('options.'.$key);
+       function getNewIconMode($table, $key = 'saveDocNew') {
+               $TSconfig = $GLOBALS['BE_USER']->getTSConfig('options.'.$key);
                $output = trim(isset($TSconfig['properties'][$table]) ? $TSconfig['properties'][$table] : $TSconfig['value']);
                return $output;
        }
@@ -1450,13 +1383,33 @@ class SC_alt_doc {
        function closeDocument($code=0) {
                global $BE_USER;
 
-                       // If current document is found in docHandler, then unset it, possibly unset it ALL and finally, write it to the session data:
-               if (isset($this->docHandler[$this->storeUrlMd5]))       {
+                       // If current document is found in docHandler,
+                       // then unset it, possibly unset it ALL and finally, write it to the session data
+               if (isset($this->docHandler[$this->storeUrlMd5])) {
+
+                               // add the closing document to the recent documents
+                       $recentDocs = $BE_USER->getModuleData('opendocs::recent');
+                       if (!is_array($recentDocs)) {
+                               $recentDocs = array();
+                       }
+                       $closedDoc = $this->docHandler[$this->storeUrlMd5];
+                       $recentDocs = array_merge(array($this->storeUrlMd5 => $closedDoc), $recentDocs);
+                       if (count($recentDocs) > 8) {
+                               $recentDocs = array_slice($recentDocs, 0, 8);
+                       }
+
+                               // remove it from the list of the open documents
                        unset($this->docHandler[$this->storeUrlMd5]);
-                       if ($code=='3') $this->docHandler=array();
-                       $BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->docDat[1]));
+                       if ($code == '3') {
+                               $recentDocs = array_merge($this->docHandler, $recentDocs);
+                               $this->docHandler = array();
+                       }
+                       $BE_USER->pushModuleData('opendocs::recent', $recentDocs);
+                       $BE_USER->pushModuleData('alt_doc.php', array($this->docHandler, $this->docDat[1]));
+                       t3lib_BEfunc::setUpdateSignal('tx_opendocs::updateNumber', count($this->docHandler));
                }
 
+
                        // 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...)
                if ($this->returnEditConf && $this->retUrl!='dummy.php')        {
                        $this->retUrl.='&returnEditConf='.rawurlencode(serialize($this->editconf));
@@ -1464,8 +1417,7 @@ class SC_alt_doc {
 
                        // If code is NOT set OR set to 1, then make a header location redirect to $this->retUrl
                if (!$code || $code==1) {
-                       Header('Location: '.t3lib_div::locationHeaderUrl($this->retUrl));
-                       exit;
+                       t3lib_utility_Http::redirect($this->retUrl);
                } else {
                        $this->setDocument('',$this->retUrl);
                }
@@ -1494,31 +1446,17 @@ class SC_alt_doc {
                                $retUrl = $sParts['path'].'?'.$setupArr[2].'&returnUrl='.rawurlencode($retUrl);
                        }
                }
-               Header('Location: '.t3lib_div::locationHeaderUrl($retUrl));
-               exit;
+               t3lib_utility_Http::redirect($retUrl);
        }
 }
 
-// Include extension?
+
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_doc.php'])      {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_doc.php']);
 }
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
 // Make instance:
 $SOBE = t3lib_div::makeInstance('SC_alt_doc');
 
@@ -1533,4 +1471,5 @@ if ($SOBE->doProcessData())       {               // Checks, if a save button has been clicked (or
 $SOBE->init();
 $SOBE->main();
 $SOBE->printContent();
-?>
+
+?>
\ No newline at end of file