3 Funktionsbibliothek für den Datenimport in Lx-Office ERP
6 Author: Holger Lindemann
7 Email: hli@lx-system.de
8 Web: http://lx-system.de
12 require_once "db.php";
15 "name" => "Firmenname",
16 "department_1" => "Abteilung",
17 "department_2" => "Abteilung",
18 "street" => "Strasse + Nr",
22 "contact" => "Ansprechpartner",
25 "homepage" => "Homepage",
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",
38 "branche" => "Branche",
39 //"language" => "Sprache (de,en,fr)",
41 "creditlimit" => "Kreditlimit (nnnnnn.nn)"); /*,
42 "hierarchie" => "Hierarchie",
43 "potenzial" => "Potenzial",
44 "ar" => "Debitorenkonto",
45 "ap" => "Kreditorenkonto",
46 "matchcode" => "Matchcode",
47 "customernumber2" => "Kundennummer 2");
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",
62 "shiptoemail" => "eMail",
63 "customernumber" => "Kundennummer",
64 "vendornumber" => "Lieferantennummer");
67 "partnumber" => "Artikelnummer",
69 "description" => "Artikeltext",
71 "weight" => "Gewicht in Benutzerdefinition",
72 "notes" => "Beschreibung",
73 "notes1" => "Beschreibung",
75 "makemodel" => "Hersteller",
76 "model" => "Modellbezeichnung",
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ß vor den Konten kommen",
84 "inventory_accno" => "Bestandskonto",
85 "income_accno" => "Erlö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 "shop" => "Shopexport vorghesehen",
100 $contactscrm = array(
101 "customernumber" => "Kundennummer",
102 "vendornumber" => "Lieferantennummer",
103 "cp_cv_id" => "FirmenID in der db",
104 "firma" => "Firmenname",
105 "cp_abteilung" => "Abteilung",
106 "cp_position" => "Position/Hierarchie",
107 "cp_gender" => "Geschlecht (m/f)",
108 "cp_title" => "Titel",
109 "cp_givenname" => "Vorname",
110 "cp_name" => "Nachname",
111 "cp_email" => "eMail",
112 "cp_phone1" => "Telefon 1",
113 "cp_phone2" => "Telefon 2",
114 "cp_mobile1" => "Mobiltelefon 1",
115 "cp_mobile2" => "Mobiltelefon 2",
116 "cp_homepage" => "Homepage",
117 "cp_street" => "Strasse",
118 "cp_country" => "Land",
119 "cp_zipcode" => "PLZ",
121 "cp_privatphone" => "Privattelefon",
122 "cp_privatemail" => "private eMail",
123 "cp_notes" => "Bemerkungen",
124 "cp_stichwort1" => "Stichwort(e)",
125 "cp_id" => "Kontakt ID"
129 "customernumber" => "Kundennummer",
130 "vendornumber" => "Lieferantennummer",
131 "cp_cv_id" => "FirmenID in der db",
132 "firma" => "Firmenname",
133 "cp_greeting" => "Anrede",
134 "cp_title" => "Titel",
135 "cp_givenname" => "Vorname",
136 "cp_greeting" => "Anrede",
137 "cp_name" => "Nachname",
138 "cp_email" => "eMail",
139 "cp_phone1" => "Telefon 1",
140 "cp_phone2" => "Telefon 2",
141 "cp_mobile1" => "Mobiltelefon 1",
142 "cp_mobile2" => "Mobiltelefon 2",
143 "cp_privatphone" => "Privattelefon",
144 "cp_privatemail" => "private eMail",
145 "cp_homepage" => "Homepage",
146 "cp_id" => "Kontakt ID"
149 function checkCRM() {
151 $sql="select * from crm";
152 $rs=$db->getAll($sql);
160 function chkUsr($usr) {
161 // ist es ein gültiger ERP-Benutzer? Er muß mindestens 1 x angemeldet gewesen sein.
163 $sql="select * from employee where login = '$usr'";
164 $rs=$db->getAll($sql);
165 if ($rs[0]["id"]) { return $rs[0]["id"]; }
166 else { return false; };
170 // die nächste freie Kunden-/Lieferantennummer holen
171 global $db,$file,$test;
172 if ($test) { return "#####"; }
173 $sql1="select * from defaults";
174 $sql2="update defaults set ".$file."number = '%s'";
176 $rs=$db->getAll($sql1);
177 $nr=$rs[0][$file."number"];
178 preg_match("/^([^0-9]*)([0-9]+)/",$nr,$hits);
179 if ($hits[2]) { $nr=$hits[2]+1; $nnr=$hits[1].$nr; }
180 else { $nr=$hits[1]+1; $nnr=$nr; };
181 $rc=$db->query(sprintf($sql2,$nnr));
191 function chkKdId($data) {
192 // gibt es die Nummer schon?
193 global $db,$file,$test;
194 $sql="select * from $file where ".$file."number = '$data'";
195 $rs=$db->getAll($sql);
196 if ($rs[0][$file."number"]==$data) {
197 // ja, eine neue holen
204 function chkContact($id) {
206 $sql="select * from contact where cp_id = $id";
207 $rs=$db->getAll($sql);
208 if ($rs[0]["cp_id"]==$id) {
215 function getKdRefId($data) {
216 // gibt es die Nummer schon?
217 global $db,$file,$test;
218 if (empty($data) or !$data) {
221 $sql="select * from $file where ".$file."number = '$data'";
222 $rs=$db->getAll($sql);
226 function suchFirma($tab,$data) {
229 if (empty($data) or !$data) {
232 $data=strtoupper($data);
233 $sql="select * from $tab where upper(name) like '%$data%'";
234 $rs=$db->getAll($sql);
237 while(strpos($data," ")>0) {
238 $data=ereg_replace(" "," ",$data);
240 $data=preg_replace("/[^A-Z0-9]/ ",".*",trim($data));
241 $sql="select * from $tab where upper(name) ~ '$data'";
242 $rs=$db->getAll($sql);
244 return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
248 return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
253 //Suche Nach Kunden-/Lieferantenummer
254 function getFirma($nummer,$tabelle) {
256 $nummer=strtoupper($nummer);
257 $sql="select id from $tabelle where upper(".$tabelle."number) = '$nummer'";
258 $rs=$db->getAll($sql);
260 $nr=ereg_replace(" ","%",$nummer);
261 $sql="select id,".$tabelle."number from $tabelle where upper(".$tabelle."number) like '$nr'";
262 $rs=$db->getAll($sql);
264 $nr=ereg_replace(" ","",$nummer);
265 foreach ($rs as $row) {
266 $tmp=ereg_replace(" ","",$row[$tabelle."number"]);
267 if ($tmp==$nr) return $row["id"];
277 function getAllBG($db) {
278 $sql = "select * from buchungsgruppen order by description";
279 $rs=$db->getAll($sql);
283 function anmelden() {
284 ini_set("gc_maxlifetime","3600");
285 $tmp = @file_get_contents("../config/authentication.pl");
286 preg_match("/'db'[ ]*=> '(.+)'/",$tmp,$hits);
288 preg_match("/'password'[ ]*=> '(.+)'/",$tmp,$hits);
290 preg_match("/'user'[ ]*=> '(.+)'/",$tmp,$hits);
292 preg_match("/'host'[ ]*=> '(.+)'/",$tmp,$hits);
293 $dbhost=($hits[1])?$hits[1]:"localhost";
294 preg_match("/'port'[ ]*=> '?(.+)'?/",$tmp,$hits);
295 $dbport=($hits[1])?$hits[1]:"5432";
296 preg_match("/[ ]*\\\$self->\{cookie_name\}[ ]*=[ ]*'(.+)'/",$tmp,$hits);
297 $cookiename=$hits[1];
298 if (!$cookiename) $cookiename='lx_office_erp_session_id';
299 $cookie=$_COOKIE[$cookiename];
300 if (!$cookie) header("location: ups.html");
301 $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie);
302 if (!$auth) { return false; };
303 $_SESSION["sessid"]=$cookie;
304 $_SESSION["cookie"]=$cookiename;
305 $_SESSION["employee"]=$auth["login"];
306 $_SESSION["mansel"]=$auth["dbname"];
307 $_SESSION["dbname"]=$auth["dbname"];
308 $_SESSION["dbhost"]=(!$auth["dbhost"])?"localhost":$auth["dbhost"];
309 $_SESSION["dbport"]=(!$auth["dbport"])?"5432":$auth["dbport"];
310 $_SESSION["dbuser"]=$auth["dbuser"];
311 $_SESSION["dbpasswd"]=$auth["dbpasswd"];
312 $_SESSION["db"]=new myDB($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpasswd"],$_SESSION["dbname"],$_SESSION["dbport"],$showErr);
313 $_SESSION["authcookie"]=$authcookie;
314 $sql="select * from employee where login='".$auth["login"]."'";
315 $rs=$_SESSION["db"]->getAll($sql);
321 $_SESSION["termbegin"]=(($tmp["termbegin"]>=0)?$tmp["termbegin"]:8);
322 $_SESSION["termend"]=($tmp["termend"])?$tmp["termend"]:19;
323 $_SESSION["Pre"]=$tmp["pre"];
324 $_SESSION["interv"]=($tmp["interv"]>0)?$tmp["interv"]:60;
325 $_SESSION["loginCRM"]=$tmp["id"];
326 $_SESSION["lang"]=$tmp["countrycode"]; //"de";
327 $_SESSION["kdview"]=$tmp["kdview"];
328 $sql="select * from defaults";
329 $rs=$_SESSION["db"]->getAll($sql);
330 $_SESSION["ERPver"]=$rs[0]["version"];
338 function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie) {
339 $db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true);
340 $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on ";
341 $sql.="u.login=sc.sess_value left join auth.session s on s.id=sc.session_id ";
342 $sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc";
343 $rs=$db->getAll($sql,"authuser_1");
344 if (!$rs) return false;
347 header("location:../login.pl?action=logout");
348 /*foreach($rs as $row) {
349 $stmp.=$row["session_id"].",";
351 $sql1="delete from session where id in (".substr($stmp,-1).")";
352 $sql2="delete from session_content where session_id in (".substr($stmp,-1).")";
353 $db->query($sql1,"authuser_A");
354 $db->query($sql2,"authuser_B");
355 $sql3="insert into session ";*/
357 $sql="select * from auth.user where id=".$rs[0]["id"];
358 $rs1=$db->getAll($sql,"authuser_1");
359 if (!$rs1) return false;
361 $auth["login"]=$rs1[0]["login"];
362 $sql="select * from auth.user_config where user_id=".$rs[0]["id"];
363 $rs1=$db->getAll($sql,"authuser_2");
364 $keys=array("dbname","dbpasswd","dbhost","dbport","dbuser");
365 foreach ($rs1 as $row) {
366 if (in_array($row["cfg_key"],$keys)) {
367 $auth[$row["cfg_key"]]=$row["cfg_value"];
370 $sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'";
371 $db->query($sql,"authuser_3");
375 * Zeichencode übersetzen
379 function translate(&$txt) {
381 $encoding = mb_detect_encoding($data,"UTF-8,ISO-8859-1,ISO-8859-15,Windows-1252,ASCII");
382 $txt = iconv("$encoding",ServerCode."//TRANSLIT",$txt);
383 //$txt = mb_convert_encoding($txt, ServerCode,"$encoding");
385 $txt = iconv(FileCode,ServerCode."//TRANSLIT",$txt);
386 //$txt = mb_convert_encoding($txt, ServerCode,FileCode);