TYPO3 API  SVNRelease
wizard_add.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (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 ***************************************************************/
00027 /**
00028  * Wizard to add new records to a group/select TCEform formfield
00029  *
00030  * $Id: wizard_add.php 10121 2011-01-18 20:15:30Z ohader $
00031  * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
00032  *
00033  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *   75: class SC_wizard_add
00041  *  104:     function init()
00042  *  157:     function main()
00043  *
00044  * TOTAL FUNCTIONS: 2
00045  * (This index is automatically created/updated by the extension "extdeveval")
00046  *
00047  */
00048 
00049 
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 /**
00068  * Script Class for adding new items to a group/select field. Performs proper redirection as needed.
00069  *
00070  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00071  * @package TYPO3
00072  * @subpackage core
00073  */
00074 class SC_wizard_add {
00075 
00076         // Internal, dynamic:
00077     var $content;               // Content accumulation for the module.
00078     var $include_once=array();  // List of files to include.
00079 
00080     var $processDataFlag=0;     // If set, the TCEmain class is loaded and used to add the returning ID to the parent record.
00081 
00082         // Internal, static:
00083     var $pid;                   // Create new record -pid (pos/neg). If blank, return immediately
00084     var $table;                 // The parent table we are working on.
00085     var $id;                    // Loaded with the created id of a record when TCEforms (alt_doc.php) returns ...
00086 
00087         // Internal, static: GPvars
00088     var $P;                     // Wizard parameters, coming from TCEforms linking to the wizard.
00089     var $returnEditConf;        // Information coming back from alt_doc.php script, telling what the table/id was of the newly created record.
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098     /**
00099      * Initialization of the class.
00100      *
00101      * @return  void
00102      */
00103     function init() {
00104 
00105             // Init GPvars:
00106         $this->P = t3lib_div::_GP('P');
00107         $this->returnEditConf = t3lib_div::_GP('returnEditConf');
00108 
00109             // Get this record
00110         $origRow = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
00111 
00112             // Set table:
00113         $this->table = $this->P['params']['table'];
00114 
00115             // Get TSconfig for it.
00116         $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->P['table'],is_array($origRow)?$origRow:array('pid'=>$this->P['pid']));
00117 
00118             // Set [params][pid]
00119         if (substr($this->P['params']['pid'],0,3)=='###' && substr($this->P['params']['pid'],-3)=='###')    {
00120             $this->pid = intval($TSconfig['_'.substr($this->P['params']['pid'],3,-3)]);
00121         } else $this->pid = intval($this->P['params']['pid']);
00122 
00123             // Return if new record as parent (not possibly/allowed)
00124         if (!strcmp($this->pid,'')) {
00125             t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
00126         }
00127 
00128             // Else proceed:
00129         if ($this->returnEditConf)  {   // If a new id has returned from a newly created record...
00130             $eC = unserialize($this->returnEditConf);
00131             if (is_array($eC[$this->table]) && t3lib_div::testInt($this->P['uid'])) {
00132 
00133                     // Getting id and cmd from returning editConf array.
00134                 reset($eC[$this->table]);
00135                 $this->id = intval(key($eC[$this->table]));
00136                 $cmd = current($eC[$this->table]);
00137 
00138                     // ... and if everything seems OK we will register some classes for inclusion and instruct the object to perform processing later.
00139                 if ($this->P['params']['setValue'] && $cmd=='edit' && $this->id && $this->P['table'] && $this->P['field'] && $this->P['uid'])   {
00140 
00141                     if ($LiveRec=t3lib_BEfunc::getLiveVersionOfRecord($this->table, $this->id, 'uid'))  { $this->id=$LiveRec['uid'];}
00142 
00143 
00144                     $this->include_once[]=PATH_t3lib.'class.t3lib_loaddbgroup.php';
00145                     $this->include_once[]=PATH_t3lib.'class.t3lib_transferdata.php';
00146                     $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
00147                     $this->processDataFlag=1;
00148                 }
00149             }
00150         }
00151     }
00152 
00153     /**
00154      * Main function
00155      * Will issue a location-header, redirecting either BACK or to a new alt_doc.php instance...
00156      *
00157      * @return  void
00158      */
00159     function main() {
00160 
00161         if ($this->returnEditConf)  {
00162             if ($this->processDataFlag) {
00163 
00164                     // Preparing the data of the parent record...:
00165                 $trData = t3lib_div::makeInstance('t3lib_transferData');
00166                 $trData->fetchRecord($this->P['table'],$this->P['uid'],''); // 'new'
00167                 reset($trData->regTableItems_data);
00168                 $current = current($trData->regTableItems_data);
00169 
00170                     // If that record was found (should absolutely be...), then init TCEmain and set, prepend or append the record
00171                 if (is_array($current)) {
00172                     $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00173                     $tce->stripslashes_values=0;
00174                     $data = array();
00175                     $addEl = $this->table.'_'.$this->id;
00176 
00177                         // Setting the new field data:
00178                     if ($this->P['flexFormPath'])   {   // If the field is a flexform field, work with the XML structure instead:
00179 
00180                         $currentFlexFormData = t3lib_div::xml2array($current[$this->P['field']]); // Current value of flexform path:
00181                         $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
00182                         $curValueOfFlexform = $flexToolObj->getArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData);
00183                         $insertValue = '';
00184 
00185                         switch((string)$this->P['params']['setValue'])  {
00186                             case 'set':
00187                                 $insertValue = $addEl;
00188                             break;
00189                             case 'prepend':
00190                                 $insertValue = $curValueOfFlexform.','.$addEl;
00191                             break;
00192                             case 'append':
00193                                 $insertValue = $addEl.','.$curValueOfFlexform;
00194                             break;
00195                         }
00196                         $insertValue = implode(',',t3lib_div::trimExplode(',',$insertValue,1));
00197 
00198                         $data[$this->P['table']][$this->P['uid']][$this->P['field']] = array();
00199                         $flexToolObj->setArrayValueByPath($this->P['flexFormPath'],$data[$this->P['table']][$this->P['uid']][$this->P['field']],$insertValue);
00200                     } else {
00201                         switch((string)$this->P['params']['setValue'])  {
00202                             case 'set':
00203                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl;
00204                             break;
00205                             case 'prepend':
00206                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $current[$this->P['field']].','.$addEl;
00207                             break;
00208                             case 'append':
00209                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl.','.$current[$this->P['field']];
00210                             break;
00211                         }
00212                         $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));
00213                     }
00214 
00215                         // Submit the data:
00216                     $tce->start($data,array());
00217                     $tce->process_datamap();
00218                 }
00219             }
00220                 // Return to the parent alt_doc.php record editing session:
00221             t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
00222         } else {
00223                 // Redirecting to alt_doc.php with instructions to create a new record
00224                 // AND when closing to return back with information about that records ID etc.
00225             $redirectUrl = 'alt_doc.php?returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) . '&returnEditConf=1&edit[' . $this->P['params']['table'] . '][' . $this->pid . ']=new';
00226             t3lib_utility_Http::redirect($redirectUrl);
00227         }
00228     }
00229 }
00230 
00231 
00232 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/wizard_add.php'])) {
00233     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/wizard_add.php']);
00234 }
00235 
00236 
00237 
00238 // Make instance:
00239 $SOBE = t3lib_div::makeInstance('SC_wizard_add');
00240 $SOBE->init();
00241 
00242 // Include files?
00243 foreach($SOBE->include_once as $INC_FILE)   include_once($INC_FILE);
00244 
00245 $SOBE->main();
00246 
00247 ?>