Index: /controller/wpsg_AdminController.class.php
===================================================================
--- /controller/wpsg_AdminController.class.php	(revision 6437)
+++ /controller/wpsg_AdminController.class.php	(revision 6438)
@@ -2082,4 +2082,6 @@
 			{
 
+				$this->update_option('wpsg_imagehandler_basketimage', $_REQUEST['wpsg_imagehandler_basketimage']);
+				$this->update_option('wpsg_imagehandler_overviewimage', $_REQUEST['wpsg_imagehandler_overviewimage']);
 				$this->update_option('wpsg_showMwstAlways', $_REQUEST['wpsg_showMwstAlways']);
 				$this->update_option('wpsg_form_validation', $_REQUEST['wpsg_form_validation']);
Index: /controller/wpsg_ProduktController.class.php
===================================================================
--- /controller/wpsg_ProduktController.class.php	(revision 6437)
+++ /controller/wpsg_ProduktController.class.php	(revision 6438)
@@ -74,4 +74,65 @@
 				
 				$this->shop->callMod($_REQUEST['mod'], 'produkt_ajax');
+				
+			}
+			else if ($_REQUEST['cmd'] == 'upload')
+			{ 
+				
+				// Tabelle Produkt postids lÃ¶schen
+				$sql = "UPDATE ".WPSG_TBL_PRODUCTS." SET `postids` = '' WHERE `id` = ".$_REQUEST['edit_id'];
+				$this->db->Query($sql);
+				
+				add_post_meta($_REQUEST['post']['id'], 'wpsg_produkt_id', $_REQUEST['edit_id']);
+				
+				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
+				
+				die($this->imagehandler->getProductListBackend($_REQUEST['edit_id']));
+				
+			}
+			else if ($_REQUEST['cmd'] == 'setImageOrder')
+			{
+				
+				$reo = $_REQUEST['wpsg_reorder'];
+				$pid = $_REQUEST['edit_id'];
+				
+				$file = '';
+				$line = '';
+				
+				$sreo = '';
+
+				foreach ($reo as $v) 
+				{
+					
+					$st = explode('_', $v);
+					$sreo .= $st[1].',';
+					
+				}
+				
+				$sreo = substr($sreo, 0, strlen($sreo) - 1);
+				
+				$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array("postids" => wpsg_q($sreo)), "`id` = '".wpsg_q($pid)."'");
+				 
+				die('1');
+				
+			}
+			else if ($_REQUEST['cmd'] == 'removeImage')
+			{
+				
+				// Auch in der Mediathek lÃ¶schen
+				if ($_REQUEST['delmt'] === 'true') 
+				{
+					
+					wp_delete_post($_REQUEST['pid'], true);
+					
+				}
+				
+				// Zuordnung lÃ¶schen
+				delete_post_meta($_REQUEST['pid'], 'wpsg_produkt_id', $_REQUEST['edit_id']);
+				
+				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
+			
+				if ($this->shop->hasMod('wpsg_mod_produktartikel')) $this->shop->callMod('wpsg_mod_produktartikel', 'updatePostThumbnail', array($_REQUEST['edit_id']));
+			
+				die($this->imagehandler->getProductListBackend($_REQUEST['edit_id']));
 				
 			}
@@ -629,4 +690,22 @@
 			}
 			
+			/* Produktbilder */
+			if (!isset($_REQUEST['wpsg_lang'])) 
+			{
+				
+				if (wpsg_isSizedInt($this->shop->view['data']['id']))
+				{
+			 
+					$this->shop->view['strProductList'] = $this->imagehandler->getProductListBackend($this->shop->view['data']['id']);
+					
+				}
+			
+				$this->shop->view['arSubAction']['images'] = array(
+					'title' => __('Produktbilder', 'wpsg'),
+					'content' => $this->shop->render(WPSG_PATH_VIEW.'/produkt/images.phtml', false)
+				);
+				
+			}
+			
 			$this->shop->callMods('product_addedit_content', array(&$this->shop->view['arSubAction'], &$this->shop->view['data']));
 			
Index: /controller/wpsg_ShopController.class.php
===================================================================
--- /controller/wpsg_ShopController.class.php	(revision 6437)
+++ /controller/wpsg_ShopController.class.php	(revision 6438)
@@ -667,25 +667,4 @@
 			wp_enqueue_script('jquery');
 
-			if (false && is_admin())
-			{
-
-				$current_screen = get_current_screen();
-				$current_screen = $current_screen->id;
-
-				var_dump($current_screen);
-				$commercial = false;
-        if ( ('plugin-install' == $current_screen) || ('plugin-install-network' == $current_screen) ) {
-            if ( isset($_GET['tab']) ) {
-                $tab = $_GET['tab'];
-                if ( 'commercial' == $tab ) {
-                    $commercial = true;
-                }
-            }
-        }
-
-					die(var_dump($commercial));
-
-			}
-
 			if (is_admin() && preg_match('/wpsg/', wpsg_getStr($_REQUEST['page'])))
 			{
@@ -729,4 +708,7 @@
 					'ie_validate_empty' => __('Bitte machen Sie hier eine Angabe.', 'wpsg')
 				));
+				
+				//wp_enqueue_script('wpsg_ajaxupload', $this->getRessourceURL('js/ajaxupload.js')); ??
+				wp_enqueue_media();
 
 			}
@@ -1210,5 +1192,5 @@
 			$this->view['data']['id'] = $this->getProduktId($this->view['data']['id']);
 
-			$this->view['oProduct'] = wpsg_product::getInstance($this->view['data']['id']);
+			$this->view['oProduct'] = wpsg_product::getInstance($this->view['data']['product_key']);
 			$this->view['oProduct']->appendData($this->view['data']);
 
@@ -1889,5 +1871,5 @@
 			{
 
-				throw new \wpsg\Exception(_('Produkt ID konnte nicht gebildet werden.'), \wpsg\Exception::TYP_UNEXPECTED);
+				throw new \wpsg\Exception(_('Produkt ID konnte nicht gebildet werden: ').$produkt_key, \wpsg\Exception::TYP_UNEXPECTED);
 				return 0;
 
Index: /controller/wpsg_SystemController.class.php
===================================================================
--- /controller/wpsg_SystemController.class.php	(revision 6437)
+++ /controller/wpsg_SystemController.class.php	(revision 6438)
@@ -10,6 +10,9 @@
 		var $db;
 		
-		/** Das Shop Objekt vom Typ wpsg_ShopController */
+		/** @var wpsg_ShopController Das Shop Objekt vom Typ wpsg_ShopController */
 		var $shop;
+		
+		/** @var wpsg_imagehandler Das Imagehandler Objekt */
+		var $imagehandler;
 		
 		/** Text des letzten CURL Fehlers */
@@ -38,4 +41,6 @@
 				
 			}
+			
+			$this->imagehandler = &$GLOBALS['wpsg_ih'];
 			
 			$this->view = array();
Index: /lib/wpsg_imagehandler.class.php
===================================================================
--- /lib/wpsg_imagehandler.class.php	(revision 6438)
+++ /lib/wpsg_imagehandler.class.php	(revision 6438)
@@ -0,0 +1,183 @@
+<?php
+
+    /**
+     * User: Daschmi (daschmi@daschmi.de)
+     * Date: 01.09.2017
+     * Time: 08:04
+     */
+
+    /**
+     * In dieser Klasse sind die Funktionen zum Zugriff auf die Produktbilder gekapselt
+     * Ersetzt das alte Produktbilder Modul
+     */
+    class wpsg_imagehandler 
+    {
+        
+        /** @var wpsg_ShopController */
+        private $shop = null;
+        
+        public function __construct()
+        {
+            
+            $this->shop = &$GLOBALS['wpsg_sc'];
+            $this->db = &$GLOBALS['wpsg_db'];
+            
+        } // public function __construct()
+        
+        /**
+		 * Gibt die ID des Anhangs zu einem ProduktKey zurÃŒck
+		 * @author Daschmi
+		 * @param $product_key
+		 */
+		public function getAttachmentID($product_key)
+		{
+			
+			$arAttachmentIDs = $this->getAttachmentIDs($product_key);
+				
+			if (wpsg_isSizedArray($arAttachmentIDs)) return $arAttachmentIDs[0];
+			else return false;
+			
+		} // public function getAttachmentID($product_key)
+		
+		/**
+		 * Gibt die IDs der AnhÃ€nge zurÃŒck (Alle Bilder eines Produkts)
+		 * Beachtet die Reihenfolge aus der Spalte "postids"
+		 * 
+		 * @author Daschmi
+		 * @param String $product_key
+		 */
+		public function getAttachmentIDs($product_key, $vari_id = false)
+		{
+			
+			$product_id = $this->shop->getProduktID($product_key);
+		 
+			$arAttachmentIDs = $this->db->fetchAssocField("
+				SELECT 
+					P.`ID` 
+			  	FROM 
+			  		`".$this->shop->prefix."postmeta` AS PM
+			  		 	LEFT JOIN `".$this->shop->prefix."posts` AS P ON (PM.`post_id` = P.`ID`)
+			  	WHERE 
+			  		PM.`meta_key` = 'wpsg_produkt_id' AND 
+			  		PM.`meta_value` = '".wpsg_q($product_id)."' AND
+			  		P.`ID` IS NOT NULL
+			");
+			
+			// Die Sortierung steht in der Spalte postids im Produkt			
+			$oProduct = wpsg_product::getInstance($product_id);
+			$postids = $oProduct->postids;
+						
+			if (strpos($postids, ',') !== false)
+			{
+				
+				$arPostIDsOrder = explode(',', $postids);
+				 
+				// Die Elemente in der Reihenfolge aus $arPostIDsOrder, die auch in $arAttachmentIDs vorkommen
+				$arAttachmentIDsIntersect = array_intersect($arPostIDsOrder, $arAttachmentIDs);
+				
+				// Elemente, die in $arAttachment drin sind, aber nicht in $arPostIDsOrder
+				$arDiff = array_diff($arAttachmentIDs, $arPostIDsOrder);
+				$arAttachmentIDs = $arAttachmentIDsIntersect + $arDiff;
+				
+				
+			} 
+			 
+			// Jetzt sind in $arAttachmentIDs alle Bilder dieses Produktes
+			if ($this->shop->hasMod('wpsg_mod_productvariants') && $this->shop->callMod('wpsg_mod_productvariants', 'isVariantsProductKey', array($product_key)))
+			{
+			
+				// Bei einem Variantenprodukt muss ich jetzt noch filtern ...
+				$arVariInfo = $this->shop->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($product_key));
+				
+				return $arVariInfo['images'];
+                                
+			}
+			else if ($this->shop->hasMod('wpsg_mod_productvariants') && wpsg_isSizedInt($vari_id))
+			{
+				
+				// Daten der Produktvariation laden
+				$db_product_vari = $this->db->fetchRow("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id` = '".wpsg_q($product_id)."' AND `variation_id` = '".wpsg_q($vari_id)."' ");
+				$arAttachmentIDsProductVari = explode(',', $db_product_vari['images']);
+				
+				// Die Elemente, in der Reihenfolge aus $arAttachmentIDs. die auch in $arAttachmentIDsProductVari enthalten sind
+				$arAttachmentIDsIntersect = array_intersect($arAttachmentIDsProductVari, $arAttachmentIDs);
+				
+				// Die Elemente, die in $arAttachment drin sind, aber nicht in $arAttachmentIDsProductVari
+				$arDiff = array_diff($arAttachmentIDs, $arAttachmentIDsProductVari);
+				$arAttachmentIDs = $arAttachmentIDsIntersect + $arDiff;
+				 				
+			}
+			
+			return $arAttachmentIDs; 
+			
+		} // public function getAttachmentIDs($product_id)
+
+        /* Backend Funktionen */
+
+        /**
+         * Zeichnet die Liste der Bilder fÃŒr das Backend der Produktverwaltung
+         * @param $product_id
+         */
+        public function getProductListBackend($product_id, $size = 'thumbnail')
+        {
+            
+            global $wpdb;
+			
+			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key`='".wpsg_q('wpsg_produkt_id')."' AND `meta_value`='".wpsg_q($product_id)."' ORDER BY `post_id`");
+			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($product_id));
+			$arPostids = explode(',', $postids);
+			
+			$wp_upload_dir = wp_upload_dir();
+			$url = $wp_upload_dir['url'];
+			$i = 0;
+			
+			if (wpsg_isSizedString($postids)) {
+				foreach ($arPostids as $postid) {
+					
+					for ($i = 0; $i < count($data); $i++) {
+						if ($data[$i]['post_id'] == $postid) {
+							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
+							$guid = $p[0];
+							$arrf = pathinfo($guid);
+							$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $data[$i]['post_id'];
+							$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+							$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
+							
+							$file = $arrf['basename'];
+							$pos1 = strrpos($file, '-');
+							if ($pos1 !== false) {
+								$pos2 = strrpos($file, '.');
+								//$file = substr_replace($file, '', $pos1, $pos2 - $pos1);
+							}
+							$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+							$this->shop->view['ProduktBilder_MT'][$i]['basenameori']= $file;
+							
+						}
+					}
+				}
+				
+			} else {
+				foreach ($data as $key => $val) {
+					/*
+					$p1 = wp_get_attachment_url($val['ID']);
+					$arrf = pathinfo($p1);
+					$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+					$guid = $arrf['dirname'].'/'.$arrf['filename'].'-150x150.'.$arrf['extension'];
+					*/
+					$p = wp_get_attachment_image_src($val['post_id'], $size);	// Array mit Full-Path, Width, Height
+					$guid = $p[0];
+					$arrf = pathinfo($guid);
+					$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $val['post_id'];
+					$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+					$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
+					$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $arrf['basename']);
+					$this->shop->view['ProduktBilder_MT'][$i]['basenameori']= $file;
+					$i++;
+				}
+			}
+            
+			return $this->shop->render(WPSG_PATH_VIEW.'/produkt/images_list.phtml', false);
+            
+        } // public function getProductListBackend($product_id)
+        
+    } // class wpsg_imagehandler
Index: /model/wpsg_product.class.php
===================================================================
--- /model/wpsg_product.class.php	(revision 6437)
+++ /model/wpsg_product.class.php	(revision 6438)
@@ -90,4 +90,22 @@
 
 		} // public function setProductKey($product_key)
+
+		/**
+		 * Gibt den ProductKey zurÃŒck
+		 */
+		public function getProductKey()
+		{
+			
+			if (strlen($this->product_key) > 0) return $this->product_key;
+			else
+			{
+				 
+				if (wpsg_isSizedString($this->loadedData['product_key'])) return $this->loadedData['product_key'];
+				
+			}
+			
+			return $this->id;
+			
+		} // public function getProductKey()
 
 		/**
@@ -681,7 +699,4 @@
 				$strQueryWHERE_OR = "";
 
-				// FÃŒr die Suche nur fÃŒr alte Artikel
-				if ($GLOBALS['wpsg_sc']->hasMod('wpsg_mod_productvariants')) $strQueryWHERE_OR .= " OR `mod_varianten` LIKE '%".wpsg_q($arFilter['s'])."%' ";
-
 				$strQueryWHERE .= "
 					AND (
@@ -777,4 +792,47 @@
 		} // public function getQueryParts($arFilter = array())
 
+		public static function getInstance($product_key, $noCache = false)
+		{
+			
+			$class_name = get_called_class();
+			 
+			if (wpsg_isSizedArray($product_key))
+			{
+				
+				$arReturn = [];
+				
+				foreach ($product_key as $_id)
+				{
+					
+					$arReturn[$_id] = self::getInstance($_id);
+										
+				}
+				
+				return $arReturn;
+				
+			}
+			else if (is_array($product_key)) return array();
+			else
+			{
+			
+				if (!array_key_exists($class_name.'_'.$product_key, self::$_objCache) || $noCache === true)
+				{
+					
+					$product_id = $GLOBALS['wpsg_sc']->getProduktId($product_key);
+					
+					$oObject = new $class_name(); 
+					$oObject->load($product_id);
+					$oObject->setProductKey($product_key);
+	
+					self::$_objCache[$class_name.'_'.$product_key] = $oObject;
+			
+				}
+					
+				return self::$_objCache[$class_name.'_'.$product_key];
+				
+			}
+			
+		} // public static function getInstance($id, $noCache = false)
+
 	} // class wpsg_product extends wpsg_model
 
Index: ds/wpsg_mod_core.class
===================================================================
--- /mods/wpsg_mod_core.class	(revision 6437)
+++ 	(revision )
@@ -1,606 +1,0 @@
-<?php
-
-	/**
-	 * Dieses Modul ist ein verstecktes System Modul und ist nur in der Lizezierten Version vorhanden
-	 * @author Daschmi (daniel@maennchen1.de) 02.10.2015
-	 */
-	class wpsg_mod_core extends wpsg_mod_basic
-	{
-		 
-		var $id = 1630;
-		
-		public function __construct()
-		{
-			
-			parent::__construct(); 
-			
-		} // public function __construct()
-		
-		/**
-		 * LÃ€dt die Module
-		 */
-		public function loadModule($all)
-		{
-			 
-			$mod_dir = opendir(WPSG_PATH_MOD);
-				
-			$global = false;
-			if ($this->shop->isMultiBlog() && $this->shop->get_option('wpsg_multiblog_standalone', true) != '1') $global = true;
-				
-			while ($file = readdir($mod_dir))
-			{
-			
-				if (!is_dir(WPSG_PATH_MOD."/".$file) && $file != "." && $file != ".." && preg_match("/(.*)\.class\.php/i", $file) && $file != "wpsg_mod_basic.class.php")
-				{
-						
-					if (file_exists(WPSG_PATH_USERMOD.$file)) require_once(WPSG_PATH_USERMOD.$file);
-					else require_once(WPSG_PATH_MOD.$file);
-						
-					$class_name = preg_replace("/\.class\.php/", "", $file);
-						
-					$mod = new $class_name();
-						
-					// Demo oder Modul fÃŒr Lizenz aktiv
-					/*if ($this->shop->arLizenz['l'] == 0 || $this->shop->arLizenz['l'] >= $mod->lizenz)
-					{
-							
-						if (!isset($mod->version) || $mod->getDemoDays() > 0 || (isset($this->shop->arLizenz) && in_array(get_class($mod), (array)$this->shop->arLizenz['mods'])))
-						{
-			
-							if ($this->shop->get_option($class_name, $global) > 0 || $class_name === 'wpsg_mod_core')
-							{
-			
-								$this->shop->arModule[$class_name] = $mod;
-			
-							}
-			
-						}
-							
-						if ($all)
-						{
-			
-							$this->shop->arAllModule[$class_name] = $mod;
-			
-						}
-			
-					} */
-						
-				}
-			
-			}
-			
-			$pluginModule = array(); $pluginModule = apply_filters('wpsg_modul_load', array($pluginModule));
-			
-			if (wpsg_isSizedArray($pluginModule))
-			{
-				
-				foreach ($pluginModule as $class_name => $mod)
-				{
-					
-					if (!is_object($mod)) continue;
-					
-					if ($this->shop->get_option($class_name, $global) > 0)
-					{
-	
-						$this->shop->arModule[$class_name] = $mod;
-	
-					}
-					
-					if ($all)
-					{
-		
-						$this->shop->arAllModule[$class_name] = $mod;
-		
-					}
-					
-				}
-				
-			}
-			 			
-			uasort($this->shop->arModule, array($this->shop, "cmp_mods"));
-				
-			if ($all) uasort($this->shop->arAllModule, array($this->shop, "cmp_mods"));
-			
-			// Module werden hier erst initiiert, da dann alle Module bekannt sind und die Reihenfolge hergestellt ist
-			foreach ($this->shop->arModule as $mod_key => $m)
-			{
-			
-				if ($this->shop->get_option(get_class($m), $global) > 0)
-				{
-			
-					$m->init();
-						
-				}
-			
-			}
-			
-		} // public function loadModule($all)
-		
-		/**
-		 * Gibt true zurÃŒck wenn eine aktive Lizenz eingebunden ist
-		 */
-		public function hasActiveLicence()
-		{
-			
-			if (is_array($this->shop->arLizenz) && isset($this->shop->arLizenz['l']))
-			{
-			
-				// PrÃŒfen das in einem Multiblog nur mit der Enterprise Version gearbeitet wird
-				if ($this->shop->isMultiBlog() && $this->shop->arLizenz['l'] < 3)
-				{
-						
-					// Die installierte Lizenz kann nicht in einer Multiblog Umgebung eingesetzt werden.
-					$this->shop->addBackendError(base64_decode('RGllIGluc3RhbGxpZXJ0ZSBMaXplbnoga2FubiBuaWNodCBpbiBlaW5lciBNdWx0aWJsb2cgVW1nZWJ1bmcgZWluZ2VzZXR6dCB3ZXJkZW4u'));
-					
-					return false;
-						
-				}
-			
-				return true;
-			
-			}
-				
-			if ($this->shop->getDemoDays() < 0)
-			{
-			
-				// Ihre Lizenz von wpShopGermany ist abgelaufen
-				//$this->shop->addBackendError(base64_decode('SWhyZSBMaXplbnogdm9uIHdwU2hvcEdlcm1hbnkgaXN0IGFiZ2VsYXVmZW4='));
-			
-			}
-			
-			return false;
-			
-		}
-		
-		/**
-		 * Gibt die Tage der DemoVersion zurÃŒck
-		 */
-		public function getDemoDays()
-		{
-			
-			$isnt = $this->shop->get_option('wpsg_installed', true);
-			$rem = round((($isnt + 14 * 60 * 60 * 24) - time()) / (60 * 60 * 24), 0);
-				
-			return $rem;
-			
-		} // public function getDemoDays()
-		
-		public function admin_registrierung()
-		{
-			
-			if (!class_exists('SoapClient'))
-			{
-			
-				$this->shop->addBackendError(__('nohspc_Ihrem Server fehlt die PHP-Bibliothek fÃŒr die SOAP-UnterstÃŒtzung. Eine Registrierung Ihrer Domain ist somit nicht mÃ¶glich! <br />Weitere Informationen finden Sie in unseren <a target="_blank" href="http://wpshopgermany.maennchen1.de/faqs/wie-pruefe-ich-ob-soap-und-curl-auf-meinem-server-aktiviert-sind/">FAQ</a>.', 'wpsg'));
-				$this->shop->view['actionName'] = 'registrierung';
-				$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
-			
-				return;
-			
-			}
-				
-			if (!$this->shop->arLizenz['nr'] > 0 && wpsg_getStr($_REQUEST['do']) != 'installModul') {
-			
-				$this->shop->view = array(
-					'actionName' => 'registrierung',
-					'subTemplate' => WPSG_PATH_VIEW.base64_decode('L21vZHMvbW9kX2NvcmUvYWRtaW5fbGljZW5jZS5waHRtbA==') // /mods/mod_core/admin_licence.phtml
-				);
-			
-			}
-			else
-			{
-			
-				if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'remove')
-				{
-			
-					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('removeURL', array($_REQUEST['url'])));
-						
-					if ($reg_data === false) { $this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg')); }
-					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
-					else { $this->shop->addBackendMessage(__('Domainregistrierung erfolgreich entfernt.', 'wpsg')); }
-						
-					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&subaction=domains');
-						
-				}
-				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'register')
-				{
-						
-					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('registerURL', array($this->shop->get_option('siteurl'))));
-						
-					if ($reg_data === false) { $this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg')); }
-					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
-					else { $this->shop->addBackendMessage(__('Domainregistrierung erfolgreich.', 'wpsg')); }
-						
-					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&subaction=domains');
-						
-				}
-				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'getCredentials')
-				{
-						
-					$this->getCredentialsAction();
-						
-					return;
-						
-				}
-				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'installModul')
-				{
-											
-					if ($this->installModul($_REQUEST['modul']))
-					{
-			
-						$this->shop->addBackendMessage(__('Modul erfolgreich installiert.', 'wpsg'));
-			
-					}
-			
-					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module');
-						
-				}
-				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'aktivateModul')
-				{
-						
-					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('aktivateModul', array($_REQUEST['wpsg_modulkey'])));
-						
-					if ($reg_data === false) { $this->shop->addBackendError(__('Modul konnte nicht aktiviert werden.', 'wpsg')); }
-					else if ($reg_data === -1) { $this->shop->addBackendError(__('UngÃŒltiger Modulcode.', 'wpsg')); }
-					else if ($reg_data === -2) { $this->shop->addBackendError(__('Code bereits fÃŒr einen anderen SchlÃŒssel verwendet.', 'wpsg')); }
-					else if ($reg_data === -3) { $this->shop->addBackendError(__('Modul bereits aktiviert.', 'wpsg')); }
-					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
-					else {
-			
-						// Neuen Modulcode speichern
-						$this->shop->update_option('wpsg_key', $reg_data, true);
-			
-						$this->shop->addBackendMessage(__('Modul erfolgreich aktiviert.', 'wpsg'));
-							
-					}
-						
-					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&subaction=module');
-						
-				}
-			
-				if (isset($_REQUEST['registerdata-submit']))
-				{
-						
-					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('setRegisterInfo', array($_REQUEST)));
-						
-					if ($reg_data === false) { $this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg')); }
-					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
-					else { $this->shop->addBackendMessage(__('Registrierungsdaten erfolgreich ÃŒbermittelt', 'wpsg')); }
-						
-					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung');
-						
-				}
-			
-				// Daten vom Registrierungsserver laden
-				$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('getRegisterInfo'));
-			
-				// Aktuelle Domain registriert?
-				$reg_data['registred'] = false;
-				$arURLs = array();
-				foreach ((array)$reg_data['domains'] as $d)
-				{
-						
-					$arURLs[] = preg_replace('/(.*)\/\//', '', $d['url']);
-						
-					if (preg_match('/((http\:\/\/)|(https\:\/\/)){0,1}'.preg_quote($this->shop->get_option('siteurl'), '/').'\/*/', $d['url']))
-					{
-						$reg_data['registred'] = true; break;
-					}
-						
-				}
-			
-				$this->shop->update_option('wpsg_registredURLs', $arURLs);
-			
-				if ($reg_data === false)
-				{
-						
-					$this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg'));
-						
-				}
-				else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data))
-				{
-						
-					$this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error']));
-			
-				}
-			
-				$this->shop->view = array(
-					'data' => $reg_data,
-					'actionName' => 'registrierung',
-					'subTemplate' => WPSG_PATH_VIEW.base64_decode('L21vZHMvbW9kX2NvcmUvYWRtaW5fcmVnaXN0ZXIucGh0bWw='), // /mods/mod_core/admin_register.phtml
-					'mods' => $this->shop->arLizenz['mods']
-				);
-			
-				$this->shop->loadModule(true);
-			
-				switch ($this->shop->arLizenz['l'])
-				{
-						
-					case '1': $this->shop->view['typ'] = __('Light Version', 'wpsg'); break;
-					case '2': $this->shop->view['typ'] = __('Pro Version', 'wpsg'); break;
-					case '3': $this->shop->view['typ'] = __('Enterprise Version', 'wpsg'); break;
-					default: die();
-						
-				}
-			
-			}
-			
-			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
-			
-		} // public function admin_registrierung()
-		
-		public function module_index()
-		{
-			
-			if (class_exists('SoapClient'))
-			{
-		
-				$this->shop->view['arOnlineModule'] = $this->RegisterCall('getModulInfo_V2');
-		
-				foreach ((array)$this->shop->view['arOnlineModule'] as $k => $m)
-				{
-		
-					if (wpsg_isSizedString($m['version_dev']) && wpsg_isSizedInt($this->shop->get_option('wpsg_debugURL'))) $this->shop->view['arOnlineModule'][$k]['version'] = $m['version_dev'];
-		
-					$this->shop->view['arOnlineModule'][$k]['version_local'] = $this->shop->arAllModule[$m['key']]->version;
-		
-					$global = false;
-					if ($this->shop->isMultiBlog() && $this->shop->get_option('wpsg_multiblog_standalone', true) != '1') $global = true;
-		
-					if ($this->shop->get_option($m['key'], $global) > 0)
-					{
-							
-						$this->shop->view['arOnlineModule'][$k]['installed'] = true;
-							
-					}
-					else
-					{
-							
-						$this->shop->view['arOnlineModule'][$k]['installed'] = false;
-							
-					}
-		
-					if ($this->shop->get_option('wpsg_debugURL') == '1' && isset($this->shop->view['arOnlineModule'][$k]['version_dev']))
-					{
-		
-						$this->shop->view['arOnlineModule'][$k]['version'] = $m['version_dev'];
-							
-					}
-		
-				}
-						
-			}
-			else
-			{
-					
-				$this->shop->addBackendError(__('nohspc_Ihrem Server fehlt die PHP-Bibliothek fÃŒr die SOAP-UnterstÃŒtzung. Eine Registrierung Ihrer Domain ist somit nicht mÃ¶glich! <br />Weitere Informationen finden Sie in unseren <a target="_blank" href="http://wpshopgermany.maennchen1.de/faqs/wie-pruefe-ich-ob-soap-und-curl-auf-meinem-server-aktiviert-sind/">FAQ</a>.', 'wpsg'));
-					
-			}
-			
-			echo $this->render(WPSG_PATH_VIEW.'/mods/mod_core/module_index.phtml');
-			
-		} // public function module_index()
-		
-		/**
-		 * Sendet eine Anfrage an den Registrierungs Server und gibt das Ergebnis zurÃŒck
-		 */
-		public function RegisterCall($func_name, $args = array())
-		{
-				
-			$SOAP = new SoapClient(
-				null,
-				array(
-					'location' => base64_decode('aHR0cHM6Ly9zaG9wLm1hZW5uY2hlbjEuZGUvcmVnaXN0cmllcnVuZy8='), // https://shop.maennchen1.de/registrierung/
-					'uri' => 'http://shop.maennchen1.de',
-					'cache_wsdl' => WSDL_CACHE_NONE
-				)
-			);
-				
-			if (!$this->shop->hasActiveLicence())
-			{
-					
-				$args = array_merge(array('No_wpsg'), $args);
-		
-			}
-			else
-			{
-		
-				// Hier kein wpsg_array_merge da die index gleich sind
-				$args = array_merge(array($this->shop->get_option('wpsg_key', true)), $args);
-		
-			}
-				
-			try {
-					
-				$result = $SOAP->__soapCall($func_name, $args);
-		
-			}
-			catch (Exception $e)
-			{
-		
-				$this->shop->addBackendError(wpsg_translate(__('SOAP Fehler: #1#', 'wpsg'), $e->getMessage()));
-		
-			}
-				
-			return $result;
-				
-		} // public function RegisterCall($func_name, $args)
-	
-		public function installModul($modul_key)
-		{
-			
-			global $wp_filesystem;
-			
-			ob_start();
-			$request_creds = request_filesystem_credentials(
-				WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&noheader=1&do=installModul&modul='.$modul_key,
-				'',
-				false,
-				false,
-				null
-			);
-			ob_end_clean();
-				
-			// 1 gibt es bei Windows Rechnern zurÃŒck, da es hier egal ist
-			// Ein Array ist es wenn das Formular bereits abgeschickt wurde und die Anfrage vom Formular kommt
-			// false ist es wenn kein Zugriff ist dann muss das Formular angezeigt werden
-				
-			if (false === $request_creds)
-			{
-			
-				// Berechtigungen anfragen
-				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&do=getCredentials&modul='.$_REQUEST['modul']);
-			
-			}
-			else if (is_array($request_creds))
-			{
-			
-				if (!WP_Filesystem($request_creds))
-				{
-			
-					// Eingegebene Daten waren falsch
-					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&do=getCredentials&modul='.$_REQUEST['modul']);
-			
-				}
-			
-			}
-			
-			$temp_name = $this->shop->getTempName($modul_key.'.zip');
-			@unlink($temp_name);
-				
-			if ($this->shop->get_option('wpsg_debugURL') === '1' && $this->shop->hasMod('wpsg_mod_core'))
-			{
-			
-				$url = 'http://dl.maennchen1.de/wpsg/'.$modul_key.'/'.$modul_key.'_dev.zip';
-			
-			}
-			else
-			{
-			
-				$url = 'http://dl.maennchen1.de/wpsg/'.$modul_key.'/'.$modul_key.'_latest.zip';
-			
-			}
-			
-			$bOK = @copy($url, $temp_name);
-			
-			if (!$bOK)
-			{
-			
-				$bOK = @file_put_contents($temp_name, $this->shop->get_url_content($url));
-			
-				if (!$bOK)
-				{
-						
-					// Pfad finden fÃŒr das Wordpress Filesystem
-					if ($GLOBALS['wpsg_sc']->isMultiBlog())
-						$ftp_path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/';
-						else
-							$ftp_path = WP_CONTENT_DIR.'/uploads/wpsg_temp/';
-								
-							$ftp_path = trailingslashit($wp_filesystem->find_folder($ftp_path)).preg_replace('/(.*)\/wpsg_temp\//', '', $temp_name);
-								
-							$bOK = $wp_filesystem->put_contents($ftp_path, $this->shop->get_url_content($url), FS_CHMOD_FILE);
-								
-							if (!$bOK)
-							{
-									
-								$this->shop->addBackendError(wpsg_translate(__('Modul (#1#) konnte nicht kopiert werden!', 'wpsg'), $modul_key));
-								return false;
-			
-							}
-								
-				}
-			
-			}
-				
-			$zip = new ZipArchive();
-			
-			if ($zip->open($temp_name) === true)
-			{
-			
-				try
-				{
-						
-					$bOK = @$zip->extractTo(WPSG_PATH.'/../');
-					$zip->close();
-			
-					if ($bOK === false)
-					{
-			
-						throw new Exception();
-							
-					}
-					else
-					{
-			
-						return true;
-							
-					}
-			
-				}
-				catch (Exception $e)
-				{
-						
-					// Es ist ein Fehler aufgetreten, jetzt versuche ich die Datei mit dem Wordpress Filesystem zu entpacken
-						
-					// Pfad finden fÃŒr das Wordpress Filesystem
-					$ftp_path = trailingslashit($wp_filesystem->find_folder(realpath(WPSG_PATH.'/../')));
-						
-					$bOK = unzip_file($temp_name, $ftp_path);
-						
-					if ($bOK !== true)
-					{
-			
-						$strError = '';
-			
-						// Hier ist immer noch ein Fehler aufgetreten
-						foreach ((array)$bOK->errors as $e)
-						{
-								
-							$strError .= $e[0].' ';
-			
-						}
-						 
-						$this->shop->addBackendError(wpsg_translate(__('Fehler beim Entpacken: #1#', 'wpsg'), $strError)); return false;
-			
-					}
-					else
-					{
-			
-						return true;
-			
-					}
-						
-				}
-			
-			}
-			else
-			{
-			
-				$this->shop->addBackendError(__('Datei konnte nicht ÃŒbertragen werden.', 'wpsg')); return false;
-			
-			}
-			
-			$this->shop->addBackendError(__('Datei konnte nicht entpackt werden.', 'wpsg')); return false;
-			
-		} // public function installModul($modul_key)
-		
-		/**
-		 * Fragt die Rechte ab und installiert anschlieÃend ein Modul
-		 */
-		public function getCredentialsAction()
-		{
-				
-			echo request_filesystem_credentials(
-				WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&noheader=1&do=installModul&modul='.$_REQUEST['modul'],
-				'',
-				false,
-				false,
-				null
-			);
-				
-		} // public function getCredentialsAction()
-		
-	} // class wpsg_mod_core extends wpsg_mod_basic
-
-?>
Index: /mods/wpsg_mod_downloadplus.class.php
===================================================================
--- /mods/wpsg_mod_downloadplus.class.php	(revision 6437)
+++ /mods/wpsg_mod_downloadplus.class.php	(revision 6438)
@@ -776,5 +776,4 @@
 				
 				$arVarianten = $this->shop->callMod('wpsg_mod_productvariants', 'getVariants', array($p_id, true, true, true));
-				$this->unserializeVariant($arVarianten);
 				
 				$strVarKey = preg_replace('/(^pv_\d+\|)/', '', $p_key);
Index: /mods/wpsg_mod_productvariants.class.php
===================================================================
--- /mods/wpsg_mod_productvariants.class.php	(revision 6437)
+++ /mods/wpsg_mod_productvariants.class.php	(revision 6438)
@@ -65,8 +65,5 @@
 				name varchar(255) NOT NULL,
 				shortname varchar(255) NOT NULL,
-				anr varchar(255) NOT NULL,
-				price double(10,2) NOT NULL,
-				stock int(11) NOT NULL,
-				images text NOT NULL,
+				anr varchar(255) NOT NULL,				 
 				deleted int(1) NOT NULL,
 				pos int(11) NOT NULL,
@@ -97,4 +94,5 @@
 				stock int(11) NOT NULL,
 				images text NOT NULL,
+				images_set text NOT NULL,
 				weight double(10,2) NOT NULL,
 				fmenge double(10,2) NOT NULL,
@@ -172,5 +170,5 @@
 			if (wpsg_isSizedString($_REQUEST['action'], 'wpsg_productvariants_switch'))
 			{
-
+				
 				if (wpsg_isSizedInt($_REQUEST['wpsg_post_id']))
 				{
@@ -188,6 +186,5 @@
 
                 $this->getProductKeyFromRequest($product_key, $product_id, $form_data);
-                //$product_key = $_REQUEST['product_key'];
-
+                
 				$product_data = $this->shop->loadProduktArray($product_id, array(
 					'id' => $product_key,
@@ -219,6 +216,5 @@
 
 			$product_data['arVariant'] = $this->getVariants($product_data['product_id'], true, true, true);
-			$this->unserializeVariant($product_data['arVariant']);
-
+			
 			if (wpsg_isSizedArray($product_data['arVariant']))
 			{
@@ -358,10 +354,5 @@
         public function getProductKeyFromRequest(&$product_key, $product_id, $form_data)
         {
-
-            //if (!wpsg_isSizedArray($form_data['wpsg_mod_productvariants'])) return false;
-
-            //foreach ($form_data['wpsg_mod_productvariants'] as $var_id => $vari_id) $form_data['wpsg_mod_productvariants'][$var_id] = $var_id.':'.$vari_id;
-            //$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_mod_productvariants']);
-
+ 
         	if (!wpsg_isSizedArray($form_data['wpsg_vp'])) return false;
 
@@ -579,80 +570,27 @@
         	else if ($_REQUEST['cmd'] == 'wpsg_var_setImageOrder')
         	{
-
-        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
-        		$this->unserializeVariant($vp_data);
-
-        		if ($_REQUEST['vari_id'] == -1)
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['picOrder'] = $_REQUEST['wpsg_reorder'];
-
-        		}
-        		else
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['picOrder'] = $_REQUEST['wpsg_reorder'];
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pidOrder'] = $_REQUEST['wpsg_postids'];
-        			
-        		}
-
-        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
+				
+				$vp_data = $this->getVariants($_REQUEST['edit_id'], true, false, true);
+				
+				$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['vari_id']]['images'] = implode(',', $_REQUEST['wpsg_reorder']);
+
+				$this->saveVariantsData($vp_data);
 
         		die("1");
-
+				
         	}
         	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_setPic')
         	{
-        		//die('wpsg_vp_vari_setPic');
-        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
-        		$this->unserializeVariant($vp_data);
-
-        		if ($_REQUEST['vari_id'] >= 0)
-        		{
-
-        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic']);
-        			$arPostid = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid']);
-
-        			$pic = $_REQUEST['pic'];
-        			$postid = $_REQUEST['post_id'];
-
-        			$pic = preg_replace('/\-(\d+)x(\d+)\./', '.', $pic);
-
-        			if (in_array($pic, $arPic))
-        			{
-        				unset($arPic[array_search($pic, $arPic)]);
-        				unset($arPostid[array_search($postid, $arPostid)]);
-        			}
-        			else
-        			{
-        				$arPic[] = $pic;
-        				$arPostid[] = $postid;
-        			}
-
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic'] = implode(",", $arPic);
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid'] = implode(",", $arPostid);
-
-        		}
-        		else
-        		{
-
-        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['pic']);
-
-        			if (in_array($_REQUEST['pic'], $arPic))
-        			{
-        				unset($arPic[array_search($_REQUEST['pic'], $arPic)]);
-        			}
-        			else
-        			{
-        				$arPic[] = $_REQUEST['pic'];
-        			}
-
-        			$vp_data[$_REQUEST['var_id']]['pic'] = implode(",", $arPic);
-
-        		}
-
-        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
+
+        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, false, true);
+				
+				$arImages = explode(',', @$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['vari_id']]['images_set']);
+				
+				if (!in_array($_REQUEST['attachment_id'], $arImages)) $arImages[] = $_REQUEST['attachment_id'];
+				else unset($arImages[array_search($_REQUEST['attachment_id'], $arImages)]);
+				
+				$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['vari_id']]['images_set'] = implode(',', wpsg_trim(array_unique($arImages)));
+				
+				$this->saveVariantsData($vp_data);
 
         		die("1");
@@ -781,5 +719,5 @@
         		}
 
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		$this->saveVariantsData($vp_data);
 
         		die(strval($_REQUEST['value']));
@@ -855,40 +793,57 @@
          * Speichert die Varianten
          */
-        public function saveVarianten($produkt_id, $vp_data)
+        public function saveVariantsData($vp_data)
         {
-
-        	$vp_data = $this->clearArrayForSerialization($vp_data);
-
-        	$temp = wpsg_q(serialize($vp_data));
-        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
-        		"images" => wpsg_q(serialize($vp_data))
-        	), "`id` = '".wpsg_q($_REQUEST['vari_id'])."'");
-
-        } // public function saveVarianten($produkt_id, $vp_data)
-
-        /**
-         * Speichert die Variationen
-         */
-        public function saveVariation($produkt_id, $vp_data)
-        {
-
-        	$vp_data = $this->clearArrayForSerialization($vp_data);
-
-        	$temp = wpsg_q(serialize($vp_data));
-        	$vdata['pic'] = '';
-        	if (isset($vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic']))
-        		$vdata['pic'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic'];
-        	$vdata['picOrder'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['picOrder'];
-        	$vdata['postid'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['postid'];
-
-        	if (isset($vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pidOrder']))
-        		$vdata['pidOrder'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pidOrder'];
-        	
-        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
-        			"images" => wpsg_q(serialize($vdata))
-        	), "`variation_id` = '".wpsg_q($_REQUEST['vari_id'])."'");
-
-        } // public function saveVariation($produkt_id, $vp_data)
-
+ 
+			foreach ($vp_data as $var_id => $var_data)
+			{
+				
+				foreach ($var_data['arVariation'] as $vari_id => $vari_data)
+				{
+					
+					if (!wpsg_isSizedInt($vari_data['id']))
+					{
+					
+						// Variation zu Produkt suchen
+						$exist_id = $this->db->fetchOne("SELECT `id` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `variation_id` = '".wpsg_q($_REQUEST['vari_id'])."' AND `product_id` = '".wpsg_q($_REQUEST['product_id'])."' ");
+						
+						$vari_data['id'] = $exist_id;
+						
+					}
+						
+					
+					if (!wpsg_isSizedInt($vari_data['id']))
+					{
+						
+						// Ist im Request alles drin was ich brauche, dann anlegen
+						if (wpsg_isSizedInt($_REQUEST['var_id']) && wpsg_isSizedInt($_REQUEST['vari_id']) && wpsg_isSizedInt($_REQUEST['product_id']))
+						{
+							
+							$this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+								'variation_id' => wpsg_q($_REQUEST['vari_id']),
+								'product_id' => wpsg_q($_REQUEST['product_id']),
+								'images' => wpsg_q($vari_data['images']),
+								'images_set' => wpsg_q($vari_data['images_set'])
+							));
+							
+						}
+						
+					} 
+					else 
+					{
+						
+						$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+							'images' => wpsg_q($vari_data['images']),
+							'images_set' => wpsg_q($vari_data['images_set'])
+						), " `id` = '".wpsg_q($vari_data['id'])."' ");
+						
+					}
+					
+				}
+				
+			} 
+						
+        } // public function saveVariantsData($produkt_id, $vp_data)
+ 
         /**
          * LÃ€dt die Varianteninformationen aus dem serialisierten Array
@@ -1012,4 +967,5 @@
 
         /**
+		 * DEPRECATED!
          * Gibt die Bilder als Array fÃŒr die Variation zurÃŒck
          * Beachtet die Reihenfolge die im Backend ÃŒber Drag&Drop definiert ist
@@ -1025,6 +981,5 @@
         	//$vp_data = $this->loadVarianten($product_id);
         	$vp_data = $this->getVariants($product_id, true, true, true);
-        	$this->unserializeVariant($vp_data);
-
+        	
         	$arProductBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
 
@@ -1184,4 +1139,16 @@
 		{
 
+			if (!$this->isVariantsProductKey($product_key)) return false;
+
+			$product_id = $this->shop->getProduktID($product_key);
+			
+			$vp_data = $this->getVariants($product_id, true, true, true);
+									
+			$this->shop->view['vp_data'] = $vp_data;
+			$this->shop->view['vp_info'] = $this->getVariantenInfoArray($product_key);
+			
+			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt.phtml', false);
+			
+			/*
 			$produkt_id = $this->shop->getProduktId($product_key);
 			$produkt_data = $this->shop->cache->loadProduct($produkt_id);
@@ -1199,6 +1166,5 @@
 			//public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false)
 			$vp_data = $this->getVariants($produkt_id, true, true, true);
-			$this->unserializeVariant($vp_data);
-
+			
 			if ($this->isVariantsProductKey($product_key)) {
 				$arVar = $this->explodeProductKey($product_key);
@@ -1307,5 +1273,6 @@
 				return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt.phtml', false);
 
-			}
+			}			
+			*/ 
 
 		} // public function renderTemplate($produkt_id)
@@ -1646,6 +1613,5 @@
 			//$arVari = $this->loadVarianten($product_id);
 			$arVari = $this->getVariants($product_id, true, true, true);
-			$this->unserializeVariant($arVari);
-
+			
 			$arTemp = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
 
@@ -1769,5 +1735,5 @@
 
 				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
-				$strQuerySELECT .= " , PV.`id` AS iid, PV.`variation_id`, PV.`active`, PV.`anr`, PV.`price`, PV.`stock`, PV.`images`, PV.`weight`, PV.`fmenge` ";
+				$strQuerySELECT .= " , PV.`id` AS iid, PV.`variation_id`, PV.`active`, PV.`anr`, PV.`price`, PV.`stock`, PV.`images`, PV.`images_set`, PV.`weight`, PV.`fmenge` ";
 
 			}
@@ -1794,7 +1760,4 @@
 
 			$arVari = $this->db->fetchAssoc($strQuery);
-			$this->unserializeVariation($arVari);
-
-			// TODO: Ãbersetzung
 
 			return $arVari;
@@ -1816,26 +1779,5 @@
 			}
 		}	// private function unserializeVariation(&$arVari)
-
-		private function unserializeVariant(&$arVar) {
-			foreach ($arVar as &$va) {
-				if ($va['type'] == 0) $va['typ'] = 'select';
-				if ($va['type'] == 1) $va['typ'] = 'radio';
-				if ($va['type'] == 2) $va['typ'] = 'image';
-
-				foreach ($va['arVariation'] as &$vi) {
-					$ar = @unserialize($vi['images']);
-					$vi['pic'] = '';
-					$vi['sel'] = 0;
-					$vi['picOrder'] = Array();
-					if (wpsg_isSizedArray($ar)) {
-						foreach($ar as $k => $v) {
-							$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
-							$vi[$k] = $v;
-						}
-					}
-				}
-			}
-		}	// private function unserializeVariant(&$arVar)
-
+ 
 		public function stockVarianten($product_id)
 		{
@@ -1846,6 +1788,5 @@
 			//$this->shop->view['arVariant']
 			$vp_data = $this->getVariants($product_id, true, true, true);
-			$this->unserializeVariant($vp_data);
-
+			
 			$html = '<table>';
 			foreach ($vp_data as $var) {
@@ -2003,5 +1944,5 @@
 		 * @param Boolean $global Globale Varianten?
 		 */
-		public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false, $serVariationen = false)
+		public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false)
 		{
 
@@ -2100,4 +2041,8 @@
 					{
 
+						$strQueryWHERE = "";
+						
+						if ($onlyActive === false) $strQueryWHERE .= " AND PVI.`active` = '1' ";
+						
 						$arData[$k]['arVariation'] = $this->db->fetchAssoc("
 							SELECT
@@ -2110,23 +2055,9 @@
 								VI.`deleted` != '1' AND
 								VI.`variant_id` = '".wpsg_q($v['id'])."' AND
-								PVI.`product_id` = '".wpsg_q($product_id)."' AND
-								PVI.`active` = '1'
+								PVI.`product_id` = '".wpsg_q($product_id)."' 								
 							ORDER BY
 								VI.`pos` ASC
 						", "variation_id");
-
-						// Bilder deserialisieren
-						foreach ($arData[$k]['arVariation'] as $vari_id => $vari_data)
-						{
-
-							if ($serVariationen == true) {
-								$arData[$k]['arVariation'][$vari_id]['images'] = @unserialize($vari_data['images']);
-								if (wpsg_isSizedString($arData[$k]['arVariation'][$vari_id]['images'])) $arData[$k]['arVariation'][$vari_id]['images'] = wpsg_trim(explode(',', $arData[$k]['arVariation'][$vari_id]['images']));
-								else $arData[$k]['arVariation'][$vari_id]['images'] = array();
-
-							}
-
-						}
-
+ 
 					}
 				}
@@ -2192,16 +2123,13 @@
 		 * Liest die Informationen anhand eines VariantenschlÃŒssels aus
 		 */
-		public function getVariantenInfoArray($vari_key)
-		{
-
-			//$produkt_id = preg_replace('/(vp_)|(\/(.*))/', '', $vari_key);
-			$produkt_id = preg_replace('/(pv_)|(\|(.*))/', '', $vari_key);
-			//$arVari = explode('|', preg_replace('/vp_'.$produkt_id.'\//', '', $vari_key));
-			$arVari = explode('|', preg_replace('/pv_'.$produkt_id.'\|/', '', $vari_key));
+		public function getVariantenInfoArray($product_key)
+		{
+
+			$produkt_id = $this->shop->getProduktID($product_key);
+			$arVari = explode('|', preg_replace('/pv_'.$produkt_id.'\|/', '', $product_key));
 
 			//$vp_data = $this->loadVarianten($produkt_id);
 			$vp_data = $this->getVariants($produkt_id, true, true, true);
-			$this->unserializeVariant($vp_data);
-
+			
 			$arKey = array();
 			$arAKey = array();
@@ -2211,8 +2139,8 @@
 
 			// kein Produkt-Key dann keine Weiterarbeit nÃ¶tig
-			if (is_numeric($vari_key)) {
+			if (is_numeric($product_key)) {
 				$arReturn['key'] = '';
 				$arReturn['akey'] = '';
-				$arReturn['pics'] = array();
+				$arReturn['images'] = array();
 				return $arReturn;
 
@@ -2222,4 +2150,8 @@
 			if ($this->shop->hasMod('wpsg_mod_weight')) $arReturn['weight'] = 0;
 
+			/** Alle Bilder des Produkts */
+			$arImagesProduct = $this->shop->imagehandler->getAttachmentIDs($produkt_id);
+			$arImages = $arImagesProduct;
+			
 			foreach ($arVari as $var_key)
 			{
@@ -2228,107 +2160,49 @@
 				$var_value = preg_replace('/(.*)\:/', '', $var_key);
 
-				if ($vp_data[$var_id]['typ'] == 'checkbox')
+				$arPicsVariante = array();
+
+				/* Bilder dieser Variation */
+				$arImagesVariation = explode(',', $vp_data[$var_id]['arVariation'][$var_value]['images_set']);
+				
+				/* Schnittmenge */
+				$arImages = array_intersect($arImages, $arImagesVariation);
+				
+				$r = array(
+					'vari_id' => $var_value,
+					'name' 	=> $vp_data[$var_id]['name'],
+					'value' => $vp_data[$var_id]['arVariation'][$var_value]['name'],
+					'preis'	=> $vp_data[$var_id]['arVariation'][$var_value]['price'],
+					'artnr'	=> @$vp_data[$var_id]['arVariation'][$var_value]['artnr'],
+					'images' => $arImagesVariation
+				);
+
+				if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['weight']))
 				{
 
-					$arPicsVariante = array();
-
-					if (isset($vp_data[$var_id]['pic']))
-					{
-
-						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['pic']));
-
-					}
-
-					if ($var_value == '1')
-					{
-
-						$r = array(
-								'name' => $vp_data[$var_id]['name'],
-								'preis' => $vp_data[$var_id]['price'],
-								'artnr'	=> $vp_data[$var_id]['arVariation'][2]['anr'],
-								'pics' => $arPicsVariante
-						);
-
-						if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['weight']))
-						{
-
-							$r['weight'] = $vp_data[$var_id]['weight'];
-							$arReturn['weight'] += $r['weight'];
-
-						}
-
-						if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['fmenge']))
-						{
-
-							$r['fmenge'] = $vp_data[$var_id]['fmenge'];
-							$arReturn['fmenge'] += $r['fmenge'];
-
-						}
-
-						$arReturn[] = $r;
-
-						$arKey[] = $vp_data[$var_id]['name'];
-
-						$arPics = array_intersect($arPics, $arPicsVariante);
-
-					}
-					else
-					{
-
-						// Checkbox ist nicht markiert
-						//$arPics = array_unique(array_merge($arPics, $arPicsVariante));
-
-					}
-
-				}
-				else
+					$r['weight'] = $vp_data[$var_id]['arVariation'][$var_value]['weight'];
+					$arReturn['weight'] += $r['weight'];
+
+				}
+
+				if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['fmenge']))
 				{
 
-					$arPicsVariante = array();
-
-					if (isset($vp_data[$var_id]['arVariation'][$var_value]['pic']))
-					{
-
-						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['arVariation'][$var_value]['pic']));
-						$arPics = array_unique(array_merge($arPics, $arPicsVariante));
-
-					}
-
-					$r = array(
-							'name' 	=> $vp_data[$var_id]['name'],
-							'value' => $vp_data[$var_id]['arVariation'][$var_value]['name'],
-							'preis'	=> $vp_data[$var_id]['arVariation'][$var_value]['price'],
-							'artnr'	=> @$vp_data[$var_id]['arVariation'][$var_value]['artnr'],
-							'pics' => $arPicsVariante
-					);
-
-					if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['weight']))
-					{
-
-						$r['weight'] = $vp_data[$var_id]['arVariation'][$var_value]['weight'];
-						$arReturn['weight'] += $r['weight'];
-
-					}
-
-					if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['fmenge']))
-					{
-
-						$r['fmenge'] = $vp_data[$var_id]['arVariation'][$var_value]['fmenge'];
-						$arReturn['fmenge'] += $r['fmenge'];
-
-					}
-
-					$arReturn[] = $r;
-
-					$arKey[] = $vp_data[$var_id]['arVariation'][$var_value]['name'];
-					$arAKey[] = @$vp_data[$var_id]['arVariation'][$var_value]['anr'];
-
-				}
-
+					$r['fmenge'] = $vp_data[$var_id]['arVariation'][$var_value]['fmenge'];
+					$arReturn['fmenge'] += $r['fmenge'];
+
+				}
+
+				$arReturn[$var_id] = $r;
+
+				$arKey[] = $vp_data[$var_id]['arVariation'][$var_value]['name'];
+				$arAKey[] = @$vp_data[$var_id]['arVariation'][$var_value]['anr'];
+ 
 			}
 
 			$arReturn['key'] = implode(' / ', $arKey);
 			$arReturn['akey'] = implode(' / ', $arAKey);
-			$arReturn['pics'] = array_unique($arPics);
+			$arReturn['images'] = wpsg_trim(array_unique($arImages));
+			
+			if (!wpsg_isSizedArray($arReturn['images'])) $arReturn['images'] = $arImagesProduct;
 
 			return $arReturn;
Index: ds/wpsg_mod_productvariants.class.ppp
===================================================================
--- /mods/wpsg_mod_productvariants.class.ppp	(revision 6437)
+++ 	(revision )
@@ -1,2379 +1,0 @@
-<?php
-
-	/**
-	 * Modulklasse "Produktvarianten"
-	 * @author Daschmi (27.04.2016)
-	 */
-	class wpsg_mod_productvariants extends wpsg_mod_basic
-	{
-
-		var $lizenz = 1;
-		var $id = 99;
-
-		const TYPE_SELECT = 0;
-		const TYPE_RADIO = 1;
-		const TYPE_IMAGE = 2;
-
-		static $arTypeLabel;
-
-		/**
-		 * Constructor
-		 */
-		public function __construct()
-		{
-
-			parent::__construct();
-
-			self::$arTypeLabel = array(
-				self::TYPE_SELECT => __('Select Box', 'wpsg'),
-				self::TYPE_RADIO => __('Radio Boxen', 'wpsg'),
-				self::TYPE_IMAGE => __('Bilderauswahl', 'wpsg')
-			);
-
-			$this->name = __('Produktvarianten', 'wpsg');
-			$this->group = __('Produkte', 'wpsg');
-			$this->desc = __('ErmÃ¶glicht es zentral Varianten anzulegen und diese im Produkt zu aktivieren.', 'wpsg');
-
-			wpsg_define('WPSG_TBL_VARIANTS', $this->shop->prefix.'wpsg_variants');
-			wpsg_define('WPSG_TBL_VARIANTS_VARI', $this->shop->prefix.'wpsg_variants_vari');
-			wpsg_define('WPSG_TBL_PRODUCTS_VARIANT', $this->shop->prefix.'wpsg_products_variant');
-			wpsg_define('WPSG_TBL_PRODUCTS_VARIATION', $this->shop->prefix.'wpsg_products_variation');
-
-		} // public function __construct()
-
-		public function install()
-		{
-
-			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
-
-			$sql = "CREATE TABLE ".WPSG_TBL_VARIANTS." (
-				id int(11) NOT NULL AUTO_INCREMENT,
-				name varchar(255) NOT NULL,
-				product_id int(11) NOT NULL,
-				deleted int(1) NOT NULL,
-				pos int(11) NOT NULL,
-				type int(11) NOT NULL,
-				PRIMARY KEY  (id),
-				KEY product_id (product_id)
-			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
-
-			dbDelta($sql);
-
-			$sql = "CREATE TABLE ".WPSG_TBL_VARIANTS_VARI." (
-				id int(11) NOT NULL AUTO_INCREMENT,
-				variant_id int(11) NOT NULL,
-				name varchar(255) NOT NULL,
-				shortname varchar(255) NOT NULL,
-				anr varchar(255) NOT NULL,
-				price double(10,2) NOT NULL,
-				stock int(11) NOT NULL,
-				images text NOT NULL,
-				deleted int(1) NOT NULL,
-				pos int(11) NOT NULL,
-				PRIMARY KEY  (id)
-			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
-
-			dbDelta($sql);
-
-			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS_VARIANT." (
-				id int(11) NOT NULL AUTO_INCREMENT,
-				variant_id int(11) NOT NULL,
-				product_id int(11) NOT NULL,
-				pos int(11) NOT NULL,
-				PRIMARY KEY  (id),
-				KEY product_id (product_id),
-				KEY variant_id (variant_id)
-			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
-
-			dbDelta($sql);
-
-			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS_VARIATION." (
-				id int(11) NOT NULL AUTO_INCREMENT,
-				variation_id int(11) NOT NULL,
-				product_id int(11) NOT NULL,
-				active int(1) NOT NULL,
-				anr varchar(255) NOT NULL,
-				price double(10,2) NOT NULL,
-				stock int(11) NOT NULL,
-				images text NOT NULL,
-				weight double(10,2) NOT NULL,
-				fmenge double(10,2) NOT NULL,
-				PRIMARY KEY  (id),
-				KEY product_id (product_id),
-				KEY variation_id (variation_id)
-			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
-
-			dbDelta($sql);
-
-		} // public function install()
-
-		public function settings_edit()
-		{
-
-			$this->shop->view['wpsg_mod_productvariants']['html'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_html.phtml', false);
-
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/settings_edit.phtml');
-
-		} // public function settings_edit_afterform()
-
-		public function settings_save()
-		{
-
-			$this->shop->update_option('wpsg_mod_productvariants_price', $_REQUEST['wpsg_mod_productvariants_price']);
-			$this->shop->update_option('wpsg_vp_detailview', $_REQUEST['wpsg_vp_detailview']);
-
-		} // public function settings_save()
-
-		public function be_ajax()
-		{
-
-			$action = $_REQUEST['subaction'].'Action';
-
-			$this->$action();
-
-		} // public function be_ajax()
-
-		public function wpsg_enqueue_scripts()
-		{
-
-			if (!is_admin())
-			{
-
-				wp_enqueue_script('wpsg_mod_productvariants_js', $this->shop->getRessourceURL('mods/mod_productvariants/frontend.js'));
-				wp_localize_script('wpsg_mod_productvariants_js', 'wpsg_vp_showpic', array('wpsg_vp_showpic' => $this->shop->get_option('wpsg_vp_showpic')));
-
-			}
-
-		} // public function wpsg_enqueue_scripts()
-
-		public function product_addedit_content(&$product_content, &$product_data)
-		{
-
-			// Wenn eine Ãbersetzung bearbeitet wird, dann nichts machen
-			if (isset($_REQUEST['wpsg_lang'])) return;
-
-			if (wpsg_isSizedInt($product_data['id']))
-			{
-
-				$this->shop->view['wpsg_mod_productvariants']['html'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_html.phtml', false);
-
-			}
-
-			$product_content['wpsg_mod_productvariants'] = array(
-				'title' => __('Produktvarianten', 'wpsg'),
-				'content' => $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt_addedit_content.phtml', false)
-			);
-
-		} // public function product_addedit_content(&$product_content, &$produkt_data)
-
-		public function template_redirect()
-		{
-
-			if (wpsg_isSizedString($_REQUEST['action'], 'wpsg_productvariants_switch'))
-			{
-
-				if (wpsg_isSizedInt($_REQUEST['wpsg_post_id']))
-				{
-
-					global $post;
-					$post = get_post($_REQUEST['wpsg_post_id']);
-
-				}
-
-				// Produkt Key nach der Auswahl bilden
-				parse_str($_REQUEST['form_data'], $form_data);
-
-				$product_id = $this->shop->getProduktId($form_data['wpsg']['produkt_id']);
-                $product_key = '';
-
-                $this->getProductKeyFromRequest($product_key, $product_id, $form_data);
-                //$product_key = $_REQUEST['product_key'];
-
-				$product_data = $this->shop->loadProduktArray($product_id, array(
-					'id' => $product_key,
-					'product_key' => $product_key,
-					'menge' => $form_data['wpsg']['menge'],
-					'referer' => $form_data['myReferer']
-				));
-
-				// Damit das Div die gleiche Index Id bekommt
-				$GLOBALS['wpsg_produkt_index'] = $_REQUEST['product_index'] - 1;
-
-				$this->shop->noReleatedProducts = true;
-
-				if (wpsg_isSizedString($form_data['wpsg']['template'])) $template = $form_data['wpsg']['template'];
-				else $template = false;
-
-				if (wpsg_isSizedInt($form_data['titleDisplayed'])) $this->shop->titleDisplayed = 1;
-
-				die($this->shop->renderProdukt($product_data, $template));
-
-			}
-
-		} // public function template_redirect()
-
-		public function loadProduktArray(&$product_data)
-		{
-
-			//if ($GLOBALS['step'] > 4) return;
-
-			$product_data['arVariant'] = $this->getVariants($product_data['product_id'], true, true, true);
-			$this->unserializeVariant($product_data['arVariant']);
-
-			if (wpsg_isSizedArray($product_data['arVariant']))
-			{
-
-				// Default Kombination setzen
-                if (preg_match('/^pv_/', $product_data['id']))
-                {
-
-                    $product_data['product_key'] = $product_data['id'];
-
-                }
-				else if (!isset($product_data['product_key']) || is_numeric($product_data['product_key']))
-				{
-
-					$arDefaultKey = array();
-
-					foreach ($product_data['arVariant'] as $variant_id => $variant_data)
-					{
-
-						$arDefaultKeyValues = $variant_id.':'.array_keys($variant_data['arVariation'])[0];
-						$arDefaultKey[] = $arDefaultKeyValues;
-
-					}
-
-					$strDefaultKey = 'pv_'.$product_data['id'].'|'.implode('|', $arDefaultKey);
-
-					$product_data['product_key'] = $strDefaultKey;
-					$product_data['id'] = $strDefaultKey;
-
-				}
-
-				$arProductKey = $this->explodeProductKey($product_data['product_key']);
-
-				$arProductImagesPossible = array();
-				$arPostidsImagesPossible = array();
-				
-				// Gesetzte Variante wÃ€hlen und aufwerten
-				foreach ($product_data['arVariant'] as $var_id => $var_data)
-				{
-
-					foreach ($var_data['arVariation'] as $vari_id => $vari_data)
-					{
-
-						if ($arProductKey['arVari'][$var_id] == $vari_id)
-						{
-
-							$pics = unserialize($vari_data['images']);
-							unset($vari_data['pics']);
-							if (wpsg_isSizedArray($pics)) {
-								$pic = explode(',', $pics['pic']);
-								if (strlen($pic[0]) == 0) unset($pic[0]);
-								$postids = explode(',', $pics['postid']);
-								if (strlen($postids[0]) == 0) unset($postids[0]);
-								//$vari_data['images'] = array('pic' => array());
-								//$vari_data['images']['pic'] = $pic;
-								foreach ($pic as $k => &$file) {
-									$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
-								}
-								$vari_data['pics'] = $pic;
-								$vari_data['postids'] = $postids;								
-							}
-
-							if (isset($vari_data['pics'])) {
-								if (wpsg_isSizedArray($arProductImagesPossible)) $arProductImagesPossible = array_intersect($arProductImagesPossible, $vari_data['pics']);
-								else if (wpsg_isSizedArray($vari_data['pics'])) $arProductImagesPossible = $vari_data['pics'];
-
-							}
-							if (isset($vari_data['postids'])) {
-								if (wpsg_isSizedArray($arPostidsImagesPossible)) $arPostidsImagesPossible = array_intersect($arPostidsImagesPossible, $vari_data['postids']);
-								else if (wpsg_isSizedArray($vari_data['postids'])) $arPostidsImagesPossible = $vari_data['postids'];
-								
-							}
-							
-							$product_data['arVariant'][$var_id]['arVariation'][$vari_id]['set'] = true;
-
-						}
-						else $product_data['arVariant'][$var_id]['arVariation'][$vari_id]['set'] = false;
-
-					}
-
-				}
-
-				if (wpsg_isSizedArray($arPostidsImagesPossible)) $product_data['image_postid'] = array_shift($arPostidsImagesPossible);
-				
-				if (wpsg_isSizedArray($arProductImagesPossible)) $product_data['image_show'] = array_shift($arProductImagesPossible);
-				if (wpsg_isSizedString($product_data['image_show']))
-					$product_data['image_show'] = sanitize_file_name($product_data['image_show']);
-					
-				// Preise fÃŒr die Varianten berechnen
-				if (!(isset($product_data['varPriceAdded']) && ($product_data['varPriceAdded'] = 1)))
-				{
-
-					$product_data['preis_netto_preVariants'] = $product_data['preis_netto'];
-					$product_data['preis_brutto_preVariants'] = $product_data['preis_brutto'];
-
-					if ($this->shop->getBackendTaxView() === WPSG_BRUTTO)
-					{
-
-						$product_data['preis_brutto'] = $this->calculateVariantsPrice($product_data['preis_brutto'], $product_data['arVariant'], $product_data['product_key']);
-						$product_data['preis_netto'] = wpsg_calculatePreis($product_data['preis_brutto'], WPSG_NETTO, $product_data['mwst_value']);
-
-					}
-					else
-					{
-
-						$product_data['preis_netto'] = $this->calculateVariantsPrice($product_data['preis_netto'], $product_data['arVariant'], $product_data['product_key']);
-						$product_data['preis_brutto'] = wpsg_calculatePreis($product_data['preis_netto'], WPSG_BRUTTO, $product_data['mwst_value']);
-
-					}
-
-					$product_data['preis_preVariants'] = $product_data['preis'];
-
-				}
-
-				// Preise fÃŒr das Frontend ermitteln
-				if ($this->shop->getFrontendTaxView() === WPSG_BRUTTO)
-				{
-
-					$product_data['preis'] = $product_data['preis_brutto'];
-
-				}
-				else
-				{
-
-					$product_data['preis'] = $product_data['preis_netto'];
-
-				}
-
-			}
-			if ($product_data['preis_brutto'] == 161.00) {
-
-				$product_data['preis'] = $product_data['preis_brutto'];
-			}
-
-		} // public function loadProduktArray(&$produkt_data)
-
-        public function getProductKeyFromRequest(&$product_key, $product_id, $form_data)
-        {
-
-            //if (!wpsg_isSizedArray($form_data['wpsg_mod_productvariants'])) return false;
-
-            //foreach ($form_data['wpsg_mod_productvariants'] as $var_id => $vari_id) $form_data['wpsg_mod_productvariants'][$var_id] = $var_id.':'.$vari_id;
-            //$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_mod_productvariants']);
-
-        	if (!wpsg_isSizedArray($form_data['wpsg_vp'])) return false;
-
-        	foreach ($form_data['wpsg_vp'] as $var_id => $vari_id) $form_data['wpsg_vp'][$var_id] = $var_id.':'.$vari_id;
-        	$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_vp']);
-
-        } // public function getProductKeyFromRequest($product_id, $form_data)
-
-        public function produkt_ajax()
-        {
-
-        	//error_reporting(E_ALL);
-
-        	if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'wpsg_vp_add')
-        	{
-        		die('wpsg_vp_add');
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		$data = array(
-        				"name" => $_REQUEST['name'],
-        				"typ" => $_REQUEST['typ'],
-        				"aktiv" => "1"
-        		);
-
-        		if ($_REQUEST['typ'] == "checkbox")
-        		{
-        			$data['preis'] = "0";
-        		}
-        		else
-        		{
-        			$data['vari'] = array();
-        		}
-
-        		$vp_data[] = $data;
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-
-        		$this->shop->view['message'] = array(0, __("Variante erfolgreich angelegt.", "wpsg"));
-
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == 'wpsg_var_reorder')
-        	{
-        		die('wpsg_var_reorder');
-        		parse_str($_REQUEST['wpsg_reorder'], $wpsg_reorder);
-
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-        		$vp_data_neu = array();
-
-        		foreach ($wpsg_reorder['variante'] as $order)
-        		{
-
-        			if (array_key_exists($order, $vp_data))
-        			{
-
-        				$vp_data_neu[] = $vp_data[$order];
-        				unset($vp_data[$order]);
-
-        			}
-
-        		}
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data_neu);
-
-        		$this->shop->view['message'] = array(0, __('Variantenreihenfolge gespeichert.', 'wpsg'));
-
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == 'wpsg_vari_reorder')
-        	{
-        		die('wpsg_vari_reorder');
-        		parse_str($_REQUEST['wpsg_reorder'], $wpsg_reorder);
-
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		foreach ($wpsg_reorder as $var_key => $order)
-        		{
-
-        			$var_id = preg_replace('/^variorder\_/', '', $var_key);
-
-        			wpsg_array_reorder($vp_data[$var_id]['vari'], $order);
-
-        			if (wpsg_isSizedArray($vp_data[$var_id]['lang']))
-        			{
-
-        				foreach ($vp_data[$var_id]['lang'] as $lang_key => $lang_vari)
-        				{
-
-        					wpsg_array_reorder($vp_data[$var_id]['lang'][$lang_key]['vari'], $order);
-
-        				}
-
-        			}
-
-        		}
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-
-        		$this->shop->view['message'] = array(0, __("Variationenreihenfolge gespeichert.", "wpsg"));
-
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == 'wpsg_vp_refreh')
-        	{
-        		die('wpsg_vp_refreh');
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == "wpsg_vp_del")
-        	{
-        		die('wpsg_vp_del');
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		unset($vp_data[$_REQUEST['var_id']]);
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-
-        		$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich gelÃ¶scht.", "wpsg"));
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == "wpsg_vp_deaktiv")
-        	{
-        		die('wpsg_vp_deaktiv');
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		if ($_REQUEST['status'] == "1")
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['aktiv'] = 1;
-        			$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich aktiviert.", "wpsg"));
-
-        		}
-        		else
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['aktiv'] = 0;
-        			$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich deaktiviert.", "wpsg"));
-
-        		}
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == "wpsg_vp_addVariation")
-        	{
-        		die('wpsg_vp_addVariation');
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		$vp_data[$_REQUEST['var_id']]['vari'][] = array(
-        				"name" => $_REQUEST['vari_name'],
-        				"preis" => wpsg_tf($_REQUEST['vari_preis']),
-        				"aktiv" => "1"
-        		);
-
-        		$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich angelegt.", "wpsg"));
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == "wpsg_vp_vari_del")
-        	{
-        		die('wpsg_vp_vari_del');
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		unset($vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]);
-
-        		if (wpsg_isSizedArray($vp_data[$_REQUEST['var_id']]['lang']))
-        		{
-
-        			foreach ($vp_data[$_REQUEST['var_id']]['lang'] as $lang_key => $lang_vari)
-        			{
-
-        				unset($vp_data[$_REQUEST['var_id']]['lang'][$lang_key]['vari'][$_REQUEST['vari_id']]);
-
-        			}
-
-        		}
-
-        		$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich gelÃ¶scht.", "wpsg"));
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == "wpsg_vp_vari_deaktiv")
-        	{
-        		die('wpsg_vp_vari_deaktiv');
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-
-        		if ($_REQUEST['status'] == "1")
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['aktiv'] = 1;
-        			$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich aktiviert.", "wpsg"));
-
-        		}
-        		else
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['aktiv'] = 0;
-        			$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich deaktiviert.", "wpsg"));
-
-        		}
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-        		die($this->drawVarianten($_REQUEST['edit_id']));
-
-        	}
-        	else if ($_REQUEST['cmd'] == 'wpsg_var_setImageOrder')
-        	{
-
-        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
-        		$this->unserializeVariant($vp_data);
-
-        		if ($_REQUEST['vari_id'] == -1)
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['picOrder'] = $_REQUEST['wpsg_reorder'];
-
-        		}
-        		else
-        		{
-
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['picOrder'] = $_REQUEST['wpsg_reorder'];
-
-        		}
-
-        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
-
-        		die("1");
-
-        	}
-        	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_setPic')
-        	{
-        		//die('wpsg_vp_vari_setPic');
-        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
-        		$this->unserializeVariant($vp_data);
-
-        		if ($_REQUEST['vari_id'] >= 0)
-        		{
-
-        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic']);
-        			$arPostid = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid']);
-
-        			$pic = $_REQUEST['pic'];
-        			$postid = $_REQUEST['post_id'];
-
-        			$pic = preg_replace('/\-(\d+)x(\d+)\./', '.', $pic);
-
-        			if (in_array($pic, $arPic))
-        			{
-        				unset($arPic[array_search($pic, $arPic)]);
-        				unset($arPostid[array_search($postid, $arPostid)]);
-        			}
-        			else
-        			{
-        				$arPic[] = $pic;
-        				$arPostid[] = $postid;
-        			}
-
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic'] = implode(",", $arPic);
-        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid'] = implode(",", $arPostid);
-
-        		}
-        		else
-        		{
-
-        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['pic']);
-
-        			if (in_array($_REQUEST['pic'], $arPic))
-        			{
-        				unset($arPic[array_search($_REQUEST['pic'], $arPic)]);
-        			}
-        			else
-        			{
-        				$arPic[] = $_REQUEST['pic'];
-        			}
-
-        			$vp_data[$_REQUEST['var_id']]['pic'] = implode(",", $arPic);
-
-        		}
-
-        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
-
-        		die("1");
-
-        	}
-        	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_inlineEdit')
-        	{
-        		die('wpsg_vp_vari_inlineEdit');
-
-        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
-        		$product_data = $this->shop->cache->loadProduct($_REQUEST['edit_id']);
-
-        		if ($_REQUEST['typ'] == "vari_name")
-        		{
-
-        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
-        			{
-        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['vari'][$_REQUEST['vari_id']]['name'] = wpsg_q($_REQUEST['value']);
-        			}
-        			else
-        			{
-        				$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['name'] = wpsg_q($_REQUEST['value']);
-        			}
-
-        		}
-        		else if ($_REQUEST['typ'] == "vari_artnr")
-        		{
-
-        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
-        			{
-        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['vari'][$_REQUEST['vari_id']]['artnr'] = wpsg_q($_REQUEST['value']);
-        			}
-        			else
-        			{
-        				$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['artnr'] = wpsg_q($_REQUEST['value']);
-        			}
-
-        		}
-        		else if ($_REQUEST['typ'] == "vari_preis")
-        		{
-
-        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
-        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['preis'] = $_REQUEST['value'];
-        			$_REQUEST['value'] = wpsg_ff($_REQUEST['value'], $this->shop->get_option('wpsg_currency'));
-
-        		}
-        		else if ($_REQUEST['typ'] == "vari_fmenge")
-        		{
-
-        			$arFeinheiten = explode(',', $this->shop->get_option('wpsg_mod_fuellmenge_einheit'));
-
-        			$_REQUEST['value'] = wpsg_ff(wpsg_tf($_REQUEST['value']), $arFeinheiten[$product_data['feinheit']]);
-        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['fmenge'] = wpsg_tf($_REQUEST['value']);
-
-        		}
-        		else if ($_REQUEST['typ'] == "vari_weight")
-        		{
-
-        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
-        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['weight'] = $_REQUEST['value'];
-
-        		}
-        		else if ($_REQUEST['typ'] == "vari_stock")
-        		{
-
-        			$_REQUEST['value'] = intval($_REQUEST['value']);
-        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['stock'] = $_REQUEST['value'];
-
-        		}
-        		else if ($_REQUEST['typ'] == "var_name")
-        		{
-
-        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
-        			{
-        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['name'] = $_REQUEST['value'];
-        			}
-        			else
-        			{
-        				$vp_data[$_REQUEST['var_id']]['name'] = $_REQUEST['value'];
-        			}
-
-        		}
-        		else if ($_REQUEST['typ'] == "var_preis")
-        		{
-
-        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
-        			$vp_data[$_REQUEST['var_id']]['preis'] = $_REQUEST['value'];
-        			$_REQUEST['value'] = wpsg_ff($_REQUEST['value'], $this->shop->get_option('wpsg_currency'));
-
-        		}
-        		else if ($_REQUEST['typ'] == "var_weight")
-        		{
-
-        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
-        			$vp_data[$_REQUEST['var_id']]['weight'] = $_REQUEST['value'];
-
-        		}
-        		else if ($_REQUEST['typ'] == "var_fmenge")
-        		{
-
-        			$arFeinheiten = explode(',', $this->shop->get_option('wpsg_mod_fuellmenge_einheit'));
-
-        			$_REQUEST['value'] = wpsg_ff(wpsg_tf($_REQUEST['value']), $arFeinheiten[$product_data['feinheit']]);
-        			$vp_data[$_REQUEST['var_id']]['fmenge'] = wpsg_tf($_REQUEST['value']);
-
-        		}
-        		else if ($_REQUEST['typ'] == "var_artnr")
-        		{
-
-        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
-        			{
-        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['artnr'] = wpsg_q($_REQUEST['value']);
-        			}
-        			else
-        			{
-        				$vp_data[$_REQUEST['var_id']]['artnr'] = wpsg_q($_REQUEST['value']);
-        			}
-
-        		}
-        		else if ($_REQUEST['typ'] == "var_stock")
-        		{
-
-        			$_REQUEST['value'] = intval($_REQUEST['value']);
-        			$vp_data[$_REQUEST['var_id']]['stock'] = $_REQUEST['value'];
-
-        		}
-
-        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
-
-        		die(strval($_REQUEST['value']));
-
-        	}
-
-        } // public function produkt_ajax()
-
-		/**
-		 * Darf das Produkt gekauft werden?
-		 */
-		public function canOrder($product_key)
-		{
-
-			$product_id = $this->shop->getProduktID($product_key);
-
-			if ($this->isVariantsProduct($product_id))
-			{
-
-				$nActive = 0;
-
-				$variants = $this->getVariants($product_id);
-
-				foreach ($variants as $var_id => $var_info)
-				{
-
-					$nActive += $var_info['count_active'];
-
-				}
-
-				if ($nActive <= 0) return -2;
-
-			}
-
-		}
-
-		/* Modulfunktionen */
-
-		/**
-		 * Gibt den Bestand fÃŒr eine Variation zurÃŒck
-		 * @var $product_key String
-		 * Beispiel: pv_1|1:1
-		 *
-		 * Wird vom Lagerbestandsmodul aufgerufen, sollte NUR mit einem VariantenschlÃŒssel aufgerufen werden
-		 */
-		public function getStockForVariation($product_key)
-		{
-
-			$arVariInfo = $this->explodeProductKey($product_key);
-			$oProduct = wpsg_product::getInstance($arVariInfo['product_id']);
-
-			if (!wpsg_isSizedArray($arVariInfo['arVari'])) return $oProduct->stock;
-			else
-			{
-
-				$nStock = 0;
-				$variConf = $this->getVariants($arVariInfo['product_id'], true, true, true);
-
-				foreach ($arVariInfo['arVari'] as $var_id => $vari_id)
-				{
-
-					$nStock += $variConf[$var_id]['arVariation'][$vari_id]['stock'];
-
-				}
-
-				return $nStock;
-
-			}
-
-		} // public function getStockForVariation($product_key)
-
-        /**
-         * Speichert die Varianten
-         */
-        public function saveVarianten($produkt_id, $vp_data)
-        {
-
-        	$vp_data = $this->clearArrayForSerialization($vp_data);
-
-        	$temp = wpsg_q(serialize($vp_data));
-        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
-        		"images" => wpsg_q(serialize($vp_data))
-        	), "`id` = '".wpsg_q($_REQUEST['vari_id'])."'");
-
-        } // public function saveVarianten($produkt_id, $vp_data)
-
-        /**
-         * Speichert die Variationen
-         */
-        public function saveVariation($produkt_id, $vp_data)
-        {
-
-        	$vp_data = $this->clearArrayForSerialization($vp_data);
-
-        	$temp = wpsg_q(serialize($vp_data));
-        	$vdata['pic'] = '';
-        	if (isset($vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic']))
-        		$vdata['pic'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic'];
-        	$vdata['picOrder'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['picOrder'];
-        	$vdata['postid'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['postid'];
-
-        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
-        			"images" => wpsg_q(serialize($vdata))
-        	), "`variation_id` = '".wpsg_q($_REQUEST['vari_id'])."'");
-
-        } // public function saveVariation($produkt_id, $vp_data)
-
-        /**
-         * LÃ€dt die Varianteninformationen aus dem serialisierten Array
-         * @param $noTrans Wird diese Variable auf true gesetzt, so wird die Ãbersetzung nicht geladen (Wie Backend) Wichtig wenn die Varianten wieder gespeichert werden sollen!
-         */
-        public function loadVarianten($produkt_id, $noTrans = false, $noCache = false)
-        {
-
-        	if (is_admin()) $noCache = true;
-
-        	if (!$noCache && array_key_exists($produkt_id.$noTrans, wpsg_getArray($this->cache_variData))) return $this->cache_variData[$produkt_id.$noTrans];
-
-        	// Ãbersetzung verarbeiten
-        	if (is_admin() || $noTrans === true)
-        	{
-
-        		//$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($produkt_id)."'"));
-        		$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($_REQUEST['vari_id'])."'"));
-        		if (!is_array($vp_data)) $vp_data = array();
-
-        	}
-        	else
-        	{
-
-        		// Im Frontend geht es nach der Sprache auf der der Shop aktuell lÃ€uft
-        		if ($this->shop->isOtherLang())
-        		{
-
-        			$parent_lang_id = $this->db->fetchOne("SELECT `lang_parent` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($produkt_id)."'");
-        			if (!wpsg_isSizedInt($parent_lang_id)) $parent_lang_id = $produkt_id;
-
-        			$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($parent_lang_id)."'"));
-        			if (!is_array($vp_data)) $vp_data = array();
-
-        			foreach ($vp_data as $k => $v)
-        			{
-
-        				// Den Namen der Variante auf die aktuelle Sprache stellen
-        				if (wpsg_isSizedString($vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['name'])) $vp_data[$k]['name'] = $vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['name'];
-
-        				if (wpsg_isSizedArray($vp_data[$k]['vari']))
-        				{
-
-        					foreach ($vp_data[$k]['vari'] as $k2 => $vari)
-        					{
-
-        						// Den Namen der Variation auf die aktuelle Sprache korrigieren
-        						if (wpsg_isSizedString($vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['vari'][$k2]['name'])) $vp_data[$k]['vari'][$k2]['name'] = $vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['vari'][$k2]['name'];
-
-        					}
-
-        				}
-
-        			}
-
-        		}
-        		else
-        		{
-
-        			if (isset($_REQUEST['vari_id']))
-					{
-
-        				$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($_REQUEST['vari_id'])."'"));
-        				if (!is_array($vp_data)) $vp_data = array();
-
-        			}
-        			else
-        			{
-
-        				$strQuery =
-        				"SELECT PVV.`id`, PVV.`variation_id`, PVV.`product_id`, PVV.`anr`, PVV.`price`, PVV.`stock`, PVV.`images`, PVV.`weight`, PVV.`fmenge`, PVV.`active`,
-        				 VV.`variant_id`, VV.`name` AS VVname, VV.`shortname`, PV.`pos` AS PVpos, VV.`pos` AS VVpos,
-        				 V.`name` AS Vname, V.`type`
-        				 FROM ".WPSG_TBL_VARIANTS." AS V, ".WPSG_TBL_VARIANTS_VARI." AS VV,
-        				 ".WPSG_TBL_PRODUCTS_VARIATION." AS PVV, ".WPSG_TBL_PRODUCTS_VARIANT." AS PV
-        				 WHERE V.`id` = VV.`variant_id` AND VV.`id` = PVV.`variation_id` AND PV.`variant_id` = VV.`variant_id` AND
-        				 PVV.`product_id` = '".wpsg_q($produkt_id)."' AND VV.`deleted` != 1 AND V.`deleted` != 1
-        				 ORDER BY PV.`pos`, VV.`pos`";
-
-        				//$vp_data = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id` = '".wpsg_q($produkt_id)."'");
-        				$vp_data = $this->db->fetchAssoc($strQuery);
-        				if (!is_array($vp_data)) $vp_data = array();
-        				$this->unserializeVariation($vp_data);
-
-        			}
-
-        		}
-
-        	}
-
-        	$this->cache_variData[$produkt_id.$noTrans] = $vp_data;
-
-        	return $vp_data;
-
-        } // public function loadVarianten($produkt_id)
-
-        private function clearArrayForSerialization($ar)
-        {
-
-        	foreach ((array)$ar as $k => $v)
-        	{
-
-        		if (wpsg_isSizedArray($v))
-        		{
-
-        			$ar[$k] = $this->clearArrayForSerialization($v);
-
-        		}
-        		else
-        		{
-
-        			$ar[$k] = preg_replace('/\'|\`|\ÂŽ|\"/', '', $v);
-
-        		}
-
-        	}
-
-        	return $ar;
-
-        } // private function clearArrayForSerialization($ar)
-
-        /**
-         * Gibt die Bilder als Array fÃŒr die Variation zurÃŒck
-         * Beachtet die Reihenfolge die im Backend ÃŒber Drag&Drop definiert ist
-         * @param int $var_id Key der Variante
-         * @param int $vari_id Key der Variation
-         */
-        public function getVariImages($product_id, $var_id, $vari_id)
-        {
-
-        	$_REQUEST['var_id'] = $var_id;
-        	$_REQUEST['vari_id'] = $vari_id;
-
-        	//$vp_data = $this->loadVarianten($product_id);
-        	$vp_data = $this->getVariants($product_id, true, true, true);
-        	$this->unserializeVariant($vp_data);
-
-        	$arProductBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
-
-        	$arReturn = array();
-
-        	if (!isset($vp_data[$var_id])) return $arProductBilder;
-        	//if (!wpsg_isSizedArray($vp_data[$var_id]['vari'][$vari_id]['picOrder']) && !wpsg_isSizedArray($vp_data[$var_id]['picOrder'])) return $arProductBilder;
-        	if (!wpsg_isSizedArray($vp_data[$var_id]['arVariation'][$vari_id]['picOrder'])) return $arProductBilder;
-
-        	// Sortierung
-        	// Bilder in Reihenfolge von picOrder
-        	if (isset($vp_data[$var_id]['typ']) && ($vp_data[$var_id]['typ'] == 'checkbox') && wpsg_isSizedArray($vp_data[$var_id]['picOrder'])) $arReturn = $vp_data[$var_id]['picOrder'];
-        	else if (wpsg_isSizedArray($vp_data[$var_id]['arVariation'][$vari_id]['picOrder'])) $arReturn = $vp_data[$var_id]['arVariation'][$vari_id]['picOrder'];
-
-        	/*
-        	// PrÃŒfen ob die Bilder noch in Produktbilder Array drin sind
-        	foreach ($arReturn as $k => $v)
-        	{
-
-        		if (!in_array($v, $arProductBilder)) unset($arReturn[$k]);
-        		else unset($arProductBilder[array_search($v, $arProductBilder)]);
-
-        	}
-        	*/
-
-        	$arProductBilderSort = Array();
-        	foreach ($arProductBilder as $v) {
-        		$k = array_search($v['basenameori'], $arReturn);
-        		if ($k !== false)
-        			$arProductBilderSort[$k] = $v;
-
-        	}
-        	ksort($arProductBilderSort);
-
-        	// Bilder aus dem ProduktArray noch hinzufÃŒgen, die eventuell nicht im sortierten Array enthalten sind
-        	foreach ($arProductBilder as $k => $v)
-        	{
-
-        		//$arReturn[] = $v['basenameori'];
-        		$k = array_search($v['basenameori'], $arReturn);
-        		if ($k === false)
-        			$arProductBilderSort[] = $v;
-
-        	}
-        	//$arReturn = array_unique($arReturn);
-
-        	$arImageSelect = array();
-
-        	// Sind die Bilder in der Variante ausgewÃ€hlt?
-        	if (!is_admin())
-        	{
-
-        		//if ($vp_data[$var_id]['typ'] == 'checkbox' && wpsg_isSizedString($vp_data[$var_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['pic']);
-        		if ($vp_data[$var_id]['type'] == '3' && wpsg_isSizedString($vp_data[$var_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['pic']);
-        		else if (wpsg_isSizedString($vp_data[$var_id]['arVariation'][$vari_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['arVariation'][$vari_id]['pic']);
-
-        		foreach ($arReturn as $k => $v)
-        		{
-
-        			if (!in_array($v, $arImageSelect)) unset($arReturn[$k]);
-
-        		}
-
-        	}
-
-        	//return $arReturn;
-        	return $arProductBilderSort;
-
-        } // public function getVariImages($product_id, $var_id, $vari_id)
-
-        /**
-         * Gibt den Namen der Variante zurÃŒck
-         */
-        public function getVariantenName($vp_data, $var_id)
-        {
-
-        	$name = $vp_data[$var_id]['name'];
-
-        	if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
-        	{
-        		if ($vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['name'] != "")
-        		{
-        			$name = $vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['name'];
-        		}
-        	}
-
-        	return ((trim($name) == "")?"----":$name);
-
-        } // public function getVariantenName($vp_data, $v_id)
-
-        /**
-         * Gibt den Namen der Variation zurÃŒck
-         */
-        public function getVariName($vp_data, $var_id, $vari_id)
-        {
-
-        	$name = $vp_data[$var_id]['arVariation'][$vari_id]['name'];
-
-        	if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
-        	{
-        		if ($vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['arVariation'][$vari_id]['name'] != "")
-        		{
-        			$name = $vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['arVariation'][$vari_id]['name'];
-        		}
-        	}
-
-        	return ((trim($name) == "")?"----":$name);
-
-        } // public function getVariName($vp_data, $var_id, $vari_id)
-
-		/**
-		 * PrÃŒft ob das Produkt ein Variantenprodukt ist oder nicht
-		 */
-		public function isVariantsProduct($product_id)
-		{
-
-			$strQuery = "
-					SELECT
-						COUNT(*)
-					FROM
-						`".WPSG_TBL_VARIANTS_VARI."` AS VI
-							LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
-					WHERE
-						PVI.`product_id` = '".wpsg_q($product_id)."' AND
-						PVI.`active` = '1' AND
-						VI.`deleted` != '1'
-			";
-
-			$nActiveVariants = $this->db->fetchOne($strQuery);
-
-			if ($nActiveVariants > 0) return true; else return false;
-
-		} // public function isVariantsProduct($product_id)
-
-		/**
-		 * Integration in das Produkttemplate
-		 */
-		public function productTemplate($product_data)
-		{
-
-			die("Veraltet");
-
-			if (!wpsg_isSizedArray($product_data['arVariant'])) return;
-
-			$this->shop->view['wpsg_mod_productvariants']['product_id'] = $product_data['product_id'];
-			$this->shop->view['wpsg_mod_productvariants']['arVariants'] = $product_data['arVariant'];
-			$this->shop->view['wpsg_mod_productvariants']['product_variants'] = $this->explodeProductKey($product_data['product_key'])['arVari'];
-
-			$this->shop->render(WPSG_PATH_VIEW.'mods/mod_productvariants/productTemplate.phtml');
-
-		} // public function productTemplate($product_key)
-
-		/**
-		 * Ãbernimmt die Auswahl der Variante im Produkttemplate
-		 */
-		public function renderTemplate($product_key)
-		{
-
-			$produkt_id = $this->shop->getProduktId($product_key);
-			$produkt_data = $this->shop->cache->loadProduct($produkt_id);
-			$tax_value = $this->shop->getCalcTaxValue($produkt_data['mwst_key']);
-
-			if ($this->shop->isOtherLang())
-			{
-
-				$produkt_trans_id = $this->db->fetchOne("SELECT `id` FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($produkt_id)."' AND `lang_locale` = '".wpsg_q($this->shop->getCurrentLanguageCode())."'");
-
-				if (wpsg_isSizedInt($produkt_trans_id)) $produkt_id = $produkt_trans_id;
-
-			}
-
-			//public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false)
-			$vp_data = $this->getVariants($produkt_id, true, true, true);
-			$this->unserializeVariant($vp_data);
-
-			if ($this->isVariantsProductKey($product_key)) {
-				$arVar = $this->explodeProductKey($product_key);
-				foreach ($arVar['arVari'] as $v => $vv) {
-					$vp_data[$v]['arVariation'][$vv]['sel'] = 1;
-
-				}
-
-			}
-
-			if (is_array($vp_data) && sizeof($vp_data) > 0)
-			{
-
-				$arpb = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array(&$produkt_id));
-
-				//$this->shop->view['data']['vp_data'] = $vp_data;
-				$this->shop->view['wpsg_mod_productvariants']['set'] = $this->getSetVariArray($product_key);
-
-				// Rabattpreise vorkalkulieren
-				//$this->shop->callMod('wpsg_mod_discount', 'addDiscountToVari', array(&$produkt_id, &$this->shop->view['data']['vp_data']));
-
-				$arPossibleImages = array();
-
-				// Bilddaten ergÃ€nzen
-				foreach ($vp_data as $k1 => &$v1) {
-					foreach ($v1['arVariation'] as $k2 => &$v2) {
-						$arpic = explode(',', $v2['pic']);
-						$v2['showpic'] = '';
-						if (wpsg_isSizedArray($v2['picOrder'])) {
-							// Bilder umsortiert, Reihenfolge checken
-							$k = 5000;
-							foreach ($arpic as $ap)
-								foreach ($v2['picOrder'] as $kp => $vp) {
-									if ($ap == $vp)
-										if ($kp < $k) $k = $kp;
-
-								}
-							$v2['showpic'] = $v2['picOrder'][$k];
-						}
-						else
-						{
-							$max = sizeof($arpic);
-							if (isset($arpic[$max - 1]))
-								$v2['showpic'] = $arpic[$max - 1];		// 1 wegen Komma am Anfang
-						}
-						$found = -1;
-						$v2['guid'] = '';
-						$v2['post_id'] = 0;
-						foreach ($arpb as $k3 => $v3) {
-							if ($v2['showpic'] === $v3['basenameori']) $found = $k3;
-						}
-						if ($found != -1) {
-							$v2['guid'] = $arpb[$found]['guid'];
-							$v2['post_id'] = $arpb[$found]['post_id'];
-						}
-
-					}
-				}
-
-				unset($v1);
-				unset($v2);
-
-				$this->shop->view['data']['vp_data'] = $vp_data;
-
-				foreach ($this->shop->view['data']['vp_data'] as $k => $v)
-				{
-
-					if ($v['typ'] == "checkbox")	// 0 = checkbox
-					{
-
-						if (get_option("wpsg_vp_showpic") == "1" && wpsg_isSizedString($v['pic']))
-						{
-
-							//$this->shop->view['data']['vp_data'][$k]['showpic'] = $this->getImageSelectImage($produkt_id, $k, $k2, $product_key);
-
-						}
-
-						// Preis an Ausgabe im Frontend anpassen
-						//if ($this->shop->getFrontendTaxview() == WPSG_NETTO && $this->shop->getBackendTaxview() == WPSG_BRUTTO) $this->shop->view['data']['vp_data'][$k]['preis'] = wpsg_calculatePreis($v['preis'], WPSG_NETTO, $tax_value);
-						//else if ($this->shop->getFrontendTaxview() == WPSG_BRUTTO && $this->shop->getBackendTaxview() == WPSG_NETTO) $this->shop->view['data']['vp_data'][$k]['preis'] = wpsg_calculatePreis($v['preis'], WPSG_BRUTTO, $tax_value);
-
-					}
-					else
-					{
-
-						foreach ($v['arVariation'] as $k2 => $v2)
-						{
-
-							if (get_option("wpsg_vp_showpic") == "1" && wpsg_isSizedString($v2['pic']))
-							{
-
-								//$this->shop->view['data']['vp_data'][$k]['vari'][$k2]['showpic'] = $this->getImageSelectImage($produkt_id, $k, $k2, $product_key);
-
-							}
-
-							// Preis an Ausgabe im Frontend anpassen
-							if ($this->shop->getFrontendTaxview() == WPSG_NETTO && $this->shop->getBackendTaxview() == WPSG_BRUTTO) $this->shop->view['data']['vp_data'][$k]['arVariation'][$k2]['price'] = wpsg_calculatePreis($v2['price'], WPSG_NETTO, $tax_value);
-							else if ($this->shop->getFrontendTaxview() == WPSG_BRUTTO && $this->shop->getBackendTaxview() == WPSG_NETTO) $this->shop->view['data']['vp_data'][$k]['arVariation'][$k2]['price'] = wpsg_calculatePreis($v2['price'], WPSG_BRUTTO, $tax_value);
-
-						}
-
-					}
-
-				}
-
-				return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt.phtml', false);
-
-			}
-
-		} // public function renderTemplate($produkt_id)
-
-		/**
-		 * Gibt ein Array mit Informationen aus dem VariantenschlÃŒssel zurÃŒck
-		 * Besp: pv_1|1:1
-		 * Array
-			(
-    			[product_id] => 1
-    			[arVari] => Array
-		 		(
-            		[1] => 1
-        		)
-
-			)
-		 * Anhand des ProduktschlÃŒssels z.B. pv|4:6|1:8|6:11|5:10
-		 */
-		public function explodeProductKey($product_key)
-		{
-
-			if (is_numeric($product_key)) return array(
-				'product_id' => $product_key,
-				'arVari' => array()
-			);
-
-			$arKey = explode('|', $product_key);
-			$arReturn = array();
-
-			for ($i = 1; $i < sizeof($arKey); $i ++)
-			{
-
-				$arKeyValue = explode(':', $arKey[$i]);
-				$arReturn[$arKeyValue[0]] = $arKeyValue[1];
-
-			}
-
-			return array(
-				'product_id' => substr($arKey[0], 3),
-				'arVari' => $arReturn
-			);
-
-		} // public function explodeProductKey($product_key)
-
-		/**
-		 * Gibt true zurÃŒck, wenn der Preis im Produkttemplate angezeigt werden soll
-		 * Andersrum programmiert, da die Default Einstellung anzeigen ist????
-		 */
-		public function showVariPrice($vari_price)
-		{
-
-			switch ($this->shop->get_option('wpsg_mod_productvariants_price'))
-			{
-
-				case '1': // nur wenn grÃ¶Ãer 0
-
-					if ($vari_price <= 0) return false;
-
-					break;
-
-				case '0': // nie anzeigen
-
-					return false;
-
-					break;
-
-			}
-
-			return true;
-
-		} // public function showVariPrice($vari_price)
-
-		private function calculateVariantsPrice($price, $arVariant, $product_key)
-		{
-
-			$arProductVariant = $this->explodeProductKey($product_key)['arVari'];
-
-			foreach ($arProductVariant as $variant_id => $variation_id)
-			{
-
-				$price += $arVariant[$variant_id]['arVariation'][$variation_id]['price'];
-
-			}
-
-			return $price;
-		}
-
-		private function admin_showAction()
-		{
-
-			$this->shop->view['product_id'] = $_REQUEST['product_id'];
-			$this->shop->view['arVariants'] = $this->getVariants($_REQUEST['product_id'], true);
-
-			die($this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_show.phtml'));
-
-		} // private function showAction()
-
-		private function admin_addAction()
-		{
-
-			$this->db->ImportQuery(WPSG_TBL_VARIANTS, array(
-				'name' => wpsg_q(__('', 'wpsg')),
-				'product_id' => wpsg_q($_REQUEST['product_id']),
-				'deleted' => '0',
-				'pos' => '5000'
-			));
-
-			$this->admin_showAction();
-
-		} // private function admin_addAction()
-
-		private function admin_editAction()
-		{
-
-			$this->shop->view['product_id'] = wpsg_getStr($_REQUEST['product_id'], '0');
-			$this->shop->view['variant'] = $this->getVariant($_REQUEST['variant_id']);
-			$this->shop->view['arVariation'] = $this->getVariationOfVariant($_REQUEST['variant_id'], $_REQUEST['product_id']);
-
-			die($this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_edit.phtml'));
-
-		} // private function admin_editAction()
-
-		private function admin_variation_addAction()
-		{
-
-			$variation_id = $this->db->ImportQuery(WPSG_TBL_VARIANTS_VARI, array(
-				'variant_id' => wpsg_q($_REQUEST['variant_id']),
-				'name' => __('', 'wpsg'),
-				'deleted' => '0'
-			));
-
-			if (wpsg_isSizedInt($_REQUEST['product_id']))
-			{
-
-				$this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
-					'variation_id' => wpsg_q($variation_id),
-					'product_id' => wpsg_q($_REQUEST['product_id'])
-				));
-
-			}
-
-			$this->admin_editAction();
-
-		} // private function admin_variation_addAction()
-
-		private function admin_delAction()
-		{
-
-			$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array(
-				'deleted' => '1'
-			), " `id` = '".wpsg_q($_REQUEST['variant_id'])."' ");
-
-			$this->admin_showAction();
-
-		} // private function admin_delAction()
-
-		private function admin_variation_delAction()
-		{
-
-			$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array(
-				'deleted' => '1'
-			), " `id` = '".wpsg_q($_REQUEST['variation_id'])."' ");
-
-			$this->admin_editAction();
-
-		} // private function admin_variation_delAction()
-
-		private function setProductVariant($product_id, $variant_id, $field, $value)
-		{
-
-			if (!wpsg_isSizedInt($product_id) || !wpsg_isSizedInt($variant_id)) die("Systemfehler");
-
-			$id_exist = $this->db->fetchOne("
-				SELECT
-					`id`
-				FROM
-					`".WPSG_TBL_PRODUCTS_VARIANT."`
-				WHERE
-					`variant_id` = '".wpsg_q($variant_id)."' AND
-					`product_id` = '".wpsg_q($product_id)."'
-			");
-
-			$data = array(
-				$field => wpsg_q($value),
-				'product_id' => wpsg_q($product_id),
-				'variant_id' => wpsg_q($variant_id)
-			);
-
-			if (wpsg_isSizedInt($id_exist)) $this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIANT, $data, " `id` = '".wpsg_q($id_exist)."' ");
-			else $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIANT, $data);
-
-		} // private function setProductVariant($product_id, $variant_id, $field, $value)
-
-		private function setProductVariation($product_id, $variation_id, $field, $value)
-		{
-
-			if (!wpsg_isSizedInt($product_id) || !wpsg_isSizedInt($variation_id)) die("Systemfehler");
-
-			$id_exist = $this->db->fetchOne("
-				SELECT
-					`id`
-				FROM
-					`".WPSG_TBL_PRODUCTS_VARIATION."`
-				WHERE
-					`variation_id` = '".wpsg_q($variation_id)."' AND
-					`product_id` = '".wpsg_q($product_id)."'
-			");
-
-			$data = array(
-				$field => wpsg_q($value),
-				'product_id' => wpsg_q($product_id),
-				'variation_id' => wpsg_q($variation_id)
-			);
-
-			if (wpsg_isSizedInt($id_exist)) $this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, $data, " `id` = '".wpsg_q($id_exist)."' ");
-			else $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $data);
-
-			if (($field == 'stock') || ($field == 'active'))
-			{
-				$this->setStockFromVariation($product_id);
-			}
-
-		} // private function setProductVariation($product_id, $field, $value)
-
-		private function setStockFromVariation($product_id)
-		{
-
-			if ($this->isVariantsProductKey($product_id)) {
-				$arr = $this->explodeProductKey($product_id);
-				$product_id = $arr['product_id'];
-			}
-
-			$sql = "SELECT SUM(PVI.`stock`) AS SU FROM `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI
-						LEFT JOIN `".WPSG_TBL_VARIANTS_VARI."` AS VVI ON PVI.`variation_id`= VVI.`id`
-						WHERE PVI.`product_id`='".wpsg_q($product_id)."' AND VVI.`deleted`!='1' AND PVI.`active`='1'
-				";
-			$stock = $this->db->fetchOne($sql);
-
-			$data = array('stock' => wpsg_q($stock));
-
-			$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, $data, " `id` = '".wpsg_q($product_id)."' ");
-
-			//getProductKeyFromRequest(&$product_key, $product_id, $form_data)
-			//$stock = $this->shop->callMod('wpsg_mod_productvariants', 'getStockForVariation', array());
-
-		}	// private function setStockFromVariation($product_id)
-
-		private function admin_inlineEditAction()
-		{
-
-			if (wpsg_isSizedString($_REQUEST['field'], 'name'))
-			{
-
-				$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('name' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
-
-			}
-			else if (wpsg_isSizedString($_REQUEST['field'], 'type'))
-			{
-
-				$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('type' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
-				die(self::$arTypeLabel[$_REQUEST['value']]);
-
-			}
-			else if (wpsg_isSizedString($_REQUEST['field'], 'pos'))
-			{
-
-				$i = 0; foreach ($_REQUEST['value'] as $var)
-				{
-
-					$var_id = substr($var, 4);
-
-					if (wpsg_isSizedInt($_REQUEST['product_id'])) $this->setProductVariant($_REQUEST['product_id'], $var_id, 'pos', $i);
-					else $this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('pos' => wpsg_q($i)), " `id` = '".wpsg_q($var_id)."' ");
-
-					$i ++;
-
-				}
-
-				die('1');
-
-			}
-			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_name'))
-			{
-
-				$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('name' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
-
-			}
-			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_shortname'))
-			{
-
-				$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('shortname' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
-
-			}
-			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_pos'))
-			{
-
-				$i = 0; foreach ($_REQUEST['value'] as $vari)
-				{
-
-					$vari_id = substr($vari, 5);
-
-					$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('pos' => wpsg_q($i)), " `id` = '".wpsg_q($vari_id)."' ");
-
-					$i ++;
-
-				}
-
-				die('1');
-
-			}
-			else if (preg_match('/vari_(.*)/', $_REQUEST['field']))
-			{
-				$value = $_REQUEST['value'];
-				$f = $_REQUEST['field'];
-				if (($f == 'vari_price') || ($f == 'vari_stock') || ($f == 'vari_weight')) {
-					$value =  wpsg_tf($value);
-				}
-				$this->setProductVariation($_REQUEST['product_id'], $_REQUEST['field_id'], substr($_REQUEST['field'], 5), $value);
-
-			}
-
-			// TODO: Ãbersetzung
-
-			die($_REQUEST['value']);
-
-		} // private function admin_inlineEditAction()
-
-		/**
-		 * Gibt die MÃ¶glichken Bilder einer Variantenkombination zurÃŒck
-		 */
-		public function getKombiVariImages($var_key, $var_id = false)
-		{
-
-			if (!$this->shop->hasMod('wpsg_mod_produktbilder')) return false;
-
-			$arVarSelected = $this->getSetVariArray($var_key);
-			$product_id = $this->shop->getProduktID($var_key);
-			//$arVari = $this->loadVarianten($product_id);
-			$arVari = $this->getVariants($product_id, true, true, true);
-			$this->unserializeVariant($arVari);
-
-			$arTemp = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
-
-			if (!$this->isVariantsProductKey($var_key)) return $arTemp;
-
-			$arBilder = array();
-			foreach ($arTemp as $bild) {
-				$arBilder[] = $bild['basenameori'];
-			}
-
-			/*
-			// Schauen ob ein Bild nach dem Dateinamen dabei ist
-			foreach ($arBilder as $bild)
-			{
-				$image = false;
-				$filename = preg_replace("/\.([^\.]*)/", "", $bild);
-				if ($filename == "vp_".str_replace(":", "-", $var_key)) $image = $bild;
-
-				if ($image !== false) return array($image);
-			}
-			*/
-			foreach ($arVari as $var_key => $var)
-			{
-				if (array_key_exists($var_key, $arVarSelected))
-				{
-					if ($var_id === $var_key) continue;
-					if ($var['typ'] == "checkbox")
-					{
-						if ($arVarSelected[$var_key] == "1")
-						{
-							$arBilder = array_intersect($arBilder, explode(",", $var['pic']));
-						}
-						else
-						{
-							$arBilder = array_diff($arBilder, explode(",", $var['pic']));
-						}
-					}
-					else
-					{
-						$pics = wpsg_getStr($var['arVariation'][$arVarSelected[$var_key]]['pic']);
-						$arBilder = array_intersect($arBilder, explode(",", wpsg_getStr($var['arVariation'][$arVarSelected[$var_key]]['pic'])));
-					}
-				}
-			}
-			//$arBilder = $this->checkPics($arBilder, $product_id);
-
-			if (wpsg_isSizedArray($arBilder))
-			{
-				$arBilder = array_values($arBilder);
-				foreach ($arTemp as $k => $bild) {
-					if ($arBilder[0] != $bild['basenameori']) unset($arTemp[$k]);
-				}
-				//return $arBilder;
-				$arTemp = array_values($arTemp);
-				return $arTemp;
-			}
-			else
-			{
-				return array();
-			}
-		}
-
-		/**
-		 * Gibt einen Array zurÃŒck, bei denen die SchlÃŒssel die Varianten sind und die Werte die gewÃ€hlten Variationen
-		 */
-		private function getSetVariArray($product_key)
-		{
-
-			if (!$this->isVariantsProductKey($product_key)) return array();
-
-			$arVariSet = explode('|', preg_replace('/^pv_\d*\//', '', $product_key));
-			$arReturn = array();
-			unset($arVariSet[0]);
-
-			foreach ($arVariSet as $var_combi)
-			{
-
-				$var_combi = explode(':', $var_combi);
-				$var = $var_combi[0];
-				$vari = $var_combi[1];
-
-				$arReturn[$var] = $vari;
-
-			}
-
-			return $arReturn;
-
-		}	// private function getSetVariArray($product_key)
-
-		/**
-		 * Gibt die Variationen einer Variante zurÃŒck
-		 * @param Integer $variant_id ID der Variante
-		 */
-		public function getVariationOfVariant($variant_id, $product_id = false, $arProductFilter = array())
-		{
-
-			$strQuerySELECT = "";
-			$strQueryJOIN = "";
-			$strQueryWHERE = "";
-			$strQueryHAVING = "";
-
-			if (wpsg_isSizedArray($arProductFilter))
-			{
-
-				//return array($strQuerySELECT, $strQueryWHERE, $strQueryJOIN, $strQueryHAVING, $strQueryORDER);
-				//list($strQueryP_WHERE, $strQueryP_JOIN, $strQueryP_HAVING, $strQueryP_ORDER) = wpsg_product::getQueryParts($arProductFilter);
-
-				list($strQueryP_SELECT, $strQueryP_WHERE, $strQueryP_JOIN, $strQueryP_HAVING, $strQueryP_ORDER) = wpsg_product::getQueryParts($arProductFilter);
-
-				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id`) ";
-				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (P.`id` = PV.`product_id`) ";
-
-				$strQuerySELECT .= $strQueryP_SELECT;
-				$strQueryJOIN .= $strQueryP_JOIN;
-				$strQueryWHERE .= $strQueryP_WHERE;
-				$strQueryHAVING .= $strQueryP_HAVING;
-
-			}
-			else if (wpsg_isSizedInt($product_id))
-			{
-
-				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
-				$strQuerySELECT .= " , PV.`id` AS iid, PV.`variation_id`, PV.`active`, PV.`anr`, PV.`price`, PV.`stock`, PV.`images`, PV.`weight`, PV.`fmenge` ";
-
-			}
-
-			$strQuery = "
-				SELECT
-					VI.`id`, VI.`name`, VI.`shortname`, VI.`deleted`, VI.`pos`
-					".$strQuerySELECT."
-				FROM
-					`".WPSG_TBL_VARIANTS_VARI."` AS VI
-						".$strQueryJOIN."
-				WHERE
-					VI.`variant_id` = '".wpsg_q($variant_id)."' AND
-					VI.`deleted` != '1'
-					".$strQueryWHERE."
-				GROUP BY
-					VI.`id`
-				HAVING
-					1
-					".$strQueryHAVING."
-				ORDER BY
-					VI.`pos`
-			";
-
-			$arVari = $this->db->fetchAssoc($strQuery);
-			$this->unserializeVariation($arVari);
-
-			// TODO: Ãbersetzung
-
-			return $arVari;
-
-		} // public function getVariationOfVariant($variant_id)
-
-		private function unserializeVariation(&$arVari) {
-			foreach ($arVari as &$vi) {
-				$ar = @unserialize($vi['images']);
-				$vi['pic'] = '';
-				$vi['sel'] = 0;
-				$vi['picOrder'] = Array();
-				if (wpsg_isSizedArray($ar)) {
-					foreach($ar as $k => $v) {
-						$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
-						$vi[$k] = $v;
-					}
-				}
-			}
-		}	// private function unserializeVariation(&$arVari)
-
-		private function unserializeVariant(&$arVar) {
-			foreach ($arVar as &$va) {
-				if ($va['type'] == 0) $va['typ'] = 'select';
-				if ($va['type'] == 1) $va['typ'] = 'radio';
-				if ($va['type'] == 2) $va['typ'] = 'image';
-
-				foreach ($va['arVariation'] as &$vi) {
-					$ar = @unserialize($vi['images']);
-					$vi['pic'] = '';
-					$vi['sel'] = 0;
-					$vi['picOrder'] = Array();
-					if (wpsg_isSizedArray($ar)) {
-						foreach($ar as $k => $v) {
-							$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
-							$vi[$k] = $v;
-						}
-					}
-				}
-			}
-		}	// private function unserializeVariant(&$arVar)
-
-		public function stockVarianten($product_id)
-		{
-
-			$this->shop->view['product_id'] = wpsg_getStr($product_id, '0');
-			//$this->shop->view['variant'] = $this->getVariant($_REQUEST['variant_id']);
-			//$this->shop->view['arVariation'] = $this->getVariationOfVariant($_REQUEST['variant_id'], $_REQUEST['product_id']);
-			//$this->shop->view['arVariant']
-			$vp_data = $this->getVariants($product_id, true, true, true);
-			$this->unserializeVariant($vp_data);
-
-			$html = '<table>';
-			foreach ($vp_data as $var) {
-				$html .= '<tr>';
-				$html .= '<td class="col_shortname" colspan="3">'.wpsg_hspc($var['name']).'</td>';
-				$html .= '</tr>';
-			    foreach ($var['arVariation'] as $vari) {
-			    	$html .= '<tr>';
-			    	$html .= '<td class="col_active">&nbsp;';
-			    	$html .= '</td>';
-			    	$txt = wpsg_hspc($vari['name']).' : '.wpsg_hspc($vari['stock']);
-			    	$html .= '<td class="col_shortname">'.$txt.'</td>';
-			    	$html .= '<td class="col_1">';
-			    	$html .= '</td>';
-			    	$html .= '</tr>';
-				}
-			}
-			$html .= '</table>';
-			die($html);
-
-		} // private function stockVarianten($product_id)
-
-		/**
-		 * Reduziert den Bestand der Variationen in dem Array
-		 */
-		public function reduceStock($produkt_key, $menge, $reduce = true)
-		{
-
-			//$produkt_id = preg_replace('/(^pv_)|(\|(.*)$)/', '', $produkt_key);
-			//$vari_teil = preg_replace('/(.*)\//', '', $produkt_key);
-			//$arVarianten = explode('|', $vari_teil);
-			$arVar = $this->explodeProductKey($produkt_key);
-
-			//$vari_data = $this->loadVarianten($produkt_id, true, true);
-
-			// Tabellen sperren
-			if ($this->shop->get_option('wpsg_lockOrderTables') != '1')
-			{
-
-				$arLockTables[WPSG_TBL_PRODUCTS_VARIATION] = "WRITE";
-				$strQuery = "LOCK TABLES ";
-				foreach ($arLockTables as $table_name => $locktype) $strQuery .= " `".$table_name."` ".$locktype.",";
-				$this->db->Query(substr($strQuery, 0, -1));
-			}
-
-			foreach ($arVar['arVari'] as $v => $vv)
-			{
-
-				if ($reduce === true)
-				{
-
-					//$vari_data[$variante_id]['vari'][$vari_id]['stock'] -= $menge;
-					$this->db->Query("
-							UPDATE ".WPSG_TBL_PRODUCTS_VARIATION." SET `stock` = `stock` - ".wpsg_q($menge)." WHERE `id` = '".wpsg_q($vv)."'
-						");
-
-				}
-				else
-				{
-
-					//$vari_data[$variante_id]['vari'][$vari_id]['stock'] += $menge;
-					$this->db->Query("
-							UPDATE ".WPSG_TBL_PRODUCTS_VARIATION." SET `stock` = `stock` + ".wpsg_q($menge)." WHERE `id` = '".wpsg_q($vv)."'
-						");
-
-				}
-
-			}
-
-			$this->db->unlockTables();
-
-			$this->setStockFromVariation($produkt_key);
-
-			// Array zurÃŒckspeichern
-			//$this->saveVarianten($produkt_id, $vari_data);
-
-		} // public function reduceStock($produkt_id, $menge)
-
-		/**
-		 * Gibt true zurÃŒck, wenn der ÃŒbergebene Produktkey ein Varianten Produktkey ist. Sonst false.
-		 * @param \String $productkey
-		 */
-		public function isVariantsProductKey($productkey)
-		{
-
-			if (preg_match('/^pv_\d+/', $productkey))
-			{
-
-				return true;
-
-			}
-			else
-			{
-
-				return false;
-
-			}
-
-		} // public function isVariantsProductKey($productkey)
-
-		/**
-		 * Gibt eine einzelne Variante zurÃŒck
-		 * @param unknown $variant_id
-		 */
-		public function getVariant($variant_id, $bHideDeleted = true)
-		{
-
-			$strQueryWHERE = "";
-
-			if ($bHideDeleted === true) $strQueryWHERE .= " AND V.`deleted` != '1' ";
-
-			$strQuery = "
-				SELECT
-					V.*
-				FROM
-					`".WPSG_TBL_VARIANTS."` AS V
-				WHERE
-					V.`id` = '".wpsg_q($variant_id)."'
-					".$strQueryWHERE."
-			";
-
-			$arVariant = $this->db->fetchRow($strQuery);
-
-			if (!wpsg_isSizedInt($arVariant['id'])) return false;
-
-			// TODO: Ãbersetzung
-
-			return $arVariant;
-
-		} // public function getVariant($variant_id)
-
-		public function getVariation($variation_id)
-		{
-
-			$arVariation = $this->db->fetchRow("
-				SELECT
-					VI.*
-				FROM
-					`".WPSG_TBL_VARIANTS_VARI."` AS VI
-				WHERE
-					VI.`id` = '".wpsg_q($variant_id)."'
-			");
-
-			$arVariation['images'] = wpsg_trim(explode(',', $arVariation['images']));
-
-			// TODO: Ãbersetzung
-
-			return $arVariation;
-
-		} // public function getVariation($variation_id)
-
-		/**
-		 * Gibt einen Array der Produktvarianten zurÃŒck
-		 * @param Integer|Boolean $product_id Produkt ID
-		 * @param Boolean $global Globale Varianten?
-		 */
-		public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false, $serVariationen = false)
-		{
-
-			$strQuerySELECT = "";
-			$strQueryORDER = "";
-			$strQueryJOIN = "";
-			$strProductQuery = " AND ( 0 ";
-
-			if (wpsg_isSizedInt($product_id))
-			{
-
-				$strProductQuery .= " OR V.`product_id` = '".wpsg_q($product_id)."' ";
-
-				$strQueryWHERE = "";
-
-				// Wenn Lagerbestand aktiv, dann nur Veriationen mit Lagerbestand zÃ€hlen
-				// Im Backend zÃ€hle ich auch ausverkaufte Variationen mit, sonst steht in der Ãbersicht 0/2 auch wenn bei einem der Haken gesetzt ist
-				if ($this->shop->hasMod('wpsg_mod_stock') && !is_admin()) $strQueryWHERE .= " AND PVI.`stock` > 0 ";
-
-				$strQuerySELECT .= ", (
-					SELECT
-						COUNT(*)
-					FROM
-						`".WPSG_TBL_VARIANTS_VARI."` AS VI
-							LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
-					WHERE
-						PVI.`product_id` = '".wpsg_q($product_id)."' AND
-						PVI.`active` = '1' AND
-						VI.`variant_id` = V.`id` AND
-						VI.`deleted` != '1'
-						".$strQueryWHERE."
-				) AS `count_active` ";
-
-				$strQueryJOIN = " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIANT."` AS PV ON (PV.`variant_id` = V.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
-
-				$strQueryORDER .= " PV.`pos` ASC, ";
-
-			}
-			else
-			{
-
-				$strQuerySELECT .= ", '0' AS `count_active` ";
-
-			}
-
-			if ($global === true)
-			{
-
-				$strProductQuery .= " OR V.`product_id` = '0' ";
-
-			}
-
-			$strProductQuery .= " ) ";
-
-			$arData = $this->db->fetchAssoc("
-				SELECT
-					V.*,
-					(SELECT COUNT(*) FROM `".WPSG_TBL_VARIANTS_VARI."` AS VI WHERE VI.`variant_id` = V.`id` AND VI.`deleted` != '1') AS `count_variation`,
-					(
-						SELECT
-							COUNT(DISTINCT `product_id`)
-						FROM
-							`".WPSG_TBL_VARIANTS_VARI."` AS VI
-								LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
-								LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (PVI.`product_id` = P.`id`)
-						WHERE
-							VI.`variant_id` = V.`id` AND
-							PVI.`active` = '1' AND
-							P.`id` > 0 AND
-							P.`deleted` != '1'
-					) AS `count_produkte`
-					".$strQuerySELECT."
-				FROM
-					`".WPSG_TBL_VARIANTS."` AS V
-						".$strQueryJOIN."
-				WHERE
-					V.`deleted` != '1'
-					".$strProductQuery."
-				GROUP BY
-					V.`id`
-				ORDER BY
-					".$strQueryORDER."
-					V.`product_id` ASC, V.`pos`
-			", "id");
-
-			foreach ($arData as $k => $v)
-			{
-
-				if ($onlyActive === true && !wpsg_isSizedInt($v['count_active'])) unset($arData[$k]);
-				else
-				{
-
-					$arData[$k]['type_label'] = self::$arTypeLabel[$arData[$k]['type']];
-
-					if ($loadVariationen === true && wpsg_isSizedInt($product_id))
-					{
-
-						$arData[$k]['arVariation'] = $this->db->fetchAssoc("
-							SELECT
-								PVI.*,
-								VI.`name`
-							FROM
-								`".WPSG_TBL_VARIANTS_VARI."` AS VI
-									LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
-							WHERE
-								VI.`deleted` != '1' AND
-								VI.`variant_id` = '".wpsg_q($v['id'])."' AND
-								PVI.`product_id` = '".wpsg_q($product_id)."' AND
-								PVI.`active` = '1'
-							ORDER BY
-								VI.`pos` ASC
-						", "variation_id");
-
-						// Bilder deserialisieren
-						foreach ($arData[$k]['arVariation'] as $vari_id => $vari_data)
-						{
-
-							if ($serVariationen == true) {
-								$arData[$k]['arVariation'][$vari_id]['images'] = @unserialize($vari_data['images']);
-								if (wpsg_isSizedString($arData[$k]['arVariation'][$vari_id]['images'])) $arData[$k]['arVariation'][$vari_id]['images'] = wpsg_trim(explode(',', $arData[$k]['arVariation'][$vari_id]['images']));
-								else $arData[$k]['arVariation'][$vari_id]['images'] = array();
-
-							}
-
-						}
-
-					}
-				}
-
-			}
-
-			// TODO: Ãbersetzung
-
-			return $arData;
-
-		}
-
-		public function basket_preInsertDefekt()
-		{
-
-			if (is_array($_REQUEST['wpsg_vp']) && sizeof($_REQUEST['wpsg_vp']) > 0)
-			{
-
-				$var_key = 'pv_'.$_REQUEST['wpsg']['produkt_id'].'|';
-
-				foreach ($_REQUEST['wpsg_vp'] as $var => $var_value)
-				{
-
-					$var_key .= $var.":".$var_value."|";
-
-				}
-
-				$var_key = substr($var_key, 0, -1);
-
-				$_REQUEST['wpsg']['produkt_id'] = $var_key;
-
-			}
-
-		} // public function basket_preInsert()
-
-		public function basket_row(&$p, $i)
-		{
-
-			if (!preg_match('/pv_(.*)/', $p['id'])) return;
-
-			$this->shop->view['variante'] = $this->getVariantenInfoArray($p['id']);
-
-			$this->shop->view['i'] = $i;
-
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/basket_row.phtml');
-
-		} // public function basket_row(&$p)
-
-		public function overview_row(&$p, $i)
-		{
-
-			if (!preg_match('/pv_(.*)/', $p['id'])) return;
-
-			$this->shop->view['variante'] = $this->getVariantenInfoArray($p['id']);
-
-			$this->shop->view['i'] = $i;
-
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/overview_row.phtml');
-
-		} // public function basket_row(&$p)
-
-		/**
-		 * Liest die Informationen anhand eines VariantenschlÃŒssels aus
-		 */
-		public function getVariantenInfoArray($vari_key)
-		{
-
-			//$produkt_id = preg_replace('/(vp_)|(\/(.*))/', '', $vari_key);
-			$produkt_id = preg_replace('/(pv_)|(\|(.*))/', '', $vari_key);
-			//$arVari = explode('|', preg_replace('/vp_'.$produkt_id.'\//', '', $vari_key));
-			$arVari = explode('|', preg_replace('/pv_'.$produkt_id.'\|/', '', $vari_key));
-
-			//$vp_data = $this->loadVarianten($produkt_id);
-			$vp_data = $this->getVariants($produkt_id, true, true, true);
-			$this->unserializeVariant($vp_data);
-
-			$arKey = array();
-			$arAKey = array();
-			$arPics = array();
-
-			$arReturn = array();
-
-			// kein Produkt-Key dann keine Weiterarbeit nÃ¶tig
-			if (is_numeric($vari_key)) {
-				$arReturn['key'] = '';
-				$arReturn['akey'] = '';
-				$arReturn['pics'] = array();
-				return $arReturn;
-
-			}
-
-			if ($this->shop->hasMod('wpsg_mod_fuellmenge')) $arReturn['fmenge'] = 0;
-			if ($this->shop->hasMod('wpsg_mod_weight')) $arReturn['weight'] = 0;
-
-			foreach ($arVari as $var_key)
-			{
-
-				$var_id = preg_replace('/\:(.*)/', '', $var_key);
-				$var_value = preg_replace('/(.*)\:/', '', $var_key);
-
-				if ($vp_data[$var_id]['typ'] == 'checkbox')
-				{
-
-					$arPicsVariante = array();
-
-					if (isset($vp_data[$var_id]['pic']))
-					{
-
-						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['pic']));
-
-					}
-
-					if ($var_value == '1')
-					{
-
-						$r = array(
-								'name' => $vp_data[$var_id]['name'],
-								'preis' => $vp_data[$var_id]['price'],
-								'artnr'	=> $vp_data[$var_id]['arVariation'][2]['anr'],
-								'pics' => $arPicsVariante
-						);
-
-						if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['weight']))
-						{
-
-							$r['weight'] = $vp_data[$var_id]['weight'];
-							$arReturn['weight'] += $r['weight'];
-
-						}
-
-						if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['fmenge']))
-						{
-
-							$r['fmenge'] = $vp_data[$var_id]['fmenge'];
-							$arReturn['fmenge'] += $r['fmenge'];
-
-						}
-
-						$arReturn[] = $r;
-
-						$arKey[] = $vp_data[$var_id]['name'];
-
-						$arPics = array_intersect($arPics, $arPicsVariante);
-
-					}
-					else
-					{
-
-						// Checkbox ist nicht markiert
-						//$arPics = array_unique(array_merge($arPics, $arPicsVariante));
-
-					}
-
-				}
-				else
-				{
-
-					$arPicsVariante = array();
-
-					if (isset($vp_data[$var_id]['arVariation'][$var_value]['pic']))
-					{
-
-						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['arVariation'][$var_value]['pic']));
-						$arPics = array_unique(array_merge($arPics, $arPicsVariante));
-
-					}
-
-					$r = array(
-							'name' 	=> $vp_data[$var_id]['name'],
-							'value' => $vp_data[$var_id]['arVariation'][$var_value]['name'],
-							'preis'	=> $vp_data[$var_id]['arVariation'][$var_value]['price'],
-							'artnr'	=> @$vp_data[$var_id]['arVariation'][$var_value]['artnr'],
-							'pics' => $arPicsVariante
-					);
-
-					if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['weight']))
-					{
-
-						$r['weight'] = $vp_data[$var_id]['arVariation'][$var_value]['weight'];
-						$arReturn['weight'] += $r['weight'];
-
-					}
-
-					if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['fmenge']))
-					{
-
-						$r['fmenge'] = $vp_data[$var_id]['arVariation'][$var_value]['fmenge'];
-						$arReturn['fmenge'] += $r['fmenge'];
-
-					}
-
-					$arReturn[] = $r;
-
-					$arKey[] = $vp_data[$var_id]['arVariation'][$var_value]['name'];
-					$arAKey[] = @$vp_data[$var_id]['arVariation'][$var_value]['anr'];
-
-				}
-
-			}
-
-			$arReturn['key'] = implode(' / ', $arKey);
-			$arReturn['akey'] = implode(' / ', $arAKey);
-			$arReturn['pics'] = array_unique($arPics);
-
-			return $arReturn;
-
-		} // public function getVariantenInfoArray($vari_key)
-
-		/**
-		 * Wird nach dem speichern des Produktes aus der saveAction des 
-		 * Produktcontrollers aufgerufen
-		 * 
-		*/
-		public function produkt_save(&$produkt_id) {
-			
-			$varis = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id`='".wpsg_q($produkt_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[] = sanitize_file_name($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'])."'");
-				
-			}
-		}	// public function produkt_save(&$produkt_id)
-		
-
-	} // class wpsg_mod_productvariants extends wpsg_mod_basic
-
-?>
Index: ds/wpsg_mod_produktbilder.class.php
===================================================================
--- /mods/wpsg_mod_produktbilder.class.php	(revision 6437)
+++ 	(revision )
@@ -1,1067 +1,0 @@
-<?php
-
-	/**
-	 * Dieses Modul ist fÃŒr die Ausgabe der Produktbilder zustÃ€ndig
-	 */
-	class wpsg_mod_produktbilder extends wpsg_mod_basic
-	{
-		
-		var $lizenz = 1;
-		var $id = 120;
-		var $hilfeURL = 'http://wpshopgermany.de/?p=530';
-		
-		/**
-		 * Costructor
-		 */
-		public function __construct()
-		{
-			
-			parent::__construct();
-			
-			$this->name = __('Produktbilder', 'wpsg');
-			$this->group = __('Produkte', 'wpsg');
-			$this->desc = __('ErmÃ¶glicht es Bilder zu Produkten anzugeben.', 'wpsg');
-						
-		} // public function __construct()
-		
-		public function install() 
-		{ 
-			 			
-		} // public function install()
-		
-		/**
-		 * 
-		 * Enter description here ...
-		 */
-		function wpsg_enqueue_scripts()
-		{
-			
-			if (is_admin() && preg_match('/wpsg/', wpsg_getStr($_REQUEST['page'])))
-			{
-			
-				wp_enqueue_script('wpsg_ajaxupload', $this->shop->getRessourceURL('js/ajaxupload.js'));
-				wp_enqueue_media();
-				
-			}
-				
-		} // function wpsg_enqueue_scripts()
-		
-		public function be_ajax() 
-		{ 
-		
-			if ($_REQUEST['wpsg_mod_produktbilder_clearcache'] == '1')
-			{
-
-				$this->picClearCash();
-				$this->shop->addBackendMessage(__('Bildercache gelÃ¶scht.', 'wpsg')); 
-				
-				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_produktbilder');
-				
-			}
-			
-		} // public function be_ajax()
-		
-		public function settings_edit()
-		{
-			 			
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/settings_edit.phtml');
-			
-		} // public function settings_edit()
-		
-		public function settings_save()
-		{
-						
-		} // public function settings_save()
-		
-		public function admin_presentation() 
-		{ 
-
-			echo wpsg_drawForm_Checkbox('wpsg_mod_produktbilder_basketimage', __('Produktbild im Warenkorb anzeigen', 'wpsg'), $this->shop->get_option('wpsg_mod_produktbilder_basketimage'));
-			echo wpsg_drawForm_Checkbox('wpsg_mod_produktbilder_overviewimage', __('Produktbild in Bestellzusammenfassung anzeigen', 'wpsg'), $this->shop->get_option('wpsg_mod_produktbilder_overviewimage')); 
-			
-			
-		} // public function admin_presentation()
-		
-		public function admin_presentation_submit() 
-		{ 
-			
-			$this->shop->update_option('wpsg_mod_produktbilder_basketimage', $_REQUEST['wpsg_mod_produktbilder_basketimage']);
-			$this->shop->update_option('wpsg_mod_produktbilder_overviewimage', $_REQUEST['wpsg_mod_produktbilder_overviewimage']);
-			
-		} // public function admin_presentation_submit()
-		 
-		public function picClearCash($product_id = false)
-		{	
-			 
-			if (wpsg_isSizedInt($product_id))
-			{
-				
-				if (file_exists($this->getPicPath('').$product_id.'/tn/')) wpsg_rrmdir($this->getPicPath('').$product_id."/tn/");
-				
-			}
-			else
-			{
-			
-				$handle = opendir($this->getPicPath(''));
-				
-				$arFiles = array();
-				while (false !== ($filename = readdir($handle))) 
-		   		{
-		   				
-		   			if (is_dir($this->getPicPath('').$filename) && $filename != "." && $filename != ".." && $filename != '')
-		   			{
-		   				
-		   				if (file_exists($this->getPicPath('').$filename.'/tn/')) wpsg_rrmdir($this->getPicPath('').$filename."/tn/");
-		   				
-		   			}
-		   			
-		   		}
-		   		
-			}
-
-		} // public function picClearCash()
-
-		public function produkt_ajax() 
-		{
-			global $wpdb;
-			
-			if (wpsg_isSizedString($_REQUEST['cmd'], 'clearProductCache'))
-			{
-				
-				$this->picClearCash($_REQUEST['edit_id']);
-				
-				die(__('Bildercache erfolgreich gelÃ¶scht.', 'wpsg'));
-				
-			} 
-			else if ($_REQUEST['cmd'] == 'produktbilder_liste')
-			{
-				
-				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];				
-				die($this->getProduktBilderListe($_REQUEST['edit_id']));
-				
-			}
-			else if ($_REQUEST['cmd'] == 'upload_mt')
-			{
-				
-				// Mediathek				
-				$fname = $_FILES['userfile']['name'][0];
-
-				$filetype = wp_check_filetype( basename( $fname ), null );
-				$wp_upload_dir = wp_upload_dir();
-				$attachment = array(
-					'guid' => wpsg_q($wp_upload_dir['url'] . '/' . basename($fname)),
-					'post_mime_type' => wpsg_q($filetype['type']),
-					'post_title' => wpsg_q(preg_replace('/\.[^.]+$/', '', basename($fname))),
-					'post_excerpt' => wpsg_q($fname),
-					'post_parent' => '0',
-					'wpsg_produkt_id' => '6',
-					'post_status' => 'inherit'
-				);
-				
-				$_FILES = $this->diverse_array($_FILES['userfile']);
-				$attachment_id = media_handle_upload( '0', 0, $attachment );	//OK
-				
-				// Feld wpsg_produkt_id setzen mit $_REQUEST['edit_id']
-				//$this->db->UpdateQuery($wpdb->prefix."posts", array(
-				//	"wpsg_produkt_id" => $_REQUEST['edit_id']), "`ID` = '".wpsg_q($attachment_id)."'");
-				add_post_meta( $attachment_id, 'wpsg_produkt_id', $_REQUEST['edit_id'] );
-				
-				
-				// Tests
-				$p1 = wp_get_attachment_url($attachment_id);	// http://shop4.home/wp-content/uploads/2017/03/hdrechteckig.png
-				$p2 = get_attached_file( $attachment_id ); 		// C:\xampp\htdocs\wp2/wp-content/uploads/2017/03/hdrechteckig.png
-				$p3 = get_attachment_link( $attachment_id );	// http://shop4.home/hdrechteckig/
-				$p4 = get_the_title( $attachment_id );			// hdrechteckig
-				$p5 = get_post_type($attachment_id);			// attachment
-				$p6 = get_post($attachment_id);					// WP_Post
-				$p7 = wp_get_attachment_image_src($attachment_id, 'thumbnail');	// Array mit Full-URL, Width, Height
-				
-				add_image_size('s_40_40', 40, 40);
-				$ht = wp_get_attachment_image( $attachment_id, Array(40, 40));
-				$p8 = wp_get_attachment_image_src($attachment_id, Array(40, 40));
-				$p80 = $p8[0];
-				
-				//$rw = add_post_meta( $attachment_id, 'wpsg_produkt_id', '6' );
-				//$rw = add_post_meta( $attachment_id, 'wpsg_produkt_id', '5' );
-				//$rw = add_post_meta( $attachment_id, 'wpsg_produkt_id', '4' );
-				//$rw = get_post_meta( $attachment_id, 'wpsg_produkt_id' );
-				
-				unset($_FILES[0]);
-				$i = 1;
-				foreach ($_FILES as $key => $val) {
-					// File hochladen und Feld wpsg_produkt_id setzen
-					$fname = $val['name'];
-					$filetype = wp_check_filetype( basename( $fname ), null );
-					$attachment['post_mime_type'] = $filetype['type'];
-					$attachment['guid'] = $wp_upload_dir['url'] . '/' . basename( $fname );
-					$attachment['post_title'] = preg_replace( '/\.[^.]+$/', '', basename( $fname ) );
-					$attachment['post_excerpt'] = wpsg_q($fname);
-					$attachment_id = media_handle_upload( $i, 92, $attachment );
-					//$this->db->UpdateQuery($wpdb->prefix."posts", array(
-					//		"wpsg_produkt_id" => $_REQUEST['edit_id']), "`ID` = '".wpsg_q($attachment_id)."'");
-					add_post_meta( $attachment_id, 'wpsg_produkt_id', $_REQUEST['edit_id'] );
-					$i++;
-				}
-				
-				die("1");
-				//die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
-				
-			}
-			else if ($_REQUEST['cmd'] == 'removemt')
-			{
-			
-				//unlink($this->getPicPath($_REQUEST['edit_id']).'/'.$_REQUEST['file']);
-				if ($_REQUEST['delmt'] === 'true') {	// Auch in der Mediathek lÃ¶schen
-					wp_delete_post( $_REQUEST['pid'], true );
-				}
-				
-				// Zuordnung lÃ¶schen
-				delete_post_meta( $_REQUEST['pid'], 'wpsg_produkt_id', $_REQUEST['edit_id'] );
-				
-				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
-			
-				if ($this->shop->hasMod('wpsg_mod_produktartikel')) $this->shop->callMod('wpsg_mod_produktartikel', 'updatePostThumbnail', array($_REQUEST['edit_id']));
-			
-				die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
-			
-			}
-			else if ($_REQUEST['cmd'] == 'uploadmt')
-			{
-				//die('uploadmt');
-				
-				// Tabelle Produkt postids lÃ¶schen
-				$sql = "UPDATE ".WPSG_TBL_PRODUCTS." SET `postids` = '' WHERE `id` = ".$_REQUEST['edit_id'];
-				$this->db->Query($sql);
-				
-				add_post_meta( $_REQUEST['post']['id'], 'wpsg_produkt_id', $_REQUEST['edit_id'] );
-				
-				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
-				die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
-				
-			}
-			else if ($_REQUEST['cmd'] == 'produktbilder_liste_MT')
-			{
-			
-				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
-				//$content = $this->getProduktBilderListe($_REQUEST['edit_id']);
-				die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
-				
-			}
-			else if ($_REQUEST['cmd'] == 'wpsg_setImageOrder')
-			{
-				$reo = $_REQUEST['wpsg_reorder'];
-				$pid = $_REQUEST['edit_id'];
-				
-				$file = '';
-				$line = '';
-				$b = headers_sent($file, $line);
-				$a = headers_list();
-				
-				$sreo = '';
-				foreach ($reo as $v) {
-					$st = explode('_', $v);
-					$sreo .= $st[1].',';
-				}
-				
-				$sreo = substr($sreo, 0, strlen($sreo) - 1);
-				
-				$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array("postids" => wpsg_q($sreo)), "`id` = '".wpsg_q($pid)."'");
-				
-				flush();
-				die('1');
-				
-			}
-			
-		} // public function produkt_ajax()
-		
-		public function diverse_array($vector) 
-		{
-			
-			$result = array();
-			
-			foreach($vector as $key1 => $value1)
-			{
-				
-				foreach($value1 as $key2 => $value2)
-				{
-					
-					$result[$key2][$key1] = $value2;
-					
-				}
-				
-			}
-			
-			return $result;
-			
-		}
-		
-		
-		public function produkt_save(&$produkt_id) 
-		{ 
-		 
-			
-		} // public function produkt_save(&$produkt_id)
-		
-		public function produkt_del($product_id)
-		{
-			
-			$path_bilder = $this->getPicPath($product_id);
-			wpsg_rrmdir($path_bilder);
-			
-		} // public function produkt_del(&$product_id)
-		 
-		public function product_addedit_content(&$product_content, &$product_data)
-		{
-			
-			// Wenn eine Ãbersetzung bearbeitet wird, dann nichts machen
-			if (isset($_REQUEST['wpsg_lang'])) return;
-			 										
-			if (wpsg_isSizedInt($product_data['id']))
-			{
-			
-				$this->shop->view['modul'] = &$this;
-				$this->shop->view['ProduktBilderPath'] = $this->getPicPath($product_data['id']);
-				$this->shop->view['ProduktBilderURL'] = $this->getPicPath($product_data['id'], true);
-				$this->shop->view['ProduktList'] = $this->getProduktBilderListe($product_data['id']);
-			
-				$this->shop->view['ProduktList_MT'] = $this->getProduktBilderListe_MT($product_data['id']);
-				
-			}
-			
-			$product_content['wpsg_mod_productbilder'] = array(
-				'title' => __('Produktbilder', 'wpsg'),
-				'content' => $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_addedit_content.phtml', false)
-			);
-			
-		} // public function product_addedit_content(&$product_content, &$produkt_data)
-		
-		public function produkt_edit_content(&$produkt_data) 
-		{ 
-			
-			if (isset($_REQUEST['wpsg_lang'])) return;
-			
-			$this->shop->view['data'] = $produkt_data;
-			
-			if ($produkt_data['id'] > 0)
-			{
-
-				$this->shop->view['modul'] = &$this;
-				$this->shop->view['ProduktBilderPath'] = $this->getPicPath($produkt_data['id']);
-				$this->shop->view['ProduktBilderURL'] = $this->getPicPath($produkt_data['id'], true);
-				$this->shop->view['ProduktList'] = $this->getProduktBilderListe($produkt_data['id']);
-				
-			}
-			
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_content.phtml');	
-			
-		} // public function produkt_edit_content(&$produkt_data)
-		
-		public function produkt_createTranslation(&$produkt_id, &$trans_id)
-		{
-			
-		 	$path_src = $this->getPicPath($produkt_id);
-		 	$path_trg = $this->getPicPath($trans_id);
-		 	
-		 	wpsg_copy($path_src, $path_trg);
-			
-		} // public function produkt_createTranslation(&$produkt_id, &$trans_id)
-		
-		public function produkt_copy(&$produkt_id, &$copy_id) { 
-			
-			// Wie bei der Erstellung einer neuen Ãbersetzung ...
-			$this->produkt_createTranslation($produkt_id, $copy_id);
-			
-		} // public function produkt_copy(&$produkt_id, &$copy_id)
-		
-		public function checkGeneralBackendError()
-		{
-			
-						
-		} // public function checkGeneralBackendError()
-		
-		/* Modulfunktionen */
-
-		/**
-		 * Mediatheksfunktion
-		 * FÃŒgt ein neues Bild zu einem Produkt hinzu
-		 * 
-		 * @param String $file Absoluter Pfad zu dem Bild
-		 * @param $product_id ID des Produktes zu dem das Bild zugeordnet werden soll
-		 */
-		public function addImageToProduct($file, $product_id)
-		{
-			
-			// Siehe
-			// https://codex.wordpress.org/Function_Reference/wp_insert_attachment
-			
-			$wp_upload_dir = wp_upload_dir();
-			
-			$mt_filetype = wp_check_filetype(basename($file), null);
-			$mt_filename = $wp_upload_dir['path'].'/'.basename($file);
-			
-			copy($file, $mt_filename);
-			
-			$attachment = array(
-				'guid' => wpsg_q($wp_upload_dir['url'].'/'.basename($file)),
-				'post_mime_type' => wpsg_q($mt_filetype['type']),
-				'post_title' => wpsg_q(preg_replace('/\.[^.]+$/', '', basename($file))),
-				'post_excerpt' => wpsg_q(basename($file)),
-				'post_status' => 'inherit'
-			);
-			
-			$attachment_id = wp_insert_attachment($attachment, $mt_filename, '0');
-			
-			require_once(ABSPATH.'wp-admin/includes/image.php');
-			
-			$attach_data = wp_generate_attachment_metadata($attachment_id, $mt_filename);
-			wp_update_attachment_metadata($attachment_id, $attach_data);
-			
-			add_post_meta($attachment_id, 'wpsg_produkt_id', $product_id);
-						
-		} // public function addImageToProduct($file, $product_id)
-		
-		/**
-		 * Wird vom Template produkt_edit_content.phtml aufgerufen und per Ajax aktualisiert.
-		 * Zeichnet die Liste mit den Produktbildern
-		 */
-		public function getProduktBilderListe($produkt_id)
-		{
-			
-			$this->shop->view['modul'] = &$this;
-			$this->shop->view['ProduktBilderPath'] = $this->getPicPath($produkt_id);
-			$this->shop->view['ProduktBilderURL'] = $this->getPicPath($produkt_id, true);
-			$this->shop->view['ProduktBilder'] = $this->getProduktBilder($produkt_id);
-			
-			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_list.phtml', false);
-			
-		} // public function getProduktBilderListe($produkt_id)
-		
-		/**
-		 * Wird vom Template produkt_edit_content.phtml aufgerufen und per Ajax aktualisiert.
-		 * Zeichnet die Liste mit den Produktbildern
-		 */
-		public function getProduktBilderListe_MT($produkt_id, $size = 'thumbnail')
-		{
-			global $wpdb;
-			
-			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key`='".wpsg_q('wpsg_produkt_id')."' AND `meta_value`='".wpsg_q($produkt_id)."' ORDER BY `post_id`");
-			//$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."posts` WHERE `wpsg_produkt_id` = '".wpsg_q($produkt_id)."' ");
-			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($produkt_id));
-			$arPostids = explode(',', $postids);
-			
-			$wp_upload_dir = wp_upload_dir();
-			$url = $wp_upload_dir['url'];
-			$i = 0;
-			
-			if (wpsg_isSizedString($postids)) {
-				foreach ($arPostids as $postid) {
-					
-					for ($i = 0; $i < count($data); $i++) {
-						if ($data[$i]['post_id'] == $postid) {
-							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
-							$guid = $p[0];
-							$arrf = pathinfo($guid);
-							$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $data[$i]['post_id'];
-							$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
-							$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
-							
-							$file = $arrf['basename'];
-							$pos1 = strrpos($file, '-');
-							if ($pos1 !== false) {
-								$pos2 = strrpos($file, '.');
-								//$file = substr_replace($file, '', $pos1, $pos2 - $pos1);
-							}
-							$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
-							$this->shop->view['ProduktBilder_MT'][$i]['basenameori']= $file;
-							
-						}
-					}
-				}
-				
-			} else {
-				foreach ($data as $key => $val) {
-					/*
-					$p1 = wp_get_attachment_url($val['ID']);
-					$arrf = pathinfo($p1);
-					$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
-					$guid = $arrf['dirname'].'/'.$arrf['filename'].'-150x150.'.$arrf['extension'];
-					*/
-					$p = wp_get_attachment_image_src($val['post_id'], $size);	// Array mit Full-Path, Width, Height
-					$guid = $p[0];
-					$arrf = pathinfo($guid);
-					$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $val['post_id'];
-					$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
-					$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
-					$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $arrf['basename']);
-					$this->shop->view['ProduktBilder_MT'][$i]['basenameori']= $file;
-					$i++;
-				}
-			}
-			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_list_MT.phtml', false);
-				
-		} // public function getProduktBilderListe_MT($produkt_id)
-		
-		/**
-		 * Gibt die verfÃŒgbaren MÃ¶glichkeiten fÃŒr den Bildzuschnitt zurÃŒck
-		 */
-		public function getImageModes()
-		{
-		
-			return array(		
-				'n' => __('Unbearbeitet', 'wpsg'),
-				's' => __('Einpassen', 'wpsg'),
-				'sz' => __('Einpassen mit FreiflÃ€che', 'wpsg'),
-				'z' => __('Strecken', 'wpsg'),
-				'sw' => __('Skallieren auf Breite', 'wpsg'),
-				'sh' => __('Skallieren auf HÃ¶he', 'wpsg'),
-				'c' => __('Zuschneiden', 'wpsg'),
-				'cz' => __('Zentrieren und Abschneiden', 'wpsg')
-			);
-			
-		} // public function getImageModes()		
-		
-		/**
-		 * Gibt false oder die URL zu einem Bild des Produktes zurÃŒck
-		 */
-		public function getProductImage($product_key, $setW, $setH, $mode)
-		{
-			
-			$product_id = $this->shop->getProduktID($product_key);
-			
-			$arBilder = $this->getProduktBilder($product_id);
-			
-			if (!wpsg_isSizedArray($arBilder))
-			{
-				
-				$file = $this->shop->getRessourcePath('mods/mod_produktbilder/dummy.jpg');
-				
-				if (!file_exists($file)) return false;
-				else return $this->makeTn(0, $file, $setW, $setH, $mode); 
-				
-			}
-			
-			$img_url = $this->makeTn($product_id, $arBilder[0], $setW, $setH, $mode);
-			
-			return $img_url;
-			
-		} // public function getProductImage($product_key)
-
-		/**
-		 * Gibt false oder die URL zu einem Bild des Produktes zurÃŒck
-		 */
-		public function getProductImage_MT($product_key, $size = 'thumbnail')
-		{
-			
-			global $wpdb;
-			
-			$product_id = $this->shop->getProduktID($product_key);
-			
-			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key` = '".wpsg_q('wpsg_produkt_id')."' AND `meta_value` = '".wpsg_q($product_id)."' ORDER BY `post_id`");
-				
-			if (!wpsg_isSizedArray($data)) return false;
-
-			$p = wp_get_attachment_image_src($data[0]['post_id'], $size);	// Array mit Full-Path, Width, Height
-					
-			// Umsortiert, wenn Feld postids existiert
-			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($product_id));
-			$arPostids = explode(',', $postids);
-			$postid = $arPostids[0];
-			if (wpsg_isSizedString($postids)) {
-					
-					for ($i = 0; $i < count($data); $i++) {
-						if ($data[$i]['post_id'] == $postid) {
-							
-							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
-						}
-					}
-				
-			}
-			
-			// Wenn product_key dann das Bild der Variation holen.
-			if (!wpsg_isSizedInt($product_key)) {
-				
-				$ap = explode(':', $product_key);
-				$vid = $ap[count($ap) - 1];
-				$images = $this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `variation_id`=".wpsg_q($vid));
-				$ar = unserialize($images);
-				$ar2 = explode(',', $ar['pic']);
-				//$file = pathinfo($ar2[count($ar2) - 1], PATHINFO_FILENAME);
-				$ar3 = pathinfo($ar2[count($ar2) - 1]);
-				$file = $ar3['basename'];
-				$af = $file;
-				$pos1 = strrpos($file, '-');
-				if ($pos1 !== false) {
-					$pos2 = strlen($file);
-					//$af = substr_replace($file, '', $pos1, $pos2 - $pos1);
-				}
-				$af = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
-				$ar4 = pathinfo($af);
-				$af = $ar4['filename'];
-				$af2 = substr($af, 0, strlen($af) - 2);
-				//var_dump($af2);
-				$sql = "SELECT
-					P.`ID`, P.`post_title`, P.`guid`, PM.`post_id`, PM.`meta_key`, PM.`meta_value`
-					FROM `".$wpdb->prefix."posts` AS P
-					LEFT JOIN `".$wpdb->prefix."postmeta` AS PM ON (P.`ID` = PM.`post_id`)
-					WHERE
-					PM.`meta_key` = 'wpsg_produkt_id' AND
-					PM.`meta_value` = '".wpsg_q($product_id)."' AND
-					P.`post_title` = '".$af."'
-				";
-				$arr = $this->db->fetchAssoc($sql);
-				
-				if (!wpsg_isSizedArray($arr)) {
-					$sql = "SELECT
-						P.`ID`, P.`post_title`, P.`guid`, PM.`post_id`, PM.`meta_key`, PM.`meta_value`
-						FROM `".$wpdb->prefix."posts` AS P
-						LEFT JOIN `".$wpdb->prefix."postmeta` AS PM ON (P.`ID` = PM.`post_id`)
-						WHERE
-						PM.`meta_key` = 'wpsg_produkt_id' AND
-						PM.`meta_value` = '".wpsg_q($product_id)."' AND
-						P.`post_title` = '".$af2."'
-					";
-					$arr = $this->db->fetchAssoc($sql);
-				}
-				
-				$p = wp_get_attachment_image_src($arr[0]['ID'], 'thumbnail');
-				
-			}
-			
-			$img_url = $p[0];
-			
-			return $img_url;
-				
-		} // public function getProductImage_MT($product_key)
-		
-		/**
-		 * Gibt ein Array mit den Produktbildern zurÃŒck
-		 */
-		public function getProduktBilder($produkt_id)
-		{
-			
-			$arFiles = array();
-
-			// Bilder aus dem Dateisystem raussuchen
-			$path = $this->getPicPath($this->shop->getProduktId($produkt_id));
-						 
-			$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;
-			
-		} // public function getProduktBilder($produkt_id)
-		
-		/**
-		 * Gibt ein Array mit den Produktbildern zurÃŒck
-		 * $size = 'full' sollte OriginalgrÃ¶Ãe zurÃŒckgeben
-		 */
-		public function getProduktBilder_MT($produkt_id, $size = 'thumbnail')
-		{
-			
-			global $wpdb;
-				
-			if ($this->shop->callMod('wpsg_mod_productvariants', 'isVariantsProductKey', array($produkt_id))) {
-				$ar = $this->shop->callMod('wpsg_mod_productvariants', 'explodeProductKey', array($produkt_id));
-				$produkt_id = $ar['product_id'];
-			}
-			
-			$arFiles = array();		
-			
-			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key` = 'wpsg_produkt_id' AND `meta_value` = '".wpsg_q($produkt_id)."' ");
-			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($produkt_id));
-			$arPostids = explode(',', $postids);
-			
-			$ud = wp_upload_dir();
-			
-			$i = 0;
-			
-			if (wpsg_isSizedString($postids)) {
-				foreach ($arPostids as $postid) {
-					
-					for ($i = 0; $i < count($data); $i++) {
-						if ($data[$i]['post_id'] == $postid) {
-							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
-							$guid = $p[0];
-							$arrf = pathinfo($guid);
-
-							$arFiles[$i]['guid'] = $guid;
-							$arFiles[$i]['post_id'] = $data[$i]['post_id'];
-							$arFiles[$i]['basename'] = $arrf['basename'];
-							$file = $arrf['basename'];
-							$pos1 = strrpos($file, '-');
-							if ($pos1 !== false) {
-								$pos2 = strrpos($file, '.');
-								//$file = substr_replace($file, '', $pos1, $pos2 - $pos1);
-							}
-							$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
-							
-							$arFiles[$i]['basenameori']= $file;
-							
-							$arFiles[$i]['url'] = $guid;
-							$arFiles[$i]['path'] = str_replace($ud['baseurl'], $ud['basedir'], $guid);
-							
-						}
-					}
-				}
-				
-			} else {
-				
-				foreach ($data as $key => $val) 
-				{
-					
-					$p = wp_get_attachment_image_src($val['post_id'], $size);	// Array mit Full-Path, Width, Height
-					 
-					$guid = $p[0];
-					$arrf = pathinfo($guid);
-					
-					//$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $val['post_id'];
-					//$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
-					//$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
-					
-					$arFiles[$i]['guid'] = $guid;
-					$arFiles[$i]['post_id'] = $val['post_id'];
-					$arFiles[$i]['basename'] = $arrf['basename'];
-					$arFiles[$i]['basenameori'] = preg_replace('/\-(\d+)x(\d+)\./', '.', $arrf['basename']);;
-					$arFiles[$i]['url'] = $guid;
-					$arFiles[$i]['path'] = str_replace($ud['baseurl'], $ud['basedir'], $guid);				
-					
-					$i++;
-					
-				}
-			}
-			/*
-			wpsg_asort($arFiles);
-				
-			$arReturn = array();
-			foreach ($arFiles as $k => $v) $arReturn[] = $v;
-		
-			return $arReturn;
-			*/
-			
-			return $arFiles;
-			
-		} // public function getProduktBilder_MT($produkt_id)
-		
-		/*
- 		 * 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)
- 		{
- 		 	 			
- 			if ($url) $path = WPSG_URL_UPLOADS.'wpsg_produktbilder/'.$produkt_id.'/';
-			else 
-			{
-				
-				$path = WPSG_PATH_UPLOADS.'wpsg_produktbilder/'.$produkt_id.'/'; 
-				
-				if (!file_exists($path)) mkdir($path, 0777, true);
-				 
-			}
-			 			
-			if ($url === true) return $path;
-			else return wpsg_format_path($path);
-			 
- 		} // private function getPicPath($produkt_id, $url = false)
-
- 		/**
- 		 * @param int $p_id Id des Produktes
- 		 * @param String $file Dateiname des Bildes (Ohne Pfad)
- 		 * @param int $setW Angestrebte Breite des Bildes
- 		 * @param int $setH Angestrebte HÃ¶he des Bildes
- 		 * @param String $mode Modus 
- 		 * 
- 		 * Funktion kann jetzt auch mit Bildern umgehen, die nicht einem Produkt zugeordnet sind (z.B. dem Dummy Bild)
- 		 * Einfach als p_id 0 ÃŒbergeben und in $file den kompletten Pfad
-  		 */
- 		public function makeTn($p_id, $file, $setW, $setH, $mode)
-		{
-			
-			if ($p_id !== 0) $p_id = $this->shop->getProduktId($p_id);
-
-			$uploaddir = $this->getPicPath($p_id);
-			$uploaddir_tn = $this->getPicPath($p_id)."tn/";
-			$url_bilder = $this->getPicPath($p_id, true);
-			
-			if ($p_id !== 0 && !file_exists($uploaddir)) mkdir($uploaddir, 0777, true);
-			if (!file_exists($uploaddir_tn)) mkdir($uploaddir_tn, 0777, true);
-			
-			// Default Werte
-			if ($setW <= 0) $setW = 100;
-			if ($setH <= 0) $setH = 100;
-			if ($mode == "" || !isset($mode)) $mode = 's';
-			
-			if ($p_id !== 0) $src_file = $uploaddir.$file;
-			else {
-				
-				$src_file = $file;
-				$file = basename($src_file);
-				
-			}
-			
-			$trg_file = $uploaddir_tn.$mode.'-'.$setW.'-'.$setH.'-'.$file;
-			
-			if (!file_exists($src_file) || !is_file($src_file)) return;
-			
-			// Quelldatei existiert nicht
-			if (!file_exists($src_file)) return "FILE NOT FOUND: ".$uploaddir.$file;
-			
-			if (file_exists($trg_file)) return $this->shop->url(str_replace(' ', '%20', $url_bilder."tn/".$mode.'-'.$setW.'-'.$setH.'-'.$file));
-			
-			$b = copy($src_file, $trg_file);
- 
-			$ImInf = GetImageSize($trg_file);
-			$W = $ImInf[0];
-			$H = $ImInf[1];
-			
-			switch (strtolower(preg_replace("/.*\./", "", $trg_file)))
-			{
-				case 'gif':
-					$srcImage = imagecreatefromgif($trg_file);
-					break;
-				case 'png':				
-					$srcImage = imagecreatefrompng($trg_file);
-					break;
-				case 'jpg':
-					$srcImage = imagecreatefromjpeg($trg_file);
-					break;
-				case 'bmp':
-					$srcImage = imagecreatefromwbmp($trg_file);
-					break;
-				default:
-					return __("Unbekanntes Dateiformat", "wpsg");
-			}
-												
-			switch (strtolower($mode))
-			{
-				
-				case 'c':	// CROP
-					
-					$dstImage = ImageCreateTrueColor($setW, $setH);
-					 					
-					imagealphablending($dstImage, false);
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-					 					
-					// LÃ€ngste Seite finden
-					if ($W > $H)
-					{						
-						$new_width = $W / ($H / $setH);
-						imagecopyresampled($dstImage, $srcImage, 0 - ($new_width / 2) + ($setW / 2), 0, 0, 0, $new_width, $setH, $W, $H);
-					}
-					else
-					{
-						$new_height = $H / ($W / $setW);
-						imagecopyresampled($dstImage, $srcImage, 0, 0 - ($new_height / 2) + ($setH / 2), 0, 0, $setW, $new_height, $W, $H);						
-					}
-					 
-					break;	
-
-				case 'cz': // CROP CENTER
-				
-					$dstImage = ImageCreateTrueColor($setW, $setH);
-					
-					imagealphablending($dstImage, false);
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-					
-					$new_width = $H * $setW / $setH;
-					$new_height = $W * $setH / $setW;
-					
-					if ($new_width > $W)
-					{
-						
-						$y = (($H - $new_height) / 2);
-						
-						imagecopyresampled($dstImage, $srcImage, 0, 0, 0, $y, $setW, $setH, $W, $new_height);
-						
-					}
-					else
-					{
-						
-						$x = (($W - $new_width) / 2);
-						
-						imagecopyresampled($dstImage, $srcImage, 0, 0, $x, 0, $setW, $setH, $new_width, $H);
-						
-					}
-					
-					break;
-						
-				case 'z':   // STRETCH
-					 
-					$dstImage = ImageCreateTrueColor($setW, $setH);
-					
-					imagealphablending($dstImage, false);
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-					
-					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $setW, $setH, $W, $H); 
-					break;
-					
-				case 'n': 	// NIX 
-					
-					return $url_bilder.$file;
-					
-					break;
-					
-				case 'sz':  // SCALE und FreiflÃ€che
-					
-					$dstImage = ImageCreateTrueColor($setW, $setH);
-					list($width, $height) = $this->getNewSize($W, $H, $setW, $setH);					
-					 
-					imagealphablending($dstImage, false);					
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 255, 255, 255, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-					
-					$dst_x = 0; if ($width < $setW) $dst_x = ($setW - $width) / 2;
-					$dst_y = 0; if ($height < $setH) $dst_y = ($setH - $height) / 2;
-					
-					imagecopyresampled($dstImage, $srcImage, $dst_x, $dst_y, 0, 0, $width, $height, $W, $H);														
-									
-					break; 	
-
-				case 'sw': // SCALE WIDTH
-					
-					$height = $H / ($W / $setW);
-					
-					$dstImage = ImageCreateTrueColor($setW, $height);
-					
-					imagealphablending($dstImage, false);
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 255, 255, 255, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-					
-					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $setW, $height, $W, $H);
-						
-					break;
-					
-				case 'sh': // SCALE HEIGHT
-					
-					$width = $W / ($H / $setH);
-					
-					$dstImage = ImageCreateTrueColor($width, $setH);
-						
-					imagealphablending($dstImage, false);
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 255, 255, 255, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-						
-					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $width, $setH, $W, $H);
-										
-					break;
-										
-				case 's':	// SCALE INTO
-				default:
-					
-					list($width, $height) = $this->getNewSize($W, $H, $setW, $setH);					
-					$dstImage = ImageCreateTrueColor($width, $height);
-					
-					imagealphablending($dstImage, false);
-					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
-					imagefill($dstImage, 0, 0, $color);
-					imagesavealpha($dstImage, true);
-					
-					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $width, $height, $W, $H);														
-					break;
-					
-			}		
-			
-			switch (strtolower(preg_replace("/.*\./", "", $trg_file)))
-			{
-				
-				case 'gif':
-					ImageGIF($dstImage, $trg_file);
-				case 'png':
-
-					$quality = 9 - wpsg_round($this->shop->get_option('wpsg_mod_produktbilder_quality') / 10, 0);
-					if ($quality < 9) $quality = 0;
-					
-					$b = ImagePNG($dstImage, $trg_file, $quality);
-					
-					break;
-				case 'jpg':
-				case 'bmp':
-				default:
-					ImageJPEG($dstImage, $trg_file, $this->shop->get_option('wpsg_mod_produktbilder_quality'));
-					break;	
-								
-			}		
-			 
-			imageDestroy($dstImage);
-			imageDestroy($srcImage);	
-
-			return $this->shop->url(str_replace(' ', '%20', $url_bilder."tn/".$mode.'-'.$setW.'-'.$setH.'-'.$file));
-			
-		} // private function makeTn($mode, $set_width, $set_height)
-		
-		/**
-		 * Bestimmt die GrÃ¶Ãe im SeitenverhÃ€ltnis fÃŒr skalierte Bilder
-		 */
-		private function getNewSize($w, $h, $maxW, $maxH)
-		{
-		    
-		    if ($w > $h)
-		    {
-		    	
-				// Breite skalieren und schauen ob HÃ¶he reinpasst   		
-		    	// Bild ist breiter als hoch -> versuchen nach Breite zu skalieren
-		    	$newWidth = $maxW;
-		    	$newHeight = ($maxW / $w) * $h;
-		    	
-		    	if ($newHeight > $maxH)
-		    	{
-		    		
-		    		// Bild ist nach Skalierung auf Breite zu hoch ! 
-		    		// jetzt noch auf HÃ¶he skalieren
-		    		$newWidth = ($maxH / $newHeight) * $maxW;
-		    		$newHeight = $maxH;  
-		    		  			    			
-		    	}
-		    	
-		    }
-		    else 
-		    {
-		    	
-		    	// Nach HÃ¶he skalieren
-		    	$newHeight = $maxH;
-		    	$newWidth = ($maxH / $h) * $w;
-		    	
-		    	if ($newWidth > $maxW)
-		    	{
-		    		
-		    		// Bild ist nach Skalierung auf HÃ¶he zu schmal !
-		    		// jetzt Breite anpassen
-		    		$newHeight = ($maxW / $newWidth) * $maxH;
-		    		$newWidth = $maxW;
-		    		
-		    	}
-		    	
-		    }
-		    
-		    return array($newWidth, $newHeight);
-		    
-		} // function getNewSize($w, $h, $maxW, $maxH)
-		
-	} // class wpsg_mod_produktbilder extends wpsg_mod_basic
-
-?>
Index: /system/old/mod_produktbilder/produkt_addedit_content.phtml
===================================================================
--- /system/old/mod_produktbilder/produkt_addedit_content.phtml	(revision 6438)
+++ /system/old/mod_produktbilder/produkt_addedit_content.phtml	(revision 6438)
@@ -0,0 +1,364 @@
+<?php
+
+	/**
+	 * Template fÃŒr die Integration der Produktbilder in das Backend der Produktverwaltung
+	 * wird von Template /views/Produkt/addedit.phtml eingebunden
+	 */
+
+?>
+
+<!-- Modal fÃŒr FTP Pfad Anzeige -->
+<div class="modal fade" id="wpsg_mod_produktbilder_ftppath" tabindex="-1" role="dialog">
+  <div class="modal-dialog" role="document">
+    <div class="modal-content">
+      <div class="modal-header">
+        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+        <h4 class="modal-title" id="myModalLabel"><?php echo __('FTP Pfad fÃŒr Bilderupload', 'wpsg'); ?></h4>
+      </div>
+      <div class="modal-body">
+        <?php echo wpsg_hspc($this->callMod('wpsg_mod_produktbilder', 'getPicPath', array($this->view['data']['id']))); ?>
+      </div>
+      <div class="modal-footer">
+        <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __('SchlieÃen', 'wpsg'); ?></button> 
+      </div>
+    </div>
+  </div>
+</div>
+
+<!-- Modal fÃŒr LÃ¶schabfrage -->
+<div class="modal fade" tabindex="-1" role="dialog" id="wpsg_produktbilder_remove">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                <h4 class="modal-title"><?php echo __('Produktbild lÃ¶schen', 'wpsg'); ?></h4>
+            </div>
+            <div class="modal-body">
+
+                <?php echo wpsg_drawForm_Checkbox('dialog_produktbilder_delmt', __('Auch in der Mediathek lÃ¶schen', 'wpsg'), false, array()); ?>
+                
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __('Abbrechen', 'wpsg'); ?></button>
+                <button type="button" class="btn btn-primary" onclick="return wpsg_remove_bild_MT_OK();"><?php echo __('LÃ¶schen', 'wpsg'); ?></button>
+            </div>
+        </div>
+    </div>
+</div>
+
+
+<div class="panel panel-default">
+	<div class="panel-heading clearfix">
+    	<h3 class="panel-title"><?php echo __('Produktbilder', 'wpsg'); ?></h3>
+	</div>
+	<div class="panel-body">
+		
+		<?php if ($this->view['data']['id'] > 0) { ?>
+		
+			<?php if (get_option("wpsg_classicupload") == "1") { ?>
+				
+			<div class="wpsg_clear"></div><br />
+			<div><?php echo __("Um ein Bild zu lÃ¶schen klicken Sie einfach auf das Bild.", "wpsg"); ?></div>
+			<div class="wpsg_clear"></div><br />
+				
+			<input type="file" multiple="multiple" name="wpsg_mod_produktbilder_file[]" />
+				
+			<?php } else { ?>
+
+			<!--  Mediathek -->
+
+			<div class="ui-sortable" id="produktbilder_target_MT"><?php echo $this->view['ProduktList_MT']; ?></div>
+
+			<div class="wpsg_clear"></div>
+			<div><?php echo __("Bitte klicken Sie auf Mediathek um ein Bild hochzuladen. Um ein Bild zu lÃ¶schen klicken Sie einfach auf das Bild.", "wpsg"); ?></div>
+			<div><?php echo __("Die Reihenfolge kann mittels Drag&Drop verÃ€ndert werden.", "wpsg"); ?></div>
+			<div class="wpsg_clear"></div><br />
+		
+			<input value="Mediathek" class="button" type="text" style="text-align:center;" size="10" id="btnAddImgLink" />
+			<!--  <input value="UploadMT" class="button" type="text" style="text-align:center;" size="10" id="upload_button_mt" /> -->
+
+			<script type="text/javascript">/* <![CDATA[ */
+
+			jQuery(document).ready(function() {
+
+		   		jQuery('#produktbilder_target_MT').sortable( {
+					items: 'a',
+					helper : 'clone',
+					update: function(event, ui) {
+
+						//wpsg_vp_ajaxloading_show();
+						
+						var wpsg_reorder = jQuery(this).sortable('toArray');
+
+						jQuery.ajax( {
+							url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=wpsg_setImageOrder&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+							async: false,
+							data: {
+								'p_id': <?php echo '1'; ?>,
+								'wpsg_reorder': wpsg_reorder
+							},
+							success: function(data) {
+
+								data = data.replace(/\n|\r/g, '');
+								if (data != '1') alert(data);
+								//wpsg_vp_ajaxloading_hide(); 
+
+							}
+						} );
+																	 
+					}			
+				} ).disableSelection();
+
+
+			});
+
+				/*				
+				jQuery(document).ready(function() {		
+												
+					new AjaxUpload(
+						"upload_button_mt", {
+							action: "<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=upload_mt&edit_id=<?php echo $this->view['data']['id']; ?>&noheader=1",
+							onSubmit: function(file, extension) {
+
+								jQuery('#produktbilder_target_MT').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
+								
+							},
+							onComplete: function(file, response) {
+
+								//alert('onComplete=' + response);
+								if (response == '1')
+								{
+									
+									jQuery("#produktbilder_target_MT").load("<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=produktbilder_liste_MT&edit_id=<?php echo $this->view['data']['id']; ?>&noheader=1");
+
+									//jQuery('#produktbilder_target_MT').html(data);
+									//if (typeof wpsg_vp_refresh == "function") wpsg_vp_refresh();
+									
+								}
+								else
+								{
+									alert(response);
+								}
+								
+							}										
+						}
+					);					   
+			   	});
+				*/
+				
+				var post_id;
+				
+				/**
+				 * Wird beim lÃ¶schen eines Bilds (anklicken) aufgerufen
+				 */
+				function wpsg_remove_bild_MT(pid) {
+
+					post_id = pid;
+					//jQuery('#wpsg_produktbilder_remove').show();
+					jQuery('#wpsg_produktbilder_remove').modal( { } );
+					//jQuery('#wpsg_produktbilder_remove').modal('hide');
+					
+				}
+				
+				function wpsg_remove_bild_MT_OK() {
+
+					delmt = jQuery('#dialog_produktbilder_delmt').is(':checked');
+					del = jQuery('#dialog_produktbilder_del').is(':checked');
+					
+					jQuery('#wpsg_produktbilder_remove').modal('hide');
+
+					jQuery('#produktbilder_target_MT').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
+					
+					jQuery.ajax( {
+						url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=removemt&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+						async: true,
+						data: {
+							del: del,
+							delmt: delmt,
+							pid: post_id
+						},
+						success: function(data) {
+							
+							jQuery('#produktbilder_target_MT').html(data);
+
+							//if (typeof wpsg_vp_refresh == "function") wpsg_vp_refresh();
+							
+						}
+					} );
+
+					return false;
+					
+				}
+
+				jQuery(document).ready(function() {
+
+					// Set all variables to be used in scope
+					var wpframe,
+					    metaBox = jQuery('#meta-box-id.postbox'), // Your meta box id here
+					    addImgLink = metaBox.find('.upload-custom-img'),
+					    delImgLink = metaBox.find( '.delete-custom-img'),
+					    imgContainer = metaBox.find( '.custom-img-container'),
+					    imgIdInput = metaBox.find( '.custom-img-id' );
+					  
+					// ADD IMAGE LINK
+					jQuery("#btnAddImgLink").click(function (event) {
+						  
+					    event.preventDefault();
+					    
+					    // If the media frame already exists, reopen it.
+					    if ( wpframe ) {
+					      	wpframe.open();
+					      	return;
+					    }
+					    
+					    // Create a new media frame
+					    wpframe = wp.media.frames.file_frame = wp.media({
+					        title: "<?php echo __('AuswÃ€hlen oder Hochladen von Medien', 'wpsg'); ?>",
+					        button: { text: "<?php echo __('Medien benutzen', 'wpsg'); ?>" },
+					        multiple: true  // Set to true to allow multiple files to be selected
+					    });
+
+					    // When an image is selected in the media frame...
+					    wpframe.on( 'select', function() {
+
+				            var attachments = wpframe.state().get('selection').map( 
+				                function( attachment ) {
+
+				                    attachment.toJSON();
+				                    return attachment;
+				            });
+
+				            //loop through the array and do things with each attachment
+				            var i, attachment;
+				            for (i = 0; i < attachments.length; ++i) {
+
+				            	attachment = attachments[i];
+							    imgContainer.append( '<img src="'+attachment.url+'" alt="" style="max-width:100%;"/>' );
+
+				            	attachment = attachment.toJSON();
+								jQuery.ajax( {
+									url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=uploadmt&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+									async: true,
+									data: {
+										post: attachment
+									},
+									success: function(data) {
+										
+										jQuery('#produktbilder_target_MT').html(data);
+
+									}
+								} );
+
+
+				            }
+
+						    /*
+						    // Get media attachment details from the frame state
+						    var attachment = wpframe.state().get('selection').first().toJSON();
+						    // Send the attachment URL to our custom image input field.
+						    imgContainer.append( '<img src="'+attachment.url+'" alt="" style="max-width:100%;"/>' );
+						    // Send the attachment id to our hidden input
+						    imgIdInput.val( attachment.id );
+						    // Hide the add image link
+						    addImgLink.addClass( 'hidden' );
+						    // Unhide the remove image link
+						    delImgLink.removeClass( 'hidden' );
+
+						    //URL --> 
+						    //Titel --> attachment.title --> wp_posts.post_title
+						    //Beschriftung --> attachment.caption --> wp_posts.post_excerpt
+						    //Alternativtext --> attachment.title --> wp_postmeta._wp_attachment_image_alt
+						    //Beschreibung --> attachment.desription --> wp_posts.post_content
+
+							jQuery.ajax( {
+								url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=uploadmt&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+								async: true,
+								data: {
+									post: attachment
+								},
+								success: function(data) {
+									
+									jQuery('#produktbilder_target_MT').html(data);
+
+								}
+							} );
+					      	*/
+					      	
+					    });		// wpframe.on( 'select', function())
+
+					    // Finally, open the modal on click
+					    wpframe.open();
+					});	// jQuery("#btnAddImgLink").click(function (event))
+					  
+				});      // jQuery(document).ready(function())
+				
+			/* ]]> */</script>
+
+			
+			<?php } ?> 
+			
+			<script type="text/javascript">/* <![CDATA[ */
+
+				/**
+				 * LÃ¶scht den Bildercache dieses Produktes
+				 */
+				function wpsg_clearImageCache()
+				{
+
+					jQuery.ajax( {
+						url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=clearProductCache&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+						async: true,						
+						success: function(data) { alert(data); }
+					} );
+					
+					return false;
+
+				} // function wpsg_clearImageCache()					
+            
+				/**
+				 * Wird beim lÃ¶schen eines Bilds (anklicken) aufgerufen
+				 */
+				function wpsg_remove_bild(strBild)
+				{
+
+					if (!confirm('<?php echo __('Sind Sie sicher, das Sie dieses Bild lÃ¶schen mÃ¶chten?', 'wpsg'); ?>')) return false;
+
+					jQuery('#produktbilder_target').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
+					
+					jQuery.ajax( {
+						url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=remove&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+						async: true,
+						data: {
+							file: strBild
+						},
+						success: function(data) {
+							
+							jQuery('#produktbilder_target').html(data);
+
+							if (typeof wpsg_vp_refresh == "function") wpsg_vp_refresh();
+							
+						}
+					} );
+
+					return false;
+					
+				}
+			
+			/* ]]> */</script>
+			
+		<?php } else { ?>
+		<p><?php echo __('Das Hochladen von Produktbildern ist erst nach erstmaligem speichern mÃ¶glich.', 'wpsg'); ?></p>
+		<?php } ?>
+	
+		<div class="wpsg_clear"></div><br />
+		
+		<?php if (false && wpsg_isSizedInt($this->view['data']['id'])) { ?>
+		<a href="#" data-toggle="modal" data-target="#wpsg_mod_produktbilder_ftppath"><span class="wpsg-glyphicon glyphicon glyphicon-folder-open"></span><?php echo __('FTP Pfad anzeigen', 'wpsg'); ?></a><br />
+		<a href="#" onclick="return wpsg_clearImageCache();"><span class="wpsg-glyphicon glyphicon glyphicon-trash"></span><?php echo __('Bildercache dieses Produktes lÃ¶schen', 'wpsg'); ?></a><br />
+		<?php } ?>
+			
+		<a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_produktbilder"><span class="wpsg-glyphicon glyphicon glyphicon-wrench"></span><?php echo __('Zur Konfiguration der Produktbilder', 'wpsg'); ?></a>
+		
+						
+	</div>
+</div>
Index: /system/old/mod_produktbilder/produkt_edit_list.phtml
===================================================================
--- /system/old/mod_produktbilder/produkt_edit_list.phtml	(revision 6438)
+++ /system/old/mod_produktbilder/produkt_edit_list.phtml	(revision 6438)
@@ -0,0 +1,24 @@
+<?php
+	
+	/**
+	 * Template fÃŒr die Liste der Bilder eines Produkts
+	 */
+
+?>
+<?php if (sizeof($this->view['ProduktBilder']) > 0) { ?>
+
+	<?php foreach ($this->view['ProduktBilder'] as $b) { ?>
+	
+		<div class="wpsg_mod_produktbilder_admin_bild">
+			<a onclick="return wpsg_remove_bild('<?php echo $b; ?>');" href="#" title="<?php echo __('Dieses Bild lÃ¶schen.', 'wpsg'); ?>">
+				<img src="<?php echo $this->view['modul']->makeTn($this->view['data']['id'], $b, 75, 75, 'c'); ?>" alt="<?php echo wpsg_hspc($b); ?>" />
+				<span><span class="glyphicon glyphicon-trash"></span></span>
+			</a>
+		</div>
+	
+	<?php } ?>
+	<div class="wpsg_clear"></div>
+
+<?php } else { ?>
+<p><?php echo __('Bisher keine Produktbilder hochgeladen.', 'wpsg'); ?></p>
+<?php } ?>
Index: /system/old/mod_produktbilder/produkt_edit_list2.phtml
===================================================================
--- /system/old/mod_produktbilder/produkt_edit_list2.phtml	(revision 6438)
+++ /system/old/mod_produktbilder/produkt_edit_list2.phtml	(revision 6438)
@@ -0,0 +1,27 @@
+<?php
+	
+	/**
+	 * Template fÃŒr die Liste der Bilder eines Produkts
+	 */
+
+?>
+
+  <?php if (isset($this->view['ProduktBilder2']) && (sizeof($this->view['ProduktBilder2']) > 0)) { ?>
+
+	<?php foreach ($this->view['ProduktBilder2'] as $b) { ?>
+	
+		<div class="wpsg_mod_produktbilder_admin_bild">
+
+			<a onclick="return wpsg_remove_bild2('<?php echo $b['pid']; ?>');" href="#" title="<?php echo __('Dieses Bild lÃ¶schen.', 'wpsg'); ?>">
+				<img src="<?php echo $b['guid']; ?>" alt="<?php echo wpsg_hspc($b['fname']); ?>" />
+				<span><span class="glyphicon glyphicon-trash"></span></span>
+			</a>
+			
+		</div>
+	
+	<?php } ?>
+	<div class="wpsg_clear"></div>
+
+  <?php } else { ?>
+    <p><?php echo __('Bisher keine Produktbilder hochgeladen.', 'wpsg'); ?></p>
+  <?php } ?>
Index: /system/old/mod_produktbilder/produkt_edit_list_MT.phtml
===================================================================
--- /system/old/mod_produktbilder/produkt_edit_list_MT.phtml	(revision 6438)
+++ /system/old/mod_produktbilder/produkt_edit_list_MT.phtml	(revision 6438)
@@ -0,0 +1,27 @@
+<?php
+	
+	/**
+	 * Template fÃŒr die Liste der Bilder eines Produkts
+	 */
+
+?>
+
+  <?php if (isset($this->view['ProduktBilder_MT']) && (sizeof($this->view['ProduktBilder_MT']) > 0)) { ?>
+
+	<?php foreach ($this->view['ProduktBilder_MT'] as $b) { ?>
+	
+		<div id="produktbild_div_<?php echo $b['pid']; ?>" class="wpsg_mod_produktbilder_admin_bild">
+
+			<a id="produktbild_<?php echo $b['pid']; ?>" onclick="return wpsg_remove_bild_MT('<?php echo $b['pid']; ?>');" href="#" title="<?php echo __('Dieses Bild lÃ¶schen.', 'wpsg'); ?>">
+				<img src="<?php echo $b['guid']; ?>" alt="<?php echo wpsg_hspc($b['fname']); ?>" />
+				<span><span class="glyphicon glyphicon-trash"></span></span>
+			</a>
+			
+		</div>
+	
+	<?php } ?>
+	<div class="wpsg_clear"></div>
+
+  <?php } else { ?>
+    <p><?php echo __('Bisher keine Produktbilder hochgeladen.', 'wpsg'); ?></p>
+  <?php } ?>
Index: /system/old/mod_produktbilder/settings_edit.phtml
===================================================================
--- /system/old/mod_produktbilder/settings_edit.phtml	(revision 6438)
+++ /system/old/mod_produktbilder/settings_edit.phtml	(revision 6438)
@@ -0,0 +1,7 @@
+<?php
+
+	/**
+	 * Template fÃŒr die Einstellungsseite des Produktbilder Moduls
+	 */
+
+?> 
Index: /system/old/wpsg_mod_core.class
===================================================================
--- /system/old/wpsg_mod_core.class	(revision 6438)
+++ /system/old/wpsg_mod_core.class	(revision 6438)
@@ -0,0 +1,606 @@
+<?php
+
+	/**
+	 * Dieses Modul ist ein verstecktes System Modul und ist nur in der Lizezierten Version vorhanden
+	 * @author Daschmi (daniel@maennchen1.de) 02.10.2015
+	 */
+	class wpsg_mod_core extends wpsg_mod_basic
+	{
+		 
+		var $id = 1630;
+		
+		public function __construct()
+		{
+			
+			parent::__construct(); 
+			
+		} // public function __construct()
+		
+		/**
+		 * LÃ€dt die Module
+		 */
+		public function loadModule($all)
+		{
+			 
+			$mod_dir = opendir(WPSG_PATH_MOD);
+				
+			$global = false;
+			if ($this->shop->isMultiBlog() && $this->shop->get_option('wpsg_multiblog_standalone', true) != '1') $global = true;
+				
+			while ($file = readdir($mod_dir))
+			{
+			
+				if (!is_dir(WPSG_PATH_MOD."/".$file) && $file != "." && $file != ".." && preg_match("/(.*)\.class\.php/i", $file) && $file != "wpsg_mod_basic.class.php")
+				{
+						
+					if (file_exists(WPSG_PATH_USERMOD.$file)) require_once(WPSG_PATH_USERMOD.$file);
+					else require_once(WPSG_PATH_MOD.$file);
+						
+					$class_name = preg_replace("/\.class\.php/", "", $file);
+						
+					$mod = new $class_name();
+						
+					// Demo oder Modul fÃŒr Lizenz aktiv
+					/*if ($this->shop->arLizenz['l'] == 0 || $this->shop->arLizenz['l'] >= $mod->lizenz)
+					{
+							
+						if (!isset($mod->version) || $mod->getDemoDays() > 0 || (isset($this->shop->arLizenz) && in_array(get_class($mod), (array)$this->shop->arLizenz['mods'])))
+						{
+			
+							if ($this->shop->get_option($class_name, $global) > 0 || $class_name === 'wpsg_mod_core')
+							{
+			
+								$this->shop->arModule[$class_name] = $mod;
+			
+							}
+			
+						}
+							
+						if ($all)
+						{
+			
+							$this->shop->arAllModule[$class_name] = $mod;
+			
+						}
+			
+					} */
+						
+				}
+			
+			}
+			
+			$pluginModule = array(); $pluginModule = apply_filters('wpsg_modul_load', array($pluginModule));
+			
+			if (wpsg_isSizedArray($pluginModule))
+			{
+				
+				foreach ($pluginModule as $class_name => $mod)
+				{
+					
+					if (!is_object($mod)) continue;
+					
+					if ($this->shop->get_option($class_name, $global) > 0)
+					{
+	
+						$this->shop->arModule[$class_name] = $mod;
+	
+					}
+					
+					if ($all)
+					{
+		
+						$this->shop->arAllModule[$class_name] = $mod;
+		
+					}
+					
+				}
+				
+			}
+			 			
+			uasort($this->shop->arModule, array($this->shop, "cmp_mods"));
+				
+			if ($all) uasort($this->shop->arAllModule, array($this->shop, "cmp_mods"));
+			
+			// Module werden hier erst initiiert, da dann alle Module bekannt sind und die Reihenfolge hergestellt ist
+			foreach ($this->shop->arModule as $mod_key => $m)
+			{
+			
+				if ($this->shop->get_option(get_class($m), $global) > 0)
+				{
+			
+					$m->init();
+						
+				}
+			
+			}
+			
+		} // public function loadModule($all)
+		
+		/**
+		 * Gibt true zurÃŒck wenn eine aktive Lizenz eingebunden ist
+		 */
+		public function hasActiveLicence()
+		{
+			
+			if (is_array($this->shop->arLizenz) && isset($this->shop->arLizenz['l']))
+			{
+			
+				// PrÃŒfen das in einem Multiblog nur mit der Enterprise Version gearbeitet wird
+				if ($this->shop->isMultiBlog() && $this->shop->arLizenz['l'] < 3)
+				{
+						
+					// Die installierte Lizenz kann nicht in einer Multiblog Umgebung eingesetzt werden.
+					$this->shop->addBackendError(base64_decode('RGllIGluc3RhbGxpZXJ0ZSBMaXplbnoga2FubiBuaWNodCBpbiBlaW5lciBNdWx0aWJsb2cgVW1nZWJ1bmcgZWluZ2VzZXR6dCB3ZXJkZW4u'));
+					
+					return false;
+						
+				}
+			
+				return true;
+			
+			}
+				
+			if ($this->shop->getDemoDays() < 0)
+			{
+			
+				// Ihre Lizenz von wpShopGermany ist abgelaufen
+				//$this->shop->addBackendError(base64_decode('SWhyZSBMaXplbnogdm9uIHdwU2hvcEdlcm1hbnkgaXN0IGFiZ2VsYXVmZW4='));
+			
+			}
+			
+			return false;
+			
+		}
+		
+		/**
+		 * Gibt die Tage der DemoVersion zurÃŒck
+		 */
+		public function getDemoDays()
+		{
+			
+			$isnt = $this->shop->get_option('wpsg_installed', true);
+			$rem = round((($isnt + 14 * 60 * 60 * 24) - time()) / (60 * 60 * 24), 0);
+				
+			return $rem;
+			
+		} // public function getDemoDays()
+		
+		public function admin_registrierung()
+		{
+			
+			if (!class_exists('SoapClient'))
+			{
+			
+				$this->shop->addBackendError(__('nohspc_Ihrem Server fehlt die PHP-Bibliothek fÃŒr die SOAP-UnterstÃŒtzung. Eine Registrierung Ihrer Domain ist somit nicht mÃ¶glich! <br />Weitere Informationen finden Sie in unseren <a target="_blank" href="http://wpshopgermany.maennchen1.de/faqs/wie-pruefe-ich-ob-soap-und-curl-auf-meinem-server-aktiviert-sind/">FAQ</a>.', 'wpsg'));
+				$this->shop->view['actionName'] = 'registrierung';
+				$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
+			
+				return;
+			
+			}
+				
+			if (!$this->shop->arLizenz['nr'] > 0 && wpsg_getStr($_REQUEST['do']) != 'installModul') {
+			
+				$this->shop->view = array(
+					'actionName' => 'registrierung',
+					'subTemplate' => WPSG_PATH_VIEW.base64_decode('L21vZHMvbW9kX2NvcmUvYWRtaW5fbGljZW5jZS5waHRtbA==') // /mods/mod_core/admin_licence.phtml
+				);
+			
+			}
+			else
+			{
+			
+				if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'remove')
+				{
+			
+					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('removeURL', array($_REQUEST['url'])));
+						
+					if ($reg_data === false) { $this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg')); }
+					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
+					else { $this->shop->addBackendMessage(__('Domainregistrierung erfolgreich entfernt.', 'wpsg')); }
+						
+					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&subaction=domains');
+						
+				}
+				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'register')
+				{
+						
+					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('registerURL', array($this->shop->get_option('siteurl'))));
+						
+					if ($reg_data === false) { $this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg')); }
+					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
+					else { $this->shop->addBackendMessage(__('Domainregistrierung erfolgreich.', 'wpsg')); }
+						
+					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&subaction=domains');
+						
+				}
+				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'getCredentials')
+				{
+						
+					$this->getCredentialsAction();
+						
+					return;
+						
+				}
+				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'installModul')
+				{
+											
+					if ($this->installModul($_REQUEST['modul']))
+					{
+			
+						$this->shop->addBackendMessage(__('Modul erfolgreich installiert.', 'wpsg'));
+			
+					}
+			
+					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module');
+						
+				}
+				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'aktivateModul')
+				{
+						
+					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('aktivateModul', array($_REQUEST['wpsg_modulkey'])));
+						
+					if ($reg_data === false) { $this->shop->addBackendError(__('Modul konnte nicht aktiviert werden.', 'wpsg')); }
+					else if ($reg_data === -1) { $this->shop->addBackendError(__('UngÃŒltiger Modulcode.', 'wpsg')); }
+					else if ($reg_data === -2) { $this->shop->addBackendError(__('Code bereits fÃŒr einen anderen SchlÃŒssel verwendet.', 'wpsg')); }
+					else if ($reg_data === -3) { $this->shop->addBackendError(__('Modul bereits aktiviert.', 'wpsg')); }
+					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
+					else {
+			
+						// Neuen Modulcode speichern
+						$this->shop->update_option('wpsg_key', $reg_data, true);
+			
+						$this->shop->addBackendMessage(__('Modul erfolgreich aktiviert.', 'wpsg'));
+							
+					}
+						
+					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&subaction=module');
+						
+				}
+			
+				if (isset($_REQUEST['registerdata-submit']))
+				{
+						
+					$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('setRegisterInfo', array($_REQUEST)));
+						
+					if ($reg_data === false) { $this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg')); }
+					else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data)) { $this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error'])); }
+					else { $this->shop->addBackendMessage(__('Registrierungsdaten erfolgreich ÃŒbermittelt', 'wpsg')); }
+						
+					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung');
+						
+				}
+			
+				// Daten vom Registrierungsserver laden
+				$reg_data = $this->shop->callMod('wpsg_mod_core', 'RegisterCall', array('getRegisterInfo'));
+			
+				// Aktuelle Domain registriert?
+				$reg_data['registred'] = false;
+				$arURLs = array();
+				foreach ((array)$reg_data['domains'] as $d)
+				{
+						
+					$arURLs[] = preg_replace('/(.*)\/\//', '', $d['url']);
+						
+					if (preg_match('/((http\:\/\/)|(https\:\/\/)){0,1}'.preg_quote($this->shop->get_option('siteurl'), '/').'\/*/', $d['url']))
+					{
+						$reg_data['registred'] = true; break;
+					}
+						
+				}
+			
+				$this->shop->update_option('wpsg_registredURLs', $arURLs);
+			
+				if ($reg_data === false)
+				{
+						
+					$this->shop->addBackendError(__('Keine Registrierungsdaten gefunden.', 'wpsg'));
+						
+				}
+				else if (is_array($reg_data) && isset($reg_data['error']) && array_key_exists('error', $reg_data))
+				{
+						
+					$this->shop->addBackendError(wpsg_translate(__('Fehler im Registrierungsserver: #1#', 'wpsg'), $reg_data['error']));
+			
+				}
+			
+				$this->shop->view = array(
+					'data' => $reg_data,
+					'actionName' => 'registrierung',
+					'subTemplate' => WPSG_PATH_VIEW.base64_decode('L21vZHMvbW9kX2NvcmUvYWRtaW5fcmVnaXN0ZXIucGh0bWw='), // /mods/mod_core/admin_register.phtml
+					'mods' => $this->shop->arLizenz['mods']
+				);
+			
+				$this->shop->loadModule(true);
+			
+				switch ($this->shop->arLizenz['l'])
+				{
+						
+					case '1': $this->shop->view['typ'] = __('Light Version', 'wpsg'); break;
+					case '2': $this->shop->view['typ'] = __('Pro Version', 'wpsg'); break;
+					case '3': $this->shop->view['typ'] = __('Enterprise Version', 'wpsg'); break;
+					default: die();
+						
+				}
+			
+			}
+			
+			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
+			
+		} // public function admin_registrierung()
+		
+		public function module_index()
+		{
+			
+			if (class_exists('SoapClient'))
+			{
+		
+				$this->shop->view['arOnlineModule'] = $this->RegisterCall('getModulInfo_V2');
+		
+				foreach ((array)$this->shop->view['arOnlineModule'] as $k => $m)
+				{
+		
+					if (wpsg_isSizedString($m['version_dev']) && wpsg_isSizedInt($this->shop->get_option('wpsg_debugURL'))) $this->shop->view['arOnlineModule'][$k]['version'] = $m['version_dev'];
+		
+					$this->shop->view['arOnlineModule'][$k]['version_local'] = $this->shop->arAllModule[$m['key']]->version;
+		
+					$global = false;
+					if ($this->shop->isMultiBlog() && $this->shop->get_option('wpsg_multiblog_standalone', true) != '1') $global = true;
+		
+					if ($this->shop->get_option($m['key'], $global) > 0)
+					{
+							
+						$this->shop->view['arOnlineModule'][$k]['installed'] = true;
+							
+					}
+					else
+					{
+							
+						$this->shop->view['arOnlineModule'][$k]['installed'] = false;
+							
+					}
+		
+					if ($this->shop->get_option('wpsg_debugURL') == '1' && isset($this->shop->view['arOnlineModule'][$k]['version_dev']))
+					{
+		
+						$this->shop->view['arOnlineModule'][$k]['version'] = $m['version_dev'];
+							
+					}
+		
+				}
+						
+			}
+			else
+			{
+					
+				$this->shop->addBackendError(__('nohspc_Ihrem Server fehlt die PHP-Bibliothek fÃŒr die SOAP-UnterstÃŒtzung. Eine Registrierung Ihrer Domain ist somit nicht mÃ¶glich! <br />Weitere Informationen finden Sie in unseren <a target="_blank" href="http://wpshopgermany.maennchen1.de/faqs/wie-pruefe-ich-ob-soap-und-curl-auf-meinem-server-aktiviert-sind/">FAQ</a>.', 'wpsg'));
+					
+			}
+			
+			echo $this->render(WPSG_PATH_VIEW.'/mods/mod_core/module_index.phtml');
+			
+		} // public function module_index()
+		
+		/**
+		 * Sendet eine Anfrage an den Registrierungs Server und gibt das Ergebnis zurÃŒck
+		 */
+		public function RegisterCall($func_name, $args = array())
+		{
+				
+			$SOAP = new SoapClient(
+				null,
+				array(
+					'location' => base64_decode('aHR0cHM6Ly9zaG9wLm1hZW5uY2hlbjEuZGUvcmVnaXN0cmllcnVuZy8='), // https://shop.maennchen1.de/registrierung/
+					'uri' => 'http://shop.maennchen1.de',
+					'cache_wsdl' => WSDL_CACHE_NONE
+				)
+			);
+				
+			if (!$this->shop->hasActiveLicence())
+			{
+					
+				$args = array_merge(array('No_wpsg'), $args);
+		
+			}
+			else
+			{
+		
+				// Hier kein wpsg_array_merge da die index gleich sind
+				$args = array_merge(array($this->shop->get_option('wpsg_key', true)), $args);
+		
+			}
+				
+			try {
+					
+				$result = $SOAP->__soapCall($func_name, $args);
+		
+			}
+			catch (Exception $e)
+			{
+		
+				$this->shop->addBackendError(wpsg_translate(__('SOAP Fehler: #1#', 'wpsg'), $e->getMessage()));
+		
+			}
+				
+			return $result;
+				
+		} // public function RegisterCall($func_name, $args)
+	
+		public function installModul($modul_key)
+		{
+			
+			global $wp_filesystem;
+			
+			ob_start();
+			$request_creds = request_filesystem_credentials(
+				WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&noheader=1&do=installModul&modul='.$modul_key,
+				'',
+				false,
+				false,
+				null
+			);
+			ob_end_clean();
+				
+			// 1 gibt es bei Windows Rechnern zurÃŒck, da es hier egal ist
+			// Ein Array ist es wenn das Formular bereits abgeschickt wurde und die Anfrage vom Formular kommt
+			// false ist es wenn kein Zugriff ist dann muss das Formular angezeigt werden
+				
+			if (false === $request_creds)
+			{
+			
+				// Berechtigungen anfragen
+				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&do=getCredentials&modul='.$_REQUEST['modul']);
+			
+			}
+			else if (is_array($request_creds))
+			{
+			
+				if (!WP_Filesystem($request_creds))
+				{
+			
+					// Eingegebene Daten waren falsch
+					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&do=getCredentials&modul='.$_REQUEST['modul']);
+			
+				}
+			
+			}
+			
+			$temp_name = $this->shop->getTempName($modul_key.'.zip');
+			@unlink($temp_name);
+				
+			if ($this->shop->get_option('wpsg_debugURL') === '1' && $this->shop->hasMod('wpsg_mod_core'))
+			{
+			
+				$url = 'http://dl.maennchen1.de/wpsg/'.$modul_key.'/'.$modul_key.'_dev.zip';
+			
+			}
+			else
+			{
+			
+				$url = 'http://dl.maennchen1.de/wpsg/'.$modul_key.'/'.$modul_key.'_latest.zip';
+			
+			}
+			
+			$bOK = @copy($url, $temp_name);
+			
+			if (!$bOK)
+			{
+			
+				$bOK = @file_put_contents($temp_name, $this->shop->get_url_content($url));
+			
+				if (!$bOK)
+				{
+						
+					// Pfad finden fÃŒr das Wordpress Filesystem
+					if ($GLOBALS['wpsg_sc']->isMultiBlog())
+						$ftp_path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_temp/';
+						else
+							$ftp_path = WP_CONTENT_DIR.'/uploads/wpsg_temp/';
+								
+							$ftp_path = trailingslashit($wp_filesystem->find_folder($ftp_path)).preg_replace('/(.*)\/wpsg_temp\//', '', $temp_name);
+								
+							$bOK = $wp_filesystem->put_contents($ftp_path, $this->shop->get_url_content($url), FS_CHMOD_FILE);
+								
+							if (!$bOK)
+							{
+									
+								$this->shop->addBackendError(wpsg_translate(__('Modul (#1#) konnte nicht kopiert werden!', 'wpsg'), $modul_key));
+								return false;
+			
+							}
+								
+				}
+			
+			}
+				
+			$zip = new ZipArchive();
+			
+			if ($zip->open($temp_name) === true)
+			{
+			
+				try
+				{
+						
+					$bOK = @$zip->extractTo(WPSG_PATH.'/../');
+					$zip->close();
+			
+					if ($bOK === false)
+					{
+			
+						throw new Exception();
+							
+					}
+					else
+					{
+			
+						return true;
+							
+					}
+			
+				}
+				catch (Exception $e)
+				{
+						
+					// Es ist ein Fehler aufgetreten, jetzt versuche ich die Datei mit dem Wordpress Filesystem zu entpacken
+						
+					// Pfad finden fÃŒr das Wordpress Filesystem
+					$ftp_path = trailingslashit($wp_filesystem->find_folder(realpath(WPSG_PATH.'/../')));
+						
+					$bOK = unzip_file($temp_name, $ftp_path);
+						
+					if ($bOK !== true)
+					{
+			
+						$strError = '';
+			
+						// Hier ist immer noch ein Fehler aufgetreten
+						foreach ((array)$bOK->errors as $e)
+						{
+								
+							$strError .= $e[0].' ';
+			
+						}
+						 
+						$this->shop->addBackendError(wpsg_translate(__('Fehler beim Entpacken: #1#', 'wpsg'), $strError)); return false;
+			
+					}
+					else
+					{
+			
+						return true;
+			
+					}
+						
+				}
+			
+			}
+			else
+			{
+			
+				$this->shop->addBackendError(__('Datei konnte nicht ÃŒbertragen werden.', 'wpsg')); return false;
+			
+			}
+			
+			$this->shop->addBackendError(__('Datei konnte nicht entpackt werden.', 'wpsg')); return false;
+			
+		} // public function installModul($modul_key)
+		
+		/**
+		 * Fragt die Rechte ab und installiert anschlieÃend ein Modul
+		 */
+		public function getCredentialsAction()
+		{
+				
+			echo request_filesystem_credentials(
+				WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=registrierung&noheader=1&do=installModul&modul='.$_REQUEST['modul'],
+				'',
+				false,
+				false,
+				null
+			);
+				
+		} // public function getCredentialsAction()
+		
+	} // class wpsg_mod_core extends wpsg_mod_basic
+
+?>
Index: /system/old/wpsg_mod_productvariants.class.ppp
===================================================================
--- /system/old/wpsg_mod_productvariants.class.ppp	(revision 6438)
+++ /system/old/wpsg_mod_productvariants.class.ppp	(revision 6438)
@@ -0,0 +1,2379 @@
+<?php
+
+	/**
+	 * Modulklasse "Produktvarianten"
+	 * @author Daschmi (27.04.2016)
+	 */
+	class wpsg_mod_productvariants extends wpsg_mod_basic
+	{
+
+		var $lizenz = 1;
+		var $id = 99;
+
+		const TYPE_SELECT = 0;
+		const TYPE_RADIO = 1;
+		const TYPE_IMAGE = 2;
+
+		static $arTypeLabel;
+
+		/**
+		 * Constructor
+		 */
+		public function __construct()
+		{
+
+			parent::__construct();
+
+			self::$arTypeLabel = array(
+				self::TYPE_SELECT => __('Select Box', 'wpsg'),
+				self::TYPE_RADIO => __('Radio Boxen', 'wpsg'),
+				self::TYPE_IMAGE => __('Bilderauswahl', 'wpsg')
+			);
+
+			$this->name = __('Produktvarianten', 'wpsg');
+			$this->group = __('Produkte', 'wpsg');
+			$this->desc = __('ErmÃ¶glicht es zentral Varianten anzulegen und diese im Produkt zu aktivieren.', 'wpsg');
+
+			wpsg_define('WPSG_TBL_VARIANTS', $this->shop->prefix.'wpsg_variants');
+			wpsg_define('WPSG_TBL_VARIANTS_VARI', $this->shop->prefix.'wpsg_variants_vari');
+			wpsg_define('WPSG_TBL_PRODUCTS_VARIANT', $this->shop->prefix.'wpsg_products_variant');
+			wpsg_define('WPSG_TBL_PRODUCTS_VARIATION', $this->shop->prefix.'wpsg_products_variation');
+
+		} // public function __construct()
+
+		public function install()
+		{
+
+			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
+
+			$sql = "CREATE TABLE ".WPSG_TBL_VARIANTS." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				name varchar(255) NOT NULL,
+				product_id int(11) NOT NULL,
+				deleted int(1) NOT NULL,
+				pos int(11) NOT NULL,
+				type int(11) NOT NULL,
+				PRIMARY KEY  (id),
+				KEY product_id (product_id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+			$sql = "CREATE TABLE ".WPSG_TBL_VARIANTS_VARI." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				variant_id int(11) NOT NULL,
+				name varchar(255) NOT NULL,
+				shortname varchar(255) NOT NULL,
+				anr varchar(255) NOT NULL,
+				price double(10,2) NOT NULL,
+				stock int(11) NOT NULL,
+				images text NOT NULL,
+				deleted int(1) NOT NULL,
+				pos int(11) NOT NULL,
+				PRIMARY KEY  (id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS_VARIANT." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				variant_id int(11) NOT NULL,
+				product_id int(11) NOT NULL,
+				pos int(11) NOT NULL,
+				PRIMARY KEY  (id),
+				KEY product_id (product_id),
+				KEY variant_id (variant_id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS_VARIATION." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				variation_id int(11) NOT NULL,
+				product_id int(11) NOT NULL,
+				active int(1) NOT NULL,
+				anr varchar(255) NOT NULL,
+				price double(10,2) NOT NULL,
+				stock int(11) NOT NULL,
+				images text NOT NULL,
+				weight double(10,2) NOT NULL,
+				fmenge double(10,2) NOT NULL,
+				PRIMARY KEY  (id),
+				KEY product_id (product_id),
+				KEY variation_id (variation_id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+		} // public function install()
+
+		public function settings_edit()
+		{
+
+			$this->shop->view['wpsg_mod_productvariants']['html'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_html.phtml', false);
+
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/settings_edit.phtml');
+
+		} // public function settings_edit_afterform()
+
+		public function settings_save()
+		{
+
+			$this->shop->update_option('wpsg_mod_productvariants_price', $_REQUEST['wpsg_mod_productvariants_price']);
+			$this->shop->update_option('wpsg_vp_detailview', $_REQUEST['wpsg_vp_detailview']);
+
+		} // public function settings_save()
+
+		public function be_ajax()
+		{
+
+			$action = $_REQUEST['subaction'].'Action';
+
+			$this->$action();
+
+		} // public function be_ajax()
+
+		public function wpsg_enqueue_scripts()
+		{
+
+			if (!is_admin())
+			{
+
+				wp_enqueue_script('wpsg_mod_productvariants_js', $this->shop->getRessourceURL('mods/mod_productvariants/frontend.js'));
+				wp_localize_script('wpsg_mod_productvariants_js', 'wpsg_vp_showpic', array('wpsg_vp_showpic' => $this->shop->get_option('wpsg_vp_showpic')));
+
+			}
+
+		} // public function wpsg_enqueue_scripts()
+
+		public function product_addedit_content(&$product_content, &$product_data)
+		{
+
+			// Wenn eine Ãbersetzung bearbeitet wird, dann nichts machen
+			if (isset($_REQUEST['wpsg_lang'])) return;
+
+			if (wpsg_isSizedInt($product_data['id']))
+			{
+
+				$this->shop->view['wpsg_mod_productvariants']['html'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_html.phtml', false);
+
+			}
+
+			$product_content['wpsg_mod_productvariants'] = array(
+				'title' => __('Produktvarianten', 'wpsg'),
+				'content' => $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt_addedit_content.phtml', false)
+			);
+
+		} // public function product_addedit_content(&$product_content, &$produkt_data)
+
+		public function template_redirect()
+		{
+
+			if (wpsg_isSizedString($_REQUEST['action'], 'wpsg_productvariants_switch'))
+			{
+
+				if (wpsg_isSizedInt($_REQUEST['wpsg_post_id']))
+				{
+
+					global $post;
+					$post = get_post($_REQUEST['wpsg_post_id']);
+
+				}
+
+				// Produkt Key nach der Auswahl bilden
+				parse_str($_REQUEST['form_data'], $form_data);
+
+				$product_id = $this->shop->getProduktId($form_data['wpsg']['produkt_id']);
+                $product_key = '';
+
+                $this->getProductKeyFromRequest($product_key, $product_id, $form_data);
+                //$product_key = $_REQUEST['product_key'];
+
+				$product_data = $this->shop->loadProduktArray($product_id, array(
+					'id' => $product_key,
+					'product_key' => $product_key,
+					'menge' => $form_data['wpsg']['menge'],
+					'referer' => $form_data['myReferer']
+				));
+
+				// Damit das Div die gleiche Index Id bekommt
+				$GLOBALS['wpsg_produkt_index'] = $_REQUEST['product_index'] - 1;
+
+				$this->shop->noReleatedProducts = true;
+
+				if (wpsg_isSizedString($form_data['wpsg']['template'])) $template = $form_data['wpsg']['template'];
+				else $template = false;
+
+				if (wpsg_isSizedInt($form_data['titleDisplayed'])) $this->shop->titleDisplayed = 1;
+
+				die($this->shop->renderProdukt($product_data, $template));
+
+			}
+
+		} // public function template_redirect()
+
+		public function loadProduktArray(&$product_data)
+		{
+
+			//if ($GLOBALS['step'] > 4) return;
+
+			$product_data['arVariant'] = $this->getVariants($product_data['product_id'], true, true, true);
+			$this->unserializeVariant($product_data['arVariant']);
+
+			if (wpsg_isSizedArray($product_data['arVariant']))
+			{
+
+				// Default Kombination setzen
+                if (preg_match('/^pv_/', $product_data['id']))
+                {
+
+                    $product_data['product_key'] = $product_data['id'];
+
+                }
+				else if (!isset($product_data['product_key']) || is_numeric($product_data['product_key']))
+				{
+
+					$arDefaultKey = array();
+
+					foreach ($product_data['arVariant'] as $variant_id => $variant_data)
+					{
+
+						$arDefaultKeyValues = $variant_id.':'.array_keys($variant_data['arVariation'])[0];
+						$arDefaultKey[] = $arDefaultKeyValues;
+
+					}
+
+					$strDefaultKey = 'pv_'.$product_data['id'].'|'.implode('|', $arDefaultKey);
+
+					$product_data['product_key'] = $strDefaultKey;
+					$product_data['id'] = $strDefaultKey;
+
+				}
+
+				$arProductKey = $this->explodeProductKey($product_data['product_key']);
+
+				$arProductImagesPossible = array();
+				$arPostidsImagesPossible = array();
+				
+				// Gesetzte Variante wÃ€hlen und aufwerten
+				foreach ($product_data['arVariant'] as $var_id => $var_data)
+				{
+
+					foreach ($var_data['arVariation'] as $vari_id => $vari_data)
+					{
+
+						if ($arProductKey['arVari'][$var_id] == $vari_id)
+						{
+
+							$pics = unserialize($vari_data['images']);
+							unset($vari_data['pics']);
+							if (wpsg_isSizedArray($pics)) {
+								$pic = explode(',', $pics['pic']);
+								if (strlen($pic[0]) == 0) unset($pic[0]);
+								$postids = explode(',', $pics['postid']);
+								if (strlen($postids[0]) == 0) unset($postids[0]);
+								//$vari_data['images'] = array('pic' => array());
+								//$vari_data['images']['pic'] = $pic;
+								foreach ($pic as $k => &$file) {
+									$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+								}
+								$vari_data['pics'] = $pic;
+								$vari_data['postids'] = $postids;								
+							}
+
+							if (isset($vari_data['pics'])) {
+								if (wpsg_isSizedArray($arProductImagesPossible)) $arProductImagesPossible = array_intersect($arProductImagesPossible, $vari_data['pics']);
+								else if (wpsg_isSizedArray($vari_data['pics'])) $arProductImagesPossible = $vari_data['pics'];
+
+							}
+							if (isset($vari_data['postids'])) {
+								if (wpsg_isSizedArray($arPostidsImagesPossible)) $arPostidsImagesPossible = array_intersect($arPostidsImagesPossible, $vari_data['postids']);
+								else if (wpsg_isSizedArray($vari_data['postids'])) $arPostidsImagesPossible = $vari_data['postids'];
+								
+							}
+							
+							$product_data['arVariant'][$var_id]['arVariation'][$vari_id]['set'] = true;
+
+						}
+						else $product_data['arVariant'][$var_id]['arVariation'][$vari_id]['set'] = false;
+
+					}
+
+				}
+
+				if (wpsg_isSizedArray($arPostidsImagesPossible)) $product_data['image_postid'] = array_shift($arPostidsImagesPossible);
+				
+				if (wpsg_isSizedArray($arProductImagesPossible)) $product_data['image_show'] = array_shift($arProductImagesPossible);
+				if (wpsg_isSizedString($product_data['image_show']))
+					$product_data['image_show'] = sanitize_file_name($product_data['image_show']);
+					
+				// Preise fÃŒr die Varianten berechnen
+				if (!(isset($product_data['varPriceAdded']) && ($product_data['varPriceAdded'] = 1)))
+				{
+
+					$product_data['preis_netto_preVariants'] = $product_data['preis_netto'];
+					$product_data['preis_brutto_preVariants'] = $product_data['preis_brutto'];
+
+					if ($this->shop->getBackendTaxView() === WPSG_BRUTTO)
+					{
+
+						$product_data['preis_brutto'] = $this->calculateVariantsPrice($product_data['preis_brutto'], $product_data['arVariant'], $product_data['product_key']);
+						$product_data['preis_netto'] = wpsg_calculatePreis($product_data['preis_brutto'], WPSG_NETTO, $product_data['mwst_value']);
+
+					}
+					else
+					{
+
+						$product_data['preis_netto'] = $this->calculateVariantsPrice($product_data['preis_netto'], $product_data['arVariant'], $product_data['product_key']);
+						$product_data['preis_brutto'] = wpsg_calculatePreis($product_data['preis_netto'], WPSG_BRUTTO, $product_data['mwst_value']);
+
+					}
+
+					$product_data['preis_preVariants'] = $product_data['preis'];
+
+				}
+
+				// Preise fÃŒr das Frontend ermitteln
+				if ($this->shop->getFrontendTaxView() === WPSG_BRUTTO)
+				{
+
+					$product_data['preis'] = $product_data['preis_brutto'];
+
+				}
+				else
+				{
+
+					$product_data['preis'] = $product_data['preis_netto'];
+
+				}
+
+			}
+			if ($product_data['preis_brutto'] == 161.00) {
+
+				$product_data['preis'] = $product_data['preis_brutto'];
+			}
+
+		} // public function loadProduktArray(&$produkt_data)
+
+        public function getProductKeyFromRequest(&$product_key, $product_id, $form_data)
+        {
+
+            //if (!wpsg_isSizedArray($form_data['wpsg_mod_productvariants'])) return false;
+
+            //foreach ($form_data['wpsg_mod_productvariants'] as $var_id => $vari_id) $form_data['wpsg_mod_productvariants'][$var_id] = $var_id.':'.$vari_id;
+            //$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_mod_productvariants']);
+
+        	if (!wpsg_isSizedArray($form_data['wpsg_vp'])) return false;
+
+        	foreach ($form_data['wpsg_vp'] as $var_id => $vari_id) $form_data['wpsg_vp'][$var_id] = $var_id.':'.$vari_id;
+        	$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_vp']);
+
+        } // public function getProductKeyFromRequest($product_id, $form_data)
+
+        public function produkt_ajax()
+        {
+
+        	//error_reporting(E_ALL);
+
+        	if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'wpsg_vp_add')
+        	{
+        		die('wpsg_vp_add');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		$data = array(
+        				"name" => $_REQUEST['name'],
+        				"typ" => $_REQUEST['typ'],
+        				"aktiv" => "1"
+        		);
+
+        		if ($_REQUEST['typ'] == "checkbox")
+        		{
+        			$data['preis'] = "0";
+        		}
+        		else
+        		{
+        			$data['vari'] = array();
+        		}
+
+        		$vp_data[] = $data;
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		$this->shop->view['message'] = array(0, __("Variante erfolgreich angelegt.", "wpsg"));
+
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_var_reorder')
+        	{
+        		die('wpsg_var_reorder');
+        		parse_str($_REQUEST['wpsg_reorder'], $wpsg_reorder);
+
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$vp_data_neu = array();
+
+        		foreach ($wpsg_reorder['variante'] as $order)
+        		{
+
+        			if (array_key_exists($order, $vp_data))
+        			{
+
+        				$vp_data_neu[] = $vp_data[$order];
+        				unset($vp_data[$order]);
+
+        			}
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data_neu);
+
+        		$this->shop->view['message'] = array(0, __('Variantenreihenfolge gespeichert.', 'wpsg'));
+
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vari_reorder')
+        	{
+        		die('wpsg_vari_reorder');
+        		parse_str($_REQUEST['wpsg_reorder'], $wpsg_reorder);
+
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		foreach ($wpsg_reorder as $var_key => $order)
+        		{
+
+        			$var_id = preg_replace('/^variorder\_/', '', $var_key);
+
+        			wpsg_array_reorder($vp_data[$var_id]['vari'], $order);
+
+        			if (wpsg_isSizedArray($vp_data[$var_id]['lang']))
+        			{
+
+        				foreach ($vp_data[$var_id]['lang'] as $lang_key => $lang_vari)
+        				{
+
+        					wpsg_array_reorder($vp_data[$var_id]['lang'][$lang_key]['vari'], $order);
+
+        				}
+
+        			}
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		$this->shop->view['message'] = array(0, __("Variationenreihenfolge gespeichert.", "wpsg"));
+
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vp_refreh')
+        	{
+        		die('wpsg_vp_refreh');
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_del")
+        	{
+        		die('wpsg_vp_del');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		unset($vp_data[$_REQUEST['var_id']]);
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich gelÃ¶scht.", "wpsg"));
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_deaktiv")
+        	{
+        		die('wpsg_vp_deaktiv');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		if ($_REQUEST['status'] == "1")
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['aktiv'] = 1;
+        			$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich aktiviert.", "wpsg"));
+
+        		}
+        		else
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['aktiv'] = 0;
+        			$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich deaktiviert.", "wpsg"));
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_addVariation")
+        	{
+        		die('wpsg_vp_addVariation');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		$vp_data[$_REQUEST['var_id']]['vari'][] = array(
+        				"name" => $_REQUEST['vari_name'],
+        				"preis" => wpsg_tf($_REQUEST['vari_preis']),
+        				"aktiv" => "1"
+        		);
+
+        		$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich angelegt.", "wpsg"));
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_vari_del")
+        	{
+        		die('wpsg_vp_vari_del');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		unset($vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]);
+
+        		if (wpsg_isSizedArray($vp_data[$_REQUEST['var_id']]['lang']))
+        		{
+
+        			foreach ($vp_data[$_REQUEST['var_id']]['lang'] as $lang_key => $lang_vari)
+        			{
+
+        				unset($vp_data[$_REQUEST['var_id']]['lang'][$lang_key]['vari'][$_REQUEST['vari_id']]);
+
+        			}
+
+        		}
+
+        		$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich gelÃ¶scht.", "wpsg"));
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_vari_deaktiv")
+        	{
+        		die('wpsg_vp_vari_deaktiv');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		if ($_REQUEST['status'] == "1")
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['aktiv'] = 1;
+        			$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich aktiviert.", "wpsg"));
+
+        		}
+        		else
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['aktiv'] = 0;
+        			$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich deaktiviert.", "wpsg"));
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_var_setImageOrder')
+        	{
+
+        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
+        		$this->unserializeVariant($vp_data);
+
+        		if ($_REQUEST['vari_id'] == -1)
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['picOrder'] = $_REQUEST['wpsg_reorder'];
+
+        		}
+        		else
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['picOrder'] = $_REQUEST['wpsg_reorder'];
+
+        		}
+
+        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
+
+        		die("1");
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_setPic')
+        	{
+        		//die('wpsg_vp_vari_setPic');
+        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
+        		$this->unserializeVariant($vp_data);
+
+        		if ($_REQUEST['vari_id'] >= 0)
+        		{
+
+        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic']);
+        			$arPostid = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid']);
+
+        			$pic = $_REQUEST['pic'];
+        			$postid = $_REQUEST['post_id'];
+
+        			$pic = preg_replace('/\-(\d+)x(\d+)\./', '.', $pic);
+
+        			if (in_array($pic, $arPic))
+        			{
+        				unset($arPic[array_search($pic, $arPic)]);
+        				unset($arPostid[array_search($postid, $arPostid)]);
+        			}
+        			else
+        			{
+        				$arPic[] = $pic;
+        				$arPostid[] = $postid;
+        			}
+
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic'] = implode(",", $arPic);
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid'] = implode(",", $arPostid);
+
+        		}
+        		else
+        		{
+
+        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['pic']);
+
+        			if (in_array($_REQUEST['pic'], $arPic))
+        			{
+        				unset($arPic[array_search($_REQUEST['pic'], $arPic)]);
+        			}
+        			else
+        			{
+        				$arPic[] = $_REQUEST['pic'];
+        			}
+
+        			$vp_data[$_REQUEST['var_id']]['pic'] = implode(",", $arPic);
+
+        		}
+
+        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
+
+        		die("1");
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_inlineEdit')
+        	{
+        		die('wpsg_vp_vari_inlineEdit');
+
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$product_data = $this->shop->cache->loadProduct($_REQUEST['edit_id']);
+
+        		if ($_REQUEST['typ'] == "vari_name")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['vari'][$_REQUEST['vari_id']]['name'] = wpsg_q($_REQUEST['value']);
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['name'] = wpsg_q($_REQUEST['value']);
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_artnr")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['vari'][$_REQUEST['vari_id']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_preis")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['preis'] = $_REQUEST['value'];
+        			$_REQUEST['value'] = wpsg_ff($_REQUEST['value'], $this->shop->get_option('wpsg_currency'));
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_fmenge")
+        		{
+
+        			$arFeinheiten = explode(',', $this->shop->get_option('wpsg_mod_fuellmenge_einheit'));
+
+        			$_REQUEST['value'] = wpsg_ff(wpsg_tf($_REQUEST['value']), $arFeinheiten[$product_data['feinheit']]);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['fmenge'] = wpsg_tf($_REQUEST['value']);
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_weight")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['weight'] = $_REQUEST['value'];
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_stock")
+        		{
+
+        			$_REQUEST['value'] = intval($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['stock'] = $_REQUEST['value'];
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_name")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['name'] = $_REQUEST['value'];
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['name'] = $_REQUEST['value'];
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_preis")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['preis'] = $_REQUEST['value'];
+        			$_REQUEST['value'] = wpsg_ff($_REQUEST['value'], $this->shop->get_option('wpsg_currency'));
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_weight")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['weight'] = $_REQUEST['value'];
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_fmenge")
+        		{
+
+        			$arFeinheiten = explode(',', $this->shop->get_option('wpsg_mod_fuellmenge_einheit'));
+
+        			$_REQUEST['value'] = wpsg_ff(wpsg_tf($_REQUEST['value']), $arFeinheiten[$product_data['feinheit']]);
+        			$vp_data[$_REQUEST['var_id']]['fmenge'] = wpsg_tf($_REQUEST['value']);
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_artnr")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_stock")
+        		{
+
+        			$_REQUEST['value'] = intval($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['stock'] = $_REQUEST['value'];
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		die(strval($_REQUEST['value']));
+
+        	}
+
+        } // public function produkt_ajax()
+
+		/**
+		 * Darf das Produkt gekauft werden?
+		 */
+		public function canOrder($product_key)
+		{
+
+			$product_id = $this->shop->getProduktID($product_key);
+
+			if ($this->isVariantsProduct($product_id))
+			{
+
+				$nActive = 0;
+
+				$variants = $this->getVariants($product_id);
+
+				foreach ($variants as $var_id => $var_info)
+				{
+
+					$nActive += $var_info['count_active'];
+
+				}
+
+				if ($nActive <= 0) return -2;
+
+			}
+
+		}
+
+		/* Modulfunktionen */
+
+		/**
+		 * Gibt den Bestand fÃŒr eine Variation zurÃŒck
+		 * @var $product_key String
+		 * Beispiel: pv_1|1:1
+		 *
+		 * Wird vom Lagerbestandsmodul aufgerufen, sollte NUR mit einem VariantenschlÃŒssel aufgerufen werden
+		 */
+		public function getStockForVariation($product_key)
+		{
+
+			$arVariInfo = $this->explodeProductKey($product_key);
+			$oProduct = wpsg_product::getInstance($arVariInfo['product_id']);
+
+			if (!wpsg_isSizedArray($arVariInfo['arVari'])) return $oProduct->stock;
+			else
+			{
+
+				$nStock = 0;
+				$variConf = $this->getVariants($arVariInfo['product_id'], true, true, true);
+
+				foreach ($arVariInfo['arVari'] as $var_id => $vari_id)
+				{
+
+					$nStock += $variConf[$var_id]['arVariation'][$vari_id]['stock'];
+
+				}
+
+				return $nStock;
+
+			}
+
+		} // public function getStockForVariation($product_key)
+
+        /**
+         * Speichert die Varianten
+         */
+        public function saveVarianten($produkt_id, $vp_data)
+        {
+
+        	$vp_data = $this->clearArrayForSerialization($vp_data);
+
+        	$temp = wpsg_q(serialize($vp_data));
+        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+        		"images" => wpsg_q(serialize($vp_data))
+        	), "`id` = '".wpsg_q($_REQUEST['vari_id'])."'");
+
+        } // public function saveVarianten($produkt_id, $vp_data)
+
+        /**
+         * Speichert die Variationen
+         */
+        public function saveVariation($produkt_id, $vp_data)
+        {
+
+        	$vp_data = $this->clearArrayForSerialization($vp_data);
+
+        	$temp = wpsg_q(serialize($vp_data));
+        	$vdata['pic'] = '';
+        	if (isset($vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic']))
+        		$vdata['pic'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic'];
+        	$vdata['picOrder'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['picOrder'];
+        	$vdata['postid'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['postid'];
+
+        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+        			"images" => wpsg_q(serialize($vdata))
+        	), "`variation_id` = '".wpsg_q($_REQUEST['vari_id'])."'");
+
+        } // public function saveVariation($produkt_id, $vp_data)
+
+        /**
+         * LÃ€dt die Varianteninformationen aus dem serialisierten Array
+         * @param $noTrans Wird diese Variable auf true gesetzt, so wird die Ãbersetzung nicht geladen (Wie Backend) Wichtig wenn die Varianten wieder gespeichert werden sollen!
+         */
+        public function loadVarianten($produkt_id, $noTrans = false, $noCache = false)
+        {
+
+        	if (is_admin()) $noCache = true;
+
+        	if (!$noCache && array_key_exists($produkt_id.$noTrans, wpsg_getArray($this->cache_variData))) return $this->cache_variData[$produkt_id.$noTrans];
+
+        	// Ãbersetzung verarbeiten
+        	if (is_admin() || $noTrans === true)
+        	{
+
+        		//$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($produkt_id)."'"));
+        		$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($_REQUEST['vari_id'])."'"));
+        		if (!is_array($vp_data)) $vp_data = array();
+
+        	}
+        	else
+        	{
+
+        		// Im Frontend geht es nach der Sprache auf der der Shop aktuell lÃ€uft
+        		if ($this->shop->isOtherLang())
+        		{
+
+        			$parent_lang_id = $this->db->fetchOne("SELECT `lang_parent` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($produkt_id)."'");
+        			if (!wpsg_isSizedInt($parent_lang_id)) $parent_lang_id = $produkt_id;
+
+        			$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($parent_lang_id)."'"));
+        			if (!is_array($vp_data)) $vp_data = array();
+
+        			foreach ($vp_data as $k => $v)
+        			{
+
+        				// Den Namen der Variante auf die aktuelle Sprache stellen
+        				if (wpsg_isSizedString($vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['name'])) $vp_data[$k]['name'] = $vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['name'];
+
+        				if (wpsg_isSizedArray($vp_data[$k]['vari']))
+        				{
+
+        					foreach ($vp_data[$k]['vari'] as $k2 => $vari)
+        					{
+
+        						// Den Namen der Variation auf die aktuelle Sprache korrigieren
+        						if (wpsg_isSizedString($vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['vari'][$k2]['name'])) $vp_data[$k]['vari'][$k2]['name'] = $vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['vari'][$k2]['name'];
+
+        					}
+
+        				}
+
+        			}
+
+        		}
+        		else
+        		{
+
+        			if (isset($_REQUEST['vari_id']))
+					{
+
+        				$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($_REQUEST['vari_id'])."'"));
+        				if (!is_array($vp_data)) $vp_data = array();
+
+        			}
+        			else
+        			{
+
+        				$strQuery =
+        				"SELECT PVV.`id`, PVV.`variation_id`, PVV.`product_id`, PVV.`anr`, PVV.`price`, PVV.`stock`, PVV.`images`, PVV.`weight`, PVV.`fmenge`, PVV.`active`,
+        				 VV.`variant_id`, VV.`name` AS VVname, VV.`shortname`, PV.`pos` AS PVpos, VV.`pos` AS VVpos,
+        				 V.`name` AS Vname, V.`type`
+        				 FROM ".WPSG_TBL_VARIANTS." AS V, ".WPSG_TBL_VARIANTS_VARI." AS VV,
+        				 ".WPSG_TBL_PRODUCTS_VARIATION." AS PVV, ".WPSG_TBL_PRODUCTS_VARIANT." AS PV
+        				 WHERE V.`id` = VV.`variant_id` AND VV.`id` = PVV.`variation_id` AND PV.`variant_id` = VV.`variant_id` AND
+        				 PVV.`product_id` = '".wpsg_q($produkt_id)."' AND VV.`deleted` != 1 AND V.`deleted` != 1
+        				 ORDER BY PV.`pos`, VV.`pos`";
+
+        				//$vp_data = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id` = '".wpsg_q($produkt_id)."'");
+        				$vp_data = $this->db->fetchAssoc($strQuery);
+        				if (!is_array($vp_data)) $vp_data = array();
+        				$this->unserializeVariation($vp_data);
+
+        			}
+
+        		}
+
+        	}
+
+        	$this->cache_variData[$produkt_id.$noTrans] = $vp_data;
+
+        	return $vp_data;
+
+        } // public function loadVarianten($produkt_id)
+
+        private function clearArrayForSerialization($ar)
+        {
+
+        	foreach ((array)$ar as $k => $v)
+        	{
+
+        		if (wpsg_isSizedArray($v))
+        		{
+
+        			$ar[$k] = $this->clearArrayForSerialization($v);
+
+        		}
+        		else
+        		{
+
+        			$ar[$k] = preg_replace('/\'|\`|\ÂŽ|\"/', '', $v);
+
+        		}
+
+        	}
+
+        	return $ar;
+
+        } // private function clearArrayForSerialization($ar)
+
+        /**
+         * Gibt die Bilder als Array fÃŒr die Variation zurÃŒck
+         * Beachtet die Reihenfolge die im Backend ÃŒber Drag&Drop definiert ist
+         * @param int $var_id Key der Variante
+         * @param int $vari_id Key der Variation
+         */
+        public function getVariImages($product_id, $var_id, $vari_id)
+        {
+
+        	$_REQUEST['var_id'] = $var_id;
+        	$_REQUEST['vari_id'] = $vari_id;
+
+        	//$vp_data = $this->loadVarianten($product_id);
+        	$vp_data = $this->getVariants($product_id, true, true, true);
+        	$this->unserializeVariant($vp_data);
+
+        	$arProductBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
+
+        	$arReturn = array();
+
+        	if (!isset($vp_data[$var_id])) return $arProductBilder;
+        	//if (!wpsg_isSizedArray($vp_data[$var_id]['vari'][$vari_id]['picOrder']) && !wpsg_isSizedArray($vp_data[$var_id]['picOrder'])) return $arProductBilder;
+        	if (!wpsg_isSizedArray($vp_data[$var_id]['arVariation'][$vari_id]['picOrder'])) return $arProductBilder;
+
+        	// Sortierung
+        	// Bilder in Reihenfolge von picOrder
+        	if (isset($vp_data[$var_id]['typ']) && ($vp_data[$var_id]['typ'] == 'checkbox') && wpsg_isSizedArray($vp_data[$var_id]['picOrder'])) $arReturn = $vp_data[$var_id]['picOrder'];
+        	else if (wpsg_isSizedArray($vp_data[$var_id]['arVariation'][$vari_id]['picOrder'])) $arReturn = $vp_data[$var_id]['arVariation'][$vari_id]['picOrder'];
+
+        	/*
+        	// PrÃŒfen ob die Bilder noch in Produktbilder Array drin sind
+        	foreach ($arReturn as $k => $v)
+        	{
+
+        		if (!in_array($v, $arProductBilder)) unset($arReturn[$k]);
+        		else unset($arProductBilder[array_search($v, $arProductBilder)]);
+
+        	}
+        	*/
+
+        	$arProductBilderSort = Array();
+        	foreach ($arProductBilder as $v) {
+        		$k = array_search($v['basenameori'], $arReturn);
+        		if ($k !== false)
+        			$arProductBilderSort[$k] = $v;
+
+        	}
+        	ksort($arProductBilderSort);
+
+        	// Bilder aus dem ProduktArray noch hinzufÃŒgen, die eventuell nicht im sortierten Array enthalten sind
+        	foreach ($arProductBilder as $k => $v)
+        	{
+
+        		//$arReturn[] = $v['basenameori'];
+        		$k = array_search($v['basenameori'], $arReturn);
+        		if ($k === false)
+        			$arProductBilderSort[] = $v;
+
+        	}
+        	//$arReturn = array_unique($arReturn);
+
+        	$arImageSelect = array();
+
+        	// Sind die Bilder in der Variante ausgewÃ€hlt?
+        	if (!is_admin())
+        	{
+
+        		//if ($vp_data[$var_id]['typ'] == 'checkbox' && wpsg_isSizedString($vp_data[$var_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['pic']);
+        		if ($vp_data[$var_id]['type'] == '3' && wpsg_isSizedString($vp_data[$var_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['pic']);
+        		else if (wpsg_isSizedString($vp_data[$var_id]['arVariation'][$vari_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['arVariation'][$vari_id]['pic']);
+
+        		foreach ($arReturn as $k => $v)
+        		{
+
+        			if (!in_array($v, $arImageSelect)) unset($arReturn[$k]);
+
+        		}
+
+        	}
+
+        	//return $arReturn;
+        	return $arProductBilderSort;
+
+        } // public function getVariImages($product_id, $var_id, $vari_id)
+
+        /**
+         * Gibt den Namen der Variante zurÃŒck
+         */
+        public function getVariantenName($vp_data, $var_id)
+        {
+
+        	$name = $vp_data[$var_id]['name'];
+
+        	if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        	{
+        		if ($vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['name'] != "")
+        		{
+        			$name = $vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['name'];
+        		}
+        	}
+
+        	return ((trim($name) == "")?"----":$name);
+
+        } // public function getVariantenName($vp_data, $v_id)
+
+        /**
+         * Gibt den Namen der Variation zurÃŒck
+         */
+        public function getVariName($vp_data, $var_id, $vari_id)
+        {
+
+        	$name = $vp_data[$var_id]['arVariation'][$vari_id]['name'];
+
+        	if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        	{
+        		if ($vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['arVariation'][$vari_id]['name'] != "")
+        		{
+        			$name = $vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['arVariation'][$vari_id]['name'];
+        		}
+        	}
+
+        	return ((trim($name) == "")?"----":$name);
+
+        } // public function getVariName($vp_data, $var_id, $vari_id)
+
+		/**
+		 * PrÃŒft ob das Produkt ein Variantenprodukt ist oder nicht
+		 */
+		public function isVariantsProduct($product_id)
+		{
+
+			$strQuery = "
+					SELECT
+						COUNT(*)
+					FROM
+						`".WPSG_TBL_VARIANTS_VARI."` AS VI
+							LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+					WHERE
+						PVI.`product_id` = '".wpsg_q($product_id)."' AND
+						PVI.`active` = '1' AND
+						VI.`deleted` != '1'
+			";
+
+			$nActiveVariants = $this->db->fetchOne($strQuery);
+
+			if ($nActiveVariants > 0) return true; else return false;
+
+		} // public function isVariantsProduct($product_id)
+
+		/**
+		 * Integration in das Produkttemplate
+		 */
+		public function productTemplate($product_data)
+		{
+
+			die("Veraltet");
+
+			if (!wpsg_isSizedArray($product_data['arVariant'])) return;
+
+			$this->shop->view['wpsg_mod_productvariants']['product_id'] = $product_data['product_id'];
+			$this->shop->view['wpsg_mod_productvariants']['arVariants'] = $product_data['arVariant'];
+			$this->shop->view['wpsg_mod_productvariants']['product_variants'] = $this->explodeProductKey($product_data['product_key'])['arVari'];
+
+			$this->shop->render(WPSG_PATH_VIEW.'mods/mod_productvariants/productTemplate.phtml');
+
+		} // public function productTemplate($product_key)
+
+		/**
+		 * Ãbernimmt die Auswahl der Variante im Produkttemplate
+		 */
+		public function renderTemplate($product_key)
+		{
+
+			$produkt_id = $this->shop->getProduktId($product_key);
+			$produkt_data = $this->shop->cache->loadProduct($produkt_id);
+			$tax_value = $this->shop->getCalcTaxValue($produkt_data['mwst_key']);
+
+			if ($this->shop->isOtherLang())
+			{
+
+				$produkt_trans_id = $this->db->fetchOne("SELECT `id` FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($produkt_id)."' AND `lang_locale` = '".wpsg_q($this->shop->getCurrentLanguageCode())."'");
+
+				if (wpsg_isSizedInt($produkt_trans_id)) $produkt_id = $produkt_trans_id;
+
+			}
+
+			//public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false)
+			$vp_data = $this->getVariants($produkt_id, true, true, true);
+			$this->unserializeVariant($vp_data);
+
+			if ($this->isVariantsProductKey($product_key)) {
+				$arVar = $this->explodeProductKey($product_key);
+				foreach ($arVar['arVari'] as $v => $vv) {
+					$vp_data[$v]['arVariation'][$vv]['sel'] = 1;
+
+				}
+
+			}
+
+			if (is_array($vp_data) && sizeof($vp_data) > 0)
+			{
+
+				$arpb = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array(&$produkt_id));
+
+				//$this->shop->view['data']['vp_data'] = $vp_data;
+				$this->shop->view['wpsg_mod_productvariants']['set'] = $this->getSetVariArray($product_key);
+
+				// Rabattpreise vorkalkulieren
+				//$this->shop->callMod('wpsg_mod_discount', 'addDiscountToVari', array(&$produkt_id, &$this->shop->view['data']['vp_data']));
+
+				$arPossibleImages = array();
+
+				// Bilddaten ergÃ€nzen
+				foreach ($vp_data as $k1 => &$v1) {
+					foreach ($v1['arVariation'] as $k2 => &$v2) {
+						$arpic = explode(',', $v2['pic']);
+						$v2['showpic'] = '';
+						if (wpsg_isSizedArray($v2['picOrder'])) {
+							// Bilder umsortiert, Reihenfolge checken
+							$k = 5000;
+							foreach ($arpic as $ap)
+								foreach ($v2['picOrder'] as $kp => $vp) {
+									if ($ap == $vp)
+										if ($kp < $k) $k = $kp;
+
+								}
+							$v2['showpic'] = $v2['picOrder'][$k];
+						}
+						else
+						{
+							$max = sizeof($arpic);
+							if (isset($arpic[$max - 1]))
+								$v2['showpic'] = $arpic[$max - 1];		// 1 wegen Komma am Anfang
+						}
+						$found = -1;
+						$v2['guid'] = '';
+						$v2['post_id'] = 0;
+						foreach ($arpb as $k3 => $v3) {
+							if ($v2['showpic'] === $v3['basenameori']) $found = $k3;
+						}
+						if ($found != -1) {
+							$v2['guid'] = $arpb[$found]['guid'];
+							$v2['post_id'] = $arpb[$found]['post_id'];
+						}
+
+					}
+				}
+
+				unset($v1);
+				unset($v2);
+
+				$this->shop->view['data']['vp_data'] = $vp_data;
+
+				foreach ($this->shop->view['data']['vp_data'] as $k => $v)
+				{
+
+					if ($v['typ'] == "checkbox")	// 0 = checkbox
+					{
+
+						if (get_option("wpsg_vp_showpic") == "1" && wpsg_isSizedString($v['pic']))
+						{
+
+							//$this->shop->view['data']['vp_data'][$k]['showpic'] = $this->getImageSelectImage($produkt_id, $k, $k2, $product_key);
+
+						}
+
+						// Preis an Ausgabe im Frontend anpassen
+						//if ($this->shop->getFrontendTaxview() == WPSG_NETTO && $this->shop->getBackendTaxview() == WPSG_BRUTTO) $this->shop->view['data']['vp_data'][$k]['preis'] = wpsg_calculatePreis($v['preis'], WPSG_NETTO, $tax_value);
+						//else if ($this->shop->getFrontendTaxview() == WPSG_BRUTTO && $this->shop->getBackendTaxview() == WPSG_NETTO) $this->shop->view['data']['vp_data'][$k]['preis'] = wpsg_calculatePreis($v['preis'], WPSG_BRUTTO, $tax_value);
+
+					}
+					else
+					{
+
+						foreach ($v['arVariation'] as $k2 => $v2)
+						{
+
+							if (get_option("wpsg_vp_showpic") == "1" && wpsg_isSizedString($v2['pic']))
+							{
+
+								//$this->shop->view['data']['vp_data'][$k]['vari'][$k2]['showpic'] = $this->getImageSelectImage($produkt_id, $k, $k2, $product_key);
+
+							}
+
+							// Preis an Ausgabe im Frontend anpassen
+							if ($this->shop->getFrontendTaxview() == WPSG_NETTO && $this->shop->getBackendTaxview() == WPSG_BRUTTO) $this->shop->view['data']['vp_data'][$k]['arVariation'][$k2]['price'] = wpsg_calculatePreis($v2['price'], WPSG_NETTO, $tax_value);
+							else if ($this->shop->getFrontendTaxview() == WPSG_BRUTTO && $this->shop->getBackendTaxview() == WPSG_NETTO) $this->shop->view['data']['vp_data'][$k]['arVariation'][$k2]['price'] = wpsg_calculatePreis($v2['price'], WPSG_BRUTTO, $tax_value);
+
+						}
+
+					}
+
+				}
+
+				return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt.phtml', false);
+
+			}
+
+		} // public function renderTemplate($produkt_id)
+
+		/**
+		 * Gibt ein Array mit Informationen aus dem VariantenschlÃŒssel zurÃŒck
+		 * Besp: pv_1|1:1
+		 * Array
+			(
+    			[product_id] => 1
+    			[arVari] => Array
+		 		(
+            		[1] => 1
+        		)
+
+			)
+		 * Anhand des ProduktschlÃŒssels z.B. pv|4:6|1:8|6:11|5:10
+		 */
+		public function explodeProductKey($product_key)
+		{
+
+			if (is_numeric($product_key)) return array(
+				'product_id' => $product_key,
+				'arVari' => array()
+			);
+
+			$arKey = explode('|', $product_key);
+			$arReturn = array();
+
+			for ($i = 1; $i < sizeof($arKey); $i ++)
+			{
+
+				$arKeyValue = explode(':', $arKey[$i]);
+				$arReturn[$arKeyValue[0]] = $arKeyValue[1];
+
+			}
+
+			return array(
+				'product_id' => substr($arKey[0], 3),
+				'arVari' => $arReturn
+			);
+
+		} // public function explodeProductKey($product_key)
+
+		/**
+		 * Gibt true zurÃŒck, wenn der Preis im Produkttemplate angezeigt werden soll
+		 * Andersrum programmiert, da die Default Einstellung anzeigen ist????
+		 */
+		public function showVariPrice($vari_price)
+		{
+
+			switch ($this->shop->get_option('wpsg_mod_productvariants_price'))
+			{
+
+				case '1': // nur wenn grÃ¶Ãer 0
+
+					if ($vari_price <= 0) return false;
+
+					break;
+
+				case '0': // nie anzeigen
+
+					return false;
+
+					break;
+
+			}
+
+			return true;
+
+		} // public function showVariPrice($vari_price)
+
+		private function calculateVariantsPrice($price, $arVariant, $product_key)
+		{
+
+			$arProductVariant = $this->explodeProductKey($product_key)['arVari'];
+
+			foreach ($arProductVariant as $variant_id => $variation_id)
+			{
+
+				$price += $arVariant[$variant_id]['arVariation'][$variation_id]['price'];
+
+			}
+
+			return $price;
+		}
+
+		private function admin_showAction()
+		{
+
+			$this->shop->view['product_id'] = $_REQUEST['product_id'];
+			$this->shop->view['arVariants'] = $this->getVariants($_REQUEST['product_id'], true);
+
+			die($this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_show.phtml'));
+
+		} // private function showAction()
+
+		private function admin_addAction()
+		{
+
+			$this->db->ImportQuery(WPSG_TBL_VARIANTS, array(
+				'name' => wpsg_q(__('', 'wpsg')),
+				'product_id' => wpsg_q($_REQUEST['product_id']),
+				'deleted' => '0',
+				'pos' => '5000'
+			));
+
+			$this->admin_showAction();
+
+		} // private function admin_addAction()
+
+		private function admin_editAction()
+		{
+
+			$this->shop->view['product_id'] = wpsg_getStr($_REQUEST['product_id'], '0');
+			$this->shop->view['variant'] = $this->getVariant($_REQUEST['variant_id']);
+			$this->shop->view['arVariation'] = $this->getVariationOfVariant($_REQUEST['variant_id'], $_REQUEST['product_id']);
+
+			die($this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_edit.phtml'));
+
+		} // private function admin_editAction()
+
+		private function admin_variation_addAction()
+		{
+
+			$variation_id = $this->db->ImportQuery(WPSG_TBL_VARIANTS_VARI, array(
+				'variant_id' => wpsg_q($_REQUEST['variant_id']),
+				'name' => __('', 'wpsg'),
+				'deleted' => '0'
+			));
+
+			if (wpsg_isSizedInt($_REQUEST['product_id']))
+			{
+
+				$this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+					'variation_id' => wpsg_q($variation_id),
+					'product_id' => wpsg_q($_REQUEST['product_id'])
+				));
+
+			}
+
+			$this->admin_editAction();
+
+		} // private function admin_variation_addAction()
+
+		private function admin_delAction()
+		{
+
+			$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array(
+				'deleted' => '1'
+			), " `id` = '".wpsg_q($_REQUEST['variant_id'])."' ");
+
+			$this->admin_showAction();
+
+		} // private function admin_delAction()
+
+		private function admin_variation_delAction()
+		{
+
+			$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array(
+				'deleted' => '1'
+			), " `id` = '".wpsg_q($_REQUEST['variation_id'])."' ");
+
+			$this->admin_editAction();
+
+		} // private function admin_variation_delAction()
+
+		private function setProductVariant($product_id, $variant_id, $field, $value)
+		{
+
+			if (!wpsg_isSizedInt($product_id) || !wpsg_isSizedInt($variant_id)) die("Systemfehler");
+
+			$id_exist = $this->db->fetchOne("
+				SELECT
+					`id`
+				FROM
+					`".WPSG_TBL_PRODUCTS_VARIANT."`
+				WHERE
+					`variant_id` = '".wpsg_q($variant_id)."' AND
+					`product_id` = '".wpsg_q($product_id)."'
+			");
+
+			$data = array(
+				$field => wpsg_q($value),
+				'product_id' => wpsg_q($product_id),
+				'variant_id' => wpsg_q($variant_id)
+			);
+
+			if (wpsg_isSizedInt($id_exist)) $this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIANT, $data, " `id` = '".wpsg_q($id_exist)."' ");
+			else $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIANT, $data);
+
+		} // private function setProductVariant($product_id, $variant_id, $field, $value)
+
+		private function setProductVariation($product_id, $variation_id, $field, $value)
+		{
+
+			if (!wpsg_isSizedInt($product_id) || !wpsg_isSizedInt($variation_id)) die("Systemfehler");
+
+			$id_exist = $this->db->fetchOne("
+				SELECT
+					`id`
+				FROM
+					`".WPSG_TBL_PRODUCTS_VARIATION."`
+				WHERE
+					`variation_id` = '".wpsg_q($variation_id)."' AND
+					`product_id` = '".wpsg_q($product_id)."'
+			");
+
+			$data = array(
+				$field => wpsg_q($value),
+				'product_id' => wpsg_q($product_id),
+				'variation_id' => wpsg_q($variation_id)
+			);
+
+			if (wpsg_isSizedInt($id_exist)) $this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, $data, " `id` = '".wpsg_q($id_exist)."' ");
+			else $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $data);
+
+			if (($field == 'stock') || ($field == 'active'))
+			{
+				$this->setStockFromVariation($product_id);
+			}
+
+		} // private function setProductVariation($product_id, $field, $value)
+
+		private function setStockFromVariation($product_id)
+		{
+
+			if ($this->isVariantsProductKey($product_id)) {
+				$arr = $this->explodeProductKey($product_id);
+				$product_id = $arr['product_id'];
+			}
+
+			$sql = "SELECT SUM(PVI.`stock`) AS SU FROM `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI
+						LEFT JOIN `".WPSG_TBL_VARIANTS_VARI."` AS VVI ON PVI.`variation_id`= VVI.`id`
+						WHERE PVI.`product_id`='".wpsg_q($product_id)."' AND VVI.`deleted`!='1' AND PVI.`active`='1'
+				";
+			$stock = $this->db->fetchOne($sql);
+
+			$data = array('stock' => wpsg_q($stock));
+
+			$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, $data, " `id` = '".wpsg_q($product_id)."' ");
+
+			//getProductKeyFromRequest(&$product_key, $product_id, $form_data)
+			//$stock = $this->shop->callMod('wpsg_mod_productvariants', 'getStockForVariation', array());
+
+		}	// private function setStockFromVariation($product_id)
+
+		private function admin_inlineEditAction()
+		{
+
+			if (wpsg_isSizedString($_REQUEST['field'], 'name'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('name' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'type'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('type' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+				die(self::$arTypeLabel[$_REQUEST['value']]);
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'pos'))
+			{
+
+				$i = 0; foreach ($_REQUEST['value'] as $var)
+				{
+
+					$var_id = substr($var, 4);
+
+					if (wpsg_isSizedInt($_REQUEST['product_id'])) $this->setProductVariant($_REQUEST['product_id'], $var_id, 'pos', $i);
+					else $this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('pos' => wpsg_q($i)), " `id` = '".wpsg_q($var_id)."' ");
+
+					$i ++;
+
+				}
+
+				die('1');
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_name'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('name' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_shortname'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('shortname' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_pos'))
+			{
+
+				$i = 0; foreach ($_REQUEST['value'] as $vari)
+				{
+
+					$vari_id = substr($vari, 5);
+
+					$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('pos' => wpsg_q($i)), " `id` = '".wpsg_q($vari_id)."' ");
+
+					$i ++;
+
+				}
+
+				die('1');
+
+			}
+			else if (preg_match('/vari_(.*)/', $_REQUEST['field']))
+			{
+				$value = $_REQUEST['value'];
+				$f = $_REQUEST['field'];
+				if (($f == 'vari_price') || ($f == 'vari_stock') || ($f == 'vari_weight')) {
+					$value =  wpsg_tf($value);
+				}
+				$this->setProductVariation($_REQUEST['product_id'], $_REQUEST['field_id'], substr($_REQUEST['field'], 5), $value);
+
+			}
+
+			// TODO: Ãbersetzung
+
+			die($_REQUEST['value']);
+
+		} // private function admin_inlineEditAction()
+
+		/**
+		 * Gibt die MÃ¶glichken Bilder einer Variantenkombination zurÃŒck
+		 */
+		public function getKombiVariImages($var_key, $var_id = false)
+		{
+
+			if (!$this->shop->hasMod('wpsg_mod_produktbilder')) return false;
+
+			$arVarSelected = $this->getSetVariArray($var_key);
+			$product_id = $this->shop->getProduktID($var_key);
+			//$arVari = $this->loadVarianten($product_id);
+			$arVari = $this->getVariants($product_id, true, true, true);
+			$this->unserializeVariant($arVari);
+
+			$arTemp = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
+
+			if (!$this->isVariantsProductKey($var_key)) return $arTemp;
+
+			$arBilder = array();
+			foreach ($arTemp as $bild) {
+				$arBilder[] = $bild['basenameori'];
+			}
+
+			/*
+			// Schauen ob ein Bild nach dem Dateinamen dabei ist
+			foreach ($arBilder as $bild)
+			{
+				$image = false;
+				$filename = preg_replace("/\.([^\.]*)/", "", $bild);
+				if ($filename == "vp_".str_replace(":", "-", $var_key)) $image = $bild;
+
+				if ($image !== false) return array($image);
+			}
+			*/
+			foreach ($arVari as $var_key => $var)
+			{
+				if (array_key_exists($var_key, $arVarSelected))
+				{
+					if ($var_id === $var_key) continue;
+					if ($var['typ'] == "checkbox")
+					{
+						if ($arVarSelected[$var_key] == "1")
+						{
+							$arBilder = array_intersect($arBilder, explode(",", $var['pic']));
+						}
+						else
+						{
+							$arBilder = array_diff($arBilder, explode(",", $var['pic']));
+						}
+					}
+					else
+					{
+						$pics = wpsg_getStr($var['arVariation'][$arVarSelected[$var_key]]['pic']);
+						$arBilder = array_intersect($arBilder, explode(",", wpsg_getStr($var['arVariation'][$arVarSelected[$var_key]]['pic'])));
+					}
+				}
+			}
+			//$arBilder = $this->checkPics($arBilder, $product_id);
+
+			if (wpsg_isSizedArray($arBilder))
+			{
+				$arBilder = array_values($arBilder);
+				foreach ($arTemp as $k => $bild) {
+					if ($arBilder[0] != $bild['basenameori']) unset($arTemp[$k]);
+				}
+				//return $arBilder;
+				$arTemp = array_values($arTemp);
+				return $arTemp;
+			}
+			else
+			{
+				return array();
+			}
+		}
+
+		/**
+		 * Gibt einen Array zurÃŒck, bei denen die SchlÃŒssel die Varianten sind und die Werte die gewÃ€hlten Variationen
+		 */
+		private function getSetVariArray($product_key)
+		{
+
+			if (!$this->isVariantsProductKey($product_key)) return array();
+
+			$arVariSet = explode('|', preg_replace('/^pv_\d*\//', '', $product_key));
+			$arReturn = array();
+			unset($arVariSet[0]);
+
+			foreach ($arVariSet as $var_combi)
+			{
+
+				$var_combi = explode(':', $var_combi);
+				$var = $var_combi[0];
+				$vari = $var_combi[1];
+
+				$arReturn[$var] = $vari;
+
+			}
+
+			return $arReturn;
+
+		}	// private function getSetVariArray($product_key)
+
+		/**
+		 * Gibt die Variationen einer Variante zurÃŒck
+		 * @param Integer $variant_id ID der Variante
+		 */
+		public function getVariationOfVariant($variant_id, $product_id = false, $arProductFilter = array())
+		{
+
+			$strQuerySELECT = "";
+			$strQueryJOIN = "";
+			$strQueryWHERE = "";
+			$strQueryHAVING = "";
+
+			if (wpsg_isSizedArray($arProductFilter))
+			{
+
+				//return array($strQuerySELECT, $strQueryWHERE, $strQueryJOIN, $strQueryHAVING, $strQueryORDER);
+				//list($strQueryP_WHERE, $strQueryP_JOIN, $strQueryP_HAVING, $strQueryP_ORDER) = wpsg_product::getQueryParts($arProductFilter);
+
+				list($strQueryP_SELECT, $strQueryP_WHERE, $strQueryP_JOIN, $strQueryP_HAVING, $strQueryP_ORDER) = wpsg_product::getQueryParts($arProductFilter);
+
+				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id`) ";
+				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (P.`id` = PV.`product_id`) ";
+
+				$strQuerySELECT .= $strQueryP_SELECT;
+				$strQueryJOIN .= $strQueryP_JOIN;
+				$strQueryWHERE .= $strQueryP_WHERE;
+				$strQueryHAVING .= $strQueryP_HAVING;
+
+			}
+			else if (wpsg_isSizedInt($product_id))
+			{
+
+				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
+				$strQuerySELECT .= " , PV.`id` AS iid, PV.`variation_id`, PV.`active`, PV.`anr`, PV.`price`, PV.`stock`, PV.`images`, PV.`weight`, PV.`fmenge` ";
+
+			}
+
+			$strQuery = "
+				SELECT
+					VI.`id`, VI.`name`, VI.`shortname`, VI.`deleted`, VI.`pos`
+					".$strQuerySELECT."
+				FROM
+					`".WPSG_TBL_VARIANTS_VARI."` AS VI
+						".$strQueryJOIN."
+				WHERE
+					VI.`variant_id` = '".wpsg_q($variant_id)."' AND
+					VI.`deleted` != '1'
+					".$strQueryWHERE."
+				GROUP BY
+					VI.`id`
+				HAVING
+					1
+					".$strQueryHAVING."
+				ORDER BY
+					VI.`pos`
+			";
+
+			$arVari = $this->db->fetchAssoc($strQuery);
+			$this->unserializeVariation($arVari);
+
+			// TODO: Ãbersetzung
+
+			return $arVari;
+
+		} // public function getVariationOfVariant($variant_id)
+
+		private function unserializeVariation(&$arVari) {
+			foreach ($arVari as &$vi) {
+				$ar = @unserialize($vi['images']);
+				$vi['pic'] = '';
+				$vi['sel'] = 0;
+				$vi['picOrder'] = Array();
+				if (wpsg_isSizedArray($ar)) {
+					foreach($ar as $k => $v) {
+						$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
+						$vi[$k] = $v;
+					}
+				}
+			}
+		}	// private function unserializeVariation(&$arVari)
+
+		private function unserializeVariant(&$arVar) {
+			foreach ($arVar as &$va) {
+				if ($va['type'] == 0) $va['typ'] = 'select';
+				if ($va['type'] == 1) $va['typ'] = 'radio';
+				if ($va['type'] == 2) $va['typ'] = 'image';
+
+				foreach ($va['arVariation'] as &$vi) {
+					$ar = @unserialize($vi['images']);
+					$vi['pic'] = '';
+					$vi['sel'] = 0;
+					$vi['picOrder'] = Array();
+					if (wpsg_isSizedArray($ar)) {
+						foreach($ar as $k => $v) {
+							$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
+							$vi[$k] = $v;
+						}
+					}
+				}
+			}
+		}	// private function unserializeVariant(&$arVar)
+
+		public function stockVarianten($product_id)
+		{
+
+			$this->shop->view['product_id'] = wpsg_getStr($product_id, '0');
+			//$this->shop->view['variant'] = $this->getVariant($_REQUEST['variant_id']);
+			//$this->shop->view['arVariation'] = $this->getVariationOfVariant($_REQUEST['variant_id'], $_REQUEST['product_id']);
+			//$this->shop->view['arVariant']
+			$vp_data = $this->getVariants($product_id, true, true, true);
+			$this->unserializeVariant($vp_data);
+
+			$html = '<table>';
+			foreach ($vp_data as $var) {
+				$html .= '<tr>';
+				$html .= '<td class="col_shortname" colspan="3">'.wpsg_hspc($var['name']).'</td>';
+				$html .= '</tr>';
+			    foreach ($var['arVariation'] as $vari) {
+			    	$html .= '<tr>';
+			    	$html .= '<td class="col_active">&nbsp;';
+			    	$html .= '</td>';
+			    	$txt = wpsg_hspc($vari['name']).' : '.wpsg_hspc($vari['stock']);
+			    	$html .= '<td class="col_shortname">'.$txt.'</td>';
+			    	$html .= '<td class="col_1">';
+			    	$html .= '</td>';
+			    	$html .= '</tr>';
+				}
+			}
+			$html .= '</table>';
+			die($html);
+
+		} // private function stockVarianten($product_id)
+
+		/**
+		 * Reduziert den Bestand der Variationen in dem Array
+		 */
+		public function reduceStock($produkt_key, $menge, $reduce = true)
+		{
+
+			//$produkt_id = preg_replace('/(^pv_)|(\|(.*)$)/', '', $produkt_key);
+			//$vari_teil = preg_replace('/(.*)\//', '', $produkt_key);
+			//$arVarianten = explode('|', $vari_teil);
+			$arVar = $this->explodeProductKey($produkt_key);
+
+			//$vari_data = $this->loadVarianten($produkt_id, true, true);
+
+			// Tabellen sperren
+			if ($this->shop->get_option('wpsg_lockOrderTables') != '1')
+			{
+
+				$arLockTables[WPSG_TBL_PRODUCTS_VARIATION] = "WRITE";
+				$strQuery = "LOCK TABLES ";
+				foreach ($arLockTables as $table_name => $locktype) $strQuery .= " `".$table_name."` ".$locktype.",";
+				$this->db->Query(substr($strQuery, 0, -1));
+			}
+
+			foreach ($arVar['arVari'] as $v => $vv)
+			{
+
+				if ($reduce === true)
+				{
+
+					//$vari_data[$variante_id]['vari'][$vari_id]['stock'] -= $menge;
+					$this->db->Query("
+							UPDATE ".WPSG_TBL_PRODUCTS_VARIATION." SET `stock` = `stock` - ".wpsg_q($menge)." WHERE `id` = '".wpsg_q($vv)."'
+						");
+
+				}
+				else
+				{
+
+					//$vari_data[$variante_id]['vari'][$vari_id]['stock'] += $menge;
+					$this->db->Query("
+							UPDATE ".WPSG_TBL_PRODUCTS_VARIATION." SET `stock` = `stock` + ".wpsg_q($menge)." WHERE `id` = '".wpsg_q($vv)."'
+						");
+
+				}
+
+			}
+
+			$this->db->unlockTables();
+
+			$this->setStockFromVariation($produkt_key);
+
+			// Array zurÃŒckspeichern
+			//$this->saveVarianten($produkt_id, $vari_data);
+
+		} // public function reduceStock($produkt_id, $menge)
+
+		/**
+		 * Gibt true zurÃŒck, wenn der ÃŒbergebene Produktkey ein Varianten Produktkey ist. Sonst false.
+		 * @param \String $productkey
+		 */
+		public function isVariantsProductKey($productkey)
+		{
+
+			if (preg_match('/^pv_\d+/', $productkey))
+			{
+
+				return true;
+
+			}
+			else
+			{
+
+				return false;
+
+			}
+
+		} // public function isVariantsProductKey($productkey)
+
+		/**
+		 * Gibt eine einzelne Variante zurÃŒck
+		 * @param unknown $variant_id
+		 */
+		public function getVariant($variant_id, $bHideDeleted = true)
+		{
+
+			$strQueryWHERE = "";
+
+			if ($bHideDeleted === true) $strQueryWHERE .= " AND V.`deleted` != '1' ";
+
+			$strQuery = "
+				SELECT
+					V.*
+				FROM
+					`".WPSG_TBL_VARIANTS."` AS V
+				WHERE
+					V.`id` = '".wpsg_q($variant_id)."'
+					".$strQueryWHERE."
+			";
+
+			$arVariant = $this->db->fetchRow($strQuery);
+
+			if (!wpsg_isSizedInt($arVariant['id'])) return false;
+
+			// TODO: Ãbersetzung
+
+			return $arVariant;
+
+		} // public function getVariant($variant_id)
+
+		public function getVariation($variation_id)
+		{
+
+			$arVariation = $this->db->fetchRow("
+				SELECT
+					VI.*
+				FROM
+					`".WPSG_TBL_VARIANTS_VARI."` AS VI
+				WHERE
+					VI.`id` = '".wpsg_q($variant_id)."'
+			");
+
+			$arVariation['images'] = wpsg_trim(explode(',', $arVariation['images']));
+
+			// TODO: Ãbersetzung
+
+			return $arVariation;
+
+		} // public function getVariation($variation_id)
+
+		/**
+		 * Gibt einen Array der Produktvarianten zurÃŒck
+		 * @param Integer|Boolean $product_id Produkt ID
+		 * @param Boolean $global Globale Varianten?
+		 */
+		public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false, $serVariationen = false)
+		{
+
+			$strQuerySELECT = "";
+			$strQueryORDER = "";
+			$strQueryJOIN = "";
+			$strProductQuery = " AND ( 0 ";
+
+			if (wpsg_isSizedInt($product_id))
+			{
+
+				$strProductQuery .= " OR V.`product_id` = '".wpsg_q($product_id)."' ";
+
+				$strQueryWHERE = "";
+
+				// Wenn Lagerbestand aktiv, dann nur Veriationen mit Lagerbestand zÃ€hlen
+				// Im Backend zÃ€hle ich auch ausverkaufte Variationen mit, sonst steht in der Ãbersicht 0/2 auch wenn bei einem der Haken gesetzt ist
+				if ($this->shop->hasMod('wpsg_mod_stock') && !is_admin()) $strQueryWHERE .= " AND PVI.`stock` > 0 ";
+
+				$strQuerySELECT .= ", (
+					SELECT
+						COUNT(*)
+					FROM
+						`".WPSG_TBL_VARIANTS_VARI."` AS VI
+							LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+					WHERE
+						PVI.`product_id` = '".wpsg_q($product_id)."' AND
+						PVI.`active` = '1' AND
+						VI.`variant_id` = V.`id` AND
+						VI.`deleted` != '1'
+						".$strQueryWHERE."
+				) AS `count_active` ";
+
+				$strQueryJOIN = " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIANT."` AS PV ON (PV.`variant_id` = V.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
+
+				$strQueryORDER .= " PV.`pos` ASC, ";
+
+			}
+			else
+			{
+
+				$strQuerySELECT .= ", '0' AS `count_active` ";
+
+			}
+
+			if ($global === true)
+			{
+
+				$strProductQuery .= " OR V.`product_id` = '0' ";
+
+			}
+
+			$strProductQuery .= " ) ";
+
+			$arData = $this->db->fetchAssoc("
+				SELECT
+					V.*,
+					(SELECT COUNT(*) FROM `".WPSG_TBL_VARIANTS_VARI."` AS VI WHERE VI.`variant_id` = V.`id` AND VI.`deleted` != '1') AS `count_variation`,
+					(
+						SELECT
+							COUNT(DISTINCT `product_id`)
+						FROM
+							`".WPSG_TBL_VARIANTS_VARI."` AS VI
+								LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+								LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (PVI.`product_id` = P.`id`)
+						WHERE
+							VI.`variant_id` = V.`id` AND
+							PVI.`active` = '1' AND
+							P.`id` > 0 AND
+							P.`deleted` != '1'
+					) AS `count_produkte`
+					".$strQuerySELECT."
+				FROM
+					`".WPSG_TBL_VARIANTS."` AS V
+						".$strQueryJOIN."
+				WHERE
+					V.`deleted` != '1'
+					".$strProductQuery."
+				GROUP BY
+					V.`id`
+				ORDER BY
+					".$strQueryORDER."
+					V.`product_id` ASC, V.`pos`
+			", "id");
+
+			foreach ($arData as $k => $v)
+			{
+
+				if ($onlyActive === true && !wpsg_isSizedInt($v['count_active'])) unset($arData[$k]);
+				else
+				{
+
+					$arData[$k]['type_label'] = self::$arTypeLabel[$arData[$k]['type']];
+
+					if ($loadVariationen === true && wpsg_isSizedInt($product_id))
+					{
+
+						$arData[$k]['arVariation'] = $this->db->fetchAssoc("
+							SELECT
+								PVI.*,
+								VI.`name`
+							FROM
+								`".WPSG_TBL_VARIANTS_VARI."` AS VI
+									LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+							WHERE
+								VI.`deleted` != '1' AND
+								VI.`variant_id` = '".wpsg_q($v['id'])."' AND
+								PVI.`product_id` = '".wpsg_q($product_id)."' AND
+								PVI.`active` = '1'
+							ORDER BY
+								VI.`pos` ASC
+						", "variation_id");
+
+						// Bilder deserialisieren
+						foreach ($arData[$k]['arVariation'] as $vari_id => $vari_data)
+						{
+
+							if ($serVariationen == true) {
+								$arData[$k]['arVariation'][$vari_id]['images'] = @unserialize($vari_data['images']);
+								if (wpsg_isSizedString($arData[$k]['arVariation'][$vari_id]['images'])) $arData[$k]['arVariation'][$vari_id]['images'] = wpsg_trim(explode(',', $arData[$k]['arVariation'][$vari_id]['images']));
+								else $arData[$k]['arVariation'][$vari_id]['images'] = array();
+
+							}
+
+						}
+
+					}
+				}
+
+			}
+
+			// TODO: Ãbersetzung
+
+			return $arData;
+
+		}
+
+		public function basket_preInsertDefekt()
+		{
+
+			if (is_array($_REQUEST['wpsg_vp']) && sizeof($_REQUEST['wpsg_vp']) > 0)
+			{
+
+				$var_key = 'pv_'.$_REQUEST['wpsg']['produkt_id'].'|';
+
+				foreach ($_REQUEST['wpsg_vp'] as $var => $var_value)
+				{
+
+					$var_key .= $var.":".$var_value."|";
+
+				}
+
+				$var_key = substr($var_key, 0, -1);
+
+				$_REQUEST['wpsg']['produkt_id'] = $var_key;
+
+			}
+
+		} // public function basket_preInsert()
+
+		public function basket_row(&$p, $i)
+		{
+
+			if (!preg_match('/pv_(.*)/', $p['id'])) return;
+
+			$this->shop->view['variante'] = $this->getVariantenInfoArray($p['id']);
+
+			$this->shop->view['i'] = $i;
+
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/basket_row.phtml');
+
+		} // public function basket_row(&$p)
+
+		public function overview_row(&$p, $i)
+		{
+
+			if (!preg_match('/pv_(.*)/', $p['id'])) return;
+
+			$this->shop->view['variante'] = $this->getVariantenInfoArray($p['id']);
+
+			$this->shop->view['i'] = $i;
+
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/overview_row.phtml');
+
+		} // public function basket_row(&$p)
+
+		/**
+		 * Liest die Informationen anhand eines VariantenschlÃŒssels aus
+		 */
+		public function getVariantenInfoArray($vari_key)
+		{
+
+			//$produkt_id = preg_replace('/(vp_)|(\/(.*))/', '', $vari_key);
+			$produkt_id = preg_replace('/(pv_)|(\|(.*))/', '', $vari_key);
+			//$arVari = explode('|', preg_replace('/vp_'.$produkt_id.'\//', '', $vari_key));
+			$arVari = explode('|', preg_replace('/pv_'.$produkt_id.'\|/', '', $vari_key));
+
+			//$vp_data = $this->loadVarianten($produkt_id);
+			$vp_data = $this->getVariants($produkt_id, true, true, true);
+			$this->unserializeVariant($vp_data);
+
+			$arKey = array();
+			$arAKey = array();
+			$arPics = array();
+
+			$arReturn = array();
+
+			// kein Produkt-Key dann keine Weiterarbeit nÃ¶tig
+			if (is_numeric($vari_key)) {
+				$arReturn['key'] = '';
+				$arReturn['akey'] = '';
+				$arReturn['pics'] = array();
+				return $arReturn;
+
+			}
+
+			if ($this->shop->hasMod('wpsg_mod_fuellmenge')) $arReturn['fmenge'] = 0;
+			if ($this->shop->hasMod('wpsg_mod_weight')) $arReturn['weight'] = 0;
+
+			foreach ($arVari as $var_key)
+			{
+
+				$var_id = preg_replace('/\:(.*)/', '', $var_key);
+				$var_value = preg_replace('/(.*)\:/', '', $var_key);
+
+				if ($vp_data[$var_id]['typ'] == 'checkbox')
+				{
+
+					$arPicsVariante = array();
+
+					if (isset($vp_data[$var_id]['pic']))
+					{
+
+						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['pic']));
+
+					}
+
+					if ($var_value == '1')
+					{
+
+						$r = array(
+								'name' => $vp_data[$var_id]['name'],
+								'preis' => $vp_data[$var_id]['price'],
+								'artnr'	=> $vp_data[$var_id]['arVariation'][2]['anr'],
+								'pics' => $arPicsVariante
+						);
+
+						if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['weight']))
+						{
+
+							$r['weight'] = $vp_data[$var_id]['weight'];
+							$arReturn['weight'] += $r['weight'];
+
+						}
+
+						if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['fmenge']))
+						{
+
+							$r['fmenge'] = $vp_data[$var_id]['fmenge'];
+							$arReturn['fmenge'] += $r['fmenge'];
+
+						}
+
+						$arReturn[] = $r;
+
+						$arKey[] = $vp_data[$var_id]['name'];
+
+						$arPics = array_intersect($arPics, $arPicsVariante);
+
+					}
+					else
+					{
+
+						// Checkbox ist nicht markiert
+						//$arPics = array_unique(array_merge($arPics, $arPicsVariante));
+
+					}
+
+				}
+				else
+				{
+
+					$arPicsVariante = array();
+
+					if (isset($vp_data[$var_id]['arVariation'][$var_value]['pic']))
+					{
+
+						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['arVariation'][$var_value]['pic']));
+						$arPics = array_unique(array_merge($arPics, $arPicsVariante));
+
+					}
+
+					$r = array(
+							'name' 	=> $vp_data[$var_id]['name'],
+							'value' => $vp_data[$var_id]['arVariation'][$var_value]['name'],
+							'preis'	=> $vp_data[$var_id]['arVariation'][$var_value]['price'],
+							'artnr'	=> @$vp_data[$var_id]['arVariation'][$var_value]['artnr'],
+							'pics' => $arPicsVariante
+					);
+
+					if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['weight']))
+					{
+
+						$r['weight'] = $vp_data[$var_id]['arVariation'][$var_value]['weight'];
+						$arReturn['weight'] += $r['weight'];
+
+					}
+
+					if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['fmenge']))
+					{
+
+						$r['fmenge'] = $vp_data[$var_id]['arVariation'][$var_value]['fmenge'];
+						$arReturn['fmenge'] += $r['fmenge'];
+
+					}
+
+					$arReturn[] = $r;
+
+					$arKey[] = $vp_data[$var_id]['arVariation'][$var_value]['name'];
+					$arAKey[] = @$vp_data[$var_id]['arVariation'][$var_value]['anr'];
+
+				}
+
+			}
+
+			$arReturn['key'] = implode(' / ', $arKey);
+			$arReturn['akey'] = implode(' / ', $arAKey);
+			$arReturn['pics'] = array_unique($arPics);
+
+			return $arReturn;
+
+		} // public function getVariantenInfoArray($vari_key)
+
+		/**
+		 * Wird nach dem speichern des Produktes aus der saveAction des 
+		 * Produktcontrollers aufgerufen
+		 * 
+		*/
+		public function produkt_save(&$produkt_id) {
+			
+			$varis = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id`='".wpsg_q($produkt_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[] = sanitize_file_name($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'])."'");
+				
+			}
+		}	// public function produkt_save(&$produkt_id)
+		
+
+	} // class wpsg_mod_productvariants extends wpsg_mod_basic
+
+?>
Index: /system/old/wpsg_mod_produktbilder.class
===================================================================
--- /system/old/wpsg_mod_produktbilder.class	(revision 6438)
+++ /system/old/wpsg_mod_produktbilder.class	(revision 6438)
@@ -0,0 +1,920 @@
+
+				
+		public function produkt_ajax() 
+		{
+			global $wpdb;
+			 
+			else if ($_REQUEST['cmd'] == 'upload_mt')
+			{
+				
+				// Mediathek				
+				$fname = $_FILES['userfile']['name'][0];
+
+				$filetype = wp_check_filetype( basename( $fname ), null );
+				$wp_upload_dir = wp_upload_dir();
+				$attachment = array(
+					'guid' => wpsg_q($wp_upload_dir['url'] . '/' . basename($fname)),
+					'post_mime_type' => wpsg_q($filetype['type']),
+					'post_title' => wpsg_q(preg_replace('/\.[^.]+$/', '', basename($fname))),
+					'post_excerpt' => wpsg_q($fname),
+					'post_parent' => '0',
+					'wpsg_produkt_id' => '6',
+					'post_status' => 'inherit'
+				);
+				
+				$_FILES = $this->diverse_array($_FILES['userfile']);
+				$attachment_id = media_handle_upload( '0', 0, $attachment );	//OK
+				
+				// Feld wpsg_produkt_id setzen mit $_REQUEST['edit_id']
+				//$this->db->UpdateQuery($wpdb->prefix."posts", array(
+				//	"wpsg_produkt_id" => $_REQUEST['edit_id']), "`ID` = '".wpsg_q($attachment_id)."'");
+				add_post_meta( $attachment_id, 'wpsg_produkt_id', $_REQUEST['edit_id'] );
+				
+				
+				// Tests
+				$p1 = wp_get_attachment_url($attachment_id);	// http://shop4.home/wp-content/uploads/2017/03/hdrechteckig.png
+				$p2 = get_attached_file( $attachment_id ); 		// C:\xampp\htdocs\wp2/wp-content/uploads/2017/03/hdrechteckig.png
+				$p3 = get_attachment_link( $attachment_id );	// http://shop4.home/hdrechteckig/
+				$p4 = get_the_title( $attachment_id );			// hdrechteckig
+				$p5 = get_post_type($attachment_id);			// attachment
+				$p6 = get_post($attachment_id);					// WP_Post
+				$p7 = wp_get_attachment_image_src($attachment_id, 'thumbnail');	// Array mit Full-URL, Width, Height
+				
+				add_image_size('s_40_40', 40, 40);
+				$ht = wp_get_attachment_image( $attachment_id, Array(40, 40));
+				$p8 = wp_get_attachment_image_src($attachment_id, Array(40, 40));
+				$p80 = $p8[0];
+				
+				//$rw = add_post_meta( $attachment_id, 'wpsg_produkt_id', '6' );
+				//$rw = add_post_meta( $attachment_id, 'wpsg_produkt_id', '5' );
+				//$rw = add_post_meta( $attachment_id, 'wpsg_produkt_id', '4' );
+				//$rw = get_post_meta( $attachment_id, 'wpsg_produkt_id' );
+				
+				unset($_FILES[0]);
+				$i = 1;
+				foreach ($_FILES as $key => $val) {
+					// File hochladen und Feld wpsg_produkt_id setzen
+					$fname = $val['name'];
+					$filetype = wp_check_filetype( basename( $fname ), null );
+					$attachment['post_mime_type'] = $filetype['type'];
+					$attachment['guid'] = $wp_upload_dir['url'] . '/' . basename( $fname );
+					$attachment['post_title'] = preg_replace( '/\.[^.]+$/', '', basename( $fname ) );
+					$attachment['post_excerpt'] = wpsg_q($fname);
+					$attachment_id = media_handle_upload( $i, 92, $attachment );
+					//$this->db->UpdateQuery($wpdb->prefix."posts", array(
+					//		"wpsg_produkt_id" => $_REQUEST['edit_id']), "`ID` = '".wpsg_q($attachment_id)."'");
+					add_post_meta( $attachment_id, 'wpsg_produkt_id', $_REQUEST['edit_id'] );
+					$i++;
+				}
+				
+				die("1");
+				//die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
+				
+			}
+			else if ($_REQUEST['cmd'] == 'removemt')
+			{
+			
+				//unlink($this->getPicPath($_REQUEST['edit_id']).'/'.$_REQUEST['file']);
+				if ($_REQUEST['delmt'] === 'true') {	// Auch in der Mediathek lÃ¶schen
+					wp_delete_post( $_REQUEST['pid'], true );
+				}
+				
+				// Zuordnung lÃ¶schen
+				delete_post_meta( $_REQUEST['pid'], 'wpsg_produkt_id', $_REQUEST['edit_id'] );
+				
+				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
+			
+				if ($this->shop->hasMod('wpsg_mod_produktartikel')) $this->shop->callMod('wpsg_mod_produktartikel', 'updatePostThumbnail', array($_REQUEST['edit_id']));
+			
+				die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
+			
+			}
+			
+			else if ($_REQUEST['cmd'] == 'produktbilder_liste_MT')
+			{
+			
+				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
+				//$content = $this->getProduktBilderListe($_REQUEST['edit_id']);
+				die($this->getProduktBilderListe_MT($_REQUEST['edit_id']));
+				
+			}
+			else if ($_REQUEST['cmd'] == 'wpsg_setImageOrder')
+			{
+				$reo = $_REQUEST['wpsg_reorder'];
+				$pid = $_REQUEST['edit_id'];
+				
+				$file = '';
+				$line = '';
+				$b = headers_sent($file, $line);
+				$a = headers_list();
+				
+				$sreo = '';
+				foreach ($reo as $v) {
+					$st = explode('_', $v);
+					$sreo .= $st[1].',';
+				}
+				
+				$sreo = substr($sreo, 0, strlen($sreo) - 1);
+				
+				$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array("postids" => wpsg_q($sreo)), "`id` = '".wpsg_q($pid)."'");
+				
+				flush();
+				die('1');
+				
+			}
+			
+		} // public function produkt_ajax()
+		
+		public function diverse_array($vector) 
+		{
+			
+			$result = array();
+			
+			foreach($vector as $key1 => $value1)
+			{
+				
+				foreach($value1 as $key2 => $value2)
+				{
+					
+					$result[$key2][$key1] = $value2;
+					
+				}
+				
+			}
+			
+			return $result;
+			
+		}
+		
+		
+		public function produkt_save(&$produkt_id) 
+		{ 
+		 
+			
+		} // public function produkt_save(&$produkt_id)
+		
+		public function produkt_del($product_id)
+		{
+			
+			$path_bilder = $this->getPicPath($product_id);
+			wpsg_rrmdir($path_bilder);
+			
+		} // public function produkt_del(&$product_id)
+		 
+		public function product_addedit_content(&$product_content, &$product_data)
+		{
+			
+			// Wenn eine Ãbersetzung bearbeitet wird, dann nichts machen
+			if (isset($_REQUEST['wpsg_lang'])) return;
+			 										
+			if (wpsg_isSizedInt($product_data['id']))
+			{
+			
+				$this->shop->view['modul'] = &$this;
+				$this->shop->view['ProduktBilderPath'] = $this->getPicPath($product_data['id']);
+				$this->shop->view['ProduktBilderURL'] = $this->getPicPath($product_data['id'], true);
+				$this->shop->view['ProduktList'] = $this->getProduktBilderListe($product_data['id']);
+			
+				$this->shop->view['ProduktList_MT'] = $this->getProduktBilderListe_MT($product_data['id']);
+				
+			}
+			
+			$product_content['wpsg_mod_productbilder'] = array(
+				'title' => __('Produktbilder', 'wpsg'),
+				'content' => $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_addedit_content.phtml', false)
+			);
+			
+		} // public function product_addedit_content(&$product_content, &$produkt_data)
+		
+		public function produkt_edit_content(&$produkt_data) 
+		{ 
+			
+			if (isset($_REQUEST['wpsg_lang'])) return;
+			
+			$this->shop->view['data'] = $produkt_data;
+			
+			if ($produkt_data['id'] > 0)
+			{
+
+				$this->shop->view['modul'] = &$this;
+				$this->shop->view['ProduktBilderPath'] = $this->getPicPath($produkt_data['id']);
+				$this->shop->view['ProduktBilderURL'] = $this->getPicPath($produkt_data['id'], true);
+				$this->shop->view['ProduktList'] = $this->getProduktBilderListe($produkt_data['id']);
+				
+			}
+			
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_content.phtml');	
+			
+		} // public function produkt_edit_content(&$produkt_data)
+		
+		public function produkt_createTranslation(&$produkt_id, &$trans_id)
+		{
+			
+		 	$path_src = $this->getPicPath($produkt_id);
+		 	$path_trg = $this->getPicPath($trans_id);
+		 	
+		 	wpsg_copy($path_src, $path_trg);
+			
+		} // public function produkt_createTranslation(&$produkt_id, &$trans_id)
+		
+		public function produkt_copy(&$produkt_id, &$copy_id) { 
+			
+			// Wie bei der Erstellung einer neuen Ãbersetzung ...
+			$this->produkt_createTranslation($produkt_id, $copy_id);
+			
+		} // public function produkt_copy(&$produkt_id, &$copy_id)
+		
+		public function checkGeneralBackendError()
+		{
+			
+						
+		} // public function checkGeneralBackendError()
+		
+		/* Modulfunktionen */
+
+		/**
+		 * Mediatheksfunktion
+		 * FÃŒgt ein neues Bild zu einem Produkt hinzu
+		 * 
+		 * @param String $file Absoluter Pfad zu dem Bild
+		 * @param $product_id ID des Produktes zu dem das Bild zugeordnet werden soll
+		 */
+		public function addImageToProduct($file, $product_id)
+		{
+			
+			// Siehe
+			// https://codex.wordpress.org/Function_Reference/wp_insert_attachment
+			
+			$wp_upload_dir = wp_upload_dir();
+			
+			$mt_filetype = wp_check_filetype(basename($file), null);
+			$mt_filename = $wp_upload_dir['path'].'/'.basename($file);
+			
+			copy($file, $mt_filename);
+			
+			$attachment = array(
+				'guid' => wpsg_q($wp_upload_dir['url'].'/'.basename($file)),
+				'post_mime_type' => wpsg_q($mt_filetype['type']),
+				'post_title' => wpsg_q(preg_replace('/\.[^.]+$/', '', basename($file))),
+				'post_excerpt' => wpsg_q(basename($file)),
+				'post_status' => 'inherit'
+			);
+			
+			$attachment_id = wp_insert_attachment($attachment, $mt_filename, '0');
+			
+			require_once(ABSPATH.'wp-admin/includes/image.php');
+			
+			$attach_data = wp_generate_attachment_metadata($attachment_id, $mt_filename);
+			wp_update_attachment_metadata($attachment_id, $attach_data);
+			
+			add_post_meta($attachment_id, 'wpsg_produkt_id', $product_id);
+						
+		} // public function addImageToProduct($file, $product_id)
+		
+		/**
+		 * Wird vom Template produkt_edit_content.phtml aufgerufen und per Ajax aktualisiert.
+		 * Zeichnet die Liste mit den Produktbildern
+		 */
+		public function getProduktBilderListe($produkt_id)
+		{
+			
+			$this->shop->view['modul'] = &$this;
+			$this->shop->view['ProduktBilderPath'] = $this->getPicPath($produkt_id);
+			$this->shop->view['ProduktBilderURL'] = $this->getPicPath($produkt_id, true);
+			$this->shop->view['ProduktBilder'] = $this->getProduktBilder($produkt_id);
+			
+			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_list.phtml', false);
+			
+		} // public function getProduktBilderListe($produkt_id)
+		
+		/**
+		 * Wird vom Template produkt_edit_content.phtml aufgerufen und per Ajax aktualisiert.
+		 * Zeichnet die Liste mit den Produktbildern
+		 */
+		public function getProduktBilderListe_MT($produkt_id, $size = 'thumbnail')
+		{
+			global $wpdb;
+			
+			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key`='".wpsg_q('wpsg_produkt_id')."' AND `meta_value`='".wpsg_q($produkt_id)."' ORDER BY `post_id`");
+			//$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."posts` WHERE `wpsg_produkt_id` = '".wpsg_q($produkt_id)."' ");
+			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($produkt_id));
+			$arPostids = explode(',', $postids);
+			
+			$wp_upload_dir = wp_upload_dir();
+			$url = $wp_upload_dir['url'];
+			$i = 0;
+			
+			if (wpsg_isSizedString($postids)) {
+				foreach ($arPostids as $postid) {
+					
+					for ($i = 0; $i < count($data); $i++) {
+						if ($data[$i]['post_id'] == $postid) {
+							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
+							$guid = $p[0];
+							$arrf = pathinfo($guid);
+							$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $data[$i]['post_id'];
+							$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+							$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
+							
+							$file = $arrf['basename'];
+							$pos1 = strrpos($file, '-');
+							if ($pos1 !== false) {
+								$pos2 = strrpos($file, '.');
+								//$file = substr_replace($file, '', $pos1, $pos2 - $pos1);
+							}
+							$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+							$this->shop->view['ProduktBilder_MT'][$i]['basenameori']= $file;
+							
+						}
+					}
+				}
+				
+			} else {
+				foreach ($data as $key => $val) {
+					/*
+					$p1 = wp_get_attachment_url($val['ID']);
+					$arrf = pathinfo($p1);
+					$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+					$guid = $arrf['dirname'].'/'.$arrf['filename'].'-150x150.'.$arrf['extension'];
+					*/
+					$p = wp_get_attachment_image_src($val['post_id'], $size);	// Array mit Full-Path, Width, Height
+					$guid = $p[0];
+					$arrf = pathinfo($guid);
+					$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $val['post_id'];
+					$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+					$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
+					$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $arrf['basename']);
+					$this->shop->view['ProduktBilder_MT'][$i]['basenameori']= $file;
+					$i++;
+				}
+			}
+			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_list_MT.phtml', false);
+				
+		} // public function getProduktBilderListe_MT($produkt_id)
+		
+		/**
+		 * Gibt die verfÃŒgbaren MÃ¶glichkeiten fÃŒr den Bildzuschnitt zurÃŒck
+		 */
+		public function getImageModes()
+		{
+		
+			return array(		
+				'n' => __('Unbearbeitet', 'wpsg'),
+				's' => __('Einpassen', 'wpsg'),
+				'sz' => __('Einpassen mit FreiflÃ€che', 'wpsg'),
+				'z' => __('Strecken', 'wpsg'),
+				'sw' => __('Skallieren auf Breite', 'wpsg'),
+				'sh' => __('Skallieren auf HÃ¶he', 'wpsg'),
+				'c' => __('Zuschneiden', 'wpsg'),
+				'cz' => __('Zentrieren und Abschneiden', 'wpsg')
+			);
+			
+		} // public function getImageModes()		
+		
+		/**
+		 * Gibt false oder die URL zu einem Bild des Produktes zurÃŒck
+		 */
+		public function getProductImage($product_key, $setW, $setH, $mode)
+		{
+			
+			$product_id = $this->shop->getProduktID($product_key);
+			
+			$arBilder = $this->getProduktBilder($product_id);
+			
+			if (!wpsg_isSizedArray($arBilder))
+			{
+				
+				$file = $this->shop->getRessourcePath('mods/mod_produktbilder/dummy.jpg');
+				
+				if (!file_exists($file)) return false;
+				else return $this->makeTn(0, $file, $setW, $setH, $mode); 
+				
+			}
+			
+			$img_url = $this->makeTn($product_id, $arBilder[0], $setW, $setH, $mode);
+			
+			return $img_url;
+			
+		} // public function getProductImage($product_key)
+
+		/**
+		 * Gibt false oder die URL zu einem Bild des Produktes zurÃŒck
+		 */
+		public function getProductImage_MT($product_key, $size = 'thumbnail')
+		{
+			
+			global $wpdb;
+			
+			$product_id = $this->shop->getProduktID($product_key);
+			
+			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key` = '".wpsg_q('wpsg_produkt_id')."' AND `meta_value` = '".wpsg_q($product_id)."' ORDER BY `post_id`");
+				
+			if (!wpsg_isSizedArray($data)) return false;
+
+			$p = wp_get_attachment_image_src($data[0]['post_id'], $size);	// Array mit Full-Path, Width, Height
+					
+			// Umsortiert, wenn Feld postids existiert
+			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($product_id));
+			$arPostids = explode(',', $postids);
+			$postid = $arPostids[0];
+			if (wpsg_isSizedString($postids)) {
+					
+					for ($i = 0; $i < count($data); $i++) {
+						if ($data[$i]['post_id'] == $postid) {
+							
+							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
+						}
+					}
+				
+			}
+			
+			// Wenn product_key dann das Bild der Variation holen.
+			if (!wpsg_isSizedInt($product_key)) {
+				
+				$ap = explode(':', $product_key);
+				$vid = $ap[count($ap) - 1];
+				$images = $this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `variation_id`=".wpsg_q($vid));
+				$ar = unserialize($images);
+				$ar2 = explode(',', $ar['pic']);
+				//$file = pathinfo($ar2[count($ar2) - 1], PATHINFO_FILENAME);
+				$ar3 = pathinfo($ar2[count($ar2) - 1]);
+				$file = $ar3['basename'];
+				$af = $file;
+				$pos1 = strrpos($file, '-');
+				if ($pos1 !== false) {
+					$pos2 = strlen($file);
+					//$af = substr_replace($file, '', $pos1, $pos2 - $pos1);
+				}
+				$af = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+				$ar4 = pathinfo($af);
+				$af = $ar4['filename'];
+				$af2 = substr($af, 0, strlen($af) - 2);
+				//var_dump($af2);
+				$sql = "SELECT
+					P.`ID`, P.`post_title`, P.`guid`, PM.`post_id`, PM.`meta_key`, PM.`meta_value`
+					FROM `".$wpdb->prefix."posts` AS P
+					LEFT JOIN `".$wpdb->prefix."postmeta` AS PM ON (P.`ID` = PM.`post_id`)
+					WHERE
+					PM.`meta_key` = 'wpsg_produkt_id' AND
+					PM.`meta_value` = '".wpsg_q($product_id)."' AND
+					P.`post_title` = '".$af."'
+				";
+				$arr = $this->db->fetchAssoc($sql);
+				
+				if (!wpsg_isSizedArray($arr)) {
+					$sql = "SELECT
+						P.`ID`, P.`post_title`, P.`guid`, PM.`post_id`, PM.`meta_key`, PM.`meta_value`
+						FROM `".$wpdb->prefix."posts` AS P
+						LEFT JOIN `".$wpdb->prefix."postmeta` AS PM ON (P.`ID` = PM.`post_id`)
+						WHERE
+						PM.`meta_key` = 'wpsg_produkt_id' AND
+						PM.`meta_value` = '".wpsg_q($product_id)."' AND
+						P.`post_title` = '".$af2."'
+					";
+					$arr = $this->db->fetchAssoc($sql);
+				}
+				
+				$p = wp_get_attachment_image_src($arr[0]['ID'], 'thumbnail');
+				
+			}
+			
+			$img_url = $p[0];
+			
+			return $img_url;
+				
+		} // public function getProductImage_MT($product_key)
+		
+		/**
+		 * Gibt ein Array mit den Produktbildern zurÃŒck
+		 */
+		public function getProduktBilder($produkt_id)
+		{
+			
+			$arFiles = array();
+
+			// Bilder aus dem Dateisystem raussuchen
+			$path = $this->getPicPath($this->shop->getProduktId($produkt_id));
+						 
+			$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;
+			
+		} // public function getProduktBilder($produkt_id)
+
+		
+		
+		/**
+		 * Gibt ein Array mit den Produktbildern zurÃŒck
+		 * $size = 'full' sollte OriginalgrÃ¶Ãe zurÃŒckgeben
+		 */
+		public function getProduktBilder_MT($produkt_id, $size = 'thumbnail')
+		{
+			
+			global $wpdb;
+				
+			if ($this->shop->callMod('wpsg_mod_productvariants', 'isVariantsProductKey', array($produkt_id))) {
+				$ar = $this->shop->callMod('wpsg_mod_productvariants', 'explodeProductKey', array($produkt_id));
+				$produkt_id = $ar['product_id'];
+			}
+			
+			$arFiles = array();		
+			
+			$data = $this->db->fetchAssoc("SELECT * FROM `".$wpdb->prefix."postmeta` WHERE `meta_key` = 'wpsg_produkt_id' AND `meta_value` = '".wpsg_q($produkt_id)."' ");
+			$postids = $this->db->fetchOne("SELECT `postids` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id`=".wpsg_q($produkt_id));
+			$arPostids = explode(',', $postids);
+			
+			$ud = wp_upload_dir();
+			
+			$i = 0;
+			
+			if (wpsg_isSizedString($postids)) {
+				foreach ($arPostids as $postid) {
+					
+					for ($i = 0; $i < count($data); $i++) {
+						if ($data[$i]['post_id'] == $postid) {
+							$p = wp_get_attachment_image_src($data[$i]['post_id'], $size);	// Array mit Full-Path, Width, Height
+							$guid = $p[0];
+							$arrf = pathinfo($guid);
+
+							$arFiles[$i]['guid'] = $guid;
+							$arFiles[$i]['post_id'] = $data[$i]['post_id'];
+							$arFiles[$i]['basename'] = $arrf['basename'];
+							$file = $arrf['basename'];
+							$pos1 = strrpos($file, '-');
+							if ($pos1 !== false) {
+								$pos2 = strrpos($file, '.');
+								//$file = substr_replace($file, '', $pos1, $pos2 - $pos1);
+							}
+							$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+							
+							$arFiles[$i]['basenameori']= $file;
+							
+							$arFiles[$i]['url'] = $guid;
+							$arFiles[$i]['path'] = str_replace($ud['baseurl'], $ud['basedir'], $guid);
+							
+						}
+					}
+				}
+				
+			} else {
+				
+				foreach ($data as $key => $val) 
+				{
+					
+					$p = wp_get_attachment_image_src($val['post_id'], $size);	// Array mit Full-Path, Width, Height
+					 
+					$guid = $p[0];
+					$arrf = pathinfo($guid);
+					
+					//$this->shop->view['ProduktBilder_MT'][$i]['pid'] = $val['post_id'];
+					//$this->shop->view['ProduktBilder_MT'][$i]['fname'] = $arrf['basename'];
+					//$this->shop->view['ProduktBilder_MT'][$i]['guid'] = $guid;
+					
+					$arFiles[$i]['guid'] = $guid;
+					$arFiles[$i]['post_id'] = $val['post_id'];
+					$arFiles[$i]['basename'] = $arrf['basename'];
+					$arFiles[$i]['basenameori'] = preg_replace('/\-(\d+)x(\d+)\./', '.', $arrf['basename']);;
+					$arFiles[$i]['url'] = $guid;
+					$arFiles[$i]['path'] = str_replace($ud['baseurl'], $ud['basedir'], $guid);				
+					
+					$i++;
+					
+				}
+			}
+			/*
+			wpsg_asort($arFiles);
+				
+			$arReturn = array();
+			foreach ($arFiles as $k => $v) $arReturn[] = $v;
+		
+			return $arReturn;
+			*/
+			
+			return $arFiles;
+			
+		} // public function getProduktBilder_MT($produkt_id)
+		
+		/*
+ 		 * 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)
+ 		{
+ 		 	 			
+ 			if ($url) $path = WPSG_URL_UPLOADS.'wpsg_produktbilder/'.$produkt_id.'/';
+			else 
+			{
+				
+				$path = WPSG_PATH_UPLOADS.'wpsg_produktbilder/'.$produkt_id.'/'; 
+				
+				if (!file_exists($path)) mkdir($path, 0777, true);
+				 
+			}
+			 			
+			if ($url === true) return $path;
+			else return wpsg_format_path($path);
+			 
+ 		} // private function getPicPath($produkt_id, $url = false)
+
+ 		/**
+ 		 * @param int $p_id Id des Produktes
+ 		 * @param String $file Dateiname des Bildes (Ohne Pfad)
+ 		 * @param int $setW Angestrebte Breite des Bildes
+ 		 * @param int $setH Angestrebte HÃ¶he des Bildes
+ 		 * @param String $mode Modus 
+ 		 * 
+ 		 * Funktion kann jetzt auch mit Bildern umgehen, die nicht einem Produkt zugeordnet sind (z.B. dem Dummy Bild)
+ 		 * Einfach als p_id 0 ÃŒbergeben und in $file den kompletten Pfad
+  		 */
+ 		public function makeTn($p_id, $file, $setW, $setH, $mode)
+		{
+			
+			if ($p_id !== 0) $p_id = $this->shop->getProduktId($p_id);
+
+			$uploaddir = $this->getPicPath($p_id);
+			$uploaddir_tn = $this->getPicPath($p_id)."tn/";
+			$url_bilder = $this->getPicPath($p_id, true);
+			
+			if ($p_id !== 0 && !file_exists($uploaddir)) mkdir($uploaddir, 0777, true);
+			if (!file_exists($uploaddir_tn)) mkdir($uploaddir_tn, 0777, true);
+			
+			// Default Werte
+			if ($setW <= 0) $setW = 100;
+			if ($setH <= 0) $setH = 100;
+			if ($mode == "" || !isset($mode)) $mode = 's';
+			
+			if ($p_id !== 0) $src_file = $uploaddir.$file;
+			else {
+				
+				$src_file = $file;
+				$file = basename($src_file);
+				
+			}
+			
+			$trg_file = $uploaddir_tn.$mode.'-'.$setW.'-'.$setH.'-'.$file;
+			
+			if (!file_exists($src_file) || !is_file($src_file)) return;
+			
+			// Quelldatei existiert nicht
+			if (!file_exists($src_file)) return "FILE NOT FOUND: ".$uploaddir.$file;
+			
+			if (file_exists($trg_file)) return $this->shop->url(str_replace(' ', '%20', $url_bilder."tn/".$mode.'-'.$setW.'-'.$setH.'-'.$file));
+			
+			$b = copy($src_file, $trg_file);
+ 
+			$ImInf = GetImageSize($trg_file);
+			$W = $ImInf[0];
+			$H = $ImInf[1];
+			
+			switch (strtolower(preg_replace("/.*\./", "", $trg_file)))
+			{
+				case 'gif':
+					$srcImage = imagecreatefromgif($trg_file);
+					break;
+				case 'png':				
+					$srcImage = imagecreatefrompng($trg_file);
+					break;
+				case 'jpg':
+					$srcImage = imagecreatefromjpeg($trg_file);
+					break;
+				case 'bmp':
+					$srcImage = imagecreatefromwbmp($trg_file);
+					break;
+				default:
+					return __("Unbekanntes Dateiformat", "wpsg");
+			}
+												
+			switch (strtolower($mode))
+			{
+				
+				case 'c':	// CROP
+					
+					$dstImage = ImageCreateTrueColor($setW, $setH);
+					 					
+					imagealphablending($dstImage, false);
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+					 					
+					// LÃ€ngste Seite finden
+					if ($W > $H)
+					{						
+						$new_width = $W / ($H / $setH);
+						imagecopyresampled($dstImage, $srcImage, 0 - ($new_width / 2) + ($setW / 2), 0, 0, 0, $new_width, $setH, $W, $H);
+					}
+					else
+					{
+						$new_height = $H / ($W / $setW);
+						imagecopyresampled($dstImage, $srcImage, 0, 0 - ($new_height / 2) + ($setH / 2), 0, 0, $setW, $new_height, $W, $H);						
+					}
+					 
+					break;	
+
+				case 'cz': // CROP CENTER
+				
+					$dstImage = ImageCreateTrueColor($setW, $setH);
+					
+					imagealphablending($dstImage, false);
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+					
+					$new_width = $H * $setW / $setH;
+					$new_height = $W * $setH / $setW;
+					
+					if ($new_width > $W)
+					{
+						
+						$y = (($H - $new_height) / 2);
+						
+						imagecopyresampled($dstImage, $srcImage, 0, 0, 0, $y, $setW, $setH, $W, $new_height);
+						
+					}
+					else
+					{
+						
+						$x = (($W - $new_width) / 2);
+						
+						imagecopyresampled($dstImage, $srcImage, 0, 0, $x, 0, $setW, $setH, $new_width, $H);
+						
+					}
+					
+					break;
+						
+				case 'z':   // STRETCH
+					 
+					$dstImage = ImageCreateTrueColor($setW, $setH);
+					
+					imagealphablending($dstImage, false);
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+					
+					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $setW, $setH, $W, $H); 
+					break;
+					
+				case 'n': 	// NIX 
+					
+					return $url_bilder.$file;
+					
+					break;
+					
+				case 'sz':  // SCALE und FreiflÃ€che
+					
+					$dstImage = ImageCreateTrueColor($setW, $setH);
+					list($width, $height) = $this->getNewSize($W, $H, $setW, $setH);					
+					 
+					imagealphablending($dstImage, false);					
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 255, 255, 255, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+					
+					$dst_x = 0; if ($width < $setW) $dst_x = ($setW - $width) / 2;
+					$dst_y = 0; if ($height < $setH) $dst_y = ($setH - $height) / 2;
+					
+					imagecopyresampled($dstImage, $srcImage, $dst_x, $dst_y, 0, 0, $width, $height, $W, $H);														
+									
+					break; 	
+
+				case 'sw': // SCALE WIDTH
+					
+					$height = $H / ($W / $setW);
+					
+					$dstImage = ImageCreateTrueColor($setW, $height);
+					
+					imagealphablending($dstImage, false);
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 255, 255, 255, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+					
+					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $setW, $height, $W, $H);
+						
+					break;
+					
+				case 'sh': // SCALE HEIGHT
+					
+					$width = $W / ($H / $setH);
+					
+					$dstImage = ImageCreateTrueColor($width, $setH);
+						
+					imagealphablending($dstImage, false);
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 255, 255, 255, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+						
+					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $width, $setH, $W, $H);
+										
+					break;
+										
+				case 's':	// SCALE INTO
+				default:
+					
+					list($width, $height) = $this->getNewSize($W, $H, $setW, $setH);					
+					$dstImage = ImageCreateTrueColor($width, $height);
+					
+					imagealphablending($dstImage, false);
+					$color = imagecolortransparent($dstImage, imagecolorallocatealpha($dstImage, 0, 0, 0, 127));
+					imagefill($dstImage, 0, 0, $color);
+					imagesavealpha($dstImage, true);
+					
+					imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $width, $height, $W, $H);														
+					break;
+					
+			}		
+			
+			switch (strtolower(preg_replace("/.*\./", "", $trg_file)))
+			{
+				
+				case 'gif':
+					ImageGIF($dstImage, $trg_file);
+				case 'png':
+
+					$quality = 9 - wpsg_round($this->shop->get_option('wpsg_mod_produktbilder_quality') / 10, 0);
+					if ($quality < 9) $quality = 0;
+					
+					$b = ImagePNG($dstImage, $trg_file, $quality);
+					
+					break;
+				case 'jpg':
+				case 'bmp':
+				default:
+					ImageJPEG($dstImage, $trg_file, $this->shop->get_option('wpsg_mod_produktbilder_quality'));
+					break;	
+								
+			}		
+			 
+			imageDestroy($dstImage);
+			imageDestroy($srcImage);	
+
+			return $this->shop->url(str_replace(' ', '%20', $url_bilder."tn/".$mode.'-'.$setW.'-'.$setH.'-'.$file));
+			
+		} // private function makeTn($mode, $set_width, $set_height)
+		
+		/**
+		 * Bestimmt die GrÃ¶Ãe im SeitenverhÃ€ltnis fÃŒr skalierte Bilder
+		 */
+		private function getNewSize($w, $h, $maxW, $maxH)
+		{
+		    
+		    if ($w > $h)
+		    {
+		    	
+				// Breite skalieren und schauen ob HÃ¶he reinpasst   		
+		    	// Bild ist breiter als hoch -> versuchen nach Breite zu skalieren
+		    	$newWidth = $maxW;
+		    	$newHeight = ($maxW / $w) * $h;
+		    	
+		    	if ($newHeight > $maxH)
+		    	{
+		    		
+		    		// Bild ist nach Skalierung auf Breite zu hoch ! 
+		    		// jetzt noch auf HÃ¶he skalieren
+		    		$newWidth = ($maxH / $newHeight) * $maxW;
+		    		$newHeight = $maxH;  
+		    		  			    			
+		    	}
+		    	
+		    }
+		    else 
+		    {
+		    	
+		    	// Nach HÃ¶he skalieren
+		    	$newHeight = $maxH;
+		    	$newWidth = ($maxH / $h) * $w;
+		    	
+		    	if ($newWidth > $maxW)
+		    	{
+		    		
+		    		// Bild ist nach Skalierung auf HÃ¶he zu schmal !
+		    		// jetzt Breite anpassen
+		    		$newHeight = ($maxW / $newWidth) * $maxH;
+		    		$newWidth = $maxW;
+		    		
+		    	}
+		    	
+		    }
+		    
+		    return array($newWidth, $newHeight);
+		    
+		} // function getNewSize($w, $h, $maxW, $maxH)
+		
+	} // class wpsg_mod_produktbilder extends wpsg_mod_basic
+
+?>
Index: /views/admin/presentation.phtml
===================================================================
--- /views/admin/presentation.phtml	(revision 6437)
+++ /views/admin/presentation.phtml	(revision 6438)
@@ -31,6 +31,11 @@
 	 				'2' => __('Serverseitig + Javascript V2', 'wpsg')
 	 			), $this->get_option('wpsg_form_validation')); ?>
-	 			<?php $this->callMods('admin_presentation'); ?>
-			 	<?php echo wpsg_drawForm_Checkbox('wpsg_showMwstAlways', __('MwSt. Spalte auch bei einem Satz zeigen', 'wpsg'), $this->get_option('wpsg_showMwstAlways')); ?>
+	 			
+				<?php echo wpsg_drawForm_Checkbox('wpsg_imagehandler_basketimage', __('Produktbild im Warenkorb anzeigen', 'wpsg'), $this->shop->get_option('wpsg_imagehandler_basketimage')); ?>
+				<?php echo wpsg_drawForm_Checkbox('wpsg_imagehandler_overviewimage', __('Produktbild in Bestellzusammenfassung anzeigen', 'wpsg'), $this->shop->get_option('wpsg_imagehandler_overviewimage')); ?>
+				
+				<?php $this->callMods('admin_presentation'); ?>
+			 	
+				<?php echo wpsg_drawForm_Checkbox('wpsg_showMwstAlways', __('MwSt. Spalte auch bei einem Satz zeigen', 'wpsg'), $this->get_option('wpsg_showMwstAlways')); ?>
 			 	<?php echo wpsg_drawForm_Checkbox('wpsg_showArticelnumber', __('Artikelnummer im Produkttemplate anzeigen', 'wpsg'), $this->get_option('wpsg_showArticelnumber')); ?>
 			 	<?php echo wpsg_drawForm_Checkbox('wpsg_hideBasketCountrySelect', __('LÃ€nderauswahl im Warenkorb verbergen', 'wpsg'), $this->get_option('wpsg_hideBasketCountrySelect')); ?>
Index: /views/css/admin.css
===================================================================
--- /views/css/admin.css	(revision 6437)
+++ /views/css/admin.css	(revision 6438)
@@ -151,4 +151,14 @@
 #wpsg-bs.wpsg_products .wpsg_productgroup_link_wrap { float:left; }
 .wpsg_mod_productvariants_productimage_row .mark { display:inline-block; background-color:#FFF; border:2px solid #444444;}
+.wpsg_be_imagelist_image { width:100px; }
+.wpsg_be_productindex_image { border:0px !important; width:75px; background-color:#FFFFFF; }
+
+/* Bild allgemein */
+.box_img_wrap { position:relative; padding-top:100%; border:1px solid #000000; background:transparent; }
+.box_img_wrap img {border:0px !important; position:absolute; left:50%; top:50%; max-height:100% !important; max-width:100%!important; height:auto!important; width:auto!important; margin:0px !important; 
+    transform:translateY(-50%) translateX(-50%);
+    -ms-transform:translateY(-50%) translateX(-50%);
+    -webkit-transform:translateY(-50%) translateX(-50%);
+}
 
 /*
Index: /views/mailtemplates/html/order.phtml
===================================================================
--- /views/mailtemplates/html/order.phtml	(revision 6437)
+++ /views/mailtemplates/html/order.phtml	(revision 6438)
@@ -19,5 +19,5 @@
 					<tr>
 						<td style="padding:0px; ">
-							<?php if ($this->hasMod('wpsg_mod_produktbilder') && wpsg_isSizedInt($this->get_option('wpsg_mod_produktbilder_overviewimage'))) { $arBilder = $this->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($this->getProduktId($p['id']))); ?>
+							<?php if ($this->hasMod('wpsg_mod_produktbilder') && wpsg_isSizedInt($this->get_option('wpsg_imagehandler_overviewimage'))) { $arBilder = $this->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($this->getProduktId($p['id']))); ?>
 							<?php if (wpsg_isSizedArray($arBilder)) { ?>  				
 							<a style="width:50px; width:50px; margin-right:10px; float:left;" href="<?php echo $this->getProduktLink($this->getProduktId($p['id'])); ?>" title="<?php echo wpsg_hspc(((wpsg_isSizedString($p['detailname'])?$p['detailname']:$p['name']))); ?>">
Index: /views/mods/mod_productvariants/admin_edit.phtml
===================================================================
--- /views/mods/mod_productvariants/admin_edit.phtml	(revision 6437)
+++ /views/mods/mod_productvariants/admin_edit.phtml	(revision 6438)
@@ -174,27 +174,25 @@
     			<td class="col_id">&nbsp;</td>
    				<?php 
-				$pbArr = $this->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($this->view['product_id']));
-				$k = $this->view['variant']['id'];
-				$kv = $vari['id'];
-				$temp = $this->callMod('wpsg_mod_productvariants', 'getVariImages', array($this->view['product_id'], $k, $vari['iid']));
+				 
+					$arAttachmentIDs = $this->imagehandler->getAttachmentIDs($this->view['product_id'], $vari['id']);
+					
 				?>
-    			<td class="ui-sortable" colspan="<?php echo $colspan; ?>"  id="wpsg_mod_productvariants_productimage_<?php echo $k; ?>_<?php echo $kv; ?>" >
-					<?php $j = 0; foreach ($temp as $b) { $j ++; ?>
-							<?php // $this->view['variant']['id']	$vari  $var  $kv  $_REQUEST['pic']
-							$file2 = $b['basenameori'];
-							$href = wp_get_attachment_image_src($b['post_id'], Array(25, 25));
-							?>	
-							<a class="<?php echo ((in_array($file2, explode(",", $vari['pic'])))?'mark':''); ?> pic" id="<?php echo $file2; ?>" data-pid="<?php echo $b['post_id']; ?>" 
-							onclick="return wpsg_vp_vari_setPic(this, <?php echo $k; ?>, <?php echo $kv; ?>, '<?php echo $file2; ?>', <?php echo $j; ?>, <?php echo $b['post_id']; ?>);">
-							<img src="<?php echo $href[0]; ?>" alt="" width="25px" height="25px"/>
-							</a>
-        			<?php } ?>
+				<td class="ui-sortable" colspan="<?php echo $colspan; ?>"  id="wpsg_images_productimage_<?php echo $this->view['variant']['id']; ?>_<?php echo $vari['id']; ?>" >
+			 
+					<?php foreach ($arAttachmentIDs as $attachment_id) { ?>
 					
-					<?php if (wpsg_isSizedInt($j)) { ?>
-			   		<script type="text/javascript">/* <![CDATA[ */
-
-			   			jQuery(document).ready(function() {   
-			   				
-					   		jQuery('#wpsg_mod_productvariants_productimage_<?php echo $k; ?>_<?php echo $kv; ?>').sortable( {
+						<a href="#" class="<?php echo ((in_array($attachment_id, explode(",", $vari['images_set'])))?'mark':''); ?> pic" id="<?php echo $attachment_id; ?>" onclick="return wpsg_vp_vari_setPic(this, <?php echo $this->view['variant']['id']; ?>, <?php echo $vari['id'] ?>, '<?php echo $attachment_id; ?>', <?php echo $this->view['product_id']; ?>);">
+							
+							<?php echo wp_get_attachment_image($attachment_id, array(25, 25), true); ?>
+							
+						</a>
+						
+					<?php } ?>
+					
+					<script type="text/javascript">
+
+						jQuery(document).ready(function() {   
+			   				 
+					   		jQuery('#wpsg_images_productimage_<?php echo $this->view['variant']['id']; ?>_<?php  echo $vari['id']; ?>').sortable( {
 								items: 'a',
 								helper : 'clone',  
@@ -204,17 +202,11 @@
 									
 									var wpsg_reorder = jQuery(this).sortable('toArray');
-									var wpsg_postids = jQuery(this).sortable('toArray', {attribute: 'data-pid'});
-									alert(wpsg_postids + ' ' + wpsg_reorder);
-									var iid = jQuery('#productvariation_iid_' + <?php echo $kv; ?>).val();
-									//alert('iid: ' + iid);
-
+									 
 									jQuery.ajax( {			
 										url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_productvariants&cmd=wpsg_var_setImageOrder&noheader=1&edit_id=<?php echo $this->view['product_id']; ?>',
 										async: false,
 										data: {				
-											'var_id': <?php echo $k; ?>,
-											'vari_id': <?php echo $kv; ?>,
-											'iid': iid,
-											'wpsg_postids': wpsg_postids,
+											'var_id': <?php echo $this->view['variant']['id']; ?>,
+											'vari_id': <?php echo $vari['id']; ?>,
 											'wpsg_reorder': wpsg_reorder
 										},
@@ -222,4 +214,5 @@
 
 											if (data != '1') alert(data);
+											
 											wpsg_vp_ajaxloading_hide(); 
 
@@ -228,13 +221,12 @@
 																				 
 								}			
-							} ).disableSelection();
+							} ).disableSelection(); 
 
 			   			} );
 			   		
-				   		/* ]]> */</script>
-			   		
-			   		<?php } ?>
-    				
-    			</td>
+					</script>
+					
+				</td>
+				 				
     		</tr>
 
@@ -246,5 +238,5 @@
 	<script type="text/javascript">/* <![CDATA[ */
 
-	function wpsg_vp_vari_setPic(htmlElement, var_id, vari_id, pic, pic_index, post_id)
+	function wpsg_vp_vari_setPic(htmlElement, var_id, vari_id, attachment_id, product_id)
 	{
 
@@ -252,7 +244,5 @@
 
 		wpsg_vp_ajaxloading_show();
-		iid = jQuery('#productvariation_iid_' + vari_id).val();
-		//alert('iid:' + iid);
-		
+		 
 		jQuery.ajax( {
 			url: "<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_productvariants&cmd=wpsg_vp_vari_setPic&noheader=1&edit_id=<?php echo $this->view['product_id']; ?>",
@@ -261,37 +251,11 @@
 				var_id: var_id,
 				vari_id: vari_id,
-				iid: iid,
-				pic_index: pic_index,
-				post_id: post_id,
-				pic: pic
+				product_id: product_id,
+				attachment_id: attachment_id
 			},
 			success: function(data) { 
-				if (vari_id >= 0)
-				{
-					
-					if (jQuery(htmlElement).hasClass('mark'))
-					{
-						jQuery(htmlElement).removeClass('mark');
-					}
-					else
-					{
-						jQuery(htmlElement).addClass('mark');
-					}
-					
-				}
-				else
-				{
-					
-					if (jQuery(htmlElement).hasClass('mark'))
-					{
-						jQuery(htmlElement).removeClass('mark');
-					}
-					else
-					{
-						jQuery(htmlElement).addClass('mark');
-					}
-					
-				}
-
+				
+				jQuery(htmlElement).toggleClass('mark');
+				
 				wpsg_vp_ajaxloading_hide();
 				
Index: /views/mods/mod_productvariants/produkt.phtml
===================================================================
--- /views/mods/mod_productvariants/produkt.phtml	(revision 6437)
+++ /views/mods/mod_productvariants/produkt.phtml	(revision 6438)
@@ -8,14 +8,7 @@
 
 <div class="wpsg_mod_productvariants_product_wrap" id="wpsg_mod_productvariants_product_wrap_<?php echo $GLOBALS['wpsg_produkt_index']; ?>" wpsg-productindex="<?php echo $GLOBALS['wpsg_produkt_index']; ?>"> 
-	<?php $vAktiv = false; if (is_array($this->view['data']['vp_data']) && sizeof($this->view['data']['vp_data']) > 0) { ?>
+	<?php $vAktiv = false; if (is_array($this->view['vp_data']) && sizeof($this->view['vp_data']) > 0) { ?>
 	
-		<?php $kk = -1; 
-			foreach ($this->view['data']['vp_data'] as $k => $var) { 
-			
-			$kk++;
-			//if ($var['active'] == "1") 
-			{ 
-	
-				$vAktiv = true; ?>
+		<?php $kk = -1; foreach ($this->view['vp_data'] as $k => $var) { $kk ++; ?>
 			
 				<div class="wpsg_vp_field wpsg_vp_field_<?php echo $this->getProduktId($this->view['data']['id']); ?>">
@@ -32,5 +25,5 @@
 					
 						<?php /* SELECT-Box START */ ?>
-						<?php if ($var['typ'] == "select") { ?>
+						<?php if ($var['type'] == wpsg_mod_productvariants::TYPE_SELECT) { ?>
 							<label>			 			
 								<select name="wpsg_vp[<?php echo $k; ?>]" class="wpsg_vp_update" id="wpsg_vpfield_<?php echo $this->getProduktId($this->view['data']['id']); ?>_<?php echo $k; ?>">
@@ -42,5 +35,5 @@
 											<?php if (!$this->hasMod('wpsg_mod_stock') || $vari['stock'] > 0) { ?>
 											
-												<option value="<?php echo $kv; ?>" <?php echo ((wpsg_getStr($this->view['wpsg_mod_productvariants']['set'][$k]) == $kv)?'selected="selected"':''); ?>>						
+												<option value="<?php echo $kv; ?>" <?php echo ((wpsg_getStr($this->view['vp_info'][$k]['vari_id']) == $kv)?'selected="selected"':''); ?>>						
 												<?php echo $vari['name']; ?>
 													
@@ -100,5 +93,5 @@
 						
 						<?php /* IMAGE START */ ?>
-						<?php if ($var['typ'] == 'image' && $this->hasMod('wpsg_mod_produktbilder')) { ?>
+						<?php if ($var['type'] == wpsg_mod_productvariants::TYPE_IMAGE && $this->hasMod('wpsg_mod_produktbilder')) { ?>
 							<div class="wpsg_mod_productvariants_imageselect wpsg_mod_productvariants_imageselect_<?php echo $k; ?>">
 							<span>
@@ -122,5 +115,5 @@
 						
 						<?php /* Radio-Buttons START */ ?>
-						<?php if ($var['typ'] == "radio") { ?>			
+						<?php if ($var['type'] == wpsg_mod_productvariants::TYPE_RADIO) { ?>			
 							<?php $j = 0; foreach ($var['arVariation'] as $kv => $vari) { if ($vari['active'] == "1") { $j ++; ?>
 								<?php if (!$this->hasMod('wpsg_mod_stock') || $vari['stock'] > 0 || $this->get_option('wpsg_mod_vp_showProduct') === '1') { ?>					
@@ -180,6 +173,5 @@
 				</div>
 	
-			<?php } /* $var['active'] == "1" */ ?>
-		<?php } /* foreach ($this->view['data']['vp_data'] as $k => $var) */ ?>
+		<?php } /* foreach ($this->view['vp_data'] as $k => $var) */ ?>
 	<?php } /* $vAktiv = false; ENDE */ ?>
 	
Index: /views/produkt/images.phtml
===================================================================
--- /views/produkt/images.phtml	(revision 6438)
+++ /views/produkt/images.phtml	(revision 6438)
@@ -0,0 +1,230 @@
+<?php
+
+    /**
+     * Template fÃŒr den Reiter "Produktbilder" in der Produktverwaltung
+     */
+
+?>
+
+<!-- Modal fÃŒr LÃ¶schabfrage -->
+<div class="modal fade" tabindex="-1" role="dialog" id="wpsg_produktbilder_remove">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                <h4 class="modal-title"><?php echo __('Produktbild lÃ¶schen', 'wpsg'); ?></h4>
+            </div>
+            <div class="modal-body">
+
+                <?php echo wpsg_drawForm_Checkbox('dialog_produktbilder_delmt', __('Auch in der Mediathek lÃ¶schen', 'wpsg'), false, array()); ?>
+                
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo __('Abbrechen', 'wpsg'); ?></button>
+                <button type="button" class="btn btn-primary" onclick="return wpsg_remove_bild_MT_OK();"><?php echo __('LÃ¶schen', 'wpsg'); ?></button>
+            </div>
+        </div>
+    </div>
+</div>
+
+
+<div class="panel panel-default">
+	<div class="panel-heading clearfix">
+    	<h3 class="panel-title"><?php echo __('Produktbilder', 'wpsg'); ?></h3>
+	</div>
+	<div class="panel-body">
+		
+		<?php if ($this->view['data']['id'] > 0) { ?>
+		
+			<!--  Mediathek -->
+
+			<div class="ui-sortable" id="produktbilder_target_MT"><?php echo $this->view['strProductList']; ?></div>
+
+			<div class="wpsg_clear"></div>
+			<div><?php echo __("Bitte klicken Sie auf Mediathek um ein Bild hochzuladen. Um ein Bild zu lÃ¶schen klicken Sie einfach auf das Bild.", "wpsg"); ?></div>
+			<div><?php echo __("Die Reihenfolge kann mittels Drag&Drop verÃ€ndert werden.", "wpsg"); ?></div>
+			<div class="wpsg_clear"></div><br />
+		
+			<input value="Mediathek" class="button" type="text" style="text-align:center;" size="10" id="btnAddImgLink" />
+
+			<script type="text/javascript">/* <![CDATA[ */
+								
+				var post_id;
+				
+				/**
+				 * Wird beim lÃ¶schen eines Bilds (anklicken) aufgerufen
+				 */
+				function wpsg_remove_bild_MT(pid) {
+
+					post_id = pid;
+					//jQuery('#wpsg_produktbilder_remove').show();
+					jQuery('#wpsg_produktbilder_remove').modal( { } );
+					//jQuery('#wpsg_produktbilder_remove').modal('hide');
+					
+				}
+				
+				function wpsg_remove_bild_MT_OK() {
+
+					delmt = jQuery('#dialog_produktbilder_delmt').is(':checked');
+					del = jQuery('#dialog_produktbilder_del').is(':checked');
+					
+					jQuery('#wpsg_produktbilder_remove').modal('hide');
+
+					jQuery('#produktbilder_target_MT').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
+					
+					jQuery.ajax( {
+						url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&cmd=removeImage&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+						async: true,
+						data: {
+							del: del,
+							delmt: delmt,
+							pid: post_id
+						},
+						success: function(data) {
+							
+							jQuery('#produktbilder_target_MT').html(data);
+
+							//if (typeof wpsg_vp_refresh == "function") wpsg_vp_refresh();
+							
+						}
+					} );
+
+					return false;
+					
+				}
+
+				/**
+				 * Wird beim lÃ¶schen eines Bilds (anklicken) aufgerufen
+				 */
+				function wpsg_remove_bild(strBild)
+				{
+
+					if (!confirm('<?php echo __('Sind Sie sicher, das Sie dieses Bild lÃ¶schen mÃ¶chten?', 'wpsg'); ?>')) return false;
+
+					jQuery('#produktbilder_target').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
+					
+					jQuery.ajax( {
+						url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=remove&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+						async: true,
+						data: {
+							file: strBild
+						},
+						success: function(data) {
+							
+							jQuery('#produktbilder_target').html(data);
+
+							if (typeof wpsg_vp_refresh == "function") wpsg_vp_refresh();
+							
+						}
+					} );
+
+					return false;
+					
+				}
+                
+				jQuery(document).ready(function() {
+
+                    jQuery('#produktbilder_target_MT').sortable( {
+                        items: 'a',
+                        helper : 'clone',
+                        update: function(event, ui) {
+     
+                            var wpsg_reorder = jQuery(this).sortable('toArray');
+    
+                            jQuery.ajax( {
+                                url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&cmd=setImageOrder&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+                                async: false,
+                                data: {
+                                    'p_id': <?php echo '1'; ?>,
+                                    'wpsg_reorder': wpsg_reorder
+                                },
+                                success: function(data) {
+    
+                                    data = data.replace(/\n|\r/g, '');
+                                    if (data != '1') alert(data);
+                                    //wpsg_vp_ajaxloading_hide(); 
+    
+                                }
+                            } );
+                                                                         
+                        }			
+                    } ).disableSelection();
+                    
+					// Set all variables to be used in scope
+					var wpframe,
+					    metaBox = jQuery('#meta-box-id.postbox'), // Your meta box id here
+					    addImgLink = metaBox.find('.upload-custom-img'),
+					    delImgLink = metaBox.find( '.delete-custom-img'),
+					    imgContainer = metaBox.find( '.custom-img-container'),
+					    imgIdInput = metaBox.find( '.custom-img-id' );
+					  
+					// ADD IMAGE LINK
+					jQuery("#btnAddImgLink").click(function (event) {
+						  
+					    event.preventDefault();
+					    
+					    // If the media frame already exists, reopen it.
+					    if ( wpframe ) {
+					      	wpframe.open();
+					      	return;
+					    }
+					    
+					    // Create a new media frame
+					    wpframe = wp.media.frames.file_frame = wp.media({
+					        title: "<?php echo __('AuswÃ€hlen oder Hochladen von Medien', 'wpsg'); ?>",
+					        button: { text: "<?php echo __('Medien benutzen', 'wpsg'); ?>" },
+					        multiple: true  // Set to true to allow multiple files to be selected
+					    });
+
+					    // When an image is selected in the media frame...
+					    wpframe.on( 'select', function() {
+
+				            var attachments = wpframe.state().get('selection').map( 
+				                function( attachment ) {
+
+				                    attachment.toJSON();
+				                    return attachment;
+				            });
+
+				            //loop through the array and do things with each attachment
+				            var i, attachment;
+				            for (i = 0; i < attachments.length; ++i) {
+
+				            	attachment = attachments[i];
+							    imgContainer.append( '<img src="'+attachment.url+'" alt="" style="max-width:100%;"/>' );
+
+				            	attachment = attachment.toJSON();
+								jQuery.ajax( {
+									url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&cmd=upload&noheader=1&edit_id=<?php echo $this->view['data']['id']; ?>',
+									async: true,
+									data: {
+										post: attachment
+									},
+									success: function(data) {
+										
+										jQuery('#produktbilder_target_MT').html(data);
+
+									}
+								} );
+
+
+				            }
+
+					    });		
+
+					    // Finally, open the modal on click
+					    wpframe.open();
+                        
+					});	// jQuery("#btnAddImgLink").click(function (event))
+					  
+				}); // jQuery(document).ready(function())
+							
+			/* ]]> */</script>
+			
+		<?php } else { ?>
+		<p><?php echo __('Das Hochladen von Produktbildern ist erst nach erstmaligem speichern mÃ¶glich.', 'wpsg'); ?></p>
+		<?php } ?>
+	
+		<div class="wpsg_clear"></div>
+	</div>
+</div>
Index: /views/produkt/images_list.phtml
===================================================================
--- /views/produkt/images_list.phtml	(revision 6438)
+++ /views/produkt/images_list.phtml	(revision 6438)
@@ -0,0 +1,36 @@
+<?php
+	
+	/**
+	 * Template fÃŒr die Liste der Bilder eines Produkts
+	 */
+
+?>
+
+<?php if (isset($this->view['ProduktBilder_MT']) && (sizeof($this->view['ProduktBilder_MT']) > 0)) { ?>
+
+	<?php foreach ($this->view['ProduktBilder_MT'] as $b) { ?>
+	
+		<div id="produktbild_div_<?php echo $b['pid']; ?>" class="wpsg_mod_produktbilder_admin_bild">
+
+			<a id="produktbild_<?php echo $b['pid']; ?>" onclick="return wpsg_remove_bild_MT('<?php echo $b['pid']; ?>');" href="#" title="<?php echo __('Dieses Bild lÃ¶schen.', 'wpsg'); ?>">
+				
+				<div class="box_img_wrap wpsg_be_imagelist_image">
+												
+					<?php echo wp_get_attachment_image($b['pid'], 'medium'); ?>
+						
+				</div>
+				  
+				<span><span class="glyphicon glyphicon-trash"></span></span>
+			</a>
+			
+		</div>
+	
+	<?php } ?>
+    
+	<div class="wpsg_clear"></div>
+
+<?php } else { ?>
+    
+    <p><?php echo __('Bisher keine Produktbilder hochgeladen.', 'wpsg'); ?></p>
+    
+<?php } ?>
Index: /views/produkt/index.phtml
===================================================================
--- /views/produkt/index.phtml	(revision 6437)
+++ /views/produkt/index.phtml	(revision 6438)
@@ -35,8 +35,6 @@
 					<?php if (wpsg_isSizedArray($this->view['arData'])) { ?>
 					<li role="presentation" class="<?php echo ((wpsg_isSizedString($_REQUEST['action'], 'export'))?'active':''); ?>"><a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=export&noheader=1"><span class="glyphicon glyphicon-export"></span><?php echo __("Daten-Export", "wpsg"); ?></a></li>
-                    <?php if ($this->hasMod('wpsg_mod_produktbilder')) { ?>
                     <li role="presentation" class="<?php echo ((wpsg_isSizedString($_REQUEST['action'], 'export'))?'active':''); ?>"><a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=exportMedia&noheader=1"><span class="glyphicon glyphicon-export"></span><?php echo __("Daten-Export mit Medien", "wpsg"); ?></a></li>
                     <?php } ?>
-					<?php } ?>
 			 	</ul>
 			</div>
@@ -154,7 +152,5 @@
                 <thead>
                     <tr>
-                        <?php if ($this->hasMod('wpsg_mod_produktbilder')) { ?>
                         <th class="manage-column column-title wpsg_pic_col"></th>
-                        <?php } ?>
                         <th class="wpsg_order" data-order="name"><?php echo __("Name", 'wpsg'); ?></th>
                         <th class="wpsg_order" data-order="anr"><?php echo __("Artikelnummer", 'wpsg'); ?></th>
@@ -176,23 +172,15 @@
                     <?php foreach ($this->view['arData'] as $oProduct) { $d = $oProduct->data; ?>
                     <tr>
-                        <?php if ($this->hasMod('wpsg_mod_produktbilder')) { ?>
                         <td class="post-title wpsg_pic_col">
-                            <?php
-
-                                //$img = $this->callMod('wpsg_mod_produktbilder', 'getProductImage_MT', array($d['id'], 40, 40, 'c'));
-                                $img = $this->callMod('wpsg_mod_produktbilder', 'getProductImage_MT', array($d['id']));
-
-                                if ($img !== false)
-                                {
-
-                                    echo '<a href="'.WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Produkt&amp;action=edit&amp;edit_id='.$d['id'].'" title="'.wpsg_translate(__('Produkt fÃŒr Sprache #1# bearbeiten.', 'wpsg'), $d['name']).'">';
-                                    echo '<img src="'.$img.'" alt="" width="40px" height="40px" />';
-                                    echo '</a>';
-
-                                }
-
-                            ?>
-                        </td>
-                        <?php } ?>
+                            
+                            <?php $attachment_id = $this->imagehandler->getAttachmentID($oProduct->getProductKey()); ?>
+                             
+                            <a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=edit&edit_id=<?php echo $d['id']; ?>" title="<?php echo wpsg_translate(__('Produkt fÃŒr Sprache #1# bearbeiten.', 'wpsg'), $d['name']) ?>">
+                                <div class="box_img_wrap wpsg_be_productindex_image">
+                                    <?php echo wp_get_attachment_image($attachment_id, 'medium'); ?>
+                                </div>
+                            </a>
+                            
+                        </td>
                         <td class="post-title column-title">
                             <strong>
Index: /views/warenkorb/basket.phtml
===================================================================
--- /views/warenkorb/basket.phtml	(revision 6437)
+++ /views/warenkorb/basket.phtml	(revision 6438)
@@ -44,5 +44,5 @@
 				<?php $this->view['$bPicture'] = false; ?>
 
-				<?php if ($this->get_option('wpsg_mod_produktbilder_basketimage') == '1' && $this->hasMod('wpsg_mod_produktbilder')) {
+				<?php if ($this->get_option('wpsg_imagehandler_basketimage') == '1' && $this->hasMod('wpsg_mod_produktbilder')) {
 
 					if (wpsg_isSizedString($product_data['varianten_image'])) $arImages = array($product_data['varianten_image']);
Index: /views/warenkorb/overview.phtml
===================================================================
--- /views/warenkorb/overview.phtml	(revision 6437)
+++ /views/warenkorb/overview.phtml	(revision 6438)
@@ -123,5 +123,5 @@
 				<?php $this->view['$bPicture'] = false; ?>
 
-				<?php if ($this->get_option('wpsg_mod_produktbilder_basketimage') == '1' && $this->hasMod('wpsg_mod_produktbilder')) {
+				<?php if ($this->get_option('wpsg_imagehandler_basketimage') == '1' && $this->hasMod('wpsg_mod_produktbilder')) {
 
 					if (wpsg_isSizedString($product_data['varianten_image'])) $arImages = array($product_data['varianten_image']);
Index: /wpshopgermany.php
===================================================================
--- /wpshopgermany.php	(revision 6437)
+++ /wpshopgermany.php	(revision 6438)
@@ -118,4 +118,5 @@
 	require_once(dirname(__FILE__).'/lib/helper_functions.inc.php');
 	require_once(dirname(__FILE__).'/lib/wpsg_db.class.php');
+	require_once(dirname(__FILE__).'/lib/wpsg_imagehandler.class.php');
 	require_once(dirname(__FILE__).'/lib/wpsg_cache.class.php');
 	require_once(dirname(__FILE__).'/lib/wpsg_basket.class.php');
@@ -144,4 +145,7 @@
 	$GLOBALS['wpsg_db'] = new wpsg_db();
 
+	/** @var wpsg_imagehandler */
+	$GLOBALS['wpsg_ih'] = new wpsg_imagehandler();
+
 	/** @var wpsg_ShopController */
 	$GLOBALS['wpsg_sc'] = new wpsg_ShopController();
