From 0873c774b2fed0f3dc05f6aa41d3eff8f5ece57e Mon Sep 17 00:00:00 2001 From: Holger Lindemann Date: Wed, 15 Feb 2012 12:16:09 +0100 Subject: [PATCH] =?utf8?q?Neue=20Schopschnittstelle=20f=C3=BCr=20den=20PHP?= =?utf8?q?eppershop=202.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- peppershop/ArtikelErpToShop.php | 75 +++++ peppershop/ArtikelShopToErp.php | 73 +++++ peppershop/BestellungShopToErp.php | 84 ++++++ peppershop/LiesMich.txt | 33 +++ peppershop/Picture.php | 89 ++++++ peppershop/conf.php | 90 ++++++ peppershop/confedit.php | 459 +++++++++++++++++++++++++++++ peppershop/dblib.php | 150 ++++++++++ peppershop/erplib.php | 417 ++++++++++++++++++++++++++ peppershop/error.php | 37 +++ peppershop/menu.ini | 15 + peppershop/pepper.php | 459 +++++++++++++++++++++++++++++ 12 files changed, 1981 insertions(+) create mode 100644 peppershop/ArtikelErpToShop.php create mode 100644 peppershop/ArtikelShopToErp.php create mode 100644 peppershop/BestellungShopToErp.php create mode 100644 peppershop/LiesMich.txt create mode 100644 peppershop/Picture.php create mode 100644 peppershop/conf.php create mode 100644 peppershop/confedit.php create mode 100644 peppershop/dblib.php create mode 100644 peppershop/erplib.php create mode 100644 peppershop/error.php create mode 100644 peppershop/menu.ini create mode 100644 peppershop/pepper.php diff --git a/peppershop/ArtikelErpToShop.php b/peppershop/ArtikelErpToShop.php new file mode 100644 index 000000000..c8cf075eb --- /dev/null +++ b/peppershop/ArtikelErpToShop.php @@ -0,0 +1,75 @@ +\n\n\n\n\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 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 "\n\n"; +} +?> diff --git a/peppershop/ArtikelShopToErp.php b/peppershop/ArtikelShopToErp.php new file mode 100644 index 000000000..c8e1dd2dc --- /dev/null +++ b/peppershop/ArtikelShopToErp.php @@ -0,0 +1,73 @@ +\n\n\n\n\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 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 "\n\n"; +} +?> diff --git a/peppershop/BestellungShopToErp.php b/peppershop/BestellungShopToErp.php new file mode 100644 index 000000000..4d596671f --- /dev/null +++ b/peppershop/BestellungShopToErp.php @@ -0,0 +1,84 @@ +\n\n\n\n\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 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 "
"; print_r($shopdb->db); print_r($shopnr); echo "
"; +} 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 "
Auftragsliste"; + echo "\n\n"; +} + +?> diff --git a/peppershop/LiesMich.txt b/peppershop/LiesMich.txt new file mode 100644 index 000000000..152317e87 --- /dev/null +++ b/peppershop/LiesMich.txt @@ -0,0 +1,33 @@ +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. +_gr.jpg und _kl.jpg + +Dann den Namen 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 diff --git a/peppershop/Picture.php b/peppershop/Picture.php new file mode 100644 index 000000000..692a7ea31 --- /dev/null +++ b/peppershop/Picture.php @@ -0,0 +1,89 @@ +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; + } + + +} +?> diff --git a/peppershop/conf.php b/peppershop/conf.php new file mode 100644 index 000000000..77466edbd --- /dev/null +++ b/peppershop/conf.php @@ -0,0 +1,90 @@ + diff --git a/peppershop/confedit.php b/peppershop/confedit.php new file mode 100644 index 000000000..b70fd4d41 --- /dev/null +++ b/peppershop/confedit.php @@ -0,0 +1,459 @@ +$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