Documentation TYPO3 par Ameos

alt_doc.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00081 require('init.php');
00082 require('template.php');
00083 $LANG->includeLLFile('EXT:lang/locallang_alt_doc.xml');
00084 require_once (PATH_t3lib.'class.t3lib_tceforms.php');
00085 require_once (PATH_t3lib.'class.t3lib_clipboard.php');
00086 
00087 require_once (PATH_t3lib.'class.t3lib_tcemain.php');
00088 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
00089 require_once (PATH_t3lib.'class.t3lib_transferdata.php');
00090 
00091 
00092 t3lib_BEfunc::lockRecords();
00093 
00094 
00095 
00096 
00105 class SC_alt_doc {
00106 
00107                 // Internal, static: GPvars:
00108         var $editconf;                  // GPvar "edit": Is an array looking approx like [tablename][list-of-ids]=command, eg. "&edit[pages][123]=edit". See t3lib_BEfunc::editOnClick(). Value can be seen modified internally (converting NEW keyword to id, workspace/versioning etc).
00109         var $columnsOnly;               // Commalist of fieldnames to edit. The point is IF you specify this list, only those fields will be rendered in the form. Otherwise all (available) fields in the record is shown according to the types configuration in $TCA
00110         var $defVals;                   // Default values for fields (array with tablenames, fields etc. as keys). Can be seen modified internally.
00111         var $overrideVals;              // Array of values to force being set (as hidden fields). Will be set as $this->defVals IF defVals does not exist.
00112         var $returnUrl;                 // If set, this value will be set in $this->retUrl (which is used quite many places as the return URL). If not set, "dummy.php" will be set in $this->retUrl
00113         var $closeDoc;                  // Close-document command. Not really sure of all options...
00114         var $doSave;                    // Quite simply, if this variable is set, then the processing of incoming data will be performed - as if a save-button is pressed. Used in the forms as a hidden field which can be set through JavaScript if the form is somehow submitted by JavaScript).
00115 
00116         var $data;                              // GPvar (for processing only) : The data array from which the data comes...
00117         var $mirror;                    // GPvar (for processing only) : ?
00118         var $cacheCmd;                  // GPvar (for processing only) : Clear-cache cmd.
00119         var $redirect;                  // GPvar (for processing only) : Redirect (not used???)
00120         var $disableRTE;                // GPvar (for processing only) : If set, the rich text editor is disabled in the forms.
00121         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.
00122         var $vC;                                // GPvar (for processing only) : Verification code, internal stuff.
00123         var $uc;                                // GPvar : update BE_USER->uc
00124         
00125         var $popViewId;                 // GPvar (module) : ID for displaying the page in the frontend (used for SAVE/VIEW operations)
00126         var $popViewId_addParams;       // GPvar (module) : Additional GET vars for the link, eg. "&L=xxx"
00127         var $viewUrl;                   // GPvar (module) : Alternative URL for viewing the frontend pages.
00128         var $editRegularContentFromId;          // If this is pointing to a page id it will automatically load all content elements (NORMAL column/default language) from that page into the form!
00129         var $recTitle;                          // Alternative title for the document handler.
00130         var $disHelp;                           // Disable help... ?
00131         var $noView;                            // If set, then no SAVE/VIEW button is printed
00132         var $returnEditConf;            // If set, the $this->editconf array is returned to the calling script (used by wizard_add.php for instance)
00133         var $localizationMode;          // GP var, localization mode for TCEforms (eg. "text")
00134 
00135 
00136                 // Internal, static:
00137         var $doc;                               // Document template object
00138         var $content;                   // Content accumulation
00139 
00140         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.
00141         var $R_URL_parts;               // Contains the parts of the REQUEST_URI (current url). By parts we mean the result of resolving REQUEST_URI (current url) by the parse_url() function. The result is an array where eg. "path" is the script path and "query" is the parameters...
00142         var $R_URL_getvars;             // Contains the current GET vars array; More specifically this array is the foundation for creating the R_URI internal var (which becomes the "url of this script" to which we submit the forms etc.)
00143         var $R_URI;                             // Set to the URL of this script including variables which is needed to re-display the form. See main()
00144 
00145         var $storeTitle;                // Is loaded with the "title" of the currently "open document" - this is used in the Document Selector box. (see makeDocSel())
00146         var $storeArray;                // Contains an array with key/value pairs of GET parameters needed to reach the current document displayed - used in the Document Selector box. (see compileStoreDat())
00147         var $storeUrl;                  // Contains storeArray, but imploded into a GET parameter string (see compileStoreDat())
00148         var $storeUrlMd5;               // Hashed value of storeURL (see compileStoreDat())
00149 
00150         var $docDat;                    // Module session data
00151         var $docHandler;                // An array of the "open documents" - keys are md5 hashes (see $storeUrlMd5) identifying the various documents on the GET parameter list needed to open it. The values are arrays with 0,1,2 keys with information about the document (see compileStoreDat()). The docHandler variable is stored in the $docDat session data, key "0".
00152 
00153 
00154                 // Internal: Related to the form rendering:
00155         var $elementsData;              // Array of the elements to create edit forms for.
00156         var $firstEl;                   // Pointer to the first element in $elementsData
00157         var $errorC;                    // Counter, used to count the number of errors (when users do not have edit permissions)
00158         var $newC;                              // Counter, used to count the number of new record forms displayed
00159         var $viewId;                    // Is set to the pid value of the last shown record - thus indicating which page to show when clicking the SAVE/VIEW button
00160         var $viewId_addParams;  // Is set to additional parameters (like "&L=xxx") if the record supports it.
00161         var $modTSconfig;               // Module TSconfig, loaded from main() based on the page id value of viewId
00162         var $tceforms;                  // Contains the instance of TCEforms class.
00163         var $generalPathOfForm; // Contains the root-line path of the currently edited record(s) - for display.
00164 
00165 
00166                 // Internal, dynamic:
00167         var $dontStoreDocumentRef;      // Used internally to disable the storage of the document reference (eg. new records)
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00180         function preInit()      {
00181                 global $BE_USER;
00182 
00183                 if (t3lib_div::_GP('justLocalized'))    {
00184                         $this->localizationRedirect(t3lib_div::_GP('justLocalized'));
00185                 }
00186 
00187                         // Setting GPvars:
00188                 $this->editconf = t3lib_div::_GP('edit');
00189                 $this->defVals = t3lib_div::_GP('defVals');
00190                 $this->overrideVals = t3lib_div::_GP('overrideVals');
00191                 $this->columnsOnly = t3lib_div::_GP('columnsOnly');
00192                 $this->returnUrl = t3lib_div::_GP('returnUrl');
00193                 $this->closeDoc = t3lib_div::_GP('closeDoc');
00194                 $this->doSave = t3lib_div::_GP('doSave');
00195                 $this->returnEditConf = t3lib_div::_GP('returnEditConf');
00196                 $this->localizationMode = t3lib_div::_GP('localizationMode');
00197                 $this->uc = t3lib_div::_GP('uc');
00198 
00199 
00200                         // Setting override values as default if defVals does not exist.
00201                 if (!is_array($this->defVals) && is_array($this->overrideVals)) {
00202                         $this->defVals = $this->overrideVals;
00203                 }
00204 
00205                         // Setting return URL
00206                 $this->retUrl = $this->returnUrl ? $this->returnUrl : 'dummy.php';
00207 
00208                         // Fix $this->editconf if versioning applies to any of the records
00209                 $this->fixWSversioningInEditConf();
00210 
00211                         // Make R_URL (request url) based on input GETvars:
00212                 $this->R_URL_parts = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
00213                 $this->R_URL_getvars = t3lib_div::_GET();
00214                 $this->R_URL_getvars['edit'] = $this->editconf;
00215 
00216                         // MAKE url for storing
00217                 $this->compileStoreDat();
00218 
00219                         // Initialize more variables.
00220                 $this->dontStoreDocumentRef=0;
00221                 $this->storeTitle='';
00222 
00223                         // Get session data for the module:
00224                 $this->docDat = $BE_USER->getModuleData('alt_doc.php','ses');
00225                 $this->docHandler = $this->docDat[0];
00226 
00227                         // If a request for closing the document has been sent, act accordingly:
00228                 if ($this->closeDoc>0)  {
00229                         $this->closeDocument($this->closeDoc);
00230                 }
00231 
00232                         // If NO vars are sent to the script, try to read first document:
00233                 if (is_array($this->R_URL_getvars) && count($this->R_URL_getvars)<2 && !is_array($this->editconf))      {       // Added !is_array($this->editconf) because editConf must not be set either. Anyways I can't figure out when this situation here will apply...
00234                         $this->setDocument($this->docDat[1]);
00235                 }
00236         }
00237 
00243         function doProcessData()        {
00244                 $out = $this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']);
00245                 return $out;
00246         }
00247 
00253         function processData()  {
00254                 global $BE_USER,$TYPO3_CONF_VARS;
00255 
00256                         // GPvars specifically for processing:
00257                 $this->data = t3lib_div::_GP('data');
00258                 $this->cmd = t3lib_div::_GP('cmd');
00259                 $this->mirror = t3lib_div::_GP('mirror');
00260                 $this->cacheCmd = t3lib_div::_GP('cacheCmd');
00261                 $this->redirect = t3lib_div::_GP('redirect');
00262                 $this->disableRTE = t3lib_div::_GP('_disableRTE');
00263                 $this->returnNewPageId = t3lib_div::_GP('returnNewPageId');
00264                 $this->vC = t3lib_div::_GP('vC');
00265 
00266                         // See tce_db.php for relevate options here:
00267                         // Only options related to $this->data submission are included here.
00268                 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00269                 $tce->stripslashes_values=0;
00270 
00271                         // Setting default values specific for the user:
00272                 $TCAdefaultOverride = $BE_USER->getTSConfigProp('TCAdefaults');
00273                 if (is_array($TCAdefaultOverride))      {
00274                         $tce->setDefaultsFromUserTS($TCAdefaultOverride);
00275                 }
00276 
00277                         // Setting internal vars:
00278                 if ($BE_USER->uc['neverHideAtCopy'])    {       $tce->neverHideAtCopy = 1;      }
00279                 $tce->debug=0;
00280                 $tce->disableRTE = $this->disableRTE;
00281 
00282                         // Loading TCEmain with data:
00283                 $tce->start($this->data,$this->cmd);
00284                 if (is_array($this->mirror))    {       $tce->setMirror($this->mirror); }
00285 
00286                         // If pages are being edited, we set an instruction about updating the page tree after this operation.
00287                 if (isset($this->data['pages']))        {
00288                         t3lib_BEfunc::getSetUpdateSignal('updatePageTree');
00289                 }
00290 
00291 
00292                         // Checking referer / executing
00293                 $refInfo=parse_url(t3lib_div::getIndpEnv('HTTP_REFERER'));
00294                 $httpHost = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
00295                 if ($httpHost!=$refInfo['host'] && $this->vC!=$BE_USER->veriCode() && !$TYPO3_CONF_VARS['SYS']['doNotCheckReferer'])    {
00296                         $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));
00297                         debug('Error: Referer host did not match with server host.');
00298                 } else {
00299 
00300                                 // Perform the saving operation with TCEmain:
00301                         $tce->process_uploads($_FILES);
00302                         $tce->process_datamap();
00303                         $tce->process_cmdmap();
00304 
00305                                 // If there was saved any new items, load them:
00306                         if (count($tce->substNEWwithIDs_table)) {
00307                                         // save the expanded/collapsed states for new inline records, if any
00308                                 t3lib_TCEforms_inline::updateInlineView($this->uc, $tce);
00309 
00310                                 $newEditConf = array();
00311 
00312                                 foreach($this->editconf as $tableName => $tableCmds) {
00313                                         $keys = array_keys($tce->substNEWwithIDs_table, $tableName);
00314                                         if(count($keys) > 0) {
00315                                                 foreach($keys as $key) {
00316                                                         $editId = $tce->substNEWwithIDs[$key];
00317                                                                 // check if the $editId isn't a child record of an IRRE action
00318                                                         if (!(is_array($tce->newRelatedIDs[$tableName]) && in_array($editId, $tce->newRelatedIDs[$tableName]))) {
00319                                                                         // translate new id to the workspace version:
00320                                                                 if ($versionRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $tableName, $editId,'uid')) {
00321                                                                         $editId = $versionRec['uid'];
00322                                                                 }
00323                                                                 $newEditConf[$tableName][$editId] = 'edit';
00324                                                         }
00325         
00326                                                                 // Traverse all new records and forge the content of ->editconf so we can continue to EDIT these records!
00327                                                         if ($tableName=='pages' && $this->retUrl!='dummy.php' && $this->returnNewPageId)        {
00328                                                                 $this->retUrl.='&id='.$tce->substNEWwithIDs[$key];
00329                                                         }
00330                                                 }
00331                                         } else {
00332                                                 $newEditConf[$tableName] = $tableCmds;
00333                                         }
00334                                 }
00335 
00336                                         // Resetting editconf if newEditConf has values:
00337                                 if (count($newEditConf)) {
00338                                         $this->editconf = $newEditConf;
00339                                 }
00340                                 
00341                                         // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
00342                                 $this->R_URL_getvars['edit']=$this->editconf;
00343 
00344                                         // Unsetting default values since we don't need them anymore.
00345                                 unset($this->R_URL_getvars['defVals']);
00346 
00347                                         // Re-compile the store* values since editconf changed...
00348                                 $this->compileStoreDat();
00349                         }
00350 
00351                                 // See if any records was auto-created as new versions?
00352                         if (count($tce->autoVersionIdMap))      {
00353                                 $this->fixWSversioningInEditConf($tce->autoVersionIdMap);
00354                         }
00355 
00356                                 // If a document is saved and a new one is created right after.
00357                         if (isset($_POST['_savedoknew_x']) && is_array($this->editconf))        {
00358 
00359                                         // Finding the current table:
00360                                 reset($this->editconf);
00361                                 $nTable=key($this->editconf);
00362 
00363                                         // Finding the first id, getting the records pid+uid
00364                                 reset($this->editconf[$nTable]);
00365                                 $nUid=key($this->editconf[$nTable]);
00366                                 $nRec = t3lib_BEfunc::getRecord($nTable,$nUid,'pid,uid');
00367 
00368                                         // Setting a blank editconf array for a new record:
00369                                 $this->editconf=array();
00370                                 if ($this->getNewIconMode($nTable)=='top')      {
00371                                         $this->editconf[$nTable][$nRec['pid']]='new';
00372                                 } else {
00373                                         $this->editconf[$nTable][-$nRec['uid']]='new';
00374                                 }
00375 
00376                                         // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
00377                                 $this->R_URL_getvars['edit']=$this->editconf;
00378 
00379                                         // Re-compile the store* values since editconf changed...
00380                                 $this->compileStoreDat();
00381                         }
00382 
00383                         $tce->printLogErrorMessages(
00384                                 isset($_POST['_saveandclosedok_x']) ?
00385                                 $this->retUrl :
00386                                 $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?
00387                         );
00388                 }
00389                 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!
00390                         $this->closeDocument(abs($this->closeDoc));
00391                 }
00392         }
00393 
00399         function init() {
00400                 global $BE_USER,$LANG,$BACK_PATH;
00401 
00402                         // Setting more GPvars:
00403                 $this->popViewId = t3lib_div::_GP('popViewId');
00404                 $this->popViewId_addParams = t3lib_div::_GP('popViewId_addParams');
00405                 $this->viewUrl = t3lib_div::_GP('viewUrl');
00406                 $this->editRegularContentFromId = t3lib_div::_GP('editRegularContentFromId');
00407                 $this->recTitle = t3lib_div::_GP('recTitle');
00408                 $this->disHelp = t3lib_div::_GP('disHelp');
00409                 $this->noView = t3lib_div::_GP('noView');
00410 
00411                         // Set other internal variables:
00412                 $this->R_URL_getvars['returnUrl']=$this->retUrl;
00413                 $this->R_URI = $this->R_URL_parts['path'].'?'.t3lib_div::implodeArrayForUrl('',$this->R_URL_getvars);
00414 
00415                         // MENU-ITEMS:
00416                         // If array, then it's a selector box menu
00417                         // If empty string it's just a variable, that'll be saved.
00418                         // Values NOT in this array will not be saved in the settings-array for the module.
00419                 $this->MOD_MENU = array(
00420                         'showPalettes' => '',
00421                         'showDescriptions' => '',
00422                         'disableRTE' => ''
00423                 );
00424 
00425                         // Setting virtual document name
00426                 $this->MCONF['name']='xMOD_alt_doc.php';
00427 
00428                         // CLEANSE SETTINGS
00429                 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
00430 
00431                         // Create an instance of the document template object
00432                 $this->doc = t3lib_div::makeInstance('mediumDoc');
00433                 $this->doc->bodyTagMargins['x']=5;
00434                 $this->doc->bodyTagMargins['y']=5;
00435                 $this->doc->backPath = $BACK_PATH;
00436                 $this->doc->docType = 'xhtml_trans';
00437 
00438                 $this->doc->form='<form action="'.htmlspecialchars($this->R_URI).'" method="post" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
00439 
00440                 $this->doc->JScode = $this->doc->wrapScriptTags('
00441                         function jumpToUrl(URL,formEl)  {       //
00442                                 if (!TBE_EDITOR.isFormChanged())        {
00443                                         window.location.href = URL;
00444                                 } else if (formEl && formEl.type=="checkbox") {
00445                                         formEl.checked = formEl.checked ? 0 : 1;
00446                                 }
00447                         }
00448 
00449                                 // Object: TS:
00450                         function typoSetup      ()      {       //
00451                                 this.uniqueID = "";
00452                         }
00453                         var TS = new typoSetup();
00454 
00455                                 // Info view:
00456                         function launchView(table,uid,bP)       {       //
00457                                 var backPath= bP ? bP : "";
00458                                 var thePreviewWindow="";
00459                                 thePreviewWindow = window.open(backPath+"show_item.php?table="+encodeURIComponent(table)+"&uid="+encodeURIComponent(uid),"ShowItem"+TS.uniqueID,"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
00460                                 if (thePreviewWindow && thePreviewWindow.focus) {
00461                                         thePreviewWindow.focus();
00462                                 }
00463                         }
00464                         function deleteRecord(table,id,url)     {       //
00465                                 if (
00466                                         '.($GLOBALS['BE_USER']->jsConfirmation(4)?'confirm('.$LANG->JScharCode($LANG->getLL('deleteWarning')).')':'1==1').'
00467                                 )       {
00468                                         window.location.href = "tce_db.php?cmd["+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC='.$BE_USER->veriCode().'&prErr=1&uPT=1";
00469                                 }
00470                                 return false;
00471                         }
00472                 '.(isset($_POST['_savedokview_x']) && $this->popViewId ?
00473                         'if (window.opener) { '.
00474                                 t3lib_BEfunc::viewOnClick($this->popViewId,'',t3lib_BEfunc::BEgetRootLine($this->popViewId),'',$this->viewUrl,$this->popViewId_addParams,FALSE).
00475                                 ' } else { '.
00476                                 t3lib_BEfunc::viewOnClick($this->popViewId,'',t3lib_BEfunc::BEgetRootLine($this->popViewId),'',$this->viewUrl,$this->popViewId_addParams).
00477                                 ' } '
00478                         : '')
00479                 ).$this->doc->getDynTabMenuJScode();
00480 
00481                         // Setting up the context sensitive menu:
00482                 $CMparts = $this->doc->getContextMenuCode();
00483                 $this->doc->JScode.= $CMparts[0];
00484                 $this->doc->bodyTagAdditions = $CMparts[1];
00485                 $this->doc->postCode.= $CMparts[2];
00486         }
00487 
00493         function main() {
00494                 global $BE_USER,$LANG;
00495 
00496                         // Starting content accumulation:
00497                 $this->content='';
00498                 $this->content.=$this->doc->startPage('TYPO3 Edit Document');
00499 
00500                         // Begin edit:
00501                 if (is_array($this->editconf))  {
00502                         
00503                                 // Initialize TCEforms (rendering the forms)
00504                         $this->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
00505                         $this->tceforms->initDefaultBEMode();
00506                         $this->tceforms->doSaveFieldName = 'doSave';
00507                         $this->tceforms->localizationMode = t3lib_div::inList('text,media',$this->localizationMode) ? $this->localizationMode : '';     // text,media is keywords defined in TYPO3 Core API..., see "l10n_cat"
00508                         $this->tceforms->returnUrl = $this->R_URI;
00509                         $this->tceforms->palettesCollapsed = !$this->MOD_SETTINGS['showPalettes'];
00510                         $this->tceforms->disableRTE = $this->MOD_SETTINGS['disableRTE'];
00511                         $this->tceforms->enableClickMenu = TRUE;
00512                         $this->tceforms->enableTabMenu = TRUE;
00513 
00514                                 // Clipboard is initialized:
00515                         $this->tceforms->clipObj = t3lib_div::makeInstance('t3lib_clipboard');          // Start clipboard
00516                         $this->tceforms->clipObj->initializeClipboard();        // Initialize - reads the clipboard content from the user session
00517 
00518                                 // Setting external variables:
00519                         if ($BE_USER->uc['edit_showFieldHelp']!='text' && $this->MOD_SETTINGS['showDescriptions'])      $this->tceforms->edit_showFieldHelp='text';
00520 
00521                         if ($this->editRegularContentFromId)    {
00522                                 $this->editRegularContentFromId();
00523                         }
00524 
00525                                 // Creating the editing form, wrap it with buttons, document selector etc.
00526                         $editForm = $this->makeEditForm();
00527 
00528                         if ($editForm)  {
00529                                 reset($this->elementsData);
00530                                 $this->firstEl = current($this->elementsData);
00531 
00532                                         // language switch/selector for editing
00533                                         // show only when a single record is edited - multiple records are too confusing
00534                                 if (count($this->elementsData)==1) {
00535                                         $languageSwitch = $this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']);
00536                                 }
00537 
00538 
00539                                 if ($this->viewId)      {
00540                                                 // Module configuration:
00541                                         $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->viewId,'mod.xMOD_alt_doc');
00542                                 } else $this->modTSconfig=array();
00543 
00544                                 $panel = $this->makeButtonPanel();
00545                                 $docSel = $this->makeDocSel();
00546                                 $cMenu = $this->makeCmenu();
00547 
00548                                 $formContent = $this->compileForm($panel,$docSel,$cMenu,$editForm,$languageSwitch);
00549 
00550                                 $this->content.= $this->tceforms->printNeededJSFunctions_top().
00551                                                                         $formContent.
00552                                                                         $this->tceforms->printNeededJSFunctions();
00553                                 $this->content.= $this->functionMenus();
00554 
00555                                         // Add CSH:
00556                                 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms', $GLOBALS['BACK_PATH'],'<br/>|',FALSE,'margin-top: 20px;');
00557 
00558                                 $this->content.= $this->shortCutLink();
00559 
00560                                 $this->tceformMessages();
00561                         }
00562                 }
00563         }
00564 
00565 
00571         function printContent() {
00572                 $this->content.= $this->doc->endPage();
00573                 $this->content = $this->doc->insertStylesAndJS($this->content);
00574                 echo $this->content;
00575         }
00576 
00577 
00578 
00579 
00580 
00581 
00582 
00583 
00584 
00585 
00586 
00587 
00588 
00589 
00590 
00591 
00592 
00593 
00594 
00595 
00596         /***************************
00597          *
00598          * Sub-content functions, rendering specific parts of the module content.
00599          *
00600          ***************************/
00601 
00607         function makeEditForm() {
00608                 global $BE_USER,$LANG,$TCA;
00609 
00610                         // Initialize variables:
00611                 $this->elementsData=array();
00612                 $this->errorC=0;
00613                 $this->newC=0;
00614                 $thePrevUid='';
00615                 $editForm='';
00616 
00617                         // Traverse the GPvar edit array
00618                 foreach($this->editconf as $table => $conf)     {       // Tables:
00619                         if (is_array($conf) && $TCA[$table] && $BE_USER->check('tables_modify',$table)) {
00620 
00621                                         // Traverse the keys/comments of each table (keys can be a commalist of uids)
00622                                 foreach($conf as $cKey => $cmd) {
00623                                         if ($cmd=='edit' || $cmd=='new')        {
00624 
00625                                                         // Get the ids:
00626                                                 $ids = t3lib_div::trimExplode(',',$cKey,1);
00627 
00628                                                         // Traverse the ids:
00629                                                 foreach($ids as $theUid)        {
00630 
00631                                                                 // Checking if the user has permissions? (Only working as a precaution, because the final permission check is always down in TCE. But it's good to notify the user on beforehand...)
00632                                                                 // First, resetting flags.
00633                                                         $hasAccess = 1;
00634                                                         $deniedAccessReason = '';
00635                                                         $deleteAccess = 0;
00636                                                         $this->viewId = 0;
00637 
00638                                                                 // If the command is to create a NEW record...:
00639                                                         if ($cmd=='new')        {
00640                                                                 if (intval($theUid))    {               // NOTICE: the id values in this case points to the page uid onto which the record should be create OR (if the id is negativ) to a record from the same table AFTER which to create the record.
00641 
00642                                                                                 // Find parent page on which the new record reside
00643                                                                         if ($theUid<0)  {       // Less than zero - find parent page
00644                                                                                 $calcPRec=t3lib_BEfunc::getRecord($table,abs($theUid));
00645                                                                                 $calcPRec=t3lib_BEfunc::getRecord('pages',$calcPRec['pid']);
00646                                                                         } else {        // always a page
00647                                                                                 $calcPRec=t3lib_BEfunc::getRecord('pages',abs($theUid));
00648                                                                         }
00649 
00650                                                                                 // Now, calculate whether the user has access to creating new records on this position:
00651                                                                         if (is_array($calcPRec))        {
00652                                                                                 $CALC_PERMS = $BE_USER->calcPerms($calcPRec);   // Permissions for the parent page
00653                                                                                 if ($table=='pages')    {       // If pages:
00654                                                                                         $hasAccess = $CALC_PERMS&8 ? 1 : 0;
00655                                                                                         $this->viewId = $calcPRec['pid'];
00656                                                                                 } else {
00657                                                                                         $hasAccess = $CALC_PERMS&16 ? 1 : 0;
00658                                                                                         $this->viewId = $calcPRec['uid'];
00659                                                                                 }
00660                                                                         }
00661                                                                 }
00662                                                                 $this->dontStoreDocumentRef=1;          // Don't save this document title in the document selector if the document is new.
00663                                                         } else {        // Edit:
00664                                                                 $calcPRec = t3lib_BEfunc::getRecord($table,$theUid);
00665                                                                 t3lib_BEfunc::fixVersioningPid($table,$calcPRec);
00666                                                                 if (is_array($calcPRec))        {
00667                                                                         if ($table=='pages')    {       // If pages:
00668                                                                                 $CALC_PERMS = $BE_USER->calcPerms($calcPRec);
00669                                                                                 $hasAccess = $CALC_PERMS&2 ? 1 : 0;
00670                                                                                 $deleteAccess = $CALC_PERMS&4 ? 1 : 0;
00671                                                                                 $this->viewId = $calcPRec['uid'];
00672                                                                         } else {
00673                                                                                 $CALC_PERMS = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',$calcPRec['pid']));   // Fetching pid-record first.
00674                                                                                 $hasAccess = $CALC_PERMS&16 ? 1 : 0;
00675                                                                                 $deleteAccess = $CALC_PERMS&16 ? 1 : 0;
00676                                                                                 $this->viewId = $calcPRec['pid'];
00677 
00678                                                                                         // Adding "&L=xx" if the record being edited has a languageField with a value larger than zero!
00679                                                                                 if ($TCA[$table]['ctrl']['languageField'] && $calcPRec[$TCA[$table]['ctrl']['languageField']]>0)        {
00680                                                                                         $this->viewId_addParams = '&L='.$calcPRec[$TCA[$table]['ctrl']['languageField']];
00681                                                                                 }
00682                                                                         }
00683 
00684                                                                                 // Check internals regarding access:
00685                                                                         if ($hasAccess) {
00686                                                                                 $hasAccess = $BE_USER->recordEditAccessInternals($table, $calcPRec);
00687                                                                                 $deniedAccessReason = $BE_USER->errorMsg;
00688                                                                         }
00689                                                                 } else $hasAccess = 0;
00690                                                         }
00691 
00692                                                         // AT THIS POINT we have checked the access status of the editing/creation of records and we can now proceed with creating the form elements:
00693 
00694                                                         if ($hasAccess) {
00695                                                                 $prevPageID = is_object($trData)?$trData->prevPageID:'';
00696                                                                 $trData = t3lib_div::makeInstance('t3lib_transferData');
00697                                                                 $trData->addRawData = TRUE;
00698                                                                 $trData->defVals = $this->defVals;
00699                                                                 $trData->lockRecords=1;
00700                                                                 $trData->disableRTE = $this->MOD_SETTINGS['disableRTE'];
00701                                                                 $trData->prevPageID = $prevPageID;
00702                                                                 $trData->fetchRecord($table,$theUid,$cmd=='new'?'new':'');      // 'new'
00703                                                                 reset($trData->regTableItems_data);
00704                                                                 $rec = current($trData->regTableItems_data);
00705                                                                 $rec['uid'] = $cmd=='new' ? uniqid('NEW') : $theUid;
00706                                                                 if ($cmd=='new')        {
00707                                                                         $rec['pid'] = $theUid=='prev'?$thePrevUid:$theUid;
00708                                                                 }
00709                                                                 $this->elementsData[]=array(
00710                                                                         'table' => $table,
00711                                                                         'uid' => $rec['uid'],
00712                                                                         'pid' => $rec['pid'],
00713                                                                         'cmd' => $cmd,
00714                                                                         'deleteAccess' => $deleteAccess
00715                                                                 );
00716 
00717                                                                         // Now, render the form:
00718                                                                 if (is_array($rec))     {
00719 
00720                                                                                 // Setting visual path / title of form:
00721                                                                         $this->generalPathOfForm = $this->tceforms->getRecordPath($table,$rec);
00722                                                                         if (!$this->storeTitle) {
00723                                                                                 $this->storeTitle = $this->recTitle ? htmlspecialchars($this->recTitle) : t3lib_BEfunc::getRecordTitle($table,$rec,TRUE);
00724                                                                         }
00725 
00726                                                                                 // Setting variables in TCEforms object:
00727                                                                         $this->tceforms->hiddenFieldList = '';
00728                                                                         $this->tceforms->globalShowHelp = $this->disHelp ? 0 : 1;
00729                                                                         if (is_array($this->overrideVals[$table]))      {
00730                                                                                 $this->tceforms->hiddenFieldListArr = array_keys($this->overrideVals[$table]);
00731                                                                         }
00732 
00733                                                                                 // Register default language labels, if any:
00734                                                                         $this->tceforms->registerDefaultLanguageData($table,$rec);
00735 
00736                                                                                 // Create form for the record (either specific list of fields or the whole record):
00737                                                                         $panel = '';
00738                                                                         if ($this->columnsOnly) {
00739                                                                                 if(is_array($this->columnsOnly)){
00740                                                                                         $panel.= $this->tceforms->getListedFields($table,$rec,$this->columnsOnly[$table]);
00741                                                                                 } else {
00742                                                                                         $panel.= $this->tceforms->getListedFields($table,$rec,$this->columnsOnly);
00743                                                                                 }
00744                                                                         } else {
00745                                                                                 $panel.= $this->tceforms->getMainFields($table,$rec);
00746                                                                         }
00747                                                                         $panel = $this->tceforms->wrapTotal($panel,$rec,$table);
00748 
00749                                                                                 // Setting the pid value for new records:
00750                                                                         if ($cmd=='new')        {
00751                                                                                 $panel.= '<input type="hidden" name="data['.$table.']['.$rec['uid'].'][pid]" value="'.$rec['pid'].'" />';
00752                                                                                 $this->newC++;
00753                                                                         }
00754 
00755                                                                                 // Display "is-locked" message:
00756                                                                         if ($lockInfo = t3lib_BEfunc::isRecordLocked($table,$rec['uid']))       {
00757                                                                                 $lockIcon = '
00758 
00759                                                                                         <!--
00760                                                                                                 Warning box:
00761                                                                                         -->
00762                                                                                         <table border="0" cellpadding="0" cellspacing="0" class="warningbox">
00763                                                                                                 <tr>
00764                                                                                                         <td><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/recordlock_warning3.gif','width="17" height="12"').' alt="" /></td>
00765                                                                                                         <td>'.htmlspecialchars($lockInfo['msg']).'</td>
00766                                                                                                 </tr>
00767                                                                                         </table>
00768                                                                                 ';
00769                                                                         } else $lockIcon = '';
00770 
00771                                                                                 // Combine it all:
00772                                                                         $editForm.= $lockIcon.$panel;
00773                                                                 }
00774 
00775                                                                 $thePrevUid = $rec['uid'];
00776                                                         } else {
00777                                                                 $this->errorC++;
00778                                                                 $editForm.=$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.noEditPermission',1).'<br /><br />'.
00779                                                                                         ($deniedAccessReason ? 'Reason: '.htmlspecialchars($deniedAccessReason).'<br/><br/>' : '');
00780                                                         }
00781                                                 }
00782                                         }
00783                                 }
00784                         }
00785                 }
00786 
00787                 return $editForm;
00788         }
00789 
00795         function makeButtonPanel()      {
00796                 global $TCA,$LANG;
00797 
00798                 $panel='';
00799 
00800                         // Render SAVE type buttons:
00801                         // The action of each button is decided by its name attribute. (See doProcessData())
00802                 if (!$this->errorC && !$TCA[$this->firstEl['table']]['ctrl']['readOnly'])       {
00803 
00804                                 // SAVE button:
00805                         $panel.= '<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).'" />';
00806 
00807                                 // SAVE / VIEW button:
00808                         if ($this->viewId && !$this->noView && t3lib_extMgm::isLoaded('cms')) {
00809                                 $panel.= '<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).'" />';
00810                         }
00811 
00812                                 // SAVE / NEW button:
00813                         if (count($this->elementsData)==1 && $this->getNewIconMode($this->firstEl['table'])) {
00814                                 $panel.= '<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).'" />';
00815                         }
00816 
00817                                 // SAVE / CLOSE
00818                         $panel.= '<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).'" />';
00819                 }
00820 
00821                         // CLOSE button:
00822                 $panel.= '<a href="#" onclick="document.editform.closeDoc.value=1; document.editform.submit(); return false;">'.
00823                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" />'.
00824                                 '</a>';
00825 
00826                         // DELETE + UNDO buttons:
00827                 if (!$this->errorC && !$TCA[$this->firstEl['table']]['ctrl']['readOnly'] && count($this->elementsData)==1)      {
00828                         if ($this->firstEl['cmd']!='new' && t3lib_div::testInt($this->firstEl['uid']))  {
00829 
00830                                         // Delete:
00831                                 if ($this->firstEl['deleteAccess'] && !$TCA[$this->firstEl['table']]['ctrl']['readOnly'] && !$this->getNewIconMode($this->firstEl['table'],'disableDelete')) {
00832                                         $aOnClick = 'return deleteRecord(\''.$this->firstEl['table'].'\',\''.$this->firstEl['uid'].'\',unescape(\''.rawurlencode($this->retUrl).'\'));';
00833                                         $panel.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
00834                                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/deletedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->getLL('deleteItem',1).'" alt="" />'.
00835                                                         '</a>';
00836                                 }
00837 
00838                                         // Undo:
00839                                 $undoButton = 0;
00840                                 $undoRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp', 'sys_history', 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->firstEl['table'], 'sys_history').' AND recuid='.intval($this->firstEl['uid']), '', 'tstamp DESC', '1');
00841                                 if ($undoButtonR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($undoRes))     {
00842                                         $undoButton = 1;
00843                                 }
00844                                 if ($undoButton) {
00845                                         $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;';
00846                                         $panel.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
00847                                                         '<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="" />'.
00848                                                         '</a>';
00849                                 }
00850                                 if ($this->getNewIconMode($this->firstEl['table'],'showHistory'))       {
00851                                         $aOnClick = 'window.location.href=\'show_rechis.php?element='.rawurlencode($this->firstEl['table'].':'.$this->firstEl['uid']).'&returnUrl='.rawurlencode($this->R_URI).'\'; return false;';
00852                                         $panel.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
00853                                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/history2.gif','width="13" height="12"').' class="c-inputButton" alt="" />'.
00854                                                         '</a>';
00855                                 }
00856 
00857                                         // If only SOME fields are shown in the form, this will link the user to the FULL form:
00858                                 if ($this->columnsOnly) {
00859                                         $panel.= '<a href="'.htmlspecialchars($this->R_URI.'&columnsOnly=').'">'.
00860                                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' class="c-inputButton" title="'.$LANG->getLL('editWholeRecord',1).'" alt="" />'.
00861                                                         '</a>';
00862                                 }
00863                         }
00864                 }
00865                 return $panel;
00866         }
00867 
00874         function makeDocSel()   {
00875                 global $BE_USER,$LANG;
00876 
00877                         // Render the selector ONLY if it has not been disabled:
00878                 if (!$this->modTSconfig['properties']['disableDocSelector'])    {
00879 
00880                                 // Checking if the currently open document is stored in the list of "open documents" - if not, then add it:
00881                         if ((strcmp($this->docDat[1],$this->storeUrlMd5)||!isset($this->docHandler[$this->storeUrlMd5])) && !$this->dontStoreDocumentRef)       {
00882                                 $this->docHandler[$this->storeUrlMd5]=array($this->storeTitle,$this->storeArray,$this->storeUrl);
00883                                 $BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->storeUrlMd5));
00884                         }
00885 
00886                                 // Now, create the document selector box:
00887                         $docSel='';
00888                         if (is_array($this->docHandler))        {
00889                                 $opt = array();
00890                                 $opt[] = '<option>[ '.$LANG->getLL('openDocs',1).': ]</option>';
00891 
00892                                         // Traverse the list of open documents:
00893                                 foreach($this->docHandler as $md5k => $setupArr)        {
00894                                         $theValue = 'alt_doc.php?'.$setupArr[2].'&returnUrl='.rawurlencode($this->retUrl);
00895                                         $opt[]='<option value="'.htmlspecialchars($theValue).'"'.(!strcmp($md5k,$this->storeUrlMd5)?' selected="selected"':'').'>'.htmlspecialchars(strip_tags(t3lib_div::htmlspecialchars_decode($setupArr[0]))).'</option>';
00896                                 }
00897 
00898                                         // Compile the selector box finally:
00899                                 $onChange = 'if(this.options[this.selectedIndex].value && !TBE_EDITOR.isFormChanged()){window.location.href=(this.options[this.selectedIndex].value);}';
00900                                 $docSel='<select name="_docSelector" onchange="'.htmlspecialchars($onChange).'">'.implode('',$opt).'</select>';
00901 
00902                                         // Add CSH:
00903                                 $docSel.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms_docSelector', $GLOBALS['BACK_PATH'],'', TRUE);
00904                         }
00905                 } else $docSel='';
00906                 return $docSel;
00907         }
00908 
00916         function makeCmenu()    {
00917 
00918                         // Generate the menu if NOT disabled:
00919                 if (!$this->modTSconfig['properties']['disableCacheSelector'])  {
00920                         $cMenu = $this->doc->clearCacheMenu(intval($this->viewId),!$this->modTSconfig['properties']['disableDocSelector']);
00921 
00922                                 // Add CSH:
00923                         $cMenu.=t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'TCEforms_cacheSelector', $GLOBALS['BACK_PATH'],'', TRUE);
00924                 } else $cMenu ='';
00925                 return $cMenu;
00926         }
00927 
00938         function compileForm($panel,$docSel,$cMenu,$editForm, $langSelector='') {
00939                 global $LANG;
00940 
00941 
00942                 $formContent='';
00943                 $formContent.='
00944 
00945                         <!--
00946                                 Header of the editing page.
00947                                 Contains the buttons for saving/closing, the document selector and menu selector.
00948                                 Shows the path of the editing operation as well.
00949                         -->
00950                         <table border="0" cellpadding="0" cellspacing="1" width="470" id="typo3-altdoc-header">
00951                                 <tr>
00952                                         <td nowrap="nowrap" valign="top">'.$panel.'</td>
00953                                         <td nowrap="nowrap" valign="top" align="right">'.$docSel.$cMenu.'</td>
00954                                 </tr>';
00955 
00956                 if ($langSelector) {
00957                         $langSelector ='<div id="typo3-altdoc-lang-selector">'.$langSelector.'</div>';
00958                 }
00959 
00960                 if (is_array($this->tceforms->extraFormHeaders))        {
00961                         $formContent .= implode(chr(10), $this->tceforms->extraFormHeaders);
00962                 }
00963 
00964                 $pagePath = '<div id="typo3-altdoc-page-path">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path',1).': '.htmlspecialchars($this->generalPathOfForm).'</div>';
00965 
00966                 $formContent.='
00967                                 <tr>
00968                                         <td colspan="2"><div id="typo3-altdoc-header-info-options">'.$pagePath.$langSelector.'</div></td>
00969                                 </tr>
00970                         </table>
00971 
00972 
00973 
00974 
00975                         <!--
00976                                 EDITING FORM:
00977                         -->
00978 
00979                         '.$editForm.'
00980 
00981 
00982 
00983                         <!--
00984                                 Saving buttons (same as in top)
00985                         -->
00986 
00987                         '.$panel.
00988                         '<input type="hidden" name="returnUrl" value="'.htmlspecialchars($this->retUrl).'" />
00989                         <input type="hidden" name="viewUrl" value="'.htmlspecialchars($this->viewUrl).'" />';
00990 
00991                 if ($this->returnNewPageId)     {
00992                         $formContent.='<input type="hidden" name="returnNewPageId" value="1" />';
00993                 }
00994                 $formContent.='<input type="hidden" name="popViewId" value="'.htmlspecialchars($this->viewId).'" />';
00995                 if ($this->viewId_addParams) {
00996                         $formContent.='<input type="hidden" name="popViewId_addParams" value="'.htmlspecialchars($this->viewId_addParams).'" />';
00997                 }
00998                 $formContent.='<input type="hidden" name="closeDoc" value="0" />';
00999                 $formContent.='<input type="hidden" name="doSave" value="0" />';
01000                 $formContent.='<input type="hidden" name="_serialNumber" value="'.md5(microtime()).'" />';
01001                 $formContent.='<input type="hidden" name="_disableRTE" value="'.$this->tceforms->disableRTE.'" />';
01002 
01003                 return $formContent;
01004         }
01005 
01011         function functionMenus()        {
01012                 global $BE_USER,$LANG;
01013 
01014                 $funcMenus = '';
01015 
01016                         // Show palettes:
01017                 $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'=>''))),'id="checkShowPalettes"').'<label for="checkShowPalettes">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showPalettes',1).'</label>';
01018 
01019                         // Show descriptions/help texts:
01020                 if ($BE_USER->uc['edit_showFieldHelp']!='text') {
01021                         $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'=>''))),'id="checkShowDescriptions"').'<label for="checkShowDescriptions">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.showDescriptions',1).'</label>';
01022                 }
01023 
01024                         // Show disable RTE checkbox:
01025                 if ($BE_USER->isRTE())  {
01026                         $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'=>''))),'id="checkDisableRTE"').'<label for="checkDisableRTE">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.disableRTE',1).'</label>';
01027                 }
01028 
01029                 return '
01030 
01031                                 <!--
01032                                         Function menus (checkboxes for selecting options):
01033                                 -->
01034                                 '.$funcMenus;
01035         }
01036 
01042         function shortCutLink() {
01043                 global $BE_USER,$LANG;
01044 
01045                         // ShortCut
01046                 if ($this->returnUrl!='close.html')     {
01047                         $content.='<br /><br />';
01048 
01049                                 // Shortcut:
01050                         if ($BE_USER->mayMakeShortcut())        {
01051                                 $content.=$this->doc->makeShortcutIcon('returnUrl,edit,defVals,overrideVals,columnsOnly,returnNewPageId,editRegularContentFromId,disHelp,noView',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name'],1);
01052                         }
01053 
01054                                 // Open in new window:
01055                         $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;';
01056                         $content.='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
01057                                         '<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="" />'.
01058                                         '</a>';
01059                 }
01060                 return '
01061 
01062                                 <!--
01063                                         Shortcut link:
01064                                 -->
01065                                 '.$content;
01066         }
01067 
01073         function tceformMessages()      {
01074                 if (count($this->tceforms->commentMessages))    {
01075                         $this->content.='
01076 
01077 <!-- TCEFORM messages
01078 '.htmlspecialchars(implode(chr(10),$this->tceforms->commentMessages)).'
01079 -->
01080 
01081 ';
01082                 }
01083         }
01084 
01085 
01086 
01087 
01088 
01089 
01090 
01091 
01092 
01093 
01094 
01095 
01096 
01097         /***************************
01098          *
01099          * Localization stuff
01100          *
01101          ***************************/
01102 
01112         function languageSwitch($table, $uid, $pid=NULL)        {
01113                 global $TCA;
01114 
01115                 $content = '';
01116 
01117                 $languageField = $TCA[$table]['ctrl']['languageField'];
01118                 $transOrigPointerField = $TCA[$table]['ctrl']['transOrigPointerField'];
01119 
01120                         // table editable and activated for languages?
01121                 if ($GLOBALS['BE_USER']->check('tables_modify',$table) && $languageField && $transOrigPointerField && !$TCA[$table]['ctrl']['transOrigPointerTable'])   {
01122 
01123                         if(is_null($pid)) {
01124                                 $row = t3lib_befunc::getRecord($table, $uid, 'pid');
01125                                 $pid = $row['pid'];
01126                         }
01127 
01128                                 // get all avalibale languages for the page
01129                         $langRows = $this->getLanguages($pid);
01130 
01131                                 // page available in other languages than default language?
01132                         if (is_array($langRows) && count($langRows)>1) {
01133 
01134                                 $rowsByLang = array();
01135                                 $fetchFields = 'uid,'.$languageField.','.$transOrigPointerField;
01136 
01137                                         // get record in current language
01138                                 $rowCurrent = t3lib_befunc::getRecord($table, $uid, $fetchFields);
01139                                 $currentLanguage = $rowCurrent[$languageField];
01140 
01141                                 if ($currentLanguage>-1)        {       // Disabled for records with [all] language!
01142                                                 // get record in default language if needed
01143                                         if ($currentLanguage) {
01144                                                 $rowsByLang[0] = t3lib_befunc::getRecord($table, $rowCurrent[$transOrigPointerField], $fetchFields);
01145                                         } else {
01146                                                 $rowsByLang[0] = $rowCurrent;
01147                                         }
01148 
01149                                                 // get record in other languages to see what's already available
01150                                         $translations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
01151                                                 $fetchFields,
01152                                                 $table,
01153                                                 'pid='.intval($pid).
01154                                                         ' AND '.$languageField.'>0'.
01155                                                         ' AND '.$transOrigPointerField.'='.intval($rowsByLang[0]['uid']).
01156                                                         t3lib_BEfunc::deleteClause($table).
01157                                                         t3lib_BEfunc::versioningPlaceholderClause($table)
01158                                         );
01159                                         foreach ($translations as $row) {
01160                                                 $rowsByLang[$row[$languageField]] = $row;
01161                                         }
01162 
01163                                         $langSelItems=array();
01164                                         foreach ($langRows as $lang) {
01165                                                 if ($GLOBALS['BE_USER']->checkLanguageAccess($lang['uid']))     {
01166 
01167                                                         $newTranslation = isset($rowsByLang[$lang['uid']]) ? '' : ' ['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.new',1).']';
01168 
01169                                                                 // create url for creating a localized record
01170                                                         if($newTranslation) {
01171                                                                 $href = $this->doc->issueCommand(
01172                                                                         '&cmd['.$table.']['.$rowsByLang[0]['uid'].'][localize]='.$lang['uid'],
01173                                                                         $this->backPath.'alt_doc.php?justLocalized='.rawurlencode($table.':'.$rowsByLang[0]['uid'].':'.$lang['uid']).'&returnUrl='.rawurlencode($this->retUrl)
01174                                                                 );
01175 
01176                                                                 // create edit url
01177                                                         } else {
01178                                                                 $href = $this->backPath.'alt_doc.php?';
01179                                                                 $href .= '&edit['.$table.']['.$rowsByLang[$lang['uid']]['uid'].']=edit';
01180                                                                 $href .= '&returnUrl='.rawurlencode($this->retUrl);
01181                                                         }
01182 
01183                                                         $langSelItems[$lang['uid']]='
01184                                                                         <option value="'.htmlspecialchars($href).'"'.($currentLanguage==$lang['uid']?' selected="selected"':'').'>'.htmlspecialchars($lang['title'].$newTranslation).'</option>';
01185                                                 }
01186                                         }
01187 
01188                                                 // If any languages are left, make selector:
01189                                         if (count($langSelItems)>1)             {
01190                                                 $onChange = 'if(this.options[this.selectedIndex].value){window.location.href=(this.options[this.selectedIndex].value);}';
01191                                                 $content = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xml:LGL.language',1).' <select name="_langSelector" onchange="'.htmlspecialchars($onChange).'">
01192                                                                 '.implode('',$langSelItems).'
01193                                                         </select>';
01194                                         }
01195                                 }
01196                         }
01197                 }
01198                 return $content;
01199         }
01200 
01201 
01208         function localizationRedirect($justLocalized)   {
01209                 global $TCA;
01210 
01211                 list($table,$orig_uid,$language) = explode(':',$justLocalized);
01212 
01213                 if ($TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])     {
01214                         list($localizedRecord) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
01215                                         'uid',
01216                                         $table,
01217                                         $TCA[$table]['ctrl']['languageField'].'='.intval($language).' AND '.
01218                                                 $TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($orig_uid).
01219                                                 t3lib_BEfunc::deleteClause($table).
01220                                                 t3lib_BEfunc::versioningPlaceholderClause($table)
01221                                 );
01222 
01223                         if (is_array($localizedRecord)) {
01224                                         // Create parameters and finally run the classic page module for creating a new page translation
01225                                 $params = '&edit['.$table.']['.$localizedRecord['uid'].']=edit';
01226                                 $returnUrl = '&returnUrl='.rawurlencode(t3lib_div::_GP('returnUrl'));
01227                                 $location = $GLOBALS['BACK_PATH'].'alt_doc.php?'.$params.$returnUrl;
01228 
01229                                 header('Location: '.t3lib_div::locationHeaderUrl($location));
01230                                 exit;
01231                         }
01232                 }
01233         }
01234 
01235 
01242         function getLanguages($id)      {
01243                 global $LANG;
01244 
01245                 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($id, 'mod.SHARED');
01246 
01247                 $languages = array(
01248                         0 => array(
01249                                 'uid' => 0,
01250                                 'pid' => 0,
01251                                 'hidden' => 0,
01252                                 'title' => strlen($modSharedTSconfig['properties']['defaultLanguageLabel']) ? $modSharedTSconfig['properties']['defaultLanguageLabel'].' ('.$GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_web_list.xml:defaultLanguage').')' : $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_mod_web_list.xml:defaultLanguage'),
01253                                 'flag' => $modSharedTSconfig['properties']['defaultLanguageFlag'],
01254                         )
01255                 );
01256 
01257                 $exQ = $GLOBALS['BE_USER']->isAdmin() ? '' : ' AND sys_language.hidden=0';
01258                 if ($id)        {
01259                         $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
01260                                                         'sys_language.*',
01261                                                         'pages_language_overlay,sys_language',
01262                                                         'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid='.intval($id).$exQ,
01263                                                         'pages_language_overlay.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.static_lang_isocode,sys_language.flag',
01264                                                         'sys_language.title'
01265                                                 );
01266                 } else {
01267                         $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
01268                                                         'sys_language.*',
01269                                                         'sys_language',
01270                                                         'sys_language.hidden=0',
01271                                                         '',
01272                                                         'sys_language.title'
01273                                                 );
01274                 }
01275                 if ($rows) {
01276                         foreach ($rows as $row) {
01277                                 $languages[$row['uid']] = $row;
01278                         }
01279                 }
01280                 return $languages;
01281         }
01282 
01283 
01284 
01285 
01286 
01287 
01288 
01289 
01290 
01291 
01292         /***************************
01293          *
01294          * Other functions
01295          *
01296          ***************************/
01297 
01304         function fixWSversioningInEditConf($mapArray=FALSE)     {
01305                 global $TCA,$BE_USER;
01306 
01307                         // Traverse the editConf array
01308                 if (is_array($this->editconf))  {
01309                         foreach($this->editconf as $table => $conf)     {       // Tables:
01310                                 if (is_array($conf) && $TCA[$table])    {
01311 
01312                                                 // Traverse the keys/comments of each table (keys can be a commalist of uids)
01313                                         $newConf = array();
01314                                         foreach($conf as $cKey => $cmd) {
01315                                                 if ($cmd=='edit')       {
01316                                                                 // Traverse the ids:
01317                                                         $ids = t3lib_div::trimExplode(',', $cKey, 1);
01318                                                         foreach($ids as $idKey => $theUid)      {
01319                                                                 if (is_array($mapArray))        {
01320                                                                         if ($mapArray[$table][$theUid]) {
01321                                                                                 $ids[$idKey] = $mapArray[$table][$theUid];
01322                                                                         }
01323                                                                 } else {        // Default, look for versions in workspace for record:
01324                                                                         $calcPRec = $this->getRecordForEdit($table,$theUid);
01325                                                                         if (is_array($calcPRec))        {
01326                                                                                         // Setting UID again if it had changed, eg. due to workspace versioning.
01327                                                                                 $ids[$idKey] = $calcPRec['uid'];
01328                                                                         }
01329                                                                 }
01330         #else unset($ids[$idKey]);
01331                                                         }
01332 
01333                                                                 // Add the possibly manipulated IDs to the new-build newConf array:
01334                                                         $newConf[implode(',',$ids)] = $cmd;
01335                                                 } else {
01336                                                         $newConf[$cKey] = $cmd;
01337                                                 }
01338                                         }
01339                                                 // Store the new conf array:
01340                                         $this->editconf[$table] = $newConf;
01341                                 }
01342                         }
01343                 }
01344         }
01345 
01353         function getRecordForEdit($table,$theUid)       {
01354                 global $TCA;
01355 
01356                         // Fetch requested record:
01357                 $reqRecord = t3lib_BEfunc::getRecord($table,$theUid,'uid,pid');
01358 
01359                 if (is_array($reqRecord))       {
01360                                 // If workspace is OFFLINE:
01361                         if ($GLOBALS['BE_USER']->workspace!=0)  {
01362 
01363                                         // Check for versioning support of the table:
01364                                 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS'])       {
01365 
01366                                                 // If the record is already a version of "something" pass it by.
01367                                         if ($reqRecord['pid']==-1)      {
01368 
01369                                                         // (If it turns out not to be a version of the current workspace there will be trouble, but that is handled inside TCEmain then and in the interface it would clearly be an error of links if the user accesses such a scenario)
01370                                                 return $reqRecord;
01371                                         } else {        // The input record was online and an offline version must be found or made:
01372 
01373                                                         // Look for version of this workspace:
01374                                                 $versionRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $reqRecord['uid'],'uid,pid,t3ver_oid');
01375                                                 return is_array($versionRec) ? $versionRec : $reqRecord;
01376                                         }
01377                                 } else return FALSE;            // This means that editing cannot occur on this record because it was not supporting versioning which is required inside an offline workspace.
01378                         } else return $reqRecord;       // In ONLINE workspace, just return the originally requested record:
01379                 } else return FALSE;    // Return false because the table/uid was not found anyway.
01380         }
01381 
01387         function editRegularContentFromId()     {
01388                 if (t3lib_extMgm::isLoaded('cms'))      {
01389                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01390                                                 'uid',
01391                                                 'tt_content',
01392                                                 'pid='.intval($this->editRegularContentFromId).
01393                                                         t3lib_BEfunc::deleteClause('tt_content').
01394                                                         t3lib_BEfunc::versioningPlaceholderClause('tt_content').
01395                                                         ' AND colPos=0 AND sys_language_uid=0',
01396                                                 '',
01397                                                 'sorting'
01398                                         );
01399                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
01400                                 $ecUids=array();
01401                                 while($ecRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))     {
01402                                         $ecUids[]=$ecRec['uid'];
01403                                 }
01404                                 $this->editconf['tt_content'][implode(',',$ecUids)]='edit';
01405                         }
01406                 }
01407         }
01408 
01415         function compileStoreDat()      {
01416                 $this->storeArray = t3lib_div::compileSelectedGetVarsFromArray('edit,defVals,overrideVals,columnsOnly,disHelp,noView,editRegularContentFromId',$this->R_URL_getvars);
01417                 $this->storeUrl = t3lib_div::implodeArrayForUrl('',$this->storeArray);
01418                 $this->storeUrlMd5 = md5($this->storeUrl);
01419         }
01420 
01428         function getNewIconMode($table,$key='saveDocNew')       {
01429                 global $BE_USER;
01430                 $TSconfig = $BE_USER->getTSConfig('options.'.$key);
01431                 $output = trim(isset($TSconfig['properties'][$table]) ? $TSconfig['properties'][$table] : $TSconfig['value']);
01432                 return $output;
01433         }
01434 
01441         function closeDocument($code=0) {
01442                 global $BE_USER;
01443 
01444                         // If current document is found in docHandler, then unset it, possibly unset it ALL and finally, write it to the session data:
01445                 if (isset($this->docHandler[$this->storeUrlMd5]))       {
01446                         unset($this->docHandler[$this->storeUrlMd5]);
01447                         if ($code=='3') $this->docHandler=array();
01448                         $BE_USER->pushModuleData('alt_doc.php',array($this->docHandler,$this->docDat[1]));
01449                 }
01450 
01451                         // 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...)
01452                 if ($this->returnEditConf && $this->retUrl!='dummy.php')        {
01453                         $this->retUrl.='&returnEditConf='.rawurlencode(serialize($this->editconf));
01454                 }
01455 
01456                         // If code is NOT set OR set to 1, then make a header location redirect to $this->retUrl
01457                 if (!$code || $code==1) {
01458                         Header('Location: '.t3lib_div::locationHeaderUrl($this->retUrl));
01459                         exit;
01460                 } else {
01461                         $this->setDocument('',$this->retUrl);
01462                 }
01463         }
01464 
01473         function setDocument($currentDocFromHandlerMD5='',$retUrl='alt_doc_nodoc.php')  {
01474                 if (!t3lib_extMgm::isLoaded('cms') && !strcmp($retUrl,'alt_doc_nodoc.php'))     return;
01475 
01476                 if (!$this->modTSconfig['properties']['disableDocSelector'] && is_array($this->docHandler) && count($this->docHandler)) {
01477                         if (isset($this->docHandler[$currentDocFromHandlerMD5]))        {
01478                                 $setupArr=$this->docHandler[$currentDocFromHandlerMD5];
01479                         } else {
01480                                 reset($this->docHandler);
01481                                 $setupArr=current($this->docHandler);
01482                         }
01483                         if ($setupArr[2])       {
01484                                 $sParts = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
01485                                 $retUrl = $sParts['path'].'?'.$setupArr[2].'&returnUrl='.rawurlencode($retUrl);
01486                         }
01487                 }
01488                 Header('Location: '.t3lib_div::locationHeaderUrl($retUrl));
01489                 exit;
01490         }
01491 }
01492 
01493 // Include extension?
01494 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_doc.php'])       {
01495         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_doc.php']);
01496 }
01497 
01498 
01499 
01500 
01501 
01502 
01503 
01504 
01505 
01506 
01507 
01508 
01509 
01510 
01511 
01512 
01513 // Make instance:
01514 $SOBE = t3lib_div::makeInstance('SC_alt_doc');
01515 
01516 // Preprocessing, storing data if submitted to
01517 $SOBE->preInit();
01518 if ($SOBE->doProcessData())     {               // Checks, if a save button has been clicked (or the doSave variable is sent)
01519         $SOBE->processData();
01520 }
01521 
01522 
01523 // Main:
01524 $SOBE->init();
01525 $SOBE->main();
01526 $SOBE->printContent();
01527 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6