Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e2edfbac

Von Holger Lindemann vor mehr als 16 Jahren hinzugefügt

  • ID e2edfbacbd62049b7220069f6ce36e76a29da4ec
  • Vorgänger 9dda820f
  • Nachfolger f5e340df

Neue Anmeldung berücksichtigt

Unterschiede anzeigen:

lxo-import/shiptoB.php
11 11
Web: http://www.linet-services.de
12 12

  
13 13
*/
14
if ($_GET["login"]) {
15
	$login=$_GET["login"];
16
} else {
17
	$login=$_POST["login"];
18
};
19

  
20
require ("import_lib.php");
21
$db=new myDB($login);
22
$crm=checkCRM();
23

  
24
if ($_POST["ok"]) {
25
	$login=$_POST["login"];
26
	$test=$_POST["test"];
27

  
28
	
29
	$shipto_fld = array_keys($shiptos);
30
	$shipto=$shiptos;
31
	
32
	$nun=time();
33

  
34 14
	function ende($nr) {
35 15
		echo "Abbruch: $nr\n";
36
		echo "Aufruf: shiptoB.php [login customer|vendor] [test] | [felder]\n";
37 16
		exit($nr);
38 17
	}
18

  
39 19
	if ($_POST["ok"]=="Hilfe") {
40 20
		echo "Importfelder:<br>";
41 21
		echo "Feldname => Bedeutung<br>";
......
45 25
		exit(0);
46 26
	};
47 27

  
28
if (!$_SESSION["db"]) {
29
	$conffile="../config/authentication.pl";
30
	if (!is_file($conffile)) {
31
		ende(4);
32
	}
33
}
34
require ("import_lib.php");
35

  
36
if (!anmelden()) ende(5);
37

  
38
/* get DB instance */
39
$db=$_SESSION["db"]; //new myDB($login);
40

  
41

  
42
$crm=checkCRM();
43

  
44
if ($_POST["ok"] == "Import") {
45
	$test=$_POST["test"];
46
	
47
	$shipto_fld = array_keys($shiptos);
48
	$shipto=$shiptos;
49
	
50
	$nun=time();
51

  
52

  
48 53
	clearstatcache ();
49 54

  
50 55
	$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
51 56

  
52
if (!empty($_FILES["Datei"]["name"])) { 
53
	$file=$_POST["ziel"];
54
	if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file."_shipto.csv")) {
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 {
55 66
		$file=false;
56
		echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
57 67
	} 
58
} else if (is_file($_POST["ziel"]."_shipto.csv")) {
59
	$file=$_POST["ziel"];
60
} else {
61
	$file=false;
62
} 
63

  
64
if (!$file) ende (2);
68
	if (!$file) ende (2);
65 69

  
66
if (!file_exists($file."_shipto.csv")) ende(5);
70
	if (!file_exists($file."_shipto.csv")) ende(5);
67 71

  
68
if (!file_exists("../users/$login.conf")) ende(3);
72
	$employee=chkUsr($_SESSION["employee"]);
73
	if (!$employee) ende(4);
69 74

  
75
	if (!$db->chkcol($file)) ende(6);
70 76

  
71
$employee=chkUsr($login);
72
if (!$employee) ende(4);
73

  
74
if (!$db->chkcol($file)) ende(6);
75

  
76
$f=fopen($file."_shipto.csv","r");
77
$zeile=fgets($f,1000);
78
$infld=split($trenner,strtolower($zeile));
79
$first=true;
77
	$f=fopen($file."_shipto.csv","r");
78
	$zeile=fgetcsv($f,1000,$trenner);
79
	$first=true;
80 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);
81 88

  
82
foreach ($infld as $fld) {
83
	$fld = trim(strtr($fld,array("\""=>"","'"=>"")));
84
	$in_fld[]=$fld;
85
}
86
$j=0;
87
$zeile=fgetcsv($f,1000,$trenner);
88 89
while (!feof($f)){
89 90
	$i=-1;
90 91
	$firma="";
......
95 96
	$vals=" values (";
96 97
	foreach($zeile as $data) {
97 98
		$i++;
98
		if ($in_fld[$i]=="firma") { 
99
			$firma=addslashes(trim($data)); 
100
			continue;
101
		};
102 99
		if (!in_array($in_fld[$i],$shipto_fld)) {
103 100
			continue;
104 101
		}
105 102
		$data=addslashes(trim($data));
106 103
		if ($in_fld[$i]=="trans_id" && $data) {
107 104
			$data=chkKdId($data);
108
			if ($data) $firma="";
109 105
			if (!$id) $id = $data;
110 106
			continue;
111
		} 
107
		} else  if ($in_fld[$i]=="trans_id") {
108
			continue;
109
		}
112 110
		if ($in_fld[$i]==$file."number" && $data) {
113 111
			$tmp=getFirma($data,$file);
114
			if ($tmp) $firma="";
115 112
			if ($id<>$tmp) $id=$tmp;
116 113
			continue;
117
		} 
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
		}
118 125
		$keys.=$in_fld[$i].",";
119 126
		
120 127
		if ($data==false or empty($data) or !$data) {
121 128
                        $vals.="null,";
122 129
                } else {
123 130
                	if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
124
				$data="0".$data;
131
				$data=$prenumber.$data;
125 132
			} else if ($in_fld[$i]=="cp_country" && $data) {
126 133
				$data=mkland($data);
127 134
			}
......
135 142
// 		$zeile=fgetcsv($f,1000,$trenner);
136 143
// 		continue;
137 144
// 	}
138
	if ($firma) {
139
		$data=suchFirma($file,$firma);
140
		if ($data) {
141
			$vals.=$data["trans_id"].",";
142
			$keys.="trans_id,";
143
		}
144
	} else if ($id) {
145
			$vals.=$id.",";
146
			$keys.="trans_id,";
147
	}
148
	if ($keys<>"(") {
145
	if ($keys<>"(" && $id) {
146
		$vals.=$id.",'CT'";
147
		$keys.="trans_id,module";
149 148
		if ($test) {
150 149
			if ($first) {
151 150
				echo "<table border='1'>\n";
152 151
				echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n";
153 152
				$first=false;
154 153
			};
155
			$vals=str_replace("',","'</td><td>",substr($vals,9,-1));
154
			$vals=str_replace("',","'</td><td>",$vals);
156 155
			echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n";
157 156
			flush();
158 157
		} else {
159
			$sql.=substr($keys,0,-1).")";
160
			$sql.=substr($vals,0,-1).")";
158
			$sql.=$keys.")";
159
			$sql.=$vals.")";
161 160
			$rc=$db->query($sql);
162 161
			if (!$rc) echo "Fehler: ".$sql."\n";
163 162
		}
164 163
		$j++;
164
	} else {
165
		echo $keys."<br>";
166
		echo $vals."<br>";
165 167
	};
166 168
	$zeile=fgetcsv($f,1000,$trenner);
167 169
}
......
171 173
<p class="listtop">Lieferanschriftimport f&uuml;r die ERP</p>
172 174
<form name="import" method="post" enctype="multipart/form-data" action="shiptoB.php">
173 175
<input type="hidden" name="MAX_FILE_SIZE" value="300000">
174
<input type="hidden" name="login" value="<?= $login ?>">
175 176
<table>
176 177
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
177 178
<tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
178 179
<tr><td>Trennzeichen</td><td><input type="text" size="2" maxlength="1" name="trenner" value=";"></td></tr>
180
<tr><td>Telefonvorwahl</td><td><input type="text" size="4" maxlength="10" name="prenumber" value=""></td></tr>
179 181
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
180 182
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
181 183
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>

Auch abrufbar als: Unified diff