Index: /mods/mod_converter/M1_Converter_update.php
===================================================================
--- /mods/mod_converter/M1_Converter_update.php	(revision 6540)
+++ /mods/mod_converter/M1_Converter_update.php	(revision 6540)
@@ -0,0 +1,1381 @@
+<?php
+
+/**
+ * Dieses Modul dient zur Konvertierung der Daten aus wpShopGermany Version 3
+ * in die wpShopGermany Version 4.
+ * 
+ * @author hartmut
+ */
+class M1_Converter_update
+{
+	
+	private $m1cpb1;
+	
+	public function __construct($m1cpb) {
+		//global $GLOBALS;
+		//$this->glob = &$GLOBALS;
+		$this->m1cpb1 = $m1cpb;
+	}
+	
+	/**
+	 * Konvertierung der Kundenadressen.
+	 * 
+	 * Wenn das Feld adress_id=0 ist, wird die Adresse aus der Kundentabelle
+	 * in die Adresstabelle kopiert und in dem Feld adress_id der Bezug
+	 * zur Adresse hergestellt.
+	*/
+	public function M1_Converter_kunden() {
+		
+	    $anz1 = 0;
+	    $anz2 = 0;
+	?>
+	
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+	<?php
+	    $kunden = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_KU."` ORDER BY `id` ASC");
+	 
+	    foreach ($kunden as $k)
+	    {
+	    	$anz2++;
+	    	if (isset($k['adress_id']) && ($k['adress_id'] == '0'))
+	    	{
+	    		$kid = $k['id'];
+	    		
+	    		// Daten aus Kunden in Tabelle Adresse ÃŒbernehmen
+	    		// und die adress_id in WPSG_TBL_KU eintragen.
+	    		$data = array();
+	    		$data['cdate'] = "NOW()";
+	    		$data['title'] = $k['title'];
+	    		$data['name'] = $k['name'];
+	    		$data['vname'] = $k['vname'];
+	    		$data['firma'] = $k['firma'];
+	    		$data['fax'] = $k['fax'];
+	    		$data['strasse'] = $k['strasse'];
+	    		//$data['nr'] = $k['nr'];
+	    		$data['plz'] = $k['plz'];
+	    		$data['ort'] = $k['ort'];
+	    		$data['land'] = $k['land'];
+	    		$data['tel'] = $k['tel'];
+	    		$aid = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_ADRESS, $data);
+	    		
+	    		$kdata = array('adress_id' => $aid);
+	    		$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_KU, $kdata, "`id` = '".$kid."'");
+	    		$anz1++;
+	    		
+	    	}
+	    	
+	    }
+	    
+	    unset($_REQUEST['action']);
+    	echo '<br /><br />';
+    	echo $anz1.' Adresse(n) von '.$anz2.' Kunden neu angelegt.<br /><br />';
+    	
+    	echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+    	//$GLOBALS['wpsg_sc']->addFrontendMessage(__('Test.', 'wpsg'));
+    	
+	}	// public function M1_Converter_kunden()
+
+	/**
+	 * Konvertierung der Bestellungen
+	 *
+	 * Ãber die k_id wird die adress_id aus der Kundentabelle geholt
+	 * und in das Feld adress_id in der Bestellungen-Tabelle eingetragen.
+	 * Wenn eine Lieferadresse vorhanden ist, wird diese in die Tabelle
+	 * Adressen kopiert und die id in das Feld shipping_adress_id eingetragen.
+	 *
+	 */
+	public function M1_Converter_order() {
+		
+		$anz1 = 0;
+		$anz2 = 0;
+		$anz3 = 0;
+		$anz4 = 0;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+	<?php
+		
+		$order = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDER."` ORDER BY `id` ASC");
+	
+		foreach ($order as $o)
+		{
+			$anz2++;
+			$oid = $o['id'];
+			
+			if (isset($o['adress_id']) && ($o['adress_id'] == '0'))
+			{
+			
+				// Aus WPSG_TBL_ORDER k_id nehmen und aus WPSG_TBL_KU adress_id in
+				// WPSG_TBL_ORDER in das Feld adress_id eintragen.
+				$kid = $o['k_id'];
+				
+				$kdata = $GLOBALS['wpsg_sc']->db->fetchRow("SELECT * FROM `".WPSG_TBL_KU."` WHERE `id` = '".wpsg_q($kid)."' ");
+				if (!is_array($kdata))
+				{
+					$anz4++;
+				}
+				
+				if (isset($kdata['adress_id']) && $kdata['adress_id'] != '0')
+				{
+					$aid = $kdata['adress_id'];
+					$odata = array('adress_id' => $aid);
+					$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_ORDER, $odata, "`id` = '".$oid."'");
+					$anz3++;
+				}
+			}
+	
+			// Wenn in WPSG_TBL_ORDER eine Versandadresse angegeben ist, diese in
+			// WPSG_TBL_ADRESS anlegen und in WPSG_TBL_ORDER in shipping_adress_id eintragen.
+			if (isset($o['shipping_ort']) && ($o['shipping_ort'] != '') && ($o['shipping_adress_id'] == '0'))
+			{
+				
+				$data = array();
+				$data['cdate'] = "NOW()";
+				$data['title'] = $o['shipping_title'];
+				$data['name'] = $o['shipping_name'];
+				$data['vname'] = $o['shipping_vname'];
+				$data['firma'] = $o['shipping_firma'];
+				$data['strasse'] = $o['shipping_strasse'];
+				$data['nr'] = $o['shipping_hausnr'];
+				$data['plz'] = $o['shipping_plz'];
+				$data['ort'] = $o['shipping_ort'];
+				$data['land'] = $o['shipping_land'];
+				$aid = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_ADRESS, $data);
+				
+				$odata = array('shipping_adress_id' => $aid);
+				$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_ORDER, $odata, "`id` = '".$oid."'");
+				
+				$anz1++;
+			}
+				
+		}
+		
+		unset($_REQUEST['action']);
+		echo '<br /><br />';
+		echo $anz1.' Versandadresse(n) von '.$anz2.' Bestellungen neu angelegt.<br /><br />';
+		echo $anz3.' Rechnungsadresse(n) aus den Kunden ÃŒbernommen. '.$anz4.' Kunden nicht gefunden.<br /><br />';
+		
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+		
+	}	// public function M1_Converter_order()
+
+	/**
+	 * Konvertierung der Anrede bei den Adressen.
+	 *
+	 * Herr wird zu 0 und Frau wird zu 1 geÃ€ndert.
+	*/
+	public function M1_Converter_anrede() {
+		
+		$anz1 = 0;
+		$anz2 = 0;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+	<?php
+	    $adress = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ADRESS."` ORDER BY `id` ASC");
+	 
+	    foreach ($adress as $a)
+	    {
+	    	$anz1++;
+
+	    	if (($a['title'] == 'Herr') || ($a['title'] == 'Frau'))
+	    	{
+		    	$aid = $a['id'];
+		    	if ($a['title'] == 'Herr') $title = 0;
+		    	if ($a['title'] == 'Frau') $title = 1;
+	    	
+		    	$data = array('title' => $title);
+		    	$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_ADRESS, $data, "`id` = '".$aid."'");
+
+	    		$anz2++;
+	    	}
+	    	
+	    }
+	    
+	    unset($_REQUEST['action']);
+    	echo '<br /><br />';
+    	echo $anz2.' Anreden von '.$anz1.' Adressen geÃ€ndert.<br /><br />';
+    	
+    	echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+	    
+	}	// public function M1_Converter_anrede()
+
+
+	/**
+	 * PrÃŒfen, ob der Import der Produktbilder und Varianten schon durchgefÃŒhrt wurde.
+	 * 
+	 * @return int  0 oder 1 (1 wenn noch kein Import erfolgt ist, 0 wenn ja)
+	*/
+	public function M1_Converter_prod0() {
+
+		require_once(ABSPATH."wp-admin".'/includes/post.php');
+		date_default_timezone_set('Europe/Berlin');
+		
+		if ( null == get_page_by_title('wpsg_variants_import') ) {
+			// Create the page
+			$arPost = array(
+				'comment_status' => 'closed',
+				'ping_status' => 'closed',
+				'post_author' => 1,
+				'post_date' => date('Y-m-d H:i:s'),
+				'post_name' => 'wpsg_variants_import',
+				'post_title' => 'wpsg_variants_import',
+				'post_status' => 'publish',
+				'post_type' => 'page'
+    		);
+			wp_insert_post($arPost);
+			$this->m1cpb1 = new progressbar(0, 100, 300, 30);
+			$this->m1cpb1->print_code();
+			
+			// Variantentabellen leeren
+			$GLOBALS['wpsg_sc']->db->Query("TRUNCATE `".WPSG_TBL_VARIANTS."`");
+			$GLOBALS['wpsg_sc']->db->Query("TRUNCATE `".WPSG_TBL_VARIANTS_VARI."`");
+			$GLOBALS['wpsg_sc']->db->Query("TRUNCATE `".WPSG_TBL_PRODUCTS_VARIANT."`");
+			$GLOBALS['wpsg_sc']->db->Query("TRUNCATE `".WPSG_TBL_PRODUCTS_VARIATION."`");
+			
+			return '1';
+		} else {
+			// The page exists
+			$page = get_page_by_title('wpsg_variants_import');
+			$ar = get_object_vars($page);
+			$dt1 = $ar['post_date'];
+			$dt2 = wpsg_fromDate($dt1, false);
+			//echo '<br /><br />';
+			//echo 'Ãbernahme der Varianten und Produktbilder ist schon erfolgt am '.$dt2.'.<br /><br />';
+			unset($_REQUEST['action']);
+			return '0';
+		}
+		
+	}	// public function M1_Converter_prod0()
+	
+	/**
+	 * Importieren der Bilder und Varianten eines Produktes.
+	 * 
+	 * Die Produktbilder werden in die Mediathek importiert
+	 * und die Varianten/Variationen aus der Produkt-Tabelle 
+	 * Feld mod_varianten in die neue Tabellenstruktur ÃŒbernommen.
+	 * 
+	*/
+	public function M1_Converter_prod1() {
+		
+		$anz1 = 0;
+		$anz2 = 0;
+		$anz3 = 0;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		<br />
+	<?php
+
+		ini_set('max_execution_time', 1200);
+		
+		$products = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS."` ORDER BY `id` ASC");
+	
+		$i1 = 0;
+		$i2 = 0;
+		$arPostids = array();
+		$arNamen1 = array();	// alter Name
+		$arNamen2 = array();	// neuer Name
+		$pcount = count($products);
+		usleep(5000);			// 5ms
+		
+		//foreach ($products as $p)
+		{
+			
+			$pid = $_REQUEST['pid'];
+			$p = $GLOBALS['wpsg_sc']->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".$pid);
+			
+			// Alle Produktbilder hochladen, postid und neuen Namen merken.
+			// Diese Funktion hat keine Wirkung, wenn PHP im Safe Mode ausgefÃŒhrt wird
+			$temp = set_time_limit(2000);		// Retriggern
+			//if ($temp == false) echo 'set_time_limit=false';
+			$arPic = $this->getProduktBilder($pid);
+			//$arPics = array_unique(array_merge($arPics, $arPic));
+			//$path = 'C:\xampp\htdocs\wp1\wp-content\uploads\wpsg_produktbilder';
+			
+			foreach ($arPic as $pic)
+			{
+				$anz3++;
+				$postid = 0;
+				$this->loadPicture($pic, $pid, $postid, $dname1, $dname2);
+				$arPostids[] = $postid;
+				$arNamen1[] = $dname1;
+				$arNamen2[] = $dname2;
+				
+			}
+			
+			//$pid = $p['id'];
+			$panr = $p['anr'];
+			$arPics = array();
+			
+			if ($p['mod_varianten'] != '')
+			{
+				$arVar = unserialize($p['mod_varianten']);
+				
+				$i1 = 0;
+				
+				foreach ($arVar as $v)
+				{
+					$data = array();
+					if ($v['typ'] == 'checkbox') $data['type'] = 0;
+					if ($v['typ'] == 'select') $data['type'] = 0;
+					if ($v['typ'] == 'radio') $data['type'] = 1;
+					if ($v['typ'] == 'image') $data['type'] = 2;
+					$data['product_id'] = $pid;
+					$data['name'] = $v['name'];
+					$vid1 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_VARIANTS, $data);
+					
+					$data = array();
+					$data['variant_id'] = $vid1;
+					$data['product_id'] = $pid;
+					$data['pos'] = $i1;
+					$vid2 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIANT, $data);
+					
+					if ($v['typ'] == 'checkbox')
+					{	// Checkbox durch Selectbox ersetzen mit zwei Variationen (ja/nein).
+						// Checkbox hat im Shop V3 keine Variationen.
+						$data1 = array();
+						$data1['variant_id'] = $vid1;
+						$data1['name'] = 'ja';
+						$data1['shortname'] = 'ja';
+						$data1['price'] = $v['preis'];
+						$data1[images]= implode(',', $arPostids);
+						if (isset($v['weight'])) $data1['weight'] = $v['weight'];
+						$vvid1 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_VARIANTS_VARI, $data1);
+						$data2 = array();
+						$data2['variation_id'] = $vvid1;
+						$data2['product_id'] = $pid;
+						$data2['active'] = $v['aktiv'];
+						$data2['price'] = $v['preis'];
+						$data2['images']= implode(',', $arPostids);
+						$data2['images_set'] = '';
+						$arpic = wpsg_trim(explode(',', $v['pic']));
+						foreach ($arpic as $pic) {
+							$x = array_search($pic, $arNamen1);
+							if ($x !== false)
+							{
+								if (strlen($data2['images_set']) > 0 ) $data2['images_set'] .= ',';
+								$data2['images_set'] .= $arPostids[$x];
+							}
+						}
+						if (isset($v['weight'])) $data2['weight'] = $v['weight'];
+						$vvid1 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $data2);
+						
+						$data1['name'] = 'nein';
+						$data1['shortname'] = 'nein';
+						$vvid1 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_VARIANTS_VARI, $data1);
+						$data2['variation_id'] = $vvid1;
+						$vvid1 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $data2);
+						
+						//vp_673/0_1|1_2
+						//$i1.'_'.$i2 ersetzen durch $vid1.':'.$vvid1
+						$x1 = $i1.'_'.$i2;
+						$x2 = $vid1.':'.$vvid1;
+						$pk = 'vp_'.$pid;
+						//WHERE `p_id` = $pid   oder  WHERE `productkey` LIKE '%'.$pk.'%'
+						$sql = "UPDATE ".WPSG_TBL_ORDERPRODUCT." SET `productkey` = REPLACE(`productkey`, '".$x1."', '".$x2."') WHERE `p_id`=".$pid;
+						$GLOBALS['wpsg_sc']->db->Query($sql);
+						$i2++;
+						
+					}
+					
+					$anz1++;
+					$i2 = 0;
+					foreach ($v['vari'] as $vv)
+					{
+						$data = array();
+						$data['variant_id'] = $vid1;
+						if (isset($vv['name']))  $data['name'] = $vv['name'];
+						if (isset($vv['name']))  $data['shortname'] = $vv['name'];
+						if (isset($vv['artnr'])) $data['anr'] = $vv['artnr'];
+						else $data['anr'] = $panr;
+						
+						$vvid1 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_VARIANTS_VARI, $data);
+						
+						$sdata = array();
+						if (isset($vv['pic'])) $sdata['pic'] = $vv['pic'];
+						if (isset($vv['picOrder'])) $sdata['picOrder'] = $vv['picOrder'];
+						$arpic = wpsg_trim(explode(',', $vv['pic']));
+						$sdata['postid'] = '';
+						$sdata['postid'] = implode(',', $arPostids);
+						$sdata['pic'] = '';
+						foreach ($arpic as $pic) {
+							$x = array_search($pic, $arNamen1);
+							if ($x !== false)
+							{
+
+								if (strlen($sdata['pic']) > 0 ) $sdata['pic'] .= ',';
+								$sdata['pic'] .= $arPostids[$x];
+							}
+						}
+						
+						if (isset($sdata['picOrder'])) {
+							$sdata['postid'] = '';
+							foreach ($sdata['picOrder'] as &$pic) {
+								$x = array_search($pic, $arNamen1);
+								if ($x !== false)
+								{
+									//$pic = $arNamen2[$x];
+									unset($arNamen1[$x]);
+									if (strlen($sdata['postid']) > 0 ) $sdata['postid'] .= ',';
+									$sdata['postid'] .= $arPostids[$x];
+									unset($arPostids[$x]);
+								}
+							}
+							foreach ($arPostids as $postid) {
+								if (strlen($sdata['postid']) > 0 ) $sdata['postid'] .= ',';
+								$sdata['postid'] .= $postid;
+							}
+						}
+						
+						$data = array();
+						$data['variation_id'] = $vvid1;
+						$data['product_id'] = $pid;
+						if (isset($vv['aktiv'])) $data['active'] = $vv['aktiv'];
+						if (isset($vv['artnr'])) $data['anr'] = $vv['artnr'];
+						else $data['anr'] = $panr;
+						
+						if (isset($vv['preis'])) $data['price'] = $vv['preis'];
+						if (isset($vv['stock'])) $data['stock'] = $vv['stock'];
+						//$data['images'] = $ser;
+						$data['images'] = $sdata['postid'];
+						$data['images_set'] = $sdata['pic'];
+						$vvid2 = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $data);
+						
+						if (isset($vv['pic']))
+						{
+							$arPicsVariante = wpsg_trim(explode(',', $vv['pic']));
+							$arPics = array_unique(array_merge($arPics, $arPicsVariante));
+						}
+						$anz2++;
+						
+						//vp_673/0_1|1_2
+						//$i1.'_'.$i2 ersetzen durch $vid1.':'.$vvid1
+						$x1 = $i1.'_'.$i2;
+						$x2 = $vid1.':'.$vvid1;
+						$pk = 'vp_'.$pid;
+						//WHERE `p_id` = $pid   oder  WHERE `productkey` LIKE '%'.$pk.'%'
+						$sql = "UPDATE ".WPSG_TBL_ORDERPRODUCT." SET `productkey` = REPLACE(`productkey`, '".$x1."', '".$x2."') WHERE `p_id`=".$pid;
+						$GLOBALS['wpsg_sc']->db->Query($sql);
+						$i2++;
+						
+					}
+					$i1++;
+					
+				}	// foreach ($arVar as $v)
+				
+				// 'vp_'.$pid.'/'  ersetzen durch  'pv_'.$pid.'|'
+				$x1 = 'vp_'.$pid.'/';
+				$x2 = 'pv_'.$pid.'|';
+				$sql = "UPDATE ".WPSG_TBL_ORDERPRODUCT." SET `productkey` = REPLACE(`productkey`, '".$x1."', '".$x2."') WHERE `p_id`=".$pid;
+				$GLOBALS['wpsg_sc']->db->Query($sql);
+
+				// Tabelle Produkte postids lÃ¶schen
+				$sql = "UPDATE ".WPSG_TBL_PRODUCTS." SET `postids` = '' WHERE `id`=".$pid;
+				$GLOBALS['wpsg_sc']->db->Query($sql);
+				
+			}	// if ($p['mod_varianten'] != '')
+			
+			$this->m1cpb1->step(100 / $pcount);
+		}	// foreach ($products as $p)
+		
+		//if (($num + 1) == $pcount)
+		{
+			echo $pcount.' Produkte analysiert.<br /><br />';
+			unset($_REQUEST['action']);
+			echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+			
+		}
+		
+		ini_set('max_execution_time', 30);
+		
+	}	// public function M1_Converter_prod1()
+
+	/**
+	 * Laden des Bildes in den Mediathek-Ordner und Eintragen der 
+	 * Informationen in die Tabelle wp_posts und wp_postmeta.
+	 * 
+	 * @param string $pic	Dateiname des Bildes
+	 * @param string $pid	Produkt-ID
+	 * @param string $postid	Post-ID
+	 * @param string $dname1	Dateiname
+	 * @param string $dname2	Basename
+	*/
+	public function loadPicture($pic, $pid, &$postid, &$dname1, &$dname2)
+	{
+		//$file = $path.'/'.$pid.'/'.$pic;
+		$path = $this->getPicPath($pid);
+		$file = $path.$pic;
+		if (!file_exists($file)) return;
+		
+		$filename = basename($file);
+		$parent_post_id = 0;
+		$wp_upload_dir = wp_upload_dir();
+		
+		// LÃ€dt das Bild in den Mediathek-Ordner (uploads/yyyy/mm/)
+		$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
+		if (!$upload_file['error']) {
+			$wp_filetype = wp_check_filetype($filename, null);
+			$arFn = pathinfo($upload_file['file']); 
+			$attachment = array(
+					'guid' => $wp_upload_dir['url'] . '/' . $filename,
+					'guid' => $upload_file['url'],
+					'post_mime_type' => $wp_filetype['type'],
+					'post_parent' => $parent_post_id,
+					'post_title' => preg_replace('/\.[^.]+$/', '', $arFn['basename']),
+					'post_excerpt' => $arFn['basename'],
+					'post_parent' => '0',
+					'wpsg_produkt_id' => $pid,
+					'post_content' => '',
+					'post_status' => 'inherit'
+			);
+			// Eintrag in wp_posts und wp_postmeta (_wp_attached_file)
+			// Returns the resulting post ID (int) on success or 0 (int) on failure.
+			$attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], $parent_post_id );
+			$postid = $attachment_id;
+			$dname2 = $arFn['basename'];
+			$dname1 = $filename;
+			//$attachment_id = media_handle_upload( '0', 0, $attachment );	//OK
+			// Eintrag in wp_postmeta (wpsg_produkt_id)
+			add_post_meta( $attachment_id, 'wpsg_produkt_id', $pid );
+			
+			if (!is_wp_error($attachment_id)) {
+				require_once(ABSPATH . "wp-admin" . '/includes/image.php');
+				// Erzeugt attachment-metadata
+				$attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
+				// Eintrag in wp_postmeta (_wp_attachment_metadata)
+				wp_update_attachment_metadata( $attachment_id, $attachment_data );
+			}
+		}
+		
+	}
+	
+	
+	/**
+	 * Zippen der Produktbilder
+	 * 
+	 * LÃ¶schen der Thumbnails und Zippen der Produktbilder von WPSG Version 3
+	 * in die Datei uploads/wpsg_produktbilder/backup.zip
+	 * 
+	*/
+	public function M1_Converter_zip() {
+		
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+	<?php
+	
+		ini_set('max_execution_time', 300);
+		
+		$products = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS."` ORDER BY `id` ASC");
+	
+		// Thumbnail-Verzeichnisse lÃ¶schen
+		foreach ($products as $p)
+		{
+	
+			$path_post_thumbnail = $this->getPicPath($p['id'], false, false).'tn/';
+			wpsg_rrmdir($path_post_thumbnail);
+	
+		}
+		
+		//$path = 'C:/xampp/htdocs/wp2/wp-content/uploads/wpsg_produktbilder/';
+		$path = $this->getPicPath('');
+		$path = str_replace('//', '/', $path);
+		$path = str_replace('\\', '/', $path);
+		$zpath = $path.'backup.zip';
+		
+		$oldPath = getcwd();
+		if (chdir($path) != true) {
+			die("ERROR: Could not change directory");
+		}
+		
+		// Objekt erstellen und prÃŒfen, ob der Server zippen kann
+		$zip = new ZipArchive();
+		// ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ÃŒberschreibt nicht das Archiv,
+		// deshalb die Archivdatei vorher lÃ¶schen
+		if (file_exists($zpath)) unlink($zpath);
+		
+		if ($zip->open($zpath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
+			die ("ERROR: Could not open archive");
+		}
+		
+		// Gehe durch die Ordner und fÃŒge alle Dateien zum Archiv hinzu
+		$len = strlen($path);
+		$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
+		foreach ($iterator as $key => $value) {
+			if (substr($key, strlen($key) - 1) != '.') {
+				$filename = substr($key, $len);
+				$zip->addFile(realpath($key), $filename) or die ("ERROR: Could not add file: $key");
+				echo $key.'<br />';
+			}
+		}
+		
+		// Zip-Datei speichern
+		$anz = $zip->numFiles;
+		$zip->close();
+		echo "<br />Archiv erfolgreich erstellt.";
+		chdir($oldPath);
+		
+		echo '<br /><br />';
+		echo $anz.' Dateien komprimiert.<br /><br />';
+		
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+	
+		ini_set('max_execution_time', 30);
+		
+	}	// public function M1_Converter_zip()
+
+	/**
+	 * Unzippen der Produktbilder
+	 *
+	 * Entpacken der Produktbilder in das Verzeichnis uploads/wpsg_produktbilder.
+	 *
+	 */
+	public function M1_Converter_unzip() {
+		
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+	<?php
+	
+		ini_set('max_execution_time', 300);
+		
+		//$path = 'C:/xampp/htdocs/wp2/wp-content/uploads/wpsg_produktbilder/';
+		$path = $this->getPicPath('');
+		$path = str_replace('//', '/', $path);
+		$path = str_replace('\\', '/', $path);
+		$zpath = $path.'backup.zip';
+		
+		// Objekt erstellen und prÃŒfen, ob der Server unzippen kann
+		$zip = new ZipArchive();
+		
+		if ($zip->open($zpath) !== TRUE) {
+			die ("ERROR: Could not open archive");
+		}
+		
+		if ($zip->extractTo($path) == true) echo '<br /><br />ZIP-Archiv erfolgreich entpackt.<br /><br />';
+		else echo '<br /><br />Fehler beim Entpacken des ZIP-Archivs.<br /><br />';
+	
+		$zip->close();
+		
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+	
+		ini_set('max_execution_time', 30);
+		
+	}	// public function M1_Converter_unzip()
+
+	/**
+	 * Ãndern der Kategorie von category in wpsgtax in der Tabelle wp_term_taxonomy
+	 * 
+	*/
+	public function M1_Converter_category() {
+		
+		global $myprogressbar1;
+		global $GLOBALS;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		$anz = 0;
+	
+		$sql = "SELECT * FROM `".$GLOBALS['wpdb']->prefix."term_relationships`";
+		$arTRel = $GLOBALS['wpsg_sc']->db->fetchAssoc($sql);
+	
+		$pathkey = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_produktartikel_pathkey'));
+	
+		foreach ($arTRel AS $trel) {
+		
+			$sql = "SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID` = '".wpsg_q($trel['object_id'])."'";
+			$arPosts = $GLOBALS['wpsg_sc']->db->fetchRow($sql);
+		
+			if ($arPosts['post_type'] == $pathkey) {
+			
+				$tt_id = $trel['term_taxonomy_id'];
+			
+				// Tabelle wp_term_taxonomy Feld taxonomy von category in wpsgtax Ã€ndern
+				$data = array(
+					'taxonomy' => 'wpsgtax'
+				);
+				$krit = "`term_taxonomy_id` = '".wpsg_q($tt_id)."' AND `taxonomy` = '".wpsg_q('category')."'";
+				$tname = $GLOBALS['wpdb']->prefix."term_taxonomy";
+				$GLOBALS['wpsg_sc']->db->UpdateQuery($GLOBALS['wpdb']->prefix."term_taxonomy", $data, "`term_taxonomy_id` = '".wpsg_q($tt_id)."' AND `taxonomy` = '".wpsg_q('category')."'");
+			
+				$anz++;
+			}
+			
+		}
+	
+		//$mp->set(15); // auf 15 % setzen
+		//$mp->complete(); // fertig!
+		
+		echo '<br /><br />';
+		echo $anz.' Kategorien geÃ€ndert von category auf wpsgtax.<br /><br />';
+	
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+		ini_set('max_execution_time', 30);
+	
+	}	// public function M1_Converter_category()
+
+	/**
+	 * Umkopieren der Lieferscheine in die neue Verzeichnisstruktur.
+	 * 
+	 * Lieferscheine kopieren von
+	 * C:\xampp\htdocs\wp2\wp-content\uploads\wpsg\wpsg_deliverynote\order_id\deliverynote_dn_id.pdf
+	 * nach
+	 * C:\xampp\htdocs\wp2\wp-content\uploads\wpsg\wpsg_deliverynote\yyyy\mm\order_id
+	 * 
+	*/
+	public function M1_Converter_lief() {
+		
+		global $myprogressbar1;
+		global $GLOBALS;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		$anz1 = 0;
+		$anz2 = 0;
+		
+		$liefs = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_DELIVERYNOTE."` ORDER BY `id` ASC");
+		
+		foreach ($liefs AS $lief) {
+		
+			$datum = $lief['cdate'];
+			$ym = date('Y/m/', strtotime($datum));
+			$fname = 'deliverynote_'.$lief['id'].'.pdf';
+			$oid = $lief['order_id'];
+			
+			if ($GLOBALS['wpsg_sc']->isMultiBlog())
+			{
+				$from = WPSG_PATH_CONTENT.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_deliverynote/'.$oid.'/';
+				$to = WPSG_PATH_CONTENT.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_deliverynote/'.$ym.$oid.'/';
+			}
+			else
+			{
+				$from = WPSG_PATH_CONTENT.'uploads/wpsg/wpsg_deliverynote/'.$oid.'/';
+				$to = WPSG_PATH_CONTENT.'uploads/wpsg/wpsg_deliverynote/'.$ym.$oid.'/';
+			}
+			$anz1++;
+			
+			if (file_exists($from.$fname))
+			{
+				if (!is_dir($to)) {
+					mkdir($to, 0777, true);
+				}
+				//mkdir($to, 0777, true);
+				copy($from.$fname, $to.$fname);
+				$anz2++;
+			}
+			
+		}
+	
+		//$mp->set(15); // auf 15 % setzen
+		//$mp->complete(); // fertig!
+		
+		echo '<br /><br />';
+		echo $anz1.' Lieferscheine bearbeitet.<br /><br />';
+		echo $anz2.' Lieferscheindateien kopiert.<br /><br />';
+		
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+		ini_set('max_execution_time', 30);
+	
+	}	// public function M1_Converter_lief()
+	
+	/**
+	 * Umkopieren der Rechnungen in die neue Verzeichnisstruktur.
+	 * 
+	 * Rechnungen kopieren von
+	 * C:\xampp\htdocs\wp2\wp-content\uploads\wpsg_rechnungen\order_id\re_id.pdf
+	 * nach
+	 * C:\xampp\htdocs\wp2\wp-content\uploads\wpsg\wpsg_rechnungen\yyyy\mm\order_id
+	 * 
+	*/
+	public function M1_Converter_rech() {
+		
+		global $myprogressbar1;
+		global $GLOBALS;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		$anz1 = 0;
+		$anz2 = 0;
+		
+		$rechs = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` ORDER BY `id` ASC");
+		
+		foreach ($rechs AS $rech) {
+		
+			$datum = $rech['datum'];
+			$ym = date('Y/m/', strtotime($datum));
+			$fname = ''.$rech['id'].'.pdf';
+			$oid = $rech['o_id'];
+			
+			if ($GLOBALS['wpsg_sc']->isMultiBlog())
+			{
+				$from = WPSG_PATH_CONTENT.'/'.WPSG_MB_UPLOADS.'/wpsg_rechnungen/'.$oid.'/';
+				$to = WPSG_PATH_CONTENT.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_rechnungen/'.$ym.$oid.'/';
+			}
+			else
+			{
+				$from = WPSG_PATH_CONTENT.'uploads/wpsg_rechnungen/'.$oid.'/';
+				$to = WPSG_PATH_CONTENT.'uploads/wpsg/wpsg_rechnungen/'.$ym.$oid.'/';
+			}
+			$anz1++;
+			
+			if (file_exists($from.$fname))
+			{
+				if (!is_dir($to)) {
+					mkdir($to, 0777, true);
+				}
+				//mkdir($to, 0777, true);
+				copy($from.$fname, $to.$fname);
+				$anz2++;
+			}
+			
+		}
+	
+		//$mp->set(15); // auf 15 % setzen
+		//$mp->complete(); // fertig!
+		
+		echo '<br /><br />';
+		echo $anz1.' Rechnungen/Gutschriften bearbeitet.<br /><br />';
+		echo $anz2.' Rechnungs-/Gutschrift-Dateien kopiert.<br /><br />';
+		
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+		ini_set('max_execution_time', 30);
+	
+	}	// public function M1_Converter_rech()
+	
+	/**
+	 * LÃ¶schen der Produktbilder in der Mediathek und der zugehÃ¶rigen
+	 * EintrÃ€ge in wp_posts und wp_postmeta.
+	 *  
+	*/
+	public function M1_Converter_media() {
+
+	?>
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		
+		ini_set('max_execution_time', 1200);
+
+		//wp_delete_post( $postid, $force_delete );
+		//wp_delete_attachment( $attachmentid, $force_delete );
+		//SELECT * FROM `wp_postmeta` WHERE `meta_key`='wpsg_produkt_id' AND `meta_value`=11
+		
+		$post_id = $_REQUEST['post_id'];
+		wp_delete_attachment($post_id, true);
+		
+		$GLOBALS['wpsg_sc']->db->Query("DELETE FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `post_title` = '".wpsg_q('wpsg_variants_import')."' ");
+		
+	}
+
+	/**
+	 * Berechnen der Preise netto/brutto, da diese vorher nicht gefÃŒhrt wurden.
+	 * 
+	 * Wenn die Preise netto/brutto 0 sind, diese neu berechnen,
+	 * denn diese sind erst in neueren WPSG3-Versionen benutzt.
+	 * 
+	*/
+	public function M1_Converter_preis() {
+		
+		global $myprogressbar1;
+		global $GLOBALS;
+	?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		$anz1 = 0;	// Bestellungen
+		$anz2 = 0;	// Bestellte Produkte
+	
+		$order = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDER."` ORDER BY `id` ASC");
+	
+		foreach ($order as $o)
+		{
+			if (!wpsg_isSized($o['price_gesamt_netto']) && !wpsg_isSized($o['price_gesamt_brutto']))
+			{
+				// Wenn die Preise netto/brutto 0 sind, diese neu berechnen.
+				$odata = array();
+				
+				$adress = $GLOBALS['wpsg_sc']->db->fetchRow("SELECT * FROM `".WPSG_TBL_ADRESS."` WHERE `id` = '".wpsg_q($o['adress_id'])."' ");
+				if (wpsg_isSizedInt($adress['land']))
+					$land = $adress['land'];
+				else
+					$land = 1;
+				
+				$country = wpsg_country::getInstance($land);
+				$arcountry = get_object_vars($country);
+				$arcountry = $arcountry['data'];
+			
+				// Tabelle wp_wpsg_order_products berechnen und updaten
+				$oProds = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDERPRODUCT."` WHERE `o_id` = '".wpsg_q($o['id'])."' ");
+				
+				$sum_netto = 0.0;
+				$sum_brutto = 0.0;
+				
+				foreach ($oProds as $op)
+				{
+					// Aus Tabelle wp_wpsg_products mwst_key holen
+					$prod = $GLOBALS['wpsg_sc']->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($op['p_id'])."' ");
+					
+					if ($prod['mwst_key'] == 'a')
+						$mwst = $arcountry['mwst_a'];
+					else if ($prod['mwst_key'] == 'b')
+						$mwst = $arcountry['mwst_b'];
+					else if ($prod['mwst_key'] == 'c')
+						$mwst = $arcountry['mwst_c'];
+					else if ($prod['mwst_key'] == 'd')
+						$mwst = $arcountry['mwst_d'];
+					else $mwst = 0.0;
+					
+					if (!wpsg_isSized($mwst)) $mwst = 0.0;
+					$mwst = $mwst / 100;
+					
+					// mwst_value, price_netto, price_brutto, mwst_key, mod_vp_varkey berechnen
+					$opdata = array();
+					$opdata['mod_vp_varkey'] = '';
+					$opdata['mwst_key'] = $prod['mwst_key'];
+					
+					if (!wpsg_isSized($op['price_brutto']) && !wpsg_isSized($op['price_netto']))
+					{
+					
+						if ($o['price_frontend'] == WPSG_BRUTTO)
+						{
+							$opdata['price_brutto'] = $op['price'];
+							$opdata['price_netto'] = $op['price'] / (1 + $mwst);
+							$opdata['mwst_value'] = $opdata['price_brutto'] - $opdata['price_netto'];
+						}
+						else
+						{
+							$opdata['price_netto'] = $op['price'];
+							$opdata['price_brutto'] = $op['price'] * (1 + $mwst);
+							$opdata['mwst_value'] = $op['price'] * $mwst;
+						}
+					
+						// Summieren fÃŒr Tabelle wp_wpsg_order
+						$sum_netto += $op['menge'] * $opdata['price_netto'];
+						$sum_brutto += $op['menge'] * $opdata['price_brutto'];
+
+					}
+					else
+					{
+						$sum_netto += $op['menge'] * $op['price_netto'];
+						$sum_brutto += $op['menge'] * $op['price_brutto'];
+					}
+					
+					// Tabelle wp_wpsg_order_products updaten
+					$anz2++;
+					$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_ORDERPRODUCT, $opdata, "`id` = '".$op['id']."'");
+					
+				}
+				
+				$mwsta = $sum_brutto / $sum_netto;
+				
+				// Preise in wp_wpsg_order berechnen
+				if ($o['price_frontend'] == WPSG_BRUTTO)
+				{
+					if ($o['price_gs'] > 0)
+					{
+						$odata['price_gs_brutto'] = $o['price_gs'];
+						$odata['price_gs_netto'] = $o['price_gs'] / $mwsta;
+					}
+					$sum_brutto -= $odata['price_gs_brutto'];
+					$sum_netto -= $odata['price_gs_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+					if ($o['price_rabatt'] > 0)
+					{
+						$odata['price_rabatt_brutto'] = $o['price_rabatt'];
+						$odata['price_rabatt_netto'] = $o['price_rabatt'] / $mwsta;
+					}
+					$sum_brutto -= $odata['price_rabatt_brutto'];
+					$sum_netto -= $odata['price_rabatt_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+					if ($o['price_payment'] > 0)
+					{
+						$sp = $GLOBALS['wpsg_sc']->arPayment[$o['type_payment']];
+						if ($sp['mwst_key'] == '0') $mwstx = $mwsta; else $mwstx=$sp['mwst_value'] / 100 + 1;
+						$odata['price_payment_brutto'] = $o['price_payment'];
+						$odata['price_payment_netto'] = $o['price_payment'] / $mwsta;
+						$odata['mwst_payment'] = $odata['price_payment_brutto'] - $odata['price_payment_netto'];
+					}
+					$sum_brutto += $odata['price_payment_brutto'];
+					$sum_netto += $odata['price_payment_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+					if ($o['price_shipping'] > 0)
+					{
+						$sp = $GLOBALS['wpsg_sc']->arShipping[$o['type_shipping']];
+						if ($sp['mwst_key'] == '0') $mwstx = $mwsta; else $mwstx=$sp['mwst_value'] / 100 + 1;
+						$odata['price_shipping_brutto'] = $o['price_shipping'];
+						$odata['price_shipping_netto'] = $o['price_shipping'] / $mwstx;
+						$odata['mwst_shipping'] = $odata['price_shipping_brutto'] - $odata['price_shipping_netto'];
+					}
+					$sum_brutto += $odata['price_shipping_brutto'];
+					$sum_netto += $odata['price_shipping_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+				}
+				else	// if ($o['price_frontend'] == WPSG_BRUTTO)
+				{
+					if ($o['price_gs'] > 0)
+					{
+						$odata['price_gs_brutto'] = $o['price_gs'];
+						$odata['price_gs_netto'] = $o['price_gs'] * $mwsta;
+					}
+					$sum_brutto -= $odata['price_gs_brutto'];
+					$sum_netto -= $odata['price_gs_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+					if ($o['price_rabatt'] > 0)
+					{
+						$odata['price_rabatt_brutto'] = $o['price_rabatt'];
+						$odata['price_rabatt_netto'] = $o['price_rabatt'] * $mwsta;
+					}
+					$sum_brutto -= $odata['price_rabatt_brutto'];
+					$sum_netto -= $odata['price_rabatt_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+					if ($o['price_payment'] > 0)
+					{
+						$sp = $GLOBALS['wpsg_sc']->arPayment[$o['type_payment']];
+						if ($sp['mwst_key'] == '0') $mwstx = $mwsta; else $mwstx=$sp['mwst_value'] / 100 + 1;
+						$odata['price_payment_brutto'] = $o['price_payment'];
+						$odata['price_payment_netto'] = $o['price_payment'] * $mwstx;
+						$odata['mwst_payment'] = $o['price_payment'] * ($mwstx - 1);
+					}
+					$sum_brutto += $odata['price_payment_brutto'];
+					$sum_netto += $odata['price_payment_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+					if ($o['price_shipping'] > 0)
+					{
+						$sp = $GLOBALS['wpsg_sc']->arShipping[$o['type_shipping']];
+						if ($sp['mwst_key'] == '0') $mwstx = $mwsta; else $mwstx=$sp['mwst_value'] / 100 + 1;
+						$odata['price_shipping_brutto'] = $o['price_shipping'];
+						$odata['price_shipping_netto'] = $o['price_shipping'] * $mwstx;
+						$odata['mwst_shipping'] = $o['price_shipping'] * ($mwstx - 1);
+					}
+					$sum_brutto += $odata['price_shipping_brutto'];
+					$sum_netto += $odata['price_shipping_netto'];
+					$mwsta = $sum_brutto / $sum_netto;
+					
+				}	// if ($o['price_frontend'] == WPSG_BRUTTO)  else
+					
+				$odata['price_gesamt_netto'] = $sum_netto;
+				$odata['price_gesamt_brutto'] = $sum_brutto;
+				
+				// Tabelle wp_wpsg_order updaten
+				$anz1++;
+				$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_ORDER, $odata, "`id` = '".$o['id']."'");
+				
+			}
+		
+		}	// foreach ($order as $o)
+	
+		//$mp->complete(); // fertig!
+	
+		echo '<br /><br />';
+		echo $anz1.' Bestellungen bearbeitet.<br /><br />';
+		echo $anz2.' Bestellte Produkte bearbeitet.<br /><br />';
+		
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+		ini_set('max_execution_time', 30);
+	
+	}	// public function M1_Converter_preis()
+	
+	/**
+	 * Allgemeine Konvertierungsfunktionen
+	 * 
+	 * Shop V3 Zahlungsart Rechnung (4) als Zahlvariante anlegen, wenn verwendet.
+	 * Tabelle WPSG_TBL_ORDER Feld type_payment.
+	 * In der Tabelle wp_options sind die Einstellungen fÃŒr die Zahlungsart
+	 * Rechnung enthalten, wenn sie im Shop V3 benutzt wurde.
+	 * 
+	 */
+	public function M1_Converter_allgemein() {
+		
+		global $myprogressbar1;
+		global $GLOBALS;
+		?>
+		<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'M1-Converter/style.css'; ?>" type="text/css" media="all" />
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		$anz1 = 0;
+		$anz2 = 0;
+		
+		$orders = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDER."` WHERE `type_payment`='4' ORDER BY `id` ASC");
+		
+		// Test
+		/*
+		$GLOBALS['wpsg_sc']->update_option('wpsg_mod_invoice_type_bezeichnung', 'Rechnung');
+		$GLOBALS['wpsg_sc']->update_option('wpsg_mod_invoice_type_gebuehr', 2);
+		$GLOBALS['wpsg_sc']->update_option('wpsg_mod_invoice_type_hint', 'Rechnung-Beschreibung');
+		$GLOBALS['wpsg_sc']->update_option('wpsg_mod_invoice_type_aktiv', 1);
+		$GLOBALS['wpsg_sc']->update_option('wpsg_mod_invoice_type_mwst', 'c');
+		$GLOBALS['wpsg_sc']->update_option('wpsg_mod_invoice_type_mwstland', 0);
+		*/
+		
+		if (wpsg_isSizedArray($orders)) {
+			// Zahlvariante anlegen
+			$data = array();
+			$data['name'] = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_invoice_type_bezeichnung'));
+			$data['rabgeb'] = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_invoice_type_gebuehr'));
+			$data['hint'] = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_invoice_type_hint'));
+			$data['mwst_key'] = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_invoice_type_mwst'));
+			$data['mwst_laender'] = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_invoice_type_mwstland'));
+			$data['aktiv'] = wpsg_q($GLOBALS['wpsg_sc']->get_option('wpsg_mod_invoice_type_aktiv'));
+			
+			$zid = $GLOBALS['wpsg_sc']->db->ImportQuery(WPSG_TBL_ZV, $data);
+			
+			$zdata = array();
+			$zdata['type_payment'] = $zid;
+			
+			// Zahlvariante bei diesen Produkten korrigieren
+			foreach ($orders as $order) {
+				$oid = $order['id'];
+				$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_ORDER, $zdata, "`id` = '".$oid."'");
+				$anz1++;
+			}
+			
+		}
+		
+		echo '<br /><br />';
+		echo $anz1.' Bestellungen Zahlungsart Rechnungen korrigiert.<br /><br />';
+		
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button" href="'.admin_url('admin.php?page=M1_Converter_dispatch&action=show">ZurÃŒck</a><br />');
+		ini_set('max_execution_time', 30);
+	
+	}	// public function M1_Converter_allgemein()
+	
+	public function M1_Converter_test() {
+		
+		global $myprogressbar1;
+		global $GLOBALS;
+	?>
+	    <div class="wrap">
+	        <h2>M1-Converter</h2>
+		</div>
+		
+	<?php
+		
+		ini_set('max_execution_time', 1200);
+	
+		$fn1 = sanitize_title('Baby bumble chrom.jpg');
+		$fn2 = sanitize_file_name('Baby bumble chrom.jpg');
+		$fn3 = sanitize_file_name('Baby-- bumble chrom.jpg');
+		
+		$products = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS."` ORDER BY `id` ASC");
+		
+		$i1 = 0;
+		$i2 = 0;
+		$anz = count($products);
+
+		echo '<br /><br />';
+		echo $anz.' Produkte.<br /><br />';
+		$this->m1cpb1->print_code();
+		
+		$test = unserialize('a:1:{i:1;a:4:{s:4:"name";s:5:"Farbe";s:3:"typ";s:6:"select";s:5:"aktiv";s:1:"1";s:4:"vari";a:5:{i:0;a:7:{s:4:"name";s:3:"rot";s:5:"preis";s:1:"0";s:5:"aktiv";s:1:"1";s:3:"pic";s:51:",bimble-baby-red-1-small.png,bimble-red-2-small.png";s:5:"artnr";s:5:"10-12";s:5:"stock";s:1:"2";s:6:"weight";s:1:"0";}i:1;a:7:{s:4:"name";s:7:"limette";s:5:"preis";s:1:"0";s:5:"aktiv";s:1:"1";s:3:"pic";s:24:",bimble-lime-2-small.png";s:5:"artnr";s:5:"10-14";s:5:"stock";s:1:"1";s:6:"weight";s:1:"0";}i:2;a:6:{s:4:"name";s:4:"gelb";s:5:"preis";s:0:"";s:5:"aktiv";s:1:"1";s:5:"stock";s:1:"3";s:5:"artnr";s:5:"10-11";s:3:"pic";s:26:",bimble-yellow-2-small.png";}i:3;a:6:{s:4:"name";s:7:"violett";s:5:"preis";s:0:"";s:5:"aktiv";s:1:"1";s:5:"stock";s:1:"3";s:5:"artnr";s:5:"10-13";s:3:"pic";s:26:",bimble-purple-2-small.png";}i:4;a:6:{s:4:"name";s:7:"tÃŒrkis";s:5:"preis";s:0:"";s:5:"aktiv";s:1:"1";s:5:"stock";s:1:"3";s:5:"artnr";s:5:"10-15";s:3:"pic";s:24:",bimble-cyan-2-small.png";}}}}');
+
+
+		foreach ($products as $p)
+		{
+			$varis = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id`='".wpsg_q($p['id'])."' ");
+			
+			foreach ($varis as $v)
+			{
+				$im0 = unserialize($v['images']);
+				
+				$im1 = array();
+				$im1 = $im0;
+				//$im1['pic'] = array(); 
+				//$im1['picOrder'] = $im0['picOrder'];
+				//$im1['postid'] = array();
+				
+				$pids = explode(',', $im0['postid']);
+				$postid = array();
+				$pic = array();
+				foreach ($pids as $pid)
+				{
+					
+					$post = $GLOBALS['wpsg_sc']->db->fetchRow("SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID` = '".wpsg_q($pid)."' ");
+					if (isset($post['ID'])) 
+					{
+						$postid[] = $post['ID'];
+						$pic[] = $post['post_excerpt'];
+					}
+				}
+				$im1['pic'] = implode(',', $pic);
+				$im1['postid'] = implode(',', $postid);
+				$images = serialize($im1);
+				// Update WPSG_TBL_PRODUCTS_VARIATION
+				$data = array('images' => $images);
+				////$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, $data, "`id` = '".wpsg_q($v['id'])."'");
+				
+			}
+			
+		}
+		
+		
+		//wp_delete_post( $postid, $force_delete );
+		//wp_delete_attachment( $attachmentid, $force_delete );
+		//SELECT * FROM `wp_postmeta` WHERE `meta_key`='wpsg_produkt_id' AND `meta_value`=11
+		
+		$posts = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `meta_key`='".wpsg_q('wpsg_produkt_id')."' ORDER BY `post_id`");
+		foreach ($posts AS $post) {
+			////wp_delete_attachment($post['post_id'], true);
+			
+		}
+		////$GLOBALS['wpsg_sc']->db->Query("DELETE FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `post_title` = '".wpsg_q('wpsg_variants_import')."' ");
+		
+		foreach ($products as $p)
+		{
+			$arPic = $this->getProduktBilder($p['id'], false);
+			$i1++;
+			$i2 = $i2 + count($arPic);
+
+			$mp = $this->m1cpb1;
+			$mp->step(100 / $anz);
+			usleep(20000);			// 20ms
+			//sleep(1);
+			$temp = set_time_limit(2000);		// Retriggern
+			//if ($temp == false) echo 'set_time_limit=false ';
+			
+		}
+		
+		//$mp->set(15); // auf 15 % setzen
+		$mp->complete(); // fertig!
+		
+		echo '<br /><br />';
+		echo $anz.' Produkte.<br /><br />';
+	
+		unset($_REQUEST['action']);
+		echo '<a class="m1c_button " style="cursor:pointer; margin-top:10px; width:120px; text-align:center; padding:5px 5px 5px 5px; line-height:28px; border:1px solid #29556E; color:#29556E; background-color:#ffffff; font-weight:bold; display:inline-block;text-decoration:none;" href="';
+		echo admin_url('admin.php?page=M1_Converter_dispatch');
+		echo '">ZurÃŒck</a><br />';
+		ini_set('max_execution_time', 30);
+	
+	}	// public function M1_Converter_test()
+	
+
+	/*
+	 * Gibt den absoluten Pfad zurÃŒck wo die Bilder gespeichert sind
+	 * Ist der Parameter $url auf true so wird der relative Pfad fÃŒr die Ausgabe in 
+	 * URLs zurÃŒckgegeben.
+	 * 
+	 */
+	public function getPicPath($produkt_id, $url = false, $mkdir = true)
+	{
+		
+		if ($GLOBALS['wpsg_sc']->isMultiBlog())
+		{
+			
+			if ($url) return WPSG_URL_CONTENT.WPSG_MB_UPLOADS.'/wpsg/wpsg_produktbilder/'.$produkt_id.'/';
+			else
+			{
+				
+				$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_produktbilder/'.$produkt_id.'/';
+				
+				if (!file_exists($path) && ($mkdir == true)) mkdir($path, 0777, true);
+				
+				return $path;
+				
+			}
+			
+		}
+		else
+		{
+			
+			if ($url) return WPSG_URL_CONTENT.'uploads/wpsg_produktbilder/'.$produkt_id.'/';
+			else
+			{
+				
+				$path = WP_CONTENT_DIR.'/uploads/wpsg_produktbilder/'.$produkt_id.'/';
+				
+				if (!file_exists($path) && ($mkdir == true)) mkdir($path, 0777, true);
+				
+				return $path;
+				
+			}
+			
+		}
+		
+	} // function getPicPath($produkt_id, $url = false)
+
+	/**
+	 * Gibt ein Array mit den Produktbildern zurÃŒck
+	 */
+	public function getProduktBilder($produkt_id, $mkdir = true)
+	{
+		
+		$arFiles = array();
+		
+		// Bilder aus dem Dateisystem raussuchen
+		$path = $this->getPicPath($produkt_id, false, $mkdir);
+		
+		if (!file_exists($path) && ($mkdir == false)) return array();
+		
+		$handle = opendir($path);
+		
+		while ($filename = readdir($handle))
+		{
+			
+			if (is_file($path.'/'.$filename) && $filename != '.' && $filename != '..' && $filename != '')
+			{
+				
+				$arFiles[] = $filename;
+				
+			}
+			
+		}
+		
+		wpsg_asort($arFiles);
+		
+		$arReturn = array();
+		foreach ($arFiles as $k => $v) $arReturn[] = $v;
+		
+		return $arReturn;
+		
+	} // function getProduktBilder($produkt_id)
+
+} // class M1_Converter
+?>
Index: /mods/mod_converter/M1_progressbar.class.php
===================================================================
--- /mods/mod_converter/M1_progressbar.class.php	(revision 6540)
+++ /mods/mod_converter/M1_progressbar.class.php	(revision 6540)
@@ -0,0 +1,94 @@
+<?php
+/*
+*	PHP Fortschrittsbalken v1.3
+*	(c) 2010 by Fabian Schlieper
+*	fabian@fabi.me
+*	http://fabi.me/
+*/
+
+class progressbar1
+{
+	private static $js_prefix = "_pbr_";
+	
+	private static function _echo( $string )
+	{
+		echo $string;
+		@ob_flush();
+		@flush();
+	}
+	
+	private static function execute_js($code, $short_tag=true)
+	{
+		$code = trim($code);
+		self::_echo($short_tag ? "<script>$code</script>" : "<script type=\"text/javascript\"><!--\n$code\n// --></script>");
+	}
+		
+	private $id=0, $value=0, $steps=0, $width=0, $height=0, $color='', $bgcolor='', $inner_styleclass='', $outer_styleclass='', $show_digits=true;
+	
+	public function progressbar( $value = 0, $steps = 100, $width = 100, $height = 20, $color = '#0C0', $bgcolor = '#FFF', $inner_styleclass = '', $outer_styleclass = '')
+	{
+		static $progress_bars;		
+		if(empty($progress_bars))
+			$progress_bars = 0;
+			
+		$this->id = $progress_bars;
+		$this->value = $value;
+		$this->steps = $steps;
+		$this->width = $width;
+		$this->height = $height;
+		$this->color = $color;
+		$this->bgcolor = $bgcolor;
+		$this->inner_styleclass = $inner_styleclass;
+		$this->outer_styleclass = $outer_styleclass;
+		
+		$progress_bars++;
+	}
+	
+	public function set_show_digits($show = true)
+	{
+		$this->show_digits = !!$show;
+	}
+	
+	public function print_code()
+	{
+		static $init_printed;
+		
+		$jsp = self::$js_prefix;
+		
+		if(empty($init_printed))
+		{
+			self::execute_js("var {$jsp}bs=[];var {$jsp}ds=[];var {$jsp}ss=[];var {$jsp}ws=[];var {$jsp}dc=[];function {$jsp}s(f,d){var e=(d/{$jsp}ss[f]);if({$jsp}ds[f]){{$jsp}ds[f].innerHTML=\"\"+Math.round(e*100)+\" %\";}{$jsp}bs[f].style.width=\"\"+Math.round(e*{$jsp}ws[f])+\"px\";var c=(e>=0.5);if({$jsp}ds[f]&&{$jsp}dc[f]!=c){var a=(c?document.getElementById(\"{$jsp}b\"+f):{$jsp}bs[f]);{$jsp}ds[f].style.color=a.style.backgroundColor;{$jsp}dc[f]=c}}function {$jsp}i(e,d,a,b){{$jsp}bs[e]=document.getElementById(\"{$jsp}\"+e);{$jsp}ds[e]=document.getElementById(\"{$jsp}d\"+e);{$jsp}dc[e]=false;{$jsp}ss[e]=a;{$jsp}ws[e]=b;{$jsp}s(e,d)};", false);
+			$init_printed = true;
+		}
+
+		$id = $this->id;
+		$w = "width:{$this->width}px;";
+		$h = "height:{$this->height}px;";
+		$osc = empty($this->outer_styleclass) ? false : $this->outer_styleclass;
+		$isc = empty($this->inner_styleclass) ? false : $this->inner_styleclass;
+		$cl = "color:{$this->color};";
+
+		self::_echo("<div id=\"{$jsp}b{$id}\" style=\"{$w}{$h}text-align:left;background-color:{$this->bgcolor};overflow:hidden;".($osc?"\" class=\"{$osc}\"":"border:1px solid #000;\"").">");
+		if($this->show_digits)
+			self::_echo("\n<div id=\"{$jsp}d{$id}\" style=\"{$w}{$h}text-align:center;line-height:{$this->height}px;position:absolute;z-index:3;{$cl}\"></div>");
+		self::_echo("<div id=\"{$jsp}{$id}\" style=\"width:0px;{$h}background-{$cl}".($isc?" class=\"{$isc}\"":"\"")."></div>");
+		self::_echo("\n</div>");
+		self::execute_js("{$jsp}i({$this->id},{$this->value},{$this->steps},{$this->width});");
+	}	
+	
+	public function set($v)
+	{
+		if($v < 0) $v = 0;
+		else if($v >= $this->steps) $v = $this->steps;
+		
+		if($this->value != $v)
+		{
+			$this->value = $v;
+			self::execute_js(self::$js_prefix.'s('.$this->id.','.$v.');');
+		}
+	}
+	public function step($d=1) { $this->set($this->value+$d); }	
+	public function reset() { $this->set(0); }	
+	public function complete() { $this->set($this->steps); }
+}
+?>
Index: /mods/mod_converter/install.txt
===================================================================
--- /mods/mod_converter/install.txt	(revision 6540)
+++ /mods/mod_converter/install.txt	(revision 6540)
@@ -0,0 +1,30 @@
+------------------------------------------------------------------------------------------
+Installation WPSG4 und M1-Converter
+------------------------------------------------------------------------------------------
+
+- Neue Domain anlegen
+- Datenbank WPSG3 als SQL-Dump exportieren
+- Datenbank fÃŒr WPSG4 anlegen und den SQL-Dump importieren
+- Plugin WPSG4 installieren und aktivieren
+- Zugangsdaten fÃŒr die Datenbank in wp-config.php eintragen
+  (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST)
+- Themes installieren
+
+
+- Plugin M1-Converter ZIP-Datei auspacken nach /wp-content/plugins/ und aktivieren
+- Verzeichnis /wp-content/uploads von WPSG3 nach WPSG4 kopieren
+- M1-Converter starten
+
+
+- AufrÃ€umen, LÃ¶schen nicht mehr benÃ¶tigter Verzeichnisse
+  - /wp-content/uploads/wpsg_produktbilder
+  - /wp-content/uploads/wpsg_rechnungen
+  - /wp-content/uploads/wpsg/wpsg_deliverynote: Verzeichnisse auÃer mit Jahreszahl
+
+
+- /wp-content/uploads/wpsg/wpsg_girocode
+  .htaccess:  Allow from all
+
+
+------------------------------------------------------------------------------------------
+------------------------------------------------------------------------------------------
Index: /mods/mod_converter/readme.txt
===================================================================
--- /mods/mod_converter/readme.txt	(revision 6540)
+++ /mods/mod_converter/readme.txt	(revision 6540)
@@ -0,0 +1,47 @@
+=== M1-Converter ===
+Contributors: user, user, user
+Tags: tag, tag, tag
+Donate link: http://example.com/
+Requires at least: 4.7
+Tested up to: 4.8.2
+Requires PHP: 5.6
+Stable tag: 1.1
+License: GPLv2 or later
+License URI: http://www.gnu.org/licenses/gpl-2.0.html
+
+
+Converts data from wpShopGermany Version 3 to Version 4.
+
+
+== Description ==
+Converts data from wpShopGermany Version 3 to Version 4.
+Copy product images from wpShopGermany Version 3 to Version 4 into Wordpress Mediathek.
+Copy deliverynotes and invoices from wpShopGermany Version 3 to Version 4.
+
+
+== Installation ==
+1. Upload \"M1-Converter.zip\" to the \"/wp-content/plugins/\" directory and extract it.
+1. Activate the plugin through the \"Plugins\" menu in WordPress.
+
+
+== Frequently Asked Questions ==
+= No question at this time =
+No answer to that question.
+
+
+== Screenshots ==
+1. No screenshots at this time.
+
+
+== Changelog ==
+= 1.1 =
+* More functions.
+* New design.
+
+= 1.0 =
+* Initial release.
+
+
+== Upgrade Notice ==
+= 1.1 =
+This version fixes a security related bug. Upgrade immediately.
Index: /mods/mod_converter/style.css
===================================================================
--- /mods/mod_converter/style.css	(revision 6540)
+++ /mods/mod_converter/style.css	(revision 6540)
@@ -0,0 +1,62 @@
+.m1_converter_admin_content { padding:20px 0 0 20px; padding-top:20px; width:800px; }
+
+.panel {
+	margin-bottom:20px;
+	background-color:#fff;
+	border:1px solid transparent;
+	box-shadow:0 1px 2px rgba(0, 0, 0, 0.05);
+	-webkit-box-shadow:0 1px 2px rgba(0, 0, 0, .05);
+}
+
+.panel-default {
+	border-color:#ddd;
+}
+
+.panel-heading {
+	color:#333;
+	background-color:#f5f5f5;
+	border-color:#ddd;
+	padding:10px 15px;
+	border-bottom:1px solid transparent;
+	border-top-left-radius:3px;
+	border-top-right-radius:3px;
+	background-image: linear-gradient(to bottom, #f5f5f5 0%, #e8e8e8 100%);
+	background-image: -webkit-linear-gradient(top, #f5f5f5 0%, #e8e8e8 100%);
+	background-image: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#e8e8e8));
+	background-repeat:repeat-x;
+}
+.panel-title {
+	margin-top:0;
+	margin-bottom:0;
+	color:inherit;
+	font-size:16px;
+}
+
+.panel-body {
+	padding:15px;
+}
+
+.clearfix {}
+
+/* Allgemeine Button Styles */
+.m1c_button { cursor:pointer; margin-top:10px; width:120px; text-align:center; padding:5px 5px 5px 5px; line-height:28px; border:1px solid #29556E; color:#29556E; background-color:#ffffff; font-weight:bold; display:inline-block; text-transform:uppercase; text-decoration:none; }
+.m1c_button .fa { margin-left:5px; margin-right:5px; }
+.m1c_button:hover { background-color:#e5e5e5; color:#1a1a1a; text-decoration:none; border-color:rbg(181,230,29); }
+.m1c_button_100 { width:100%; text-align:center; }
+.m1c_button_right { float:right; }
+.m1c_button_layout2 { background-color:#29556E; color:#FFFFFF; border-color:#28546D; }
+.m1c_button_layout3 { background-color:#FFFFFF; color:#959595; border-color:#EAEAEA; }
+.m1c_button_layout2:hover,
+.m1c_button_layout3:hover { color:#1a1a1a; background-color:#e5e5e5; border-color:#1a1a1a; }
+
+label {
+    display: inline-block;
+    max-width: 100%;
+    margin-bottom: 5px;
+    font-weight: bold;
+    vertical-align: middle;
+    cursor: default;
+    box-sizing: border-box;
+}
+/* fÃŒr trac-Hilfe */
+h1 { font-size:16px; }
Index: /mods/wpsg_mod_basic.class.php
===================================================================
--- /mods/wpsg_mod_basic.class.php	(revision 6539)
+++ /mods/wpsg_mod_basic.class.php	(revision 6540)
@@ -96,5 +96,6 @@
 			5000	=> 'wpsg_mod_trustedshops', // Sollte nach den Zahlungsanbietern kommen wegen order_done
 			5100    => 'wpsg_mod_productview', 
-			5200    => 'wpsg_mod_recaptcha'
+			5200    => 'wpsg_mod_recaptcha',
+			5300	=> 'wpsg_mod_converter'
 		);
 		
Index: /mods/wpsg_mod_converter.class.php
===================================================================
--- /mods/wpsg_mod_converter.class.php	(revision 6540)
+++ /mods/wpsg_mod_converter.class.php	(revision 6540)
@@ -0,0 +1,838 @@
+<?php
+
+require_once(WPSG_PATH_MOD. 'mod_converter/M1_Converter_update.php');
+require_once(WPSG_PATH_MOD. 'mod_converter/M1_progressbar.class.php');
+
+	/**
+	 * Dieses Modul ermÃ¶glicht die Konvertierung der Daten von WPSG3 nach WPSG4
+	 * @author hartmut
+	 */
+	class wpsg_mod_converter extends wpsg_mod_basic
+	{
+		
+		var $id = 5300;
+		var $hilfeURL = 'https://doc.wpshopgermany.de/4/m1-converter/';
+		
+		var $m1cauto = false;
+		var $m1cconv;
+		var $m1cpb;
+		var $status = 0;
+		
+		/**
+		 * Constructor
+		 */
+		public function __construct()
+		{
+			
+			parent::__construct();
+			
+			$this->name = __('Converter', 'wpsg');
+			$this->group = __('Sonstiges', 'wpsg');
+			$this->desc = __('ErmÃ¶glicht die Konvertierung von WPSG3 nach WPSG4.', 'wpsg');
+			
+			$this->m1cpb = new progressbar1(0, 100, 300, 30);
+			$this->m1cconv = new M1_Converter_update($this->m1cpb);
+			
+		} // public function __construct()
+		
+		/** Initiiert das Modul / Wird nur aufgerufen wenn das Modul aktiv ist */
+		public function init()
+		{
+			add_action( 'admin_init', array($this, 'restrict_admin_with_redirect'), 1 );
+			
+		}
+		
+		function wpsg_add_pages()
+		{
+			
+			add_submenu_page(
+					null,
+					'M1-Converter',
+					'M1-Converter',
+					'manage_options',
+					'M1_Converter_dispatch',
+					array($this, 'M1_Converter_dispatch'));
+			
+		}
+		
+		function restrict_admin_with_redirect() {
+			
+			if (isset($_REQUEST['noheader'])) return;
+			
+			if (isset($_REQUEST['page']) && preg_match('/^wpsg/i', $_REQUEST['page']) && $_REQUEST['page'] != 'M1_Converter_dispatch')
+			{
+			
+				if (is_admin() && $this->shop->get_option('wpsg_mod_converter') != false)
+				{
+					
+					//http://shop4.home/wp-admin/admin.php?page=M1_Converter_dispatch
+					//$this->shop->update_option('wpsg_mod_converter', false);
+					$this->shop->update_option('wpsg_mod_converter_auto', false);
+					wp_redirect(WPSG_URL_WP.'wp-admin/admin.php?page=M1_Converter_dispatch');
+				}
+			}
+			
+		}
+		
+		/**
+		 * Wird von wpsg_enqueue_scripts aufgerufen
+		 */
+		public function wpsg_enqueue_scripts()
+		{
+			if (is_admin()) {
+				//wp_enqueue_script('wpsg_mod_converter', $this->shop->getRessourceURL('js/shariff/shariff.min.js'));
+				//wp_enqueue_style ('wpsg_mod_converter_style', $this->shop->getRessourceURL('js/shariff/shariff.min.css'));
+				
+			}
+			
+		}
+		
+		/**
+		 * PrÃŒft den Status der Konvertierung und gibt true zurÃŒck,
+		 * wenn alle Schritte durchgefÃŒhrt wurden.
+		 */
+		private function checkStatus($step)
+		{
+			
+			$this->status = $this->shop->get_option('wpsg_mod_converter_status');
+			$a = bindec($step);
+			$this->status = $this->status | $a;
+			$this->shop->update_option('wpsg_mod_converter_status', $this->status);
+			$this->m1cauto = $this->shop->get_option('wpsg_mod_converter_auto');
+			
+			// 11 1111 1111
+			if (($this->status == 1023) && ($this->m1cauto == false)) {
+				$this->shop->update_option('wpsg_mod_converter', false);
+				$this->shop->update_option('wpsg_mod_converter_status', 0);
+				//$_REQUEST['action'] = 'ende';
+				//$this->M1_Converter_dispatch();
+			}
+			
+		}
+		
+		
+		/**
+		 * Funktionsverteiler
+		 *
+		 * Je nach der gewÃ€hlten Aktion wird die entsprechende Funktion aufgerufen.
+		 *
+		 */
+		function M1_Converter_dispatch()
+		{
+			//global $m1cpb, $m1cconv;
+			
+			//parent::dispatch();
+			
+			if (!isset($_REQUEST['action'])) {
+				
+				$this->M1_Converter_preshow();
+				
+			}
+			
+			//$m1cconv = new M1_Converter($GLOBALS['m1cpb']);
+			
+			if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'auto')
+			{
+				
+				//$this->m1cauto = true;
+				$this->shop->update_option('wpsg_mod_converter_auto', true);
+				$this->M1_Converter_auto();
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'show')
+			{
+				
+				$this->M1_Converter_show();
+				//$this->shop->update_option('wpsg_mod_converter', false);
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'ende')
+			{
+				
+				$this->shop->update_option('wpsg_mod_converter', false);
+				$this->shop->update_option('wpsg_mod_converter_status', 0);
+				//$this->shop->update_option('wpsg_mod_converter_auto', false);
+				//wp_redirect('/wp-admin/admin.php');
+				//wp_redirect('/wp-admin/admin.php?page=wpsg-Admin&action=module');
+				//http://shop4.home/wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_converter
+				die("FIN");
+				//wp_redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_converter');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'allgemein')
+			{
+				
+				$this->m1cconv->M1_Converter_allgemein();
+				$this->checkStatus('1'); 
+					
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'kunden')
+			{
+				
+				$this->m1cconv->M1_Converter_kunden();
+				$this->checkStatus('10');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'order')
+			{
+				
+				$this->m1cconv->M1_Converter_order();
+				$this->checkStatus('100');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'anrede')
+			{
+				
+				$this->m1cconv->M1_Converter_anrede();
+				$this->checkStatus('1000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'media')
+			{
+				
+				$this->m1cconv->M1_Converter_media();
+				$this->checkStatus('10000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'prod1')
+			{
+				
+				$this->m1cconv->M1_Converter_prod1();
+				$this->checkStatus('100000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'preis')
+			{
+				
+				$this->m1cconv->M1_Converter_preis();
+				$this->checkStatus('1000000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'category')
+			{
+				
+				$this->m1cconv->M1_Converter_category();
+				$this->checkStatus('10000000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'lief')
+			{
+				
+				$this->m1cconv->M1_Converter_lief();
+				$this->checkStatus('100000000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'rech')
+			{
+				
+				$this->m1cconv->M1_Converter_rech();
+				$this->checkStatus('1000000000');
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'produkt')
+			{
+				
+				$this->m1cconv->M1_Converter_produkt();
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'zip')
+			{
+				
+				$this->m1cconv->M1_Converter_zip();
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'unzip')
+			{
+				
+				$this->m1cconv->M1_Converter_unzip();
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'test')
+			{
+				
+				$this->m1cconv->M1_Converter_test();
+				
+			}
+			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'prod0')
+			{
+				
+				die($this->m1cconv->M1_Converter_prod0());
+				
+			}
+			
+		}	// function M1_Converter_dispatch()
+		
+		/**
+		 * Startseite
+		 *
+		 * PrÃŒfen, ob der Shop als Plugin installiert ist und eine
+		 * richtige Versionsnummer hat.
+		 *
+		 */
+		function M1_Converter_preshow() {
+			
+			global $m1cpb;
+			
+			?>
+    
+	<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'wpshopgermany/mods/mod_converter/style.css'; ?>" type="text/css" media="all" />
+
+	<div class="m1_converter_admin_content" >
+    	<div class="panel panel-default" >
+    		<div class="panel-heading clearfix" >
+        		<h2 class="panel-title" >M1-Converter</h2>
+			</div>
+			
+			<div class="panel-body" >
+				
+				<label ><?php echo __('Der M1-Converter integriert die Daten in die neue wpShopGermany Version 4.', 'wpsg'); ?></label>
+	        	<br /><br />
+				
+		        <?php
+		        $wpsgi = true;
+
+		        if ((isset($GLOBALS['wpsg_sc']) && is_object($GLOBALS['wpsg_sc'])))
+		        {
+		        	echo __('WPSG-Installation gefunden in: '.admin_url(), 'wpsg');
+					$wpsgi = true;
+		        }
+				else
+				{
+					echo __('<br />Keine WPSG-Installation gefunden!', 'wpsg');
+					$wpsgi = false;
+				}
+
+				if (!defined('WPSG_VERSION')) define('WPSG_VERSION', '0.0.0');
+			
+				echo __('<br /> WPSG-Version: '.WPSG_VERSION.' ', 'wpsg');
+				$ver = substr(WPSG_VERSION, 0, 1);
+				$res = version_compare(WPSG_VERSION, '3.99.0');
+				// -1: erste Version ist kleiner
+				// 0:  die Versionen sind gleich
+				// 1:  die zweite Version ist kleiner
+				if ($res >= 0)
+				{
+					echo __('<br /> WPSG-Version OK.', 'wpsg');
+					$wpsgi = true;
+				}
+				else
+				{
+					echo __('<br />WPSG-Version zu niedrig!', 'wpsg');
+					$wpsgi = false;
+				}
+				
+				echo '<br /><br />';
+				
+		        if ($wpsgi == true) {
+				?>
+		        	<a class="m1c_button " title="Konvertieren von WPSG Version 3" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=show'); ?>">Konvertieren von WPSG Version 3</a>
+				
+				<?php } ?>
+    		</div>
+		</div>
+	</div>
+	<div id="wpsg-bs"></div>
+	
+<?php }
+/**
+ * Hauptseite von der die einzelnen Funktionen aufgerufen werden
+ *
+ * Analyse der Datenbank und anzeigen der wichtigsten Informationen.
+ * Buttons fÃŒr den Aufruf der einzelnen Funktionen und fÃŒr
+ * einen automatischen Durchlauf durch die gesamte Konvertierung.
+ *
+ *
+ */
+function M1_Converter_show() {
+	global $m1cpb, $m1cconv;
+	
+	?>
+    
+	<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'wpshopgermany/views/js/bootstrap-3.3.6-dist/css/bootstrap.css'; ?>" type="text/css" media="all" />
+	<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'wpshopgermany/views/js/bootstrap-3.3.6-dist/css/bootstrap-glyphfont.css'; ?>" type="text/css" media="all" />
+	<link rel="stylesheet" href="<?php echo WPSG_PLUGIN_URL.'wpshopgermany/mods/mod_converter/style.css'; ?>" type="text/css" media="all" />
+
+	<script src="<?php echo WPSG_PLUGIN_URL.'wpshopgermany/views/js/bootstrap-3.3.6-dist/js/bootstrap.min.js'?>"></script>
+
+	<div class="m1_converter_admin_content" >
+    	<div class="panel panel-default" >
+    		<div class="panel-heading clearfix" >
+        		<h2 class="panel-title" >M1-Converter</h2>
+			</div>
+			
+			<div class="panel-body" >
+				
+				<label ><?php echo __('Der M1-Converter wandelt die bestehenden Daten aus Ihrer wpShopGermany Version 3 um und integriert die Daten in die neue wpShopGermany Version 4.', 'wpsg'); ?></label>
+	        	<br /><br />
+
+		        <?php
+		        $wpsgi = true;
+		        
+		        if ((isset($GLOBALS['wpsg_sc']) && is_object($GLOBALS['wpsg_sc'])))
+		        {
+		        	echo __('WPSG-Installation gefunden in: '.admin_url(), 'wpsg');
+					$wpsgi = true;
+		        }
+				else
+				{
+					echo __('<br />Keine WPSG-Installation gefunden!', 'wpsg');
+					$wpsgi = false;
+				}
+
+				if (!defined('WPSG_VERSION')) define('WPSG_VERSION', '0.0.0');
+			
+				echo __('<br /> WPSG-Version: '.WPSG_VERSION.' ', 'wpsg');
+				$ver = substr(WPSG_VERSION, 0, 1);
+				$res = version_compare(WPSG_VERSION, '3.99.0');
+				// -1: die erste Version ist kleiner
+				// 0:  die Versionen sind gleich
+				// 1:  die zweite Version ist kleiner
+				if ($res >= 0) 
+				{
+					echo __('<br /> WPSG-Version OK.', 'wpsg');
+					$wpsgi = true;
+				}
+				else
+				{
+					echo __('<br />WPSG-Version zu niedrig!', 'wpsg');
+					$wpsgi = false;
+				}
+				
+		        if ($wpsgi == true) {
+				
+				$db = $GLOBALS['wpsg_db'];
+		
+				echo '<br />';
+				$kunden = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_KU."` ORDER BY `id` ASC");
+				echo __('<br />'.count($kunden).' Kunden', 'wpsg');
+		
+				$orders = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDER."` ORDER BY `id` ASC");
+				echo __('<br />'.count($orders).' Bestellungen', 'wpsg');
+		
+				$products = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS."` ORDER BY `id` ASC");
+				$i1 = 0;
+				$i2 = 0;
+
+				foreach ($products as $p)
+				{
+					$arPic = $this->m1cconv->getProduktBilder($p['id'], false);
+					$i1++;
+					$i2 = $i2 + count($arPic);
+				}
+				echo __('<br />'.$i1.' Produkte mit '.$i2.' Bildern', 'wpsg');
+		
+				echo __('<br /><br />Bilderverzeichnis fÃŒr Produkt 1: '.$this->m1cconv->getPicPath(1), 'wpsg');
+		
+        		?>
+        		<br /><br />
+        		<a id="idauto" class="m1c_button" title="Auto" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=auto'); ?>">Automatisch</a>
+        		AusfÃŒhren der Schritte Allgemein, Kunden, Bestellungen bis Rechnungen
+        		
+		        <br /><br />
+		        <label ><?php echo __('WÃ€hlen Sie die gewÃŒnschte Aktion aus. AbhÃ€ngig vom Umfang kann die Ãbertragung ein paar Minuten dauern. WÃ€hrend dieser Zeit ist es ratsam, keine VerÃ€nderungen an der Instanz vorzunehmen oder andere Prozesse zeitgleich abzuarbeiten.', 'wpsg'); ?></label>
+		        <br /><br />
+        
+				<div>
+					<div style="background:white;width:10px;vertical-align:top;margin-top:10px;height:490px;display:inline-block;">
+					<canvas id="sprogress" ></canvas>
+					</div>
+					<div style="background:white;width:8px;height:500px;display:inline-block;"></div>
+					<div style="display:inline-block;width:90%;">
+
+			        <a class="m1c_button" title="Allgemeine Konfigurationen" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=allgemein'); ?>">Allgemein</a>
+					<a href="#" data-wpsg-tip="M1C-Allgemein" 
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Allgemeine Konfigurationen<br />
+
+			        <a class="m1c_button" title="Konvertieren der Kundenadressen" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=kunden'); ?>">Kunden</a>
+					<a href="#" data-wpsg-tip="M1C-Kunden" 
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Konvertieren der Kundenadressen<br />
+
+			        <a class="m1c_button" title="Konvertieren der Bestellungen" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=order'); ?>">Bestellungen</a>
+					<a href="#" data-wpsg-tip="M1C-Bestellungen"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Konvertieren der Bestellungen, Rechnungsadresse und Lieferadresse<br />
+
+			        <a class="m1c_button" title="Konvertieren der Anreden" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=anrede'); ?>">Anreden</a>
+					<a href="#" data-wpsg-tip="M1C-Anrede"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Konvertieren der Anrede in der Tabelle der Adressen<br />
+
+			        <div style="height:48px;margin-bottom:3px;">
+			        <a class="m1c_button" title="LÃ¶schen der Produktbilder in der Mediathek" id="idmedia" href="#">Mediathek</a>
+					<a href="#" data-wpsg-tip="M1C-Mediathek" 
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0" 
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					<div style="display:inline-block; height:48px; vertical-align:middle">LÃ¶schen der Produktbilder in der Mediathek.<br /><span id="mprogress">0 Produktbilder in der Mediathek gelÃ¶scht.</span></div>
+					</div>
+
+			        <div style="height:48px;margin-bottom:3px;">
+			        <a class="m1c_button" title="Konvertieren der Produkte" id="idajax" href="#">Produkte</a>
+					<a href="#" data-wpsg-tip="M1C-Produkte" 
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0" 
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					<div style="display:inline-block; height:48px; vertical-align:middle">Konvertieren der Produkte/Varianten und Ãbernahme der Produktbilder in die Mediathek.<br /><span id="progress">0 Produkte konvertiert.</span></div>
+					</div>
+
+			        <a class="m1c_button" title="Berechnen der Preise netto/brutto" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=preis'); ?>">Preise</a>
+					<a href="#" data-wpsg-tip="M1C-Preise"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Berechnen der Preise netto/brutto<br />
+
+			        <a class="m1c_button" title="Konvertieren der Kategorien" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=category'); ?>">Kategorien</a>
+					<a href="#" data-wpsg-tip="M1C-Kategorien"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Konvertieren der Kategorien<br />
+
+			        <a class="m1c_button" title="Lieferscheine in neue Verzeichnisstruktur kopieren" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=lief'); ?>">Lieferscheine</a>
+					<a href="#" data-wpsg-tip="M1C-Lieferscheine"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Lieferscheine in die neue Verzeichnisstruktur kopieren<br />
+
+			        <a class="m1c_button" title="Rechnungen in neue Verzeichnisstruktur kopieren" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=rech'); ?>">Rechnungen</a>
+					<a href="#" data-wpsg-tip="M1C-Rechnungen"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Rechnungen in die neue Verzeichnisstruktur kopieren<br />
+
+			        <a class="m1c_button" title="LÃ¶schen der Thumbnails und Zippen der Produktbilder" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=zip'); ?>">Packen</a>
+					<a href="#" data-wpsg-tip="M1C-Zip"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					LÃ¶schen der Thumbnails und Zippen der Produktbilder von WPSG3<br />
+
+			        <a class="m1c_button" title="Entpacken der Produktbilder" href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=unzip'); ?>">Entpacken</a>
+					<a href="#" data-wpsg-tip="M1C-Unzip"
+					rel="?page=wpsg-Admin&amp;subaction=loadHelp&amp;noheader=1&amp;field=Bestellung_0"
+					class="glyphicon glyphicon-question-sign" aria-hidden="true"></a>
+					Entpacken der Produktbilder<br />
+
+					<!--
+			        <a href="<?php echo admin_url('admin.php?page=M1_Converter_dispatch&action=test'); ?>">Test</a>
+			        <br /><br />
+					-->
+					</div>
+					</div>
+				<?php } ?>
+    		</div>
+		</div>
+	</div>
+	<div id="wpsg-bs"></div>
+	
+<script type="text/javascript">
+
+	<?php
+	$products = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS."` ORDER BY `id` ASC");
+	//$products = array();
+	$posts = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `meta_key`='".wpsg_q('wpsg_produkt_id')."' ORDER BY `post_id`");
+	?>
+
+	var m1cauto = 0;
+	
+function wpsg_ajaxBindM1C()
+{
+	
+	// Hilfe Tooltips
+	jQuery('*[data-wpsg-tip]').on('click', function() {
+
+		jQuery(this).off('click').on('click', function() { return false; } );
+
+		var po = this;
+
+		jQuery(this).popover( {
+			'html': true,
+			'content': '<div id="wpsg-popover-content">Bitte warten...</div>',
+			'trigger': 'focus',
+			'container': '#wpsg-bs',
+			'placement': 'right'
+		} ).popover('show');
+
+		jQuery.ajax( {
+			url: '?page=wpsg-Admin&subaction=loadHelp&noheader=1',
+			data: {
+				field: jQuery(this).attr('data-wpsg-tip')
+			},
+			success: function(data) {
+				
+				var popover = jQuery(po).attr('data-content', data).data('popover');
+				jQuery(po).data('bs.popover').options.content = data;
+				
+				jQuery(po).popover('show');
+				
+			}
+		} );
+		
+		return false;
+		
+	} );
+
+}
+
+var po; 
+
+function wpsg_ajaxBind()
+{
+	
+	// Hilfe Tooltips
+	jQuery('*[data-wpsg-tip]').on('click', function() { 
+
+		//jQuery(this).off('click').on('click', function() { return false; } );
+
+		if (typeof po === "object")
+		{
+			
+			if (po != this) jQuery(po).popover('hide');
+			
+		}
+		
+		po = this;
+		
+		if (jQuery(this).hasClass('activated'))
+		{
+							
+			jQuery(this).popover('show');
+			
+			return false;
+			
+		}
+		
+		jQuery(this).popover( {
+			'html': true,
+			'content': '<div id="wpsg-popover-content">Bitte warten...</div>',
+			'trigger': 'focus',
+			'container': '#wpsg-bs',
+			'placement': 'right'
+		} ).popover('show');
+
+		jQuery.ajax( {
+			url: '?page=wpsg-Admin&subaction=loadHelp&noheader=1',
+			data: {
+				field: jQuery(this).attr('data-wpsg-tip')
+			},
+			success: function(data) {
+				
+				var popover = jQuery(po).attr('data-content', data).data('popover');
+				jQuery(po).data('bs.popover').options.content = data;
+				
+				jQuery(po).popover('show');
+									
+			}
+		} );
+		 
+		jQuery(this).addClass('activated');
+		
+		return false;
+		
+	} );
+			
+}
+
+
+jQuery(document).ready(function () {
+
+	//wpsg_ajaxBindM1C();
+	wpsg_ajaxBind();
+
+	// Konvertieren der Produkte und Varianteninformationen und
+	// Ãbernahme der Produktbilder in die Mediathek.
+	jQuery(document).on("click", "#idajax", function () {
+		//alert('ajax');
+
+		var produkte = <?php echo json_encode($products); ?>;
+		var pid = 1;
+		var i, anz;
+		anz = produkte.length;
+		pid = produkte[0].id;
+
+	    request = jQuery.ajax({
+	        url: 'admin.php?page=M1_Converter_dispatch&action=prod0&noheader=1',
+	        type: "post",
+	        async: false,
+        	success: function (response) {
+				if ((response == '\n0') || (response == '0')) {
+					alert('Die Ãbernahme ist schon erfolgt.');
+					pid = -1;
+					return;
+        		}
+        	},
+        	error: function(jqXHR, textStatus, errorThrown) {
+            	console.log(textStatus, errorThrown);
+        	}
+	        
+	    });
+
+		if (pid == -1) return false;
+		
+		for (i = 0; i < anz; i++) {
+			pid = produkte[i].id;
+		    request = jQuery.ajax({
+		        url: 'admin.php?page=M1_Converter_dispatch&action=prod1&noheader=1',
+		        type: "post",
+		        async: false,
+		        data: {
+			        'pid': pid,
+			        'num': i,
+		        },
+	        	success: function (response) {
+					console.log((i + 1) + ' Produkte konvertiert.');
+					jQuery('#progress').html(' ' + (i + 1) + ' Produkte konvertiert.');
+	
+	        	},
+	        	error: function(jqXHR, textStatus, errorThrown) {
+	            	console.log(textStatus, errorThrown);
+	        	}
+		        
+		    });
+
+		}
+
+		if (m1cauto === 0)
+			alert('Ãbernahme der Produktbilder und Varianteninformationen beendet.');
+
+	    return false;
+	});
+
+	// AufrÃ€umen der Mediathek.
+	// Eventuell vorhandene Produktbilder werden gelÃ¶scht.
+	jQuery(document).on("click", "#idmedia", function () {
+		//alert('ajax');
+
+		var posts = <?php echo json_encode($posts); ?>;
+		var postid = 1;
+		var i, anz;
+		anz = posts.length;
+		pid = posts[0].post_id;
+
+		for (i = 0; i < anz; i++) {
+			pid = posts[i].post_id;
+		    request = jQuery.ajax({
+		        url: 'admin.php?page=M1_Converter_dispatch&action=media&noheader=1',
+		        type: "post",
+		        async: false,
+		        data: {
+			        'post_id': pid,
+			        'num': i,
+		        },
+	        	success: function (response) {
+					console.log((i + 1) + ' Produktbilder gelÃ¶scht.');
+					jQuery('#mprogress').html(' ' + (i + 1) + ' Produktbilder in der Mediathek gelÃ¶scht.');
+	
+	        	},
+	        	error: function(jqXHR, textStatus, errorThrown) {
+	            	console.log(textStatus, errorThrown);
+	        	}
+		        
+		    });
+
+		}
+		if (m1cauto == 0) alert('Mediathek aufrÃ€umen beendet.');
+		
+	    return false;
+	});
+			
+});
+
+// Starten des automatischen Durchlaufs zur Konvertierung 
+// der Daten.
+jQuery(document).on("click", "#idauto", function () {
+
+	jQuery('.m1c_button').bind('click', false);
+	m1cauto = 1;
+	
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=auto&noheader=1');
+	progress(0);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=allgemein&noheader=1');
+	progress(1);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=kunden&noheader=1');
+	progress(2);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=order&noheader=1');
+	progress(3);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=anrede&noheader=1');
+	progress(4);
+
+	jQuery('#idmedia').unbind('click', false);
+	jQuery('#idmedia').trigger("click");
+	jQuery('#idmedia').bind('click', false);
+	progress(5);
+	jQuery('#idajax').unbind('click', false);
+	jQuery('#idajax').trigger("click");
+	jQuery('#idajax').bind('click', false);
+	progress(6);
+
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=preis&noheader=1');
+	progress(7);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=category&noheader=1');
+	progress(8);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=lief&noheader=1');
+	progress(9);
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=rech&noheader=1');
+	progress(10);
+
+	jQuery('.m1c_button').unbind('click', false);
+	m1cauto = 0;
+	//alert('Automatische Konvertierung beendet.');
+	ajaxCall('admin.php?page=M1_Converter_dispatch&action=ende&noheader=1');
+	return false;
+	
+});
+
+function ajaxCall(url) {
+
+    request = jQuery.ajax({
+        url: url,
+        type: "post",
+        async: false,
+        data: {
+	        'post_id': 0,
+	        'num': 0,
+        },
+    	success: function (response) {
+
+    		if (response === "FIN") {
+    			alert('Konvertierung beendet.');
+        		//alert("<?php echo WPSG_URL_WP?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_converter");
+				//wp_redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_converter');
+        		location.href = "<?php echo WPSG_URL_WP?>wp-admin/admin.php?page=wpsg-Admin&action=module";
+        	}
+			console.log(url);
+    	},
+    	error: function(jqXHR, textStatus, errorThrown) {
+        	console.log(textStatus, errorThrown);
+    	}
+        
+    });
+
+}
+
+// Anzeige des senkrechten Fortschrittsbalken.
+function progress(fill) {
+	var c = document.getElementById("sprogress");
+	var ctx = c.getContext("2d");
+	if (fill == 0) {
+		ctx.fillStyle = "#FFFFFF";
+		ctx.fillRect(0, 0, 10, 10 * 50);
+	}
+	jQuery('#sprogress').attr('height', fill * 50);
+	ctx.fillStyle = "#00FF00";
+	ctx.fillRect(0, 0, 8, fill * 50);
+	//alert('progress');
+
+}
+
+function pause(delay) {
+    var start = new Date().getTime();
+    while (new Date().getTime() < start + delay);
+}
+
+</script>
+
+<?php }
+	} // class wpsg_mod_converter extends wpsg_mod_basic
+?>
