"; 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."_contact.csv")) { $file=false; echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")
"; } } else if (is_file($_POST["ziel"]."_contact.csv")) { $file=$_POST["ziel"]; } else { $file=false; } if (!$file) ende (2); if (!file_exists($file."_contact.csv")) ende(5); $prenumber=$_POST["prenumber"]; $employee=chkUsr($_SESSION["employee"]); if (!$employee) ende(4); if (!$db->chkcol($file)) ende(6); $f=fopen($file."_contact.csv","r"); $zeile=fgetcsv($f,2000,$trenner); $first=true; foreach ($zeile as $fld) { $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>"")))); $in_fld[]=$fld; } $j=0; $zeile=fgetcsv($f,2000,$trenner); while (!feof($f)){ $i=-1; $firma=""; $name=false; $id=false; $sql="insert into contacts "; $keys="("; $vals=" values ("; foreach($zeile as $data) { $i++; if (!in_array($in_fld[$i],$kunde_fld)) { continue; } $data=addslashes(trim($data)); if ($in_fld[$i]=="firma" && $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) { $id = $data; }; continue; } else if($in_fld[$i]=="cp_cv_id") { continue; } if ($in_fld[$i]==$file."number" && $data) { 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=$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 ($id) { $vals.=$id.","; $keys.="cp_cv_id,"; } if ($keys<>"(" && $val_count>2) { if ($test) { if ($first) { echo "\n"; echo "\n"; $first=false; }; $vals=str_replace("',","'\n"; flush(); } else { $sql.=substr($keys,0,-1).")"; $sql.=substr($vals,0,-1).")"; $rc=$db->query($sql); if (!$rc) echo "Fehler: ".$sql."\n"; } $j++; }; $zeile=fgetcsv($f,1200,$trenner); } fclose($f); echo $j." $file importiert.\n";} else { ?>

Kontakt-Adressimport für die ERP

".str_replace(",","",substr($keys,1,-1))."
",substr($vals,9,-1)); echo "
".str_replace("null,","null",$vals)."
Zieltabellecustomer vendor
Trennzeichen
Telefonvorwahl
Testja
Daten