Documentation TYPO3 par Ameos

wizard_add.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 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 ***************************************************************/
00050 $BACK_PATH = '';
00051 require ('init.php');
00052 require ('template.php');
00053 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00075 class SC_wizard_add {
00076 
00077                 // Internal, dynamic:
00078         var $content;                           // Content accumulation for the module.
00079         var $include_once=array();      // List of files to include.
00080 
00081         var $processDataFlag=0;         // If set, the TCEmain class is loaded and used to add the returning ID to the parent record.
00082 
00083                 // Internal, static:
00084         var $pid;                                       // Create new record -pid (pos/neg). If blank, return immediately
00085         var $table;                                     // The parent table we are working on.
00086         var $id;                                        // Loaded with the created id of a record when TCEforms (alt_doc.php) returns ...
00087 
00088                 // Internal, static: GPvars
00089         var $P;                                         // Wizard parameters, coming from TCEforms linking to the wizard.
00090         var $returnEditConf;            // Information coming back from alt_doc.php script, telling what the table/id was of the newly created record.
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00104         function init() {
00105 
00106                         // Init GPvars:
00107                 $this->P = t3lib_div::_GP('P');
00108                 $this->returnEditConf = t3lib_div::_GP('returnEditConf');
00109 
00110                         // Get this record
00111                 $origRow = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
00112 
00113                         // Set table:
00114                 $this->table = $this->P['params']['table'];
00115 
00116                         // Get TSconfig for it.
00117                 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->table,is_array($origRow)?$origRow:array('pid'=>$this->P['pid']));
00118 
00119                         // Set [params][pid]
00120                 if (substr($this->P['params']['pid'],0,3)=='###' && substr($this->P['params']['pid'],-3)=='###')        {
00121                         $this->pid = intval($TSconfig['_'.substr($this->P['params']['pid'],3,-3)]);
00122                 } else $this->pid = intval($this->P['params']['pid']);
00123 
00124                         // Return if new record as parent (not possibly/allowed)
00125                 if (!strcmp($this->pid,''))     {
00126                         header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
00127                         exit;
00128                 }
00129 
00130                         // Else proceed:
00131                 if ($this->returnEditConf)      {       // If a new id has returned from a newly created record...
00132                         $eC = unserialize($this->returnEditConf);
00133                         if (is_array($eC[$this->table]) && t3lib_div::testInt($this->P['uid'])) {
00134 
00135                                         // Getting id and cmd from returning editConf array.
00136                                 reset($eC[$this->table]);
00137                                 $this->id = intval(key($eC[$this->table]));
00138                                 $cmd = current($eC[$this->table]);
00139 
00140                                         // ... and if everything seems OK we will register some classes for inclusion and instruct the object to perform processing later.
00141                                 if ($this->P['params']['setValue'] && $cmd=='edit' && $this->id && $this->P['table'] && $this->P['field'] && $this->P['uid'])   {
00142                                         $this->include_once[]=PATH_t3lib.'class.t3lib_loaddbgroup.php';
00143                                         $this->include_once[]=PATH_t3lib.'class.t3lib_transferdata.php';
00144                                         $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
00145                                         $this->processDataFlag=1;
00146                                 }
00147                         }
00148                 }
00149         }
00150 
00157         function main() {
00158 
00159                 if ($this->returnEditConf)      {
00160                         if ($this->processDataFlag)     {
00161 
00162                                         // Preparing the data of the parent record...:
00163                                 $trData = t3lib_div::makeInstance('t3lib_transferData');
00164                                 $trData->fetchRecord($this->P['table'],$this->P['uid'],'');     // 'new'
00165                                 reset($trData->regTableItems_data);
00166                                 $current = current($trData->regTableItems_data);
00167 
00168                                         // If that record was found (should absolutely be...), then init TCEmain and set, prepend or append the record
00169                                 if (is_array($current)) {
00170                                         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00171                                         $tce->stripslashes_values=0;
00172                                         $data=array();
00173                                         $addEl = $this->table.'_'.$this->id;
00174                                         switch((string)$this->P['params']['setValue'])  {
00175                                                 case 'set':
00176                                                         $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl;
00177                                                 break;
00178                                                 case 'prepend':
00179                                                         $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $current[$this->P['field']].','.$addEl;
00180                                                 break;
00181                                                 case 'append':
00182                                                         $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl.','.$current[$this->P['field']];
00183                                                 break;
00184                                         }
00185 
00186                                                 // Setting the new field data:
00187                                         $data[$this->P['table']][$this->P['uid']][$this->P['field']] = implode(',',t3lib_div::trimExplode(',',$data[$this->P['table']][$this->P['uid']][$this->P['field']],1));
00188 
00189                                                 // Submit the data:
00190                                         $tce->start($data,array());
00191                                         $tce->process_datamap();
00192                                 }
00193                         }
00194                                 // Return to the parent alt_doc.php record editing session:
00195                         header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
00196                 } else {
00197                                 // Redirecting to alt_doc.php with instructions to create a new record AND when closing to return back with information about that records ID etc.
00198                         header('Location: '.t3lib_div::locationHeaderUrl('alt_doc.php?returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).'&returnEditConf=1&edit['.$this->P['params']['table'].']['.$this->pid.']=new'));
00199                 }
00200         }
00201 }
00202 
00203 // Include extension?
00204 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_add.php'])    {
00205         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_add.php']);
00206 }
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 // Make instance:
00220 $SOBE = t3lib_div::makeInstance('SC_wizard_add');
00221 $SOBE->init();
00222 
00223 // Include files?
00224 foreach($SOBE->include_once as $INC_FILE)       include_once($INC_FILE);
00225 
00226 $SOBE->main();
00227 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6