Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[Packages/TYPO3.CMS.git] / typo3 / wizard_add.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skaarhoj (kasper@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 table
29 *
30 * $Id$
31 *
32 * @author Kasper Skaarhoj <kasper@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 *
38 *
39 * 74: class SC_wizard_add
40 * 88: function init()
41 * 134: function main()
42 *
43 * TOTAL FUNCTIONS: 2
44 * (This index is automatically created/updated by the extension "extdeveval")
45 *
46 */
47
48
49 $BACK_PATH='';
50 require ('init.php');
51 require ('template.php');
52 include ('sysext/lang/locallang_wizards.php');
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 /**
68 * Script Class
69 *
70 * @author Kasper Skaarhoj <kasper@typo3.com>
71 * @package TYPO3
72 * @subpackage core
73 */
74 class SC_wizard_add {
75 var $include_once=array();
76 var $content;
77
78 var $returnEditConf;
79 var $processDataFlag=0;
80 var $P;
81 var $pid;
82 var $table;
83 var $id;
84
85 /**
86 * @return [type] ...
87 */
88 function init() {
89 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
90
91 $this->P = t3lib_div::GPvar('P',1);
92 //debug($this->P);
93
94 // Get this record
95 $origRow = t3lib_BEfunc::getRecord($this->P["table"],$this->P["uid"]);
96
97 // Get TSconfig for it.
98 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->table,is_array($origRow)?$origRow:array("pid"=>$this->P["pid"]));
99 // Set [params][pid]
100 if (substr($this->P["params"]["pid"],0,3)=="###" && substr($this->P["params"]["pid"],-3)=="###") {
101 $this->pid = intval($TSconfig["_".substr($this->P["params"]["pid"],3,-3)]);
102 } else $this->pid = intval($this->P["params"]["pid"]);
103
104 // Return if new record
105 if (!strcmp($this->pid,"")) {
106 header("Location: ".t3lib_div::locationHeaderUrl($this->P["returnUrl"]));
107 exit;
108 }
109
110 // Else proceed.
111 $this->returnEditConf = t3lib_div::GPvar("returnEditConf");
112 if ($this->returnEditConf) {
113 $eC = unserialize(t3lib_div::GPvar("returnEditConf"));
114 $this->table = $this->P["params"]["table"];
115 if (is_array($eC[$this->table]) && t3lib_div::testInt($this->P["uid"])) {
116 reset($eC[$this->table]);
117 $this->id = intval(key($eC[$this->table]));
118 $cmd = current($eC[$this->table]);
119 if ($this->P["params"]["setValue"] && $cmd=="edit" && $this->id && $this->P["table"] && $this->P["field"] && $this->P["uid"]) {
120 $this->include_once[]=PATH_t3lib."class.t3lib_loaddbgroup.php";
121 $this->include_once[]=PATH_t3lib."class.t3lib_transferdata.php";
122 $this->include_once[]=PATH_t3lib."class.t3lib_tcemain.php";
123 $this->processDataFlag=1;
124 }
125 }
126 }
127 }
128
129 /**
130 * [Describe function...]
131 *
132 * @return [type] ...
133 */
134 function main() {
135 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
136
137
138
139 // Else proceed.
140 if ($this->returnEditConf) {
141 if ($this->processDataFlag) {
142 $trData = t3lib_div::makeInstance("t3lib_transferData");
143 $trData->fetchRecord($this->P["table"],$this->P["uid"],""); // "new"
144 reset($trData->regTableItems_data);
145 $current = current($trData->regTableItems_data);
146
147 if (is_array($current)) {
148 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
149 $data=array();
150 $addEl = $this->table."_".$this->id;
151 switch((string)$this->P["params"]["setValue"]) {
152 case "set":
153 $data[$this->P["table"]][$this->P["uid"]][$this->P["field"]]=$addEl;
154 break;
155 case "prepend":
156 $data[$this->P["table"]][$this->P["uid"]][$this->P["field"]] = $current[$this->P["field"]].",".$addEl;
157 break;
158 case "append":
159 $data[$this->P["table"]][$this->P["uid"]][$this->P["field"]] = $addEl.",".$current[$this->P["field"]];
160 break;
161 }
162 $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));
163
164 $tce->start($data,array());
165 $tce->stripslashes_values=0;
166 $tce->process_datamap();
167 }
168 }
169 header("Location: ".t3lib_div::locationHeaderUrl($this->P["returnUrl"]));
170 } else {
171 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"));
172 }
173 }
174 }
175
176 // Include extension?
177 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_add.php']) {
178 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_add.php']);
179 }
180
181
182
183
184
185
186
187
188
189
190
191
192 // Make instance:
193 $SOBE = t3lib_div::makeInstance('SC_wizard_add');
194 $SOBE->init();
195
196 // Include files?
197 reset($SOBE->include_once);
198 while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
199
200 $SOBE->main();
201 $SOBE->printContent();
202 ?>