Index: /controller/wpsg_ProduktController.class.php
===================================================================
--- /controller/wpsg_ProduktController.class.php	(revision 6247)
+++ /controller/wpsg_ProduktController.class.php	(revision 6248)
@@ -859,4 +859,37 @@
 			$oProduct->delete();
 						
+			// Alle Bilder eines Produktes in der Mediathek lÃ¶schen
+			$pid = $_REQUEST['edit_id'];
+			$data = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `meta_key`='".wpsg_q('wpsg_produkt_id')."' AND `meta_value`='".wpsg_q($pid)."' ORDER BY `post_id`");
+			
+			foreach ($data as $pm) {
+				// Wenn das Bild mehrmals verwendet wird, ist die post_id mehrmals vorhanden.
+				$sql = "SELECT * FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `post_id` = '".wpsg_q($pm['post_id'])."'";
+				$pis = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `post_id` = '".wpsg_q($pm['post_id'])."' AND `meta_key` = '".wpsg_q('wpsg_produkt_id')."'");
+				
+				if (count($pis) > 1) {
+					// Nur den Eintrag mit der post_id, meta_key='wpsg_produkt_id' und meta_value=product_id lÃ¶schen.
+					$GLOBALS['wpsg_sc']->db->Query("DELETE FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `post_id` = '".wpsg_q($pm['post_id'])."' AND `meta_key` = '".wpsg_q('wpsg_produkt_id')."' AND `meta_value` = '".wpsg_q($pid)."' ");
+					
+				}
+				if (count($pis) == 1) {
+					// Alle EintrÃ€ge in wp_postmeta mit der post_id und den Eintrag in wp_posts mit ID=post_id lÃ¶schen.
+					//$GLOBALS['wpsg_sc']->db->Query("DELETE FROM `".$GLOBALS['wpdb']->prefix."postmeta` WHERE `post_id` = '".wpsg_q($pm['post_id'])."' ");
+					//$GLOBALS['wpsg_sc']->db->Query("DELETE FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID` = '".wpsg_q($pm['post_id'])."' ");
+					
+					// Tabelle Produkte Eintrag postids leeren
+					$data = array(
+							'postids' => ''
+					);
+					$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_PRODUCTS, $data, "`id` = '".wpsg_q($pid)."'");
+					
+					// Bilddateien lÃ¶schen
+					//delete_post_meta($pm['post_id'], 'wpsg_produkt_id');	// LÃ¶scht den Eintrag bei mehreren Produkten
+					wp_delete_attachment( $pm['post_id'], true );	// LÃ¶scht alle EintrÃ€ge zu der post_id und die Bilder
+					
+				}
+			}
+			
+			
 			$this->addBackendMessage(__('Produkt erfolgreich gelÃ¶scht.', 'wpsg'));
 			$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Produkt&action=index');
Index: /lib/install.php
===================================================================
--- /lib/install.php	(revision 6247)
+++ /lib/install.php	(revision 6248)
@@ -53,4 +53,5 @@
 		basket_multiple INT(1) NOT NULL, 
 		rating INT(1) NOT NULL,
+	  	postids VARCHAR(255) NOT NULL,	  	
 	  	PRIMARY KEY  (id),
 	  	KEY lang_parent (lang_parent)
Index: /mods/wpsg_mod_produktbilder.class.php
===================================================================
--- /mods/wpsg_mod_produktbilder.class.php	(revision 6247)
+++ /mods/wpsg_mod_produktbilder.class.php	(revision 6248)
@@ -187,5 +187,5 @@
 				unlink($this->getPicPath($_REQUEST['edit_id']).'/'.$_REQUEST['file']);
 				
-				$this->shop->view['data']['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']));
@@ -303,4 +303,28 @@
 				
 			}
+			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();
+				
+			}
 			
 		} // public function produkt_ajax()
@@ -501,26 +525,46 @@
 			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)."' ");
+			$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;
-			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;
-				$i++;
-			}
-			
+			
+			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;
+							
+						}
+					}
+				}
+				
+			} 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;
+					$i++;
+				}
+			}
 			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_list_MT.phtml', false);
 				
Index: /views/mods/mod_produktbilder/produkt_addedit_content.phtml
===================================================================
--- /views/mods/mod_produktbilder/produkt_addedit_content.phtml	(revision 6247)
+++ /views/mods/mod_produktbilder/produkt_addedit_content.phtml	(revision 6248)
@@ -68,5 +68,5 @@
 			<!--  Mediathek -->
 
-			<div id="produktbilder_target_MT"><?php echo $this->view['ProduktList_MT']; ?></div>
+			<div class="ui-sortable" id="produktbilder_target_MT"><?php echo $this->view['ProduktList_MT']; ?></div>
 
 			<div class="wpsg_clear"></div>
@@ -78,4 +78,37 @@
 
 			<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) {
+
+								if (data != '1') alert(data);
+								//wpsg_vp_ajaxloading_hide(); 
+
+							}
+						} );
+																	 
+					}			
+				} ).disableSelection();
+
+
+			});
+
 				/*				
 				jQuery(document).ready(function() {		
@@ -156,5 +189,5 @@
 				}
 
-				jQuery(document).ready(function() {		
+				jQuery(document).ready(function() {
 
 					// Set all variables to be used in scope
@@ -181,9 +214,42 @@
 					        title: "<?php echo __('AuswÃ€hlen oder Hochladen von Medien', 'wpsg'); ?>",
 					        button: { text: "<?php echo __('Medien benutzen', 'wpsg'); ?>" },
-					        multiple: false  // Set to true to allow multiple files to be selected
+					        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();
@@ -215,27 +281,13 @@
 								}
 							} );
-					      
-					    });
+					      	*/
+					      	
+					    });		// wpframe.on( 'select', function())
 
 					    // Finally, open the modal on click
 					    wpframe.open();
-					  });
+					});	// jQuery("#btnAddImgLink").click(function (event))
 					  
-					  // DELETE IMAGE LINK
-					  delImgLink.on( 'click', function( event ){
-
-					    event.preventDefault();
-					    // Clear out the preview image
-					    imgContainer.html( '' );
-					    // Un-hide the add image link
-					    addImgLink.removeClass( 'hidden' );
-					    // Hide the delete image link
-					    delImgLink.addClass( 'hidden' );
-					    // Delete the image id from the hidden input
-					    imgIdInput.val( '' );
-
-					  });
-
-				});      
+				});      // jQuery(document).ready(function())
 				
 			/* ]]> */</script>
@@ -295,5 +347,5 @@
 		<?php } else { ?>
 		<p><?php echo __('Das Hochladen von Produktbildern ist erst nach erstmaligem speichern mÃ¶glich.', 'wpsg'); ?></p>
-		<?php } ?> 
+		<?php } ?>
 	
 		<div class="wpsg_clear"></div><br />
Index: /views/mods/mod_produktbilder/produkt_edit_list_MT.phtml
===================================================================
--- /views/mods/mod_produktbilder/produkt_edit_list_MT.phtml	(revision 6247)
+++ /views/mods/mod_produktbilder/produkt_edit_list_MT.phtml	(revision 6248)
@@ -11,7 +11,7 @@
 	<?php foreach ($this->view['ProduktBilder_MT'] as $b) { ?>
 	
-		<div class="wpsg_mod_produktbilder_admin_bild">
+		<div id="produktbild_div_<?php echo $b['pid']; ?>" class="wpsg_mod_produktbilder_admin_bild">
 
-			<a onclick="return wpsg_remove_bild_MT('<?php echo $b['pid']; ?>');" href="#" title="<?php echo __('Dieses Bild lÃ¶schen.', 'wpsg'); ?>">
+			<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>
