Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1d69ac97

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

PHP-basierten CSV-Import-Code entfernt

Unterschiede anzeigen:

lxo-import/addressB.php
1
<html>
2
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
3
<body>
4
<?php
5
/*
6
Kunden- bzw. Lieferantenimport mit Browser nach Lx-Office ERP
7

  
8
Copyright (C) 2005
9
Author: Holger Lindemann
10
Email: hli@lx-system.de
11
Web: http://lx-system.de
12

  
13
*/
14

  
15
require ("import_lib.php");
16

  
17
function ende($txt) {
18
  echo "Abbruch: $txt<br>";
19
  exit(1);
20
}
21

  
22
if (!$_SESSION["db"]) {
23
    $conffile="../config/lx_office.conf";
24
    if (!is_file($conffile)) {
25
        ende("lx_office.conf nicht gefunden oder unlesbar");
26
    }
27
}
28

  
29
if (!anmelden()) ende("Anmeldung fehlgeschlagen");
30

  
31
if ($_POST["ok"]=="Hilfe") {
32
    echo "Importfelder:<br>";
33
    echo "Feldname => Bedeutung<br>";
34
    foreach($address as $key=>$val) {
35
        echo "$key => $val<br>";
36
    }
37
    $header=implode(";",array_keys($address));
38
    echo $header;
39
    exit(0);
40
};
41

  
42
if ($_POST["ok"]) {
43

  
44
$nun=time();
45

  
46

  
47
/* get DB instance */
48
$db=$_SESSION["db"]; //new myDB($login);
49

  
50
$crm=checkCRM();
51

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

  
68
if (!$file) ende ("Kein Datenfile");
69

  
70
$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
71
if ($trenner=="other") {
72
    $trenner=trim($trennzeichen);
73
} 
74
if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
75

  
76
if (!file_exists($dir.$file.".csv")) ende("$file.csv nicht im Ordner oder leer");
77

  
78
if (!$db->chkcol($file)) ende("Importspalte kann nicht angelegt werden");
79

  
80
$employee=chkUsr($_SESSION["employee"]);
81
if (!$employee) ende("Ung&uuml;ltiger User");
82

  
83
$kunde_fld = array_keys($address);
84

  
85
    //Zeichencodierung des Servers
86
    $tmpcode = $db->getServerCode();
87
    //Leider sind die Benennungen vom Server anders als von mb_detect_encoding
88
    if ($tmpcode == "UTF8") {
89
         define("ServerCode","UTF-8");
90
    } else if ($tmpcode == "LATIN9") {
91
         define("ServerCode","ISO-8859-15");
92
    } else if ($tmpcode == "LATIN1") {
93
         define("ServerCode","ISO-8859-1");
94
    } else {
95
         define("ServerCode",$tmpcode);
96
    }
97
    //Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
98
    //DB und LxO müssen ja nicht auf der gleichen Maschiene sein.
99
    if($tmpcode<>$db->getClientCode()) {
100
        $rc = $db->setClientCode($tmpcode);
101
    }
102

  
103
    // Zeichenkodierung File
104
    if ($_POST["encoding"] == "auto") {
105
         define("Auto",true);
106
         define("Translate",true);
107
    } else {
108
         define("Auto",false);
109
         if ($_POST["encoding"] == ServerCode) {
110
            define("Translate",false);
111
         } else {
112
            define("Translate",true);
113
            define("FileCode",$_POST["encoding"]);
114
         }
115
    }
116

  
117
function chkBusiness($data,$id=true) {
118
global $db;
119
    if ($id) {
120
        $rs = $db->getAll("select id from business where id =$data");
121
    } else {
122
        $rs = $db->getAll("select id from business where decription ilike '$data'");
123
    }
124
    if ($rs[0]["id"]) {
125
        return $rs[0]["id"];
126
    } else {
127
        return "null";
128
    }
129
}
130

  
131
function chkSalesman($data,$id=true) {
132
global $db;
133
    if ($id) {
134
        $rs = $db->getAll("select id from employee where id =$data");
135
    } else {
136
        $rs = $db->getAll("select id from employee where login ilike '$data'");
137
    }
138
    if ($rs[0]["id"]) {
139
        return $rs[0]["id"];
140
    } else {
141
        return "null";
142
    }
143
}
144

  
145
$f=fopen($dir.$file.".csv","r");
146
$zeile=fgets($f,1200);
147
$infld=explode($trenner,strtolower($zeile));
148
$first=true;
149
$ok=true;
150
$p=0;
151
foreach ($infld as $fld) {
152
    $fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
153
    if (in_array($fld,$kunde_fld)) {
154
        if ($fld=="branche" && !$crm) {  continue; };
155
        if ($fld=="sw" && !$crm) {  continue; };
156
        $in_fld[$fld]=$p;
157
        //$fldpos[$fld]=$p;
158
        //$in_fld[]=$fld;
159
    }
160
    $p++;
161
}
162
$infld = array_keys($in_fld);
163
$infld[] = "import";
164
$infld = implode(",",$infld);
165
$j=0;
166
$m=0;
167
$zeile=fgetcsv($f,1200,$trenner);
168
if ($ok) while (!feof($f)){
169
    $i=0;
170
    $m++;
171
    $anrede="";
172
    $Matchcode="";
173
    $sql="insert into $file ";
174
    $keys=array();
175
    $vals=array();
176
    $number=false;
177
    //foreach($zeile as $data) {
178
    
179
    foreach($in_fld as $fld => $pos) {
180
        switch ($fld) {
181
            case "name"         :
182
            case "department_1" :
183
            case "department_2" :
184
            case "matchcode"    : 
185
            case "street"       :
186
            case "city"         :
187
            case "notes"        :
188
            case "sw"           :
189
            case "branche"      :
190
            case "country"      :
191
            case "contact"      :
192
            case "homepage"     :
193
            case "email"        :
194
            case "bank"         : $data = addslashes(trim($zeile[$pos]));
195
                                  if (Translate) translate($data);
196
            case "ustid"        : $data = strtr(trim($zeile[$pos])," ","");
197
            case "bank_code"    : $data = trim($zeile[$pos]);
198
            case "account_number":
199
            case "greeting"     :
200
            case "taxnumber"    :
201
            case "zipcode"      : 
202
            case "phone"        :
203
            case "fax"          : $data = trim($zeile[$pos]);
204
                                  $data = "'$data'";
205
                                  if ($data=="''") {
206
                                        $vals[] = "null";
207
                                  } else {
208
                                        $vals[] = $data;
209
                                  }
210
                                  break;
211
            case "business_id"  : $vals[] = chkBusiness(trim($zeile[$pos]));
212
                                  break;
213
            case "salesman_id"  : $vals[] = chkSalesman(trim($zeile[$pos]));
214
                                  break;
215
            case "taxincluded"  : $data = strtolower(substr($zeile[$pos],0,1));
216
                                  if ($data!="f" && $data!="t") { $vals[] = "'f'"; }
217
                                  else { $vals[] = "'".$data."'";}
218
                                  break;
219
            case "taxzone_id"   : $data = trim($zeile[$pos])*1;
220
                                  if ($data>3 && $data<0) $data = 0;
221
                                  $vals[] = $data;
222
                                  break;
223
            case "creditlimit"  : 
224
            case "discount"     :
225
            case "terms"        : $vals[] = trim($zeile[$pos])*1;
226
                                  break;
227
            case "customernumber":
228
            case "vendornumber" : $data = trim($zeile[$pos]);
229
                                  if (empty($data) or !$data) {
230
                                      $vals[] = getKdId();
231
                                      $number = true;
232
                                  } else {
233
                                      $vals[] = chkKdId($data);
234
                                      $number = true;
235
                                  }
236
                                  break;
237
        }
238
    };
239
    if (!in_array("taxzone_id",$in_fld)) {
240
        $in_fld[] = "taxzone_id";
241
        $vals[] = 0;
242
    }
243
        // seit 2.6 ist die DB-Kodierung UTF-8 @holger Ansonsten einmal vorher die DB-Encoding auslesen
244
        // Falls die Daten ISO-kodiert kommen entsprechend wandeln
245
        // done!
246
        // UTF-8 MUSS als erstes stehen, da ansonsten die Prüfung bei ISO-8859-1 aufhört ...
247
        // die blöde mb_detect... tut leider nicht immer, daher die Möglichkeit der Auswahl
248
        // TODO Umlaute am Anfang wurden bei meinem Test nicht übernommen (Österreich). S.a.:
249
        // http://forum.de.selfhtml.org/archiv/2007/1/t143904/
250
    if ($test) {
251
            if ($first) {
252
                echo "<table border='1'>\n<tr><td>";
253
                echo implode('</th><th>',array_keys($in_fld));
254
                echo "</td></tr>\n";
255
                $first=false;
256
            };
257
            echo "<tr><td>";
258
            echo implode('</td><td>',$vals);
259
            echo "</td></tr>\n";
260
            //echo "Import $j<br>\n";
261
            flush();
262
    } else {
263
            $vals[] = $nun;
264
            $sql = "INSERT INTO $file (".$infld.") values (".implode(",",$vals).")";
265
            $rc=$db->query($sql);
266
            if ($j % 10 == 0) { echo "."; flush(); };
267
            if (!$rc) {  echo "<br />Fehler: ".$sql."<br />"; flush(); };
268
    }
269
    $j++;
270
    $zeile=fgetcsv($f,1200,$trenner);
271
}
272
fclose($f);
273
if ($test) echo "</table>\n ##### = Neue Kunden-/Lieferantennummer\n<br>";
274
echo $j." $file importiert.\n";
275
} else {
276
?>
277

  
278
<p class="listtop">Adressimport f&uuml;r die ERP<p>
279
<br>
280
<form name="import" method="post" enctype="multipart/form-data" action="addressB.php">
281
<!--form name="import" method="post"  action="addressB.php"-->
282
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
283
<input type="hidden" name="login" value="<?php echo  $login ?>">
284
<table>
285
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
286
<tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
287
<tr><td>Trennzeichen</td><td>
288
        <input type="radio" name="trenner" value=";" checked>Semikolon
289
        <input type="radio" name="trenner" value=",">Komma
290
        <input type="radio" name="trenner" value="#9" checked>Tabulator
291
        <input type="radio" name="trenner" value=" ">Leerzeichen
292
        <input type="radio" name="trenner" value="other">
293
        <input type="text" size="2" name="trennzeichen" value="">
294
</td></tr>
295
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
296
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
297
<tr><td>Verwendete<br />Zeichecodierung</td><td>
298
        <select name="encoding">
299
        <option value="auto">Automatisch (versuchen)</option>
300
        <option value="UTF-8">UTF-8</option>
301
        <option value="ISO-8859-1">ISO-8859-1</option>
302
        <option value="ISO-8859-15">ISO-8859-15</option>
303
        <option value="Windows-1252">Windows-1252</option>
304
        <option value="ASCII">ASCII</option>
305
        </select>
306
</td></tr>
307
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
308
</table>
309
</form>
310
<?php }; ?>
lxo-import/blz.php
1
<html>
2
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
3
<body>
4
<?php
5
/*
6
BLZimport mit Browser nach Lx-Office ERP
7
Holger Lindemann <hli@lx-system.de>
8
*/
9

  
10

  
11
/* display help */
12
if ($_POST["ok"]=="Hilfe") {
13
	echo "<br>Die erste Zeile enth&auml;lt keine Feldnamen der Daten.<br>";
14
	echo "Die Datenfelder haben eine feste Breite.<br><br>"; 
15
	echo "Die Daten k&ouml;nnen hier bezogen werden:<br>";
16
	echo "<a http='http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php'>";
17
	echo "http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php</a>";
18
	exit(0);
19
} else if ($_POST) {
20
	function ende($nr) {
21
		echo "Abbruch: $nr<br>";
22
		echo "Fehlende oder falsche Daten.";
23
		exit(1);
24
	}
25

  
26
	function l2u($str) {
27
		return iconv("ISO-8859-1", "UTF-8",$str);
28
	}
29

  
30
	require ("import_lib.php");
31

  
32
	if (!$_SESSION["db"]) {
33
		$conffile="../config/lx_office.conf";
34
		if (!is_file($conffile)) {
35
			ende(4);
36
		}
37
		if (!anmelden()) ende(5);
38
	}
39

  
40

  
41
	/* get DB instance */
42
	$db=$_SESSION["db"]; 
43

  
44
	$test=$_POST["test"];
45

  
46
	clearstatcache ();
47

  
48
	/* no data? */
49
	if (empty($_FILES["Datei"]["name"]))
50
		ende (2);
51

  
52
	/* copy file */
53
	if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],"blz.txt")) {
54
		print_r($_FILES);
55
		echo $_FILES["Datei"]["tmp_name"];
56
		echo "Upload von Datei fehlerhaft.";
57
		echo $_FILES["Datei"]["error"], "<br>";
58
		ende (2);
59
	} 
60

  
61
	/* check if file is really there */
62
	if (!file_exists("blz.txt")) 
63
		ende(3);
64

  
65
	$sqlins="INSERT INTO blz_data (blz,fuehrend,bezeichnung,plz,ort,kurzbez,pan,bic,pzbm,nummer,aekz,bl,folgeblz) ";
66
	$sqlins.="VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s')";
67
	$teststr="<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>";
68
	$teststr.="<td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%s</td></tr>\n";
69
	$sqldel="delete from blz_data";
70
	$ok="true";
71
	$cnt=0;
72
	$f=fopen("blz.txt","r");
73
	if ($test) echo "Testdurchlauf <br><table>\n";
74
	$i=0;
75
	$start=time();
76
	$rs = $db->getAll("SELECT current_setting('server_encoding')");
77
	$srvencoding = $rs[0]['current_setting'];
78
	$rs = $db->getAll("SELECT current_setting('client_encoding')");
79
	$cliencoding = $rs[0]['current_setting'];
80
	echo "SRV: $srvencoding - - CLI: $cliencoding<br>";
81
	if ($f) {
82
		//Cliententcoding auf Latin:
83
		if (!$test) { $rc=$db->query("BEGIN"); if ($cliencoding=="UTF8") $db->query("SET CLIENT_ENCODING TO 'latin-9'"); };
84
		if (!$test) $rc=$db->query($sqldel);
85
		while (($zeile=fgets($f,256)) != FALSE) {
86
			$cnt++;
87
			if (!$test){
88
				//Datenfile ist immer Latin!!
89
				//zwei Möglichkeiten der Zeichenwandlung. Was ist besser??
90
				//Client nicht umgestellt, Zeichen wandeln
91
				/*$sql=sprintf($sqlins,substr($zeile,0,8),substr($zeile,8,1),l2u(substr($zeile,9,58)),substr($zeile,67,5),
92
						l2u(substr($zeile,72,35)),l2u(substr($zeile,107,27)),substr($zeile,134,5),substr($zeile,139,11),
93
						substr($zeile,150,2),substr($zeile,152,6),substr($zeile,158,1),substr($zeile,159,1),
94
						substr($zeile,160,8));*/
95
				//Client umgestellt + und auch bei nicht UTF-Client:
96
				$sql=sprintf($sqlins,substr($zeile,0,8),substr($zeile,8,1),substr($zeile,9,58),substr($zeile,67,5),
97
						substr($zeile,72,35),substr($zeile,107,27),substr($zeile,134,5),substr($zeile,139,11),
98
						substr($zeile,150,2),substr($zeile,152,6),substr($zeile,158,1),substr($zeile,159,1),
99
						substr($zeile,160,8));
100
				$rc=$db->query($sql);
101
				if(DB::isError($rc)) {
102
					echo $sql."<br><pre>";
103
					echo $rc->getMessage()."</pre><br>";
104
					$ok=false;
105
					break;
106
				}
107
				if ($cnt % 10 == 0) { 
108
					if ($cnt % 1000 == 0) { $x=time()-$start; echo sprintf("%dsec %6d<br>",$x,$cnt); }
109
					else if ($cnt % 100 == 0) { echo "!"; }
110
					else { echo '.'; }
111
					flush(); 
112
				}
113
			} else {
114
				echo sprintf($teststr,substr($zeile,0,8),substr($zeile,8,1),l2u(substr($zeile,9,58)),substr($zeile,67,5),
115
                                                l2u(substr($zeile,72,35)),l2u(substr($zeile,107,27)),substr($zeile,134,5),substr($zeile,139,11),
116
                                                substr($zeile,150,2),substr($zeile,152,6),substr($zeile,158,1),substr($zeile,159,1),
117
                                                substr($zeile,160,8));
118
				$rc=true;
119
			}
120
			if (!$rc) { 
121
				$ok=false;
122
				break;
123
			}
124
			$i++;
125
		}
126
		if ($ok) {
127
			if (!$test) $rc=$db->query("COMMIT");
128
			echo "<br>$i Daten erfolgreich importierti<br>";
129
			if ($cliencoding=="UTF8") $db->query("SET CLIENT_ENCODING TO 'UTF8'");
130
			$stop=time();
131
			echo $stop-$start." Sekunden";
132
		} else {
133
			if (!$test) $rc=$db->query("ROLLBACK");
134
			echo "Fehler in Zeile: ".$i."<br>";
135
			echo $sql."<br>";
136
			ende(6);
137
		}
138
	} else {
139
		ende(4);
140
	}
141
	echo "</table><br>Fertig. $i Banken importiert.";
142
} else {
143
?>
144
<p class="listtop">BLZ-Import f&uuml;r die ERP<p>
145
<br>Die erste Zeile enth&auml;lt keine Feldnamen der Daten.<br>
146
Die Datenfelder haben eine feste Breite.<br><br>
147
Die Daten k&ouml;nnen hier bezogen werden:<br>
148
<a http='http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php'>
149
http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php</a><br><br>
150
Das File vorher <b>nicht</b> auf UTF8 wandeln!<br><br>
151
Achtung!! Die bestehenden BLZ-Daten werden zun&auml;chst gel&ouml;scht.
152
<br>
153
<form name="import" method="post" enctype="multipart/form-data" action="blz.php">
154
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">
155
<input type="hidden" name="login" value="<?php echo $login ?>">
156
<table>
157
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
158
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
159
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
160
</table>
161
</form>
162
<?php } ?>
lxo-import/contactB.php
1
<html>
2
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
3
<body>
4
<?php
5
/*
6
Kontaktimport mit Browser nach Lx-Office ERP
7

  
8
Copyright (C) 2005
9
Author: Holger Lindemann
10
Email: hli@lx-system.de
11
Web: http://lx-system.de
12

  
13
*/
14
if (!$_SESSION["db"]) {
15
	$conffile="../config/lx_office.conf";
16
	if (!is_file($conffile)) {
17
		ende(4);
18
	}
19
}
20

  
21
function ende($nr) {
22
  echo "Abbruch: $nr\n";
23
  exit($nr);
24
}
25

  
26

  
27
require ("import_lib.php");
28

  
29
if (!anmelden()) ende(5);
30

  
31
/* get DB instance */
32
$db=$_SESSION["db"]; //new myDB($login);
33

  
34

  
35
$crm=checkCRM();
36

  
37
if ($_POST["ok"]) {
38
    $dir = "../users/";
39

  
40
	$test=$_POST["test"];
41

  
42
	if ($crm) {
43
		$kunde_fld = array_keys($contactscrm);
44
		$contact=$contactscrm;
45
	} else {
46
		$kunde_fld = array_keys($contacts);
47
		$contact=$contacts;
48
	}
49
	$nun=time();
50

  
51
	if ($_POST["ok"]=="Hilfe") {
52
		echo "Importfelder:<br>";
53
		echo "Feldname => Bedeutung<br>";
54
		foreach($contact as $key=>$val) {
55
			echo "$key => $val<br>";
56
		}
57
		exit(0);
58
	};
59

  
60
	clearstatcache ();
61

  
62
	$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
63
    if ($trenner=="other") {
64
        $trenner=trim($trennzeichen);
65
        if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
66
    }
67
 
68

  
69
if (!empty($_FILES["Datei"]["name"])) { 
70
	$file=$_POST["ziel"];
71
	if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file."_contact.csv")) {
72
		$file=false;
73
		echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
74
	} 
75
} else if (is_file($dir.$_POST["ziel"]."_contact.csv")) {
76
	$file=$_POST["ziel"];
77
} else {
78
	$file=false;
79
} 
80

  
81
if (!$file) ende (2);
82

  
83
if (!file_exists($dir.$file."_contact.csv")) ende(5);
84

  
85
//$prenumber=$_POST["prenumber"];
86

  
87
$employee=chkUsr($_SESSION["employee"]);
88
if (!$employee) ende(4);
89

  
90
if (!$db->chkcol($file)) ende(6);
91

  
92
    //Zeichencodierung des Servers
93
    $tmpcode = $db->getServerCode();
94
    //Leider sind die Benennungen vom Server anders als von mb_detect_encoding
95
    if ($tmpcode == "UTF8") {
96
         define("ServerCode","UTF-8");
97
    } else if ($tmpcode == "LATIN9") {
98
         define("ServerCode","ISO-8859-15");
99
    } else if ($tmpcode == "LATIN1") {
100
         define("ServerCode","ISO-8859-1");
101
    } else {
102
         define("ServerCode",$tmpcode);
103
    }
104
    //Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
105
    //DB und LxO müssen ja nicht auf der gleichen Maschiene sein.
106
    if($tmpcode<>$db->getClientCode()) {
107
        $rc = $db->setClientCode($tmpcode);
108
    }
109

  
110
    // Zeichenkodierung File
111
    if ($_POST["encoding"] == "auto") {
112
         define("Auto",true);
113
         define("Translate",true);
114
    } else {
115
         define("Auto",false);
116
         if ($_POST["encoding"] == ServerCode) {
117
            define("Translate",false);
118
         } else {
119
            define("Translate",true);
120
            define("FileCode",$_POST["encoding"]);
121
         }
122
    }
123

  
124

  
125
$f=fopen($dir.$file."_contact.csv","r");
126
$zeile=fgetcsv($f,2000,$trenner);
127

  
128
$first=true;
129

  
130
foreach ($zeile as $fld) {
131
	$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
132
	$in_fld[]=$fld;
133
    if (substr($fld,0,2) == "x_") $kunde_fld[] = $fld;
134
}
135
$j=0;
136
$zeile=fgetcsv($f,2000,$trenner);
137
while (!feof($f)){
138
	$i=-1;
139
	$firma="";
140
	$name=false;
141
	$id=false;
142
	$sql="insert into contacts ";
143
	$keys="(";
144
	$vals=" values (";
145
    unset($extra);
146
    $extra = array();
147
	foreach($zeile as $data) {
148
		$i++;
149
		if (!in_array($in_fld[$i],$kunde_fld)) {
150
			continue;
151
		}
152
		$data=addslashes(trim($data));
153
		if ($in_fld[$i]=="firma" && $data) { 
154
            if (Translate) translate($data);
155
			$data=suchFirma($file,$data);
156
			if ($data) {
157
				$id=$data["cp_cv_id"];
158
			}
159
			continue;
160
		} else if ($in_fld[$i]=="firma") {
161
			continue;
162
		} ;
163
		if ($in_fld[$i]=="cp_cv_id" && $data) {
164
			$data=chkKdId($data);
165
			if ($data) {
166
				$id = $data;
167
			};
168
			continue;
169
		} else  if($in_fld[$i]=="cp_cv_id") {
170
			continue;
171
		}
172
        if (substr($in_fld[$i],0,2)=="x_" && $data) {
173
            $extra[substr($in_fld[$i],2)] = $data;
174
            continue;
175
        } else if ((substr($in_fld[$i],0,2)=="x_")) {
176
            continue;
177
        };
178
		if ($in_fld[$i]==$file."number" && $data) {
179
			if (!$id) {
180
				$tmp=getFirma($data,$file);
181
				if ($tmp) {
182
					$id=$tmp;
183
				}
184
			}
185
			continue;
186
		} else if  ($in_fld[$i]==$file."number") {
187
			continue;
188
		}
189
		if ($in_fld[$i]=="cp_id" && $data) {
190
			$tmp=chkContact($data);
191
			if ($tmp) {
192
				$keys.="cp_id,";
193
				$vals.="$tmp,";
194
			} 
195
			continue;
196
		} else if ($in_fld[$i]=="cp_id") {
197
			continue;
198
		}
199

  
200
		$keys.=$in_fld[$i].",";
201
		
202
		if ($data==false or empty($data) or !$data) {
203
                        $vals.="null,";
204
                } else {
205

  
206
                    if (Translate) translate($data);
207

  
208
                	/*if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
209
				        $data=$prenumber.$data;
210
                    } else if ($in_fld[$i]=="cp_country" && $data) {
211
                        $data=mkland($data);
212
                    } */
213
    		    	if ($in_fld[$i]=="cp_name") $name=true;
214
                    $vals.="'".$data."',";
215
                    // bei jedem gefuellten Datenfeld erhoehen
216
                    $val_count++;
217
                }
218
	}
219
	if (!$name) {
220
		$zeile=fgetcsv($f,1200,$trenner);
221
		continue;
222
	}
223
	if ($id) {
224
			$vals.=$id.",";
225
			$keys.="cp_cv_id,";
226
	}
227
	if ($keys<>"(" && $val_count>2) {
228
		if ($test) {
229
			if ($first) {
230
				echo "<table border='1'>\n";
231
				echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n";
232
				$first=false;
233
			};
234
			$vals=str_replace("',","'</td><td>",substr($vals,9,-1));
235
			echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n";
236
			flush();
237
		} else {
238
            $newID=uniqid (rand());
239
            $now = date('Y-m-d H:i').":1.$j";
240
            $sql.= $keys."mtime)";
241
            $sql.= $vals."'$now')";
242
			$rc=$db->query($sql);
243
			if (!$rc) echo "Fehler: ".$sql."\n";
244
            $rs = $db->getAll("select cp_id,cp_name from contacts where mtime = '$now'");
245
            $cp_id = $rs[0]["cp_id"];
246
            echo "(".$rs[0]["cp_name"].":$cp_id)".count($extra).";";
247
            if (count($extra)>0 and $cp_id) {
248
                foreach ($extra as $fld=>$val) {
249
                    $rc = insertExtra("P",$cp_id,$fld,$val);
250
                }
251
            }
252
		}
253
		$j++;
254
	};
255
	$zeile=fgetcsv($f,1200,$trenner);
256
}
257
fclose($f);
258
echo $j." $file importiert.\n";} else {
259
?>
260
<p class="listtop">Kontakt-Adressimport f&uuml;r die ERP</p>
261
<form name="import" method="post" enctype="multipart/form-data" action="contactB.php">
262
<input type="hidden" name="MAX_FILE_SIZE" value="3000000">
263
<table>
264
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
265
<tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
266
<tr><td>Trennzeichen</td><td>
267
        <input type="radio" name="trenner" value=";" checked>Semikolon
268
        <input type="radio" name="trenner" value=",">Komma
269
        <input type="radio" name="trenner" value="#9" checked>Tabulator
270
        <input type="radio" name="trenner" value=" ">Leerzeichen
271
        <input type="radio" name="trenner" value="other">
272
        <input type="text" size="2" name="trennzeichen" value="">
273
</td></tr>
274
<!--tr><td>Telefonvorwahl</td><td><input type="text" size="4" maxlength="1" name="prenumber" value=""></td></tr-->
275
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
276
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
277
<tr><td>Verwendete<br />Zeichecodierung</td><td>
278
        <select name="encoding">
279
        <option value="auto">Automatisch (versuchen)</option>
280
        <option value="UTF-8">UTF-8</option>
281
        <option value="ISO-8859-1">ISO-8859-1</option>
282
        <option value="ISO-8859-15">ISO-8859-15</option>
283
        <option value="Windows-1252">Windows-1252</option>
284
        <option value="ASCII">ASCII</option>
285
        </select>
286
</td></tr>
287
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
288
</table>
289
</form>
290
<?php }; ?>
lxo-import/customer.bsp
1
name;department_1;department_2;street;zipcode;city;country;contact;phone;fax;homepage;email;notes;discount;taxincluded;terms;customernumber;taxnumber;ustid;account_number;bank_code;bank;branche;sw;creditlimit
2
Import Kunde;;;Am Weg 3;12345;Sonstwo;D;Fr. Werner;01234123;;www.test.xx;info@test.xx;Hallole;;;;;;;2222;11223344;Meine Bank;Dienstleistung;;
lxo-import/customer_contact.bsp
1
customernumber;cp_cv_id;firma;cp_abteilung;cp_position;cp_gender;cp_title;cp_givenname;cp_name;cp_email;cp_phone1;cp_phone2;cp_mobile1;cp_mobile2;cp_homepage;cp_street;cp_country;cp_zipcode;cp_city;cp_privatphone;cp_privatemail;cp_notes;cp_stichwort1;cp_id
2
;;Import Kunde;Verwaltung;Leiter;m;Dr.;Hans Heinrich;Import;;;;;;;;D;12345;Sonstwo;;;;
lxo-import/customer_shipto.bsp
1
firma;shiptoname;shiptodepartment_1;shiptodepartment_2;shiptostreet;shiptozipcode;shiptocity;shiptocountry;shiptocontact;shiptophone;shiptofax;shiptoemail;customernumber
2
Import Kunde;Import Kunde;Lagerhaus;;Bahnhofstr. 4;12345;Sonstwo;D;Hr. Hansen;0293948;lager@firma.false;
lxo-import/db.php
1
<?php
2
require_once "DB.php";
3
class myDB extends DB {
4

  
5
 var $db = false;
6
 var $rc = false;
7
 var $showErr = false; // Browserausgabe
8
 var $debug = false; // 1 = SQL-Ausgabe, 2 = zusätzlich Ergebnis
9
 var $log = true;  // Alle Abfragen mitloggen
10
 var $path = "/tmp/";
11
 var $lfh = false;
12
 
13
    function dbFehler($sql,$err) {
14
        $efh=fopen($this->path."lxcrm".date("w").".err","a");
15
        fputs($efh,date("Y-m-d H:i:s ->"));
16
        fputs($efh,$sql."\n");
17
        fputs($efh,$err."\n");
18
        fputs($efh,print_r($this->rc,true));
19
        fputs($efh,"\n");
20
        fclose($efh);
21
        if ($this->showErr)
22
            echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
23
    }
24

  
25
    function showDebug($sql) {
26
        echo $sql."<br>";
27
        if ($this->debug==2) {
28
            echo "<pre>";
29
            print_r($this->rc);
30
            echo "</pre>";
31
        };
32
    }
33

  
34
    function writeLog($txt) {
35
        if ($this->lfh===false)
36
            $this->lfh=fopen($this->path."lxcrm".date("w").".log","a");
37
        fputs($this->lfh,date("Y-m-d H:i:s ->"));
38
        fputs($this->lfh,$txt."\n");
39
        fputs($this->lfh,print_r($this->rc,true));
40
        fputs($this->lfh,"\n");
41
    }
42

  
43
    function closeLogfile() {
44
        fclose($this->lfh);
45
    }
46
    
47
    function myDB($host,$user,$pwd,$db,$port,$showErr=false) {
48
        $dsn = array(
49
                    'phptype'  => 'pgsql',
50
                    'username' => $user,
51
                    'password' => $pwd,
52
                    'hostspec' => $host,
53
                    'database' => $db,
54
                    'port'     => $port
55
                );
56
        $this->showErr=$showErr;
57
        $this->db=DB::connect($dsn);
58
        if (!$this->db || DB::isError($this->db)) {
59
            if ($this->log) $this->writeLog("Connect $dns");
60
            $this->dbFehler("Connect ".print_r($dsn,true),$this->db->getMessage()); 
61
            die ($this->db->getMessage());
62
        }
63
        if ($this->log) $this->writeLog("Connect: ok ");
64
        return $this->db;
65
    }
66

  
67
    function query($sql) {
68
        $this->rc=@$this->db->query($sql);
69
        if ($this->debug) $this->showDebug($sql);
70
        if ($this->log) $this->writeLog($sql);
71
        if(DB::isError($this->rc)) {
72
            $this->dbFehler($sql,$this->rc->getMessage());
73
            $this->rollback();
74
            return false;
75
        } else {
76
            return $this->rc;
77
        }
78
    }
79

  
80
    function begin() {
81
        $this->query("BEGIN");
82
    }
83
    function commit() {
84
        $this->query("COMMIT");
85
    }
86
    function rollback() {
87
        $this->query("ROLLBACK");
88
    }
89

  
90
    function getAll($sql) {
91
        $this->rc=$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
92
        if ($this->debug) $this->showDebug($sql);
93
        if ($this->log) $this->writeLog($sql);
94
        if(DB::isError($this->rc)) {
95
            $this->dbFehler($sql,$this->rc->getMessage());
96
            return false;
97
        } else {
98
            return $this->rc;
99
        }
100
    }
101

  
102
    function saveData($txt) {
103
        if (get_magic_quotes_gpc()) {     
104
            return $txt;
105
        } else {
106
            return DB::quoteSmart($string); 
107
        }
108
    }
109

  
110
    function execute($statement, $data){
111
        $sth = $this->db->prepare($statement);           //Prepare
112
        /*if (PEAR::isError($sth)) {
113
            $this->dbFehler($statement,$sth->getMessage());
114
            $this->rollback();
115
            return false;
116
        }*/
117
        $rc = $this->db->execute($sth,$data);
118
        if(PEAR::isError($rc)) {
119
            $this->dbFehler(print_r($data,true),$rc->getMessage()."\n".print_r($rc,true));
120
            $this->rollback();
121
            return false;
122
        }
123
        $this->db->commit();
124
        return true;
125
    }
126

  
127
    function chkcol($tbl) {
128
        // gibt es die Spalte import schon?
129
        $rc=$this->db->query("select import from $tbl limit 1");
130
        if(DB::isError($rc)) {
131
           $rc=$this->db->query("alter table $tbl add column import int4");
132
           if(DB::isError($rc)) { return false; }
133
           else { return true; }
134
        } else { return true; };
135
    }
136

  
137
    /**
138
     * Zeichekodirung der DB ermitteln
139
     * 
140
     * @return String
141
     */
142
    function getServerCode() {
143
        $sql="SHOW  server_encoding";
144
        $rs = $this->getAll($sql);
145
        return $rs[0]["server_encoding"];
146
    }
147
    function getClientCode() {
148
        $sql="SHOW  client_encoding";
149
        $rs = $this->getAll($sql);
150
        return $rs[0]["client_encoding"];
151
    }
152
    function setClientCode($encoding) {
153
        $sql="SET  client_encoding = '$encoding'";
154
        $rc = $this->query($sql);
155
        return $rc;
156
    }
157
           
158
}
159
?>
lxo-import/import_lib.php
1
<?php
2
/*
3
Funktionsbibliothek f?r den Datenimport in Lx-Office ERP
4

  
5
Copyright (C) 2005
6
Author: Holger Lindemann
7
Email: hli@lx-system.de
8
Web: http://lx-system.de
9

  
10
*/
11

  
12
require_once "db.php";
13

  
14
$address = array(
15
    "name" => "Firmenname",
16
    "department_1" => "Abteilung",
17
    "department_2" => "Abteilung",
18
    "street" => "Strasse + Nr",
19
    "zipcode" => "Plz",
20
    "city" => "Ort",
21
    "country" => "Land",
22
    "contact" => "Ansprechpartner",
23
    "phone" => "Telefon",
24
    "fax" => "Fax",
25
    "homepage" => "Homepage",
26
    "email" => "eMail",
27
    "notes" => "Bemerkungen",
28
    "discount" => "Rabatt (nn.nn)",
29
    "taxincluded" => "incl. Steuer? (t/f)",
30
    "terms" => "Zahlungsziel (Tage)",
31
    "customernumber" => "Kundennummer",
32
    "vendornumber" => "Lieferantennummer",
33
    "taxnumber" => "Steuernummer",
34
    "ustid" => "Umsatzsteuer-ID",
35
    "account_number" => "Kontonummer",
36
    "bank_code" => "Bankleitzahl",
37
    "bank" => "Bankname",
38
    "branche" => "Branche",
39
    "business_id" => "BranchenID",
40
    "salesman_id" => "Verk?uferID",
41
    //"language" => "Sprache (de,en,fr)",
42
    "sw" => "Stichwort",
43
    "creditlimit" => "Kreditlimit (nnnnnn.nn)"); /*,
44
    "hierarchie" => "Hierarchie",
45
    "potenzial" => "Potenzial",
46
    "ar" => "Debitorenkonto",
47
    "ap" => "Kreditorenkonto",
48
    "matchcode" => "Matchcode",
49
    "customernumber2" => "Kundennummer 2"); 
50
    Kundenspezifisch */
51
        
52
$shiptos = array(
53
    "firma" => "Firmenname",
54
    "shiptoname" => "Liefername",
55
    "shiptodepartment_1" => "Abteilung",
56
    "shiptodepartment_2" => "Abteilung",
57
    "shiptostreet" => "Strasse + Nr",
58
    "shiptozipcode" => "Plz",
59
    "shiptocity" => "Ort",
60
    "shiptocountry" => "Land",
61
    "shiptocontact" => "Ansprechpartner",
62
    "shiptophone" => "Telefon",
63
    "shiptofax" => "Fax",
64
    "shiptoemail" => "eMail",
65
    "customernumber" => "Kundennummer",
66
    "vendornumber" => "Lieferantennummer");
67

  
68
$parts = array( 
69
    "partnumber" => "Artikelnummer",
70
    "ean" => "Barcode",
71
    "description" => "Artikeltext",
72
    "unit" => "Einheit",
73
    "weight" => "Gewicht in Benutzerdefinition",
74
    "notes" => "Beschreibung",
75
    "notes1" => "Beschreibung",
76
    "formel" => "Formel",
77
    "makemodel" => "Hersteller",
78
    "model" => "Modellbezeichnung",
79
    "image" => "Pfad/Dateiname",
80
    "drawing" => "Pfad/Dateiname",
81
    "microfiche" => "Pfad/Dateiname",
82
    "listprice" => "Listenpreis",
83
    "sellprice" => "Verkaufspreis",
84
    "lastcost" => "letzter EK",
85
    "art" => "Ware/Dienstleistung (*/d), mu&szlig; vor den Konten kommen",
86
    "inventory_accno" => "Bestandskonto",
87
    "income_accno" => "Erl&ouml;skonto",
88
    "expense_accno" => "Konto Umsatzkosten",
89
    "obsolete" => "Gesperrt (Y/N)",
90
    "lastcost" => "letzer EK-Preis",
91
    "rop" => "Mindestbestand",
92
    "shop" => "Shopartikel (Y/N)",
93
    "assembly" => "St&uuml;ckliste (Y/N); wird noch nicht unterst&uuml;tzt",
94
    "partsgroup" => "Warengruppenbezeichnung",
95
    "partsgroup1" => "2.Warengruppenbezeichnung",
96
    "partsgroup2" => "3.Warengruppenbezeichnung",
97
    "partsgroup3" => "4.Warengruppenbezeichnung",
98
    "partsgroup4" => "5.Warengruppenbezeichnung",
99
    "shop"  => "Shopexport vorghesehen",
100
    );
101
    
102
$contactscrm = array(
103
    "customernumber" => "Kundennummer",
104
    "vendornumber" => "Lieferantennummer",
105
    "cp_cv_id" => "FirmenID in der db",
106
    "firma" => "Firmenname",
107
    "cp_abteilung" => "Abteilung",
108
    "cp_position" => "Position/Hierarchie",
109
    "cp_gender" => "Geschlecht (m/f)",
110
    "cp_title" => "Titel",
111
    "cp_givenname" => "Vorname",
112
    "cp_name" => "Nachname",
113
    "cp_email" => "eMail",
114
    "cp_phone1" => "Telefon 1",
115
    "cp_phone2" => "Telefon 2",
116
    "cp_mobile1" => "Mobiltelefon 1",
117
    "cp_mobile2" => "Mobiltelefon 2",
118
    "cp_homepage" => "Homepage",
119
    "cp_street" => "Strasse",
120
    "cp_country" => "Land",
121
    "cp_zipcode" => "PLZ",
122
    "cp_city" => "Ort",
123
    "cp_privatphone" => "Privattelefon",
124
    "cp_privatemail" => "private eMail",
125
    "cp_notes" => "Bemerkungen",
126
    "cp_stichwort1" => "Stichwort(e)",
127
    "cp_id" => "Kontakt ID"
128
    );
129

  
130
$contacts = array(
131
    "customernumber" => "Kundennummer",
132
    "vendornumber" => "Lieferantennummer",
133
    "cp_cv_id" => "FirmenID in der db",
134
    "firma" => "Firmenname",
135
    "cp_greeting" => "Anrede",
136
    "cp_title" => "Titel",
137
    "cp_givenname" => "Vorname",
138
    "cp_greeting" => "Anrede",
139
    "cp_name" => "Nachname",
140
    "cp_email" => "eMail",
141
    "cp_phone1" => "Telefon 1",
142
    "cp_phone2" => "Telefon 2",
143
    "cp_mobile1" => "Mobiltelefon 1",
144
    "cp_mobile2" => "Mobiltelefon 2",
145
    "cp_privatphone" => "Privattelefon",
146
    "cp_privatemail" => "private eMail",
147
    "cp_homepage" => "Homepage",
148
    "cp_id" => "Kontakt ID"
149
    );
150

  
151
function checkCRM() {
152
    global $db;
153
    $sql="select * from crm";
154
    $rs=$db->getAll($sql);
155
    if ($rs) {
156
        return true;
157
    } else {
158
        return false;
159
    }
160
}
161

  
162
function chkUsr($usr) {
163
// ist es ein g?ltiger ERP-Benutzer? Er mu? mindestens 1 x angemeldet gewesen sein.
164
    global $db;
165
    $sql="select * from employee where login = '$usr'";
166
    $rs=$db->getAll($sql);
167
    if ($rs[0]["id"]) { return $rs[0]["id"]; } 
168
    else { return false; };
169
}
170

  
171
function getKdId() {
172
// die n?chste freie Kunden-/Lieferantennummer holen
173
    global $db,$file,$test;
174
    if ($test) { return "#####"; }
175
    $sql1="select * from defaults";
176
    $sql2="update defaults set ".$file."number = '%s'";
177
    $db->begin();
178
    $rs=$db->getAll($sql1);
179
    $nr=$rs[0][$file."number"];
180
    preg_match("/^([^0-9]*)([0-9]+)/",$nr,$hits);
181
    if ($hits[2]) { $nr=$hits[2]+1; $nnr=$hits[1].$nr; }
182
    else { $nr=$hits[1]+1; $nnr=$nr; };
183
    $rc=$db->query(sprintf($sql2,$nnr));
184
    if ($rc) { 
185
        $db->commit(); 
186
        return $nnr;
187
    } else { 
188
        $db->rollback(); 
189
        return false;
190
    };
191
}
192

  
193
function chkKdId($data) {
194
// gibt es die Nummer schon?
195
    global $db,$file,$test;
196
    $sql="select * from $file where ".$file."number = '$data'";
197
    $rs=$db->getAll($sql);
198
    if ($rs[0][$file."number"]==$data) {
199
        // ja, eine neue holen
200
        return getKdId();
201
    } else {
202
        return $data;
203
    }
204
}
205

  
206
function chkContact($id) {
207
    global $db;
208
    $sql="select * from contact where cp_id = $id";
209
    $rs=$db->getAll($sql);
210
    if ($rs[0]["cp_id"]==$id) {
211
        return true;
212
    } else {
213
        return false;
214
    }
215
}
216

  
217
function getKdRefId($data) {
218
// gibt es die Nummer schon?
219
    global $db,$file,$test;
220
    if (empty($data) or !$data) {   
221
        return false; 
222
    } 
223
    $sql="select * from $file where ".$file."number = '$data'";
224
    $rs=$db->getAll($sql);
225
    return $rs[0]["id"];
226
}
227
/**
228
 * TODO: short description.
229
 * 
230
 * @param mixed  $tab 
231
 * @param object $own 
232
 * @param mixed  $fld 
233
 * @param mixed  $val 
234
 * 
235
 * @return TODO
236
 */
237
function insertExtra($tab,$own,$fld,$val)  {
238
    global $db;
239
    $sql = "insert into extra_felder (fkey,fval,tab,owner) ";
240
    $sql.= "values ('$fld','$val','$tab','$own')";
241
    $rc = $db->query($sql);
242
    return $rc;
243
}
244
function suchFirma($tab,$data) {
245
// gibt die Firma ?
246
    global $db;
247
    if (empty($data) or !$data) {   
248
        return false; 
249
    }
250
    $data=strtoupper($data);
251
    $sql="select * from $tab where upper(name) like '%$data%'";
252
    $rs=$db->getAll($sql);
253
    if (!$rs) {
254
        $org=$data;
255
        while(strpos($data,"  ")>0) {
256
            $data=str_replace("  "," ",$data);
257
        }
258
         $data=preg_replace("/[^A-Z0-9]/ ",".*",trim($data));
259
        $sql="select * from $tab where upper(name) ~ '$data'"; 
260
        $rs=$db->getAll($sql);
261
        if (count($rs)==1) {
262
            return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
263
        }
264
        return false;
265
    } else {
266
        return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
267
    }
268
}
269

  
270

  
271
//Suche Nach Kunden-/Lieferantenummer
272
function getFirma($nummer,$tabelle) {
273
    global $db;
274
    $nummer=strtoupper($nummer);
275
    $sql="select id from $tabelle where upper(".$tabelle."number) = '$nummer'";
276
    $rs=$db->getAll($sql);
277
    if (!$rs) {
278
        $nr=str_replace(" ","%",$nummer);
279
        $sql="select id,".$tabelle."number from $tabelle where upper(".$tabelle."number) like '$nr'";
280
        $rs=$db->getAll($sql);
281
        if ($rs) {
282
            $nr=str_replace(" ","",$nummer);
283
            foreach ($rs as $row) {
284
                $tmp=str_replace(" ","",$row[$tabelle."number"]);
285
                if ($tmp==$nr) return $row["id"];
286
            }
287
        } else { 
288
            return false;
289
        }
290
    } else {
291
        return $rs[0]["id"];
292
    }
293
}
294

  
295
function getAllBG($db) {
296
    $sql  = "select * from buchungsgruppen order by description";
297
    $rs=$db->getAll($sql);
298
    return $rs;
299
}
300

  
301
function getAllUnits($db,$type) {
302
    $sql  = "select * from units where type = '$type' order by sortkey";
303
    $rs=$db->getAll($sql);
304
    return $rs;
305
}
306

  
307
function anmelden($login=false,$pwd=false) {
308
    ini_set("gc_maxlifetime","3600");
309
    if (file_exists("../config/lx_office.conf")) {
310
        $lxo = fopen("../config/lx_office.conf","r");
311
    } else if (file_exists("../config/lx_office.conf.default")) {
312
        $lxo = fopen("../config/lx_office.conf.default","r");
313
    } else {
314
        return false;
315
    }
316
    $dbsec = false;
317
    $tmp = fgets($lxo,512);
318
    while (!feof($lxo)) {
319
       if (preg_match("/^[\s]*#/",$tmp)) {
320
            $tmp = fgets($lxo,512);
321
            continue;
322
       }
323
       if ($dbsec) {
324
            preg_match("/db[ ]*= (.+)/",$tmp,$hits);
325
            if ($hits[1]) $dbname=$hits[1];
326
            preg_match("/password[ ]*= (.+)/",$tmp,$hits);
327
            if ($hits[1]) $dbpasswd=$hits[1];
328
            preg_match("/user[ ]*= (.+)/",$tmp,$hits);
329
            if ($hits[1]) $dbuser=$hits[1];
330
            preg_match("/host[ ]*= (.+)/",$tmp,$hits);
331
            if ($hits[1]) $dbhost=($hits[1])?$hits[1]:"localhost";
332
            preg_match("/port[ ]*= (.+)/",$tmp,$hits);
333
            if ($hits[1]) $dbport=($hits[1])?$hits[1]:"5432";
334
            if (preg_match("/\[[a-z]+/",$tmp)) break;
335
            $tmp = fgets($lxo,512);
336
            continue;
337
       }
338
       preg_match("/[ ]*cookie_name[ ]*=[ ]*(.+)/",$tmp,$hits);
339
       if ($hits[1]) $cookiename=$hits[1];
340
       if (preg_match("!\[authentication/database\]!",$tmp)) $dbsec = true;
341
       $tmp = fgets($lxo,512);
342
    }
343
    if (!$cookiename) $cookiename='lx_office_erp_session_id';
344
    $cookie=$_COOKIE[$cookiename];
345
    if ($login) {
346
        $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,false,$login,$pwd);
347
    } else {
348
        $cookie=$_COOKIE[$cookiename];
349
        if (!$cookie) header("location: ups.html");
350
        $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,false,false);
351
    };
352
    if (!$auth) { return false; };
353
    $_SESSION["sessid"]=$cookie;
354
    $_SESSION["cookie"]=$cookiename;
355
    $_SESSION["employee"]=$auth["login"];
356
    $_SESSION["mansel"]=$auth["dbname"];
357
    $_SESSION["dbname"]=$auth["dbname"];
358
    $_SESSION["dbhost"]=(!$auth["dbhost"])?"localhost":$auth["dbhost"];
359
    $_SESSION["dbport"]=(!$auth["dbport"])?"5432":$auth["dbport"];
360
    $_SESSION["dbuser"]=$auth["dbuser"];
361
    $_SESSION["dbpasswd"]=$auth["dbpasswd"];
362
    $_SESSION["db"]=new myDB($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpasswd"],$_SESSION["dbname"],$_SESSION["dbport"],$showErr);
363
    $_SESSION["authcookie"]=$authcookie;
364
    $sql="select * from employee where login='".$auth["login"]."'";
365
    $rs=$_SESSION["db"]->getAll($sql);
366
    if(!$rs) {
367
            return false;
368
    } else {
369
        if ($rs) {
370
            $tmp=$rs[0];
371
            $_SESSION["termbegin"]=(($tmp["termbegin"]>=0)?$tmp["termbegin"]:8);
372
            $_SESSION["termend"]=($tmp["termend"])?$tmp["termend"]:19;
373
            $_SESSION["Pre"]=$tmp["pre"];
374
            $_SESSION["interv"]=($tmp["interv"]>0)?$tmp["interv"]:60;
375
            $_SESSION["loginCRM"]=$tmp["id"];
376
            $_SESSION["lang"]=$tmp["countrycode"]; //"de";
377
            $_SESSION["kdview"]=$tmp["kdview"];
378
            $sql="select * from defaults";
379
            $rs=$_SESSION["db"]->getAll($sql);
380
            $_SESSION["ERPver"]=$rs[0]["version"];
381
            return true;$_SESSION;
382
        } else {
383
            return false;
384
        }
385
    }
386
}
387

  
388
function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,$login,$pwd) {
389
    $db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true);
390
    if ($cookie) {
391
        $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on ";
392
        $sql.="('--- ' || u.login || E'\\n')=sc.sess_value left join auth.session s on s.id=sc.session_id ";
393
        $sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc";
394
        $rs=$db->getAll($sql,"authuser_1");
395
        if (!$rs) return false;
396
        $stmp="";
397
        if (count($rs)>1) {
398
            foreach($rs as $row) {
399
                    $stmp.=$row["session_id"].",";
400
            }
401
            $sql1="delete from session where id in (".substr($stmp,-1).")";
402
            $sql2="delete from session_content where session_id in (".substr($stmp,-1).")";
403
            $db->query($sql1,"authuser_A");
404
            $db->query($sql2,"authuser_B");
405
            header("location:../login.pl?action=logout");
406
        };
407
        $sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'";
408
        $db->query($sql,"authuser_3");
409
        $sql="select * from auth.user where id=".$rs[0]["id"];
410
    } else {
411
        $sql = "select * from auth.user where login = '$login' and password = '$pwd'";
412
    }
413
    $rs1=$db->getAll($sql,"authuser_1");
414
    if (!$rs1) return false;
415
    $auth=array();
416
    $auth["login"]=$rs1[0]["login"];
417
    $sql="select * from auth.user_config where user_id=".$rs1[0]["id"];
418
    $rs1=$db->getAll($sql,"authuser_2");
419
    $keys=array("dbname","dbpasswd","dbhost","dbport","dbuser");
420
    foreach ($rs1 as $row) {
421
        if (in_array($row["cfg_key"],$keys)) {
422
                $auth[$row["cfg_key"]]=$row["cfg_value"];
423
        }
424
    }
425
    return $auth;
426
}
427

  
428
/**
429
 * Zeichencode ?bersetzen
430
 *
431
 * @param String $txt
432
 */
433
function translate(&$txt) {
434
    if (Auto) {
435
        $encoding = mb_detect_encoding($data,"UTF-8,ISO-8859-1,ISO-8859-15,Windows-1252,ASCII");
436
        $txt = iconv("$encoding",ServerCode."//TRANSLIT",$txt);
437
        //$txt = mb_convert_encoding($txt, ServerCode,"$encoding");
438
    } else {
439
        $txt = iconv(FileCode,ServerCode."//TRANSLIT",$txt);
440
        //$txt = mb_convert_encoding($txt, ServerCode,FileCode);
441
    }
442
}
443

  
444
?>
lxo-import/parts.bsp
1
"partnumber"	"ean"	"description"	"unit"	"weight"	"notes"	"makemodel"	"model"	"image"	"sellprice"	"lastcost"	"partsgroup"	"partsgroup1"	"partsgroup2"	"partsgroup3"	"rop"	"partsgroup4"	"income_accno"	"expense_accno"	"microfiche"	"art"
2
"TI12346"	92384754671	"Importartikel 1"	"Stck"	2	"Die Beschreibung zum Artikel"	"Lx-System"	"LX123"		10	6	"Hardware"	"Test"			1.10		184	37	"Mfiche 1"	"W"
3
"TI12345"	92384754672	"Importartikel 2"		3,1	"Die Beschreibung zum Artikel"	"Lx-System"	"LX124"		13	8,1	"Hardware"	"Test"					184	37	"y"	"W"
4
"TD2345"		"Import Diestleistung"	"Std"						125								184	37		"D"
lxo-import/partsB.php
1
<?php session_start(); ?>
2
<html>
3
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
4
<body>
5
<?php
6
/*
7
Warenimport mit Browser nach Lx-Office ERP
8
Henry Margies <h.margies@maxina.de>
9
Holger Lindemann <hli@lx-system.de>
10
*/
11

  
12
$dir="../users/";
13
$gz_bin = "/bin/gzip -df ";
14
$zip_bin = "/usr/bin/unzip -o -d ".$dir;
15

  
16
function ende($txt) {
17
    echo "Abbruch: $txt<br>";
18
    exit(1);
19
}
20

  
21
if (!$_SESSION["db"]) {
22
    $conffile="../config/lx_office.conf";
23
    if (!is_file($conffile)) {
24
        ende("lx_office.conf nicht gefunden oder kein Leserecht.");
25
    }
26
}
27
require ("import_lib.php");
28

  
29
if ($_GET["login"]) {
30
    $db = anmelden($_GET["login"],$_GET["passwd"]);
31
} else {
32
    $db = anmelden();
33
}
34
//if (!$_SESSION["db"]) ende("Anmeldung fehlgeschlagen.");
35
if (!$db) ende("Anmeldung fehlgeschlagen.");
36

  
37
/* get DB instance */
38
$db=$_SESSION["db"]; //new myDB($login);
39
/* just display page or do real import? */
40
if ($_POST["ok"] || $_GET["cron"]=="1") {
41

  
42
    require ("parts_import.php");
43
    //Zeichencodierung des Servers
44
    $tmpcode = $db->getServerCode();
45
    //Leider sind die Benennungen vom Server anders als von mb_detect_encoding
46
    if ($tmpcode == "UTF8") {
47
         define("ServerCode","UTF-8");
48
    } else if ($tmpcode == "LATIN9") {
49
         define("ServerCode","ISO-8859-15");
50
    } else if ($tmpcode == "LATIN1") {
51
         define("ServerCode","ISO-8859-1");
52
    } else {
53
         define("ServerCode",$tmpcode);
54
    }
55
    //Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
56
    //DB und LxO müssen ja nicht auf der gleichen Maschine sein.
57
    if($tmpcode<>$db->getClientCode()) {
58
        $rc = $db->setClientCode($tmpcode);
59
    }
60

  
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.

Auch abrufbar als: Unified diff