Fixed bug #14336: Merge modules "Cleanup and typo3temp/" of the Install Tool (thanks...
[Packages/TYPO3.CMS.git] / typo3 / wizard_add.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Wizard to add new records to a group/select TCEform formfield
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 *
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 75: class SC_wizard_add
41 * 104: function init()
42 * 157: function main()
43 *
44 * TOTAL FUNCTIONS: 2
45 * (This index is automatically created/updated by the extension "extdeveval")
46 *
47 */
48
49
50 $BACK_PATH = '';
51 require ('init.php');
52 require ('template.php');
53 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
54
55
56
57
58
59
60
61
62
63
64
65
66
67 /**
68 * Script Class for adding new items to a group/select field. Performs proper redirection as needed.
69 *
70 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
71 * @package TYPO3
72 * @subpackage core
73 */
74 class SC_wizard_add {
75
76 // Internal, dynamic:
77 var $content; // Content accumulation for the module.
78 var $include_once=array(); // List of files to include.
79
80 var $processDataFlag=0; // If set, the TCEmain class is loaded and used to add the returning ID to the parent record.
81
82 // Internal, static:
83 var $pid; // Create new record -pid (pos/neg). If blank, return immediately
84 var $table; // The parent table we are working on.
85 var $id; // Loaded with the created id of a record when TCEforms (alt_doc.php) returns ...
86
87 // Internal, static: GPvars
88 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
89 var $returnEditConf; // Information coming back from alt_doc.php script, telling what the table/id was of the newly created record.
90
91
92
93
94
95
96
97
98 /**
99 * Initialization of the class.
100 *
101 * @return void
102 */
103 function init() {
104
105 // Init GPvars:
106 $this->P = t3lib_div::_GP('P');
107 $this->returnEditConf = t3lib_div::_GP('returnEditConf');
108
109 // Get this record
110 $origRow = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
111
112 // Set table:
113 $this->table = $this->P['params']['table'];
114
115 // Get TSconfig for it.
116 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->P['table'],is_array($origRow)?$origRow:array('pid'=>$this->P['pid']));
117
118 // Set [params][pid]
119 if (substr($this->P['params']['pid'],0,3)=='###' && substr($this->P['params']['pid'],-3)=='###') {
120 $this->pid = intval($TSconfig['_'.substr($this->P['params']['pid'],3,-3)]);
121 } else $this->pid = intval($this->P['params']['pid']);
122
123 // Return if new record as parent (not possibly/allowed)
124 if (!strcmp($this->pid,'')) {
125 t3lib_utility_Http::redirect($this->P['returnUrl']);
126 }
127
128 // Else proceed:
129 if ($this->returnEditConf) { // If a new id has returned from a newly created record...
130 $eC = unserialize($this->returnEditConf);
131 if (is_array($eC[$this->table]) && t3lib_div::testInt($this->P['uid'])) {
132
133 // Getting id and cmd from returning editConf array.
134 reset($eC[$this->table]);
135 $this->id = intval(key($eC[$this->table]));
136 $cmd = current($eC[$this->table]);
137
138 // ... and if everything seems OK we will register some classes for inclusion and instruct the object to perform processing later.
139 if ($this->P['params']['setValue'] && $cmd=='edit' && $this->id && $this->P['table'] && $this->P['field'] && $this->P['uid']) {
140
141 if ($LiveRec=t3lib_BEfunc::getLiveVersionOfRecord($this->table, $this->id, 'uid')) { $this->id=$LiveRec['uid'];}
142
143
144 $this->include_once[]=PATH_t3lib.'class.t3lib_loaddbgroup.php';
145 $this->include_once[]=PATH_t3lib.'class.t3lib_transferdata.php';
146 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
147 $this->processDataFlag=1;
148 }
149 }
150 }
151 }
152
153 /**
154 * Main function
155 * Will issue a location-header, redirecting either BACK or to a new alt_doc.php instance...
156 *
157 * @return void
158 */
159 function main() {
160
161 if ($this->returnEditConf) {
162 if ($this->processDataFlag) {
163
164 // Preparing the data of the parent record...:
165 $trData = t3lib_div::makeInstance('t3lib_transferData');
166 $trData->fetchRecord($this->P['table'],$this->P['uid'],''); // 'new'
167 reset($trData->regTableItems_data);
168 $current = current($trData->regTableItems_data);
169
170 // If that record was found (should absolutely be...), then init TCEmain and set, prepend or append the record
171 if (is_array($current)) {
172 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
173 $tce->stripslashes_values=0;
174 $data = array();
175 $addEl = $this->table.'_'.$this->id;
176
177 // Setting the new field data:
178 if ($this->P['flexFormPath']) { // If the field is a flexform field, work with the XML structure instead:
179
180 $currentFlexFormData = t3lib_div::xml2array($current[$this->P['field']]); // Current value of flexform path:
181 $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
182 $curValueOfFlexform = $flexToolObj->getArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData);
183 $insertValue = '';
184
185 switch((string)$this->P['params']['setValue']) {
186 case 'set':
187 $insertValue = $addEl;
188 break;
189 case 'prepend':
190 $insertValue = $curValueOfFlexform.','.$addEl;
191 break;
192 case 'append':
193 $insertValue = $addEl.','.$curValueOfFlexform;
194 break;
195 }
196 $insertValue = implode(',',t3lib_div::trimExplode(',',$insertValue,1));
197
198 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = array();
199 $flexToolObj->setArrayValueByPath($this->P['flexFormPath'],$data[$this->P['table']][$this->P['uid']][$this->P['field']],$insertValue);
200 } else {
201 switch((string)$this->P['params']['setValue']) {
202 case 'set':
203 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl;
204 break;
205 case 'prepend':
206 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $current[$this->P['field']].','.$addEl;
207 break;
208 case 'append':
209 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl.','.$current[$this->P['field']];
210 break;
211 }
212 $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));
213 }
214
215 // Submit the data:
216 $tce->start($data,array());
217 $tce->process_datamap();
218 }
219 }
220 // Return to the parent alt_doc.php record editing session:
221 t3lib_utility_Http::redirect($this->P['returnUrl']);
222 } else {
223 // Redirecting to alt_doc.php with instructions to create a new record
224 // AND when closing to return back with information about that records ID etc.
225 $redirectUrl = 'alt_doc.php?returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) . '&returnEditConf=1&edit[' . $this->P['params']['table'] . '][' . $this->pid . ']=new';
226 t3lib_utility_Http::redirect($redirectUrl);
227 }
228 }
229 }
230
231
232 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_add.php']) {
233 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_add.php']);
234 }
235
236
237
238 // Make instance:
239 $SOBE = t3lib_div::makeInstance('SC_wizard_add');
240 $SOBE->init();
241
242 // Include files?
243 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
244
245 $SOBE->main();
246
247 ?>