--- /dev/null
+<?php
+$api = php_sapi_name();
+if ( $api != "cli" ) {
+ echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
+ @apache_setenv('no-gzip', 1);
+ @ini_set('zlib.output_compression', 0);
+ @ini_set('implicit_flush', 1);
+ $shopnr = $_GET["Shop"];
+ $nofiles = ( $_GET["nofiles"] == '1' )?true:false;
+} else {
+ if ( $argc > 1 ) {
+ $tmp = explode("=",trim($argv[1]));
+ if ( count($tmp) != 2 ) {
+ echo "Falscher Aufruf: php <scriptname.php> shop=1\n";
+ exit (-1);
+ } else {
+ $shopnr = $tmp[1];
+ }
+ }
+}
+
+include_once("conf$shopnr.php");
+include_once("error.php");
+include_once("dblib.php");
+include_once("pepper.php");
+include_once("erplib.php");
+include_once("Picture.php");
+
+//Fehlerinstanz
+$err = new error($api);
+
+//Bilder
+$pict = new picture($ERPftphost,$ERPftpuser,$ERPftppwd,$ERPimgdir,$SHOPftphost,$SHOPftpuser,$SHOPftppwd,$SHOPimgdir,$err);
+//$pict->original = false;
+
+//ERP-Instanz
+$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+if ($erpdb->db->connected_database_name == $ERPdbname) {
+ $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
+} else {
+ $err->out('Keine Verbindung zur ERP',true);
+ exit();
+}
+//Shop-Instanz
+$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err);
+if ($shopdb->db->connected_database_name == $SHOPdbname) {
+ $shop = new pepper($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr,$pict,$nopic,$nopicerr,$nofiles);
+} else {
+ $err->out('Keine Verbindung zum Shop',true);
+ exit();
+}
+$artikel = $erp->getParts($pricegroup);
+$lang = $shop->getLang("de");
+$cnt = 0;
+$errors = 0;
+
+if ( $api != 'cli' ) ob_start();
+
+$err->out("Artikelexport für Shop $shopnr",true);
+
+if ($artikel) foreach ($artikel as $row) {
+ $rc = $shop->saveArtikel($row,"de");
+ if ($rc) {
+ $cnt++;
+ if ( $cnt % 10 == 0 ) $err->out(".");
+ } else {
+ $errors++;
+ }
+}
+$err->out('',true);
+$err->out("$cnt Artikel übertragen, $errors Artikel nicht",true);
+if ( $api != "cli" ) {
+ echo "</body>\n</html>\n";
+}
+?>
--- /dev/null
+<?php
+$api = php_sapi_name();
+if ( $api != "cli" ) {
+ echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
+ @apache_setenv('no-gzip', 1);
+ @ini_set('zlib.output_compression', 0);
+ @ini_set('implicit_flush', 1);
+ $shopnr = $_GET["Shop"];
+ $nofiles = ( $_GET["nofiles"] == '1' )?true:false;
+} else {
+ if ( $argc > 1 ) {
+ $tmp = explode("=",trim($argv[1]));
+ if ( count($tmp) != 2 ) {
+ echo "Falscher Aufruf: php <scriptname.php> shop=1\n";
+ exit (-1);
+ } else {
+ $shopnr = $tmp[1];
+ }
+ }
+}
+
+include_once("conf$shopnr.php");
+include_once("error.php");
+include_once("dblib.php");
+include_once("pepper.php");
+include_once("erplib.php");
+
+//Fehlerinstanz
+$err = new error($api);
+
+
+//ERP-Instanz
+$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+if ($erpdb->db->connected_database_name == $ERPdbname) {
+ $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
+} else {
+ $err->out('Keine Verbindung zur ERP',true);
+ exit();
+}
+
+//Shop-Instanz
+$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err);
+if ($shopdb->db->connected_database_name == $SHOPdbname) {
+ $shop = new pepper($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr);
+} else {
+ $err->out('Keine Verbindung zum Shop',true);
+ exit();
+}
+
+$artikel = $shop->getAllArtikel();
+$cnt = 0;
+$errors = 0;
+//Artikel die mehreren Warengruppen zugeordnet sind, werden nur einmal importiert.
+//Es wird dann auch nur die erste Warengruppe angelegt.
+if ( $api != 'cli' ) ob_start();
+
+$err->out("Artikelimport von Shop $shopnr",true);
+
+if ($artikel) foreach ($artikel as $row) {
+ $rc = $erp->chkPartnumber($row,true);
+ if ($rc) {
+ $cnt++;
+ } else {
+ $err->out('Fehler: '.$row['partnumber'],true);
+ $errors++;
+ }
+}
+$err->out('',true);
+$err->out("$cnt Artikel geprüft bzw. übertragen, $errors Artikel nicht",true);
+if ( $api != "cli" ) {
+ echo "</body>\n</html>\n";
+}
+?>
--- /dev/null
+<?php
+$api = php_sapi_name();
+if ( $api != "cli" ) {
+ echo "<html>\n<head>\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n</head>\n<body>\n";
+ @apache_setenv('no-gzip', 1);
+ @ini_set('zlib.output_compression', 0);
+ @ini_set('implicit_flush', 1);
+ $shopnr = $_GET["Shop"];
+ $nofiles = ( $_GET["nofiles"] == '1' )?true:false;
+} else {
+ if ( $argc > 1 ) {
+ $tmp = explode("=",trim($argv[1]));
+ if ( count($tmp) != 2 ) {
+ echo "Falscher Aufruf: php <scriptname.php> shop=1\n";
+ exit (-1);
+ } else {
+ $shopnr = $tmp[1];
+ }
+ }
+}
+
+include_once("conf$shopnr.php");
+include_once("error.php");
+include_once("dblib.php");
+include_once("pepper.php");
+include_once("erplib.php");
+//Fehlerinstanz
+$err = new error();
+
+$err->out("Shop $shopnr, Bestellimport",true);
+
+//ERP-Instanz
+$erpdb = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+if ($erpdb->db->connected_database_name == $ERPdbname) {
+ $erp = new erp($erpdb,$err,$divStd,$divVerm,$auftrnr,$kdnum,$preA,$preK,$invbrne,$mwstS,$OEinsPart,$lager);
+} else {
+ $err->out('Keine Verbindung zur ERP',true);
+ exit();
+}
+
+//Shop-Instanz
+$shopdb = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err);
+if ($shopdb->db->connected_database_name == $SHOPdbname) {
+ $shop = new pepper($shopdb,$err,$SHOPdbname,$divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,$mwstLX,$mwstS,$variantnr);
+//echo "<pre>"; print_r($shopdb->db); print_r($shopnr); echo "</pre>";
+} else {
+ $err->out('Keine Verbindung zum Shop',true);
+ exit();
+}
+
+$bestellungen = $shop->getBestellung($ERPusrID);
+//print_r($bestellungen); exit(1);
+$cnt = 0;
+$errors = 0;
+
+$err->out("Bestellimport vom Shop $shopnr",true);
+
+if ($bestellungen) foreach ($bestellungen as $row) {
+ $rc = $erp->mkAuftrag($row,$shopnr,$longtxt);
+ if ($rc>0) {
+ $rc = $shop->setKundenNr($row['customer']['shopid'],$rc);
+ if ($rc>0) {
+ $shop->setAbgeholt($row['cusordnumber']);
+ $cnt++;
+ $err->out("ok",true);
+ } else {
+ $errors++;
+ $err->out("Fehler setKdNr ".$row['customer']['shopid'],true);
+ }
+ } else if ($rc == -1) {
+ $errors++;
+ $err->out("Fehler mkAuftrag ".$row['cusordnumber'],true);
+ } else {
+ $err->out("Fehler Kunde zuordnen ".$row['customer']['shopid'].":".$row['cusordnumber'],true);
+ $errors++;
+ }
+}
+$err->out('Von '.count($bestellungen)." Bestellungen $cnt übertragen, $errors nicht",true);
+if ( $api != "cli" ) {
+ echo "<br /><a href='../oe.pl?vc=customer&type=sales_order&nextsub=orders&action=Weiter&open=1¬delivered=1&delivered=1&l_ordnumber=Y&l_transdate=Y&l_reqdate=1&l_name=Y&l_employee=Y&l_amount=Y'>Auftragsliste</a>";
+ echo "</body>\n</html>\n";
+}
+
+?>
--- /dev/null
+Varianten können in LxO eigene Artikelnummern haben.
+Die Artikelnummer wird dann automatisch ergänzt um "-" und die Variarions-ID.
+Aus "A1001" wird z.B. "A1001-1" für die erste (Standard) Variante.
+Variations-IDs MÜSSEN!! Lückenlos bei 1 beginnen, da sonst der Shop ins Schleudern kommt!!!!!
+
+Preise werden berechnet: Grundpreis + Preis für die Variante
+Text wird ergänzt: Standardtext + ", Variantengruppe: Variante"
+
+Ein beschreibbares Verzeichnis "tmp" wird als Unterverzeichnis erwartet.
+z.B.:
+ln -s /tmp
+
+Wenn ein Platzhalterbild eingesetzt werden soll, so muß das Bild zuerst auf
+den Shopserver übertragen werden.
+<bildname>_gr.jpg und <bildname>_kl.jpg
+
+Dann den Namen <bildname> in der Maske eintragen. Man kann bestimmen, ob
+das Bild immer genommen wird, wenn kein Bild angegeben wird oder nur wenn
+der Upload schief gegangen ist.
+
+Artikelexport (Lx -> Shop) kann ohne Bilderupload durchgeführt werden.
+Spart Bandbreite und Zeit, wenn nur Updates gemacht werden.
+Parameterübergabe: nofiles=1
+[Shop--Warenexport]
+module=shop/ArtikelErpToShop.php
+nofiles=1
+
+Shop ist Mehrshopfähig. Shopnummer muß beim Aufruf übergeben werden:
+Shop=1
+
+Die Im-/Exportmodule lassen sich auch auf der Konsole oder per Cron-Job aufrufen:
+
+php ArtikelShopToErp.php shop=1 > /tmp/export.log
--- /dev/null
+<?php
+
+
+class picture {
+
+ var $smallwidth = 150;
+ var $bigwidth = 800;
+ var $original = true;
+ var $err = false;
+
+ function picture($ERPhost,$ERPuser,$ERPpass,$ERPimgdir,$SHOPhost,$SHOPuser,$SHOPpass,$SHOPimgdir,$err) {
+ $this->ERPftphost = $ERPhost;
+ $this->ERPftpuser = $ERPuser;
+ $this->ERPftppwd = $ERPpass;
+ $this->ERPimgdir = $ERPimgdir;
+ $this->SHOPftphost = $SHOPhost;
+ $this->SHOPftpuser = $SHOPuser;
+ $this->SHOPftppwd = $SHOPpass;
+ $this->SHOPimgdir = $SHOPimgdir;
+ $this->err = $err;
+ }
+
+ function copyImage($id,$image,$typ) {
+ if ( !$this->fromERP($image) ) return false;
+ if ( !$this->mkbilder() ) return false;
+ return $this->toShop($id,$typ);
+ }
+
+ function mkbilder() {
+ if ( !class_exists("Imagick") ) { $this->err->out("Imagick-Extention nicht installiert",true); return false; };
+ $handle = new Imagick();
+ if ( !$handle->readImage("./tmp/tmp.file_org") ) return false;
+ $d = $handle->getImageGeometry();
+ if ( $d["width"]<$d["height"] ) {
+ $faktor = $d["height"]/$d["width"];
+ } else {
+ $faktor = $d["width"]/$d["height"];
+ }
+ $smallheight = floor($this->smallwidth*$faktor);
+ $handle->thumbnailImage($this->smallwidth, $smallheight);
+ $rc = $handle->writeImage( "./tmp/tmp.file_small");
+ if ( !$this->original ) {
+ $handle->readImage("./tmp/tmp.file_org");
+ $bigheight = floor($this->bigwidth * $faktor);
+ $handle->thumbnailImage( $this->bigwidth, $bigheight);
+ return $handle->writeImage( "./tmp/tmp.file_org");
+ }
+ return $rc;
+ }
+
+ function fromERP($image) {
+ if ( $this->ERPftphost == 'localhost' ) {
+ exec("cp $this->ERPimgdir/$image ./tmp/tmp.file_org",$aus,$rc2);
+ if ( $rc2>0 ) { $this->err->out("[Downloadfehler: $image]",true); return false; };
+ } else {
+ $conn_id = ftp_connect($this->ERPftphost);
+ $rc = @ftp_login($conn_id,$this->ERPftpuser,$this->ERPftppwd);
+ $src = $this->ERPimgdir."/".$image;
+ $upload = @ftp_get($conn_id,"tmp/tmp.file_org","$src",FTP_BINARY);
+ if ( !$upload ) { $this->err->out("[Ftp Downloadfehler! $image]",true); return false; };
+ ftp_quit($conn_id);
+ }
+ $this->image = $image;
+ return true;
+ }
+
+ function toShop($id,$typ) {
+ $grpic = $id."_gr.".$typ;
+ $klpic = $id."_kl.".$typ;
+ if ( $this->SHOPftphost == 'localhost' ) {
+ exec("cp ./tmp/tmp.file_org $this->SHOPimgdir/$grpic",$aus,$rc1);
+ exec("cp ./tmp/tmp.file_small $this->SHOPimgdir/$klpic",$aus,$rc2);
+ if ( $rc1>0 || $rc2>0 ) { $this->err->out("[Uploadfehler: $this->image / $grpic]",true); return false; };
+ } else {
+ $conn_id = ftp_connect($this->SHOPftphost);
+ @ftp_login($conn_id,$this->SHOPftpuser,$this->SHOPftppwd);
+ @ftp_chdir($conn_id,$this->SHOPimgdir);
+ $upload = @ftp_put($conn_id,$this->SHOPimgdir."/$grpic","tmp/tmp.file_org",FTP_BINARY);
+ if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! $grpic]",true); return false; };
+ $upload = @ftp_put($conn_id,$this->SHOPimgdir."/$klpic","tmp/tmp.file_small",FTP_BINARY);
+ if ( !$upload ) { $this->err->out("[Ftp Uploadfehler! $klpic]",true); return false; };
+ @ftp_quit($conn_id);
+ }
+ return true;
+ }
+
+
+}
+?>
--- /dev/null
+<?php
+// Verbindung zur ERP-db
+$ERPuser='lxoffice';
+$ERPpass='lxgeheim';
+$ERPhost='localhost';
+$ERPdbname='demo';
+$codeLX='UTF-8';
+$mwstLX='1';
+$ERPusrName='demo';
+$ERPusrID='';
+$ERPimgdir='/var/www/lx-office-erp';
+$maxSize='';
+$ERPftphost='localhost';
+$ERPftpuser='pepper';
+$ERPftppwd='pepper';
+//Verbindung zur osCommerce-db
+$SHOPuser='pepper';
+$SHOPpass='sehrgeheim';
+$SHOPhost='localhost';
+$SHOPdbname='Pepper';
+$codeS='UTF-8';
+$mwstS='1';
+$SHOPimgdir='/var/www/Pepper/shop/ProdukteBilder';
+$SHOPftphost='localhost';
+$SHOPftpuser='pepper';
+$SHOPftppwd='pepper';
+$nopic='nopic';
+$nopicerr='1';
+$divStd["ID"]='';
+$divStd["NR"]='divStd';
+$divStd["Unit"]='';
+$divStd["TXT"]='';
+$divStd["BUGRU"]='';
+$divStd["TAX"]='';
+$divVerm["ID"]='';
+$divVerm["NR"]='divVerm';
+$divVerm["Unit"]='';
+$divVerm["TXT"]='';
+$divVerm["BUGRU"]='';
+$divVerm["TAX"]='';
+$versandS["ID"]='';
+$versandS["NR"]='divStd';
+$versandS["Unit"]='';
+$versandS["TXT"]='Versandkosten';
+$versandS["BUGRU"]='';
+$versandS["TAX"]='';
+$versandV["ID"]='';
+$versandV["NR"]='divVerm';
+$versandV["Unit"]='';
+$versandV["TXT"]='Versandkosten';
+$versandV["BUGRU"]='';
+$versandV["TAX"]='';
+$minder["ID"]='';
+$minder["NR"]='divStd';
+$minder["Unit"]='';
+$minder["TXT"]='Mindermengenzuschlag';
+$minder["BUGRU"]='';
+$minder["TAX"]='';
+$nachn["ID"]='';
+$nachn["NR"]='';
+$nachn["Unit"]='';
+$nachn["TXT"]='';
+$nachn["BUGRU"]='';
+$nachn["TAX"]='';
+$treuh["ID"]='';
+$treuh["NR"]='';
+$treuh["Unit"]='';
+$treuh["TXT"]='Treuhandkosten';
+$treuh["BUGRU"]='';
+$treuh["TAX"]='';
+$paypal["ID"]='';
+$paypal["NR"]='divStd';
+$paypal["Unit"]='';
+$paypal["TXT"]='Paypalkosten';
+$paypal["BUGRU"]='';
+$paypal["TAX"]='';
+$bgcol[1]='#ddddff';
+$bgcol[2]='#ddffdd';
+$preA='G_';
+$preK='';
+$auftrnr='1';
+$kdnum='1';
+$pricegroup='';
+$unit='Stck';
+$longtxt='2';
+$invbrne='2';
+$variantnr='1';
+$OEinsPart='1';
+$lager='';
+?>
--- /dev/null
+<?
+// $Id: confedit.php 2009/02/10 14:41:30 hli Exp $
+if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ Header("WWW-Authenticate: Basic realm='Configurations-Editor'");
+ Header("HTTP/1.0 401 Unauthorized");
+ echo "Sie müssen sich autentifizieren\n";
+ exit;
+} else {
+ if (!$_POST) {
+ //Je Shop ein Conf-File == Multishop
+ $Shop=$_GET["Shop"];
+ if ($Shop != "" and file_exists ("conf$Shop.php")) {
+ require "conf$Shop.php";
+ $out = "Konfiguration für Shop $Shop gelesen";
+ } else {
+ //Singleshop oder noch kein Shop definiert
+ require "conf.php";
+ $out = "Standard-Konfiguration gelesen";
+ }
+ if ($_SERVER['PHP_AUTH_USER']<>$ERPftpuser || $_SERVER['PHP_AUTH_PW']<>$ERPftppwd) {
+ Header("WWW-Authenticate: Basic realm='My Realm'");
+ Header("HTTP/1.0 401 Unauthorized");
+ echo "Sie müssen sich autentifizieren\n";
+ exit;
+ }
+ echo $out;
+ }
+}
+
+include_once("error.php");
+include_once("dblib.php");
+$api = php_sapi_name();
+if ( $api == 'cli' ) {
+ echo "Nur im Browser benutzen\n";
+ exit(-1);
+};
+$err = new error($api);
+
+$zeichen = array("","UTF-8","ISO-8859-1","ISO-8859-15","Windows-1252","ASCII");
+function lager($sel,$db) {
+ if (!$db) return '';
+ $sql = "select w.description as lager,b.description as platz,b.id from ";
+ $sql .= "bin b left join warehouse w on w.id=b.warehouse_id ";
+ $sql .= "order by b.warehouse_id,b.id";
+ $bin=$db->getall($sql);
+ echo "\t<option value=-1 ".(($sel==-1)?'selected':'').">kein Lagerbestand\n";
+ echo "\t<option value=1 ".(($sel==1)?'selected':'').">Gesamtbestand\n";
+ if ($bin) foreach ($bin as $row) {
+ echo "\t<option value=".$row['id'];
+ if ($sel==$row['id']) echo " selected";
+ echo ">".$row['lager']." ".$row['platz']."\n";
+ }
+}
+function unit($sel,$db) {
+ if (!$db) return '';
+ $sql="select name from units order by sortkey";
+ $pgs=$db->getall($sql);
+ if ($sel=='') $sel=$pgs[0]['name'];
+ if ($pgs) foreach ($pgs as $row) {
+ echo "\t<option value=".$row['name'];
+ if ($sel==$row['name']) echo " selected";
+ echo ">".$row['name']."\n";
+ }
+}
+function pg($sel,$db) {
+ if (!$db) return '';
+ $sql="select id,pricegroup from pricegroup";
+ $pgs=$db->getall($sql);
+ echo "\t<option value=0";
+ if ($sel==0) echo " selected";
+ echo ">Standard VK\n";
+ if ($pgs) foreach ($pgs as $row) {
+ echo "\t<option value=".$row['id'];
+ if ($sel==$row['id']) echo " selected";
+ echo ">".$row['pricegroup']."\n";
+ }
+}
+function getTax($db) {
+ $sql = "SELECT BG.id AS bugru,T.rate,TK.startdate,C.taxkey_id, ";
+ $sql .= "(SELECT id FROM chart WHERE accno = T.taxnumber) AS tax_id, ";
+ $sql .= "BG.income_accno_id_0,BG.expense_accno_id_0 ";
+ $sql .= "FROM buchungsgruppen BG LEFT JOIN chart C ON BG.income_accno_id_0=C.id ";
+ $sql .= "LEFT JOIN taxkeys TK ON TK.chart_id=C.id ";
+ $sql .= "LEFT JOIN tax T ON T.id=TK.tax_id WHERE TK.startdate <= now()";
+ $rs = $db->getAll($sql);
+ if ($rs) foreach ($rs as $row) {
+ $nr = $row['bugru'];
+ if (!$TAX[$nr]) {
+ $data = array();
+ $data['startdate'] = $row['startdate'];
+ $data['rate'] = $row['rate']*100.0;
+ $TAX[$nr] = $data;
+ } else if ($TAX[$nr]['startdate'] < $row['startdate']) {
+ $TAX[$nr]["startdate"] = $row['startdate'];
+ $TAX[$nr]["rate"] = $row['rate']*100.0;
+ }
+ }
+ return $TAX;
+}
+function fputsA($f,$key,$var,$bg=false) {
+ $lf="\n";
+ fputs($f,'$'.$key.'["ID"]=\''. $var['ID'].'\';'.$lf);
+ fputs($f,'$'.$key.'["NR"]=\''. $var['NR'].'\';'.$lf);
+ fputs($f,'$'.$key.'["Unit"]=\''. $var['Unit'].'\';'.$lf);
+ fputs($f,'$'.$key.'["TXT"]=\''. $var['TXT'].'\';'.$lf);
+ if ($bg) fputs($f,'$'.$key.'["BUGRU"]=\''. $var['BUGRU'].'\';'.$lf);
+ if ($bg) fputs($f,'$'.$key.'["TAX"]=\''. $var['TAX'].'\';'.$lf);
+}
+if ($_POST["ok"]=="sichern") {
+ foreach ($_POST as $key=>$val) {
+ ${$key} = $val;
+ }
+};
+ $ok=true;
+ $dbP = new mydb($ERPhost,$ERPdbname,$ERPuser,$ERPpass,$ERPport,'pgsql',$err);
+ if (!$dbP->db) {
+ $ok=false;
+ echo "Keine Verbindung zur ERP<br>";
+ $dbP=false;
+ unset($divStd['ID']);
+ unset($divVerm['ID']);
+ unset($minder['ID']);
+ unset($versand['ID']);
+ unset($nachn['ID']);
+ unset($paypal['ID']);
+ unset($treuh['ID']);
+ unset($ERPusr['ID']);
+ } else {
+ $tax = getTax($dbP);
+ $sql="SELECT id,description,unit,buchungsgruppen_id FROM parts where partnumber = '%s'";
+ $rs=$dbP->getOne(sprintf($sql,$divStd['NR']));
+ $divStd['ID']=$rs['id'];
+ $divStd['Unit']=$rs['unit'];
+ $divStd['BUGRU']=$rs['buchungsgruppen_id'];
+ $divStd['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ $divStd['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$divVerm['NR']));
+ $divVerm['ID']=$rs['id'];
+ $divVerm['Unit']=$rs['unit'];
+ $divVerm['BUGRU']=$rs['buchungsgruppen_id'];
+ $divVerm['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ $divVerm['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$versandS['NR']));
+ $versandS['ID']=$rs['id'];
+ $versandS['Unit']=$rs['unit'];
+ $versandS['BUGRU']=$rs['buchungsgruppen_id'];
+ $versandS['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ if ($versandS['TXT'] == '') $versandS['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$versandV['NR']));
+ $versandV['ID']=$rs['id'];
+ $versandV['Unit']=$rs['unit'];
+ $versandV['BUGRU']=$rs['buchungsgruppen_id'];
+ $versandV['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ if ($versandV['TXT'] == '') $versandV['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$nachn['NR']));
+ $nachn['ID']=$rs['id'];
+ $nachn['Unit']=$rs['unit'];
+ $nachn['BUGRU']=$rs['buchungsgruppen_id'];
+ $nachn['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ if ($nachn['TXT'] == '') $nachn['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$minder['NR']));
+ $minder['ID']=$rs['id'];
+ $minder['Unit']=$rs['unit'];
+ $minder['BUGRU']=$rs['buchungsgruppen_id'];
+ $minder['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ if ($minder['TXT'] == '') $minder['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$paypal['NR']));
+ $paypal['ID']=$rs['id'];
+ $paypal['Unit']=$rs['unit'];
+ $paypal['BUGRU']=$rs['buchungsgruppen_id'];
+ $paypal['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ if ($paypal['TXT'] == '') $paypal['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne(sprintf($sql,$treuh['NR']));
+ $treuh['ID']=$rs['id'];
+ $treuh['Unit']=$rs['unit'];
+ $treuh['BUGRU']=$rs['buchungsgruppen_id'];
+ $treuh['TAX']=$tax[$rs['buchungsgruppen_id']]['rate'];
+ if ($treuh['TXT'] == '') $treuh['TXT']=addslashes($rs['description']);
+ $rs=$dbP->getOne("select id from employee where login = '".$ERPusrName."'");
+ $ERPusrID=$rs['id'];
+ }
+ $dbM = new mydb($SHOPhost,$SHOPdbname,$SHOPuser,$SHOPpass,$SHOPport,'mysql',$err);
+ if (!$dbM->db) {
+ $ok=false;
+ echo "Keine Verbindung zum Shop<br>";
+ $dbM=false;
+ };
+if ($_POST["ok"]=="sichern") {
+ $lf="\n";
+ $f=@fopen("conf$Shop.php","w");
+ if ($f) {
+ $v="1.5";
+ $d=date("Y/m/d H:i:s");
+ fputs($f,"<?php$lf// Verbindung zur ERP-db$lf");
+ fputs($f,'$ERPuser=\''.$ERPuser.'\';'.$lf);
+ fputs($f,'$ERPpass=\''.$ERPpass.'\';'.$lf);
+ fputs($f,'$ERPhost=\''.$ERPhost.'\';'.$lf);
+ fputs($f,'$ERPdbname=\''.$ERPdbname.'\';'.$lf);
+ fputs($f,'$codeLX=\''.$codeLX.'\';'.$lf);
+ fputs($f,'$mwstLX=\''.$mwstLX.'\';'.$lf);
+ fputs($f,'$ERPusrName=\''.$ERPusrName.'\';'.$lf);
+ fputs($f,'$ERPusrID=\''.$ERPusrID.'\';'.$lf);
+ fputs($f,'$ERPimgdir=\''.$ERPimgdir.'\';'.$lf);
+ fputs($f,'$maxSize=\''.$maxSize.'\';'.$lf);
+ fputs($f,'$ERPftphost=\''.$ERPftphost.'\';'.$lf);
+ fputs($f,'$ERPftpuser=\''.$ERPftpuser.'\';'.$lf);
+ fputs($f,'$ERPftppwd=\''.$ERPftppwd.'\';'.$lf);
+ fputs($f,'//Verbindung zur osCommerce-db'.$lf);
+ fputs($f,'$SHOPuser=\''.$SHOPuser.'\';'.$lf);
+ fputs($f,'$SHOPpass=\''.$SHOPpass.'\';'.$lf);
+ fputs($f,'$SHOPhost=\''.$SHOPhost.'\';'.$lf);
+ fputs($f,'$SHOPdbname=\''.$SHOPdbname.'\';'.$lf);
+ fputs($f,'$codeS=\''.$codeS.'\';'.$lf);
+ fputs($f,'$mwstS=\''.$mwstS.'\';'.$lf);
+ fputs($f,'$SHOPimgdir=\''.$SHOPimgdir.'\';'.$lf);
+ fputs($f,'$SHOPftphost=\''.$SHOPftphost.'\';'.$lf);
+ fputs($f,'$SHOPftpuser=\''.$SHOPftpuser.'\';'.$lf);
+ fputs($f,'$SHOPftppwd=\''.$SHOPftppwd.'\';'.$lf);
+ fputs($f,'$nopic=\''.$nopic.'\';'.$lf);
+ fputs($f,'$nopicerr=\''.$nopicerr.'\';'.$lf);
+ fputsA($f,'divStd',$divStd,true);
+ fputsA($f,'divVerm',$divVerm,true);
+ fputsA($f,'versandS',$versandS,true);
+ fputsA($f,'versandV',$versandV,true);
+ fputsA($f,'minder',$minder,true);
+ fputsA($f,'nachn',$nachn,true);
+ fputsA($f,'treuh',$treuh,true);
+ fputsA($f,'paypal',$paypal,true);
+ fputs($f,'$bgcol[1]=\'#ddddff\';'.$lf);
+ fputs($f,'$bgcol[2]=\'#ddffdd\';'.$lf);
+ fputs($f,'$preA=\''.$preA.'\';'.$lf);
+ fputs($f,'$preK=\''.$preK.'\';'.$lf);
+ fputs($f,'$auftrnr=\''.$auftrnr.'\';'.$lf);
+ //fputs($f,'$utftrans=\''.$utftrans.'\';'.$lf);
+ fputs($f,'$kdnum=\''.$kdnum.'\';'.$lf);
+ fputs($f,'$pricegroup=\''.$pricegroup.'\';'.$lf);
+ fputs($f,'$unit=\''.$unit.'\';'.$lf);
+ fputs($f,'$longtxt=\''.$longtxt.'\';'.$lf);
+ fputs($f,'$invbrne=\''.$invbrne.'\';'.$lf);
+ fputs($f,'$variantnr=\''.$variantnr.'\';'.$lf);
+ fputs($f,'$OEinsPart=\''.$OEinsPart.'\';'.$lf);
+ fputs($f,'$lager=\''.$lager.'\';'.$lf);
+ //fputs($f,'$showErr=true;'.$lf);
+ fputs($f,"?>");
+ fclose($f);
+ echo "Konfiguration conf$Shop.php gesichert.";
+ } else {
+ echo "Konfigurationsdatei (conf$Shop.php) konnte nicht geschrieben werden";
+ }
+}
+?>
+<html>
+<body>
+<center>
+<table style="background-color:#cccccc" border="0">
+<form name="ConfEdit" method="post" action="confedit.php">
+<input type="hidden" name="Shop" value="<?= $Shop ?>">
+<input type="hidden" name="divStd[ID]" value="<?= $divStd['ID'] ?>">
+<input type="hidden" name="divVerm[ID]" value="<?= $divVerm['ID'] ?>">
+<input type="hidden" name="minder[ID]" value="<?= $minder['ID'] ?>">
+<input type="hidden" name="versandS[ID]" value="<?= $versandS['ID'] ?>">
+<input type="hidden" name="versandV[ID]" value="<?= $versandV['ID'] ?>">
+<input type="hidden" name="nachn[ID]" value="<?= $nachn['ID'] ?>">
+<input type="hidden" name="paypal[ID]" value="<?= $paypal['ID'] ?>">
+<input type="hidden" name="treuh[ID]" value="<?= $treuh['ID'] ?>">
+<input type="hidden" name="ERPusr[ID]" value="<?= $ERPusr['ID'] ?>">
+
+<tr><th>Daten</th><th>Lx-ERP</th><th><?php echo $Shop ?></th><th>Shop</th></tr>
+<tr>
+ <td>db-Host</td>
+ <td colspan="2"><input type="text" name="ERPhost" size="25" value="<?= $ERPhost ?>"></td>
+ <td><input type="text" name="SHOPhost" size="25" value="<?= $SHOPhost ?>"></td>
+</tr>
+<tr>
+ <td>Database</td>
+ <td colspan="2"><input type="text" name="ERPdbname" size="20" value="<?= $ERPdbname ?>"></td>
+ <td><input type="text" name="SHOPdbname" size="20" value="<?= $SHOPdbname ?>"></td>
+</tr>
+<tr>
+ <td>db-User Name</td>
+ <td colspan="2"><input type="text" name="ERPuser" size="15" value="<?= $ERPuser ?>"></td>
+ <td><input type="text" name="SHOPuser" size="15" value="<?= $SHOPuser ?>"></td>
+</tr>
+<tr>
+ <td>db-User PWD</td>
+ <td colspan="2"><input type="text" name="ERPpass" size="15" value="<?= $ERPpass ?>"></td>
+ <td><input type="text" name="SHOPpass" size="15" value="<?= $SHOPpass ?>"></td>
+</tr>
+</tr>
+ <td>Zeichensatz</td>
+ <td colspan="2"><select name="codeLX">
+<?php foreach($zeichen as $code) {
+ echo "<option value='".$code."'";
+ if ($code == $codeLX) echo " selected";
+ echo ">".$code."\n"; };
+?>
+ </select></td>
+ <td ><select name="codeS">
+<?php foreach($zeichen as $code) {
+ echo "<option value='".$code."'";
+ if ($code == $codeS) echo " selected";
+ echo ">".$code."\n"; };
+?>
+ </select></td>
+</tr>
+<tr>
+ <td>Preise </td>
+ <td colspan="2"> <input type="radio" name="mwstLX" value="1" <?= ($mwstLX==1)?"checked":'' ?>> incl.
+ <input type="radio" name="mwstLX" value="0" <?= ($mwstLX<>1)?"checked":'' ?>> excl. MwSt</td>
+ <td><input type="radio" name="mwstS" value="1" <?= ($mwstS==1)?"checked":'' ?>> incl.
+ <input type="radio" name="mwstS" value="0" <?= ($mwstS<>1)?"checked":'' ?>> excl. MwSt</td>
+</tr>
+<tr>
+ <td>User-ID</td>
+ <td colspan="2"><input type="text" name="ERPusrName" size="10" value="<?= $ERPusrName ?>">
+ <input type="checkbox" name="a1" <?= (empty($ERPusrID)?'':"checked") ?>></td>
+ <td></td>
+</tr>
+<tr>
+ <td>Image-Dir</td>
+ <td colspan="2"><input type="text" name="ERPimgdir" size="30" value="<?= $ERPimgdir ?>"></td>
+ <td><input type="text" name="SHOPimgdir" size="30" value="<?= $SHOPimgdir ?>"></td>
+</tr>
+<tr>
+ <td>Platzhalterbild</td>
+ <td colspan="2"><input type="text" name="nopic" size="20" value="<?php echo $nopic; ?>">ohne Endung</td>
+ <td colspan="2"><input type="checkbox" value="1" name="nopicerr" <?= (empty($nopicerr)?'':"checked") ?>>nur bei fehlerhaftem Upload verwenden</td>
+</tr>
+<tr>
+ <td>FTP-Host</td>
+ <td colspan="2"><input type="text" name="ERPftphost" size="20" value="<?= $ERPftphost ?>"></td>
+ <td><input type="text" name="SHOPftphost" size="20" value="<?= $SHOPftphost ?>"></td>
+</tr>
+<tr>
+ <td>FTP-User</td>
+ <td colspan="2"><input type="text" name="ERPftpuser" size="15" value="<?= $ERPftpuser ?>"></td>
+ <td><input type="text" name="SHOPftpuser" size="15" value="<?= $SHOPftpuser ?>"></td>
+</tr>
+<tr>
+ <td>FTP-User PWD</td>
+ <td colspan="2"><input type="text" name="ERPftppwd" size="15" value="<?= $ERPftppwd ?>"></td>
+ <td><input type="text" name="SHOPftppwd" size="15" value="<?= $SHOPftppwd ?>"></td>
+</tr>
+<tr>
+ <td>Nr Diverse Std-MwSt</td>
+ <td><input type="text" name="divStd[NR]" size="10" value="<?= $divStd['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($divStd['ID'])?'':"checked") ?>></td>
+ <td>Nr Diverse Verm-MwSt</td>
+ <td><input type="text" name="divVerm[NR]" size="10" value="<?= $divVerm['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($divVerm['ID'])?'':"checked") ?>></td>
+</tr>
+<tr>
+ <td>Nr Versand Std-MwSt</td>
+ <td><input type="text" name="versandS[NR]" size="10" value="<?= $versandS['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($versandS['ID'])?'':"checked") ?>></td>
+ <td>Text:</td>
+ <td><input type="text" name="versandS[TXT]" size="20" value="<?= $versandS['TXT'] ?>"><?= $versandS['TAX'] ?></td>
+<tr>
+ <td>Nr Versand Verm-MwSt</td>
+ <td><input type="text" name="versandV[NR]" size="10" value="<?= $versandV['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($versandV['ID'])?'':"checked") ?>></td>
+ <td>Text:</td>
+ <td><input type="text" name="versandV[TXT]" size="20" value="<?= $versandV['TXT'] ?>"><?= $versandV['TAX'] ?></td>
+</tr>
+<tr>
+ <td>Nr Paypal</td>
+ <td><input type="text" name="paypal[NR]" size="10" value="<?= $paypal['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($paypal['ID'])?'':"checked") ?>></td>
+ <td>Text:</td>
+ <td><input type="text" name="paypal[TXT]" size="20" value="<?= $paypal['TXT'] ?>"></td>
+</tr>
+<tr>
+ <td>Nr Treuhand</td>
+ <td><input type="text" name="treuh[NR]" size="10" value="<?= $treuh['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($treuh['ID'])?'':"checked") ?>></td>
+ <td>Text:</td>
+ <td><input type="text" name="treuh[TXT]" size="20" value="<?= $treuh['TXT'] ?>"></td>
+</tr>
+<tr>
+ <td>Nr Mindermenge</td>
+ <td><input type="text" name="minder[NR]" size="10" value="<?= $minder['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($minder['ID'])?'':"checked") ?>></td>
+ <td>Text:</td>
+ <td><input type="text" name="minder[TXT]" size="20" value="<?= $minder['TXT'] ?>"></td>
+</tr>
+<tr>
+ <td>Nr Nachname</td>
+ <td><input type="text" name="nachn[NR]" size="10" value="<?= $nachn['NR'] ?>">
+ <input type="checkbox" name="a1" <?= (empty($nachn['ID'])?'':"checked") ?>></td>
+ <td>Text:</td>
+ <td><input type="text" name="nachn[TXT]" size="20" value="<?= $nachn['TXT'] ?>"></td>
+</tr>
+<tr>
+ <td>Std-Einheit</td>
+ <td><select name="unit">
+<? unit($unit,$dbP); ?>
+ </select></td>
+ <td>Preisgruppe</td>
+ <td><select name="pricegroup">
+<? pg($pricegroup,$dbP); ?>
+ </select></td>
+<tr>
+ <td colspan="2">Auftragsnummern durch</td>
+ <td><input type="radio" name="auftrnr" value="1" <?= ($auftrnr==1)?"checked":'' ?>> LxO</td>
+ <td><input type="radio" name="auftrnr" value="0" <?= ($auftrnr<>1)?"checked":'' ?>> Shop</td>
+</tr>
+<tr>
+ <td colspan="2">Kundennummern durch</td>
+ <td><input type="radio" name="kdnum" value="1" <?= ($kdnum==1)?"checked":'' ?>> LxO</td>
+ <td><input type="radio" name="kdnum" value="0" <?= ($kdnum<>1)?"checked":'' ?>> Shop</td>
+</tr>
+<tr>
+ <td colspan="2">Nummernerweiterung</td>
+ <td>Auftrag<input type="text" name="preA" size="5" value="<?= $preA ?>"></td>
+ <td>Kunde<input type="text" name="preK" size="5" value="<?= $preK ?>"></td>
+</tr>
+<tr>
+ <td>Lagerbestand aus</td>
+ <td><select name="lager">
+<? lager($lager,$dbP); ?>
+ </select></td>
+ <td></td>
+ <td></td>
+<tr>
+<tr>
+ <td colspan="3">Langbeschreibung aus Shop übernehmen</td>
+ <td><input type="radio" name="longtxt" value="1" <?= ($longtxt<>2)?"checked":'' ?>>Ja
+ <input type="radio" name="longtxt" value="2" <?= ($longtxt==2)?"checked":'' ?>>Nein</td>
+
+</tr>
+<tr>
+ <td colspan="3">LxO-Rechnungen sind Netto</td>
+ <td><input type="radio" name="invbrne" value="1" <?= ($invbrne<>2)?"checked":'' ?>>Ja
+ <input type="radio" name="invbrne" value="2" <?= ($invbrne==2)?"checked":'' ?>>Nein</td>
+</tr>
+<tr>
+ <td colspan="3">Varianten sind eigene Nummern in Lx (-n)</td>
+ <td><input type="radio" name="variantnr" value="1" <?= ($variantnr<>2)?"checked":'' ?>>Ja
+ <input type="radio" name="variantnr" value="2" <?= ($variantnr==2)?"checked":'' ?>>Nein</td>
+</tr>
+<tr>
+ <td colspan="3">Unbekannte Artikel beim Bestellimport anlegen</td>
+ <td><input type="radio" name="OEinsPart" value="1" <?= ($OEinsPart<>2)?"checked":'' ?>>Ja
+ <input type="radio" name="OEinsPart" value="2" <?= ($OEinsPart==2)?"checked":'' ?>>Nein</td>
+</tr>
+
+<!--tr>
+ <td>Bildergrösse (byte)</td>
+ <td><input type="text" name="maxSize" size="10" value="<?= $maxSize ?>"></td>
+ <td></td>
+</tr-->
+
+
+<tr><td colspan="4" align="center"><input type="submit" name="ok" value="sichern"></td></tr>
+</form>
+</table>
+</center>
+</body>
+</html>
--- /dev/null
+<?php
+
+include_once("MDB2.php");
+
+class mydb {
+
+ var $db = false;
+ var $error = false;
+ var $debug = true;
+ var $dbf = false;
+
+ function mydb($host,$db,$user,$pass,$port,$proto,$error) {
+ $this->error = $error;
+ $dsn = array('phptype' => $proto,
+ 'username' => $user,
+ 'password' => $pass,
+ 'hostspec' => $host,
+ 'database' => $db,
+ 'port' => $port);
+ if ( $this->debug ) {
+ $this->dbf = fopen ("tmp/shop.log","w");
+ if ( !$this->dbf ) $this->debug = false;
+ }
+ $this->connect($dsn);
+ }
+
+ function log($txt) {
+ $now = date('Y-m-d H:i:s');
+ fputs($this->dbf,$now." : ".$txt."\n");
+ }
+ function connect($dsn) {
+ $options = array('result_buffering' => false,);
+ $this->db = MDB2::connect($dsn,$options);
+ if ( $this->debug ) $this->log('Connect:');
+ if (PEAR::isError($this->db)) {
+ if ( $this->debug ) $this->log($this->db->getMessage());
+ $this->error->write('dblib->connect',$this->db->getMessage());
+ $this->error->write('dblib->connect',print_r($dsn,true));
+ $this->db = false;
+ return false;
+ }
+ $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
+ }
+ function Begin() {
+ return $this->db->beginTransaction();
+ }
+ function Commit() {
+ return $this->db->commit();
+ }
+ function Rollback() {
+ return $this->db->rollback();
+ }
+
+ function getAll($sql) {
+ $rs = $this->db->queryAll($sql);
+ if ( $this->debug ) $this->log($sql);
+ if (PEAR::isError($rs)) {
+ if ( $this->debug ) $this->log($rs->getUserinfo());
+ $this->error->write('dblib->getAll',$rs->getUserinfo());
+ return false;
+ }
+ return $rs;
+ }
+
+ function getOne($sql) {
+ $rs = $this->db->queryRow($sql);
+ if ( $this->debug ) $this->log($sql);
+ if (PEAR::isError($rs)) {
+ if ( $this->debug ) $this->log($rs->getUserinfo());
+ $this->error->write('dblib->getOne',$rs->getUserinfo());
+ return false;
+ }
+ return $rs;
+ }
+ function query($sql) {
+ $rc = $this->db->query($sql);
+ if ( $this->debug ) $this->log($sql);
+ if (PEAR::isError($rc)) {
+ if ( $this->debug ) $this->log($rc->getUserinfo());
+ $this->error->write('dblib->query',$rc->getUserinfo());
+ return false;
+ }
+ return $rc;
+ }
+ function insert($statement,$data) {
+ if ( $this->debug ) $this->log("INSERT ".$statement);
+ $sth = $this->db->prepare($statement); //Prepare
+ if (PEAR::isError($sth)) {
+ $this->error->write('dblib->insert 1',$sth->getMessage());
+ $this->error->write('dblib->insert 2',$sth->getUserinfo());
+ $this->rollback();
+ return false;
+ }
+ if ( $this->debug ) $this->log(print_r($data,true));
+ $rc =& $sth->execute($data);
+ if (PEAR::isError($rc)) {
+ if ( $this->debug ) $this->log($rc->getUserinfo());
+ $this->error->write('dblib->insert 3',$rc->getUserinfo());
+ return false;
+ }//else{
+ // $rc = $this->commit();
+ //}
+ return $rc;
+ }
+ function update($statement,$data) {
+ if ( $this->debug ) $this->log("UPDATE ".$statement);
+ $sth = $this->db->prepare($statement); //Prepare
+ if (PEAR::isError($sth)) {
+ if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
+ $this->error->write('dblib->update 1',$sth->getMessage());
+ $this->error->write('dblib->update 2',$sth->getUserinfo());
+ $this->rollback();
+ return false;
+ }
+ if ( $this->debug ) $this->log(print_r($data,true));
+ $rc =& $sth->execute($data);
+ if (PEAR::isError($rc)) {
+ if ( $this->debug ) $this->log("ERRPOR ".$rc->getUserinfo());
+ $this->error->write('dblib->update 3',$rc->getUserinfo());
+ return false;
+ }//else{
+ // $rc = $this->commit();
+ //}
+ return $rc;
+ }
+ function insertMultipe($statement,$data) {
+ $this->db->loadModule('Extended');
+ if (!$this->db->supports('transactions')){
+ return false;
+ }
+ $sth = $this->db->prepare($statement); //Prepare
+ if (PEAR::isError($sth)) {
+ $this->error->write('dblib->insertMultiple',$sth->getMessage());
+ $this->rollback();
+ return false;
+ }
+ $rc =& $this->db->beginTransaction();
+ $rc =& $this->db->extended->executeMultiple($sth, $data);
+ if (PEAR::isError($rc)) {
+ $this->error->write('dblib->insertMultiple',$rc->getUserinfo());
+ $this->rollback();
+ return false;
+ }else{
+ $rc = $this->commit();
+ }
+ return $rc;
+ }
+}
+
+?>
--- /dev/null
+<?php
+/*
+
+shop muß gesetzt sein, obsolet nicht
+
+Multishop: Hierfür müssen benutzerdefinierte Variablen angelegt werden.
+Typ:checkbox, Name=shop[0-9A-Z]+, Bearbeitbar=nein
+
+
+*/
+
+class erp {
+
+ var $db = false;
+ var $error = false;
+ var $TAX = false;
+ var $mkPart = true;
+ var $divStd = false;
+ var $divVerm = false;
+ var $doordnr = false;
+ var $docustnr = false;
+ var $lager = 1;
+ var $preordnr = '';
+ var $precustnr = '';
+ var $OEinsPart = false;
+ var $INVnetto = true; //Rechnungen mit Nettopreisen
+ var $SHOPincl = true; //Shoppreise sind Brutto
+
+ function erp($db,$error,$divStd,$divVerm,$doordnr,$docustnr,$preordnr,$precustnr,$INVnetto,$SHOPincl,$OEinsPart,$lager) {
+ $this->db = $db;
+ $this->error = $error;
+ $this->divStd = $divStd;
+ $this->divVerm = $divVerm;
+ $this->doordnr = $doordnr;
+ $this->preordnr = $preordnr;
+ $this->docustnr = $docustnr;
+ $this->precustnr = $precustnr;
+ $this->INVnetto = ($INVnetto == 1)?true:false;
+ $this->SHOPincl = ($SHOPincl == 1)?true:false;
+ $this->OEinsPart = ($OEinsPart == 1)?true:false;
+ $this->lager = ($lager)?$lager:1;
+ $this->getTax();
+ }
+
+ function getTax() {
+ $sql = "SELECT BG.id AS bugru,T.rate,TK.startdate,C.taxkey_id, ";
+ $sql .= "(SELECT id FROM chart WHERE accno = T.taxnumber) AS tax_id, ";
+ $sql .= "BG.income_accno_id_0,BG.expense_accno_id_0 ";
+ $sql .= "FROM buchungsgruppen BG LEFT JOIN chart C ON BG.income_accno_id_0=C.id ";
+ $sql .= "LEFT JOIN taxkeys TK ON TK.chart_id=C.id ";
+ $sql .= "LEFT JOIN tax T ON T.id=TK.tax_id WHERE TK.startdate <= now()";
+ $rs = $this->db->getAll($sql);
+ if ($rs) foreach ($rs as $row) {
+ $nr = $row['bugru'];
+ if (!$this->TAX[$nr]) {
+ $data = array();
+ $data['startdate'] = $row['startdate'];
+ $data['rate'] = $row['rate'];
+ $data['taxkey'] = $row['taxkey_id'];
+ $data['taxid'] = $row['tax_id'];
+ $data['income'] = $row['income_accno_id_0'];
+ $data['expense'] = $row['expense_accno_id_0'];
+ $this->TAX[$nr] = $data;
+ } else if ($this->TAX[$nr]['startdate'] < $row['startdate']) {
+ $this->TAX[$nr]["startdate"] = $row['startdate'];
+ $this->TAX[$nr]["rate"] = $row['rate'];
+ $this->TAX[$nr]["taxkey"] = $row['taxkey_id'];
+ $this->TAX[$nr]["taxid"] = $row['tax_id'];
+ $this->TAX[$nr]["income"] = $row['income_accno_id_0'];
+ $this->TAX[$nr]["expense"] = $row['expense_accno_id_0'];
+ }
+ }
+ }
+
+ function getParts($stdprice=0,$shop=0) {
+ $where = "WHERE 1=1 ";
+ if ($stdprice>0) {
+ $sql = "SELECT P.partnumber,P.description,P.notes,P.weight,G.price as sellprice,P.sellprice as stdprice,";
+ $sql .= "PG.partsgroup,P.image,P.buchungsgruppen_id as bugru,P.unit";
+ if ($this->lager>1) {
+ $sql .= ",(select sum(qty) from inventory where bin_id = ".$this->lager." and parts_id = P.id) as onhand ";
+ } else {
+ $sql .= ",P.onhand ";
+ }
+ $sql .= "FROM parts P ";
+ $sql .= "LEFT JOIN partsgroup PG on PG.id=P.partsgroup_id ";
+ $sql .= "LEFT JOIN prices G on G.parts_id=P.id ";
+ $where .= "AND (G.pricegroup_id=$stdprice ";
+ $where .= "or G.pricegroup_id is null) ";
+ } else {
+ $sql = "SELECT P.partnumber,P.description,P.notes,P.weight,P.sellprice,";
+ $sql .= "PG.partsgroup,P.image,P.buchungsgruppen_id as bugru,P.unit ";
+ if ($this->lager>1) {
+ $sql .= ",(select sum(qty) from inventory where bin_id = ".$this->lager." and parts_id = P.id) as onhand ";
+ } else {
+ $sql .= ",P.onhand ";
+ }
+ $sql .= "FROM parts P left join partsgroup PG on PG.id=P.partsgroup_id ";
+ }
+ if ($shop>0) {
+ $sql .= "LEFT JOIN custom_variables CV on CV.trans_id=P.id ";
+ $where .= "AND (CV.config_id = $shop AND bool_value = 't')";
+ }
+ $where .= "AND shop = 't' ";
+ $where .= "AND obsolete = 'f' ORDER BY P.partnumber";
+ $rs = $this->db->getAll($sql.$where);
+ if ($rs) for($i = 0; $i < count($rs); $i++) {
+ $rs[$i]['tax'] = $this->TAX[$rs[$i]['bugru']]['rate'];
+ }
+ return $rs;
+ }
+
+ function getPartsLang($lang,$alle) {
+ $sql = "SELECT P.partnumber,L.translation,P.description,L.longdescription,P.notes,PG.partsgroup ";
+ $sql .= "FROM parts P left join translation L on L.parts_id=P.id left join partsgroup PG on PG.id=P.partsgroup_id ";
+ $sql .= "WHERE P.shop='t' and (L.language_id = $lang";
+ if ($alle) {
+ $sql .= " or L.language_id is Null)";
+ } else {
+ $sql.=")";
+ };
+ $rs = $this->getAll($sql);
+ $data=array();
+ if ($rs) foreach ($rs as $row) {
+ if (!$data[$row["partnumber"]]) $data[$row["partnumber"]]=$row;
+ }
+ return $data;
+ }
+ function getNewNr($typ) {
+ /*
+ so = Auftragsnummer
+ customer = Kundennummer
+ */
+ $typ .= "number";
+ $sql = "SELECT $typ FROM defaults";
+ $rs = $this->db->getOne($sql);
+ $i=strlen($rs["$typ"])-1;
+ //Nummern können Buchstaben, Zeichen und Zahlen enthalten
+ //nur die Zahlen von rechts werden aber inkrementiert.
+ while($i>=0) {
+ if ($rs["$typ"][$i] >= "0" and $rs["$typ"][$i]<="9") {
+ $n=$rs["$typ"][$i].$n;
+ $i--;
+ } else {
+ $pre = substr($rs["$typ"],0,$i+1);
+ $i=-1;
+ }
+ };
+ $nr = (int)$n + 1;
+ $sonr = $pre.$nr;
+ $sql = "UPDATE defaults SET $typ = '$sonr'";
+ $rc = $this->db->query($sql);
+ if (!$rc) {
+ $this->error->write('erplib','Neue Nummer ($typ) nicht gesichert: '.$sonr);
+ }
+ return $sonr;
+ }
+ function newOrder($data) {
+ /*Einen neuen Auftrag anlegen. Folgendes Array muß übergeben werden:
+ $data = array(ordnumber,customer_id,employee_id,taxzone_id,amount,netamount,transdate,notes,intnotes,shipvia)
+ Rückgabe oe.id */
+ $this->db->begin();
+ $incltax = ($this->INVnetto)?'f':'t';
+ $sql = "INSERT INTO oe (ordnumber,customer_id,employee_id,taxzone_id,taxincluded,curr,amount,netamount,transdate,notes,intnotes,shipvia,cusordnumber) ";
+ $sql .= "values (:ordnumber,:customer_id,:employee_id,:taxzone_id,'$incltax',:curr,:amount,:netamount,:transdate,:notes,:intnotes,:shipvia,:cusordnumber)";
+ $rc = $this->db->insert($sql,$data);
+ $sql = "SELECT * FROM oe where ordnumber = '".$data["ordnumber"]."'";
+ $rs = $this->db->getOne($sql);
+ if (!$rs['id']) {
+ $this->error->write('erplib','Auftrag erzeugen: '.$data["ordnumber"]);
+ $this->db->rollback();
+ return false;
+ } else {
+ $this->err->out(" Auftrag: ".$data["ordnumber"]." ");
+ return $rs['id'];
+ }
+ }
+ function insParts($trans_id,$data,$longtxt) {
+ /*Artikel in die orderitem einfügen. Folgende Daten müssen übergeben werden:
+ $trans_id = (int) oe.id
+ $data = array(trans_id,partnumber,description,longdescription,qty,sellprice,unit)*/
+ foreach ($data as $row) {
+ $row['trans_id'] = $trans_id;
+ //$sql = "SELECT id FROM parts WHERE partnumber = '".$row['partnumber']."'";
+ //$tmp = $this->db->getOne($sql);
+ $tmp = $this->chkPartnumber($row,$this->OEinsPart,true);
+ if ($tmp) {
+ $row['parts_id'] = $tmp['id'];
+ } else {
+ if ($this->TAX[$this->divStd['BUGRU']]['rate'] == $row['mwst']/100) {
+ $row['parts_id'] = $this->divStd['ID'];
+ } else if ($this->TAX[$this->divVerm['BUGRU']]['rate'] == $row['mwst']/100) {
+ $row['parts_id'] = $this->divVerm['ID'];
+ } else {
+ $row['parts_id'] = $this->divStd['ID'];
+ }
+ }
+ if ($this->INVnetto) {
+ if ($this->SHOPincl)
+ $row['sellprice'] = round($row['sellprice'] / (100 + $row['taxrate']) * 100,2);
+ } else {
+ if (!$this->SHOPincl)
+ $row['sellprice'] = round($row['sellprice'] * (100 + $row['taxrate']) * 100,2);
+ }
+ $row['unit'] = $this->chkUnit($row['unit']);
+ if ($longtxt == 1) {
+ //$row['longdescription'] = addslashes($row['longdescription']);
+ $row['longdescription'] = $row['longdescription'];
+ } else {
+ //$row['longdescription'] = addslashes($tmp['longdescription']);
+ $row['longdescription'] = $tmp['longdescription'];
+ }
+ //$row['description'] = addslashes($row['description']);
+ $sql = "INSERT INTO orderitems (trans_id,parts_id,description,longdescription,qty,sellprice,unit,pricegroup_id,discount) ";
+ $sql .= "VALUES (:trans_id,:parts_id,:description,:longdescription,:qty,:sellprice,:unit,0,0)";
+ $row["trans_id"]=$trans_id;
+ $rc = $this->db->insert($sql,$row);
+ if (!$rc) {
+ $this->db->rollback();
+ return false;
+ };
+ };
+ $this->db->commit();
+ return true;
+ }
+ function insCustomer($data) {
+ $this->err->out('Insert:'.$data["name"].' ');
+ if ($this->docustnr == 1) {
+ $data['customernumber'] = $this->getNewNr('customer');
+ } else {
+ $data['customernumber'] = $data['shopid'];
+ }
+ $data['customernumber'] = $this->precustnr.$data['customernumber'];
+ if ($data['customernumber']>0) {
+ if (!$data['greeting']) $data['greeting'] = '';
+ $sql = "INSERT INTO customer (greeting,name,street,city,zipcode,country,contact,phone,email,customernumber)";
+ $sql .= " VALUES (:greeting,:name,:street,:city,:zipcode,:country,:contact,:phone,:email,:customernumber)";
+ $rc = $this->db->insert($sql,$data);
+ $sql = "SELECT id FROM customer WHERE customernumber = '".$data['customernumber']."'";
+ $rs = $this->db->getOne($sql);
+ $rc = $rs['id'];
+ $this->err->out("Kd-Nr: ".$data['customernumber'].":".$rs['id']);
+ } else {
+ $this->error->write('erplib','Kunde anlegen: '.$data["name"]);
+ $this->db->rollback();
+ return false;
+ }
+ return $rc;
+ }
+ function chkCustomer($data) {
+ if ($data['customer_id']>0) {
+ $sql = "SELECT * FROM customer WHERE id = ".$data['customer_id'];
+ $rs = $this->db->getOne($sql);
+ if ($rs['id'] == $data['customer_id']) {
+ $this->err->out('Update:'.$data['customer_id'].' ');
+ $sql = "UPDATE customer SET greeting = :greeting,name = :name,street = :street,city = :city,country = :country,";
+ $sql .= "zipcode = :zipcode,contact = :contact,phone = :phone,email = :email WHERE id = :customer_id";
+ $rc = $this->db->update($sql,$data);
+ if ($rc) $rc = $data['customer_id'];
+ } else {
+ $rc = $this->insCustomer($data);
+ }
+ } else {
+ $rc = $this->insCustomer($data);
+ }
+ return $rc;
+ }
+ function mkAuftrag($data,$shop,$longtxt) {
+ $this->db->Begin();
+ $data["notes"] .= "\nBezahlung:".$data['bezahlung']."\n";
+ if ($data['bezahlung'] == "Kreditkarte") $data["notes"] .= $data['kreditkarte']."\n";
+ if ($shop) {
+ $data["intnotes"] = "Shop: $shop";
+ } else {
+ $data["intnotes"] = "";
+ };
+ $data["customer_id"] = $this->chkCustomer($data["customer"]);
+ $parts = $data['parts'];
+ unset($data['parts']);
+ unset($data['customer']);
+ if ($this->doordnr == 1) {
+ $data["ordnumber"] = $this->getNewNr('so');
+ } else {
+ $data["ordnumber"] = $data['cusordnumber'];
+ }
+ $data["ordnumber"] = $this->preordnr.$data["ordnumber"];
+ $tid = $this->newOrder($data);
+ if ($tid) {
+ $rc = $this->insParts($tid,$parts,$longtxt);
+ if (!$rc) {
+ $this->error->write('erplib','Artikel zu Auftrag');
+ return -1;
+ }
+ } else {
+ $this->error->write('erplib','Auftrag anlegen');
+ return -1;
+ }
+ $this->err->out($data["customer"]["firma"]." ");
+ $rc = $this->db->Commit();
+ return $data["customer_id"];
+ }
+ function chkPartsgroup($pg,$new=True) {
+ /*gibt es die Warengruppe?
+ Rückgabe nichts oder die partsgroup.id
+ ggf neu anlegen*/
+ $sql = "SELECT * FROM partsgroup WHERE partsgroup = '".$pg."'";
+ $rs = $this->db->getOne($sql);
+ if ($rs) {
+ return $rs['id'];
+ } else if ($this->mkPart and $new) {
+ return $this->mkNewPartsgroup($pg);
+ } else {
+ return '';
+ };
+ }
+ function mkNewPartsgroup($name) {
+ $sql = "INSERT INTO partsgroup (partsgroup) VALUES ('".$name."')";
+ $rc = $this->db->query($sql);
+ if ($rc) {
+ return $this->chkPartsgroup($name,False);
+ } else {
+ return '';
+ }
+ }
+ function chkUnit($unit) {
+ /*Prüfen ob es die Unit gibt.
+ wenn nicht, die Standardunit zurückgeben*/
+ if ($unit == '') {
+ return $this->stdUnit();
+ } else {
+ $sql = "SELECT * FROM units WHERE name ilike '".$unit."'";
+ $rs = $this->db->getOne($sql);
+ if ($rs) {
+ return $rs["name"];
+ } else {
+ return $this->stdUnit();
+ }
+ }
+ }
+ function stdUnit() {
+ $sql = "SELECT * FROM units WHERE type = 'dimension' ORDER BY sortkey LIMIT 1";
+ $rs = $this->db->getOne($sql);
+ return $rs["name"];
+ }
+ function chkPartnumber($data,$new=True,$long=false) {
+ $sql = "SELECT * FROM parts WHERE partnumber = '".$data["partnumber"]."'";
+ $rs = $this->db->getOne($sql);
+ if ($rs) {
+ if ($long) {
+ return $rs;
+ } else {
+ return $rs['id'];
+ }
+ } else if ($this->mkPart and $new) {
+ $data['id'] = $this->mkNewPart($data);
+ if ($long) {
+ return $data;
+ } else {
+ return $data['id'];
+ }
+ } else {
+ return '';
+ };
+ }
+ function mkNewPart($data) {
+ /*eine neue Ware anlegen, sollte nicht direkt aufgerufen werden.
+ Auf vorhandene partnumber wird nicht geprüft.
+ Folgendes Array muß übergeben werden:
+ $data = array(partnumber,description,longdescription,weight,sellprice,taxrate,partsgroup,unit)
+ Rückgabe parts.id
+ */
+ if ($data['partnumber'] == '') {
+ $this->error->write('erplib','Artikelnummer fehlt');
+ return false;
+ }
+ if ($data['description'] == '') {
+ $this->error->write('erplib','Artikelbezeichnung fehlt');
+ return false;
+ }
+ $data['notes'] = addslashes($data['longdescription']);
+ if ($data['weight']*1 != $data['weight']) $data['weight']=0;
+ if ($data['sellprice']*1 != $data['sellprice']) $data['sellprice']=0;
+ if (!in_array($data["buchungsgruppen_id"],$this->TAX)) {
+ foreach ($this->TAX as $key=>$tax) {
+ if ($tax["rate"] == $data["taxrate"]/100) {
+ $data["buchungsgruppen_id"] = $key;
+ break;
+ }
+ }
+ if (!$data["buchungsgruppen_id"]) {
+ $this->error->write('erplib','Buchungsgruppe konnte nicht zugeordnet werden');
+ return false;
+ }
+ };
+ if ($data["partsgroup"]) {
+ $data["partsgroup_id"] = $this->chkPartsgroup($data["partsgroup"]);
+ } else {
+ $data["partsgroup_id"] = '';
+ };
+ $data['unit'] = $this->chkUnit($data['unit']);
+ if ($data['unit'] == '') {
+ $this->error->write('erplib','Artikeleinheit fehlt oder falsch');
+ return false;
+ }
+ $data['shop'] = 't';
+ $sql = "INSERT INTO parts (partnumber,description,sellprice,weight,notes,shop,unit,partsgroup_id,";
+ $sql .= "image,buchungsgruppen_id,inventory_accno_id,income_accno_id,expense_accno_id) ";
+ $sql .= "VALUES (:partnumber,:description,:sellprice,:weight,:notes,:shop,:unit,:partsgroup_id,";
+ $sql .= ":image,:buchungsgruppen_id,1,1,1)";
+ $rc = $this->db->insert($sql,$data);
+ $x = $this->chkPartnumber($data,False);
+ $this->err->out('Neuer Artikel: '.$data['partnumber'],true);
+ $this->error->write('erplib','Artikel neu: '.$data['partnumber']);
+ return $x;
+ }
+}
+?>
--- /dev/null
+<?php
+
+class error {
+
+ var $log = false;
+ var $api = '';
+ var $lf = '<br />';
+
+ function error($api) {
+ $this->log = fopen("/tmp/shop.log","a");
+ $this->api = $api;
+ if ( $api == 'cli' ) { $this->lf = "\n"; }
+ else { $this->lf = "<br />"; };
+ }
+
+ function write($func,$string) {
+ $now = date('Y-m-d H:m:i ');
+ fputs($this->log,$now.$func."\n");
+ fputs($this->log,$string."\n");
+ }
+
+ function close() {
+ fclose($this->log);
+ }
+ function out($txt,$lf=false) {
+ if ( $this->api != 'cli' ) {
+ echo str_repeat(" ", 256);
+ echo $txt;
+ if ( $lf ) echo $this->lf;
+ flush(); ob_flush();
+ } else {
+ echo $txt;
+ if ( $lf ) echo $this->lf;
+ }
+ }
+}
+?>
--- /dev/null
+
+[Shop]
+
+[Shop--Warenexport]
+module=peppershop/ArtikelErpToShop.php
+
+[Shop--Warenexport]
+module=peppershop/ArtikelShopToErp.php
+
+[Shop--Bestellungen]
+module=peppershop/BestellungShop.php
+
+[Shop--Konfiguration]
+module=peppershop/confedit.php
+
--- /dev/null
+<?php
+/*
+Funktionen für den Zugriff auf den Peppershop
+*/
+
+class pepper {
+
+ var $db = false;
+ var $error = false;
+ var $divStd = false;
+ var $divVerm = false;
+ var $minder = false;
+ var $paypal = false;
+ var $treuh = false;
+ var $nachn = false;
+ var $shopcode = 'ISO-8859-1';
+ var $erpcode = 'UTF-8';
+ var $VariantNr = true;
+ var $EU = array('AT','BE','BG','CZ','DK','EE','ES','FI','FR','GB','GR','HR','HU','IE','IT','LU','LV','MT','NL','PL','PT','RO','SE','SI','SK');
+ var $Kategorien = False;
+ var $dezimal = 2;
+
+ var $tableerp = array("partnumber"=>"artikel_nr","description"=>"name","notes"=>"beschreibung",
+ "unit"=>"anzahl_einheit","weight"=>"gewicht","sellprice"=>"preis",
+ "tax"=>"mwst_satz","image"=>"bild_gross","onhand"=>"lagerbestand");
+ var $tableshop = array("datum"=>"transdate","rechnungsbetrag"=>"amount","nettobetrag"=>"netamount","waehrung"=>"curr",
+ "anmerkung"=>"notes","mwst"=>"mwst","bestellungs_id"=>"cusordnumber","bezahlungsart"=>"bezahlung",
+ "kreditkarte"=>"kreditkarte","versandart"=>"shipvia");
+ var $custshop = array("kontakt"=>"contact","ort"=>"city","plz"=>"zipcode","land"=>"country","tel"=>"phone",
+ "fax"=>"fax","email"=>"email","beschreibung"=>"notes","strasse"=>"street","firma"=>"name",
+ "kunden_nr"=>"customer_id","anrede"=>"greeting","k_id"=>"shopid",
+ "bankname"=>"bank","blz"=>"bank_code","kontonummer"=>"account_number",
+ "iban"=>"iban","bic"=>"bic","attributwert1"=>"ustid");
+ var $ordershop = array("datum"=>"transdate","rechnungsbetrag"=>"amount","rechnungs_nr"=>"",
+ "waehrung"=>"currency","beschreibung"=>"notes",
+ "mwst"=>"mwst","versandart"=>"shipvia");
+ var $orderparts = array("artikelname"=>"description","name"=>"description","preis"=>"sellprice","anzahl"=>"qty","artikel_nr"=>"partnumber",
+ "partsgroup"=>"partsgroup","beschreibung"=>"longdescription","gewicht"=>"weight",
+ "mwst_satz"=>"taxrate","bild_gross"=>"image","anzahl_einheit"=>"unit");
+ var $pic = false;
+
+ function pepper($db,$error,$dbname,
+ $divStd,$divVerm,$minder,$nachn,$versandS,$versandV,$paypal,$treuhand,
+ $mwstLX,$mwstS,$variantnr,$pic=false,$nopic=false,$nopicerr=false,$nofiles=false,
+ $erpcode='UTF-8',$shopcode='ISO-8859-1') {
+ $this->db = $db;
+ $this->error = $error;
+ $this->divStd = $divStd ;
+ $this->divVerm = $divVerm ;
+ $this->minder = $minder ;
+ $this->nachn = $nachn ;
+ $this->versandS = $versandS ;
+ $this->versandV = $versandV ;
+ $this->paypal = $paypal ;
+ $this->treuhand = $treuhand;
+ $this->erpcode = $erpcode;
+ $this->mwstLX = $mwstLX;
+ $this->mwstS = $mwstS;
+ $this->VariantNr = ($variantnr==1)?true:false;
+ $this->pic = $pic;
+ $this->nopic = ( $nopic != '' )?$nopic:false;
+ $this->nopicerr = ( $nopicerr != '' )?true:false;
+ $this->nofiles = $nofiles;
+ if ($shopcode == 'AUTO') {
+ $sql = "SELECT TABLE_COLLATION FROM information_schema.TABLES WHERE table_schema = '$dbname' AND table_name = 'kunde'";
+ $rs = $this->db->getOne($sql);
+ if ($rs) {
+ preg_match('/([^_]+)/',$rs['table_collation'],$hits);
+ if (count($hits)>0) {
+ $this->shopcode = $hits[1];
+ } else {
+ $this->shopcode = 'ISO-8859-1';
+ }
+ }
+ } else {
+ $this->shopcode = $shopcode;
+ }
+ }
+ function _toERP($txt) {
+ return mb_convert_encoding($txt,$this->erpcode,$this->shopcode);
+ }
+ function _toShop($txt) {
+ return mb_convert_encoding($txt,$this->shopcode,$this->erpcode);
+ }
+ function translateTable($data,$table) {
+ $newdata = array();
+ foreach ($data as $key=>$val) {
+ if ($this->{$table}[$key])
+ $newdata[$this->{$table}[$key]] = $val;
+ }
+ return $newdata;
+ }
+ function getCategoryID($name,$mwst) {
+ if (empty($name)) {
+ $name = "Default";
+ } else {
+ $name = $this->_toShop($name);
+ }
+ //Kategorien werden durch die ERP mit "!" getrennt
+ preg_match_all("/([^!]+)!?/",$name,$kat);
+ if (count($kat)>0) {
+ $kat = $kat[1];
+ } else {
+ return false;
+ };
+ $parent = 0;
+ $sql = "select * from kategorien where name like '%s' and parent_id = %d";
+ if (count($kat)>0) foreach ($kat as $wg) {
+ $sql_ = sprintf($sql,$wg,$parent);
+ $rs=$this->db->getOne($sql_);
+ if ($rs["kategorie_id"]) { // gefunden
+ $parent=$rs["kategorie_id"];
+ $mwst=$rs["mwst_satz"];
+ } else { // nicht gefunden, anlegen
+ $parent=$this->createCategory($wg,$mwst,$parent);
+ }
+ }
+ return $parent;
+ }
+ function createCategory($name,$mwst,$parent) {
+ $sql = "select max(positions_nr) as cnt from kategorien WHERE parent_id = ".$parent;
+ $rs=$this->db->getOne($sql);
+ $pos = $rs['cnt'] + 1;
+ $sql = "INSERT INTO kategorien (positions_nr,name,mwst_satz,ist_sichtbar,parent_id) ";
+ $sql .= "VALUES (".$pos.",'".$name."',".$mwst.",'Y',".$parent.")";
+ $rc = $this->db->query($sql);
+ if ($rc) {
+ $sql = "SELECT kategorie_id FROM kategorien where name = '".$name."' and parent_id = ".$parent;
+ $rs = $this->db->getOne($sql);
+ return $rs['kategorie_id'];
+ } else {
+ return false;
+ }
+ }
+ function getLang($lang) {
+ $sql = "SELECT * FROM locale WHERE iso_639_1_code like '$lang' and aktiviert = 'Y'";
+ $rs = $this->db->getOne($sql);
+ return $rs['locale_id'];
+ }
+ function saveArtikel($data,$lang) {
+ $langID = $this->getLang(strtolower($lang));
+ $values = $this->translateTable($data,"tableerp"); //$this->tableerp);
+ if ($this->mwstLX and !$this->mwstS) { //ERP-Bruttopreis Shop-Nettopreis
+ $values['preis'] = round($values['preis'] / (1 + $values["mwst_satz"]),2);
+ } else if (!$this->mwstLX and $this->mwstS) { //ERP-Nettopreis Shop-Bruttopreis
+ $values['preis'] = round($values['preis'] * (1 + $values["mwst_satz"]),2);
+ }
+ $values["name"] = $this->_toShop($values["name"]);
+ $values["beschreibung"] = $this->_toShop($values["beschreibung"]);
+ $values["mwst_satz"] = $values["mwst_satz"] * 100;
+ $values["kategorie_id"] = $this->getCategoryID($data["partsgroup"],$values["mwst_satz"]);
+ $values["artikel_id"] = $this->checkArtikelOK($values["artikel_nr"]);
+ if ($values["artikel_id"]>0) {
+ $rc = $this->updateArtikel($values);
+ } else {
+ $rc = $this->insertArtikel($values);
+ };
+ return $rc;
+ }
+ function checkArtikelOK($nr) {
+ $sql = "SELECT artikel_id,artikel_nr FROM artikel WHERE artikel_nr = '".$nr."'";
+ $rs = $this->db->getOne($sql);
+ if ( $rs["artikel_nr"] == $nr ) {
+ return $rs["artikel_id"];
+ } else {
+ return false;
+ }
+ }
+ function insertArtikel($data) {
+ $newID = uniqid(rand());
+ $this->db->Begin();
+ $sql = "INSERT INTO artikel (artikel_nr,name) VALUES ('".$data["artikel_nr"]."','$newID')";
+ $rc = $this->db->query($sql);
+ $sql = "SELECT * FROM artikel WHERE name='$newID'";
+ $rs = $this->db->getOne($sql);
+ if ($rs['name'] == $newID) {
+ $data["artikel_id"] = $rs["artikel_id"];
+ $statement = "INSERT INTO artikel_kategorie (fk_artikel_id,fk_kategorie_id) VALUES (?,?)";
+ $values = array($rs["artikel_id"],$data["kategorie_id"]);
+ $rc = $this->db->insert($statement,$values);
+ if (!$rc) {
+ $this->error->out($data['artikel_nr'].' konnte nicht zur Gruppe '.$data['kategorie_id'].' zugefügt werden.');
+ $this->error->write('pepper',$data['artikel_nr'].' konnte nicht zur Gruppe '.$data['kategorie_id'].' zugefügt werden.');
+ $this->db->Rollback();
+ return false;
+ }
+ $this->db->Commit();
+ $this->error->out($data['artikel_nr']." insert ",true);
+ $rc = $this->updateArtikel($data);
+ } else { return false; }
+ return $rc;
+ }
+ function updateArtikel($values) {
+ $sql = "UPDATE artikel SET name = :name, beschreibung = :beschreibung, preis = :preis, gewicht = :gewicht, ";
+ if ( !$this->nofiles ) {
+ //vorhandene Bilder übertragen
+ if ( $values['bild_gross'] != '' ) {
+ preg_match("/(.+)\.(jpg|png|jpeg|gif)/i",$values['bild_gross'],$tmp);
+ $sql .= "bild_gross = :bild_gross, bild_klein = :bild_klein, bildtyp = :bildtyp, ";
+ if ( count($tmp) == 3 ) {
+ if ( $this->pic && $this->pic->copyImage($values['artikel_id'],$values['bild_gross'],$tmp[2]) ) {
+ $values['bild_gross'] = $values['artikel_id']."_gr.".$tmp[2];
+ $values['bild_klein'] = $values['artikel_id']."_kl.".$tmp[2];
+ $values['bildtyp'] = $tmp[2];
+ } else if ( $this->nopic ){
+ $sql .= "bild_gross = :bild_gross, bild_klein = :bild_klein, bildtyp = :bildtyp, ";
+ $values['bild_gross'] = $this->nopic."_gr.jpg";
+ $values['bild_klein'] = $this->nopic."_kl.jpg";
+ $values['bildtyp'] = 'jpg';
+ }
+ }
+ } else if ( $this->nopic && !$this->nopicerr ){
+ $sql .= "bild_gross = :bild_gross, bild_klein = :bild_klein, bildtyp = :bildtyp, ";
+ $values['bild_gross'] = $this->nopic."_gr.jpg";
+ $values['bild_klein'] = $this->nopic."_kl.jpg";
+ $values['bildtyp'] = 'jpg';
+ }
+ }
+ $sql .= "mwst_satz = :mwst_satz, anzahl_einheit = :anzahl_einheit ";
+ //Kein Lagerbestand übergeben, also nichts ändern
+ if ( $values['lagerbestand'] != '' ) $sql .= ",lagerbestand = :lagerbestand ";
+ $sql .= "WHERE artikel_id = :artikel_id ";
+ $rc = $this->db->update($sql,$values);
+ if ($rc) {
+ return $values["artikel_id"];
+ } else {
+ return false;
+ }
+ }
+ function getBestellung($employee_id) {
+ $sql = "SELECT * FROM mehrwertsteuer WHERE beschreibung = 'Porto und Verpackung'";
+ $rs = $this->db->getOne($sql);
+ $versandsteuer = $rs["mwst_satz"];
+ $sql = "SELECT * FROM bestellung WHERE bestellung_bezahlt='N' ";
+ $sql .= "AND rechnungs_nr != '' AND session_id = '' ";
+ $sql .= 'ORDER BY bestellungs_id';
+ $rs=$this->db->getAll($sql);
+ if (!$rs) return array();
+ $data = false;
+ foreach ($rs as $row) {
+ $tmp = $this->getBestellArtikel($row["bestellungs_id"]);
+ $artikel = $tmp['data'];
+ if ($versandsteuer == -2) $versandsteuer = $tmp['mwst'];
+ if ($row["versandkosten"]>0) {
+ if ($versandsteuer == $this->versandV['TAX']) {
+ $artikel[] = array("partnumber"=>$this->versandV['NR'],"description"=>$this->versandV['TXT'],
+ "qty"=>1,"unit"=>$this->versandV['Unit'],"sellprice"=>$row["versandkosten"]);
+ } else {
+ $artikel[] = array("partnumber"=>$this->versandS['NR'],"description"=>$this->versandS['TXT'],"taxrate"=>$this->versandS['TAX'],
+ "qty"=>1,"unit"=>$this->versandS['Unit'],"sellprice"=>$row["versandkosten"]);
+ }
+ }
+ if ($row["nachnamebetrag"]>0)
+ $artikel[] = array("partnumber"=>$this->nachn['NR'],"description"=>$this->nachn['TXT'],"taxrate"=>$this->nachn['TAX'],
+ "qty"=>1,"unit"=>$this->nachn['Unit'],"sellprice"=>$row["nachnamebetrag"]);
+ if ($row["paypalkosten"]>0)
+ $artikel[] = array("partnumber"=>$this->paypal['NR'],"description"=>$this->paypal['TXT'],"taxrate"=>$this->paypal['TAX'],
+ "qty"=>1,"unit"=>$this->paypal['Unit'],"sellprice"=>round($row["paypalkosten"],2));
+ if ($row["treuhandkosten"]>0)
+ $artikel[] = array("partnumber"=>$this->treuh['NR'],"description"=>$this->treuh['TXT'],"taxrate"=>$this->treuh['TAX'],
+ "qty"=>1,"unit"=>$this->treuh['Unit'],"sellprice"=>$row["treuhandkosten"]);
+ if ($row["mindermengenzuschlag"]>0)
+ $artikel[] = array("partnumber"=>$this->minder['NR'],"description"=>$this->minder['TXT'],"taxrate"=>$this->minder['TAX'],
+ "qty"=>1,"unit"=>$this->minder['Unit'],"sellprice"=>$row["mindermengenzuschlag"]);
+ if ($row["versandland_id"] == "DE") {
+ $taxzone_id = 0;
+ } else if (in_array($this->EU,$row["versandland_id"])) {
+ if (preg_match('/^[^0-9]{2,3}[ 0-9]+$/',$row["customer"]['ustid'])) {
+ $taxzone_id = 1;
+ } else {
+ $taxzone_id = 2;
+ }
+ } else {
+ $taxzone_id = 3;
+ }
+ if ($row["kreditkarten_nummer"]) {
+ $row["kreditkarte"] = $row['kreditkarten_hersteller']."\n";
+ $row["kreditkarte"] = $row['kreditkarten_nummer']." ID:".$row['kreditkarten_id']."\n";
+ $row["kreditkarte"] = $row['kreditkarten_ablaufdatum']."\n";
+ $row["kreditkarte"] = $row['kreditkarten_vorname']." ".$row['kreditkarten_nachname']."\n";
+ }
+ $row["versandart"] = $this->_toERP($row["versandart"]);
+ $row = $this->translateTable($row,"tableshop");
+ $row["taxzone_id"] = $taxzone_id;
+ $row["notes"] = $this->_toERP($row["notes"]);
+ $row["employee_id"] = $employee_id;
+ $row["parts"] = $artikel;
+ $row["mwst"] = round($row["mwst"],2);
+ $row["amount"]= round($row["amount"],2);
+ $row["netamount"] = $row["amount"] - $row["mwst"];
+ $row["customer"] = $this->getBestellungKunde($row["cusordnumber"]);
+ $data[] = $row;
+ }
+ return $data;
+ }
+ function getBestellungKunde($bestellung) {
+ $sql = "SELECT * FROM kunde LEFT JOIN bestellung_kunde ON Kunden_ID=FK_Kunden_ID ";
+ $sql .= "WHERE FK_Bestellungs_ID=$bestellung";
+ $rs=$this->db->getOne($sql);
+ if ($rs["firma"]) {
+ $rs["kontakt"] = $this->_toERP($rs["vorname"]." ".$rs["nachname"]);
+ $rs["firma"] = $this->_toERP($rs["firma"]);
+ } else {
+ $rs["kontakt"] = $this->_toERP($rs["vorname"]." ".$rs["nachname"]);
+ $rs["firma"] = $this->_toERP($rs["nachname"].", ".$rs["vorname"]);
+ }
+ $rs["strasse"] = $this->_toERP($rs["strasse"])." ".$rs['hausnummer'];
+ $rs["ort"] = $this->_toERP($rs["ort"]);
+ $rs["bankname"] = $this->_toERP($rs["bankname"]);
+ if ($rs) {
+ return $this->translateTable($rs,"custshop");
+ } else {
+ $this->error->write("pepper","Die Kunde der Bestellung $bestellung konnte nicht gelesen werden");
+ return false;
+ }
+ }
+ function getBestellArtikel($bestellung) {
+ if (!$this->kategorien) $this->getKategorien();
+ $sql = "SELECT B.*,P.artikel_nr,P.beschreibung,P.mwst_satz,P.anzahl_einheit,P.bild_gross,";
+ $sql .= "AK.fk_kategorie_id as partsgroup ";
+ $sql .= "FROM artikel_bestellung B LEFT JOIN artikel P ";
+ $sql .= "ON B.fk_artikel_id=P.artikel_id LEFT JOIN artikel_kategorie AK on AK.fk_artikel_id=P.artikel_id ";
+ $sql .= "WHERE fk_bestellungs_id=".$bestellung;
+ $rs=$this->db->getAll($sql);
+ if (!$rs) {
+ $this->error->write("pepper","Die Artikel der Bestellung $bestellung konnte nicht gelesen werden");
+ return false;
+ }
+ $a_b_ID = array();
+ foreach ($rs as $row) {
+ if (in_array($row['a_b_id'],$a_b_ID)) continue;
+ $row['artikelname'] = $this->_toERP($row['artikelname']);
+ $row['beschreibung'] = $this->_toERP($row['beschreibung']);
+ if ($row['variation'] != '') {
+ $tmp = $this->splitVariant($row['variation'],$row['anzahl'],$row['fk_artikel_id']);
+ $row['artikelname'] .= $this->_toERP($tmp['text']);
+ $row['preis'] += $tmp['preis'];
+ if ($tmp['nr']) $row['artikel_nr'] .= '-'.$tmp['nr'];
+ }
+ if ($row['optionen'] != '') {
+ $tmp = $this->splitOption($row['optionen'],$row['anzahl']);
+ $row['artikelname'] .= $this->_toERP($tmp['text']);
+ $row['preis'] += $tmp['preis'];
+ }
+ $row['anzahl_einheit'] = $this->_toERP($row['anzahl_einheit']);
+ $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['partsgroup']]);
+ $mwst[$row['mwst_satz']] = $row['preis'] * $row['anzahl'] / (100+$row['mwst_satz']) * 100;
+ $data[] = $this->translateTable($row,"orderparts");
+ $a_b_ID[] = $row['a_b_id'];
+ }
+ arsort($mwst);
+ $tmp = each($mwst); //MwSt-Satz mit grösstem Anteil
+ return array('data'=>$data,'mwst'=>$tmp['key']);
+ }
+ function splitVariant($txt,$qty,$artnr) {
+ $vari=split(chr(254),$txt);
+ $text = '';
+ $preis = 0;
+ if ($vari) {
+ for($cnt=0; $cnt<count($vari); $cnt++) {
+ $nr = false;
+ $tmp = split('<::>',$vari[$cnt]);
+ if ($this->VariantNr) {
+ //$nr = $this->_getVariantNr($tmp[0],$tmp[1],$artnr);
+ $sql = 'SELECT variations_nr FROM artikel_variationen where fk_artikel_id = '.$artnr;
+ $sql .= ' and variationstext = \''.$tmp[1].'\' and variations_grp = (';
+ $sql .= 'SELECT gruppen_nr FROM artikel_variationsgruppen WHERE fk_artikel_id = '.$artnr;
+ $sql .= ' AND gruppentext = \''.$tmp[0].'\')';
+ $rs=$this->db->getOne($sql);
+ $nr = $rs['variations_nr'];
+ }
+ //$text.="\n".$tmp[0].": ".$tmp[1];
+ $text.=", ".$tmp[0].": ".$tmp[1];
+ $cnt++;
+ $preis+=trim($vari[$cnt]) * $qty;
+ }
+ };
+ return array("preis"=>$preis,"text"=>$text,"nr"=>$nr);
+ }
+ function splitOption($txt,$qty) {
+ $vari=split(chr(254),$txt);
+ $text = '';
+ $preis = 0;
+ if ($vari) {
+ for($cnt=0; $cnt<count($vari); $cnt++) {
+ $text.="\n".str_replace('<::>',': ',$vari[$cnt]);
+ $cnt++;
+ $preis+=trim($vari[$cnt]) * $qty;
+ }
+ };
+ return array("preis"=>$preis,"text"=>$text);
+ }
+ function setAbgeholt($bestellung) {
+ $sql = "UPDATE bestellung SET Bestellung_bezahlt='Y' WHERE Bestellungs_ID = $bestellung"; // in ($bestellungen)";
+ $rc = $this->db->query($sql);
+ if (!$rc) {
+ $this->error->write("pepper","Die Bestellung $bestellung konnten nicht als abgeholt markiert werden");
+ return false;
+ } else {
+ return true;
+ }
+ }
+ function setKundenNr($id,$nr) {
+ $sql = "UPDATE kunde SET kunden_nr = '$nr' WHERE k_id = $id";
+ $rc = $this->db->query($sql);
+ if (!$rc) {
+ $this->error->write("pepper","Die Kundennummer $nr konnte nicht dem Kunden $id zugeordnet werden");
+ return false;
+ } else {
+ return true;
+ }
+ }
+ function getAllArtikel() {
+ if (!$this->Kategorien) $this->getKategorien();
+ $sql = "SELECT a.*,k.fk_kategorie_id as katid FROM artikel a LEFT JOIN artikel_kategorie k on a.artikel_id = k.fk_artikel_id";
+ $rs = $this->db->getAll($sql);
+ if ($rs) foreach ($rs as $row) {
+ $row['partsgroup'] = $this->_toERP($this->Kategorien[$row['katid']]);
+ $row['name'] = $this->_toERP($row['name']);
+ $row['beschreibung'] = $this->_toERP($row['beschreibung']);
+ if (!$this->mwstLX) $row['preis'] = round(($row['preis'] / (100 + $row['mwst_satz']) * 100),$this->dezimal);
+ $data[] = $this->translateTable($row,"orderparts");
+ }
+ return $data;
+ }
+ function getKategorien() {
+ $sql = "SELECT kategorie_id,name,parent_id FROM kategorien WHERE parent_id >= 0 order by parent_id";
+ $rs = $this->db->getAll($sql);
+ if ($rs) {
+ foreach($rs as $row) { $this->katrs[$row['kategorie_id']] = $row;};
+ foreach($this->katrs as $row) {
+ if ($row['parent_id'] == '0') {
+ $name = $row['name'];
+ } else {
+ $name = $this->mkKategorien($row['kategorie_id'],'');
+ }
+ $this->Kategorien[$row['kategorie_id']] = $name;
+ }
+ }
+ }
+ function mkKategorien($id,$name) {
+ if ($this->katrs[$id]['parent_id'] == '0') {
+ if ($name) {
+ return $this->katrs[$id]['name'].'!'.$name;
+ } else {
+ return $this->katrs[$id]['name']."#";
+ }
+ } else {
+ if (!$name) {
+ $name = $this->katrs[$id]['name'];
+ } else {
+ $name = $this->katrs[$id]['name'].'!'.$name;
+ }
+ $name = $this->mkKategorien($this->katrs[$id]['parent_id'],$name);
+ }
+ return $name;
+ }
+}
+?>