Revision 3c2ec7dc
Von Holger Lindemann vor etwa 14 Jahren hinzugefügt
lxo-import/import_lib.php | ||
---|---|---|
279 | 279 |
$rs=$db->getAll($sql); |
280 | 280 |
return $rs; |
281 | 281 |
} |
282 |
|
|
282 | 283 |
function getAllUnits($db,$type) { |
283 | 284 |
$sql = "select * from units where type = '$type' order by sortkey"; |
284 | 285 |
$rs=$db->getAll($sql); |
285 | 286 |
return $rs; |
286 | 287 |
} |
287 | 288 |
|
288 |
function anmelden() { |
|
289 |
function anmelden($login=false,$pwd=false) {
|
|
289 | 290 |
ini_set("gc_maxlifetime","3600"); |
290 | 291 |
$tmp = @file_get_contents("../config/authentication.pl"); |
291 | 292 |
preg_match("/'db'[ ]*=> '(.+)'/",$tmp,$hits); |
... | ... | |
301 | 302 |
preg_match("/[ ]*\\\$self->\{cookie_name\}[ ]*=[ ]*'(.+)'/",$tmp,$hits); |
302 | 303 |
$cookiename=$hits[1]; |
303 | 304 |
if (!$cookiename) $cookiename='lx_office_erp_session_id'; |
304 |
$cookie=$_COOKIE[$cookiename]; |
|
305 |
if (!$cookie) header("location: ups.html"); |
|
306 |
$auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie); |
|
305 |
if ($login) { |
|
306 |
$auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,false,$login,$pwd); |
|
307 |
} else { |
|
308 |
$cookie=$_COOKIE[$cookiename]; |
|
309 |
if (!$cookie) header("location: ups.html"); |
|
310 |
$auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,false,false); |
|
311 |
}; |
|
307 | 312 |
if (!$auth) { return false; }; |
308 | 313 |
$_SESSION["sessid"]=$cookie; |
309 | 314 |
$_SESSION["cookie"]=$cookiename; |
... | ... | |
333 | 338 |
$sql="select * from defaults"; |
334 | 339 |
$rs=$_SESSION["db"]->getAll($sql); |
335 | 340 |
$_SESSION["ERPver"]=$rs[0]["version"]; |
336 |
return true; |
|
341 |
return true;$_SESSION;
|
|
337 | 342 |
} else { |
338 | 343 |
return false; |
339 | 344 |
} |
340 | 345 |
} |
341 | 346 |
} |
342 | 347 |
|
343 |
function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie) { |
|
348 |
function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie,$login,$pwd) {
|
|
344 | 349 |
$db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true); |
345 |
$sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on "; |
|
346 |
$sql.="u.login=sc.sess_value left join auth.session s on s.id=sc.session_id "; |
|
347 |
$sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc"; |
|
348 |
$rs=$db->getAll($sql,"authuser_1"); |
|
349 |
if (!$rs) return false; |
|
350 |
$stmp=""; |
|
351 |
if (count($rs)>1) { |
|
352 |
header("location:../login.pl?action=logout"); |
|
353 |
/*foreach($rs as $row) { |
|
354 |
$stmp.=$row["session_id"].","; |
|
355 |
} |
|
356 |
$sql1="delete from session where id in (".substr($stmp,-1).")"; |
|
357 |
$sql2="delete from session_content where session_id in (".substr($stmp,-1).")"; |
|
358 |
$db->query($sql1,"authuser_A"); |
|
359 |
$db->query($sql2,"authuser_B"); |
|
360 |
$sql3="insert into session ";*/ |
|
350 |
if ($cookie) { |
|
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 |
foreach($rs as $row) { |
|
359 |
$stmp.=$row["session_id"].","; |
|
360 |
} |
|
361 |
$sql1="delete from session where id in (".substr($stmp,-1).")"; |
|
362 |
$sql2="delete from session_content where session_id in (".substr($stmp,-1).")"; |
|
363 |
$db->query($sql1,"authuser_A"); |
|
364 |
$db->query($sql2,"authuser_B"); |
|
365 |
header("location:../login.pl?action=logout"); |
|
366 |
}; |
|
367 |
$sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'"; |
|
368 |
$db->query($sql,"authuser_3"); |
|
369 |
$sql="select * from auth.user where id=".$rs[0]["id"]; |
|
370 |
} else { |
|
371 |
$sql = "select * from auth.user where login = '$login' and password = '$pwd'"; |
|
361 | 372 |
} |
362 |
$sql="select * from auth.user where id=".$rs[0]["id"]; |
|
363 | 373 |
$rs1=$db->getAll($sql,"authuser_1"); |
364 | 374 |
if (!$rs1) return false; |
365 | 375 |
$auth=array(); |
366 | 376 |
$auth["login"]=$rs1[0]["login"]; |
367 |
$sql="select * from auth.user_config where user_id=".$rs[0]["id"]; |
|
377 |
$sql="select * from auth.user_config where user_id=".$rs1[0]["id"];
|
|
368 | 378 |
$rs1=$db->getAll($sql,"authuser_2"); |
369 | 379 |
$keys=array("dbname","dbpasswd","dbhost","dbport","dbuser"); |
370 | 380 |
foreach ($rs1 as $row) { |
... | ... | |
372 | 382 |
$auth[$row["cfg_key"]]=$row["cfg_value"]; |
373 | 383 |
} |
374 | 384 |
} |
375 |
$sql="update auth.session set mtime = '".date("Y-M-d H:i:s.100001")."' where id = '".$rs[0]["session_id"]."'"; |
|
376 |
$db->query($sql,"authuser_3"); |
|
377 | 385 |
return $auth; |
378 | 386 |
} |
387 |
|
|
379 | 388 |
/** |
380 | 389 |
* Zeichencode ?bersetzen |
381 | 390 |
* |
lxo-import/partsB.php | ||
---|---|---|
1 |
<?php session_start(); ?> |
|
1 | 2 |
<html> |
2 | 3 |
<LINK REL="stylesheet" HREF="../css/lx-office-erp.css" TYPE="text/css" TITLE="Lx-Office stylesheet"> |
3 | 4 |
<body> |
... | ... | |
25 | 26 |
} |
26 | 27 |
require ("import_lib.php"); |
27 | 28 |
|
28 |
if (!anmelden()) ende("Anmeldung fehlgeschlagen."); |
|
29 |
if ($_GET["login"]) { |
|
30 |
$db = anmelden($_GET["login"],$_GET["passwd"]); |
|
31 |
} else { |
|
32 |
$db = anmelden(); |
|
33 |
} |
|
34 |
//if (!$_SESSION["db"]) ende("Anmeldung fehlgeschlagen."); |
|
35 |
if (!$db) ende("Anmeldung fehlgeschlagen."); |
|
29 | 36 |
|
30 | 37 |
/* get DB instance */ |
31 | 38 |
$db=$_SESSION["db"]; //new myDB($login); |
32 |
|
|
33 | 39 |
/* just display page or do real import? */ |
34 |
if ($_POST["ok"]) { |
|
40 |
if ($_POST["ok"] || $_GET["cron"]=="1") {
|
|
35 | 41 |
|
36 | 42 |
require ("parts_import.php"); |
37 | 43 |
//Zeichencodierung des Servers |
... | ... | |
92 | 98 |
|
93 | 99 |
clearstatcache (); |
94 | 100 |
|
95 |
$test = $_POST["test"]; |
|
96 |
$lager = $_POST["lager"]; |
|
97 |
$TextUpd = $_POST["TextUpd"]; |
|
98 |
$trenner = ($_POST["trenner"])?$_POST["trenner"]:","; |
|
99 |
$trennzeichen = ($_POST["trennzeichen"])?$_POST["trennzeichen"]:""; |
|
100 |
$precision = $_POST["precision"]; |
|
101 |
$quotation = $_POST["quotation"]; |
|
102 |
$quottype = $_POST["quottype"]; |
|
103 | 101 |
$file = "parts"; |
104 | 102 |
|
105 |
/* no data? */ |
|
106 |
if (empty($_FILES["Datei"]["name"])) |
|
107 |
ende ("Kein Datenfile angegeben"); |
|
108 |
|
|
109 |
/* copy file */ |
|
110 |
if (substr($_FILES["Datei"]["name"],-2)=="gz") { |
|
111 |
if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv.gz")) { |
|
112 |
echo $gz_bin.$dir.$file.".csv.gz"; |
|
103 |
if ($_GET["cron"]==1) { |
|
104 |
$Cron = True; |
|
105 |
if (file_exists($dir.$file.".zip")) { |
|
106 |
exec ($zip_bin.$dir.$file.".zip"); |
|
107 |
} else if (file_exists($dir.$file.".gz")) { |
|
113 | 108 |
exec ($gz_bin.$dir.$file.".csv.gz"); |
114 |
} else { |
|
115 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
|
116 |
}; |
|
117 |
} else if (substr($_FILES["Datei"]["name"],-3)=="zip") { |
|
118 |
if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".zip")) { |
|
119 |
exec ($zip_bin.$dir.$file.".zip"); |
|
120 |
} else { |
|
109 |
} else if (!file_exists($dir.$file.".csv")) { |
|
110 |
ende($dir.$file.".csv nicht gefunden"); |
|
111 |
} |
|
112 |
$_POST["trenner"] = "#9"; // Tabulator |
|
113 |
$_POST["trennzeichen"] = ";"; // Anderes Trennzeichen |
|
114 |
$_POST["dimensionunit"] = "Stck"; // Artikeleinheit |
|
115 |
$_POST["serviceunit"] = "Std"; // Dienstleistungseinheit |
|
116 |
$_POST["bugru"] = "1600"; // Std-Bugru |
|
117 |
$_POST["bugrufix"] = "2"; // Nur wenn keine Passende angegeben |
|
118 |
$_POST["shop"] = "f"; // Shopartikel |
|
119 |
$_POST["show"] = ""; // Kontrollausgabe |
|
120 |
$_POST["test"] = ""; // Testlauf == 1 |
|
121 |
$_POST["lager"] = ""; // Nicht gebraucht |
|
122 |
$_POST["lagerplatz"] = ""; |
|
123 |
$_POST["precision"] = "2"; // Runden auf nn Stellen |
|
124 |
$_POST["quotation"] = ""; // Preisaufschlag |
|
125 |
$_POST["quottype"] = "P"; // Prozent? |
|
126 |
$_POST["wgtrenner"] = "!"; // Trennzeichen der Warengruppen |
|
127 |
$_POST["TextUpd"] = "1"; // Textupdate durchführen |
|
128 |
$_POST["update"] = "U"; // Bei vorhandenen Nummer updaten |
|
129 |
$_POST["ware"] = "W"; // Ist ein Artikel |
|
130 |
$_POST["encoding"] = ""; |
|
131 |
} else { |
|
132 |
|
|
133 |
/* no data? */ |
|
134 |
if (empty($_FILES["Datei"]["name"])) |
|
135 |
ende ("Kein Datenfile angegeben"); |
|
136 |
|
|
137 |
/* copy file */ |
|
138 |
if (substr($_FILES["Datei"]["name"],-2)=="gz") { |
|
139 |
if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv.gz")) { |
|
140 |
echo $gz_bin.$dir.$file.".csv.gz"; |
|
141 |
exec ($gz_bin.$dir.$file.".csv.gz"); |
|
142 |
} else { |
|
143 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
|
144 |
}; |
|
145 |
} else if (substr($_FILES["Datei"]["name"],-3)=="zip") { |
|
146 |
if (move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".zip")) { |
|
147 |
exec ($zip_bin.$dir.$file.".zip"); |
|
148 |
} else { |
|
149 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
|
150 |
}; |
|
151 |
} else if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) { |
|
121 | 152 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
122 |
}; |
|
123 |
} else if (!move_uploaded_file($_FILES["Datei"]["tmp_name"],$dir.$file.".csv")) { |
|
124 |
ende ("Upload von Datei fehlerhaft.".$_FILES["Datei"]["error"]); |
|
125 |
}; |
|
153 |
}; |
|
154 |
} |
|
126 | 155 |
|
127 | 156 |
/* check if file is really there */ |
128 | 157 |
if (!file_exists($dir.$file.'.csv') or filesize($dir.$file.'.csv')==0) |
... | ... | |
132 | 161 |
if (!$db->chkcol($file)) |
133 | 162 |
ende("Importspalte konnte nicht angelegt werden"); |
134 | 163 |
|
135 |
/* first check all elements */ |
|
136 |
$_test=$_POST; |
|
137 |
$_test["precision"]=-1; |
|
138 |
$_test["quotation"]=0; |
|
139 |
$_test["lager"]=$_POST["lager"]; |
|
140 |
$_test["lagerplatz"]=$_POST["lagerplatz"]; |
|
141 |
|
|
142 | 164 |
/* just print data or insert it, if test is false */ |
143 |
import_parts($db, $dir.$file, $trenner, $trennzeichen, $parts, FALSE, !$test, $_POST["show"],$_POST);
|
|
165 |
import_parts($_SESSION["db"], $dir.$file, $parts, FALSE, $_POST);
|
|
144 | 166 |
|
145 | 167 |
} else { |
146 | 168 |
$bugrus=getAllBG($db); |
lxo-import/parts_import.php | ||
---|---|---|
226 | 226 |
return true; |
227 | 227 |
} |
228 | 228 |
|
229 |
function import_parts($db, $file, $trenner, $trennzeichen, $fields, $check, $insert, $show ,$maske) { |
|
229 |
/** |
|
230 |
* TODO: short description. |
|
231 |
* |
|
232 |
* @param double $db |
|
233 |
* @param mixed $file |
|
234 |
* @param mixed $fields |
|
235 |
* @param mixed $check |
|
236 |
* @param int $insert |
|
237 |
* @param string $show |
|
238 |
* @param mixed $maske |
|
239 |
* |
|
240 |
* @return TODO |
|
241 |
*/ |
|
242 |
function import_parts($db, $file, $fields, $check, $maske) { |
|
243 |
$insert = !$maske["test"]; |
|
244 |
$show = $maske["show"]; |
|
245 |
$trennzeichen = ($maske["trennzeichen"])?$maske["trennzeichen"]:""; |
|
246 |
$trenner = ($maske["trenner"])?$maske["trenner"]:","; |
|
230 | 247 |
$precision=$maske["precision"]; |
231 | 248 |
$quotation=$maske["quotation"]; |
232 | 249 |
$quottype=$maske["quottype"]; |
Auch abrufbar als: Unified diff
Automatisierter Import per Cronjob möglich.
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