2 <LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
6 Kontaktimport mit Browser nach Lx-Office ERP
9 Author: Holger Lindemann
10 Email: hli@lx-system.de
11 Web: http://lx-system.de
15 $login=$_GET["login"];
17 $login=$_POST["login"];
20 require ("import_lib.php");
25 $login=$_POST["login"];
29 $kunde_fld = array_keys($contactscrm);
30 $contact=$contactscrm;
32 $kunde_fld = array_keys($contacts);
38 echo "Abbruch: $nr\n";
39 echo "Aufruf: addressS.php [login customer|vendor] [test] | [felder]\n";
42 if ($_POST["ok"]=="Hilfe") {
43 echo "Importfelder:<br>";
44 echo "Feldname => Bedeutung<br>";
45 foreach($contact as $key=>$val) {
46 echo "$key => $val<br>";
53 $trenner=($_POST["trenner"])?$_POST["trenner"]:",";
55 if (!empty($_FILES["Datei"]["name"])) {
57 if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_contact.csv")) {
59 echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
61 } else if (is_file($_POST["ziel"]."_contact.csv")) {
69 if (!file_exists($file."_contact.csv")) ende(5);
71 if (!file_exists("../users/$login.conf")) ende(3);
74 $employee=chkUsr($login);
75 if (!$employee) ende(4);
77 if (!$db->chkcol($file)) ende(6);
79 $f=fopen($file."_contact.csv","r");
80 $zeile=fgets($f,1200);
81 $infld=split($trenner,strtolower($zeile));
85 foreach ($infld as $fld) {
86 $fld = trim(strtr($fld,array("\""=>"","'"=>"")));
90 $zeile=fgetcsv($f,1200,$trenner);
96 $sql="insert into contacts ";
99 foreach($zeile as $data) {
101 if ($in_fld[$i]=="firma") {
102 $firma=addslashes(trim($data));
105 if (!in_array($in_fld[$i],$kunde_fld)) {
108 $data=addslashes(trim($data));
109 if ($in_fld[$i]=="cp_cv_id" && $data) {
110 $data=chkKdId($data);
111 if ($data) $firma="";
112 if (!$id) $id = $data;
115 if ($in_fld[$i]==$file."number" && $data) {
116 $tmp=getFirma($data,$file);
118 if ($id<>$tmp) $id=$tmp;
121 $keys.=$in_fld[$i].",";
123 if ($data==false or empty($data) or !$data) {
126 if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
128 } else if ($in_fld[$i]=="cp_country" && $data) {
131 if ($in_fld[$i]=="cp_name") $name=true;
132 $vals.="'".$data."',";
133 // bei jedem gefuellten Datenfeld erhoehen
138 $zeile=fgetcsv($f,1200,$trenner);
142 $data=suchFirma($file,$firma);
144 $vals.=$data["cp_cv_id"].",";
151 if ($keys<>"(" && $val_count>2) {
154 echo "<table border='1'>\n";
155 echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n";
158 $vals=str_replace("',","'</td><td>",substr($vals,9,-1));
159 echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n";
162 $sql.=substr($keys,0,-1).")";
163 $sql.=substr($vals,0,-1).")";
164 $rc=$db->query($sql);
165 if (!$rc) echo "Fehler: ".$sql."\n";
169 $zeile=fgetcsv($f,1200,$trenner);
172 echo $j." $file importiert.\n";} else {
174 <p class="listtop">Kontakt-Adressimport für die ERP</p>
175 <form name="import" method="post" enctype="multipart/form-data" action="contactB.php">
176 <input type="hidden" name="MAX_FILE_SIZE" value="300000">
177 <input type="hidden" name="login" value="<?= $login ?>">
179 <tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
180 <tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
181 <tr><td>Trennzeichen</td><td><input type="text" size="2" maxlength="1" name="trenner" value=";"></td></tr>
182 <tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
183 <tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
184 <tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>