X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=lxo-import%2FshiptoB.php;h=bc79db1002a4b9a745904d1b9331ee04c7054b46;hb=0c095a8e7f027288a2064155476f5a59038f0e23;hp=946b17296741769c36cef416a3ada72af149e1b0;hpb=c25cb4622b88c268878dc814d4b8487584315fe7;p=kivitendo-erp.git
diff --git a/lxo-import/shiptoB.php b/lxo-import/shiptoB.php
index 946b17296..bc79db100 100644
--- a/lxo-import/shiptoB.php
+++ b/lxo-import/shiptoB.php
@@ -6,176 +6,169 @@
Lieferanschriftimport mit Browser nach Lx-Office ERP
Copyright (C) 2005
-Author: Philip Reetz
-Email: p.reetz@linet-services.de
-Web: http://www.linet-services.de
+Author: Philip Reetz, Holger Lindemann
+Email: p.reetz@linet-services.de, hli@lx-system.de
+Web: http://www.linet-services.de, http://www.lx-system.de
*/
-if ($_GET["login"]) {
- $login=$_GET["login"];
-} else {
- $login=$_POST["login"];
-};
-
-require ("import_lib.php");
-$db=new myDB($login);
-$crm=checkCRM();
-
-if ($_POST["ok"]) {
- $login=$_POST["login"];
- $test=$_POST["test"];
-
-
- $shipto_fld = array_keys($shiptos);
- $shipto=$shiptos;
-
- $nun=time();
-
- function ende($nr) {
- echo "Abbruch: $nr\n";
- echo "Aufruf: shiptoB.php [login customer|vendor] [test] | [felder]\n";
- exit($nr);
- }
- if ($_POST["ok"]=="Hilfe") {
- echo "Importfelder:
";
- echo "Feldname => Bedeutung
";
- foreach($contact as $key=>$val) {
- echo "$key => $val
";
- }
- exit(0);
- };
-
- clearstatcache ();
-
- $trenner=($_POST["trenner"])?$_POST["trenner"]:",";
-
-if (!empty($_FILES["Datei"]["name"])) {
- $file=$_POST["ziel"];
- if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_shipto.csv")) {
- $file=false;
- echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")
";
- }
-} else if (is_file($_POST["ziel"]."_shipto.csv")) {
- $file=$_POST["ziel"];
-} else {
- $file=false;
-}
-
-if (!$file) ende (2);
-
-if (!file_exists($file."_shipto.csv")) ende(5);
-
-if (!file_exists("../users/$login.conf")) ende(3);
-
-
-$employee=chkUsr($login);
-if (!$employee) ende(4);
+ require ("import_lib.php");
+
+ function ende($nr) {
+ echo "Abbruch: $nr\n";
+ exit($nr);
+ }
+
+ if ($_POST["ok"]=="Hilfe") {
+ echo "Importfelder:
";
+ echo "Feldname => Bedeutung
";
+ foreach($shiptos as $key=>$val) {
+ echo "$key => $val
";
+ }
+ $header=implode(";",array_keys($shiptos));
+ echo $header;
+ exit(0);
+ };
+
+if (!$_SESSION["db"]) {
+ $conffile="../config/authentication.pl";
+ if (!is_file($conffile)) {
+ ende("authentication.pl nicht gefunden oder unlesbar");
+ }
+}
-if (!$db->chkcol($file)) ende(6);
+if (!anmelden()) ende("Anmeldung fehlgeschlagen");
-$f=fopen($file."_shipto.csv","r");
-$zeile=fgets($f,1000);
-$infld=split($trenner,strtolower($zeile));
-$first=true;
+/* get DB instance */
+$db=$_SESSION["db"]; //new myDB($login);
+$crm=checkCRM();
-foreach ($infld as $fld) {
- $fld = trim(strtr($fld,array("\""=>"","'"=>"")));
- $in_fld[]=$fld;
-}
-$j=0;
-$zeile=fgetcsv($f,1000,$trenner);
-while (!feof($f)){
- $i=-1;
- $firma="";
- $name=false;
- $id=false;
- $sql="insert into shipto ";
- $keys="(";
- $vals=" values (";
- foreach($zeile as $data) {
- $i++;
- if ($in_fld[$i]=="firma") {
- $firma=addslashes(trim($data));
- continue;
- };
- if (!in_array($in_fld[$i],$shipto_fld)) {
- continue;
- }
- $data=addslashes(trim($data));
- if ($in_fld[$i]=="trans_id" && $data) {
- $data=chkKdId($data);
- if ($data) $firma="";
- if (!$id) $id = $data;
- continue;
- }
- if ($in_fld[$i]==$file."number" && $data) {
- $tmp=getFirma($data,$file);
- if ($tmp) $firma="";
- if ($id<>$tmp) $id=$tmp;
- continue;
- }
- $keys.=$in_fld[$i].",";
-
- if ($data==false or empty($data) or !$data) {
- $vals.="null,";
- } else {
- if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
- $data="0".$data;
- } else if ($in_fld[$i]=="cp_country" && $data) {
- $data=mkland($data);
- }
- if ($in_fld[$i]=="cp_name") $name=true;
- $vals.="'".$data."',";
- // bei jedem gefuellten Datenfeld erhoehen
- $val_count++;
+if ($_POST["ok"] == "Import") {
+ $test=$_POST["test"];
+
+ $shipto_fld = array_keys($shiptos);
+ $shipto=$shiptos;
+
+ $nun=time();
+
+ clearstatcache ();
+
+ $trenner=($_POST["trenner"])?$_POST["trenner"]:",";
+
+ if (!empty($_FILES["Datei"]["name"])) {
+ $file=$_POST["ziel"];
+ if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_shipto.csv")) {
+ $file=false;
+ echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")
";
+ }
+ } else if (is_file($_POST["ziel"]."_shipto.csv")) {
+ $file=$_POST["ziel"];
+ } else {
+ $file=false;
+ }
+ if (!$file) ende ("Kein Datenfile");
+
+ if (!file_exists($file."_shipto.csv")) ende($file."_shipto.csv nicht im Ordner gefunden oder leer");
+
+ $employee=chkUsr($_SESSION["employee"]);
+ if (!$employee) ende("Benutzer unbekannt");
+
+ if (!$db->chkcol($file)) ende("Importspalte konnte nicht angelegt werden");
+
+ $f=fopen($file."_shipto.csv","r");
+ $zeile=fgetcsv($f,1000,$trenner);
+ $first=true;
+
+ foreach ($zeile as $fld) {
+ $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
+ $in_fld[]=$fld;
+ }
+ $j=0;
+ $n=0;
+ $prenumber=$_POST["prenumber"];
+ $zeile=fgetcsv($f,1000,$trenner);
+
+ while (!feof($f)){
+ $i=-1;
+ $id=false;
+ $sql="insert into shipto ";
+ $keys="";
+ $vals="";
+ foreach($zeile as $data) {
+ $i++;
+ if (!in_array($in_fld[$i],$shipto_fld)) {
+ continue;
+ }
+ $data=addslashes(trim($data));
+ if ($in_fld[$i]=="trans_id" && $data) {
+ $data=chkKdId($data);
+ if (!$id) $id = $data;
+ continue;
+ } else if ($in_fld[$i]=="trans_id") {
+ continue;
+ }
+ if ($in_fld[$i]==$file."number" && $data) {
+ $tmp=getFirma($data,$file);
+ if ($id<>$tmp) $id=$tmp;
+ continue;
+ } else if ($in_fld[$i]==$file."number") {
+ continue;
+ }
+ if ($in_fld[$i]=="firma") {
+ if ($id) continue;
+ $data=suchFirma($file,$data);
+ if ($data) {
+ $id=$data["cp_cv_id"];
}
- }
-// if (!$name) {
-// $zeile=fgetcsv($f,1000,$trenner);
-// continue;
-// }
- if ($firma) {
- $data=suchFirma($file,$firma);
- if ($data) {
- $vals.=$data["trans_id"].",";
- $keys.="trans_id,";
- }
- } else if ($id) {
- $vals.=$id.",";
- $keys.="trans_id,";
- }
- if ($keys<>"(") {
- if ($test) {
- if ($first) {
- echo "
".str_replace(","," | ",substr($keys,1,-1))." | ",substr($vals,9,-1)); - echo " |
---|---|
".str_replace("null,","null | ",$vals)." |
".str_replace(","," | ",$keys)." |
---|---|
".str_replace(","," | ",$vals)." |
Lieferanschriftimport für die ERP