[TASK] Remove require statements for classes
[Packages/TYPO3.CMS.git] / typo3 / wizard_add.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 /**
29 * Wizard to add new records to a group/select TCEform formfield
30 *
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36 $BACK_PATH = '';
37 require('init.php');
38 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
39
40 /**
41 * Script Class for adding new items to a group/select field. Performs proper redirection as needed.
42 *
43 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 * @package TYPO3
45 * @subpackage core
46 */
47 class SC_wizard_add {
48
49 // Internal, dynamic:
50 // Content accumulation for the module.
51 var $content;
52 // List of files to include.
53 var $include_once = array();
54 // If set, the TCEmain class is loaded and used to add the returning ID to the parent record.
55 var $processDataFlag = 0;
56
57 // Internal, static:
58 // Create new record -pid (pos/neg). If blank, return immediately
59 var $pid;
60 // The parent table we are working on.
61 var $table;
62 // Loaded with the created id of a record when TCEforms (alt_doc.php) returns ...
63 var $id;
64
65 // Internal, static: GPvars
66 // Wizard parameters, coming from TCEforms linking to the wizard.
67 var $P;
68 // Information coming back from alt_doc.php script, telling what the table/id was of the newly created record.
69 var $returnEditConf;
70
71 /**
72 * Initialization of the class.
73 *
74 * @return void
75 */
76 function init() {
77
78 // Init GPvars:
79 $this->P = t3lib_div::_GP('P');
80 $this->returnEditConf = t3lib_div::_GP('returnEditConf');
81
82 // Get this record
83 $origRow = t3lib_BEfunc::getRecord($this->P['table'], $this->P['uid']);
84
85 // Set table:
86 $this->table = $this->P['params']['table'];
87
88 // Get TSconfig for it.
89 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->P['table'], is_array($origRow)?$origRow:array('pid'=>$this->P['pid']));
90
91 // Set [params][pid]
92 if (substr($this->P['params']['pid'], 0, 3) == '###' && substr($this->P['params']['pid'], -3)=='###') {
93 $this->pid = intval($TSconfig['_'.substr($this->P['params']['pid'], 3, -3)]);
94 } else $this->pid = intval($this->P['params']['pid']);
95
96 // Return if new record as parent (not possibly/allowed)
97 if (!strcmp($this->pid, '')) {
98 t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
99 }
100
101 // Else proceed:
102 // If a new id has returned from a newly created record...
103 if ($this->returnEditConf) {
104 $eC = unserialize($this->returnEditConf);
105 if (is_array($eC[$this->table]) && t3lib_utility_Math::canBeInterpretedAsInteger($this->P['uid'])) {
106
107 // Getting id and cmd from returning editConf array.
108 reset($eC[$this->table]);
109 $this->id = intval(key($eC[$this->table]));
110 $cmd = current($eC[$this->table]);
111
112 // ... and if everything seems OK we will register some classes for inclusion and instruct the object to perform processing later.
113 if ($this->P['params']['setValue'] && $cmd=='edit' && $this->id && $this->P['table'] && $this->P['field'] && $this->P['uid']) {
114
115 if ($LiveRec = t3lib_BEfunc::getLiveVersionOfRecord($this->table, $this->id, 'uid')) {
116 $this->id=$LiveRec['uid'];
117 }
118 $this->processDataFlag = 1;
119 }
120 }
121 }
122 }
123
124 /**
125 * Main function
126 * Will issue a location-header, redirecting either BACK or to a new alt_doc.php instance...
127 *
128 * @return void
129 */
130 function main() {
131
132 if ($this->returnEditConf) {
133 if ($this->processDataFlag) {
134
135 // Preparing the data of the parent record...:
136 $trData = t3lib_div::makeInstance('t3lib_transferData');
137 // 'new'
138 $trData->fetchRecord($this->P['table'], $this->P['uid'], '');
139 $current = reset($trData->regTableItems_data);
140
141 // If that record was found (should absolutely be...), then init TCEmain and set, prepend or append the record
142 if (is_array($current)) {
143 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
144 $tce->stripslashes_values = 0;
145 $data = array();
146 $addEl = $this->table.'_'.$this->id;
147
148 // Setting the new field data:
149 // If the field is a flexform field, work with the XML structure instead:
150 if ($this->P['flexFormPath']) {
151 // Current value of flexform path:
152 $currentFlexFormData = t3lib_div::xml2array($current[$this->P['field']]);
153 $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
154 $curValueOfFlexform = $flexToolObj->getArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData);
155 $insertValue = '';
156
157 switch((string)$this->P['params']['setValue']) {
158 case 'set':
159 $insertValue = $addEl;
160 break;
161 case 'prepend':
162 $insertValue = $curValueOfFlexform.','.$addEl;
163 break;
164 case 'append':
165 $insertValue = $addEl.','.$curValueOfFlexform;
166 break;
167 }
168 $insertValue = implode(',', t3lib_div::trimExplode(',', $insertValue, 1));
169
170 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = array();
171 $flexToolObj->setArrayValueByPath($this->P['flexFormPath'], $data[$this->P['table']][$this->P['uid']][$this->P['field']], $insertValue);
172 } else {
173 switch((string)$this->P['params']['setValue']) {
174 case 'set':
175 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl;
176 break;
177 case 'prepend':
178 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $current[$this->P['field']].','.$addEl;
179 break;
180 case 'append':
181 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $addEl.','.$current[$this->P['field']];
182 break;
183 }
184 $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));
185 }
186
187 // Submit the data:
188 $tce->start($data, array());
189 $tce->process_datamap();
190 }
191 }
192 // Return to the parent alt_doc.php record editing session:
193 t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
194 } else {
195 // Redirecting to alt_doc.php with instructions to create a new record
196 // AND when closing to return back with information about that records ID etc.
197 $redirectUrl = 'alt_doc.php?returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) . '&returnEditConf=1&edit[' . $this->P['params']['table'] . '][' . $this->pid . ']=new';
198 t3lib_utility_Http::redirect($redirectUrl);
199 }
200 }
201 }
202
203 // Make instance:
204 $SOBE = t3lib_div::makeInstance('SC_wizard_add');
205 $SOBE->init();
206
207 // Include files?
208 foreach ($SOBE->include_once as $INC_FILE) {
209 include_once($INC_FILE);
210 }
211
212 $SOBE->main();
213
214 ?>