X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=lxo-import%2FcontactB.php;h=f0b286805c3b2d4d64f09d3b9727abdaf4c13cde;hb=f742983addf80ee40aecd76b6602faa452ece91e;hp=8c8e53a78deb03d1b73815d45533bd03ef341cd5;hpb=c25cb4622b88c268878dc814d4b8487584315fe7;p=kivitendo-erp.git
diff --git a/lxo-import/contactB.php b/lxo-import/contactB.php
index 8c8e53a78..f0b286805 100644
--- a/lxo-import/contactB.php
+++ b/lxo-import/contactB.php
@@ -1,7 +1,7 @@
-
+";
echo "Feldname => Bedeutung
";
@@ -51,14 +60,19 @@ if ($_POST["ok"]) {
clearstatcache ();
$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
+ if ($trenner=="other") {
+ $trenner=trim($trennzeichen);
+ if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
+ }
+
if (!empty($_FILES["Datei"]["name"])) {
$file=$_POST["ziel"];
- if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_contact.csv")) {
+ if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file."_contact.csv")) {
$file=false;
echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")
";
}
-} else if (is_file($_POST["ziel"]."_contact.csv")) {
+} else if (is_file($dir.$_POST["ziel"]."_contact.csv")) {
$file=$_POST["ziel"];
} else {
$file=false;
@@ -66,28 +80,60 @@ if (!empty($_FILES["Datei"]["name"])) {
if (!$file) ende (2);
-if (!file_exists($file."_contact.csv")) ende(5);
-
-if (!file_exists("../users/$login.conf")) ende(3);
+if (!file_exists($dir.$file."_contact.csv")) ende(5);
+//$prenumber=$_POST["prenumber"];
-$employee=chkUsr($login);
+$employee=chkUsr($_SESSION["employee"]);
if (!$employee) ende(4);
if (!$db->chkcol($file)) ende(6);
-$f=fopen($file."_contact.csv","r");
-$zeile=fgets($f,1200);
-$infld=split($trenner,strtolower($zeile));
-$first=true;
+ //Zeichencodierung des Servers
+ $tmpcode = $db->getServerCode();
+ //Leider sind die Benennungen vom Server anders als von mb_detect_encoding
+ if ($tmpcode == "UTF8") {
+ define("ServerCode","UTF-8");
+ } else if ($tmpcode == "LATIN9") {
+ define("ServerCode","ISO-8859-15");
+ } else if ($tmpcode == "LATIN1") {
+ define("ServerCode","ISO-8859-1");
+ } else {
+ define("ServerCode",$tmpcode);
+ }
+ //Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
+ //DB und LxO müssen ja nicht auf der gleichen Maschiene sein.
+ if($tmpcode<>$db->getClientCode()) {
+ $rc = $db->setClientCode($tmpcode);
+ }
+
+ // Zeichenkodierung File
+ if ($_POST["encoding"] == "auto") {
+ define("Auto",true);
+ define("Translate",true);
+ } else {
+ define("Auto",false);
+ if ($_POST["encoding"] == ServerCode) {
+ define("Translate",false);
+ } else {
+ define("Translate",true);
+ define("FileCode",$_POST["encoding"]);
+ }
+ }
-foreach ($infld as $fld) {
- $fld = trim(strtr($fld,array("\""=>"","'"=>"")));
+$f=fopen($dir.$file."_contact.csv","r");
+$zeile=fgetcsv($f,2000,$trenner);
+
+$first=true;
+
+foreach ($zeile as $fld) {
+ $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
$in_fld[]=$fld;
+ if (substr($fld,0,2) == "x_") $kunde_fld[] = $fld;
}
$j=0;
-$zeile=fgetcsv($f,1200,$trenner);
+$zeile=fgetcsv($f,2000,$trenner);
while (!feof($f)){
$i=-1;
$firma="";
@@ -96,55 +142,85 @@ while (!feof($f)){
$sql="insert into contacts ";
$keys="(";
$vals=" values (";
+ unset($extra);
+ $extra = array();
foreach($zeile as $data) {
$i++;
- if ($in_fld[$i]=="firma") {
- $firma=addslashes(trim($data));
- continue;
- };
if (!in_array($in_fld[$i],$kunde_fld)) {
continue;
}
$data=addslashes(trim($data));
+ if ($in_fld[$i]=="firma" && $data) {
+ if (Translate) translate($data);
+ $data=suchFirma($file,$data);
+ if ($data) {
+ $id=$data["cp_cv_id"];
+ }
+ continue;
+ } else if ($in_fld[$i]=="firma") {
+ continue;
+ } ;
if ($in_fld[$i]=="cp_cv_id" && $data) {
$data=chkKdId($data);
- if ($data) $firma="";
- if (!$id) $id = $data;
+ if ($data) {
+ $id = $data;
+ };
+ continue;
+ } else if($in_fld[$i]=="cp_cv_id") {
continue;
- }
+ }
+ if (substr($in_fld[$i],0,2)=="x_" && $data) {
+ $extra[substr($in_fld[$i],2)] = $data;
+ continue;
+ } else if ((substr($in_fld[$i],0,2)=="x_")) {
+ continue;
+ };
if ($in_fld[$i]==$file."number" && $data) {
- $tmp=getFirma($data,$file);
- if ($tmp) $firma="";
- if ($id<>$tmp) $id=$tmp;
+ if (!$id) {
+ $tmp=getFirma($data,$file);
+ if ($tmp) {
+ $id=$tmp;
+ }
+ }
+ continue;
+ } else if ($in_fld[$i]==$file."number") {
+ continue;
+ }
+ if ($in_fld[$i]=="cp_id" && $data) {
+ $tmp=chkContact($data);
+ if ($tmp) {
+ $keys.="cp_id,";
+ $vals.="$tmp,";
+ }
continue;
- }
+ } else if ($in_fld[$i]=="cp_id") {
+ 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 (Translate) translate($data);
+
+ /*if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
+ $data=$prenumber.$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 (!$name) {
$zeile=fgetcsv($f,1200,$trenner);
continue;
}
- if ($firma) {
- $data=suchFirma($file,$firma);
- if ($data) {
- $vals.=$data["cp_cv_id"].",";
- $keys.="cp_cv_id,";
- }
- } else if ($id) {
+ if ($id) {
$vals.=$id.",";
$keys.="cp_cv_id,";
}
@@ -159,10 +235,20 @@ while (!feof($f)){
echo "".str_replace("null,","null | ",$vals)." |
\n";
flush();
} else {
- $sql.=substr($keys,0,-1).")";
- $sql.=substr($vals,0,-1).")";
+ $newID=uniqid (rand());
+ $now = date('Y-m-d H:i').":1.$j";
+ $sql.= $keys."mtime)";
+ $sql.= $vals."'$now')";
$rc=$db->query($sql);
if (!$rc) echo "Fehler: ".$sql."\n";
+ $rs = $db->getAll("select cp_id,cp_name from contacts where mtime = '$now'");
+ $cp_id = $rs[0]["cp_id"];
+ echo "(".$rs[0]["cp_name"].":$cp_id)".count($extra).";";
+ if (count($extra)>0 and $cp_id) {
+ foreach ($extra as $fld=>$val) {
+ $rc = insertExtra("P",$cp_id,$fld,$val);
+ }
+ }
}
$j++;
};
@@ -173,15 +259,32 @@ echo $j." $file importiert.\n";} else {
?>
Kontakt-Adressimport für die ERP
- }; ?>
+