2 // $Id: confedit.php 2009/02/10 14:41:30 hli Exp $
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üssen sich autentifizieren\n";
10 //Je Shop ein Conf-File == Multishop
11 if( isset($_GET["Shop"]) ) {
12 $Shop = $_GET["Shop"];
16 if ( $Shop != "" and file_exists ('conf'.$Shop.'.php') ) {
17 require 'conf'.$Shop.'.php';
18 $out = "Konfiguration für Shop $Shop gelesen";
20 //Singleshop oder noch kein Shop definiert
22 $out = "Standard-Konfiguration gelesen";
24 if ( $_SERVER['PHP_AUTH_USER']<>$ERPftpuser || $_SERVER['PHP_AUTH_PW']<>$ERPftppwd ) {
25 Header("WWW-Authenticate: Basic realm='My Realm'");
26 Header("HTTP/1.0 401 Unauthorized");
27 echo "Sie müssen sich autentifizieren\n";
34 include_once("error.php");
35 include_once("dblib.php");
36 $api = php_sapi_name();
37 if ( $api == 'cli' ) {
38 echo "Nur im Browser benutzen\n";
41 $err = new error($api);
43 $zeichen = array("","UTF-8","ISO-8859-1","ISO-8859-15","Windows-1252","ASCII");
44 function lager($sel,$db) {
46 $sql = "select w.description as lager,b.description as platz,b.id from ";
47 $sql .= "bin b left join warehouse w on w.id=b.warehouse_id ";
48 $sql .= "order by b.warehouse_id,b.id";
49 $bin=$db->getall($sql);
50 echo "\t<option value=-1 ".(($sel==-1)?'selected':'').">kein Lagerbestand\n";
51 echo "\t<option value=1 ".(($sel==1)?'selected':'').">Gesamtbestand\n";
52 if ($bin) foreach ($bin as $row) {
53 echo "\t<option value=".$row['id'];
54 if ($sel==$row['id']) echo " selected";
55 echo ">".$row['lager']." ".$row['platz']."\n";
58 function unit($sel,$db) {
60 $sql="select name from units order by sortkey";
61 $pgs=$db->getall($sql);
62 if ($sel=='') $sel=$pgs[0]['name'];
63 if ($pgs) foreach ($pgs as $row) {
64 echo "\t<option value=".$row['name'];
65 if ($sel==$row['name']) echo " selected";
66 echo ">".$row['name']."\n";
69 function pg($sel,$db) {
71 $sql="select id,pricegroup from pricegroup";
72 $pgs=$db->getall($sql);
73 echo "\t<option value=0";
74 if ($sel==0) echo " selected";
75 echo ">Standard VK\n";
76 if ($pgs) foreach ($pgs as $row) {
77 echo "\t<option value=".$row['id'];
78 if ($sel==$row['id']) echo " selected";
79 echo ">".$row['pricegroup']."\n";
82 function getTax($db) {
83 $sql = "SELECT BG.id AS bugru,T.rate,TK.startdate,C.taxkey_id, ";
84 $sql .= "(SELECT id FROM chart WHERE accno = T.taxnumber) AS tax_id, ";
85 $sql .= "BG.income_accno_id_0,BG.expense_accno_id_0 ";
86 $sql .= "FROM buchungsgruppen BG LEFT JOIN chart C ON BG.income_accno_id_0=C.id ";
87 $sql .= "LEFT JOIN taxkeys TK ON TK.chart_id=C.id ";
88 $sql .= "LEFT JOIN tax T ON T.id=TK.tax_id WHERE TK.startdate <= now()";
89 $rs = $db->getAll($sql);
90 if ($rs) foreach ($rs as $row) {
94 $data['startdate'] = $row['startdate'];
95 $data['rate'] = $row['rate']*100.0;
97 } else if ($TAX[$nr]['startdate'] < $row['startdate']) {
98 $TAX[$nr]["startdate"] = $row['startdate'];
99 $TAX[$nr]["rate"] = $row['rate']*100.0;
104 function fputsA($f,$key,$var,$bg=false) {
106 fputs($f,'$'.$key.'["ID"]=\''. $var['ID'].'\';'.$lf);
107 fputs($f,'$'.$key.'["NR"]=\''. $var['NR'].'\';'.$lf);
108 fputs($f,'$'.$key.'["Unit"]=\''. $var['Unit'].'\';'.$lf);
109 fputs($f,'$'.$key.'["TXT"]=\''. $var['TXT'].'\';'.$lf);
110 if ($bg) fputs($f,'$'.$key.'["BUGRU"]=\''. $var['BUGRU'].'\';'.$lf);
111 if ($bg) fputs($f,'$'.$key.'["TAX"]=\''. $var['TAX'].'\';'.$lf);
114 if ( isset($_POST["ok"]) ) {
115 foreach ($_POST as $key=>$val) {
119 if ( empty($ERPport) ) $ERPport = '5432';
120 if ( empty($SHOPport) ) $SHOPport = '3306';
123 $dbP = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err,$debug);
126 echo "Keine Verbindung zur ERP<br>";
128 unset($divStd['ID']);
129 unset($divVerm['ID']);
130 unset($minder['ID']);
131 unset($versand['ID']);
133 unset($paypal['ID']);
134 unset($treuhand['ID']);
135 unset($ERPusr['ID']);
138 $sql="SELECT id,description,unit,buchungsgruppen_id FROM parts where partnumber = '%s'";
139 $rs=$dbP->getOne(sprintf($sql,$divStd['NR']));
140 $divStd['ID']=$rs['id'];
141 $divStd['Unit']=$rs['unit'];
142 $divStd['BUGRU']=$rs['buchungsgruppen_id'];
143 $divStd['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
144 $divStd['TXT']=addslashes($rs['description']);
145 $rs=$dbP->getOne(sprintf($sql,$divVerm['NR']));
146 $divVerm['ID']=$rs['id'];
147 $divVerm['Unit']=$rs['unit'];
148 $divVerm['BUGRU']=$rs['buchungsgruppen_id'];
149 $divVerm['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
150 $divVerm['TXT']=addslashes($rs['description']);
151 $rs=$dbP->getOne(sprintf($sql,$versandS['NR']));
152 $versandS['ID']=$rs['id'];
153 $versandS['Unit']=$rs['unit'];
154 $versandS['BUGRU']=$rs['buchungsgruppen_id'];
155 $versandS['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
156 if ($versandS['TXT'] == '') $versandS['TXT']=addslashes($rs['description']);
157 $rs=$dbP->getOne(sprintf($sql,$versandV['NR']));
158 $versandV['ID']=$rs['id'];
159 $versandV['Unit']=$rs['unit'];
160 $versandV['BUGRU']=$rs['buchungsgruppen_id'];
161 $versandV['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
162 if ($versandV['TXT'] == '') $versandV['TXT']=addslashes($rs['description']);
163 $rs=$dbP->getOne(sprintf($sql,$nachn['NR']));
164 $nachn['ID']=$rs['id'];
165 $nachn['Unit']=$rs['unit'];
166 $nachn['BUGRU']=$rs['buchungsgruppen_id'];
167 $nachn['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
168 if ($nachn['TXT'] == '') $nachn['TXT']=addslashes($rs['description']);
169 $rs=$dbP->getOne(sprintf($sql,$minder['NR']));
170 $minder['ID']=$rs['id'];
171 $minder['Unit']=$rs['unit'];
172 $minder['BUGRU']=$rs['buchungsgruppen_id'];
173 $minder['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
174 if ($minder['TXT'] == '') $minder['TXT']=addslashes($rs['description']);
175 $rs=$dbP->getOne(sprintf($sql,$paypal['NR']));
176 $paypal['ID']=$rs['id'];
177 $paypal['Unit']=$rs['unit'];
178 $paypal['BUGRU']=$rs['buchungsgruppen_id'];
179 $paypal['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
180 if ($paypal['TXT'] == '') $paypal['TXT']=addslashes($rs['description']);
181 $rs=$dbP->getOne(sprintf($sql,$treuhand['NR']));
182 $treuhand['ID']=$rs['id'];
183 $treuhand['Unit']=$rs['unit'];
184 $treuhand['BUGRU']=$rs['buchungsgruppen_id'];
185 $treuhand['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
186 if ($treuhand['TXT'] == '') $treuhand['TXT']=addslashes($rs['description']);
187 $rs=$dbP->getOne("select id from employee where login = '".$ERPusrName."'");
190 $dbM = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err,$debug);
193 echo "Keine Verbindung zum Shop<br>";
196 if ( isset($_POST["ok"]) ) {
198 $f = @fopen('conf'.$Shop.'.php','w');
201 $d=date("Y/m/d H:i:s");
202 fputs($f,"<?php$lf// Verbindung zur ERP-db$lf");
203 fputs($f,'$debug=\''.$debug.'\';'.$lf);
204 fputs($f,'$ERPuser=\''.$ERPuser.'\';'.$lf);
205 fputs($f,'$ERPpass=\''.$ERPpass.'\';'.$lf);
206 fputs($f,'$ERPhost=\''.$ERPhost.'\';'.$lf);
207 fputs($f,'$ERPport=\''.$ERPport.'\';'.$lf);
208 fputs($f,'$ERPdbname=\''.$ERPdbname.'\';'.$lf);
209 fputs($f,'$codeLX=\''.$codeLX.'\';'.$lf);
210 fputs($f,'$mwstLX=\''.$mwstLX.'\';'.$lf);
211 fputs($f,'$ERPusrName=\''.$ERPusrName.'\';'.$lf);
212 fputs($f,'$ERPusrID=\''.$ERPusrID.'\';'.$lf);
213 fputs($f,'$ERPimgdir=\''.$ERPimgdir.'\';'.$lf);
214 fputs($f,'$maxSize=\''.$maxSize.'\';'.$lf);
215 fputs($f,'$ERPftphost=\''.$ERPftphost.'\';'.$lf);
216 fputs($f,'$ERPftpuser=\''.$ERPftpuser.'\';'.$lf);
217 fputs($f,'$ERPftppwd=\''.$ERPftppwd.'\';'.$lf);
218 fputs($f,'//Verbindung zur osCommerce-db'.$lf);
219 fputs($f,'$SHOPuser=\''.$SHOPuser.'\';'.$lf);
220 fputs($f,'$SHOPpass=\''.$SHOPpass.'\';'.$lf);
221 fputs($f,'$SHOPhost=\''.$SHOPhost.'\';'.$lf);
222 fputs($f,'$SHOPport=\''.$SHOPport.'\';'.$lf);
223 fputs($f,'$SHOPdbname=\''.$SHOPdbname.'\';'.$lf);
224 fputs($f,'$codeS=\''.$codeS.'\';'.$lf);
225 fputs($f,'$mwstS=\''.$mwstS.'\';'.$lf);
226 fputs($f,'$SHOPimgdir=\''.$SHOPimgdir.'\';'.$lf);
227 fputs($f,'$SHOPftphost=\''.$SHOPftphost.'\';'.$lf);
228 fputs($f,'$SHOPftpuser=\''.$SHOPftpuser.'\';'.$lf);
229 fputs($f,'$SHOPftppwd=\''.$SHOPftppwd.'\';'.$lf);
230 fputs($f,'$nopic=\''.$nopic.'\';'.$lf);
231 fputs($f,'$nopicerr=\''.$nopicerr.'\';'.$lf);
232 fputsA($f,'divStd',$divStd,true);
233 fputsA($f,'divVerm',$divVerm,true);
234 fputsA($f,'versandS',$versandS,true);
235 fputsA($f,'versandV',$versandV,true);
236 fputsA($f,'minder',$minder,true);
237 fputsA($f,'nachn',$nachn,true);
238 fputsA($f,'treuhand',$treuhand,true);
239 fputsA($f,'paypal',$paypal,true);
240 fputs($f,'$bgcol[1]=\'#ddddff\';'.$lf);
241 fputs($f,'$bgcol[2]=\'#ddffdd\';'.$lf);
242 fputs($f,'$preA=\''.$preA.'\';'.$lf);
243 fputs($f,'$preK=\''.$preK.'\';'.$lf);
244 fputs($f,'$auftrnr=\''.$auftrnr.'\';'.$lf);
245 //fputs($f,'$utftrans=\''.$utftrans.'\';'.$lf);
246 fputs($f,'$kdnum=\''.$kdnum.'\';'.$lf);
247 fputs($f,'$pricegroup=\''.$pricegroup.'\';'.$lf);
248 fputs($f,'$unit=\''.$unit.'\';'.$lf);
249 fputs($f,'$longtxt=\''.$longtxt.'\';'.$lf);
250 fputs($f,'$invbrne=\''.$invbrne.'\';'.$lf);
251 fputs($f,'$variantnr=\''.$variantnr.'\';'.$lf);
252 fputs($f,'$OEinsPart=\''.$OEinsPart.'\';'.$lf);
253 fputs($f,'$lager=\''.$lager.'\';'.$lf);
254 //fputs($f,'$showErr=true;'.$lf);
257 echo "Konfiguration conf$Shop.php gesichert.";
259 echo "Konfigurationsdatei (conf$Shop.php) konnte nicht geschrieben werden";
266 <table style="background-color:#cccccc" border="0">
267 <form name="ConfEdit" method="post" action="confedit.php">
268 <input type="hidden" name="Shop" value="<?= $Shop ?>">
269 <input type="hidden" name="divStd[ID]" value="<?= $divStd['ID'] ?>">
270 <input type="hidden" name="divVerm[ID]" value="<?= $divVerm['ID'] ?>">
271 <input type="hidden" name="minder[ID]" value="<?= $minder['ID'] ?>">
272 <input type="hidden" name="versandS[ID]" value="<?= $versandS['ID'] ?>">
273 <input type="hidden" name="versandV[ID]" value="<?= $versandV['ID'] ?>">
274 <input type="hidden" name="nachn[ID]" value="<?= $nachn['ID'] ?>">
275 <input type="hidden" name="paypal[ID]" value="<?= $paypal['ID'] ?>">
276 <input type="hidden" name="treuhand[ID]" value="<?= $treuhand['ID'] ?>">
277 <input type="hidden" name="ERPusr[ID]" value="<?= $ERPusr['ID'] ?>">
279 <tr><th>Daten</th><th>Lx-ERP</th><th><?php echo $Shop ?></th><th>Shop</th></tr>
282 <td colspan="2"><input type="text" name="ERPhost" size="25" value="<?= $ERPhost ?>"></td>
283 <td><input type="text" name="SHOPhost" size="25" value="<?= $SHOPhost ?>"></td>
287 <td colspan="2"><input type="text" name="ERPport" size="25" value="<?= $ERPport ?>"></td>
288 <td><input type="text" name="SHOPport" size="25" value="<?= $SHOPport ?>"></td>
292 <td colspan="2"><input type="text" name="ERPdbname" size="20" value="<?= $ERPdbname ?>"></td>
293 <td><input type="text" name="SHOPdbname" size="20" value="<?= $SHOPdbname ?>"></td>
296 <td>db-User Name</td>
297 <td colspan="2"><input type="text" name="ERPuser" size="15" value="<?= $ERPuser ?>"></td>
298 <td><input type="text" name="SHOPuser" size="15" value="<?= $SHOPuser ?>"></td>
302 <td colspan="2"><input type="text" name="ERPpass" size="15" value="<?= $ERPpass ?>"></td>
303 <td><input type="text" name="SHOPpass" size="15" value="<?= $SHOPpass ?>"></td>
307 <td colspan="2"><select name="codeLX">
308 <?php foreach($zeichen as $code) {
309 echo "<option value='".$code."'";
310 if ($code == $codeLX) echo " selected";
311 echo ">".$code."\n"; };
314 <td ><select name="codeS">
315 <?php foreach($zeichen as $code) {
316 echo "<option value='".$code."'";
317 if ($code == $codeS) echo " selected";
318 echo ">".$code."\n"; };
324 <td colspan="2"> <input type="radio" name="mwstLX" value="1" <?= ($mwstLX==1)?"checked":'' ?>> incl.
325 <input type="radio" name="mwstLX" value="0" <?= ($mwstLX<>1)?"checked":'' ?>> excl. MwSt</td>
326 <td><input type="radio" name="mwstS" value="1" <?= ($mwstS==1)?"checked":'' ?>> incl.
327 <input type="radio" name="mwstS" value="0" <?= ($mwstS<>1)?"checked":'' ?>> excl. MwSt</td>
331 <td colspan="2"><input type="text" name="ERPusrName" size="10" value="<?= $ERPusrName ?>">
332 <input type="checkbox" name="a1" <?= (empty($ERPusrID)?'':"checked") ?>></td>
337 <td colspan="2"><input type="text" name="ERPimgdir" size="30" value="<?= $ERPimgdir ?>"></td>
338 <td><input type="text" name="SHOPimgdir" size="30" value="<?= $SHOPimgdir ?>"></td>
341 <td>Platzhalterbild</td>
342 <td colspan="2"><input type="text" name="nopic" size="20" value="<?php echo $nopic; ?>">ohne Endung</td>
343 <td colspan="2"><input type="checkbox" value="1" name="nopicerr" <?= (empty($nopicerr)?'':"checked") ?>>nur bei fehlerhaftem Upload verwenden</td>
347 <td colspan="2"><input type="text" name="ERPftphost" size="20" value="<?= $ERPftphost ?>"></td>
348 <td><input type="text" name="SHOPftphost" size="20" value="<?= $SHOPftphost ?>"></td>
352 <td colspan="2"><input type="text" name="ERPftpuser" size="15" value="<?= $ERPftpuser ?>"></td>
353 <td><input type="text" name="SHOPftpuser" size="15" value="<?= $SHOPftpuser ?>"></td>
356 <td>FTP-User PWD</td>
357 <td colspan="2"><input type="text" name="ERPftppwd" size="15" value="<?= $ERPftppwd ?>"></td>
358 <td><input type="text" name="SHOPftppwd" size="15" value="<?= $SHOPftppwd ?>"></td>
361 <td>Nr Diverse Std-MwSt</td>
362 <td><input type="text" name="divStd[NR]" size="10" value="<?= $divStd['NR'] ?>">
363 <input type="checkbox" name="a1" <?= (empty($divStd['ID'])?'':"checked") ?>></td>
364 <td>Nr Diverse Verm-MwSt</td>
365 <td><input type="text" name="divVerm[NR]" size="10" value="<?= $divVerm['NR'] ?>">
366 <input type="checkbox" name="a1" <?= (empty($divVerm['ID'])?'':"checked") ?>></td>
369 <td>Nr Versand Std-MwSt</td>
370 <td><input type="text" name="versandS[NR]" size="10" value="<?= $versandS['NR'] ?>">
371 <input type="checkbox" name="a1" <?= (empty($versandS['ID'])?'':"checked") ?>></td>
373 <td><input type="text" name="versandS[TXT]" size="20" value="<?= $versandS['TXT'] ?>"><?= $versandS['TAX'] ?></td>
375 <td>Nr Versand Verm-MwSt</td>
376 <td><input type="text" name="versandV[NR]" size="10" value="<?= $versandV['NR'] ?>">
377 <input type="checkbox" name="a1" <?= (empty($versandV['ID'])?'':"checked") ?>></td>
379 <td><input type="text" name="versandV[TXT]" size="20" value="<?= $versandV['TXT'] ?>"><?= $versandV['TAX'] ?></td>
383 <td><input type="text" name="paypal[NR]" size="10" value="<?= $paypal['NR'] ?>">
384 <input type="checkbox" name="a1" <?= (empty($paypal['ID'])?'':"checked") ?>></td>
386 <td><input type="text" name="paypal[TXT]" size="20" value="<?= $paypal['TXT'] ?>"></td>
390 <td><input type="text" name="treuhand[NR]" size="10" value="<?= $treuhand['NR'] ?>">
391 <input type="checkbox" name="a1" <?= (empty($treuhand['ID'])?'':"checked") ?>></td>
393 <td><input type="text" name="treuhand[TXT]" size="20" value="<?= $treuhand['TXT'] ?>"></td>
396 <td>Nr Mindermenge</td>
397 <td><input type="text" name="minder[NR]" size="10" value="<?= $minder['NR'] ?>">
398 <input type="checkbox" name="a1" <?= (empty($minder['ID'])?'':"checked") ?>></td>
400 <td><input type="text" name="minder[TXT]" size="20" value="<?= $minder['TXT'] ?>"></td>
404 <td><input type="text" name="nachn[NR]" size="10" value="<?= $nachn['NR'] ?>">
405 <input type="checkbox" name="a1" <?= (empty($nachn['ID'])?'':"checked") ?>></td>
407 <td><input type="text" name="nachn[TXT]" size="20" value="<?= $nachn['TXT'] ?>"></td>
411 <td><select name="unit">
412 <? unit($unit,$dbP); ?>
415 <td><select name="pricegroup">
416 <? pg($pricegroup,$dbP); ?>
419 <td colspan="2">Auftragsnummern durch</td>
420 <td><input type="radio" name="auftrnr" value="1" <?= ($auftrnr==1)?"checked":'' ?>> LxO</td>
421 <td><input type="radio" name="auftrnr" value="0" <?= ($auftrnr<>1)?"checked":'' ?>> Shop</td>
424 <td colspan="2">Kundennummern durch</td>
425 <td><input type="radio" name="kdnum" value="1" <?= ($kdnum==1)?"checked":'' ?>> LxO</td>
426 <td><input type="radio" name="kdnum" value="0" <?= ($kdnum<>1)?"checked":'' ?>> Shop</td>
429 <td colspan="2">Nummernerweiterung</td>
430 <td>Auftrag<input type="text" name="preA" size="5" value="<?= $preA ?>"></td>
431 <td>Kunde<input type="text" name="preK" size="5" value="<?= $preK ?>"></td>
434 <td>Lagerbestand aus</td>
435 <td><select name="lager">
436 <? lager($lager,$dbP); ?>
442 <td colspan="3">Langbeschreibung aus Shop übernehmen</td>
443 <td><input type="radio" name="longtxt" value="1" <?= ($longtxt<>2)?"checked":'' ?>>Ja
444 <input type="radio" name="longtxt" value="2" <?= ($longtxt==2)?"checked":'' ?>>Nein</td>
448 <td colspan="3">LxO-Rechnungen sind Netto</td>
449 <td><input type="radio" name="invbrne" value="1" <?= ($invbrne<>2)?"checked":'' ?>>Ja
450 <input type="radio" name="invbrne" value="2" <?= ($invbrne==2)?"checked":'' ?>>Nein</td>
453 <td colspan="3">Varianten sind eigene Nummern in Lx (-n)</td>
454 <td><input type="radio" name="variantnr" value="1" <?= ($variantnr<>2)?"checked":'' ?>>Ja
455 <input type="radio" name="variantnr" value="2" <?= ($variantnr==2)?"checked":'' ?>>Nein</td>
458 <td colspan="3">Unbekannte Artikel beim Bestellimport anlegen</td>
459 <td><input type="radio" name="OEinsPart" value="1" <?= ($OEinsPart<>2)?"checked":'' ?>>Ja
460 <input type="radio" name="OEinsPart" value="2" <?= ($OEinsPart==2)?"checked":'' ?>>Nein</td>
464 <td>ein<input type="radio" name="debug" value="true" <?= ($debug=="true")?"checked":"" ?>>
465 aus<input type="radio" name="debug" value="false" <?= ($debug!="true")?"checked":"" ?>></td>
470 <td>Bildergrösse (byte)</td>
471 <td><input type="text" name="maxSize" size="10" value="<?= $maxSize ?>"></td>
476 <tr><td colspan="4" align="center"><input type="submit" name="ok" value="sichern"></td></tr>