Index: /changelog
===================================================================
--- /changelog	(revision 7591)
+++ /changelog	(revision 7592)
@@ -277,2 +277,6 @@
 - Feature: Gutscheinprodukte - Preis fÃŒr den Gutschein kann vom Kunden frei definiert werden
 - Feature: Gutscheinprodukte - Optionale Mindest- und Maximalschranken fÃŒr den Flexiblen Preis
+
+#4.1.7
+- Bugfix: Beim kopieren von Bildern wird die Bildzuordnung nicht mehr zerstÃ¶rt
+- Feature: Produktbilder kÃ¶nnen beim kopieren optional ausgeschlossen werden
Index: /controller/wpsg_AdminController.class.php
===================================================================
--- /controller/wpsg_AdminController.class.php	(revision 7591)
+++ /controller/wpsg_AdminController.class.php	(revision 7592)
@@ -2132,4 +2132,5 @@
 				$this->update_option('wpsg_nocache', $_REQUEST['wpsg_nocache'], false, false, WPSG_SANITIZE_CHECKBOX);
 				$this->update_option('wpsg_autolineending', $_REQUEST['wpsg_autolineending'], false, false, WPSG_SANITIZE_CHECKBOX);
+				$this->update_option('wpsg_dontcopymedia', $_REQUEST['wpsg_dontcopymedia'], false, false, WPSG_SANITIZE_CHECKBOX);
 				$this->update_option('wpsg_geo_determination', $_REQUEST['wpsg_geo_determination'], false, false, WPSG_SANITIZE_VALUES, [0, 3, 4]);
 
Index: /controller/wpsg_ProduktController.class.php
===================================================================
--- /controller/wpsg_ProduktController.class.php	(revision 7591)
+++ /controller/wpsg_ProduktController.class.php	(revision 7592)
@@ -829,5 +829,5 @@
 			// Ãbersetzungen kopieren wenn vorhanden
 			$produkt_translations = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($edit_id)."'");
-
+			
 			foreach ((array)$produkt_translations as $p)
 			{
@@ -842,16 +842,20 @@
 			}
 
-			// Bilder kopieren
-			$ih = new wpsg_imagehandler();
-			
-			$arAttachments = $ih->getAttachmentIDs($edit_id);
-			$GLOBALS['wpsg_product_copy_imagemapping'] = [];
-			
-			foreach ($arAttachments as $a_id) {
-				
-				$post = $this->db->fetchRow("SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID`='".wpsg_q($a_id)."'");
-				$n_a_id = $ih->addImageToProduct($post['guid'], $new_id);
-				
-				if (wpsg_isSizedInt($n_a_id)) $GLOBALS['wpsg_product_copy_imagemapping'][$a_id] = $n_a_id;
+			if ($this->shop->get_option('wpsg_dontcopymedia') !== '1') {
+				
+				// Bilder kopieren
+				$ih = new wpsg_imagehandler();
+				
+				$arAttachments = $ih->getAttachmentIDs($edit_id);
+				$GLOBALS['wpsg_product_copy_imagemapping'] = [];
+				
+				foreach ($arAttachments as $a_id) {
+					
+					$post = $this->db->fetchRow("SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID`='".wpsg_q($a_id)."'");
+					$n_a_id = $ih->addImageToProduct($post['guid'], $new_id);
+					
+					if (wpsg_isSizedInt($n_a_id)) $GLOBALS['wpsg_product_copy_imagemapping'][$a_id] = $n_a_id;
+					
+				}
 				
 			}
Index: /lib/wpsg_imagehandler.class.php
===================================================================
--- /lib/wpsg_imagehandler.class.php	(revision 7591)
+++ /lib/wpsg_imagehandler.class.php	(revision 7592)
@@ -31,11 +31,9 @@
 		 * @param $product_key
 		 */
-		public function getAttachmentID($product_key, $vari_id = false, $all = false)
-		{
+		public function getAttachmentID($product_key, $vari_id = false, $all = false) {
 			
 			$arAttachmentIDs = $this->getAttachmentIDs($product_key, $vari_id, $all);
 				
-			if (wpsg_isSizedArray($arAttachmentIDs))
-            {
+			if (wpsg_isSizedArray($arAttachmentIDs)) {
 
                 // return array_values($arAttachmentIDs)[0];
@@ -48,7 +46,6 @@
 			
 		} // public function getAttachmentID($product_key)
-		
-		public function addImageToProduct($file, $product_id)
-		{
+				
+		public function addImageToProduct($file, $product_id) {
 			
 			// Siehe
@@ -61,11 +58,27 @@
 			$mt_filetype = wp_check_filetype(basename($file), null);
 			$mt_filename = $wp_upload_dir['path'].'/'.basename($file);
-						
+					
+			// Neuer Dateiname muss eindeutig sein Suffixen
+			$i = 1; while(true) {
+				
+				if (!file_exists($mt_filename)) break;
+				else {
+					
+					$mt_filename = preg_replace('/\.(?!.*\.)/', '_'.$i.'.', $mt_filename); 
+					
+				}
+				
+				if ($i > 100) throw new \wpsg\Exception("Systemfehler!");
+				
+				$i ++;
+				
+			}
+			
 			copy($file, $mt_filename);
 			
 			$attachment = array(
-				'guid' => wpsg_q($wp_upload_dir['url'].'/'.basename($file)),
+				'guid' => wpsg_q($wp_upload_dir['url'].'/'.basename($mt_filename)),
 				'post_mime_type' => wpsg_q($mt_filetype['type']),
-				'post_title' => wpsg_q(preg_replace('/\.[^.]+$/', '', basename($file))),
+				'post_title' => wpsg_q(preg_replace('/\.[^.]+$/', '', basename($mt_filename))),
 				'post_excerpt' => wpsg_q(basename($file)),
 				'post_status' => 'inherit'
Index: /views/admin/extended.phtml
===================================================================
--- /views/admin/extended.phtml	(revision 7591)
+++ /views/admin/extended.phtml	(revision 7592)
@@ -49,4 +49,5 @@
 				<?php echo wpsg_drawForm_Checkbox('wpsg_nocache', __('Cachen von dynamischen Shopseiten verhindern', 'wpsg'), $this->get_option('wpsg_nocache'), array('help' => 'wpsg_nocache')); ?>
 				<?php echo wpsg_drawForm_Checkbox('wpsg_autolineending', __('MAC KompatibilitÃ€t bei Dateiimporten', 'wpsg'), $this->get_option('wpsg_autolineending'), array('help' => 'wpsg_autolineending')); ?>
+				<?php echo wpsg_drawForm_Checkbox('wpsg_dontcopymedia', __('Produktbilder nicht kopieren', 'wpsg'), $this->get_option('wpsg_dontcopymedia'), ['help' => 'wpsg_dontcopymedia']); ?>
 				<?php echo wpsg_drawForm_Select('wpsg_geo_determination', __('Abfrage des Kundenstandortes (EU-Leistungsortregel)', 'wpsg'), $this->view['arGeoMode'], $this->get_option('wpsg_geo_determination'), array('help' => 'wpsg_geo_determination')); ?>
 							
