Index: /controller/wpsg_AdminController.class.php
===================================================================
--- /controller/wpsg_AdminController.class.php	(revision 7156)
+++ /controller/wpsg_AdminController.class.php	(revision 7159)
@@ -303,15 +303,4 @@
 				$this->shop->update_option('dataprotectioncommissioner_mailtext', $_REQUEST['dataprotectioncommissioner_mailtext'], false, true);
 				$this->shop->update_option('dataprotectioncommissioner_texts', $_REQUEST['dataprotectioncommissioner_texts'], false, true);
-
-				$this->shop->update_option('wpsg_customerdatadelete_complete', $_REQUEST['wpsg_customerdatadelete_complete'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_completeeinheit', $_REQUEST['wpsg_customerdatadelete_completeeinheit'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_storno', $_REQUEST['wpsg_customerdatadelete_storno'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_stornoeinheit', $_REQUEST['wpsg_customerdatadelete_stornoeinheit'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_uncomplete', $_REQUEST['wpsg_customerdatadelete_uncomplete'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_uncompleteeinheit', $_REQUEST['wpsg_customerdatadelete_uncompleteeinheit'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_abos', $_REQUEST['wpsg_customerdatadelete_abos'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_aboseinheit', $_REQUEST['wpsg_customerdatadelete_aboseinheit'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_rechnung', $_REQUEST['wpsg_customerdatadelete_rechnung'], false, true);
-				$this->shop->update_option('wpsg_customerdatadelete_rechnungeinheit', $_REQUEST['wpsg_customerdatadelete_rechnungeinheit'], false, true);
 				
 				$this->shop->update_option('wpsg_shopdata_bank_name', $_REQUEST['wpsg_shopdata_bank_name'], false, true);
@@ -2081,15 +2070,6 @@
 				$this->update_option('dataprotectioncommissioner_cookietext', $_REQUEST['dataprotectioncommissioner_cookietext']);
 
-				$this->update_option('wpsg_customerdatadelete_complete', $_REQUEST['wpsg_customerdatadelete_complete']);
-				$this->update_option('wpsg_customerdatadelete_completeeinheit', $_REQUEST['wpsg_customerdatadelete_completeeinheit']);
-				$this->update_option('wpsg_customerdatadelete_storno', $_REQUEST['wpsg_customerdatadelete_storno']);
-				$this->update_option('wpsg_customerdatadelete_stornoeinheit', $_REQUEST['wpsg_customerdatadelete_stornoeinheit']);
-				$this->update_option('wpsg_customerdatadelete_uncomplete', $_REQUEST['wpsg_customerdatadelete_uncomplete']);
-				$this->update_option('wpsg_customerdatadelete_uncompleteeinheit', $_REQUEST['wpsg_customerdatadelete_uncompleteeinheit']);
-				$this->update_option('wpsg_customerdatadelete_abos', $_REQUEST['wpsg_customerdatadelete_abos']);
-				$this->update_option('wpsg_customerdatadelete_aboseinheit', $_REQUEST['wpsg_customerdatadelete_aboseinheit']);
-				$this->update_option('wpsg_customerdatadelete_rechnung', $_REQUEST['wpsg_customerdatadelete_rechnung']);
-				$this->update_option('wpsg_customerdatadelete_rechnungeinheit', $_REQUEST['wpsg_customerdatadelete_rechnungeinheit']);
-				
+                $this->shop->update_option('wpsg_customerdatadelete', $_REQUEST['wpsg_customerdatadelete']);
+                $this->shop->update_option('wpsg_customerdatadelete_unit', $_REQUEST['wpsg_customerdatadelete_unit']);
 				
 				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
Index: /controller/wpsg_ShopController.class.php
===================================================================
--- /controller/wpsg_ShopController.class.php	(revision 7156)
+++ /controller/wpsg_ShopController.class.php	(revision 7159)
@@ -166,4 +166,55 @@
 		}
 
+		public function wpsg_daily_hook() {
+		    
+		    $wpsg_customerdatadelete = $this->get_option('wpsg_customerdatadelete');
+		    
+		    if (wpsg_isSizedInt($wpsg_customerdatadelete)) {
+		    
+		        switch ($this->get_option('wpsg_customerdatadelete_unit')) {
+		            
+                    case '0': // Tage
+                        
+                        $strQueryHAVING = " GREATEST(`last_login`, `last_order_date`) < DATE_SUB(NOW(), INTERVAL ".wpsg_q($wpsg_customerdatadelete)." DAY) "; break;
+                        
+                    case '1': // Monate
+
+                        $strQueryHAVING = " GREATEST(`last_login`, `last_order_date`) < DATE_SUB(NOW(), INTERVAL ".wpsg_q($wpsg_customerdatadelete)." MONTH) "; break;
+                        
+                    case '2': // Jahre
+
+                        $strQueryHAVING = " GREATEST(`last_login`, `last_order_date`) < DATE_SUB(NOW(), INTERVAL ".wpsg_q($wpsg_customerdatadelete)." YEAR) "; break;
+                        
+                    default: throw new \Exception(__('UngÃŒltige Einheit fÃŒr das automatische Anonymisieren der Kundendaten.', 'wpsg'));
+		            
+                }
+		        
+                $strQuery = "
+                    SELECT
+                        K.`id`, K.`last_login`,
+                        (SELECT O.`cdate` FROM `".WPSG_TBL_ORDER."` AS O WHERE O.`k_id` = K.`id` ORDER BY O.`cdate` DESC LIMIT 1) AS `last_order_date`
+                    FROM
+                        `".WPSG_TBL_KU."` AS K
+                    WHERE
+                        K.`status` != -1		            
+                    HAVING
+                        ".$strQueryHAVING."  
+                ";
+                 
+                $arCustomerID = $this->db->fetchAssoc($strQuery);
+                 wpsg_debug($arCustomerID);               
+                foreach ($arCustomerID as $row_c) {
+                    
+                    $oCustomer = wpsg_customer::getInstance($row_c['id']);
+                    $oCustomer->anonymize();
+                    
+                }
+                
+            }
+		    
+		    die("-");
+		    
+        } // public function wpsg_daily_hook()
+		
 		/**
 		 * Wird bei der erstmaligen Installation des Plugins aufgerufen
@@ -384,5 +435,5 @@
 			$this->checkDefault('wpsg_preisangaben', WPSG_BRUTTO);
 			$this->checkDefault('wpsg_preisangaben_frontend', WPSG_BRUTTO);
-
+			
 		} // public function install()
 
Index: /lib/wpsg_db.class.php
===================================================================
--- /lib/wpsg_db.class.php	(revision 7156)
+++ /lib/wpsg_db.class.php	(revision 7159)
@@ -218,8 +218,25 @@
 		 * Aktualisiert Zeilen in der Datenbank anhand des $where Selectse
 		 */
-		function UpdateQuery($table, $data, $where)
-		{
-			
-			global $wpdb;
+		function UpdateQuery($table, $data, $where, $checkCols = false)
+		{
+			
+			global $wpdb;
+
+            /**
+             * Wenn diese Option aktiv ist, so werden Spalten nur importiert
+             * wenn sie auch in der Zieltabelle existieren.
+             */
+            if ($checkCols === true)
+            {
+
+                $arFields = $this->fetchAssoc("SHOW COLUMNS FROM `".wpsg_q($table)."` ");
+
+                $arCols = array();
+                foreach ($arFields as $f) { $arCols[] = $f['Field']; }
+                foreach ($data as $k => $v) { if (!in_array($k, $arCols)) { unset($data[$k]); } }
+
+            }
+            
+            if (!wpsg_isSizedArray($data)) throw new \Exception(__('Update ohne Daten?', 'wpsg'));
 			
 			// Query aufbauen, da wir den kompletten QueryWHERE String als String ÃŒbergeben
Index: /model/wpsg_customer.class.php
===================================================================
--- /model/wpsg_customer.class.php	(revision 7156)
+++ /model/wpsg_customer.class.php	(revision 7159)
@@ -27,4 +27,63 @@
 		} // public function load($id)
 
+        public function anonymize() {
+		    
+		    $arOrder = wpsg_Order::find(['k_id' => $this->id]);
+		    $arAdressID = [];
+		    
+		    foreach ($arOrder as $oOrder) {
+		        
+		        if ($oOrder->adress_id > 0) $arAdressID[] = $oOrder->adress_id;
+		        if ($oOrder->shipping_adress_id > 0) $arAdressID[] = $oOrder->shipping_adress_id;
+		     
+		        $this->db->Query("DELETE FROM `".WPSG_TBL_ORDER."` WHERE `o_id` = '".wpsg_q($oOrder->id)."' ");
+		        
+            }
+            
+            $arAdressID = array_unique($arAdressID);
+		    
+		    if (wpsg_isSizedArray($arAdressID)) {
+		        
+		        $this->db->UpdateQuery(WPSG_TBL_ADRESS, [
+		            'title' => '',
+                    'name' => '----',
+                    'vname' => '----',
+                    'firma' => '----',
+                    'fax' => '----',
+                    'strasse' => '----',
+                    'nr' => '----',
+                    'plz' => '----',
+                    'ort' => '----',
+                    'land' => '----',
+                    'tel' => '----',
+                ], " `id` IN (".wpsg_q(implode(',', $arAdressID)).") ");
+		        
+            }
+            
+            if (intval($this->wp_user_id) > 0) {
+
+                wp_delete_user($this->wp_user_id);
+		        
+            }
+            
+            $this->db->UpdateQuery(WPSG_TBL_KU, [
+                'paypal_payer_id' => '----',
+                'geb' => '0000-00-00',
+                'email' => '----',
+                'ustidnr' => '----',
+                'custom' => '----',
+                'passwort_saltmd5' => '',
+                'comment' => '',
+                'wp_user_id' => '',
+                'group_id' => '',
+                'wpsg_mod_statistics_long' => '----',
+                'wpsg_mod_statistics_lat' => '----',
+                'deleted' => '1',
+                'status' => '-1',
+                'anonymized' => 'NOW()'
+            ], " `id` = '".wpsg_q($this->id)."' ", true);
+		    
+        } // public function anonymize()
+        
 		/**
 		 * Aktuallisiert den Adressdatensatz
Index: /mods/wpsg_mod_kundenverwaltung.class.php
===================================================================
--- /mods/wpsg_mod_kundenverwaltung.class.php	(revision 7156)
+++ /mods/wpsg_mod_kundenverwaltung.class.php	(revision 7159)
@@ -42,7 +42,8 @@
 			 			
 			// Grundeinstellung Pro Seite
-			if ($this->shop->get_option('wpsg_mod_kundenverwaltung_perpage') === false || $this->shop->get_option('wpsg_mod_kundenverwaltung_perpage') == '')
-			{
+			if ($this->shop->get_option('wpsg_mod_kundenverwaltung_perpage') === false || $this->shop->get_option('wpsg_mod_kundenverwaltung_perpage') == '') {
+			    
 				$this->shop->update_option('wpsg_mod_kundenverwaltung_perpage', '20');
+				
 			}
 			
@@ -58,5 +59,7 @@
 		   		comment TEXT NOT NULL,
 		   		wp_user_id INT(11) DEFAULT 0 NOT NULL,		   		
-				status VARCHAR(255) NOT NULL
+				status VARCHAR(255) NOT NULL,
+				last_login DATETIME NOT NULL COMMENT 'Datum des letzten Logins',
+				anonymized DATETIME NOT NULL COMMENT 'Datum der Anonymisierung'
 		   	) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
    	   	 
@@ -68,5 +71,7 @@
    			$this->shop->checkDefault('wpsg_mod_kundenverwaltung_redirectLogout', '0');
 			$this->shop->checkDefault('wpsg_mod_kundenverwaltung_loginZwang', '1');
-   			
+
+            $this->db->UpdateQuery(WPSG_TBL_KU, ['last_login' => 'NOW()'], " `last_login` = '0000-00-00 00:00:00' ");
+			
 		} // public function install()
 		
@@ -2157,8 +2162,11 @@
 				WHERE
 					C.`id` = '".wpsg_q($kunde_id)."' AND
-					C.`deleted` != '1'
+					C.`deleted` != '1' AND
+					C.`status` != '0' AND C.`status` != '-1'
 			");
 				
 			if ($kunde['id'] != $kunde_id) return;
+			
+			$this->db->UpdateQuery(WPSG_TBL_KU, ['last_login' => 'NOW()'], " `id` = '".wpsg_q($kunde['id'])."' ");
 			
 			$kunde['custom'] = @unserialize($kunde['customin']);
Index: /views/admin/dataprotection.phtml
===================================================================
--- /views/admin/dataprotection.phtml	(revision 7156)
+++ /views/admin/dataprotection.phtml	(revision 7159)
@@ -47,37 +47,7 @@
   			<div class="panel-body">	
 						
-				<?php /* periodisches LÃ¶schen der persÃ¶nlichen Daten */ ?>
-				<?php echo wpsg_drawForm_Input ('wpsg_customerdatadelete_complete', __('vollstÃ€ndig abgeschlossene Bestellungen', 'wpsg'), $this->get_option('wpsg_customerdatadelete_complete'));?>	
-				<?php echo wpsg_drawForm_Select('wpsg_customerdatadelete_completeeinheit', __('Einheit', 'wpsg'), array('0' => __('Tag(e)', 'wpsg'), '1' => __('Monat(e)', 'wpsg'), '2' => __('Jahr(e)', 'wpsg')), $this->get_option('wpsg_customerdatadelete_completeeinheit')); ?>
-				
-				<br />
-				
-				<?php echo wpsg_drawForm_Input ('wpsg_customerdatadelete_storno', __('stonierte Bestellungen', 'wpsg'), $this->get_option('wpsg_customerdatadelete_storno')); ?>
-				<?php echo wpsg_drawForm_Select('wpsg_customerdatadelete_stornoeinheit', __('Einheit', 'wpsg'), array('0' => __('Tag(e)', 'wpsg'), '1' => __('Monat(e)', 'wpsg'), '2' => __('Jahr(e)', 'wpsg')), $this->get_option('wpsg_customerdatadelete_stornoeinheit')); ?>
-				
-				<br />
-				
-				<?php /* TODO: Abfrage greift nicht */ ?>
-				<?php if ($this->get_option('wpsg_showincompleteorder') == '1') { ?>
-					<?php echo wpsg_drawForm_Input ('wpsg_customerdatadelete_uncomplete', __('unvollstÃ€ndige Bestellungen', 'wpsg'), $this->get_option('wpsg_customerdatadelete_uncomplete')); ?>
-					<?php echo wpsg_drawForm_Select('wpsg_customerdatadelete_uncompleteeinheit', __('Einheit', 'wpsg'), array('0' => __('Tag(e)', 'wpsg'), '1' => __('Monat(e)', 'wpsg'), '2' => __('Jahr(e)', 'wpsg')), $this->get_option('wpsg_customerdatadelete_uncompleteeinheit')); ?>
-				<?php } ?>	
-					
-				<br />	
-					
-				<?php /* Abomodul aktiv */ ?>
-				<?php if ($this->hasMod('wpsg_mod_abo') == '1') { ?>
-					<?php echo wpsg_drawForm_Input ('wpsg_customerdatadelete_abos', __('gekÃŒndigte Abos', 'wpsg'), $this->get_option('wpsg_customerdatadelete_abos')); ?>
-					<?php echo wpsg_drawForm_Select('wpsg_customerdatadelete_aboseinheit', __('Einheit', 'wpsg'), array('0' => __('Tag(e)', 'wpsg'), '1' => __('Monat(e)', 'wpsg'), '2' => __('Jahr(e)', 'wpsg')), $this->get_option('wpsg_customerdatadelete_aboseinheit')); ?>
-				<?php } ?>
-	
-				<br />
-				
-				<?php /* Rechnungsmodul aktiv*/ ?>
-				<?php if ($this->hasMod('wpsg_mod_rechnungen') == '1') { ?>
-					<?php echo wpsg_drawForm_Input ('wpsg_customerdatadelete_rechnung', __('Rechnungen geschrieben', 'wpsg'), $this->get_option('wpsg_customerdatadelete_complete')); ?>
-					<?php echo wpsg_drawForm_Select('wpsg_customerdatadelete_rechnungeinheit', __('Einheit', 'wpsg'), array('0' => __('Tag(e)', 'wpsg'), '1' => __('Monat(e)', 'wpsg'), '2' => __('Jahr(e)', 'wpsg')), $this->get_option('wpsg_customerdatadelete_rechnungeinheit')); ?>
-				<?php } ?>
-				
+                <?php echo wpsg_drawForm_Input('wpsg_customerdatadelete', __('Letzte AktivitÃ€t Ã€lter als', 'wpsg'), $this->get_option('wpsg_customerdatadelete'));?>
+                <?php echo wpsg_drawForm_Select('wpsg_customerdatadelete_unit', __('Einheit', 'wpsg'), array('0' => __('Tag(e)', 'wpsg'), '1' => __('Monat(e)', 'wpsg'), '2' => __('Jahr(e)', 'wpsg')), $this->get_option('wpsg_customerdatadelete_unit')); ?>
+								
 			</div>
 			
Index: /views/mods/mod_kundenverwaltung/edit.phtml
===================================================================
--- /views/mods/mod_kundenverwaltung/edit.phtml	(revision 7156)
+++ /views/mods/mod_kundenverwaltung/edit.phtml	(revision 7159)
@@ -84,5 +84,5 @@
                         	<?php echo wpsg_drawForm_Input('ustidnr', __('UStIdNr.', 'wpsg'), @$this->view['data']['ustidnr']); ?>
                         <?php } ?>
-                        <?php echo wpsg_drawForm_Select('status', __('Status', 'wpsg'), array('inaktiv', 'aktiv'), @$this->view['data']['status'], array()); ?>
+                        <?php echo wpsg_drawForm_Select('status', __('Status', 'wpsg'), ['1' => __('Aktiv', 'wpsg'), '0' => __('Inaktiv', 'wpsg'), '-1' => __('Anonymisiert')], @$this->view['data']['status'], array()); ?>
                         <?php echo wpsg_drawForm_Checkbox('info-mail', __('Mail bei StatusÃ€nderung', 'wpsg'), '', array()); ?>
                         <?php echo wpsg_drawForm_Textarea('comment', __('Kundenkommentar', 'wpsg'), @$this->view['data']['comment']); ?>
@@ -120,5 +120,5 @@
                         </div>
 					<?php echo wpsg_drawForm_AdminboxEnd(); ?>
-
+                    
 					<?php if (wpsg_isSizedInt($this->view['data']['id'])) { ?>
 					<?php echo wpsg_drawForm_AdminboxStart(__('Information', 'wpsg')) ?>
@@ -133,13 +133,37 @@
 						<?php echo wpsg_drawForm_TextEnd(__('Bestellungen', 'wpsg'), array('noP' => true)); ?>
 
-						<?php echo wpsg_drawForm_TextStart(); ?>
-						<p>
-							<a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_kundenverwaltung&noheader=1&be_ajax=su&k_id=<?php echo $this->view['data']['id']; ?>"><?php echo __('Kundenlogin simulieren', 'wpsg'); ?></a>
-						</p>
-						<?php echo wpsg_drawForm_TextEnd(__('Kunden Login', 'wpsg'), array('noP' => true)); ?>
-
-						<?php echo wpsg_drawForm_TextStart(); ?>
-						<p><?php echo wpsg_formatTimestamp(strtotime($this->view['data']['lastorder'])); ?></p>
-						<?php echo wpsg_drawForm_TextEnd(__('Letzte Bestellung', 'wpsg'), array('noP' => true)); ?>
+                        <?php if ($this->view['data']['status'] !== '-1') { ?>
+						
+                            <?php echo wpsg_drawForm_TextStart(); ?>
+                            <p>
+                                <a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_kundenverwaltung&noheader=1&be_ajax=su&k_id=<?php echo $this->view['data']['id']; ?>"><?php echo __('Kundenlogin simulieren', 'wpsg'); ?></a>
+                            </p>
+                            <?php echo wpsg_drawForm_TextEnd(__('Kunden Login', 'wpsg'), array('noP' => true)); ?>
+                        
+                        <?php } ?>
+
+                        <?php if (wpsg_isSizedInt($this->view['data']['countOrder'])) { ?>
+						
+                            <?php echo wpsg_drawForm_TextStart(); ?>
+						    <p><?php echo wpsg_formatTimestamp(strtotime($this->view['data']['lastorder'])); ?></p>
+						    <?php echo wpsg_drawForm_TextEnd(__('Letzte Bestellung', 'wpsg'), array('noP' => true)); ?>
+                            
+                        <?php } ?>
+
+                        <?php if (strtotime($this->view['data']['anonymized']) > 0) { ?>
+
+                            <?php echo wpsg_drawForm_TextStart(); ?>
+                            <p><?php echo wpsg_formatTimestamp(strtotime($this->view['data']['anonymized'])); ?></p>
+                            <?php echo wpsg_drawForm_TextEnd(__('Anonymisiert am', 'wpsg'), array('noP' => true)); ?>
+                            
+                        <?php } ?>
+
+                        <?php if (strtotime($this->view['data']['last_login']) > 0) { ?>
+                        
+                            <?php echo wpsg_drawForm_TextStart(); ?>
+                            <p><?php echo wpsg_formatTimestamp(strtotime($this->view['data']['last_login'])); ?></p>
+                            <?php echo wpsg_drawForm_TextEnd(__('Letzte Anmeldung', 'wpsg'), array('noP' => true)); ?>
+                            
+                        <?php } ?>
 
 						<?php if ($this->hasMod('wpsg_mod_statistics')) { ?>
Index: /views/mods/mod_kundenverwaltung/index.phtml
===================================================================
--- /views/mods/mod_kundenverwaltung/index.phtml	(revision 7156)
+++ /views/mods/mod_kundenverwaltung/index.phtml	(revision 7159)
@@ -158,6 +158,10 @@
                                     |
                                     <span class="order"><a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&filter%5Bk_id%5D=<?php echo $c->id; ?>"><?php echo __('Bestellungen einsehen', 'wpsg'); ?></a></span>
+                                    
+                                    <?php if ($c->status !== '-1') { ?>
                                     |
                                     <span class="order"><a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_kundenverwaltung&noheader=1&be_ajax=su_index&k_id=<?php echo $c->id; ?>"><?php echo __('Kundenlogin simulieren', 'wpsg'); ?></a></span>
+                                    <?php } ?>
+                                    
                                 </div>
                             </td>
Index: /wpshopgermany.php
===================================================================
--- /wpshopgermany.php	(revision 7156)
+++ /wpshopgermany.php	(revision 7159)
@@ -241,8 +241,9 @@
 	}
 
+    if (!wp_next_scheduled('wpsg_daily_hook')) wp_schedule_event(time(), 'daily', 'wpsg_daily_hook');
+		
 	add_action('init', [$GLOBALS['wpsg_sc'], 'init']);
 	add_action('widgets_init', array($GLOBALS['wpsg_sc'], 'widget_init'));
-	
+    add_action('wpsg_daily_hook', [$GLOBALS['wpsg_sc'], 'wpsg_daily_hook']);
+    
 	$GLOBALS['wpsg_sc']->callMods('load', array());
-
-?>
