Index: /lib/wpsg_basket.class.php
===================================================================
--- /lib/wpsg_basket.class.php	(revision 6090)
+++ /lib/wpsg_basket.class.php	(revision 6091)
@@ -718,5 +718,6 @@
 					
 					$customer_data['adress_id'] = wpsg_q($this->db->ImportQuery(WPSG_TBL_ADRESS, $adress_data));
-										
+					$update_customer_data['adress_id'] = $customer_data['adress_id'];
+					
 				}
 				else
@@ -844,4 +845,23 @@
 				$this->shop->callMods('basket_save_order', array(&$data, &$this->arCheckout, &$arBasket, $finish_order));
 				
+				if (($finish_order === true) && (wpsg_getStr($checkout['diff_shippingadress']) == '1'))
+				{	//TODO Gesonderte Lieferadresse speichern
+					
+					$adata['cdate'] = 'NOW()';
+
+					$adata['title'] 	= $data['shipping_title'];
+					$adata['vname'] 	= $data['shipping_vname'];
+					$adata['name'] 		= $data['shipping_name'];
+					$adata['strasse'] 	= $data['shipping_strasse'];
+					$adata['plz'] 		= $data['shipping_plz'];
+					$adata['ort'] 		= $data['shipping_ort'];
+					$adata['firma'] 	= $data['shipping_firma'];
+					$adata['land'] 		= $data['shipping_land'];
+					
+					$data['shipping_adress_id'] = wpsg_q($this->db->ImportQuery(WPSG_TBL_ADRESS, $adata));
+						
+				}
+				$data['adress_id'] = $customer_data['adress_id'];
+				
 				$data['custom_data']['basket']['oOrder'] = Array();
 				//unset($data['custom_data']['basket']['oOrder']['shop']);
Index: /model/wpsg_order.class.php
===================================================================
--- /model/wpsg_order.class.php	(revision 6090)
+++ /model/wpsg_order.class.php	(revision 6091)
@@ -538,6 +538,6 @@
 		{
 			 
-			if ($this->adress_data === false) $title = $this->data['title'];
-			else $title = $this->adress_data['title'];
+			if ($this->adress_data === false) $title = wpsg_getStr($this->data['title']);
+			else $title = wpsg_getStr($this->adress_data['title']);
 			
 			if ($title == "-1") return "";
Index: /mods/wpsg_mod_kundenverwaltung.class.php
===================================================================
--- /mods/wpsg_mod_kundenverwaltung.class.php	(revision 6090)
+++ /mods/wpsg_mod_kundenverwaltung.class.php	(revision 6091)
@@ -1184,4 +1184,5 @@
 				
 				$kunde_data = $this->shop->cache->loadKunden($kunde_id);
+				if ($kunde_data['email'] == '') return false;
 				
 				$wp_user_id = wp_create_user($kunde_data['email'], $pwd, $kunde_data['email']);
Index: /mods/wpsg_mod_produktbilder.class.php
===================================================================
--- /mods/wpsg_mod_produktbilder.class.php	(revision 6090)
+++ /mods/wpsg_mod_produktbilder.class.php	(revision 6091)
@@ -47,4 +47,5 @@
 			
 				wp_enqueue_script('wpsg_ajaxupload', $this->shop->getRessourceURL('js/ajaxupload.js'));
+				wp_enqueue_media();
 				
 			}
@@ -136,4 +137,5 @@
 		public function produkt_ajax() 
 		{
+			global $wpdb;
 			
 			if (wpsg_isSizedString($_REQUEST['cmd'], 'clearProductCache'))
@@ -199,6 +201,111 @@
 				
 			}
+			else if ($_REQUEST['cmd'] == 'upload2')
+			{
+				// Mediathek
+				
+				$fname = $_FILES['userfile']['name'][0];
+
+				$filetype = wp_check_filetype( basename( $fname ), null );
+				$wp_upload_dir = wp_upload_dir();
+				$attachment = array(
+						'guid'           => $wp_upload_dir['url'] . '/' . basename( $fname ),
+						'post_mime_type' => $filetype['type'],
+						'post_title'     => 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);
+				$p2 = get_attached_file( $attachment_id ); // Full path
+				$p3 = get_attachment_link( $attachment_id );
+				$p4 = get_the_title( $attachment_id );
+				$p5 = get_post_type($attachment_id);
+				$p6 = get_post($attachment_id);
+				$p7 = wp_get_attachment_image_src($attachment_id, 'thumbnail');	// Array mit Full-Path, Width, Height
+				
+				//$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");
+				
+			}
+			else if ($_REQUEST['cmd'] == 'remove2')
+			{
+			
+				//unlink($this->getPicPath($_REQUEST['edit_id']).'/'.$_REQUEST['file']);
+				if ($_REQUEST['delmt'] == true)	// Auch in der Mediathek lÃ¶schen
+					wp_delete_post( $_REQUEST['pid'], true );
+				
+				if ($_REQUEST['del'] == 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->getProduktBilderListe2($_REQUEST['edit_id']));
+			
+			}
+			else if ($_REQUEST['cmd'] == 'uploadmt')
+			{
+				//die('uploadmt');
+				
+				add_post_meta( $_REQUEST['post']['id'], 'wpsg_produkt_id', $_REQUEST['edit_id'] );
+				
+				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
+				die($this->getProduktBilderListe2($_REQUEST['edit_id']));
+				
+			}
+			else if ($_REQUEST['cmd'] == 'produktbilder_liste2')
+			{
+			
+				$this->shop->view['data']['id'] = $_REQUEST['edit_id'];
+				//$content = $this->getProduktBilderListe($_REQUEST['edit_id']);
+				die($this->getProduktBilderListe2($_REQUEST['edit_id']));
+				
+			}
 			
 		} // 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) 
@@ -255,4 +362,6 @@
 				$this->shop->view['ProduktList'] = $this->getProduktBilderListe($product_data['id']);
 			
+				$this->shop->view['ProduktList2'] = $this->getProduktBilderListe2($product_data['id']);
+				
 			}
 			
@@ -297,5 +406,5 @@
 		public function produkt_copy(&$produkt_id, &$copy_id) { 
 			
-			// Wie bei der erstellung einer neuen Ãbersetzung ...
+			// Wie bei der Erstellung einer neuen Ãbersetzung ...
 			$this->produkt_createTranslation($produkt_id, $copy_id);
 			
@@ -325,4 +434,38 @@
 			
 		} // 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 getProduktBilderListe2($produkt_id)
+		{
+			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."posts` WHERE `wpsg_produkt_id` = '".wpsg_q($produkt_id)."' ");
+			
+			$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['ProduktBilder2'][$i]['fname'] = $arrf['basename'];
+				$guid = $arrf['dirname'].'/'.$arrf['filename'].'-150x150.'.$arrf['extension'];
+				*/
+				$p = wp_get_attachment_image_src($val['post_id'], 'thumbnail');	// Array mit Full-Path, Width, Height
+				$guid = $p[0];
+				$arrf = pathinfo($guid);
+				$this->shop->view['ProduktBilder2'][$i]['pid'] = $val['post_id'];
+				$this->shop->view['ProduktBilder2'][$i]['fname'] = $arrf['basename'];
+				$this->shop->view['ProduktBilder2'][$i]['guid'] = $guid;
+				$i++;
+			}
+			
+			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_produktbilder/produkt_edit_list2.phtml', false);
+				
+		} // public function getProduktBilderListe2($produkt_id)
 		
 		/**
@@ -372,5 +515,5 @@
 		
 		/**
-		 * Gibt eien Array mit den Produktbildern zurÃŒck
+		 * Gibt ein Array mit den Produktbildern zurÃŒck
 		 */
 		public function getProduktBilder($produkt_id)
@@ -662,5 +805,5 @@
 		
 		/**
-		 * Bestimmt die GrÃ¶Ãe im SeitenverhÃ€ltnis fÃŒr skallierte Bilder
+		 * Bestimmt die GrÃ¶Ãe im SeitenverhÃ€ltnis fÃŒr skalierte Bilder
 		 */
 		private function getNewSize($w, $h, $maxW, $maxH)
@@ -670,6 +813,6 @@
 		    {
 		    	
-				// Breite skallieren und schauen ob HÃ¶he reinpasst   		
-		    	// Bild ist breiter als hoch -> versuchen nach breite zu skallieren
+				// Breite skalieren und schauen ob HÃ¶he reinpasst   		
+		    	// Bild ist breiter als hoch -> versuchen nach Breite zu skalieren
 		    	$newWidth = $maxW;
 		    	$newHeight = ($maxW / $w) * $h;
@@ -678,6 +821,6 @@
 		    	{
 		    		
-		    		// Bild ist nach skallierung auf Breite zu hoch ! 
-		    		// jetzt noch auf HÃ¶he skallieren
+		    		// Bild ist nach Skalierung auf Breite zu hoch ! 
+		    		// jetzt noch auf HÃ¶he skalieren
 		    		$newWidth = ($maxH / $newHeight) * $maxW;
 		    		$newHeight = $maxH;  
@@ -689,5 +832,5 @@
 		    {
 		    	
-		    	// Nach HÃ¶he skallieren
+		    	// Nach HÃ¶he skalieren
 		    	$newHeight = $maxH;
 		    	$newWidth = ($maxH / $h) * $w;
@@ -696,5 +839,5 @@
 		    	{
 		    		
-		    		// Bild ist nach skallierung auf HÃ¶he zu schmal !
+		    		// Bild ist nach Skalierung auf HÃ¶he zu schmal !
 		    		// jetzt Breite anpassen
 		    		$newHeight = ($maxW / $newWidth) * $maxH;
Index: /views/mods/mod_produktbilder/produkt_addedit_content.phtml
===================================================================
--- /views/mods/mod_produktbilder/produkt_addedit_content.phtml	(revision 6090)
+++ /views/mods/mod_produktbilder/produkt_addedit_content.phtml	(revision 6091)
@@ -26,4 +26,25 @@
 </div>
 
+<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()); ?>
+                <?php echo wpsg_drawForm_Checkbox('dialog_produktbilder_del', __('Produktzuordnung 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_bild2OK();"><?php echo __('LÃ¶schen', 'wpsg'); ?></button>
+            </div>
+        </div>
+    </div>
+</div>
+
 
 <div class="panel panel-default">
@@ -149,4 +170,171 @@
 			
 		<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>
+		
+		<!--  Mediathek -->
+		<hr>
+			<div id="produktbilder_target2"><?php echo $this->view['ProduktList2']; ?></div>
+			
+			<input value="WPmedia" class="button" type="text" style="text-align:center;" size="10" id="btnAddImgLink" />
+			<input value="Upload2" class="button" type="text" style="text-align:center;" size="10" id="upload_button2" />
+
+			<script type="text/javascript">/* <![CDATA[ */
+				jQuery(document).ready(function() {									
+					new AjaxUpload(
+						"upload_button2", {
+							action: "<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=upload2&edit_id=<?php echo $this->view['data']['id']; ?>&noheader=1",
+							onSubmit: function(file, extension) {
+
+								jQuery('#produktbilder_target2').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_target2").load("<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=ajax&mod=wpsg_mod_produktbilder&cmd=produktbilder_liste2&edit_id=<?php echo $this->view['data']['id']; ?>&noheader=1");
+
+									//jQuery('#produktbilder_target2').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_bild2(pid) {
+
+					post_id = pid;
+					//jQuery('#wpsg_produktbilder_remove').show();
+					jQuery('#wpsg_produktbilder_remove').modal( { } );
+					//jQuery('#wpsg_produktbilder_remove').modal('hide');
+					
+				}
+				
+				function wpsg_remove_bild2OK() {
+
+					delmt = jQuery('#dialog_produktbilder_delmt').is(':checked');
+					del = jQuery('#dialog_produktbilder_del').is(':checked');
+					
+					jQuery('#wpsg_produktbilder_remove').modal('hide');
+
+					jQuery('#produktbilder_target2').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=remove2&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_target2').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: false  // Set to true to allow multiple files to be selected
+					    });
+
+					    // When an image is selected in the media frame...
+					    wpframe.on( 'select', function() {
+						    // 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_target2').html(data);
+
+								}
+							} );
+					      
+					    });
+
+					    // Finally, open the modal on click
+					    wpframe.open();
+					  });
+					  
+					  // 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( '' );
+
+					  });
+
+				});      
+				
+			/* ]]> */</script>
 						
 	</div>
Index: /views/mods/mod_produktbilder/produkt_edit_list2.phtml
===================================================================
--- /views/mods/mod_produktbilder/produkt_edit_list2.phtml	(revision 6091)
+++ /views/mods/mod_produktbilder/produkt_edit_list2.phtml	(revision 6091)
@@ -0,0 +1,28 @@
+<?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 } ?>
+    
