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

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

  
35
	function writeLog($txt) {
36
		if ($this->lfh===false)
37
			$this->lfh=fopen($this->logfile,"a");
38
		fputs($this->lfh,date("Y-m-d H:i:s ->"));
39
		fputs($this->lfh,$txt."\n");
40
		fputs($this->lfh,print_r($this->rc,true));
41
		fputs($this->lfh,"\n");
42
	}
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
    }
43 42

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

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

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

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

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

  
111
	function chkcol($tbl) {
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) {
112 128
        // gibt es die Spalte import schon?
113
                $rc=$this->db->query("select import from $tbl limit 1");
114
                if(DB::isError($rc)) {
115
                        $rc=$this->db->query("alter table $tbl add column import int4");
116
                        if(DB::isError($rc)) { return false; }
117
                        else { return true; }
118
		} else { return true; };
119
	}
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
    }
120 136

  
121 137
           
122 138
}
lxo-import/import_lib.php
1 1
<?php
2 2
/*
3
Funktionsbibliothek für den Datenimport in Lx-Office ERP
3
Funktionsbibliothek f?r den Datenimport in Lx-Office ERP
4 4

  
5 5
Copyright (C) 2005
6 6
Author: Holger Lindemann
......
12 12
require_once "db.php";
13 13

  
14 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
	//"language" => "Sprache (de,en,fr)",
40
	"sw" => "Stichwort",
41
	"creditlimit" => "Kreditlimit (nnnnnn.nn)"); /*,
42
	"hierarchie" => "Hierarchie",
43
	"potenzial" => "Potenzial",
44
        "ar" => "Debitorenkonto",
45
        "ap" => "Kreditorenkonto",
46
        "matchcode" => "Matchcode",
47
	"customernumber2" => "Kundennummer 2"); 
48
	Kundenspezifisch */
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
    //"language" => "Sprache (de,en,fr)",
40
    "sw" => "Stichwort",
41
    "creditlimit" => "Kreditlimit (nnnnnn.nn)"); /*,
42
    "hierarchie" => "Hierarchie",
43
    "potenzial" => "Potenzial",
44
    "ar" => "Debitorenkonto",
45
    "ap" => "Kreditorenkonto",
46
    "matchcode" => "Matchcode",
47
    "customernumber2" => "Kundennummer 2"); 
48
    Kundenspezifisch */
49 49
        
50 50
$shiptos = array(
51
	"shiptoname" => "Firmenname",
52
	"shiptodepartment_1" => "Abteilung",
53
	"shiptodepartment_2" => "Abteilung",
54
	"shiptostreet" => "Strasse + Nr",
55
	"shiptozipcode" => "Plz",
56
	"shiptocity" => "Ort",
57
	"shiptocountry" => "Land",
58
	"shiptocontact" => "Ansprechpartner",
59
	"shiptophone" => "Telefon",
60
	"shiptofax" => "Fax",
61
	"shiptoemail" => "eMail",
62
	"customernumber" => "Kundennummer",
63
	"vendornumber" => "Lieferantennummer");
51
    "firma" => "Firmenname",
52
    "shiptoname" => "Liefername",
53
    "shiptodepartment_1" => "Abteilung",
54
    "shiptodepartment_2" => "Abteilung",
55
    "shiptostreet" => "Strasse + Nr",
56
    "shiptozipcode" => "Plz",
57
    "shiptocity" => "Ort",
58
    "shiptocountry" => "Land",
59
    "shiptocontact" => "Ansprechpartner",
60
    "shiptophone" => "Telefon",
61
    "shiptofax" => "Fax",
62
    "shiptoemail" => "eMail",
63
    "customernumber" => "Kundennummer",
64
    "vendornumber" => "Lieferantennummer");
64 65

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

  
130 126
$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
	);
127
    "customernumber" => "Kundennummer",
128
    "vendornumber" => "Lieferantennummer",
129
    "cp_cv_id" => "FirmenID in der db",
130
    "firma" => "Firmenname",
131
    "cp_greeting" => "Anrede",
132
    "cp_title" => "Titel",
133
    "cp_givenname" => "Vorname",
134
    "cp_greeting" => "Anrede",
135
    "cp_name" => "Nachname",
136
    "cp_email" => "eMail",
137
    "cp_phone1" => "Telefon 1",
138
    "cp_phone2" => "Telefon 2",
139
    "cp_mobile1" => "Mobiltelefon 1",
140
    "cp_mobile2" => "Mobiltelefon 2",
141
    "cp_privatphone" => "Privattelefon",
142
    "cp_privatemail" => "private eMail",
143
    "cp_homepage" => "Homepage",
144
    "cp_id" => "Kontakt ID"
145
    );
150 146

  
151 147
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
	}
148
    global $db;
149
    $sql="select * from crm";
150
    $rs=$db->getAll($sql);
151
    if ($rs) {
152
        return true;
153
    } else {
154
        return false;
155
    }
160 156
}
161 157

  
162 158
function chkUsr($usr) {
163 159
// 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; };
160
    global $db;
161
    $sql="select * from employee where login = '$usr'";
162
    $rs=$db->getAll($sql);
163
    if ($rs[0]["id"]) { return $rs[0]["id"]; } 
164
    else { return false; };
169 165
}
170 166

  
171 167
function getKdId() {
172 168
// 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
	};
169
    global $db,$file,$test;
170
    if ($test) { return "#####"; }
171
    $sql1="select * from defaults";
172
    $sql2="update defaults set ".$file."number = '%s'";
173
    $db->begin();
174
    $rs=$db->getAll($sql1);
175
    $nr=$rs[0][$file."number"];
176
    preg_match("/^([^0-9]*)([0-9]+)/",$nr,$hits);
177
    if ($hits[2]) { $nr=$hits[2]+1; $nnr=$hits[1].$nr; }
178
    else { $nr=$hits[1]+1; $nnr=$nr; };
179
    $rc=$db->query(sprintf($sql2,$nnr));
180
    if ($rc) { 
181
        $db->commit(); 
182
        return $nnr;
183
    } else { 
184
        $db->rollback(); 
185
        return false;
186
    };
191 187
}
192 188

  
193 189
function chkKdId($data) {
194 190
// 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
	}
191
    global $db,$file,$test;
192
    $sql="select * from $file where ".$file."number = '$data'";
193
    $rs=$db->getAll($sql);
194
    if ($rs[0][$file."number"]==$data) {
195
        // ja, eine neue holen
196
        return getKdId();
197
    } else {
198
        return $data;
199
    }
204 200
}
201

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

  
215 213
function getKdRefId($data) {
216 214
// gibt es die Nummer schon?
217
global $db,$file,$test;
218
	if (empty($data) or !$data) {   
219
		return false; 
220
	} 
221
	$sql="select * from $file where ".$file."number = '$data'";
222
	$rs=$db->getAll($sql);
223
	return $rs[0]["id"];
215
    global $db,$file,$test;
216
    if (empty($data) or !$data) {   
217
        return false; 
218
    } 
219
    $sql="select * from $file where ".$file."number = '$data'";
220
    $rs=$db->getAll($sql);
221
    return $rs[0]["id"];
224 222
}
225 223

  
226 224
function suchFirma($tab,$data) {
227 225
// gibt die Firma ?
228
global $db;
229
	if (empty($data) or !$data) {   
230
		return false; 
231
	}
232
	$data=strtoupper($data);
233
	$sql="select * from $tab where upper(name) like '%$data%'";
234
	$rs=$db->getAll($sql);
235
	if (!$rs) {
236
		$org=$data;
237
		while(strpos($data,"  ")>0) {
238
			$data=ereg_replace("  "," ",$data);
239
		}
240
	 	$data=preg_replace("/[^A-Z0-9]/ ",".*",trim($data));
241
		$sql="select * from $tab where upper(name) ~ '$data'"; 
242
		$rs=$db->getAll($sql);
243
		if (count($rs)==1) {
244
			return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
245
		}
246
		return false;
247
	} else {
248
		return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
249
	}
226
    global $db;
227
    if (empty($data) or !$data) {   
228
        return false; 
229
    }
230
    $data=strtoupper($data);
231
    $sql="select * from $tab where upper(name) like '%$data%'";
232
    $rs=$db->getAll($sql);
233
    if (!$rs) {
234
        $org=$data;
235
        while(strpos($data,"  ")>0) {
236
            $data=ereg_replace("  "," ",$data);
237
        }
238
         $data=preg_replace("/[^A-Z0-9]/ ",".*",trim($data));
239
        $sql="select * from $tab where upper(name) ~ '$data'"; 
240
        $rs=$db->getAll($sql);
241
        if (count($rs)==1) {
242
            return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
243
        }
244
        return false;
245
    } else {
246
        return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
247
    }
250 248
}
251 249

  
252
$land=array("DEUTSC"=>"D","FRANKR"=>"F","SPANIE"=>"ES","ITALIE"=>"I","HOLLAN"=>"NL","NIEDER"=>"NL",
253
	"BELGIE"=>"B","LUXEMB"=>"L","NORWEG"=>"N","FINNLA"=>"","GRIECH"=>"GR","OESTER"=>"A",
254
	"SCHWEI"=>"CH","SCHWED"=>"S","AUSTRI"=>"A");
255

  
256
function mkland($data) {
257
global $land;
258
	$data=strtr($data,array("Ö"=>"OE","Ä"=>"AE","Ü"=>"UE","ö"=>"OE","ä"=>"AE","ü"=>"UE","ß"=>"SS",
259
			'?'=>'OE','?'=>'AE','?'=>'UE','?'=>'OE','?'=>'AE','?'=>'UE','?'=>'SS'));
260
	$data=strtoupper(substr($data,0,6));
261
	$cntr=$land[$data];
262
	return (strlen($cntr)>0)?$cntr:substr($data,0,3);
263
}
264 250

  
265 251
//Suche Nach Kunden-/Lieferantenummer
266 252
function getFirma($nummer,$tabelle) {
267
global $db;
268
	$nummer=strtoupper($nummer);
269
	$sql="select id from $tabelle where upper(".$tabelle."number) = '$nummer'";
270
	$rs=$db->getAll($sql);
271
	if (!$rs) {
272
		$nr=ereg_replace(" ","%",$nummer);
273
		$sql="select id,".$tabelle."number from $tabelle where upper(".$tabelle."number) like '$nr'";
274
		$rs=$db->getAll($sql);
275
		if ($rs) {
276
			$nr=ereg_replace(" ","",$nummer);
277
			foreach ($rs as $row) {
278
				$tmp=ereg_replace(" ","",$row[$tabelle."number"]);
279
				if ($tmp==$nr) return $row["id"];
280
			}
281
		} else { 
282
			return false;
283
		}
284
	} else {
285
		return $rs[0]["id"];
286
	}
253
    global $db;
254
    $nummer=strtoupper($nummer);
255
    $sql="select id from $tabelle where upper(".$tabelle."number) = '$nummer'";
256
    $rs=$db->getAll($sql);
257
    if (!$rs) {
258
        $nr=ereg_replace(" ","%",$nummer);
259
        $sql="select id,".$tabelle."number from $tabelle where upper(".$tabelle."number) like '$nr'";
260
        $rs=$db->getAll($sql);
261
        if ($rs) {
262
            $nr=ereg_replace(" ","",$nummer);
263
            foreach ($rs as $row) {
264
                $tmp=ereg_replace(" ","",$row[$tabelle."number"]);
265
                if ($tmp==$nr) return $row["id"];
266
            }
267
        } else { 
268
            return false;
269
        }
270
    } else {
271
        return $rs[0]["id"];
272
    }
287 273
}
288 274

  
289 275
function getAllBG($db) {
290
	$sql  = "select * from buchungsgruppen order by description";
291
	$rs=$db->getAll($sql);
292
	return $rs;
276
    $sql  = "select * from buchungsgruppen order by description";
277
    $rs=$db->getAll($sql);
278
    return $rs;
293 279
}
280

  
294 281
function anmelden() {
295
        ini_set("gc_maxlifetime","3600");
296
        $tmp = @file_get_contents("../config/authentication.pl");
297
        preg_match("/'db'[ ]*=> '(.+)'/",$tmp,$hits);
298
        $dbname=$hits[1];
299
        preg_match("/'password'[ ]*=> '(.+)'/",$tmp,$hits);
300
        $dbpasswd=$hits[1];
301
        preg_match("/'user'[ ]*=> '(.+)'/",$tmp,$hits);
302
        $dbuser=$hits[1];
303
        preg_match("/'host'[ ]*=> '(.+)'/",$tmp,$hits);
304
        $dbhost=($hits[1])?$hits[1]:"localhost";
305
        preg_match("/'port'[ ]*=> '?(.+)'?/",$tmp,$hits);
306
        $dbport=($hits[1])?$hits[1]:"5432";
307
	preg_match("/[ ]*\\\$self->\{cookie_name\}[ ]*=[ ]*'(.+)'/",$tmp,$hits);
308
        $cookiename=$hits[1];
309
        if (!$cookiename) $cookiename='lx_office_erp_session_id';
310
        $cookie=$_COOKIE[$cookiename];
311
        if (!$cookie) header("location: ups.html");
312
        $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie);
313
        if (!$auth) { return false; };
314
        $_SESSION["sessid"]=$cookie;
315
        $_SESSION["cookie"]=$cookiename;
316
        $_SESSION["employee"]=$auth["login"];
317
        $_SESSION["mansel"]=$auth["dbname"];
318
        $_SESSION["dbname"]=$auth["dbname"];
319
        $_SESSION["dbhost"]=(!$auth["dbhost"])?"localhost":$auth["dbhost"];
320
        $_SESSION["dbport"]=(!$auth["dbport"])?"5432":$auth["dbport"];
321
        $_SESSION["dbuser"]=$auth["dbuser"];
322
        $_SESSION["dbpasswd"]=$auth["dbpasswd"];
323
        $_SESSION["db"]=new myDB($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpasswd"],$_SESSION["dbname"],$_SESSION["dbport"],$showErr);
324
        $_SESSION["authcookie"]=$authcookie;
325
        $sql="select * from employee where login='".$auth["login"]."'";
326
        $rs=$_SESSION["db"]->getAll($sql);
327
        if(!$rs) {
328
                return false;
282
    ini_set("gc_maxlifetime","3600");
283
    $tmp = @file_get_contents("../config/authentication.pl");
284
    preg_match("/'db'[ ]*=> '(.+)'/",$tmp,$hits);
285
    $dbname=$hits[1];
286
    preg_match("/'password'[ ]*=> '(.+)'/",$tmp,$hits);
287
    $dbpasswd=$hits[1];
288
    preg_match("/'user'[ ]*=> '(.+)'/",$tmp,$hits);
289
    $dbuser=$hits[1];
290
    preg_match("/'host'[ ]*=> '(.+)'/",$tmp,$hits);
291
    $dbhost=($hits[1])?$hits[1]:"localhost";
292
    preg_match("/'port'[ ]*=> '?(.+)'?/",$tmp,$hits);
293
    $dbport=($hits[1])?$hits[1]:"5432";
294
    preg_match("/[ ]*\\\$self->\{cookie_name\}[ ]*=[ ]*'(.+)'/",$tmp,$hits);
295
    $cookiename=$hits[1];
296
    if (!$cookiename) $cookiename='lx_office_erp_session_id';
297
    $cookie=$_COOKIE[$cookiename];
298
    if (!$cookie) header("location: ups.html");
299
    $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie);
300
    if (!$auth) { return false; };
301
    $_SESSION["sessid"]=$cookie;
302
    $_SESSION["cookie"]=$cookiename;
303
    $_SESSION["employee"]=$auth["login"];
304
    $_SESSION["mansel"]=$auth["dbname"];
305
    $_SESSION["dbname"]=$auth["dbname"];
306
    $_SESSION["dbhost"]=(!$auth["dbhost"])?"localhost":$auth["dbhost"];
307
    $_SESSION["dbport"]=(!$auth["dbport"])?"5432":$auth["dbport"];
308
    $_SESSION["dbuser"]=$auth["dbuser"];
309
    $_SESSION["dbpasswd"]=$auth["dbpasswd"];
310
    $_SESSION["db"]=new myDB($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpasswd"],$_SESSION["dbname"],$_SESSION["dbport"],$showErr);
311
    $_SESSION["authcookie"]=$authcookie;
312
    $sql="select * from employee where login='".$auth["login"]."'";
313
    $rs=$_SESSION["db"]->getAll($sql);
314
    if(!$rs) {
315
            return false;
316
    } else {
317
        if ($rs) {
318
            $tmp=$rs[0];
319
            $_SESSION["termbegin"]=(($tmp["termbegin"]>=0)?$tmp["termbegin"]:8);
320
            $_SESSION["termend"]=($tmp["termend"])?$tmp["termend"]:19;
321
            $_SESSION["Pre"]=$tmp["pre"];
322
            $_SESSION["interv"]=($tmp["interv"]>0)?$tmp["interv"]:60;
323
            $_SESSION["loginCRM"]=$tmp["id"];
324
            $_SESSION["lang"]=$tmp["countrycode"]; //"de";
325
            $_SESSION["kdview"]=$tmp["kdview"];
326
            $sql="select * from defaults";
327
            $rs=$_SESSION["db"]->getAll($sql);
328
            $_SESSION["ERPver"]=$rs[0]["version"];
329
            return true;
329 330
        } else {
330
                if ($rs) {
331
                        $tmp=$rs[0];
332
                        $_SESSION["termbegin"]=(($tmp["termbegin"]>=0)?$tmp["termbegin"]:8);
333
                        $_SESSION["termend"]=($tmp["termend"])?$tmp["termend"]:19;
334
                        $_SESSION["Pre"]=$tmp["pre"];
335
                        $_SESSION["interv"]=($tmp["interv"]>0)?$tmp["interv"]:60;
336
                        $_SESSION["loginCRM"]=$tmp["id"];
337
                        $_SESSION["lang"]=$tmp["countrycode"]; //"de";
338
                        $_SESSION["kdview"]=$tmp["kdview"];
339
                        $sql="select * from defaults";
340
                        $rs=$_SESSION["db"]->getAll($sql);
341
                        $_SESSION["ERPver"]=$rs[0]["version"];
342
                        return true;
343
                } else {
344
                        return false;
345
                }
331
            return false;
346 332
        }
333
    }
347 334
}
348 335

  
349 336
function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie) {
350
        $db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true);
351
        $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on ";
352
        $sql.="u.login=sc.sess_value left join auth.session s on s.id=sc.session_id ";
353
        $sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc";
354
        $rs=$db->getAll($sql,"authuser_1");
355
        if (!$rs) return false;
356
        $stmp="";
357
        if (count($rs)>1) {
358
                header("location:../login.pl?action=logout");
359
                /*foreach($rs as $row) {
360
                        $stmp.=$row["session_id"].",";
361
                }
362
                $sql1="delete from session where id in (".substr($stmp,-1).")";
363
                $sql2="delete from session_content where session_id in (".substr($stmp,-1).")";
364
                $db->query($sql1,"authuser_A");
365
                $db->query($sql2,"authuser_B");
366
                $sql3="insert into session ";*/
337
    $db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true);
338
    $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on ";
339
    $sql.="u.login=sc.sess_value left join auth.session s on s.id=sc.session_id ";
340
    $sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc";
341
    $rs=$db->getAll($sql,"authuser_1");
342
    if (!$rs) return false;
343
    $stmp="";
344
    if (count($rs)>1) {
345
        header("location:../login.pl?action=logout");
346
        /*foreach($rs as $row) {
347
                $stmp.=$row["session_id"].",";
367 348
        }
368
        $sql="select * from auth.user where id=".$rs[0]["id"];
369
        $rs1=$db->getAll($sql,"authuser_1");
370
        if (!$rs1) return false;
371
        $auth=array();
372
        $auth["login"]=$rs1[0]["login"];
373
        $sql="select * from auth.user_config where user_id=".$rs[0]["id"];
374
        $rs1=$db->getAll($sql,"authuser_2");
375
        $keys=array("dbname","dbpasswd","dbhost","dbport","dbuser");
376
        foreach ($rs1 as $row) {
377
                if (in_array($row["cfg_key"],$keys)) {
378
                        $auth[$row["cfg_key"]]=$row["cfg_value"];
379
                }
349
        $sql1="delete from session where id in (".substr($stmp,-1).")";
350
        $sql2="delete from session_content where session_id in (".substr($stmp,-1).")";
351
        $db->query($sql1,"authuser_A");
352
        $db->query($sql2,"authuser_B");
353
        $sql3="insert into session ";*/
354
    }
355
    $sql="select * from auth.user where id=".$rs[0]["id"];
356
    $rs1=$db->getAll($sql,"authuser_1");
357
    if (!$rs1) return false;
358
    $auth=array();
359
    $auth["login"]=$rs1[0]["login"];
360
    $sql="select * from auth.user_config where user_id=".$rs[0]["id"];
361
    $rs1=$db->getAll($sql,"authuser_2");
362
    $keys=array("dbname","dbpasswd","dbhost","dbport","dbuser");
363
    foreach ($rs1 as $row) {
364
        if (in_array($row["cfg_key"],$keys)) {
365
                $auth[$row["cfg_key"]]=$row["cfg_value"];
380 366
        }
381
        $sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'";
382
        $db->query($sql,"authuser_3");
383
        return $auth;
367
    }
368
    $sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'";
369
    $db->query($sql,"authuser_3");
370
    return $auth;
384 371
}
385 372

  
386
function getLager($db) {
387
	$sql="select w.description as ort,bin.id,bin.description as platz from 	warehouse w left join bin  on w.id=bin.warehouse_id";
388
	$rs=$db->getAll($sql,"getLager");
389
	return $rs;
390
}
391 373
?>
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
9 9
*/
10 10

  
11 11

  
12
function ende($nr) {
13
	echo "Abbruch: $nr<br>";
14
	echo "Fehlende oder falsche Daten.";
15
	exit(1);
12
function ende($txt) {
13
    echo "Abbruch: $txt<br>";
14
    exit(1);
16 15
}
17 16

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

  
26
if (!anmelden()) ende(5);
25
if (!anmelden()) ende("Anmeldung fehlgeschlagen.");
27 26

  
28 27
/* get DB instance */
29 28
$db=$_SESSION["db"]; //new myDB($login);
......
32 31
/* just display page or do real import? */
33 32
if ($_POST["ok"]) {
34 33

  
35
require ("parts_import.php");
36

  
37
/* display help */
38
if ($_POST["ok"]=="Hilfe") {
39
	echo "Importfelder:<br>";
40
	echo "Feldname => Bedeutung<br>";
41
	foreach($parts as $key=>$val) {
42
		echo "$key => $val<br>";
43
	}
44
	echo "<br>Die erste Zeile enth&auml;lt die Feldnamen der Daten in ihrer richtigen Reihenfolge<br>";
45
	echo "Geben Sie das Trennzeichen der Datenspalten ein. Steuerzeichen k&ouml;nnen mit ihrem Dezimalwert gef&uuml;hrt von einem &quot;#&quot; eingegebn werden (#11).<br><br>"; 
46
	echo "Der &quot;sellprice&quot; kann um den eingegeben Wert  ge&auml;ndert werden.<br><br>";
47
	echo "Bei vorhandenen Artikelnummern (in der db), kann entweder ein Update auf den Preis (und Text) durchgef&uuml;hrt werden oder der Artikel mit anderer Artikelnummer eingef&uuml;gt werden.<br><br>";
48
	echo "Jeder Artikel mu&szlig; einer Buchungsgruppe zugeordnet werden. ";
49
	echo "Dazu mu&szlig; entweder in der Maske eine Standardbuchungsgruppe gew&auml;hlt werden <br>";
50
	echo "oder es wird ein g&uuml;ltiges Konto in 'income_accno_id' und 'expense_accno_id' eingegeben. ";
51
	echo "Das Programm versucht dann eine passende Buchungsgruppe zu finden.";
52
	exit(0);
53
};
54

  
55
clearstatcache ();
56

  
57
$test    = $_POST["test"];
58
$lager    = $_POST["lager"];
59
$TextUpd = $_POST["TextUpd"];
60
$trenner = ($_POST["trenner"])?$_POST["trenner"]:",";
61
$trennzeichen = ($_POST["trennzeichen"])?$_POST["trennzeichen"]:"";
62
$precision = $_POST["precision"];
63
$quotation = $_POST["quotation"];
64
$quottype = $_POST["quottype"];
65
$file    = "parts";
66

  
67
/* no data? */
68
if (empty($_FILES["Datei"]["name"]))
69
	ende (2);
70

  
71
/* copy file */
72
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file.".csv")) {
73
	echo "Upload von Datei fehlerhaft.";
74
	echo $_FILES["Datei"]["error"], "<br>";
75
	ende (2);
76
} 
77

  
78
/* ??? */
79
//if (!chkUsr($login))
80
//	ende(4);
81

  
82
/* ??? */
83
//if (!file_exists("../users/$login.conf")) 
84
//	ende(3);
85

  
86
/* check if file is really there */
87
if (!file_exists("$file.csv")) 
88
	ende(3);
89

  
90
/* ??? */
91
if (!$db->chkcol($file)) 
92
	ende(6);
93

  
94

  
95
/* first check all elements */
96
echo "Checking data:<br>";
97
$_test=$_POST;
98
$_test["precision"]=-1;
99
$_test["quotation"]=0;
100
$_test["lager"]=$_POST["lager"];
101
$_test["lagerplatz"]=$_POST["lagerplatz"];
102
//$_test["shop"]="n";
103
//$_test["wgtrenner"]="!";
104
$err = import_parts($db, $file, $trenner, $trennzeichen, $parts, TRUE, FALSE, FALSE,$_test);
105
echo "$err Errors found\n";
106

  
107

  
108
if ($err!=0)
109
	exit(0);
110

  
111
/* just print data or insert it, if test is false */
112
import_parts($db, $file, $trenner, $trennzeichen, $parts, FALSE, !$test, TRUE,$_POST);
34
    require ("parts_import.php");
35

  
36
    /* display help */
37
    if ($_POST["ok"]=="Hilfe") {
38
        echo "Importfelder:<br>";
39
        echo "Feldname => Bedeutung<br>";
40
        foreach($parts as $key=>$val) {
41
            echo "$key => $val<br>";
42
        }
43
        $header=implode(";",array_keys($parts));
44
        echo $header;
45
        echo "<br><br>Die erste Zeile enth&auml;lt die Feldnamen der Daten in ihrer richtigen Reihenfolge<br>";
46
        echo "Geben Sie das Trennzeichen der Datenspalten ein. Steuerzeichen k&ouml;nnen mit ihrem Dezimalwert ";
47
        echo "gef&uuml;hrt von einem &quot;#&quot; eingegebn werden (#11).<br><br>"; 
48
        echo "Wird bei &quot;Art&quot; in der Maske &quot;gemischt&quot; gew&auml;hlt, muss die Spalte &quot;art&quot; vor der Einheit stehen.<br><br>";
49
        echo "Der &quot;sellprice&quot; kann um den eingegeben Wert  ge&auml;ndert werden.<br><br>";
50
        echo "Bei vorhandenen Artikelnummern (in der db), kann entweder ein Update auf den Preis (und Text) durchgef&uuml;hrt werden oder ";
51
        echo "der Artikel mit anderer Artikelnummer eingef&uuml;gt werden.<br><br>";
52
        echo "Jeder Artikel mu&szlig; einer Buchungsgruppe zugeordnet werden. ";
53
        echo "Dazu mu&szlig; entweder in der Maske eine Standardbuchungsgruppe gew&auml;hlt werden <br>";
54
        echo "oder es wird ein g&uuml;ltiges Konto in 'income_accno_id' und 'expense_accno_id' eingegeben. ";
55
        echo "Das Programm versucht dann eine passende Buchungsgruppe zu finden.";
56
        exit(0);
57
    };
58

  
59
    clearstatcache ();
60

  
61
    $test    = $_POST["test"];
62
    $lager    = $_POST["lager"];
63
    $TextUpd = $_POST["TextUpd"];
64
    $trenner = ($_POST["trenner"])?$_POST["trenner"]:",";
65
    $trennzeichen = ($_POST["trennzeichen"])?$_POST["trennzeichen"]:"";
66
    $precision = $_POST["precision"];
67
    $quotation = $_POST["quotation"];
68
    $quottype = $_POST["quottype"];
69
    $file    = "parts";
70

  
71
    /* no data? */
72
    if (empty($_FILES["Datei"]["name"]))
73
        ende ("Kein Datenfile angegeben");
74

  
75
    /* copy file */
76
    if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$file.".csv")) {
77
        ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]);
78
    } 
79

  
80
    /* check if file is really there */
81
    if (!file_exists("$file.csv") or filesize("$file.csv")==0) 
82
        ende("Datenfile ($file.csv) nicht im Ordner gefunden oder leer");
83

  
84
    /* Zu diesem Zeitpunkt wurde der Artikel Importiert */
85
    if (!$db->chkcol($file)) 
86
        ende("Importspalte konnte nicht angelegt werden");
87

  
88
    /* first check all elements */
89
    $_test=$_POST;
90
    $_test["precision"]=-1;
91
    $_test["quotation"]=0;
92
    $_test["lager"]=$_POST["lager"];
93
    $_test["lagerplatz"]=$_POST["lagerplatz"];
94

  
95
    /* just print data or insert it, if test is false */
96
    import_parts($db, $file, $trenner, $trennzeichen, $parts, FALSE, !$test, $_POST["show"],$_POST);
113 97

  
114 98
} else {
115
	$bugrus=getAllBG($db);
116
	$lagerplatz=getLager($db);
99
    $bugrus=getAllBG($db);
117 100
?>
118 101

  
119 102
<p class="listtop">Artikelimport f&uuml;r die ERP<p>
......
124 107
<table>
125 108
<tr><td><input type="submit" name="ok" value="Hilfe"></td><td></td></tr>
126 109
<tr><td>Trennzeichen</td><td>
127
		<input type="radio" name="trenner" value=";" checked>Semikolon 
128
		<input type="radio" name="trenner" value=",">Komma 
129
		<input type="radio" name="trenner" value="#9" checked>Tabulator
130
		<input type="radio" name="trenner" value=" ">Leerzeichen
131
		<input type="radio" name="trenner" value="other"> 
132
		<input type="text" size="2" name="trennzeichen" value=""> 
110
        <input type="radio" name="trenner" value=";" checked>Semikolon 
111
        <input type="radio" name="trenner" value=",">Komma 
112
        <input type="radio" name="trenner" value="#9" checked>Tabulator
113
        <input type="radio" name="trenner" value=" ">Leerzeichen
114
        <input type="radio" name="trenner" value="other"> 
115
        <input type="text" size="2" name="trennzeichen" value=""> 
133 116
</td></tr>
134 117
<tr><td>VK-Preis<br>Nachkomma:</td><td><input type="Radio" name="precision" value="0">0  
135
			<input type="Radio" name="precision" value="1">1 
136
			<input type="Radio" name="precision" value="2" checked>2 
137
			<input type="Radio" name="precision" value="3">3 
138
			<input type="Radio" name="precision" value="4">4 
139
			<input type="Radio" name="precision" value="5">5 
140
	</td></tr>
118
            <input type="Radio" name="precision" value="1">1 
119
            <input type="Radio" name="precision" value="2" checked>2 
120
            <input type="Radio" name="precision" value="3">3 
121
            <input type="Radio" name="precision" value="4">4 
122
            <input type="Radio" name="precision" value="5">5 
123
    </td></tr>
141 124
<tr><td>VK-Preis<br>Aufschlag:</td><td><input type="text" name="quotation" size="5" value="0"> 
142
			<input type="radio" name="quottype" value="P" checked>% 
143
			<input type="radio" name="quottype" value="A">Absolut</td></tr>
125
            <input type="radio" name="quottype" value="P" checked>% 
126
            <input type="radio" name="quottype" value="A">Absolut</td></tr>
144 127
<tr><td>Vorhandene<br>Artikelnummer:</td><td><input type="radio" name="update" value="U" checked>Preis update durchf&uuml;hren<br>
145
					<input type="radio" name="update" value="I">mit neuer Nummer einf&uuml;gen</td></tr>
128
                    <input type="radio" name="update" value="I">mit neuer Nummer einf&uuml;gen</td></tr>
129
<tr><td>Kontollausgabe</td><td><input type="checkbox" name="show" value="1" checked>ja</td></tr>
146 130
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
147 131
<tr><td>Textupdate</td><td><input type="checkbox" name="TextUpd" value="1">ja</td></tr>
148 132
<tr><td>Warengruppen<br>verbinder</td><td><input type="text" name="wgtrenner" value="!" size="3"></td></tr>
149
<tr><td>Shopartikel</td><td><input type="radio" name="shop" value="t">ja <input type="radio" name="shop" value="n" checked>nein</td></tr>
133
<tr><td>Shopartikel</td><td><input type="radio" name="shop" value="t">ja <input type="radio" name="shop" value="f" checked>nein</td></tr>
150 134
<tr><td>Art</td><td><input type="Radio" name="ware" value="W" checked>Ware &nbsp; 
151
		    <input type="Radio" name="ware" value="D">Dienstleistung
152
		    <input type="Radio" name="ware" value="G">gemischt (Spalte 'art' vorhanden)</td></tr>
135
            <input type="Radio" name="ware" value="D">Dienstleistung
136
            <input type="Radio" name="ware" value="G">gemischt (Spalte 'art' vorhanden)</td></tr>
153 137
<tr><td>Default Bugru<br></td><td><select name="bugru">
154
<?	if ($bugrus) foreach ($bugrus as $bg) { ?>
155
			<option value="<?= $bg["id"] ?>"><?= $bg["description"] ?>
156
<?	} ?>
157
	</select>
158
	<input type="radio" name="bugrufix" value="0">nie<br>
159
	<input type="radio" name="bugrufix" value="1" checked>f&uuml;r alle Artikel verwenden
160
	<input type="radio" name="bugrufix" value="2">f&uuml;r Artikel ohne passende Bugru
161
	</td></tr>
162
<tr><td>Default Lager<br></td><td><select name="lager">
163
<?	if ($lagerplatz) foreach ($lagerplatz as $lp) { ?>
164
			<option value="<?= $lp["id"] ?>"><?= $lp["ort"] ?>-<?= $lp["platz"] ?>
165
<?	} ?>
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.

Auch abrufbar als: Unified diff