Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision e2903b0d

Von Holger Lindemann vor fast 17 Jahren hinzugefügt

  • ID e2903b0d056db3b97b846ddde87a44b4f5a10954
  • Vorgänger 2740f3f0
  • Nachfolger 9dda820f

Neue Anmeldung berücksichtigt

Mehrere Warengruppenfelder im CSV für Import zusammenfassen

Unterschiede anzeigen:

lxo-import/db.php
1
<?
2
require_once "DB.php";
3
class myDB extends DB {
4

  
5
 var $db = false;
6
 var $rc = false;
7
 var $showErr = false; // Browserausgabe
8
 var $debug = false; // 1 = SQL-Ausgabe, 2 = zusätzlich Ergebnis
9
 var $log = true;  // Alle Abfragen mitloggen
10
 var $errfile = "tmp/lxcrm.err";
11
 var $logfile = "tmp/lxcrm.log";
12
 var $lfh = false;
13
 
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
	}
25

  
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
	}
34

  
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
	}
43

  
44
	function closeLogfile() {
45
		fclose($this->lfh);
46
	}
47
	
48
	function myDB($host,$user,$pwd,$db,$port,$showErr=false) {
49
		$dsn = array(
50
                    'phptype'  => 'pgsql',
51
                    'username' => $user,
52
                    'password' => $pwd,
53
                    'hostspec' => $host,
54
                    'database' => $db,
55
                    'port'     => $port
56
                );
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
	}
67

  
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
	}
80

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

  
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
	}
102

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

  
111
	function chkcol($tbl) {
112
        // 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
	}
120

  
121
           
122
}
123
?>
lxo-import/import_lib.php
9 9

  
10 10
*/
11 11

  
12
require_once "DB.php";
12
require_once "db.php";
13 13

  
14 14
$address = array(
15 15
	"name" => "Firmenname",
......
69 69
	"weight" => "Gewicht in Benutzerdefinition",
70 70
	"onhand" => "Lagerbestand",
71 71
	"notes" => "Beschreibung",
72
	"notes1" => "Beschreibung",
72 73
	//"makemodel" => "Hersteller",
73 74
	//"model" => "Modellbezeichnung",
74 75
	"bin" => "Lagerort",
......
89 90
	"assembly" => "St?ckliste (Y/N); wird noch nicht unterst?tzt",
90 91
	"partsgroup" => "Warengruppenbezeichnung",
91 92
	"partsgroup1" => "2.Warengruppenbezeichnung",
93
	"partsgroup2" => "3.Warengruppenbezeichnung",
94
	"partsgroup3" => "4.Warengruppenbezeichnung",
95
	"partsgroup4" => "5.Warengruppenbezeichnung",
92 96
	//"income_accno_0" => "?Nummer? f?r Erl?se Inland",
93 97
	//"income_accno_1" => "?Nummer? f?r Erl?se EG",
94 98
	//"income_accno_3" => "?Nummer? f?r Erl?se Ausland",
......
159 163
}
160 164

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

  
284
class myDB extends DB {
285
// Datenbankklasse
286

  
287
 var $rc = false;
288
 var $showErr = false;
289
 var $db = false;
290
 var $debug = false;
291
 var $logsql = false;
292
 var $errfile = false;
293
 var $logfile = false;
294

  
295

  
296
/****************************************************
297
* uudecode
298
* in: string
299
* out: string
300
* dekodiert Perl-UU-kodierte Passwort-Strings
301
* http://de3.php.net/base64_decode (bug #171)
302
*****************************************************/
303
	function uudecode($encode) {
304
	  $encode=stripslashes($encode);
305
	  $b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
306

  
307
	  $encode = preg_replace("/^./m","",$encode);
308
	  $encode = preg_replace("/\n/m","",$encode);
309
	  for($i=0; $i<strlen($encode); $i++) {
310
	    if ($encode[$i] == '')
311
	      $encode[$i] = ' ';
312
	    $encode[$i] = $b64chars[ord($encode[$i])-32];
313
	  }
314
   
315
	  while(strlen($encode) % 4)
316
	    $encode .= "=";
317

  
318
	  return base64_decode($encode);
319
	}
320

  
321
	function dbFehler($sql,$err) {
322
		if ($this->showErr)
323
			echo "$sql : $err\n";
324
	}
325

  
326
	function showDebug($sql) {	
327
		echo $sql."\n";
328
		if ($this->debug==2) {
329
			print_r($this->rc);
330
		};
331
	}
332

  
333
	function logSql($sql) {
334
		if (!$this->logfile)  $this->logfile=fopen("import.sql","a");
335
		fputs($this->logfile,$sql."\n");
336
	}
337
	function myDB($usr) {
338
		// Datenbankparameter des ERP-Users benutzen.
339
		$tmp = file_get_contents("../users/$usr.conf");
340
		preg_match("/dbname => '(.+)'/",$tmp,$hits);
341
		$dbname=$hits[1];
342
		preg_match("/dbpasswd => '(.+)'/",$tmp,$hits);
343
		if ($hits[1]) {
344
			$dbpasswd=$this->uudecode($hits[1]);
345
		} else {
346
        		$dbpasswd="";
347
		};
348
		preg_match("/dbuser => '(.+)'/",$tmp,$hits);
349
		$dbuser=$hits[1];
350
		preg_match("/dbhost => '(.+)'/",$tmp,$hits);
351
		$dbhost=$hits[1];
352
		if (!$dbhost) $dbhost="localhost";
353
		if ($dbpasswd) {
354
			$dns=$dbuser.":".$dbpasswd."@".$dbhost."/".$dbname;
355
		} else {
356
			$dns=$dbuser."@".$dbhost."/".$dbname;
357
		};
358
		$dns="pgsql://".$dns;
359
		$this->db=DB::connect($dns);
360
		if (!$this->db) DB::dbFehler("oh oh oh",$this->db->getDebugInfo());
361
		if (DB::isError($this->db)) {
362
			$this->dbFehler("Connect",$this->db->getDebugInfo());
363
			die ($this->db->getDebugInfo());
364
		}
365
		return $this->db;
366
	}
367

  
368
	function query($sql) {
369
		$this->rc=@$this->db->query($sql);
370
		if ($this->logsql) $this->logSql($sql);
371
		if ($this->debug) $this->showDebug($sql);
372
		if(DB::isError($this->rc)) {
373
			$this->dbFehler($sql,$this->rc->getMessage());
374
			return false;
375
		} else {
376
			return $this->rc;
377
		}
378
	}
379
	function getAll($sql) {
380
		$this->rc=@$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
381
		if ($this->logsql) $this->logSql($sql);
382
		if ($this->debug) $this->showDebug($sql);
383
		if(DB::isError($this->rc)) {
384
			$this->dbFehler($sql,$this->rc->getMessage());
385
			return false;
386
		} else {
387
			return $this->rc;
388
		}
389
	}	
390

  
391
	function lock() {
392
		$this->query("BEGIN");
393
	}
394
	function commit() {
395
		$this->query("COMMIT");
396
	}
397
	function rollback() {
398
		$this->query("ROLLBACK");
399
	}
400
	function chkcol($tbl) {
401
	// gibt es die Spalte import schon?
402
		$rc=$this->db->query("select import from $tbl limit 1");
403
		if(DB::isError($rc)) {
404
			$rc=$this->db->query("alter table $tbl add column import int4");
405
			if(DB::isError($rc)) { return false; }
406
			else { return true; }
407
		
408
		} else { return true; };
409
	}
342
function authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie) {
343
        $db=new myDB($dbhost,$dbuser,$dbpasswd,$dbname,$dbport,true);
344
        $sql="select sc.session_id,u.id from auth.session_content sc left join auth.user u on ";
345
        $sql.="u.login=sc.sess_value left join auth.session s on s.id=sc.session_id ";
346
        $sql.="where session_id = '$cookie' and sc.sess_key='login'";// order by s.mtime desc";
347
        $rs=$db->getAll($sql,"authuser_1");
348
        if (!$rs) return false;
349
        $stmp="";
350
        if (count($rs)>1) {
351
                header("location:../login.pl?action=logout");
352
                /*foreach($rs as $row) {
353
                        $stmp.=$row["session_id"].",";
354
                }
355
                $sql1="delete from session where id in (".substr($stmp,-1).")";
356
                $sql2="delete from session_content where session_id in (".substr($stmp,-1).")";
357
                $db->query($sql1,"authuser_A");
358
                $db->query($sql2,"authuser_B");
359
                $sql3="insert into session ";*/
360
        }
361
        $sql="select * from auth.user_config where user_id=".$rs[0]["id"];
362
        $rs1=$db->getAll($sql,"authuser_2");
363
        $auth=array();
364
        $keys=array("login","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"];
368
                }
369
        }
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");
372
        return $auth;
410 373
}
411 374

  
412
?>
lxo-import/partsB.php
8 8
Holger Lindemann <hli@lx-system.de>
9 9
*/
10 10

  
11
/* get login via GET or POST */
12
if ($_GET["login"]) {
13
	$login=$_GET["login"];
14
} else {
15
	$login=$_POST["login"];
16
};
17 11

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

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

  
27
if (!anmelden()) ende(5);
28

  
19 29
/* get DB instance */
20
$db=new myDB($login);
30
$db=$_SESSION["db"]; //new myDB($login);
21 31

  
22 32

  
23 33
/* just display page or do real import? */
24 34
if ($_POST["ok"]) {
25 35

  
26

  
27 36
require ("parts_import.php");
28 37

  
29
function ende($nr) {
30
	echo "Abbruch: $nr<br>";
31
	echo "Fehlende oder falsche Daten.";
32
	exit(1);
33
}
34

  
35 38
/* display help */
36 39
if ($_POST["ok"]=="Hilfe") {
37 40
	echo "Importfelder:<br>";
......
42 45
	echo "<br>Die erste Zeile enth&auml;lt die Feldnamen der Daten in ihrer richtigen Reihenfolge<br>";
43 46
	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>"; 
44 47
	echo "Der &quot;sellprice&quot; kann um den eingegeben Wert  ge&auml;ndert werden.<br><br>";
45
	echo "Bei vorhandenen Artikelnummern (in der db), kann entweder ein Update auf den Preis durchgef&uuml;hrt werden oder der Artikel mit anderer Artikelnummer eingef&uuml;gt werden.<br><br>";
48
	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>";
46 49
	echo "Jeder Artikel mu&szlig; einer Buchungsgruppe zugeordnet werden. ";
47 50
	echo "Dazu mu&szlig; entweder in der Maske eine Standardbuchungsgruppe gew&auml;hlt werden <br>";
48 51
	echo "oder es wird ein g&uuml;ltiges Konto in 'income_accno_id' und 'expense_accno_id' eingegeben. ";
......
53 56
clearstatcache ();
54 57

  
55 58
$test    = $_POST["test"];
59
$TextUpd = $_POST["TextUpd"];
56 60
$trenner = ($_POST["trenner"])?$_POST["trenner"]:",";
57 61
$trennzeichen = ($_POST["trennzeichen"])?$_POST["trennzeichen"]:"";
58 62
$precision = $_POST["precision"];
......
72 76
} 
73 77

  
74 78
/* ??? */
75
if (!file_exists("../users/$login.conf")) 
76
	ende(3);
79
//if (!chkUsr($login))
80
//	ende(4);
81

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

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

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

  
86
/* ??? */
87
if (!chkUsr($login))
88
	ende(4);
89 94

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

  
......
109 116
<p class="listtop">Artikelimport f&uuml;r die ERP<p>
110 117
<br>
111 118
<form name="import" method="post" enctype="multipart/form-data" action="partsB.php">
112
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
119
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">
113 120
<input type="hidden" name="login" value="<?= $login ?>">
114 121
<table>
115
<tr><td></td><td><input type="submit" name="ok" value="Hilfe"></td></tr>
122
<tr><td><input type="submit" name="ok" value="Hilfe"></td><td></td></tr>
116 123
<tr><td>Trennzeichen</td><td>
117 124
		<input type="radio" name="trenner" value=";" checked>Semikolon 
118 125
		<input type="radio" name="trenner" value=",">Komma 
119
		<input type="radio" name="trenner" value="#9">Tabulator
126
		<input type="radio" name="trenner" value="#9" checked>Tabulator
120 127
		<input type="radio" name="trenner" value=" ">Leerzeichen
121 128
		<input type="radio" name="trenner" value="other"> 
122 129
		<input type="text" size="2" name="trennzeichen" value=""> 
......
134 141
<tr><td>Vorhandene<br>Artikelnummer:</td><td><input type="radio" name="update" value="U" checked>Preis update durchf&uuml;hren<br>
135 142
					<input type="radio" name="update" value="I">mit neuer Nummer einf&uuml;gen</td></tr>
136 143
<tr><td>Test</td><td><input type="checkbox" name="test" value="1">ja</td></tr>
137
<tr><td>Art</td><td><input type="Radio" name="ware" value="W">Ware &nbsp; 
144
<tr><td>Textupdate</td><td><input type="checkbox" name="TextUpd" value="1">ja</td></tr>
145
<tr><td>Warengruppen<br>verbinder</td><td><input type="text" name="wgtrenner" value="!" size="3"></td></tr>
146
<tr><td>Shopartikel</td><td><input type="radio" name="shop" value="t">ja <input type="radio" name="shop" value="n" checked>nein</td></tr>
147
<tr><td>Art</td><td><input type="Radio" name="ware" value="W" checked>Ware &nbsp; 
138 148
		    <input type="Radio" name="ware" value="D">Dienstleistung
139
		    <input type="Radio" name="ware" value="G" checked>gemischt (Spalte 'art' vorhanden)</td></tr>
149
		    <input type="Radio" name="ware" value="G">gemischt (Spalte 'art' vorhanden)</td></tr>
140 150
<tr><td>Default Bugru<br></td><td><select name="bugru">
141 151
<?	if ($bugrus) foreach ($bugrus as $bg) { ?>
142 152
			<option value="<?= $bg["id"] ?>"><?= $bg["description"] ?>
143 153
<?	} ?>
144 154
	</select>
145
	<input type="radio" name="bugrufix" value="0" checked>nie<br>
146
	<input type="radio" name="bugrufix" value="1">f&uuml;r alle Artikel verwenden
155
	<input type="radio" name="bugrufix" value="0">nie<br>
156
	<input type="radio" name="bugrufix" value="1" checked>f&uuml;r alle Artikel verwenden
147 157
	<input type="radio" name="bugrufix" value="2">f&uuml;r Artikel ohne passende Bugru
148 158
	</td></tr>
149 159
<tr><td>Daten</td><td><input type="file" name="Datei"></td></tr>
lxo-import/parts_import.php
23 23
	return $rs[0]["id"];
24 24
}
25 25

  
26
//Mu? noch eingebunden werden
27 26
function getMakemodel($db,$hersteller,$model,$partsid,$add=true) {
28 27
	$sql="select * from makemodel where make like '$hersteller' and model like = '$model'";
29 28
	$rs=$db->getAll($sql);
......
43 42
	return $rs[0]["id"];
44 43
}
45 44

  
46
//Auf Artikelnummer testen, bzw. neue Nummer erzeugen
47 45
function chkPartNumber($db,$number,$check) {
48 46
	if ($number<>"") {
49 47
		$sql = "select * from parts where partnumber = '$number'";
......
68 66
	}
69 67
	return $number;
70 68
}
71

  
72
//Artikelnummer testen und wenn vorhanden Preis ?ndern
73
function chkPartNumberUpd($db,$sellprice,$partnumber,$check){
69
function chkPartNumberUpd($db,$sellprice,$partnumber,$descript,$note,$check,$shop='n'){
74 70
	if ($partnumber=="") {
75 71
		$nummer=chkPartNumber($db,$partnumber,$check);
76 72
		if ($nummer=="") { return -99; }
......
79 75
	$sql = "select * from parts where partnumber = '$partnumber'";
80 76
	$rs=$db->getAll($sql);
81 77
	if ($rs[0]["id"]>0) {
82
		if ($check) return -1;
83
		$sql="update parts set sellprice = $sellprice where partnumber = '$partnumber'";
78
		$sql="update parts set sellprice = $sellprice, shop='$shop'";
79
		if ($descript) $sql.=",description='$descript',notes='$note'"; 
80
		$sql.=" where partnumber = '$partnumber'";
84 81
		$rc=$db->query($sql);
85 82
		if ($rc) return -1;
86 83
		return -99;
......
136 133
	return $rs[0]["name"];
137 134
}
138 135

  
136

  
139 137
function import_parts($db, $file, $trenner, $trennzeichen, $fields, $check, $insert, $show,$maske) {
140 138

  
141 139
	$pgshow=false;
......
144 142
	$precision=$maske["precision"];
145 143
	$quotation=$maske["quotation"];
146 144
	$quottype=$maske["quottype"];
145
	$shop=$maske["shop"];
146
	$wgtrenner=$maske["wgtrenner"];
147
	$UpdText=($maske["TextUpd"]=="1")?true:false;
147 148

  
148 149
	$Update=($maske["update"]=="U")?true:false;
149 150
	/* field description */
......
163 164
		$fld = strtolower(trim(strtr($fld,array("\""=>"","'"=>""))));
164 165
		$in_fld[]=$fld;
165 166
		if (in_array(trim($fld),$parts_fld)) {
166
			if ($fld=="partsgroup" || $fld=="partsgroup1" ) {
167
			if (substr($fld,0,10)=="partsgroup") {
167 168
				$pgshow=true;
169
			} else if ($fld=="notes" || $fld=="notes1" ) {
170
				$note2show=true;
168 171
			} else {
169 172
				show( $show, "<td>$fld</td>\n");
170 173
			}
......
177 180
		show( $show, "<td>unit</td>\n");
178 181
	};
179 182
	if ($pgshow) show( $show, "<td>partsgroup</td>\n");
183
	if ($note2show) show( $show, "<td>notes</td>\n");
180 184
	$posprice=0;
181 185
	$posnumber=0;
186
	$posdescript=0;
187
	$posnotes=0;
188
	$posnotes1=0;
182 189
	$j=0;
183 190
	foreach ($infld as $value) { 
184 191
		if ($infld[$j]=="sellprice") $posprice=$j;  
185 192
		if ($infld[$j]=="partnumber") $posnumber=$j;
193
		if ($infld[$j]=="description") $posdescript=$j;
194
		if ($infld[$j]=="notes") $posnotes=$j;
195
		if ($infld[$j]=="notes1") $posnotes1=$j;
186 196
		$j++; 
187 197
	}
188 198
	$m=0;		/* line */
189 199
	$errors=0;	/* number of errors detected */
190 200
	$income_accno = "";
191 201
	$expense_accno = "";
202

  
203
	/*if ($insert) {
204
		$sql="update parts set shop = 'n' where partnumber like '______'";
205
		$rc=$db->query($sql);
206
		//echo $sql; print_r($rc); echo "<br>";
207
		if (!$rc) {
208
			echo "Fehler: Artikel nicht aus dem Shop genommen";
209
		}
210
	};*/
192 211
	if ($quottype=="P") $quotation=($quotation+100)/100;
193
	while ( ($zeile=fgetcsv($f,15000,$trenner)) != FALSE) {
212
	while ( ($zeile=fgetcsv($f,120000,$trenner)) != FALSE) {
194 213
		$i=0;	/* column */
195 214
	        $m++;	/* increase line */
196

  
215
		
197 216
		if ($Update) {
198 217
			$sellprice=$zeile[$posprice];
199 218
			$partnumber=$zeile[$posnumber];
......
203 222
				else { $sellprice = $sellprice * $quotation; }
204 223
			};
205 224
			if ($precision>=0) $sellprice = round($sellprice,$precision);
206
			$rc=chkPartNumberUpd($db,$sellprice,$partnumber,!$insert);
225
			if ($UpdText) {
226
				$description=$zeile[$posdescript];
227
				$note=$zeile[$posnotes];
228
				$note1=$zeile[$posnotes1];
229
				$note=mb_convert_encoding($note,"ISO-8859-15","ISO-8859-15");
230
                        	$note=preg_replace('/""[^ ]/','"',$note);
231
                        	$note=" \n".addslashes($note);
232
				$note1=mb_convert_encoding($note1,"ISO-8859-15","ISO-8859-15");
233
                        	$note1=preg_replace('/""[^ ]/','"',$note1);
234
                        	$note.=" \n".addslashes($note1);
235
				$rc=chkPartNumberUpd($db,$sellprice,$partnumber,$description,$note,$check);
236
			} else {
237
				$rc=chkPartNumberUpd($db,$sellprice,$partnumber,false,false,$check);
238
			}
207 239
			if ($rc==-1) {
208 240
				show($show,"<tr><td>Update </td><td>$partnumber:$sellprice</td></tr>\n");
209 241
				continue;
......
218 250
		$sql="insert into $file ";
219 251
		$keys="(";
220 252
		$vals=" values (";
221

  
222 253
		show( $show, "<tr><td>$m</td>\n");
223 254

  
224 255
		/* for each column */
225 256
		$dienstleistung=false;
226 257
		$artikel=-1;
227 258
		$partNr=false;
228
		$pg_name_val="";
259
		$pg_name_val=array();
260
		$note_val="";
261
		$model="";
262
		$hersteller="";
229 263
		foreach($zeile as $data) {
230 264
			/* check if column will be imported */
231 265
			if (!in_array(trim($in_fld[$i]),$parts_fld)) {
......
237 271
			/* add key and data */
238 272

  
239 273
			/* special case partsgroup1 */
240
			if ($key == "partsgroup1") {
241
				if ($pg_name_val<>"") {
242
					if ($data<>"")	$pg_name_val.="!".$data;
243
				} else {
244
					$pg_name_val=$data;
245
				}
246
				$i++;
247
				continue;
248
			} else if ($key == "partsgroup") {
249
			        /* special case partsgroup */
250
				$pg_name_val=$data;
274
			if (substr($key,0,10) == "partsgroup") {
275
				if (strlen($key)==10) { $pgnr=0; } 
276
				else { $pgnr=substr($key,-1); }
277
				$pg_name_val[$pgnr]=$data;
251 278
				$i++;
252 279
				continue;
253
			} else if ($key == "lastcost" || 
280
			} else 	if ($key == "lastcost" || 
254 281
				   $key == "sellprice") {
255 282
				
256 283
				/* convert 0,0 numeric into 0.0 */
......
275 302
					//show( $show, "<td>$partnumber</td>\n");
276 303
				}
277 304
			} else if ($key == "description") {
278
				$data=mb_convert_encoding($data,"ISO-8859-15","auto");
305
				$data=mb_convert_encoding($data,"ISO-8859-15","ISO-8859-15");
306
				$data=preg_replace('/""[^ ]/','"',$data);
279 307
				$data=addslashes($data);
280 308
			} else if ($key == "notes") {
281
				$data=mb_convert_encoding($data,"ISO-8859-15","auto");
282
				$data=addslashes($data);
309
				$data=mb_convert_encoding($data,"ISO-8859-15","ISO-8859-15");
310
				$data=preg_replace('/""[^ ]/','"',$data);
311
				$notesval=addslashes($data);
312
				$i++;
313
				continue;
314
			} else if ($key == "notes1") {
315
				$data=mb_convert_encoding($data,"ISO-8859-15","ISO-8859-15");
316
				$data=preg_replace('/""[^ ]/','"',$data);
317
				$notesval.=" \n".addslashes($data);
318
				$i++;
319
				continue;
320
				//$key="notes";
321
			/*} else if ($key == "makemodel") {
322
				$data=mb_convert_encoding($data,"ISO-8859-15","ISO-8859-15");
323
				$hersteller=addslashes($data);
324
				$i++;
325
				continue;
326
			} else if ($key == "model") {
327
				$data=mb_convert_encoding($data,"ISO-8859-15","ISO-8859-15");
328
				$model=addslashes($data);
329
				$i++;
330
				continue;*/
283 331
			} else if ($key == "unit") {
284 332
				if ($data=="") {
285 333
					if ($maske["ware"]=="W") { $data=$stdunitW; }
......
293 341
				else if ($data == "Stunde")
294 342
					$data = "Std";
295 343
				/* check if unit exists */
344
				//echo "!$data!";
296 345
				if (!existUnit($db, $data)) {
297 346
					echo "Error in line $m: ";
298 347
					echo "Einheit <b>$data</b> existiert nicht ";
......
314 363
				$i++;
315 364
				show( $show, "<td>$data</td>\n");
316 365
				continue;
317
			}
366
			} 
318 367
			if ($data==false or empty($data) or !$data) {
319 368
				show( $show, "<td>NULL</td>\n");
320 369
				$i++;
321 370
				continue;
322
			}
371
			}	
323 372
			/* convert JA to Yes */
324 373
			if ($data === "J" || $data === "j")  $data = "Y";
325 374
			$vals.="'".$data."',";
......
335 384
			show( $show,"<td>$einh</td>\n");
336 385
		}
337 386
		/* special case partsgroup */
387
		//Mehrere Warengruppennamen werden mit einem Trennzeichen zu einen Namen zusammengef?rt.
338 388
		if ($pgshow) {
339
			if ($pg_name_val) {
389
			foreach($pg_name_val as $pg) {
390
				if ($pg>"") $pgname.=$pg.$wgtrenner;
391
			};
392
			unset($pg_name_val);
393
			if ($pgname and $pgname <> "!") {
394
				$pgname=substr($pgname,0,-1);
340 395
				/* get ID of partsgroup or add new 
341 396
				 * partsgroup_id */
342
				$ID = getPartsgroupId($db, $pg_name_val, $insert);
397
				$ID = getPartsgroupId($db, $pgname, $insert);
343 398
				$keys.= "partsgroup_id,";
344 399
				$vals.="'".$ID."',";
345
				show( $show, "<td>".htmlentities($pg_name_val).":$ID</td>\n");
400
				show( $show, "<td>".htmlentities($pgname).":$ID</td>\n");
401
			} else {
402
				show( $show,"<td>NULL</td>\n");
403
			}
404
		}
405
		if ($note2show) {
406
			if ($notesval) {
407
				$keys.="notes,";
408
				$vals.="'$notesval',";
409
				if (strlen($notesval)>255) {
410
					show( $show, "<td>".substr($notesval,0,25)." . . . ".htmlentities(substr($notesval,-25))."</td>\n");
411
				} else {
412
					show( $show, "<td>$notesval</td>\n");
413
				}
346 414
			} else {
347 415
				show( $show,"<td>NULL</td>\n");
348 416
			}
......
398 466
				show( $show, "<td>$partnumber</td>\n");
399 467
			}
400 468
		} 
401
		$sql.=$keys."import)";
402
		$sql.=$vals.time().")";		
403
		//show( $show, "<td> $sql </td>\n");
469
		//Automatisch Bilder mit einbinden 
470
		//Die Bilder m?ssen manuell hier (bilder/) her kopiert werden.
471
		//Names des Bildes: "bilder/" + Artikelnummer in Grossbuchstaben + ".jpg"
472
		//$bild="bilder/".strtoupper($bild).".jpg";
473
		//$sql.=$keys."image,shop,weight,import)";
474
		//$sql.="$vals'$bild','$shop',3,".time().")";	
475

  
476
		//ohne Bilder
477
		$sql.=$keys."shop,weight,import)";
478
		$sql.="$vals'$shop',3,".time().")";	
404 479

  
405 480
		if ($insert) {
406 481
			show( $show, "<td>");
......
412 487
			}
413 488
			show( $show, "</td>\n");
414 489
		}
415

  
490
		$pgname="";
416 491
		show( $show, "</tr>\n");
417 492
	}
418 493

  

Auch abrufbar als: Unified diff