commit e66d4dda8ce261100c6a4c36671a1323caed9c11
Author: Holger Lindemann <hli@lx-system.de>
Date:   Thu Feb 11 11:43:48 2010 +0100

    Umlautproblem mit Shop.
    
    Setzt vorraus, dass LxO UTF8 ist.
    Darstellungsprobleme beim Import der Bestellungen == Schönheitsfehler, später machen

diff --git a/xtcom/confedit.php b/xtcom/confedit.php
index b9d8d47a7..0d3fb7eef 100644
--- a/xtcom/confedit.php
+++ b/xtcom/confedit.php
@@ -32,6 +32,21 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
 			echo ">".$row[1]."\n";
 		}
 	}
+    /**
+     * TODO: short description.
+     * 
+     * @param string $sel 
+     * 
+     * @return TODO
+     */
+    function charset($sel) {
+        $chars = array('','latin9','utf-8');
+        foreach ($chars as $c) {
+           echo "\t<option value='$c' ";
+		   if ($sel==$c) echo " selected";
+		   echo ">$c\n";
+        }
+    }
 	function shoplang($sel,$default) {
 	global $dbM;
 		if (!$dbM) return;
@@ -188,6 +203,7 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
 			fputs($f,"\$SHOPdbname=\"".$_POST["SHOPdbname"]."\";\n");
 			fputs($f,"\$SHOPdns=\"mysql://\$SHOPuser:\$SHOPpass@\$SHOPhost/\$SHOPdbname\";\n");
 			fputs($f,"\$SHOPdir=\"".$_POST["SHOPdir"]."\";\n");
+			fputs($f,"\$SHOPchar=\"".$_POST["SHOPchar"]."\";\n");
 			fputs($f,"\$SHOPimgdir=\"".$_POST["SHOPimgdir"]."\";\n");
 			fputs($f,"\$SHOPftphost=\"".$_POST["SHOPftphost"]."\";\n");
 			fputs($f,"\$SHOPftpuser=\"".$_POST["SHOPftpuser"]."\";\n");
@@ -244,7 +260,7 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
 			fputs($f,"\$SpracheAlle=\"".$_POST["SpracheAlle"]."\";\n");
 			fputs($f,"?>");
 			fclose($f);
-			echo "<br>'conf.php' geschriebeni!<br>";
+			echo "<br>'conf.php' geschrieben!<br>";
 			if (file_exists ("conf$login.php")) {
         		        require "conf$login.php";
         		} else {
@@ -291,6 +307,7 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
 			$SHOPpass=$_POST["SHOPpass"];
 			$SHOPhost=$_POST["SHOPhost"];
 			$SHOPport=$_POST["SHOPport"];
+			$SHOPchart=$_POST["SHOPchart"];
 			$SHOPdbname=$_POST["SHOPdbname"];
 			$SHOPlang=$_POST["SHOPlang"];
 			$SHOPdir=$_POST["SHOPdir"];
@@ -399,8 +416,10 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
 <tr>
 	<td>User-ID</td>
 	<td colspan="2"><input type="text" name="ERPusrN" size="10" value="<?= $ERPusr["Name"] ?>">
-		<input type="checkbox" name="a1" <?= (empty($ERPusr["ID"])?"":"checked") ?> onFocus="blur();"></td>
-	<td></td>
+		<input type="checkbox" name="a1" <?= (empty($ERPusr["ID"])?"":"checked") ?> onFocus="blur();"> &nbsp; Charset Shop:</td>
+	<td><select name="SHOPchar">
+<? charset($SHOPchar); ?>
+	    </select></td>
 </tr>
 <tr>
 	<td>CSV-Dir</td>
@@ -428,7 +447,7 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
 	<td><input type="text" name="SHOPftppwd" size="15" value="<?= $SHOPftppwd ?>"></td>
 </tr>
 <tr>
-	<td>ID Diverse 19%</td>
+	<td>ID Diverse 16%</td>
 	<td><input type="text" name="div16NR" size="10" value="<?= $div16["NR"] ?>">
 		<input type="checkbox" name="a1" <?= (empty($div16["ID"])?"":"checked") ?>></td>
 	<td>ID Diverse 7%</td>
diff --git a/xtcom/shopimport_db.php b/xtcom/shopimport_db.php
index 377439def..dbac84a77 100644
--- a/xtcom/shopimport_db.php
+++ b/xtcom/shopimport_db.php
@@ -8,6 +8,7 @@
 *Shop: xt:Commerce 3.04
 *ERP: Lx-Office ERP 2.4.0
 ***************************************************************/
+define("ExportMode","1");
 require_once "shoplib.php";
 
 
diff --git a/xtcom/shoplib.php b/xtcom/shoplib.php
index 3fa3657df..ebbbf369b 100755
--- a/xtcom/shoplib.php
+++ b/xtcom/shoplib.php
@@ -3,7 +3,9 @@
 
 $login=$_GET["login"];
 $debug=false;
-require_once "DB.php";
+#require_once "DB.php";
+require_once "MDB2.php";
+
 if (file_exists ("conf$login.php")) {
 	require "conf$login.php";
 } else {
@@ -45,19 +47,33 @@ else { $log=false; };
 /****************************************************
 * Shopverbindung aufbauen
 ****************************************************/
-$shop=DB::connect($SHOPdns);
+/*$shop=DB::connect($SHOPdns);
 if (!$shop) shopFehler("",$shop->getDebugInfo());
 if (DB::isError($shop)) {
 	$nun=date("Y-m-d H:i:s");
 	if ($log) fputs($log,$nun.": Shop-Connect\n");
 	shopFehler("",$shop->getDebugInfo());
 	die ($shop->getDebugInfo());
+};*/
+$options = array();
+//print_r($SHOPdns);
+$shop=MDB2::factory($SHOPdns,$options);
+//echo "<pre>"; print_r($shop); echo "</pre>";
+if (!$shop) shopFehler("",$shop->getMessage());
+if (PEAR::isError($shop)) {
+        $nun=date("Y-m-d H:i:s");
+        if ($log) fputs($log,$nun.": Shop-Connect\n");
+        shopFehler("",$shop->getMessage());
+        die ($shop->getMessage());
 };
+if (ExportMode == "1") $shop->setCharset('utf8');
+$shop->setFetchMode(MDB2_FETCHMODE_ASSOC);
+
 
 /****************************************************
 * ERPverbindung aufbauen
 ****************************************************/
-$erp=DB::connect($ERPdns);
+/*$erp=DB::connect($ERPdns);
 if (!$erp) shopFehler("",$erp->getDebugInfo());
 if (DB::isError($erp)) {
 	$nun=date("Y-m-d H:i:s");
@@ -66,8 +82,26 @@ if (DB::isError($erp)) {
 	die ($erp->getDebugInfo());
 } else {
 	$erp->autoCommit(true);
+};*/
+$options = array('result_buffering' => false,);
+$erp = MDB2::factory($ERPdns,$options);
+//echo "<pre>"; print_r($erp); echo "</pre>";
+if (!$erp) shopFehler("",$erp->getMessage());
+if (PEAR::isError($erp)) {
+        $nun=date("Y-m-d H:i:s");
+        if ($log) fputs($log,$nun.": ERP-Connect\n");
+        shopFehler("",$erp->getMessage());
+        die ($erp->getMessage());
+} else {
+        if ($erp->autocommit) $erp->autocommit();
 };
 
+if ($SHOPchar and ExportMode != "1") {
+    $erp->setCharset($SHOPchar);
+} 
+$erp->setFetchMode(MDB2_FETCHMODE_ASSOC);
+
+
 
 /****************************************************
 * SQL-Befehle absetzen
@@ -78,7 +112,8 @@ function query($db,$sql,$function="--") {
  	if ($GLOBALS["log"]) fputs($GLOBALS["log"],$nun.": ".$function."\n".$sql."\n");
  	$rc=$GLOBALS[$db]->query($sql);
  	if ($GLOBALS["log"]) fputs($GLOBALS["log"],print_r($rc,true)."\n");
- 	if ($rc!==1) {
+    if(PEAR::isError($rc)) {
+ 	//if ($rc!==1) {
  	    return -99;
  	} else {
             return true;
@@ -91,8 +126,10 @@ function query($db,$sql,$function="--") {
 function getAll($db,$sql,$function="--") {
 	$nun=date("d.m.y H:i:s");
 	if ($GLOBALS["log"]) fputs($GLOBALS["log"],$nun.": ".$function."\n".$sql."\n");
-	$rs=$GLOBALS[$db]->getAll($sql,DB_FETCHMODE_ASSOC);
-	if ($rs["message"]<>"") {
+	//$rs=$GLOBALS[$db]->getAll($sql,DB_FETCHMODE_ASSOC);
+	$rs=$GLOBALS[$db]->queryAll($sql);
+	//if ($rs["message"]<>"") {
+    if ($rs->message<>"") {
 	       	if ($GLOBALS["log"]) fputs($GLOBALS["log"],print_r($rs,true)."\n");
 		return false;
 	} else {
diff --git a/xtcom/xtcomexport.php b/xtcom/xtcomexport.php
index 1313e444b..f40909da6 100644
--- a/xtcom/xtcomexport.php
+++ b/xtcom/xtcomexport.php
@@ -18,9 +18,8 @@ echo '	<link type="text/css" REL="stylesheet" HREF="css/main.css"></link>';
 echo "<body>";
 //EOF;
 
+define("ExportMode","2");
 require_once "shoplib.php";
-
-
 /**********************************************
 * getAttribut($oid,$pid)
 *
