"; echo "Fehlende oder falsche Daten."; exit(1); } if ($_POST["ok"]=="Hilfe") { echo "Importfelder:
"; echo "Feldname => Bedeutung
"; foreach($address as $key=>$val) { echo "$key => $val
"; } exit(0); }; clearstatcache (); //print_r($_FILES); $test=$_POST["test"]; if (!empty($_FILES["Datei"]["name"])) { $file=$_POST["ziel"]; if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file.".csv")) { $file=false; echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")
"; } } else if (is_file($_POST["ziel"].".csv")) { $file=$_POST["ziel"]; } else { $file=false; } if (!$file) ende (2); $trenner=($_POST["trenner"])?$_POST["trenner"]:","; //echo "../users/$login.conf"; if (!file_exists("../users/$login.conf")) ende(3); if (!file_exists("$file.csv")) ende(5); $db=new myDB($login); if (!$db->chkcol($file)) ende(6); $employee=chkUsr($login); if (!$employee) ende(4); $kunde_fld = array_keys($address); $f=fopen("$file.csv","r"); $zeile=fgets($f,1200); $infld=split($trenner,strtolower($zeile)); $first=true; $ok=true; foreach ($infld as $fld) { $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>"")))); if ($fld=="branche" && !$crm) { $in_fld[]=""; continue; }; if ($fld=="sw" && !$crm) { $in_fld[]=""; continue; }; $in_fld[]=$fld; } //print_r($in_fld); echo "
"; $j=0; $m=0; $zeile=fgetcsv($f,1200,$trenner); if ($ok) while (!feof($f)){ $i=0; //echo "Arbeite an $m "; $m++; $anrede=""; $Matchcode=""; $sql="insert into $file "; $keys="("; $vals=" values ("; $number=false; foreach($zeile as $data) { if (!in_array(trim($in_fld[$i]),$kunde_fld)) { if ($in_fld[$i]=="anrede") { $anrede=addslashes(trim($data)); } $i++; continue; }; $data=trim($data); $data=mb_convert_encoding($data,"ISO-8859-15","auto"); //$data=htmlentities($data); $data=addslashes($data); if ($in_fld[$i]==$file."number") { // customernumber || vendornumber if (empty($data) or !$data) { $data=getKdId(); $number=true; } else { $data=chkKdId($data); $number=true; } } else if ($in_fld[$i]=="taxincluded"){ $data=strtolower(substr($data,0,1)); if ($data!="f" && $data!="t") $data="f"; } else if ($in_fld[$i]=="ustid"){ $data=strtr(" ","",$data); } /*else if ($in_fld[$i]=="matchcode") { $matchcode=$data; $i++; continue; if ($data==false or empty($data) or !$data) { if (in_array($in_fld[$i],array("name"))) { $data=$matchcode; } } }*/ $keys.=$in_fld[$i].","; if ($data==false or empty($data) or !$data) { $vals.="null,"; } else { if ($in_fld[$i]=="contact"){ if ($anrede) { $vals.="'$anrede $data',"; } else { $vals.="'$data',"; } } else { $vals.="'".$data."',"; } } $i++; } if (!$number) { $keys.=$file."number,"; $vals.="'".getKdId()."',"; } if ($keys<>"(") { if ($test) { if ($first) { echo "\n"; echo "\n"; $first=false; }; $vals=str_replace("',","'\n"; //echo "Import $j
\n"; flush(); } else { $sql.=$keys."taxzone_id,import)"; $sql.=$vals."0,$nun)"; $rc=$db->query($sql); if (!$rc) echo "Fehler: ".$sql."
"; } $j++; } else { $vals=str_replace("',","'\n"; flush(); } $zeile=fgetcsv($f,1200,$trenner); } fclose($f); if ($test) echo "
".str_replace(",","",substr($keys,1,-1))."
",substr($vals,9,-1)); echo "
".str_replace("null,","null",$vals)."
",substr($vals,9,-1)); echo "
".str_replace("null,","null",$vals)."
\n ##### = Neue Kunden-/Lieferantennummer\n
"; echo $j." $file importiert.\n"; } else { ?>

Adressimport für die ERP


Zieltabellecustomer vendor
Trennzeichen
Testja
Daten