Umstellung Form::throw_on_error auf Verwendung von Exception::Lite anstelle von Hashrefs
[kivitendo-erp.git] / oscom / confedit.php
1 <?
2 // $Id: confedit.php,v 1.6 2007/01/07
3 if (!isset($_SERVER['PHP_AUTH_USER'])) {
4         Header("WWW-Authenticate: Basic realm=\"Configurations-Editor\"");
5         Header("HTTP/1.0 401 Unauthorized");
6         echo "Sie m&uuml;ssen sich autentifizieren\n";
7         exit;
8 } else {
9         $login=($_GET["login"])?$_GET["login"]:$_POST["login"];
10         if (file_exists ("conf$login.php")) {
11                 require "conf$login.php";
12         } else {
13                 require "conf.php";
14         }
15         if ($_SERVER['PHP_AUTH_USER']<>$ERPftpuser || $_SERVER['PHP_AUTH_PW']<>$ERPftppwd) {
16                 Header("WWW-Authenticate: Basic realm=\"My Realm\"");
17                 Header("HTTP/1.0 401 Unauthorized");
18                 echo "Sie m&uuml;ssen sich autentifizieren\n";
19                 exit;
20         }
21         require_once "DB.php";
22         $db=@DB::connect($ERPdns);
23         if (!DB::isError($db)) {
24                 $sql="select id,pricegroup from pricegroup";
25                 $pgs=$db->getall($sql);
26         }
27         function pg($sel) {
28         global $pgs;
29                 echo "\t<option value=0";
30                 if ($sel==0) echo " selected";
31                 echo ">Standard VK\n";
32                 if ($pgs) foreach ($pgs as $row) {
33                         echo "\t<option value=".$row[0];
34                         if ($sel==$row[0]) echo " selected";
35                         echo ">".$row[1]."\n";
36                 }
37         }
38         if ($_POST["ok"]=="sichern") {
39                 $ok=true;
40                 if ($_POST["ERPpass"]) {
41                         $dsnP="pgsql://".$_POST["ERPuser"].":".$_POST["ERPpass"]."@".$_POST["ERPhost"]."/".$_POST["ERPdbname"];
42                 } else {
43                         $dsnP="pgsql://".$_POST["ERPuser"]."@".$_POST["ERPhost"]."/".$_POST["ERPdbname"];
44                 }
45                 $dbP=@DB::connect($dsnP);
46                 if (DB::isError($dbP)||!$dbP) {
47                         $ok=false;
48                         echo "Keine Verbindung zur ERP<br>";
49                         echo $dbP->userinfo."<br>";
50                 } else {
51                         //Steuertabelle ERP
52                         $sql ="select  BG.id as bugru,T.rate,TK.startdate from buchungsgruppen BG left join chart C ";
53                         $sql.="on BG.income_accno_id_0=C.id left join taxkeys TK on TK.chart_id=C.id left join tax T ";
54                         $sql.="on T.id=TK.tax_id where TK.startdate <= now()";
55                         $rs=$dbP->getAll($sql,DB_FETCHMODE_ASSOC);
56                         $erptax=array();
57                         foreach ($rs as $row) {
58                         if ($erptax[$row["bugru"]]["startdate"]<$row["startdate"]) {
59                                 $erptax[$row["bugru"]]["startdate"]=$row["startdate"];
60                                 $erptax[$row["bugru"]]["rate"]=sprintf("%1.4f",$row["rate"]*100);
61                         }
62                         }
63                         $sql ="select  P.id,P.description,P.buchungsgruppen_id as bugru from ";
64                         $sql.="parts P where P.partnumber = '%s'";
65                         $rs=$dbP->getall(sprintf($sql,$_POST["div16NR"]));
66                         $_POST["div16ID"]=$rs[0][0];
67                         $div16txt=$rs[0][1];
68                         $_POST["div16TAX"]=$erptax[$rs[0][2]]["rate"];
69                         $rs=$dbP->getall(sprintf($sql,$_POST["div07NR"]));
70                         $_POST["div07ID"]=$rs[0][0];
71                         $_POST["div07TAX"]=$erptax[$rs[0][2]]["rate"];
72                         $div07txt=$rs[0][1];
73                         $rs=$dbP->getall(sprintf($sql,$_POST["versandNR"]));
74                         $_POST["versandID"]=$rs[0][0];
75                         $_POST["versandTAX"]=$erptax[$rs[0][2]]["rate"];
76                         $versandtxt=$rs[0][1];
77                         $rs=$dbP->getall(sprintf($sql,$_POST["nachnNR"]));
78                         $_POST["nachnID"]=$rs[0][0];
79                         $_POST["nachnTAX"]=$erptax[$rs[0][2]]["rate"];
80                         $nachntxt=$rs[0][1];
81                         $rs=$dbP->getall(sprintf($sql,$_POST["minderNR"]));
82                         $_POST["minderID"]=$rs[0][0];
83                         $_POST["minderTAX"]=$erptax[$rs[0][2]]["rate"];
84                         $mindertxt=$rs[0][1];
85                         $rs=$dbP->getall(sprintf($sql,$_POST["paypalNR"]));
86                         $_POST["paypalID"]=$rs[0][0];
87                         $_POST["paypalTAX"]=$erptax[$rs[0][2]]["rate"];
88                         $paypaltxt=$rs[0][1];
89                         $rs=$dbP->getall(sprintf($sql,$_POST["treuhNR"]));
90                         $_POST["treuhID"]=$rs[0][0];
91                         $_POST["treuhTAX"]=$erptax[$rs[0][2]]["rate"];
92                         $treuhtxt=$rs[0][1];
93                         $rs=$dbP->getall("select id from employee where login = '".$_POST["ERPusrN"]."'");
94                         $_POST["ERPusrID"]=$rs[0][0];
95                 }
96                 if ($_POST["SHOPpass"]) {
97                         $dsnM="mysql://".$_POST["SHOPuser"].":".$_POST["SHOPpass"]."@".$_POST["SHOPhost"]."/".$_POST["SHOPdbname"];
98                 } else {
99                         $dsnM="mysql://".$_POST["SHOPuser"]."@".$_POST["SHOPhost"]."/".$_POST["SHOPdbname"];
100                 }
101                 $dbM=@DB::connect($dsnM);
102                 if (DB::isError($dbM)||!$dbM) {
103                         $ok=false;
104                         echo "Keine Verbindung zum Shop<br>";
105                         echo $dbM->userinfo."<br>";
106                 };
107                 if ($ok) {
108                         $f=fopen("conf$login.php","w");
109                         $v="1.6";
110                         $d=date("Y/m/d H:i:s");
111                         fputs($f,"<?\n// Verbindung zur ERP-db\n");
112                         fputs($f,"\$ERPuser=\"".$_POST["ERPuser"]."\";\n");
113                         fputs($f,"\$ERPpass=\"".$_POST["ERPpass"]."\";\n");
114                         fputs($f,"\$ERPhost=\"".$_POST["ERPhost"]."\";\n");
115                         fputs($f,"\$ERPdbname=\"".$_POST["ERPdbname"]."\";\n");
116                         fputs($f,"\$ERPdns=\"pgsql://\$ERPuser:\$ERPpass@\$ERPhost/\$ERPdbname\";\n");
117                         fputs($f,"\$ERPusr[\"Name\"]=\"".$_POST["ERPusrN"]."\";\n");
118                         fputs($f,"\$ERPusr[\"ID\"]=\"".$_POST["ERPusrID"]."\";\n");
119                         fputs($f,"\$ERPdir=\"".$_POST["ERPdir"]."\";\n");
120                         fputs($f,"\$ERPimgdir=\"".$_POST["ERPimgdir"]."\";\n");
121                         fputs($f,"\$maxSize=\"".$_POST["maxSize"]."\";\n");
122                         fputs($f,"\$ERPftphost=\"".$_POST["ERPftphost"]."\";\n");
123                         fputs($f,"\$ERPftpuser=\"".$_POST["ERPftpuser"]."\";\n");
124                         fputs($f,"\$ERPftppwd=\"".$_POST["ERPftppwd"]."\";\n");
125                         fputs($f,"//Verbindung zur osCommerce-db\n");
126                         fputs($f,"\$SHOPuser=\"".$_POST["SHOPuser"]."\";\n");
127                         fputs($f,"\$SHOPpass=\"".$_POST["SHOPpass"]."\";\n");
128                         fputs($f,"\$SHOPhost=\"".$_POST["SHOPhost"]."\";\n");
129                         fputs($f,"\$SHOPdbname=\"".$_POST["SHOPdbname"]."\";\n");
130                         fputs($f,"\$SHOPlang=\"".$_POST["SHOPlang"]."\";\n");
131                         fputs($f,"\$SHOPdns=\"mysql://\$SHOPuser:\$SHOPpass@\$SHOPhost/\$SHOPdbname\";\n");
132                         fputs($f,"\$SHOPdir=\"".$_POST["SHOPdir"]."\";\n");
133                         fputs($f,"\$SHOPimgdir=\"".$_POST["SHOPimgdir"]."\";\n");
134                         fputs($f,"\$SHOPftphost=\"".$_POST["SHOPftphost"]."\";\n");
135                         fputs($f,"\$SHOPftpuser=\"".$_POST["SHOPftpuser"]."\";\n");
136                         fputs($f,"\$SHOPftppwd=\"".$_POST["SHOPftppwd"]."\";\n");
137                         fputs($f,"\$div16[\"ID\"]=\"".$_POST["div16ID"]."\";\n");
138                         fputs($f,"\$div07[\"ID\"]=\"".$_POST["div07ID"]."\";\n");
139                         fputs($f,"\$versand[\"ID\"]=\"".$_POST["versandID"]."\";\n");
140                         fputs($f,"\$nachn[\"ID\"]=\"".$_POST["nachnID"]."\";\n");
141                         fputs($f,"\$minder[\"ID\"]=\"".$_POST["minderID"]."\";\n");
142                         fputs($f,"\$treuh[\"ID\"]=\"".$_POST["treuhID"]."\";\n");
143                         fputs($f,"\$paypal[\"ID\"]=\"".$_POST["paypalID"]."\";\n");
144                         fputs($f,"\$div16[\"NR\"]=\"".$_POST["div16NR"]."\";\n");
145                         fputs($f,"\$div07[\"NR\"]=\"".$_POST["div07NR"]."\";\n");
146                         fputs($f,"\$versand[\"NR\"]=\"".$_POST["versandNR"]."\";\n");
147                         fputs($f,"\$nachn[\"NR\"]=\"".$_POST["nachnNR"]."\";\n");
148                         fputs($f,"\$minder[\"NR\"]=\"".$_POST["minderNR"]."\";\n");
149                         fputs($f,"\$treuh[\"NR\"]=\"".$_POST["treuhNR"]."\";\n");
150                         fputs($f,"\$paypal[\"NR\"]=\"".$_POST["paypalNR"]."\";\n");
151                         fputs($f,"\$div16[\"TAX\"]=\"".$_POST["div16TAX"]."\";\n");
152                         fputs($f,"\$div07[\"TAX\"]=\"".$_POST["div07TAX"]."\";\n");
153                         fputs($f,"\$versand[\"TAX\"]=\"".$_POST["versandTAX"]."\";\n");
154                         fputs($f,"\$nachn[\"TAX\"]=\"".$_POST["nachnTAX"]."\";\n");
155                         fputs($f,"\$minder[\"TAX\"]=\"".$_POST["minderTAX"]."\";\n");
156                         fputs($f,"\$treuh[\"TAX\"]=\"".$_POST["treuhTAX"]."\";\n");
157                         fputs($f,"\$paypal[\"TAX\"]=\"".$_POST["paypalTAX"]."\";\n");
158                         fputs($f,"\$div16[\"TXT\"]=\"".$div16txt."\";\n");
159                         fputs($f,"\$div07[\"TXT\"]=\"".$div07txt."\";\n");
160                         fputs($f,"\$versand[\"TXT\"]=\"".$versandtxt."\";\n");
161                         fputs($f,"\$nachn[\"TXT\"]=\"".$nachntxt."\";\n");
162                         fputs($f,"\$minder[\"TXT\"]=\"".$mindertxt."\";\n");
163                         fputs($f,"\$treuh[\"TXT\"]=\"".$treuhtxt."\";\n");
164                         fputs($f,"\$paypal[\"TXT\"]=\"".$paypaltxt."\";\n");
165                         fputs($f,"\$pricegroup=\"".$_POST["pricegroup"]."\";\n");
166                         fputs($f,"\$bgcol[1]=\"#ddddff\";\n");
167                         fputs($f,"\$bgcol[2]=\"#ddffdd\";\n");
168                         fputs($f,"\$preA=\"".$_POST["preA"]."\";\n");
169                         fputs($f,"\$preK=\"".$_POST["preK"]."\";\n");
170                         fputs($f,"\$auftrnr=\"".$_POST["auftrnr"]."\";\n");
171                         fputs($f,"\$debug=".$_POST["debug"].";\n");
172                         fputs($f,"\$kdnum=\"".$_POST["kdnum"]."\";\n");
173                         fputs($f,"\$stdprice=\"".$_POST["stdprice"]."\";\n");
174                         fputs($f,"\$nopic=\"".$_POST["nopic"]."\";\n");
175                         fputs($f,"\$showErr=\"true\";\n");
176                         fputs($f,"?>");
177                         fclose($f);
178                         if (file_exists ("conf$login.php")) {
179                                 require "conf$login.php";
180                         } else {
181                                 require "conf.php";
182                         }
183                         $sql="select count(*) from customers_number";
184                         $rc=@$dbM->query($sql);
185                         if ($rc->code==-18) {
186                                 $sql="CREATE TABLE customers_number ( cid int(6) NOT NULL auto_increment,  customers_id int NOT NULL default '0', ";
187                                 $sql.="kdnr int NOT NULL default '0', shipto int, PRIMARY KEY  (cid)) TYPE=MyISAM";
188                                 $rc=@$dbM->query($sql);
189                                 if ($rc->code==-1) {
190                                         echo "Fehler beim Erzeugen der Tabelle 'customers_number' in der Shop-db";
191                                 } else {
192                                         echo "Tabelle 'customers_number' in der Shop-db angelegt.";
193                                 }
194                         } else {
195                                 $sql="select shipto from customers_number limit 1";
196                                 $rc=@$dbM->query($sql);
197                                 if ($rc->code==-19) {
198                                         $sql="alter table customers_number add column shipto int";
199                                         $rc=@$dbM->query($sql);
200                                         if ($rc->code==-1) {
201                                                 echo "Fehler beim Anlegen der Spalte 'shipto' in 'customers_number'";
202                                         } else {
203                                                 echo "'shipto' in 'customers_number' angelegt.";
204                                         }
205                                 }
206                         }
207                 } else {
208                         $ERPuser=$_POST["ERPuser"];
209                         $ERPpass=$_POST["ERPpass"];
210                         $ERPhost=$_POST["ERPhost"];
211                         $ERPdbname=$_POST["ERPdbname"];
212                         $ERPusrN=$_POST["ERPusrN"];
213                         $ERPdir=$_POST["ERPdir"];
214                         $ERPimgdir=$_POST["ERPimgdir"];
215                         $maxSize=$_POST["maxSize"];
216                         $ERPftphost=$_POST["ERPftphost"];
217                         $ERPftpuser=$_POST["ERPftpuser"];
218                         $ERPftppwd=$_POST["ERPftppwd"];
219                         $SHOPuser=$_POST["SHOPuser"];
220                         $SHOPpass=$_POST["SHOPpass"];
221                         $SHOPhost=$_POST["SHOPhost"];
222                         $SHOPdbname=$_POST["SHOPdbname"];
223                         $SHOPlang=$_POST["SHOPlang"];
224                         $SHOPdir=$_POST["SHOPdir"];
225                         $SHOPimgdir=$_POST["SHOPimgdir"];
226                         $SHOPftphost=$_POST["SHOPftphost"];
227                         $SHOPftpuser=$_POST["SHOPftpuser"];
228                         $SHOPftppwd=$_POST["SHOPftppwd"];
229                         $div16NR=$_POST["div16NR"];
230                         $div07NR=$_POST["div07NR"];
231                         $versandNR=$_POST["versandNR"];
232                         $nachnNR=$_POST["nachnNR"];
233                         $treuhNR=$_POST["treuhNR"];
234                         $minderNR=$_POST["minderNR"];
235                         $paypalNR=$_POST["paypalNR"];
236                         $pricegroup=$_POST["pricegroup"];
237                         $preA=$_POST["preA"];
238                         $preK=$_POST["preK"];
239                         $kdnum=$_POST["kdnum"];
240                         $auftrnr=$_POST["auftrnr"];
241                         $debug=$_POST["debug"];
242                         $stdprice=$_POST["stdprice"];
243                         $nopic=$_POST["nopic"];
244                 }
245         }       else {
246                 if (file_exists ("conf$login.php")) {
247                         require "conf$login.php";
248                 } else {
249                         require "conf.php";
250                 }
251         }
252 ?>
253 <html>
254 <body>
255 <center>
256 <table style="background-color:#cccccc">
257 <form name="ConfEdit" method="post" action="confedit.php">
258 <input type="hidden" name="div16ID" value="<?= $div16["ID"] ?>">
259 <input type="hidden" name="div07ID" value="<?= $div07["ID"] ?>">
260 <input type="hidden" name="minderID" value="<?= $minder["ID"] ?>">
261 <input type="hidden" name="versandID" value="<?= $versand["ID"] ?>">
262 <input type="hidden" name="nachnID" value="<?= $nachn["ID"] ?>">
263 <input type="hidden" name="paypalID" value="<?= $paypal["ID"] ?>">
264 <input type="hidden" name="treuhID" value="<?= $treuh["ID"] ?>">
265 <input type="hidden" name="ERPusrID" value="<?= $ERPusr["ID"] ?>">
266 <input type="hidden" name="login" value="<?= $login ?>">
267 <tr><th>Daten</th><th>Lx-ERP</th><th></th><th>Shop</th></tr>
268 <tr>
269         <td>db-Host</td>
270         <td colspan="2"><input type="text" name="ERPhost" size="25" value="<?= $ERPhost ?>"></td>
271         <td><input type="text" name="SHOPhost" size="25" value="<?= $SHOPhost ?>"></td>
272 </tr>
273 <tr>
274         <td>Database</td>
275         <td colspan="2"><input type="text" name="ERPdbname" size="20" value="<?= $ERPdbname ?>"></td>
276         <td><input type="text" name="SHOPdbname" size="20" value="<?= $SHOPdbname ?>"></td>
277 </tr>
278 <tr>
279         <td>db-User Name</td>
280         <td colspan="2"><input type="text" name="ERPuser" size="15" value="<?= $ERPuser ?>"></td>
281         <td><input type="text" name="SHOPuser" size="15" value="<?= $SHOPuser ?>"></td>
282 </tr>
283 <tr>
284         <td>db-User PWD</td>
285         <td colspan="2"><input type="text" name="ERPpass" size="15" value="<?= $ERPpass ?>"></td>
286         <td><input type="text" name="SHOPpass" size="15" value="<?= $SHOPpass ?>"></td>
287 </tr>
288 <tr>
289         <td>User-ID</td>
290         <td colspan="2"><input type="text" name="ERPusrN" size="10" value="<?= $ERPusr["Name"] ?>">
291                 <input type="checkbox" name="a1" <?= (empty($ERPusr["ID"])?"":"checked") ?> onFocus="blur();"></td>
292         <td></td>
293 </tr>
294 <tr>
295         <td>CSV-Dir</td>
296         <td colspan="2"><input type="text" name="ERPdir" size="30" value="<?= $ERPdir ?>"></td>
297         <td><input type="text" name="SHOPdir" size="30" value="<?= $SHOPdir ?>"></td>
298 </tr>
299 <tr>
300         <td>Image-Dir</td>
301         <td colspan="2"><input type="text" name="ERPimgdir" size="30" value="<?= $ERPimgdir ?>"></td>
302         <td><input type="text" name="SHOPimgdir" size="30" value="<?= $SHOPimgdir ?>"></td>
303 </tr>
304 <tr>
305         <td>FTP-Host</td>
306         <td colspan="2"><input type="text" name="ERPftphost" size="20" value="<?= $ERPftphost ?>"></td>
307         <td><input type="text" name="SHOPftphost" size="20" value="<?= $SHOPftphost ?>"></td>
308 </tr>
309 <tr>
310         <td>FTP-User</td>
311         <td colspan="2"><input type="text" name="ERPftpuser" size="15" value="<?= $ERPftpuser ?>"></td>
312         <td><input type="text" name="SHOPftpuser" size="15" value="<?= $SHOPftpuser ?>"></td>
313 </tr>
314 <tr>
315         <td>FTP-User PWD</td>
316         <td colspan="2"><input type="text" name="ERPftppwd" size="15" value="<?= $ERPftppwd ?>"></td>
317         <td><input type="text" name="SHOPftppwd" size="15" value="<?= $SHOPftppwd ?>"></td>
318 </tr>
319 <tr>
320         <td>ID Diverse 19%</td>
321         <td><input type="text" name="div16NR" size="10" value="<?= $div16["NR"] ?>">
322                 <input type="checkbox" name="a1" <?= (empty($div16["ID"])?"":"checked") ?>></td>
323         <td>ID Diverse 7%</td>
324         <td><input type="text" name="div07NR" size="10" value="<?= $div07["NR"] ?>">
325                 <input type="checkbox" name="a1" <?= (empty($div07["ID"])?"":"checked") ?>></td>
326 </tr>
327 <tr>
328         <td>ID Versand</td>
329         <td><input type="text" name="versandNR" size="10" value="<?= $versand["NR"] ?>">
330                 <input type="checkbox" name="a1" <?= (empty($versand["ID"])?"":"checked") ?>></td>
331         <td>ID Nachname</td>
332         <td><input type="text" name="nachnNR" size="10" value="<?= $nachn["NR"] ?>">
333                 <input type="checkbox" name="a1" <?= (empty($nachn["ID"])?"":"checked") ?>></td>
334 </tr>
335 <tr>
336         <td>ID Paypal</td>
337         <td><input type="text" name="paypalNR" size="10" value="<?= $paypal["NR"] ?>">
338                 <input type="checkbox" name="a1" <?= (empty($paypal["ID"])?"":"checked") ?>></td>
339         <td>ID Treuhand</td>
340         <td><input type="text" name="treuhNR" size="10" value="<?= $treuh["NR"] ?>">
341                 <input type="checkbox" name="a1" <?= (empty($treuh["ID"])?"":"checked") ?>></td>
342 </tr>
343 <tr>
344         <td>ID Mindemenge</td>
345         <td><input type="text" name="minderNR" size="10" value="<?= $minder["NR"] ?>">
346                 <input type="checkbox" name="a1" <?= (empty($minder["ID"])?"":"checked") ?>></td>
347         <td></td>
348         <td></td>
349 </tr>
350 <tr>
351         <td colspan="2">Abweichende Shopsprache</td>
352         <td colspan="2"><input type="text" name="SHOPlang" size="5" value="<?= $SHOPlang ?>"> leer = Default</td>
353 </tr>
354 <tr>
355         <td>Preisgruppe</td>
356         <td><select name="pricegroup">
357 <? pg($pricegroup); ?>
358             </select></td>
359         <td>Defaultbild</td>
360         <td><input type="text" name="nopic" size="20" value="<?= $nopic ?>">
361 </tr>
362 <tr>
363         <td colspan="2">Auftragsnummern durch</td>
364         <td><input type="radio" name="auftrnr" value="1" <?= ($auftrnr==1)?"checked":"" ?>> LxO</td>
365         <td><input type="radio" name="auftrnr" value="0" <?= ($auftrnr<>1)?"checked":"" ?>> Shop</td>
366 </tr>
367 <tr>
368         <td colspan="2">Kundennummern durch</td>
369         <td><input type="radio" name="kdnum" value="1" <?= ($kdnum==1)?"checked":"" ?>> LxO</td>
370         <td><input type="radio" name="kdnum" value="0" <?= ($kdnum<>1)?"checked":"" ?>> Shop</td>
371 </tr>
372 <tr>
373         <td colspan="2">Nummernerweiterung</td>
374         <td>Auftrag<input type="text" name="preA" size="5" value="<?= $preA ?>"></td>
375         <td>Kunde<input type="text" name="preK" size="5" value="<?= $preK ?>"></td>
376 </tr>
377 <tr>
378         <td>Logging</td>
379         <td>ein<input type="radio" name="debug" value="true" <?= ($debug=="true")?"checked":"" ?>>
380         aus<input type="radio" name="debug" value="false" <?= ($debug!="true")?"checked":"" ?>></td>
381         <td></td><td></td>
382 </tr>
383 <tr><td colspan="4" align="center"><input type="submit" name="ok" value="sichern"></td></tr>
384 </form>
385 </table>
386 </center>
387 </body>
388 </html>
389 <? } ?>