Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fc47e483

Von Holger Lindemann vor etwa 15 Jahren hinzugefügt

  • ID fc47e4830133fb0841ae91a63f909ea7ce6d72fe
  • Vorgänger c510d88b
  • Nachfolger 57bf9c89

Code überarbeitet

Beispielimportdateien zugefügt

Unterschiede anzeigen:

lxo-import/addressB.php
15 15
require ("import_lib.php");
16 16

  
17 17
if (!$_SESSION["db"]) {
18
	$conffile="../config/authentication.pl";
19
	if (!is_file($conffile)) {
20
		ende(4);
21
	}
18
    $conffile="../config/authentication.pl";
19
    if (!is_file($conffile)) {
20
        ende("authentication.pl nicht gefunden oder unlesbar");
21
    }
22 22
}
23 23

  
24
if (!anmelden()) ende(5);
24
if (!anmelden()) ende("Anmeldung fehlgeschlagen");
25 25

  
26 26
if ($_POST["ok"]=="Hilfe") {
27
	echo "Importfelder:<br>";
28
	echo "Feldname => Bedeutung<br>";
29
	foreach($address as $key=>$val) {
30
		echo "$key => $val<br>";
31
	}
32
	exit(0);
27
    echo "Importfelder:<br>";
28
    echo "Feldname => Bedeutung<br>";
29
    foreach($address as $key=>$val) {
30
        echo "$key => $val<br>";
31
    }
32
    $header=implode(";",array_keys($address));
33
    echo $header;
34
    exit(0);
33 35
};
34 36

  
35 37
if ($_POST["ok"]) {
......
42 44

  
43 45
$crm=checkCRM();
44 46

  
45
function ende($nr) {
46
	echo "Abbruch: $nr<br>";
47
	echo "Fehlende oder falsche Daten.";
48
	exit(1);
47
function ende($txt) {
48
    echo "Abbruch: $txt<br>";
49
    exit(1);
49 50
}
50 51

  
51 52
clearstatcache ();
52 53
//print_r($_FILES);
53 54
$test=$_POST["test"];
54 55
if (!empty($_FILES["Datei"]["name"])) {
55
	$file=$_POST["ziel"];
56
	if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file.".csv")) {
57
		$file=false;
58
		echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
59
	}
56
    $file=$_POST["ziel"];
57
    if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file.".csv")) {
58
        $file=false;
59
        echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
60
    }
60 61
} else if (is_file($_POST["ziel"].".csv")) {
61
	$file=$_POST["ziel"];
62
    $file=$_POST["ziel"];
62 63
} else {
63
	$file=false;
64
    $file=false;
64 65
}
65 66

  
66
if (!$file) ende (2);
67
if (!$file) ende ("Kein Datenfile");
67 68

  
68 69
$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
69 70

  
70
if (!file_exists("$file.csv")) ende(5);
71
if (!file_exists("$file.csv")) ende("$file.csv nicht im Ordner oder leer");
71 72

  
72 73

  
73
if (!$db->chkcol($file)) ende(6);
74
if (!$db->chkcol($file)) ende("Importspalte kann nicht angelegt werden");
74 75

  
75 76
$employee=chkUsr($_SESSION["employee"]);
76
if (!$employee) ende(4);
77
if (!$employee) ende("Ung&uuml;ltiger User");
77 78

  
78 79
$kunde_fld = array_keys($address);
79 80

  
......
83 84
$first=true;
84 85
$ok=true;
85 86
foreach ($infld as $fld) {
86
	$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
87
	if ($fld=="branche" && !$crm) { $in_fld[]=""; continue; };
88
	if ($fld=="sw" && !$crm) { $in_fld[]=""; continue; };
89
	$in_fld[]=$fld;
87
    $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
88
    if ($fld=="branche" && !$crm) { $in_fld[]=""; continue; };
89
    if ($fld=="sw" && !$crm) { $in_fld[]=""; continue; };
90
    $in_fld[]=$fld;
90 91
}
91
//print_r($in_fld); echo "<br>";
92

  
92 93
$j=0;
93 94
$m=0;
94 95
$zeile=fgetcsv($f,1200,$trenner);
95 96
if ($ok) while (!feof($f)){
96
	$i=0;
97
        //echo "Arbeite an $m    ";
98
        $m++;
99
	$anrede="";
100
        $Matchcode="";
101
	$sql="insert into $file ";
102
	$keys="(";
103
	$vals=" values (";
104
	$number=false;
105
	foreach($zeile as $data) {
106
		if (!in_array(trim($in_fld[$i]),$kunde_fld)) {
107
			if ($in_fld[$i]=="anrede") {  $anrede=addslashes(trim($data)); }
108
			$i++;
109
			continue;
110
		};
111
		$data=trim($data);
112
		$data=mb_convert_encoding($data,"ISO-8859-15","auto");
113
		//$data=htmlentities($data);
114
		$data=addslashes($data);
115
		if ($in_fld[$i]==$file."number") {  // customernumber || vendornumber
116
			if (empty($data) or !$data) {
117
				$data=getKdId();
118
				$number=true;
119
			} else {
120
				$data=chkKdId($data);
121
				$number=true;
122
			}
123
		} else if ($in_fld[$i]=="taxincluded"){
124
			$data=strtolower(substr($data,0,1));
125
			if ($data!="f" && $data!="t") $data="f";
126
		} else if ($in_fld[$i]=="ustid"){
127
			$data=strtr(" ","",$data);
128
		} /*else if ($in_fld[$i]=="matchcode") {
97
    $i=0;
98
    $m++;
99
    $anrede="";
100
    $Matchcode="";
101
    $sql="insert into $file ";
102
    $keys="(";
103
    $vals=" values (";
104
    $number=false;
105
    foreach($zeile as $data) {
106
        if (!in_array(trim($in_fld[$i]),$kunde_fld)) {
107
            if ($in_fld[$i]=="anrede") {  $anrede=addslashes(trim($data)); }
108
            $i++;
109
            continue;
110
        };
111
        $data=trim($data);
112
        $data=mb_convert_encoding($data,"ISO-8859-15","auto");
113
        //$data=htmlentities($data);
114
        $data=addslashes($data);
115
        if ($in_fld[$i]==$file."number") {  // customernumber || vendornumber
116
            if (empty($data) or !$data) {
117
                $data=getKdId();
118
                $number=true;
119
            } else {
120
                $data=chkKdId($data);
121
                $number=true;
122
            }
123
        } else if ($in_fld[$i]=="taxincluded"){
124
            $data=strtolower(substr($data,0,1));
125
            if ($data!="f" && $data!="t") $data="f";
126
        } else if ($in_fld[$i]=="ustid"){
127
            $data=strtr(" ","",$data);
128
        } /*else if ($in_fld[$i]=="matchcode") {
129 129
                  $matchcode=$data;
130 130
                  $i++;
131 131
                  continue;
132 132
                if ($data==false or empty($data) or !$data) {
133
			if (in_array($in_fld[$i],array("name"))) {
134
				$data=$matchcode;
135
			}
136
		}
137
                }*/
138

  
139
		$keys.=$in_fld[$i].",";
140
		if ($data==false or empty($data) or !$data) {
141
			$vals.="null,";
142
		} else {
143
			if ($in_fld[$i]=="contact"){
144
				if ($anrede) {
145
					$vals.="'$anrede $data',";
146
				} else {
147
					$vals.="'$data',";
148
				}
149
			} else {
150
				$vals.="'".$data."',";
151
			}
152
		}
153
		$i++;
154
	}
155
	if (!$number) {
156
		$keys.=$file."number,";
157
		$vals.="'".getKdId()."',";
158
	}
159
	if ($keys<>"(") {
160
		if ($test) {
161
			if ($first) {
162
				echo "<table border='1'>\n";
163
				echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n";
164
				$first=false;
165
			};
166
			$vals=str_replace("',","'</td><td>",substr($vals,9,-1));
167
			echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n";
168
                        //echo "Import $j<br>\n";
169
			flush();
170
		} else {
171
			$sql.=$keys."taxzone_id,import)";
172
			$sql.=$vals."0,$nun)";
173
			$rc=$db->query($sql);
174
			if (!$rc) echo "Fehler: ".$sql."<br>";
175
		}
176
		$j++;
177
	} else {
133
            if (in_array($in_fld[$i],array("name"))) {
134
                $data=$matchcode;
135
            }
136
        }
137
            }*/
138

  
139
        $keys.=$in_fld[$i].",";
140
        if ($data==false or empty($data) or !$data) {
141
            $vals.="null,";
142
        } else {
143
            if ($in_fld[$i]=="contact"){
144
                if ($anrede) {
145
                    $vals.="'$anrede $data',";
146
                } else {
147
                    $vals.="'$data',";
148
                }
149
            } else {
150
                $vals.="'".$data."',";
151
            }
152
        }
153
        $i++;
154
    }
155
    if (!$number) {
156
        $keys.=$file."number,";
157
        $vals.="'".getKdId()."',";
158
    }
159
    if ($keys<>"(") {
160
        if ($test) {
161
            if ($first) {
162
                echo "<table border='1'>\n";
163
                echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n";
164
                $first=false;
165
            };
166
            $vals=str_replace("',","'</td><td>",substr($vals,9,-1));
167
            echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n";
168
            //echo "Import $j<br>\n";
169
            flush();
170
        } else {
171
            $sql.=$keys."taxzone_id,import)";
172
            $sql.=$vals."0,$nun)";
173
            $rc=$db->query($sql);
174
            if (!$rc) echo "Fehler: ".$sql."<br>";
175
        }
176
        $j++;
177
    } else {
178 178
          $vals=str_replace("',","'</td><td>",substr($vals,9,-1));
179 179
          echo "<tr><td style=\"color:red\">".str_replace("null,","null</td><td style=\"color:red\">",$vals)."</td></tr>\n";
180 180
          flush();
181 181
        }
182
	$zeile=fgetcsv($f,1200,$trenner);
182
    $zeile=fgetcsv($f,1200,$trenner);
183 183
}
184 184
fclose($f);
185 185
if ($test) echo "</table>\n ##### = Neue Kunden-/Lieferantennummer\n<br>";

Auch abrufbar als: Unified diff