From 3c2ec7dc1ba31b9fffbe7e777c60af6a85f3ba2e Mon Sep 17 00:00:00 2001 From: Holger Lindemann Date: Thu, 14 Oct 2010 14:29:11 +0200 Subject: [PATCH] =?utf8?q?Automatisierter=20Import=20per=20Cronjob=20m?= =?utf8?q?=C3=B6glich.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit z.B. mit: wget http://localhost/lxo-fcgi/lxo-import/partsB.php?cron=1&login=demo&passwd=ded5ht0W28M8U oder w3m -dump http://localhost/lxo-fcgi/lxo-import/partsB.php?cron=1&login=demo&passwd=ded5ht0W28M8U Passwort ist das Perl UU-endodet Passwort wie in der auth.user --- lxo-import/import_lib.php | 61 +++++++++++++---------- lxo-import/partsB.php | 98 +++++++++++++++++++++++-------------- lxo-import/parts_import.php | 19 ++++++- 3 files changed, 113 insertions(+), 65 deletions(-) diff --git a/lxo-import/import_lib.php b/lxo-import/import_lib.php index 238eb45c2..36cf30f14 100644 --- a/lxo-import/import_lib.php +++ b/lxo-import/import_lib.php @@ -279,13 +279,14 @@ function getAllBG($db) { $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() { +function anmelden($login=false,$pwd=false) { ini_set("gc_maxlifetime","3600"); $tmp = @file_get_contents("../config/authentication.pl"); preg_match("/'db'[ ]*=> '(.+)'/",$tmp,$hits); @@ -301,9 +302,13 @@ function anmelden() { preg_match("/[ ]*\\\$self->\{cookie_name\}[ ]*=[ ]*'(.+)'/",$tmp,$hits); $cookiename=$hits[1]; if (!$cookiename) $cookiename='lx_office_erp_session_id'; - $cookie=$_COOKIE[$cookiename]; - if (!$cookie) header("location: ups.html"); - $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie); + 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; @@ -333,38 +338,43 @@ function anmelden() { $sql="select * from defaults"; $rs=$_SESSION["db"]->getAll($sql); $_SESSION["ERPver"]=$rs[0]["version"]; - return true; + return true;$_SESSION; } else { return false; } } } -function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie) { +function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,$login,$pwd) { $db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true); - $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on "; - $sql.="u.login=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) { - header("location:../login.pl?action=logout"); - /*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"); - $sql3="insert into session ";*/ + if ($cookie) { + $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on "; + $sql.="u.login=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'"; } - $sql="select * from auth.user where id=".$rs[0]["id"]; $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=".$rs[0]["id"]; + $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) { @@ -372,10 +382,9 @@ function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie) { $auth[$row["cfg_key"]]=$row["cfg_value"]; } } - $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"); return $auth; } + /** * Zeichencode übersetzen * diff --git a/lxo-import/partsB.php b/lxo-import/partsB.php index 8a7563df6..1d280d863 100644 --- a/lxo-import/partsB.php +++ b/lxo-import/partsB.php @@ -1,3 +1,4 @@ + @@ -25,13 +26,18 @@ if (!$_SESSION["db"]) { } require ("import_lib.php"); -if (!anmelden()) ende("Anmeldung fehlgeschlagen."); +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"]) { +if ($_POST["ok"] || $_GET["cron"]=="1") { require ("parts_import.php"); //Zeichencodierung des Servers @@ -92,37 +98,60 @@ if ($_POST["ok"]) { clearstatcache (); - $test = $_POST["test"]; - $lager = $_POST["lager"]; - $TextUpd = $_POST["TextUpd"]; - $trenner = ($_POST["trenner"])?$_POST["trenner"]:","; - $trennzeichen = ($_POST["trennzeichen"])?$_POST["trennzeichen"]:""; - $precision = $_POST["precision"]; - $quotation = $_POST["quotation"]; - $quottype = $_POST["quottype"]; $file = "parts"; - /* no data? */ - if (empty($_FILES["Datei"]["name"])) - ende ("Kein Datenfile angegeben"); - - /* copy file */ - if (substr($_FILES["Datei"]["name"],-2)=="gz") { - if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv.gz")) { - echo $gz_bin.$dir.$file.".csv.gz"; + if ($_GET["cron"]==1) { + $Cron = True; + if (file_exists($dir.$file.".zip")) { + exec ($zip_bin.$dir.$file.".zip"); + } else if (file_exists($dir.$file.".gz")) { exec ($gz_bin.$dir.$file.".csv.gz"); - } else { - ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); - }; - } else if (substr($_FILES["Datei"]["name"],-3)=="zip") { - if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".zip")) { - exec ($zip_bin.$dir.$file.".zip"); - } else { + } else if (!file_exists($dir.$file.".csv")) { + ende($dir.$file.".csv nicht gefunden"); + } + $_POST["trenner"] = "#9"; // Tabulator + $_POST["trennzeichen"] = ";"; // Anderes Trennzeichen + $_POST["dimensionunit"] = "Stck"; // Artikeleinheit + $_POST["serviceunit"] = "Std"; // Dienstleistungseinheit + $_POST["bugru"] = "1600"; // Std-Bugru + $_POST["bugrufix"] = "2"; // Nur wenn keine Passende angegeben + $_POST["shop"] = "f"; // Shopartikel + $_POST["show"] = ""; // Kontrollausgabe + $_POST["test"] = ""; // Testlauf == 1 + $_POST["lager"] = ""; // Nicht gebraucht + $_POST["lagerplatz"] = ""; + $_POST["precision"] = "2"; // Runden auf nn Stellen + $_POST["quotation"] = ""; // Preisaufschlag + $_POST["quottype"] = "P"; // Prozent? + $_POST["wgtrenner"] = "!"; // Trennzeichen der Warengruppen + $_POST["TextUpd"] = "1"; // Textupdate durchführen + $_POST["update"] = "U"; // Bei vorhandenen Nummer updaten + $_POST["ware"] = "W"; // Ist ein Artikel + $_POST["encoding"] = ""; + } else { + + /* no data? */ + if (empty($_FILES["Datei"]["name"])) + ende ("Kein Datenfile angegeben"); + + /* copy file */ + if (substr($_FILES["Datei"]["name"],-2)=="gz") { + if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv.gz")) { + echo $gz_bin.$dir.$file.".csv.gz"; + exec ($gz_bin.$dir.$file.".csv.gz"); + } else { + ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); + }; + } else if (substr($_FILES["Datei"]["name"],-3)=="zip") { + if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".zip")) { + exec ($zip_bin.$dir.$file.".zip"); + } else { + ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); + }; + } else if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) { ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); - }; - } else if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) { - ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); - }; + }; + } /* check if file is really there */ if (!file_exists($dir.$file.'.csv') or filesize($dir.$file.'.csv')==0) @@ -132,15 +161,8 @@ if ($_POST["ok"]) { if (!$db->chkcol($file)) ende("Importspalte konnte nicht angelegt werden"); - /* first check all elements */ - $_test=$_POST; - $_test["precision"]=-1; - $_test["quotation"]=0; - $_test["lager"]=$_POST["lager"]; - $_test["lagerplatz"]=$_POST["lagerplatz"]; - /* just print data or insert it, if test is false */ - import_parts($db, $dir.$file, $trenner, $trennzeichen, $parts, FALSE, !$test, $_POST["show"],$_POST); + import_parts($_SESSION["db"], $dir.$file, $parts, FALSE, $_POST); } else { $bugrus=getAllBG($db); diff --git a/lxo-import/parts_import.php b/lxo-import/parts_import.php index 4159eff29..0db931230 100644 --- a/lxo-import/parts_import.php +++ b/lxo-import/parts_import.php @@ -226,7 +226,24 @@ function insPrices($db,$pid,$prices) { return true; } -function import_parts($db, $file, $trenner, $trennzeichen, $fields, $check, $insert, $show ,$maske) { +/** + * TODO: short description. + * + * @param double $db + * @param mixed $file + * @param mixed $fields + * @param mixed $check + * @param int $insert + * @param string $show + * @param mixed $maske + * + * @return TODO + */ +function import_parts($db, $file, $fields, $check, $maske) { + $insert = !$maske["test"]; + $show = $maske["show"]; + $trennzeichen = ($maske["trennzeichen"])?$maske["trennzeichen"]:""; + $trenner = ($maske["trenner"])?$maske["trenner"]:","; $precision=$maske["precision"]; $quotation=$maske["quotation"]; $quottype=$maske["quottype"]; -- 2.20.1