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