Added $Id$ keywords, cleaned up comment tags
[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 * @author Kasper Skaarhoj <kasper@typo3.com>
31 * @package TYPO3
32 * @subpackage core
33 *
34 */
35
36
37
38 $BACK_PATH="";
39 require ("init.php");
40 require ("template.php");
41 include ("sysext/lang/locallang_wizards.php");
42
43
44 // ***************************
45 // Script Classes
46 // ***************************
47 class SC_wizard_add {
48 var $include_once=array();
49 var $content;
50
51 var $returnEditConf;
52 var $processDataFlag=0;
53 var $P;
54 var $pid;
55 var $table;
56 var $id;
57
58 function init() {
59 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
60
61 $this->P = t3lib_div::GPvar("P",1);
62 //debug($this->P);
63
64 // Get this record
65 $origRow = t3lib_BEfunc::getRecord($this->P["table"],$this->P["uid"]);
66
67 // Get TSconfig for it.
68 $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->table,is_array($origRow)?$origRow:array("pid"=>$this->P["pid"]));
69 // Set [params][pid]
70 if (substr($this->P["params"]["pid"],0,3)=="###" && substr($this->P["params"]["pid"],-3)=="###") {
71 $this->pid = intval($TSconfig["_".substr($this->P["params"]["pid"],3,-3)]);
72 } else $this->pid = intval($this->P["params"]["pid"]);
73
74 // Return if new record
75 if (!strcmp($this->pid,"")) {
76 header("Location: ".t3lib_div::locationHeaderUrl($this->P["returnUrl"]));
77 exit;
78 }
79
80 // Else proceed.
81 $this->returnEditConf = t3lib_div::GPvar("returnEditConf");
82 if ($this->returnEditConf) {
83 $eC = unserialize(t3lib_div::GPvar("returnEditConf"));
84 $this->table = $this->P["params"]["table"];
85 if (is_array($eC[$this->table]) && t3lib_div::testInt($this->P["uid"])) {
86 reset($eC[$this->table]);
87 $this->id = intval(key($eC[$this->table]));
88 $cmd = current($eC[$this->table]);
89 if ($this->P["params"]["setValue"] && $cmd=="edit" && $this->id && $this->P["table"] && $this->P["field"] && $this->P["uid"]) {
90 $this->include_once[]=PATH_t3lib."class.t3lib_loaddbgroup.php";
91 $this->include_once[]=PATH_t3lib."class.t3lib_transferdata.php";
92 $this->include_once[]=PATH_t3lib."class.t3lib_tcemain.php";
93 $this->processDataFlag=1;
94 }
95 }
96 }
97 }
98 function main() {
99 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
100
101
102
103 // Else proceed.
104 if ($this->returnEditConf) {
105 if ($this->processDataFlag) {
106 $trData = t3lib_div::makeInstance("t3lib_transferData");
107 $trData->fetchRecord($this->P["table"],$this->P["uid"],""); // "new"
108 reset($trData->regTableItems_data);
109 $current = current($trData->regTableItems_data);
110
111 if (is_array($current)) {
112 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
113 $data=array();
114 $addEl = $this->table."_".$this->id;
115 switch((string)$this->P["params"]["setValue"]) {
116 case "set":
117 $data[$this->P["table"]][$this->P["uid"]][$this->P["field"]]=$addEl;
118 break;
119 case "prepend":
120 $data[$this->P["table"]][$this->P["uid"]][$this->P["field"]] = $current[$this->P["field"]].",".$addEl;
121 break;
122 case "append":
123 $data[$this->P["table"]][$this->P["uid"]][$this->P["field"]] = $addEl.",".$current[$this->P["field"]];
124 break;
125 }
126 $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));
127
128 $tce->start($data,array());
129 $tce->stripslashes_values=0;
130 $tce->process_datamap();
131 }
132 }
133 header("Location: ".t3lib_div::locationHeaderUrl($this->P["returnUrl"]));
134 } else {
135 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"));
136 }
137 }
138 }
139
140 // Include extension?
141 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/wizard_add.php"]) {
142 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["typo3/wizard_add.php"]);
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156 // Make instance:
157 $SOBE = t3lib_div::makeInstance("SC_wizard_add");
158 $SOBE->init();
159
160 // Include files?
161 reset($SOBE->include_once);
162 while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);}
163
164 $SOBE->main();
165 $SOBE->printContent();
166 ?>