Revision fc47e483
Von Holger Lindemann vor etwa 15 Jahren hinzugefügt
lxo-import/shiptoB.php | ||
---|---|---|
6 | 6 |
Lieferanschriftimport mit Browser nach Lx-Office ERP |
7 | 7 |
|
8 | 8 |
Copyright (C) 2005 |
9 |
Author: Philip Reetz |
|
10 |
Email: p.reetz@linet-services.de |
|
11 |
Web: http://www.linet-services.de |
|
9 |
Author: Philip Reetz, Holger Lindemann
|
|
10 |
Email: p.reetz@linet-services.de, hli@lx-system.de
|
|
11 |
Web: http://www.linet-services.de, http://www.lx-system.de
|
|
12 | 12 |
|
13 | 13 |
*/ |
14 |
function ende($nr) { |
|
15 |
echo "Abbruch: $nr\n"; |
|
16 |
exit($nr); |
|
17 |
} |
|
18 |
|
|
19 |
if ($_POST["ok"]=="Hilfe") { |
|
20 |
echo "Importfelder:<br>"; |
|
21 |
echo "Feldname => Bedeutung<br>"; |
|
22 |
foreach($shiptos as $key=>$val) { |
|
23 |
echo "$key => $val<br>"; |
|
24 |
} |
|
25 |
exit(0); |
|
26 |
}; |
|
14 |
require ("import_lib.php"); |
|
15 |
|
|
16 |
function ende($nr) { |
|
17 |
echo "Abbruch: $nr\n"; |
|
18 |
exit($nr); |
|
19 |
} |
|
20 |
|
|
21 |
if ($_POST["ok"]=="Hilfe") { |
|
22 |
echo "Importfelder:<br>"; |
|
23 |
echo "Feldname => Bedeutung<br>"; |
|
24 |
foreach($shiptos as $key=>$val) { |
|
25 |
echo "$key => $val<br>"; |
|
26 |
} |
|
27 |
$header=implode(";",array_keys($shiptos)); |
|
28 |
echo $header; |
|
29 |
exit(0); |
|
30 |
}; |
|
27 | 31 |
|
28 | 32 |
if (!$_SESSION["db"]) { |
29 |
$conffile="../config/authentication.pl";
|
|
30 |
if (!is_file($conffile)) {
|
|
31 |
ende(4);
|
|
32 |
}
|
|
33 |
$conffile="../config/authentication.pl";
|
|
34 |
if (!is_file($conffile)) {
|
|
35 |
ende("authentication.pl nicht gefunden oder unlesbar");
|
|
36 |
}
|
|
33 | 37 |
} |
34 |
require ("import_lib.php"); |
|
35 | 38 |
|
36 |
if (!anmelden()) ende(5);
|
|
39 |
if (!anmelden()) ende("Anmeldung fehlgeschlagen");
|
|
37 | 40 |
|
38 | 41 |
/* get DB instance */ |
39 | 42 |
$db=$_SESSION["db"]; //new myDB($login); |
40 | 43 |
|
41 |
|
|
42 | 44 |
$crm=checkCRM(); |
43 | 45 |
|
44 | 46 |
if ($_POST["ok"] == "Import") { |
45 |
$test=$_POST["test"]; |
|
46 |
|
|
47 |
$shipto_fld = array_keys($shiptos); |
|
48 |
$shipto=$shiptos; |
|
49 |
|
|
50 |
$nun=time(); |
|
51 |
|
|
52 |
|
|
53 |
clearstatcache (); |
|
54 |
|
|
55 |
$trenner=($_POST["trenner"])?$_POST["trenner"]:","; |
|
56 |
|
|
57 |
if (!empty($_FILES["Datei"]["name"])) { |
|
58 |
$file=$_POST["ziel"]; |
|
59 |
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_shipto.csv")) { |
|
60 |
$file=false; |
|
61 |
echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>"; |
|
62 |
} |
|
63 |
} else if (is_file($_POST["ziel"]."_shipto.csv")) { |
|
64 |
$file=$_POST["ziel"]; |
|
65 |
} else { |
|
66 |
$file=false; |
|
67 |
} |
|
68 |
if (!$file) ende (2); |
|
69 |
|
|
70 |
if (!file_exists($file."_shipto.csv")) ende(5); |
|
71 |
|
|
72 |
$employee=chkUsr($_SESSION["employee"]); |
|
73 |
if (!$employee) ende(4); |
|
74 |
|
|
75 |
if (!$db->chkcol($file)) ende(6); |
|
76 |
|
|
77 |
$f=fopen($file."_shipto.csv","r"); |
|
78 |
$zeile=fgetcsv($f,1000,$trenner); |
|
79 |
$first=true; |
|
80 |
|
|
81 |
foreach ($zeile as $fld) { |
|
82 |
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>"")))); |
|
83 |
$in_fld[]=$fld; |
|
84 |
} |
|
85 |
$j=0; |
|
86 |
$prenumber=$_POST["prenumber"]; |
|
87 |
$zeile=fgetcsv($f,1000,$trenner); |
|
88 |
|
|
89 |
while (!feof($f)){ |
|
90 |
$i=-1; |
|
91 |
$firma=""; |
|
92 |
$name=false; |
|
93 |
$id=false; |
|
94 |
$sql="insert into shipto "; |
|
95 |
$keys="("; |
|
96 |
$vals=" values ("; |
|
97 |
foreach($zeile as $data) { |
|
98 |
$i++; |
|
99 |
if (!in_array($in_fld[$i],$shipto_fld)) { |
|
100 |
continue; |
|
101 |
} |
|
102 |
$data=addslashes(trim($data)); |
|
103 |
if ($in_fld[$i]=="trans_id" && $data) { |
|
104 |
$data=chkKdId($data); |
|
105 |
if (!$id) $id = $data; |
|
106 |
continue; |
|
107 |
} else if ($in_fld[$i]=="trans_id") { |
|
108 |
continue; |
|
109 |
} |
|
110 |
if ($in_fld[$i]==$file."number" && $data) { |
|
111 |
$tmp=getFirma($data,$file); |
|
112 |
if ($id<>$tmp) $id=$tmp; |
|
113 |
continue; |
|
114 |
} else if ($in_fld[$i]==$file."number") { |
|
115 |
continue; |
|
116 |
} |
|
117 |
if ($in_fld[$i]=="firma") { |
|
118 |
if ($id) continue; |
|
119 |
$data=suchFirma($file,$firma); |
|
120 |
if ($data) { |
|
121 |
$id=$data["cp_cv_id"]; |
|
122 |
} |
|
123 |
continue; |
|
124 |
} |
|
125 |
$keys.=$in_fld[$i].","; |
|
126 |
|
|
127 |
if ($data==false or empty($data) or !$data) { |
|
128 |
$vals.="null,"; |
|
129 |
} else { |
|
130 |
if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) { |
|
131 |
$data=$prenumber.$data; |
|
132 |
} else if ($in_fld[$i]=="cp_country" && $data) { |
|
133 |
$data=mkland($data); |
|
134 |
} |
|
135 |
if ($in_fld[$i]=="cp_name") $name=true; |
|
136 |
$vals.="'".$data."',"; |
|
137 |
// bei jedem gefuellten Datenfeld erhoehen |
|
138 |
$val_count++; |
|
47 |
$test=$_POST["test"]; |
|
48 |
|
|
49 |
$shipto_fld = array_keys($shiptos); |
|
50 |
$shipto=$shiptos; |
|
51 |
|
|
52 |
$nun=time(); |
|
53 |
|
|
54 |
clearstatcache (); |
|
55 |
|
|
56 |
$trenner=($_POST["trenner"])?$_POST["trenner"]:","; |
|
57 |
|
|
58 |
if (!empty($_FILES["Datei"]["name"])) { |
|
59 |
$file=$_POST["ziel"]; |
|
60 |
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_shipto.csv")) { |
|
61 |
$file=false; |
|
62 |
echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>"; |
|
63 |
} |
|
64 |
} else if (is_file($_POST["ziel"]."_shipto.csv")) { |
|
65 |
$file=$_POST["ziel"]; |
|
66 |
} else { |
|
67 |
$file=false; |
|
68 |
} |
|
69 |
if (!$file) ende ("Kein Datenfile"); |
|
70 |
|
|
71 |
if (!file_exists($file."_shipto.csv")) ende($file."_shipto.csv nicht im Ordner gefunden oder leer"); |
|
72 |
|
|
73 |
$employee=chkUsr($_SESSION["employee"]); |
|
74 |
if (!$employee) ende("Benutzer unbekannt"); |
|
75 |
|
|
76 |
if (!$db->chkcol($file)) ende("Importspalte konnte nicht angelegt werden"); |
|
77 |
|
|
78 |
$f=fopen($file."_shipto.csv","r"); |
|
79 |
$zeile=fgetcsv($f,1000,$trenner); |
|
80 |
$first=true; |
|
81 |
|
|
82 |
foreach ($zeile as $fld) { |
|
83 |
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>"")))); |
|
84 |
$in_fld[]=$fld; |
|
85 |
} |
|
86 |
$j=0; |
|
87 |
$n=0; |
|
88 |
$prenumber=$_POST["prenumber"]; |
|
89 |
$zeile=fgetcsv($f,1000,$trenner); |
|
90 |
|
|
91 |
while (!feof($f)){ |
|
92 |
$i=-1; |
|
93 |
$id=false; |
|
94 |
$sql="insert into shipto "; |
|
95 |
$keys=""; |
|
96 |
$vals=""; |
|
97 |
foreach($zeile as $data) { |
|
98 |
$i++; |
|
99 |
if (!in_array($in_fld[$i],$shipto_fld)) { |
|
100 |
continue; |
|
101 |
} |
|
102 |
$data=addslashes(trim($data)); |
|
103 |
if ($in_fld[$i]=="trans_id" && $data) { |
|
104 |
$data=chkKdId($data); |
|
105 |
if (!$id) $id = $data; |
|
106 |
continue; |
|
107 |
} else if ($in_fld[$i]=="trans_id") { |
|
108 |
continue; |
|
109 |
} |
|
110 |
if ($in_fld[$i]==$file."number" && $data) { |
|
111 |
$tmp=getFirma($data,$file); |
|
112 |
if ($id<>$tmp) $id=$tmp; |
|
113 |
continue; |
|
114 |
} else if ($in_fld[$i]==$file."number") { |
|
115 |
continue; |
|
116 |
} |
|
117 |
if ($in_fld[$i]=="firma") { |
|
118 |
if ($id) continue; |
|
119 |
$data=suchFirma($file,$data); |
|
120 |
if ($data) { |
|
121 |
$id=$data["cp_cv_id"]; |
|
139 | 122 |
} |
140 |
} |
|
141 |
// if (!$name) { |
|
142 |
// $zeile=fgetcsv($f,1000,$trenner); |
|
143 |
// continue; |
|
144 |
// } |
|
145 |
if ($keys<>"(" && $id) { |
|
146 |
$vals.=$id.",'CT'"; |
|
147 |
$keys.="trans_id,module"; |
|
148 |
if ($test) { |
|
149 |
if ($first) { |
|
150 |
echo "<table border='1'>\n"; |
|
151 |
echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n"; |
|
152 |
$first=false; |
|
153 |
}; |
|
154 |
$vals=str_replace("',","'</td><td>",$vals); |
|
155 |
echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n"; |
|
156 |
flush(); |
|
157 |
} else { |
|
158 |
$sql.=$keys.")"; |
|
159 |
$sql.=$vals.")"; |
|
160 |
$rc=$db->query($sql); |
|
161 |
if (!$rc) echo "Fehler: ".$sql."\n"; |
|
162 |
} |
|
163 |
$j++; |
|
164 |
} else { |
|
165 |
echo $keys."<br>"; |
|
166 |
echo $vals."<br>"; |
|
167 |
}; |
|
168 |
$zeile=fgetcsv($f,1000,$trenner); |
|
169 |
} |
|
170 |
fclose($f); |
|
171 |
echo $j." $file importiert.\n";} else { |
|
123 |
continue; |
|
124 |
} |
|
125 |
$keys.=$in_fld[$i].","; |
|
126 |
|
|
127 |
if ($data==false or empty($data) or !$data) { |
|
128 |
$vals.="null,"; |
|
129 |
} else { |
|
130 |
if (in_array($in_fld[$i],array("shiptofax","shiptophone"))) { |
|
131 |
$data=$prenumber.$data; |
|
132 |
} |
|
133 |
$vals.="'".$data."',"; |
|
134 |
// bei jedem gefuellten Datenfeld erhoehen |
|
135 |
$val_count++; |
|
136 |
} |
|
137 |
} |
|
138 |
if ($keys<>"" && $id) { |
|
139 |
$vals.=$id.",'CT'"; |
|
140 |
$keys.="trans_id,module"; |
|
141 |
if ($test) { |
|
142 |
if ($first) { |
|
143 |
echo "<table border='1'>\n"; |
|
144 |
echo "<tr><th>".str_replace(",","</th><th>",$keys)."</th></tr>\n"; |
|
145 |
$first=false; |
|
146 |
}; |
|
147 |
echo "<tr><td>".str_replace(",","</td><td>",$vals)."</td></tr>\n"; |
|
148 |
flush(); |
|
149 |
} else { |
|
150 |
$sql.="(".$keys.")"; |
|
151 |
$sql.="values (".$vals.")"; |
|
152 |
$rc=$db->query($sql); |
|
153 |
if (!$rc) echo "Fehler: ".$sql."\n"; |
|
154 |
} |
|
155 |
$j++; |
|
156 |
} |
|
157 |
$n++; |
|
158 |
$zeile=fgetcsv($f,1000,$trenner); |
|
159 |
} |
|
160 |
fclose($f); |
|
161 |
echo "</table>".$j." $file shipto von $n importiert.\n"; |
|
162 |
} else { |
|
172 | 163 |
?> |
173 | 164 |
<p class="listtop">Lieferanschriftimport für die ERP</p> |
174 | 165 |
<form name="import" method="post" enctype="multipart/form-data" action="shiptoB.php"> |
Auch abrufbar als: Unified diff
Code überarbeitet
Beispielimportdateien zugefügt