Revision 1d69ac97
Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt
lxo-import/addressB.php | ||
---|---|---|
<html>
|
||
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
|
||
<body>
|
||
<?php
|
||
/*
|
||
Kunden- bzw. Lieferantenimport mit Browser nach Lx-Office ERP
|
||
|
||
Copyright (C) 2005
|
||
Author: Holger Lindemann
|
||
Email: hli@lx-system.de
|
||
Web: http://lx-system.de
|
||
|
||
*/
|
||
|
||
require ("import_lib.php");
|
||
|
||
function ende($txt) {
|
||
echo "Abbruch: $txt<br>";
|
||
exit(1);
|
||
}
|
||
|
||
if (!$_SESSION["db"]) {
|
||
$conffile="../config/lx_office.conf";
|
||
if (!is_file($conffile)) {
|
||
ende("lx_office.conf nicht gefunden oder unlesbar");
|
||
}
|
||
}
|
||
|
||
if (!anmelden()) ende("Anmeldung fehlgeschlagen");
|
||
|
||
if ($_POST["ok"]=="Hilfe") {
|
||
echo "Importfelder:<br>";
|
||
echo "Feldname => Bedeutung<br>";
|
||
foreach($address as $key=>$val) {
|
||
echo "$key => $val<br>";
|
||
}
|
||
$header=implode(";",array_keys($address));
|
||
echo $header;
|
||
exit(0);
|
||
};
|
||
|
||
if ($_POST["ok"]) {
|
||
|
||
$nun=time();
|
||
|
||
|
||
/* get DB instance */
|
||
$db=$_SESSION["db"]; //new myDB($login);
|
||
|
||
$crm=checkCRM();
|
||
|
||
$dir = "../users/";
|
||
clearstatcache ();
|
||
//print_r($_FILES);
|
||
$test=$_POST["test"];
|
||
if (!empty($_FILES["Datei"]["name"])) {
|
||
$file=$_POST["ziel"];
|
||
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) {
|
||
$file=false;
|
||
echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
|
||
}
|
||
} else if (is_file($dir.$_POST["ziel"].".csv")) {
|
||
$file=$_POST["ziel"];
|
||
} else {
|
||
$file=false;
|
||
}
|
||
|
||
if (!$file) ende ("Kein Datenfile");
|
||
|
||
$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
|
||
if ($trenner=="other") {
|
||
$trenner=trim($trennzeichen);
|
||
}
|
||
if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
|
||
|
||
if (!file_exists($dir.$file.".csv")) ende("$file.csv nicht im Ordner oder leer");
|
||
|
||
if (!$db->chkcol($file)) ende("Importspalte kann nicht angelegt werden");
|
||
|
||
$employee=chkUsr($_SESSION["employee"]);
|
||
if (!$employee) ende("Ungültiger User");
|
||
|
||
$kunde_fld = array_keys($address);
|
||
|
||
//Zeichencodierung des Servers
|
||
$tmpcode = $db->getServerCode();
|
||
//Leider sind die Benennungen vom Server anders als von mb_detect_encoding
|
||
if ($tmpcode == "UTF8") {
|
||
define("ServerCode","UTF-8");
|
||
} else if ($tmpcode == "LATIN9") {
|
||
define("ServerCode","ISO-8859-15");
|
||
} else if ($tmpcode == "LATIN1") {
|
||
define("ServerCode","ISO-8859-1");
|
||
} else {
|
||
define("ServerCode",$tmpcode);
|
||
}
|
||
//Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
|
||
//DB und LxO müssen ja nicht auf der gleichen Maschiene sein.
|
||
if($tmpcode<>$db->getClientCode()) {
|
||
$rc = $db->setClientCode($tmpcode);
|
||
}
|
||
|
||
// Zeichenkodierung File
|
||
if ($_POST["encoding"] == "auto") {
|
||
define("Auto",true);
|
||
define("Translate",true);
|
||
} else {
|
||
define("Auto",false);
|
||
if ($_POST["encoding"] == ServerCode) {
|
||
define("Translate",false);
|
||
} else {
|
||
define("Translate",true);
|
||
define("FileCode",$_POST["encoding"]);
|
||
}
|
||
}
|
||
|
||
function chkBusiness($data,$id=true) {
|
||
global $db;
|
||
if ($id) {
|
||
$rs = $db->getAll("select id from business where id =$data");
|
||
} else {
|
||
$rs = $db->getAll("select id from business where decription ilike '$data'");
|
||
}
|
||
if ($rs[0]["id"]) {
|
||
return $rs[0]["id"];
|
||
} else {
|
||
return "null";
|
||
}
|
||
}
|
||
|
||
function chkSalesman($data,$id=true) {
|
||
global $db;
|
||
if ($id) {
|
||
$rs = $db->getAll("select id from employee where id =$data");
|
||
} else {
|
||
$rs = $db->getAll("select id from employee where login ilike '$data'");
|
||
}
|
||
if ($rs[0]["id"]) {
|
||
return $rs[0]["id"];
|
||
} else {
|
||
return "null";
|
||
}
|
||
}
|
||
|
||
$f=fopen($dir.$file.".csv","r");
|
||
$zeile=fgets($f,1200);
|
||
$infld=explode($trenner,strtolower($zeile));
|
||
$first=true;
|
||
$ok=true;
|
||
$p=0;
|
||
foreach ($infld as $fld) {
|
||
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
|
||
if (in_array($fld,$kunde_fld)) {
|
||
if ($fld=="branche" && !$crm) { continue; };
|
||
if ($fld=="sw" && !$crm) { continue; };
|
||
$in_fld[$fld]=$p;
|
||
//$fldpos[$fld]=$p;
|
||
//$in_fld[]=$fld;
|
||
}
|
||
$p++;
|
||
}
|
||
$infld = array_keys($in_fld);
|
||
$infld[] = "import";
|
||
$infld = implode(",",$infld);
|
||
$j=0;
|
||
$m=0;
|
||
$zeile=fgetcsv($f,1200,$trenner);
|
||
if ($ok) while (!feof($f)){
|
||
$i=0;
|
||
$m++;
|
||
$anrede="";
|
||
$Matchcode="";
|
||
$sql="insert into $file ";
|
||
$keys=array();
|
||
$vals=array();
|
||
$number=false;
|
||
//foreach($zeile as $data) {
|
||
|
||
foreach($in_fld as $fld => $pos) {
|
||
switch ($fld) {
|
||
case "name" :
|
||
case "department_1" :
|
||
case "department_2" :
|
||
case "matchcode" :
|
||
case "street" :
|
||
case "city" :
|
||
case "notes" :
|
||
case "sw" :
|
||
case "branche" :
|
||
case "country" :
|
||
case "contact" :
|
||
case "homepage" :
|
||
case "email" :
|
||
case "bank" : $data = addslashes(trim($zeile[$pos]));
|
||
if (Translate) translate($data);
|
||
case "ustid" : $data = strtr(trim($zeile[$pos])," ","");
|
||
case "bank_code" : $data = trim($zeile[$pos]);
|
||
case "account_number":
|
||
case "greeting" :
|
||
case "taxnumber" :
|
||
case "zipcode" :
|
||
case "phone" :
|
||
case "fax" : $data = trim($zeile[$pos]);
|
||
$data = "'$data'";
|
||
if ($data=="''") {
|
||
$vals[] = "null";
|
||
} else {
|
||
$vals[] = $data;
|
||
}
|
||
break;
|
||
case "business_id" : $vals[] = chkBusiness(trim($zeile[$pos]));
|
||
break;
|
||
case "salesman_id" : $vals[] = chkSalesman(trim($zeile[$pos]));
|
||
break;
|
||
case "taxincluded" : $data = strtolower(substr($zeile[$pos],0,1));
|
||
if ($data!="f" && $data!="t") { $vals[] = "'f'"; }
|
||
else { $vals[] = "'".$data."'";}
|
||
break;
|
||
case "taxzone_id" : $data = trim($zeile[$pos])*1;
|
||
if ($data>3 && $data<0) $data = 0;
|
||
$vals[] = $data;
|
||
break;
|
||
case "creditlimit" :
|
||
case "discount" :
|
||
case "terms" : $vals[] = trim($zeile[$pos])*1;
|
||
break;
|
||
case "customernumber":
|
||
case "vendornumber" : $data = trim($zeile[$pos]);
|
||
if (empty($data) or !$data) {
|
||
$vals[] = getKdId();
|
||
$number = true;
|
||
} else {
|
||
$vals[] = chkKdId($data);
|
||
$number = true;
|
||
}
|
||
break;
|
||
}
|
||
};
|
||
if (!in_array("taxzone_id",$in_fld)) {
|
||
$in_fld[] = "taxzone_id";
|
||
$vals[] = 0;
|
||
}
|
||
// seit 2.6 ist die DB-Kodierung UTF-8 @holger Ansonsten einmal vorher die DB-Encoding auslesen
|
||
// Falls die Daten ISO-kodiert kommen entsprechend wandeln
|
||
// done!
|
||
// UTF-8 MUSS als erstes stehen, da ansonsten die Prüfung bei ISO-8859-1 aufhört ...
|
||
// die blöde mb_detect... tut leider nicht immer, daher die Möglichkeit der Auswahl
|
||
// TODO Umlaute am Anfang wurden bei meinem Test nicht übernommen (Österreich). S.a.:
|
||
// http://forum.de.selfhtml.org/archiv/2007/1/t143904/
|
||
if ($test) {
|
||
if ($first) {
|
||
echo "<table border='1'>\n<tr><td>";
|
||
echo implode('</th><th>',array_keys($in_fld));
|
||
echo "</td></tr>\n";
|
||
$first=false;
|
||
};
|
||
echo "<tr><td>";
|
||
echo implode('</td><td>',$vals);
|
||
echo "</td></tr>\n";
|
||
//echo "Import $j<br>\n";
|
||
flush();
|
||
} else {
|
||
$vals[] = $nun;
|
||
$sql = "INSERT INTO $file (".$infld.") values (".implode(",",$vals).")";
|
||
$rc=$db->query($sql);
|
||
if ($j % 10 == 0) { echo "."; flush(); };
|
||
if (!$rc) { echo "<br />Fehler: ".$sql."<br />"; flush(); };
|
||
}
|
||
$j++;
|
||
$zeile=fgetcsv($f,1200,$trenner);
|
||
}
|
||
fclose($f);
|
||
if ($test) echo "</table>\n ##### = Neue Kunden-/Lieferantennummer\n<br>";
|
||
echo $j." $file importiert.\n";
|
||
} else {
|
||
?>
|
||
|
||
<p class="listtop">Adressimport für die ERP<p>
|
||
<br>
|
||
<form name="import" method="post" enctype="multipart/form-data" action="addressB.php">
|
||
<!--form name="import" method="post" action="addressB.php"-->
|
||
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
|
||
<input type="hidden" name="login" value="<?php echo $login ?>">
|
||
<table>
|
||
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
|
||
<tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
|
||
<tr><td>Trennzeichen</td><td>
|
||
<input type="radio" name="trenner" value=";" checked>Semikolon
|
||
<input type="radio" name="trenner" value=",">Komma
|
||
<input type="radio" name="trenner" value="#9" checked>Tabulator
|
||
<input type="radio" name="trenner" value=" ">Leerzeichen
|
||
<input type="radio" name="trenner" value="other">
|
||
<input type="text" size="2" name="trennzeichen" value="">
|
||
</td></tr>
|
||
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
|
||
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
|
||
<tr><td>Verwendete<br />Zeichecodierung</td><td>
|
||
<select name="encoding">
|
||
<option value="auto">Automatisch (versuchen)</option>
|
||
<option value="UTF-8">UTF-8</option>
|
||
<option value="ISO-8859-1">ISO-8859-1</option>
|
||
<option value="ISO-8859-15">ISO-8859-15</option>
|
||
<option value="Windows-1252">Windows-1252</option>
|
||
<option value="ASCII">ASCII</option>
|
||
</select>
|
||
</td></tr>
|
||
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
|
||
</table>
|
||
</form>
|
||
<?php }; ?>
|
lxo-import/blz.php | ||
---|---|---|
<html>
|
||
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
|
||
<body>
|
||
<?php
|
||
/*
|
||
BLZimport mit Browser nach Lx-Office ERP
|
||
Holger Lindemann <hli@lx-system.de>
|
||
*/
|
||
|
||
|
||
/* display help */
|
||
if ($_POST["ok"]=="Hilfe") {
|
||
echo "<br>Die erste Zeile enthält keine Feldnamen der Daten.<br>";
|
||
echo "Die Datenfelder haben eine feste Breite.<br><br>";
|
||
echo "Die Daten können hier bezogen werden:<br>";
|
||
echo "<a http='http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php'>";
|
||
echo "http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php</a>";
|
||
exit(0);
|
||
} else if ($_POST) {
|
||
function ende($nr) {
|
||
echo "Abbruch: $nr<br>";
|
||
echo "Fehlende oder falsche Daten.";
|
||
exit(1);
|
||
}
|
||
|
||
function l2u($str) {
|
||
return iconv("ISO-8859-1", "UTF-8",$str);
|
||
}
|
||
|
||
require ("import_lib.php");
|
||
|
||
if (!$_SESSION["db"]) {
|
||
$conffile="../config/lx_office.conf";
|
||
if (!is_file($conffile)) {
|
||
ende(4);
|
||
}
|
||
if (!anmelden()) ende(5);
|
||
}
|
||
|
||
|
||
/* get DB instance */
|
||
$db=$_SESSION["db"];
|
||
|
||
$test=$_POST["test"];
|
||
|
||
clearstatcache ();
|
||
|
||
/* no data? */
|
||
if (empty($_FILES["Datei"]["name"]))
|
||
ende (2);
|
||
|
||
/* copy file */
|
||
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],"blz.txt")) {
|
||
print_r($_FILES);
|
||
echo $_FILES["Datei"]["tmp_name"];
|
||
echo "Upload von Datei fehlerhaft.";
|
||
echo $_FILES["Datei"]["error"], "<br>";
|
||
ende (2);
|
||
}
|
||
|
||
/* check if file is really there */
|
||
if (!file_exists("blz.txt"))
|
||
ende(3);
|
||
|
||
$sqlins="INSERT INTO blz_data (blz,fuehrend,bezeichnung,plz,ort,kurzbez,pan,bic,pzbm,nummer,aekz,bl,folgeblz) ";
|
||
$sqlins.="VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s')";
|
||
$teststr="<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>";
|
||
$teststr.="<td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td><td>%s</td></tr>\n";
|
||
$sqldel="delete from blz_data";
|
||
$ok="true";
|
||
$cnt=0;
|
||
$f=fopen("blz.txt","r");
|
||
if ($test) echo "Testdurchlauf <br><table>\n";
|
||
$i=0;
|
||
$start=time();
|
||
$rs = $db->getAll("SELECT current_setting('server_encoding')");
|
||
$srvencoding = $rs[0]['current_setting'];
|
||
$rs = $db->getAll("SELECT current_setting('client_encoding')");
|
||
$cliencoding = $rs[0]['current_setting'];
|
||
echo "SRV: $srvencoding - - CLI: $cliencoding<br>";
|
||
if ($f) {
|
||
//Cliententcoding auf Latin:
|
||
if (!$test) { $rc=$db->query("BEGIN"); if ($cliencoding=="UTF8") $db->query("SET CLIENT_ENCODING TO 'latin-9'"); };
|
||
if (!$test) $rc=$db->query($sqldel);
|
||
while (($zeile=fgets($f,256)) != FALSE) {
|
||
$cnt++;
|
||
if (!$test){
|
||
//Datenfile ist immer Latin!!
|
||
//zwei Möglichkeiten der Zeichenwandlung. Was ist besser??
|
||
//Client nicht umgestellt, Zeichen wandeln
|
||
/*$sql=sprintf($sqlins,substr($zeile,0,8),substr($zeile,8,1),l2u(substr($zeile,9,58)),substr($zeile,67,5),
|
||
l2u(substr($zeile,72,35)),l2u(substr($zeile,107,27)),substr($zeile,134,5),substr($zeile,139,11),
|
||
substr($zeile,150,2),substr($zeile,152,6),substr($zeile,158,1),substr($zeile,159,1),
|
||
substr($zeile,160,8));*/
|
||
//Client umgestellt + und auch bei nicht UTF-Client:
|
||
$sql=sprintf($sqlins,substr($zeile,0,8),substr($zeile,8,1),substr($zeile,9,58),substr($zeile,67,5),
|
||
substr($zeile,72,35),substr($zeile,107,27),substr($zeile,134,5),substr($zeile,139,11),
|
||
substr($zeile,150,2),substr($zeile,152,6),substr($zeile,158,1),substr($zeile,159,1),
|
||
substr($zeile,160,8));
|
||
$rc=$db->query($sql);
|
||
if(DB::isError($rc)) {
|
||
echo $sql."<br><pre>";
|
||
echo $rc->getMessage()."</pre><br>";
|
||
$ok=false;
|
||
break;
|
||
}
|
||
if ($cnt % 10 == 0) {
|
||
if ($cnt % 1000 == 0) { $x=time()-$start; echo sprintf("%dsec %6d<br>",$x,$cnt); }
|
||
else if ($cnt % 100 == 0) { echo "!"; }
|
||
else { echo '.'; }
|
||
flush();
|
||
}
|
||
} else {
|
||
echo sprintf($teststr,substr($zeile,0,8),substr($zeile,8,1),l2u(substr($zeile,9,58)),substr($zeile,67,5),
|
||
l2u(substr($zeile,72,35)),l2u(substr($zeile,107,27)),substr($zeile,134,5),substr($zeile,139,11),
|
||
substr($zeile,150,2),substr($zeile,152,6),substr($zeile,158,1),substr($zeile,159,1),
|
||
substr($zeile,160,8));
|
||
$rc=true;
|
||
}
|
||
if (!$rc) {
|
||
$ok=false;
|
||
break;
|
||
}
|
||
$i++;
|
||
}
|
||
if ($ok) {
|
||
if (!$test) $rc=$db->query("COMMIT");
|
||
echo "<br>$i Daten erfolgreich importierti<br>";
|
||
if ($cliencoding=="UTF8") $db->query("SET CLIENT_ENCODING TO 'UTF8'");
|
||
$stop=time();
|
||
echo $stop-$start." Sekunden";
|
||
} else {
|
||
if (!$test) $rc=$db->query("ROLLBACK");
|
||
echo "Fehler in Zeile: ".$i."<br>";
|
||
echo $sql."<br>";
|
||
ende(6);
|
||
}
|
||
} else {
|
||
ende(4);
|
||
}
|
||
echo "</table><br>Fertig. $i Banken importiert.";
|
||
} else {
|
||
?>
|
||
<p class="listtop">BLZ-Import für die ERP<p>
|
||
<br>Die erste Zeile enthält keine Feldnamen der Daten.<br>
|
||
Die Datenfelder haben eine feste Breite.<br><br>
|
||
Die Daten können hier bezogen werden:<br>
|
||
<a http='http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php'>
|
||
http://www.bundesbank.de/zahlungsverkehr/zahlungsverkehr_bankleitzahlen_download.php</a><br><br>
|
||
Das File vorher <b>nicht</b> auf UTF8 wandeln!<br><br>
|
||
Achtung!! Die bestehenden BLZ-Daten werden zunächst gelöscht.
|
||
<br>
|
||
<form name="import" method="post" enctype="multipart/form-data" action="blz.php">
|
||
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">
|
||
<input type="hidden" name="login" value="<?php echo $login ?>">
|
||
<table>
|
||
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
|
||
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
|
||
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
|
||
</table>
|
||
</form>
|
||
<?php } ?>
|
lxo-import/contactB.php | ||
---|---|---|
<html>
|
||
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
|
||
<body>
|
||
<?php
|
||
/*
|
||
Kontaktimport mit Browser nach Lx-Office ERP
|
||
|
||
Copyright (C) 2005
|
||
Author: Holger Lindemann
|
||
Email: hli@lx-system.de
|
||
Web: http://lx-system.de
|
||
|
||
*/
|
||
if (!$_SESSION["db"]) {
|
||
$conffile="../config/lx_office.conf";
|
||
if (!is_file($conffile)) {
|
||
ende(4);
|
||
}
|
||
}
|
||
|
||
function ende($nr) {
|
||
echo "Abbruch: $nr\n";
|
||
exit($nr);
|
||
}
|
||
|
||
|
||
require ("import_lib.php");
|
||
|
||
if (!anmelden()) ende(5);
|
||
|
||
/* get DB instance */
|
||
$db=$_SESSION["db"]; //new myDB($login);
|
||
|
||
|
||
$crm=checkCRM();
|
||
|
||
if ($_POST["ok"]) {
|
||
$dir = "../users/";
|
||
|
||
$test=$_POST["test"];
|
||
|
||
if ($crm) {
|
||
$kunde_fld = array_keys($contactscrm);
|
||
$contact=$contactscrm;
|
||
} else {
|
||
$kunde_fld = array_keys($contacts);
|
||
$contact=$contacts;
|
||
}
|
||
$nun=time();
|
||
|
||
if ($_POST["ok"]=="Hilfe") {
|
||
echo "Importfelder:<br>";
|
||
echo "Feldname => Bedeutung<br>";
|
||
foreach($contact as $key=>$val) {
|
||
echo "$key => $val<br>";
|
||
}
|
||
exit(0);
|
||
};
|
||
|
||
clearstatcache ();
|
||
|
||
$trenner=($_POST["trenner"])?$_POST["trenner"]:",";
|
||
if ($trenner=="other") {
|
||
$trenner=trim($trennzeichen);
|
||
if (substr($trenner,0,1)=="#") if (strlen($trenner)>1) $trenner=chr(substr($trenner,1));
|
||
}
|
||
|
||
|
||
if (!empty($_FILES["Datei"]["name"])) {
|
||
$file=$_POST["ziel"];
|
||
if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file."_contact.csv")) {
|
||
$file=false;
|
||
echo "Upload von ".$_FILES["Datei"]["name"]." fehlerhaft. (".$_FILES["Datei"]["error"].")<br>";
|
||
}
|
||
} else if (is_file($dir.$_POST["ziel"]."_contact.csv")) {
|
||
$file=$_POST["ziel"];
|
||
} else {
|
||
$file=false;
|
||
}
|
||
|
||
if (!$file) ende (2);
|
||
|
||
if (!file_exists($dir.$file."_contact.csv")) ende(5);
|
||
|
||
//$prenumber=$_POST["prenumber"];
|
||
|
||
$employee=chkUsr($_SESSION["employee"]);
|
||
if (!$employee) ende(4);
|
||
|
||
if (!$db->chkcol($file)) ende(6);
|
||
|
||
//Zeichencodierung des Servers
|
||
$tmpcode = $db->getServerCode();
|
||
//Leider sind die Benennungen vom Server anders als von mb_detect_encoding
|
||
if ($tmpcode == "UTF8") {
|
||
define("ServerCode","UTF-8");
|
||
} else if ($tmpcode == "LATIN9") {
|
||
define("ServerCode","ISO-8859-15");
|
||
} else if ($tmpcode == "LATIN1") {
|
||
define("ServerCode","ISO-8859-1");
|
||
} else {
|
||
define("ServerCode",$tmpcode);
|
||
}
|
||
//Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
|
||
//DB und LxO müssen ja nicht auf der gleichen Maschiene sein.
|
||
if($tmpcode<>$db->getClientCode()) {
|
||
$rc = $db->setClientCode($tmpcode);
|
||
}
|
||
|
||
// Zeichenkodierung File
|
||
if ($_POST["encoding"] == "auto") {
|
||
define("Auto",true);
|
||
define("Translate",true);
|
||
} else {
|
||
define("Auto",false);
|
||
if ($_POST["encoding"] == ServerCode) {
|
||
define("Translate",false);
|
||
} else {
|
||
define("Translate",true);
|
||
define("FileCode",$_POST["encoding"]);
|
||
}
|
||
}
|
||
|
||
|
||
$f=fopen($dir.$file."_contact.csv","r");
|
||
$zeile=fgetcsv($f,2000,$trenner);
|
||
|
||
$first=true;
|
||
|
||
foreach ($zeile as $fld) {
|
||
$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
|
||
$in_fld[]=$fld;
|
||
if (substr($fld,0,2) == "x_") $kunde_fld[] = $fld;
|
||
}
|
||
$j=0;
|
||
$zeile=fgetcsv($f,2000,$trenner);
|
||
while (!feof($f)){
|
||
$i=-1;
|
||
$firma="";
|
||
$name=false;
|
||
$id=false;
|
||
$sql="insert into contacts ";
|
||
$keys="(";
|
||
$vals=" values (";
|
||
unset($extra);
|
||
$extra = array();
|
||
foreach($zeile as $data) {
|
||
$i++;
|
||
if (!in_array($in_fld[$i],$kunde_fld)) {
|
||
continue;
|
||
}
|
||
$data=addslashes(trim($data));
|
||
if ($in_fld[$i]=="firma" && $data) {
|
||
if (Translate) translate($data);
|
||
$data=suchFirma($file,$data);
|
||
if ($data) {
|
||
$id=$data["cp_cv_id"];
|
||
}
|
||
continue;
|
||
} else if ($in_fld[$i]=="firma") {
|
||
continue;
|
||
} ;
|
||
if ($in_fld[$i]=="cp_cv_id" && $data) {
|
||
$data=chkKdId($data);
|
||
if ($data) {
|
||
$id = $data;
|
||
};
|
||
continue;
|
||
} else if($in_fld[$i]=="cp_cv_id") {
|
||
continue;
|
||
}
|
||
if (substr($in_fld[$i],0,2)=="x_" && $data) {
|
||
$extra[substr($in_fld[$i],2)] = $data;
|
||
continue;
|
||
} else if ((substr($in_fld[$i],0,2)=="x_")) {
|
||
continue;
|
||
};
|
||
if ($in_fld[$i]==$file."number" && $data) {
|
||
if (!$id) {
|
||
$tmp=getFirma($data,$file);
|
||
if ($tmp) {
|
||
$id=$tmp;
|
||
}
|
||
}
|
||
continue;
|
||
} else if ($in_fld[$i]==$file."number") {
|
||
continue;
|
||
}
|
||
if ($in_fld[$i]=="cp_id" && $data) {
|
||
$tmp=chkContact($data);
|
||
if ($tmp) {
|
||
$keys.="cp_id,";
|
||
$vals.="$tmp,";
|
||
}
|
||
continue;
|
||
} else if ($in_fld[$i]=="cp_id") {
|
||
continue;
|
||
}
|
||
|
||
$keys.=$in_fld[$i].",";
|
||
|
||
if ($data==false or empty($data) or !$data) {
|
||
$vals.="null,";
|
||
} else {
|
||
|
||
if (Translate) translate($data);
|
||
|
||
/*if (in_array($in_fld[$i],array("cp_fax","cp_phone1","cp_phone2"))) {
|
||
$data=$prenumber.$data;
|
||
} else if ($in_fld[$i]=="cp_country" && $data) {
|
||
$data=mkland($data);
|
||
} */
|
||
if ($in_fld[$i]=="cp_name") $name=true;
|
||
$vals.="'".$data."',";
|
||
// bei jedem gefuellten Datenfeld erhoehen
|
||
$val_count++;
|
||
}
|
||
}
|
||
if (!$name) {
|
||
$zeile=fgetcsv($f,1200,$trenner);
|
||
continue;
|
||
}
|
||
if ($id) {
|
||
$vals.=$id.",";
|
||
$keys.="cp_cv_id,";
|
||
}
|
||
if ($keys<>"(" && $val_count>2) {
|
||
if ($test) {
|
||
if ($first) {
|
||
echo "<table border='1'>\n";
|
||
echo "<tr><th>".str_replace(",","</th><th>",substr($keys,1,-1))."</th></tr>\n";
|
||
$first=false;
|
||
};
|
||
$vals=str_replace("',","'</td><td>",substr($vals,9,-1));
|
||
echo "<tr><td>".str_replace("null,","null</td><td>",$vals)."</td></tr>\n";
|
||
flush();
|
||
} else {
|
||
$newID=uniqid (rand());
|
||
$now = date('Y-m-d H:i').":1.$j";
|
||
$sql.= $keys."mtime)";
|
||
$sql.= $vals."'$now')";
|
||
$rc=$db->query($sql);
|
||
if (!$rc) echo "Fehler: ".$sql."\n";
|
||
$rs = $db->getAll("select cp_id,cp_name from contacts where mtime = '$now'");
|
||
$cp_id = $rs[0]["cp_id"];
|
||
echo "(".$rs[0]["cp_name"].":$cp_id)".count($extra).";";
|
||
if (count($extra)>0 and $cp_id) {
|
||
foreach ($extra as $fld=>$val) {
|
||
$rc = insertExtra("P",$cp_id,$fld,$val);
|
||
}
|
||
}
|
||
}
|
||
$j++;
|
||
};
|
||
$zeile=fgetcsv($f,1200,$trenner);
|
||
}
|
||
fclose($f);
|
||
echo $j." $file importiert.\n";} else {
|
||
?>
|
||
<p class="listtop">Kontakt-Adressimport für die ERP</p>
|
||
<form name="import" method="post" enctype="multipart/form-data" action="contactB.php">
|
||
<input type="hidden" name="MAX_FILE_SIZE" value="3000000">
|
||
<table>
|
||
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
|
||
<tr><td>Zieltabelle</td><td><input type="radio" name="ziel" value="customer" checked>customer <input type="radio" name="ziel" value="vendor">vendor</td></tr>
|
||
<tr><td>Trennzeichen</td><td>
|
||
<input type="radio" name="trenner" value=";" checked>Semikolon
|
||
<input type="radio" name="trenner" value=",">Komma
|
||
<input type="radio" name="trenner" value="#9" checked>Tabulator
|
||
<input type="radio" name="trenner" value=" ">Leerzeichen
|
||
<input type="radio" name="trenner" value="other">
|
||
<input type="text" size="2" name="trennzeichen" value="">
|
||
</td></tr>
|
||
<!--tr><td>Telefonvorwahl</td><td><input type="text" size="4" maxlength="1" name="prenumber" value=""></td></tr-->
|
||
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
|
||
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
|
||
<tr><td>Verwendete<br />Zeichecodierung</td><td>
|
||
<select name="encoding">
|
||
<option value="auto">Automatisch (versuchen)</option>
|
||
<option value="UTF-8">UTF-8</option>
|
||
<option value="ISO-8859-1">ISO-8859-1</option>
|
||
<option value="ISO-8859-15">ISO-8859-15</option>
|
||
<option value="Windows-1252">Windows-1252</option>
|
||
<option value="ASCII">ASCII</option>
|
||
</select>
|
||
</td></tr>
|
||
<tr><td></td><td><input type="submit" name="ok" value="Import"></td></tr>
|
||
</table>
|
||
</form>
|
||
<?php }; ?>
|
lxo-import/customer.bsp | ||
---|---|---|
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
|
||
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 | ||
---|---|---|
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
|
||
;;Import Kunde;Verwaltung;Leiter;m;Dr.;Hans Heinrich;Import;;;;;;;;D;12345;Sonstwo;;;;
|
lxo-import/customer_shipto.bsp | ||
---|---|---|
firma;shiptoname;shiptodepartment_1;shiptodepartment_2;shiptostreet;shiptozipcode;shiptocity;shiptocountry;shiptocontact;shiptophone;shiptofax;shiptoemail;customernumber
|
||
Import Kunde;Import Kunde;Lagerhaus;;Bahnhofstr. 4;12345;Sonstwo;D;Hr. Hansen;0293948;lager@firma.false;
|
lxo-import/db.php | ||
---|---|---|
<?php
|
||
require_once "DB.php";
|
||
class myDB extends DB {
|
||
|
||
var $db = false;
|
||
var $rc = false;
|
||
var $showErr = false; // Browserausgabe
|
||
var $debug = false; // 1 = SQL-Ausgabe, 2 = zusätzlich Ergebnis
|
||
var $log = true; // Alle Abfragen mitloggen
|
||
var $path = "/tmp/";
|
||
var $lfh = false;
|
||
|
||
function dbFehler($sql,$err) {
|
||
$efh=fopen($this->path."lxcrm".date("w").".err","a");
|
||
fputs($efh,date("Y-m-d H:i:s ->"));
|
||
fputs($efh,$sql."\n");
|
||
fputs($efh,$err."\n");
|
||
fputs($efh,print_r($this->rc,true));
|
||
fputs($efh,"\n");
|
||
fclose($efh);
|
||
if ($this->showErr)
|
||
echo "</td></tr></table><font color='red'>$sql : $err</font><br>";
|
||
}
|
||
|
||
function showDebug($sql) {
|
||
echo $sql."<br>";
|
||
if ($this->debug==2) {
|
||
echo "<pre>";
|
||
print_r($this->rc);
|
||
echo "</pre>";
|
||
};
|
||
}
|
||
|
||
function writeLog($txt) {
|
||
if ($this->lfh===false)
|
||
$this->lfh=fopen($this->path."lxcrm".date("w").".log","a");
|
||
fputs($this->lfh,date("Y-m-d H:i:s ->"));
|
||
fputs($this->lfh,$txt."\n");
|
||
fputs($this->lfh,print_r($this->rc,true));
|
||
fputs($this->lfh,"\n");
|
||
}
|
||
|
||
function closeLogfile() {
|
||
fclose($this->lfh);
|
||
}
|
||
|
||
function myDB($host,$user,$pwd,$db,$port,$showErr=false) {
|
||
$dsn = array(
|
||
'phptype' => 'pgsql',
|
||
'username' => $user,
|
||
'password' => $pwd,
|
||
'hostspec' => $host,
|
||
'database' => $db,
|
||
'port' => $port
|
||
);
|
||
$this->showErr=$showErr;
|
||
$this->db=DB::connect($dsn);
|
||
if (!$this->db || DB::isError($this->db)) {
|
||
if ($this->log) $this->writeLog("Connect $dns");
|
||
$this->dbFehler("Connect ".print_r($dsn,true),$this->db->getMessage());
|
||
die ($this->db->getMessage());
|
||
}
|
||
if ($this->log) $this->writeLog("Connect: ok ");
|
||
return $this->db;
|
||
}
|
||
|
||
function query($sql) {
|
||
$this->rc=@$this->db->query($sql);
|
||
if ($this->debug) $this->showDebug($sql);
|
||
if ($this->log) $this->writeLog($sql);
|
||
if(DB::isError($this->rc)) {
|
||
$this->dbFehler($sql,$this->rc->getMessage());
|
||
$this->rollback();
|
||
return false;
|
||
} else {
|
||
return $this->rc;
|
||
}
|
||
}
|
||
|
||
function begin() {
|
||
$this->query("BEGIN");
|
||
}
|
||
function commit() {
|
||
$this->query("COMMIT");
|
||
}
|
||
function rollback() {
|
||
$this->query("ROLLBACK");
|
||
}
|
||
|
||
function getAll($sql) {
|
||
$this->rc=$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
|
||
if ($this->debug) $this->showDebug($sql);
|
||
if ($this->log) $this->writeLog($sql);
|
||
if(DB::isError($this->rc)) {
|
||
$this->dbFehler($sql,$this->rc->getMessage());
|
||
return false;
|
||
} else {
|
||
return $this->rc;
|
||
}
|
||
}
|
||
|
||
function saveData($txt) {
|
||
if (get_magic_quotes_gpc()) {
|
||
return $txt;
|
||
} else {
|
||
return DB::quoteSmart($string);
|
||
}
|
||
}
|
||
|
||
function execute($statement, $data){
|
||
$sth = $this->db->prepare($statement); //Prepare
|
||
/*if (PEAR::isError($sth)) {
|
||
$this->dbFehler($statement,$sth->getMessage());
|
||
$this->rollback();
|
||
return false;
|
||
}*/
|
||
$rc = $this->db->execute($sth,$data);
|
||
if(PEAR::isError($rc)) {
|
||
$this->dbFehler(print_r($data,true),$rc->getMessage()."\n".print_r($rc,true));
|
||
$this->rollback();
|
||
return false;
|
||
}
|
||
$this->db->commit();
|
||
return true;
|
||
}
|
||
|
||
function chkcol($tbl) {
|
||
// gibt es die Spalte import schon?
|
||
$rc=$this->db->query("select import from $tbl limit 1");
|
||
if(DB::isError($rc)) {
|
||
$rc=$this->db->query("alter table $tbl add column import int4");
|
||
if(DB::isError($rc)) { return false; }
|
||
else { return true; }
|
||
} else { return true; };
|
||
}
|
||
|
||
/**
|
||
* Zeichekodirung der DB ermitteln
|
||
*
|
||
* @return String
|
||
*/
|
||
function getServerCode() {
|
||
$sql="SHOW server_encoding";
|
||
$rs = $this->getAll($sql);
|
||
return $rs[0]["server_encoding"];
|
||
}
|
||
function getClientCode() {
|
||
$sql="SHOW client_encoding";
|
||
$rs = $this->getAll($sql);
|
||
return $rs[0]["client_encoding"];
|
||
}
|
||
function setClientCode($encoding) {
|
||
$sql="SET client_encoding = '$encoding'";
|
||
$rc = $this->query($sql);
|
||
return $rc;
|
||
}
|
||
|
||
}
|
||
?>
|
lxo-import/import_lib.php | ||
---|---|---|
<?php
|
||
/*
|
||
Funktionsbibliothek f?r den Datenimport in Lx-Office ERP
|
||
|
||
Copyright (C) 2005
|
||
Author: Holger Lindemann
|
||
Email: hli@lx-system.de
|
||
Web: http://lx-system.de
|
||
|
||
*/
|
||
|
||
require_once "db.php";
|
||
|
||
$address = array(
|
||
"name" => "Firmenname",
|
||
"department_1" => "Abteilung",
|
||
"department_2" => "Abteilung",
|
||
"street" => "Strasse + Nr",
|
||
"zipcode" => "Plz",
|
||
"city" => "Ort",
|
||
"country" => "Land",
|
||
"contact" => "Ansprechpartner",
|
||
"phone" => "Telefon",
|
||
"fax" => "Fax",
|
||
"homepage" => "Homepage",
|
||
"email" => "eMail",
|
||
"notes" => "Bemerkungen",
|
||
"discount" => "Rabatt (nn.nn)",
|
||
"taxincluded" => "incl. Steuer? (t/f)",
|
||
"terms" => "Zahlungsziel (Tage)",
|
||
"customernumber" => "Kundennummer",
|
||
"vendornumber" => "Lieferantennummer",
|
||
"taxnumber" => "Steuernummer",
|
||
"ustid" => "Umsatzsteuer-ID",
|
||
"account_number" => "Kontonummer",
|
||
"bank_code" => "Bankleitzahl",
|
||
"bank" => "Bankname",
|
||
"branche" => "Branche",
|
||
"business_id" => "BranchenID",
|
||
"salesman_id" => "Verk?uferID",
|
||
//"language" => "Sprache (de,en,fr)",
|
||
"sw" => "Stichwort",
|
||
"creditlimit" => "Kreditlimit (nnnnnn.nn)"); /*,
|
||
"hierarchie" => "Hierarchie",
|
||
"potenzial" => "Potenzial",
|
||
"ar" => "Debitorenkonto",
|
||
"ap" => "Kreditorenkonto",
|
||
"matchcode" => "Matchcode",
|
||
"customernumber2" => "Kundennummer 2");
|
||
Kundenspezifisch */
|
||
|
||
$shiptos = array(
|
||
"firma" => "Firmenname",
|
||
"shiptoname" => "Liefername",
|
||
"shiptodepartment_1" => "Abteilung",
|
||
"shiptodepartment_2" => "Abteilung",
|
||
"shiptostreet" => "Strasse + Nr",
|
||
"shiptozipcode" => "Plz",
|
||
"shiptocity" => "Ort",
|
||
"shiptocountry" => "Land",
|
||
"shiptocontact" => "Ansprechpartner",
|
||
"shiptophone" => "Telefon",
|
||
"shiptofax" => "Fax",
|
||
"shiptoemail" => "eMail",
|
||
"customernumber" => "Kundennummer",
|
||
"vendornumber" => "Lieferantennummer");
|
||
|
||
$parts = array(
|
||
"partnumber" => "Artikelnummer",
|
||
"ean" => "Barcode",
|
||
"description" => "Artikeltext",
|
||
"unit" => "Einheit",
|
||
"weight" => "Gewicht in Benutzerdefinition",
|
||
"notes" => "Beschreibung",
|
||
"notes1" => "Beschreibung",
|
||
"formel" => "Formel",
|
||
"makemodel" => "Hersteller",
|
||
"model" => "Modellbezeichnung",
|
||
"image" => "Pfad/Dateiname",
|
||
"drawing" => "Pfad/Dateiname",
|
||
"microfiche" => "Pfad/Dateiname",
|
||
"listprice" => "Listenpreis",
|
||
"sellprice" => "Verkaufspreis",
|
||
"lastcost" => "letzter EK",
|
||
"art" => "Ware/Dienstleistung (*/d), muß vor den Konten kommen",
|
||
"inventory_accno" => "Bestandskonto",
|
||
"income_accno" => "Erlöskonto",
|
||
"expense_accno" => "Konto Umsatzkosten",
|
||
"obsolete" => "Gesperrt (Y/N)",
|
||
"lastcost" => "letzer EK-Preis",
|
||
"rop" => "Mindestbestand",
|
||
"shop" => "Shopartikel (Y/N)",
|
||
"assembly" => "Stückliste (Y/N); wird noch nicht unterstützt",
|
||
"partsgroup" => "Warengruppenbezeichnung",
|
||
"partsgroup1" => "2.Warengruppenbezeichnung",
|
||
"partsgroup2" => "3.Warengruppenbezeichnung",
|
||
"partsgroup3" => "4.Warengruppenbezeichnung",
|
||
"partsgroup4" => "5.Warengruppenbezeichnung",
|
||
"shop" => "Shopexport vorghesehen",
|
||
);
|
||
|
||
$contactscrm = array(
|
||
"customernumber" => "Kundennummer",
|
||
"vendornumber" => "Lieferantennummer",
|
||
"cp_cv_id" => "FirmenID in der db",
|
||
"firma" => "Firmenname",
|
||
"cp_abteilung" => "Abteilung",
|
||
"cp_position" => "Position/Hierarchie",
|
||
"cp_gender" => "Geschlecht (m/f)",
|
||
"cp_title" => "Titel",
|
||
"cp_givenname" => "Vorname",
|
||
"cp_name" => "Nachname",
|
||
"cp_email" => "eMail",
|
||
"cp_phone1" => "Telefon 1",
|
||
"cp_phone2" => "Telefon 2",
|
||
"cp_mobile1" => "Mobiltelefon 1",
|
||
"cp_mobile2" => "Mobiltelefon 2",
|
||
"cp_homepage" => "Homepage",
|
||
"cp_street" => "Strasse",
|
||
"cp_country" => "Land",
|
||
"cp_zipcode" => "PLZ",
|
||
"cp_city" => "Ort",
|
||
"cp_privatphone" => "Privattelefon",
|
||
"cp_privatemail" => "private eMail",
|
||
"cp_notes" => "Bemerkungen",
|
||
"cp_stichwort1" => "Stichwort(e)",
|
||
"cp_id" => "Kontakt ID"
|
||
);
|
||
|
||
$contacts = array(
|
||
"customernumber" => "Kundennummer",
|
||
"vendornumber" => "Lieferantennummer",
|
||
"cp_cv_id" => "FirmenID in der db",
|
||
"firma" => "Firmenname",
|
||
"cp_greeting" => "Anrede",
|
||
"cp_title" => "Titel",
|
||
"cp_givenname" => "Vorname",
|
||
"cp_greeting" => "Anrede",
|
||
"cp_name" => "Nachname",
|
||
"cp_email" => "eMail",
|
||
"cp_phone1" => "Telefon 1",
|
||
"cp_phone2" => "Telefon 2",
|
||
"cp_mobile1" => "Mobiltelefon 1",
|
||
"cp_mobile2" => "Mobiltelefon 2",
|
||
"cp_privatphone" => "Privattelefon",
|
||
"cp_privatemail" => "private eMail",
|
||
"cp_homepage" => "Homepage",
|
||
"cp_id" => "Kontakt ID"
|
||
);
|
||
|
||
function checkCRM() {
|
||
global $db;
|
||
$sql="select * from crm";
|
||
$rs=$db->getAll($sql);
|
||
if ($rs) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function chkUsr($usr) {
|
||
// ist es ein g?ltiger ERP-Benutzer? Er mu? mindestens 1 x angemeldet gewesen sein.
|
||
global $db;
|
||
$sql="select * from employee where login = '$usr'";
|
||
$rs=$db->getAll($sql);
|
||
if ($rs[0]["id"]) { return $rs[0]["id"]; }
|
||
else { return false; };
|
||
}
|
||
|
||
function getKdId() {
|
||
// die n?chste freie Kunden-/Lieferantennummer holen
|
||
global $db,$file,$test;
|
||
if ($test) { return "#####"; }
|
||
$sql1="select * from defaults";
|
||
$sql2="update defaults set ".$file."number = '%s'";
|
||
$db->begin();
|
||
$rs=$db->getAll($sql1);
|
||
$nr=$rs[0][$file."number"];
|
||
preg_match("/^([^0-9]*)([0-9]+)/",$nr,$hits);
|
||
if ($hits[2]) { $nr=$hits[2]+1; $nnr=$hits[1].$nr; }
|
||
else { $nr=$hits[1]+1; $nnr=$nr; };
|
||
$rc=$db->query(sprintf($sql2,$nnr));
|
||
if ($rc) {
|
||
$db->commit();
|
||
return $nnr;
|
||
} else {
|
||
$db->rollback();
|
||
return false;
|
||
};
|
||
}
|
||
|
||
function chkKdId($data) {
|
||
// gibt es die Nummer schon?
|
||
global $db,$file,$test;
|
||
$sql="select * from $file where ".$file."number = '$data'";
|
||
$rs=$db->getAll($sql);
|
||
if ($rs[0][$file."number"]==$data) {
|
||
// ja, eine neue holen
|
||
return getKdId();
|
||
} else {
|
||
return $data;
|
||
}
|
||
}
|
||
|
||
function chkContact($id) {
|
||
global $db;
|
||
$sql="select * from contact where cp_id = $id";
|
||
$rs=$db->getAll($sql);
|
||
if ($rs[0]["cp_id"]==$id) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function getKdRefId($data) {
|
||
// gibt es die Nummer schon?
|
||
global $db,$file,$test;
|
||
if (empty($data) or !$data) {
|
||
return false;
|
||
}
|
||
$sql="select * from $file where ".$file."number = '$data'";
|
||
$rs=$db->getAll($sql);
|
||
return $rs[0]["id"];
|
||
}
|
||
/**
|
||
* TODO: short description.
|
||
*
|
||
* @param mixed $tab
|
||
* @param object $own
|
||
* @param mixed $fld
|
||
* @param mixed $val
|
||
*
|
||
* @return TODO
|
||
*/
|
||
function insertExtra($tab,$own,$fld,$val) {
|
||
global $db;
|
||
$sql = "insert into extra_felder (fkey,fval,tab,owner) ";
|
||
$sql.= "values ('$fld','$val','$tab','$own')";
|
||
$rc = $db->query($sql);
|
||
return $rc;
|
||
}
|
||
function suchFirma($tab,$data) {
|
||
// gibt die Firma ?
|
||
global $db;
|
||
if (empty($data) or !$data) {
|
||
return false;
|
||
}
|
||
$data=strtoupper($data);
|
||
$sql="select * from $tab where upper(name) like '%$data%'";
|
||
$rs=$db->getAll($sql);
|
||
if (!$rs) {
|
||
$org=$data;
|
||
while(strpos($data," ")>0) {
|
||
$data=str_replace(" "," ",$data);
|
||
}
|
||
$data=preg_replace("/[^A-Z0-9]/ ",".*",trim($data));
|
||
$sql="select * from $tab where upper(name) ~ '$data'";
|
||
$rs=$db->getAll($sql);
|
||
if (count($rs)==1) {
|
||
return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
|
||
}
|
||
return false;
|
||
} else {
|
||
return array("cp_cv_id"=>$rs[0]["id"],"Firma"=>$rs[0]["name"]);
|
||
}
|
||
}
|
||
|
||
|
||
//Suche Nach Kunden-/Lieferantenummer
|
||
function getFirma($nummer,$tabelle) {
|
||
global $db;
|
||
$nummer=strtoupper($nummer);
|
||
$sql="select id from $tabelle where upper(".$tabelle."number) = '$nummer'";
|
||
$rs=$db->getAll($sql);
|
||
if (!$rs) {
|
||
$nr=str_replace(" ","%",$nummer);
|
||
$sql="select id,".$tabelle."number from $tabelle where upper(".$tabelle."number) like '$nr'";
|
||
$rs=$db->getAll($sql);
|
||
if ($rs) {
|
||
$nr=str_replace(" ","",$nummer);
|
||
foreach ($rs as $row) {
|
||
$tmp=str_replace(" ","",$row[$tabelle."number"]);
|
||
if ($tmp==$nr) return $row["id"];
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
return $rs[0]["id"];
|
||
}
|
||
}
|
||
|
||
function getAllBG($db) {
|
||
$sql = "select * from buchungsgruppen order by description";
|
||
$rs=$db->getAll($sql);
|
||
return $rs;
|
||
}
|
||
|
||
function getAllUnits($db,$type) {
|
||
$sql = "select * from units where type = '$type' order by sortkey";
|
||
$rs=$db->getAll($sql);
|
||
return $rs;
|
||
}
|
||
|
||
function anmelden($login=false,$pwd=false) {
|
||
ini_set("gc_maxlifetime","3600");
|
||
if (file_exists("../config/lx_office.conf")) {
|
||
$lxo = fopen("../config/lx_office.conf","r");
|
||
} else if (file_exists("../config/lx_office.conf.default")) {
|
||
$lxo = fopen("../config/lx_office.conf.default","r");
|
||
} else {
|
||
return false;
|
||
}
|
||
$dbsec = false;
|
||
$tmp = fgets($lxo,512);
|
||
while (!feof($lxo)) {
|
||
if (preg_match("/^[\s]*#/",$tmp)) {
|
||
$tmp = fgets($lxo,512);
|
||
continue;
|
||
}
|
||
if ($dbsec) {
|
||
preg_match("/db[ ]*= (.+)/",$tmp,$hits);
|
||
if ($hits[1]) $dbname=$hits[1];
|
||
preg_match("/password[ ]*= (.+)/",$tmp,$hits);
|
||
if ($hits[1]) $dbpasswd=$hits[1];
|
||
preg_match("/user[ ]*= (.+)/",$tmp,$hits);
|
||
if ($hits[1]) $dbuser=$hits[1];
|
||
preg_match("/host[ ]*= (.+)/",$tmp,$hits);
|
||
if ($hits[1]) $dbhost=($hits[1])?$hits[1]:"localhost";
|
||
preg_match("/port[ ]*= (.+)/",$tmp,$hits);
|
||
if ($hits[1]) $dbport=($hits[1])?$hits[1]:"5432";
|
||
if (preg_match("/\[[a-z]+/",$tmp)) break;
|
||
$tmp = fgets($lxo,512);
|
||
continue;
|
||
}
|
||
preg_match("/[ ]*cookie_name[ ]*=[ ]*(.+)/",$tmp,$hits);
|
||
if ($hits[1]) $cookiename=$hits[1];
|
||
if (preg_match("!\[authentication/database\]!",$tmp)) $dbsec = true;
|
||
$tmp = fgets($lxo,512);
|
||
}
|
||
if (!$cookiename) $cookiename='lx_office_erp_session_id';
|
||
$cookie=$_COOKIE[$cookiename];
|
||
if ($login) {
|
||
$auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,false,$login,$pwd);
|
||
} else {
|
||
$cookie=$_COOKIE[$cookiename];
|
||
if (!$cookie) header("location: ups.html");
|
||
$auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,false,false);
|
||
};
|
||
if (!$auth) { return false; };
|
||
$_SESSION["sessid"]=$cookie;
|
||
$_SESSION["cookie"]=$cookiename;
|
||
$_SESSION["employee"]=$auth["login"];
|
||
$_SESSION["mansel"]=$auth["dbname"];
|
||
$_SESSION["dbname"]=$auth["dbname"];
|
||
$_SESSION["dbhost"]=(!$auth["dbhost"])?"localhost":$auth["dbhost"];
|
||
$_SESSION["dbport"]=(!$auth["dbport"])?"5432":$auth["dbport"];
|
||
$_SESSION["dbuser"]=$auth["dbuser"];
|
||
$_SESSION["dbpasswd"]=$auth["dbpasswd"];
|
||
$_SESSION["db"]=new myDB($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpasswd"],$_SESSION["dbname"],$_SESSION["dbport"],$showErr);
|
||
$_SESSION["authcookie"]=$authcookie;
|
||
$sql="select * from employee where login='".$auth["login"]."'";
|
||
$rs=$_SESSION["db"]->getAll($sql);
|
||
if(!$rs) {
|
||
return false;
|
||
} else {
|
||
if ($rs) {
|
||
$tmp=$rs[0];
|
||
$_SESSION["termbegin"]=(($tmp["termbegin"]>=0)?$tmp["termbegin"]:8);
|
||
$_SESSION["termend"]=($tmp["termend"])?$tmp["termend"]:19;
|
||
$_SESSION["Pre"]=$tmp["pre"];
|
||
$_SESSION["interv"]=($tmp["interv"]>0)?$tmp["interv"]:60;
|
||
$_SESSION["loginCRM"]=$tmp["id"];
|
||
$_SESSION["lang"]=$tmp["countrycode"]; //"de";
|
||
$_SESSION["kdview"]=$tmp["kdview"];
|
||
$sql="select * from defaults";
|
||
$rs=$_SESSION["db"]->getAll($sql);
|
||
$_SESSION["ERPver"]=$rs[0]["version"];
|
||
return true;$_SESSION;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,$login,$pwd) {
|
||
$db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true);
|
||
if ($cookie) {
|
||
$sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on ";
|
||
$sql.="('--- ' || u.login || E'\\n')=sc.sess_value left join auth.session s on s.id=sc.session_id ";
|
||
$sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc";
|
||
$rs=$db->getAll($sql,"authuser_1");
|
||
if (!$rs) return false;
|
||
$stmp="";
|
||
if (count($rs)>1) {
|
||
foreach($rs as $row) {
|
||
$stmp.=$row["session_id"].",";
|
||
}
|
||
$sql1="delete from session where id in (".substr($stmp,-1).")";
|
||
$sql2="delete from session_content where session_id in (".substr($stmp,-1).")";
|
||
$db->query($sql1,"authuser_A");
|
||
$db->query($sql2,"authuser_B");
|
||
header("location:../login.pl?action=logout");
|
||
};
|
||
$sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'";
|
||
$db->query($sql,"authuser_3");
|
||
$sql="select * from auth.user where id=".$rs[0]["id"];
|
||
} else {
|
||
$sql = "select * from auth.user where login = '$login' and password = '$pwd'";
|
||
}
|
||
$rs1=$db->getAll($sql,"authuser_1");
|
||
if (!$rs1) return false;
|
||
$auth=array();
|
||
$auth["login"]=$rs1[0]["login"];
|
||
$sql="select * from auth.user_config where user_id=".$rs1[0]["id"];
|
||
$rs1=$db->getAll($sql,"authuser_2");
|
||
$keys=array("dbname","dbpasswd","dbhost","dbport","dbuser");
|
||
foreach ($rs1 as $row) {
|
||
if (in_array($row["cfg_key"],$keys)) {
|
||
$auth[$row["cfg_key"]]=$row["cfg_value"];
|
||
}
|
||
}
|
||
return $auth;
|
||
}
|
||
|
||
/**
|
||
* Zeichencode ?bersetzen
|
||
*
|
||
* @param String $txt
|
||
*/
|
||
function translate(&$txt) {
|
||
if (Auto) {
|
||
$encoding = mb_detect_encoding($data,"UTF-8,ISO-8859-1,ISO-8859-15,Windows-1252,ASCII");
|
||
$txt = iconv("$encoding",ServerCode."//TRANSLIT",$txt);
|
||
//$txt = mb_convert_encoding($txt, ServerCode,"$encoding");
|
||
} else {
|
||
$txt = iconv(FileCode,ServerCode."//TRANSLIT",$txt);
|
||
//$txt = mb_convert_encoding($txt, ServerCode,FileCode);
|
||
}
|
||
}
|
||
|
||
?>
|
lxo-import/parts.bsp | ||
---|---|---|
"partnumber" "ean" "description" "unit" "weight" "notes" "makemodel" "model" "image" "sellprice" "lastcost" "partsgroup" "partsgroup1" "partsgroup2" "partsgroup3" "rop" "partsgroup4" "income_accno" "expense_accno" "microfiche" "art"
|
||
"TI12346" 92384754671 "Importartikel 1" "Stck" 2 "Die Beschreibung zum Artikel" "Lx-System" "LX123" 10 6 "Hardware" "Test" 1.10 184 37 "Mfiche 1" "W"
|
||
"TI12345" 92384754672 "Importartikel 2" 3,1 "Die Beschreibung zum Artikel" "Lx-System" "LX124" 13 8,1 "Hardware" "Test" 184 37 "y" "W"
|
||
"TD2345" "Import Diestleistung" "Std" 125 184 37 "D"
|
lxo-import/partsB.php | ||
---|---|---|
<?php session_start(); ?>
|
||
<html>
|
||
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet">
|
||
<body>
|
||
<?php
|
||
/*
|
||
Warenimport mit Browser nach Lx-Office ERP
|
||
Henry Margies <h.margies@maxina.de>
|
||
Holger Lindemann <hli@lx-system.de>
|
||
*/
|
||
|
||
$dir="../users/";
|
||
$gz_bin = "/bin/gzip -df ";
|
||
$zip_bin = "/usr/bin/unzip -o -d ".$dir;
|
||
|
||
function ende($txt) {
|
||
echo "Abbruch: $txt<br>";
|
||
exit(1);
|
||
}
|
||
|
||
if (!$_SESSION["db"]) {
|
||
$conffile="../config/lx_office.conf";
|
||
if (!is_file($conffile)) {
|
||
ende("lx_office.conf nicht gefunden oder kein Leserecht.");
|
||
}
|
||
}
|
||
require ("import_lib.php");
|
||
|
||
if ($_GET["login"]) {
|
||
$db = anmelden($_GET["login"],$_GET["passwd"]);
|
||
} else {
|
||
$db = anmelden();
|
||
}
|
||
//if (!$_SESSION["db"]) ende("Anmeldung fehlgeschlagen.");
|
||
if (!$db) ende("Anmeldung fehlgeschlagen.");
|
||
|
||
/* get DB instance */
|
||
$db=$_SESSION["db"]; //new myDB($login);
|
||
/* just display page or do real import? */
|
||
if ($_POST["ok"] || $_GET["cron"]=="1") {
|
||
|
||
require ("parts_import.php");
|
||
//Zeichencodierung des Servers
|
||
$tmpcode = $db->getServerCode();
|
||
//Leider sind die Benennungen vom Server anders als von mb_detect_encoding
|
||
if ($tmpcode == "UTF8") {
|
||
define("ServerCode","UTF-8");
|
||
} else if ($tmpcode == "LATIN9") {
|
||
define("ServerCode","ISO-8859-15");
|
||
} else if ($tmpcode == "LATIN1") {
|
||
define("ServerCode","ISO-8859-1");
|
||
} else {
|
||
define("ServerCode",$tmpcode);
|
||
}
|
||
//Zeichensatz sollte gleich sein, sonst ist die Datenkonvertierung nutzlos
|
||
//DB und LxO müssen ja nicht auf der gleichen Maschine sein.
|
||
if($tmpcode<>$db->getClientCode()) {
|
||
$rc = $db->setClientCode($tmpcode);
|
||
}
|
||
|
Auch abrufbar als: Unified diff
PHP-basierten CSV-Import-Code entfernt