<?php

	/**
	 * AdminController für Backend 
	 */
	class wpsg_AdminController extends wpsg_SystemController 
	{
		
		/**
		 * Übernimmt das Routing
		 */
		public function dispatch()
		{
			
			parent::dispatch();
						
			if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'module')
			{
				
				$this->moduleAction();
				
			}
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'hilfe')
			{
				
				$this->hilfeAction();
				
			}
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'migratemwst')
			{
				
				$this->migratemwstAction();
				
			}
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'ueber')
			{
				
				$this->ueberAction();
				
			}
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'news')
			{
				
				$this->newsAction();
				
			}
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'registrierung')
			{
				
				if (!current_user_can('wpsg_lizence')) die(__('Kein Zugriff', 'wpsg'));
				
				$this->registrierungAction();
				
			}	 
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'clearMessage')
			{
				
				$this->shop->hidePersistentBackendError($_REQUEST['wpsg_message']);
				
				$this->shop->clearMessages();
				$this->shop->redirect(rawurldecode($_REQUEST['wpsg_redirect']));
				
			}	
			else if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'importV2')
			{
				
				$this->importV2();
				
			}
			else
			{
							
				$this->indexAction();
				
			}
			
		} // public function dispatch()
		
		/**
		 * Index des Backends
		 */
		public function indexAction()
		{
			
			$this->shop->view = array(
				'actionName' => 'index',
				'subTemplate' => WPSG_PATH_VIEW.'/admin/konfiguration.phtml'
			);
			
			$this->shop->view['arSubAction'] = array();
			$this->shop->view['arSubAction']['allgemein'] = array(
				'Menutext' => __('Allgemein', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/konfiguration.phtml'
			);			
			$this->shop->view['arSubAction']['shopdata'] = array(
				'Menutext' => __('Shopinfo', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/shopdata.phtml'
			);
			$this->shop->view['arSubAction']['extended'] = array(
				'Menutext' => __('Erweitert', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/extended.phtml'
			);
			$this->shop->view['arSubAction']['presentation'] = array(
				'Menutext' => __('Darstellung', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/presentation.phtml'
			);
			$this->shop->view['arSubAction']['loadsavesettings'] = array(
				'Menutext' => __('Einstellungen sichern', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/loadsavesettings.phtml'
			);
						
			if ($this->shop->isMultiBlog() && is_super_admin())
			{
				
				$this->shop->view['arSubAction']['blognetzwerk'] = array(
					'Menutext' => __('Blognetzwerk', 'wpsg'),
					'subTemplate' => WPSG_PATH_VIEW.'/admin/blognetzwerk.phtml'
				);	

				// Wenn da später mal mehr drin ist als der Multiblog Pfad dann sollte das aus dem If raus!
				$this->shop->view['arSubAction']['path'] = array(
					'Menutext' => __('Pfade', 'wpsg'),
					'subTemplate' => WPSG_PATH_VIEW.'/admin/path.phtml'
				);
				
			}
			
			$this->shop->view['arSubAction']['kalkulation'] = array(
				'Menutext' => __('Preiskalkulation', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/kalkulation.phtml'
			);
			$this->shop->view['arSubAction']['access'] = array(
				'Menutext' => __('Berechtigungen', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/access.phtml'
			);
			$this->shop->view['arSubAction']['widerrufsbelehrung'] = array(
				'Menutext' => __('Widerruf', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/widerrufsbelehrung.phtml'
			);
			$this->shop->view['arSubAction']['includes'] = array(
				'Menutext' => __('Bibliotheken/Includes', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/includes.phtml'
			);			
			$this->shop->view['arSubAction']['seiten'] = array(
				'Menutext' => __('Seitenkonfiguration', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/seiten.phtml'
			);
			$this->shop->view['arSubAction']['customerpreset'] = array(
				'Menutext' => __('Kundenvoreinstellungen', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/customerpreset.phtml'
			);
			$this->shop->view['arSubAction']['kundendaten'] = array(
				'Menutext' => __('Kundendaten', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/kundendaten.phtml'
			);
			$this->shop->view['arSubAction']['emailconf'] = array(
				'Menutext' => __('E-Mail Konfiguration', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/emailconf.phtml'
			);
			$this->shop->view['arSubAction']['vz'] = array(
				'Menutext' => __('Versandzonen', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/versandzonen.phtml'
			);
			$this->shop->view['arSubAction']['laender'] = array(
				'Menutext' => __('Länderverwaltung', 'wpsg'),
				'subTemplate' => WPSG_PATH_VIEW.'/admin/laender.phtml'
			);
			
			if (!$this->shop->isMultiBlog() || is_super_admin())
			{
			
				$this->shop->view['arSubAction']['deinstallieren'] = array(
					'Menutext' => __('Deinstallieren', 'wpsg'),
					'subTemplate' => WPSG_PATH_VIEW.'/admin/deinstall.phtml'
				);
				
			}
			
			if (isset($_REQUEST['submit'])) { $this->submitAction(); }
			
			if (isset($_REQUEST['subaction']))
			{
				
				if (method_exists($this, $_REQUEST['subaction'].'Action')) { call_user_func(array($this, $_REQUEST['subaction'].'Action')); }
				
				$this->shop->view['subAction'] = $_REQUEST['subaction'];
				$this->shop->view['subTemplate'] = $this->shop->view['arSubAction'][$_REQUEST['subaction']]['subTemplate'];
				
			}
			else
			{

				if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'update') { $this->updateAction(); }
				else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'loadHelp') { $this->loadHelpAction(); }
								
				$this->shop->view['subAction'] = 'allgemein';
				
			}
			
			// Korrektur der Serialisierten Einstellungen beim Aufruf der Allgemein Seite
			if ($this->shop->view['subAction'] == 'allgemein')
			{
				
				$arLanguages = $this->shop->getStoreLanguages();
				
				$this->shop->view['arLanguages'] = array();
				
				if (wpsg_isSizedArray($arLanguages))
				{
					
					foreach ($arLanguages as $lang)
					{
					
						$this->shop->view['arLanguages'][$lang['lang']] = $lang['name'];
						
					}
					
				}
								
				$this->CheckAndCorrectSerOption();
				
			}
			
			$this->shop->callMods('admin_index', array($this));
			$this->shop->view['adminController'] = &$this;
			
			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
			
		} // public function indexAction()

		private function downloadLicenceAction()
		{
			
			wpsg_header::startDownloadContent('key.txt', $this->shop->get_option('wpsg_key'));
			
		} // private function downloadLicenceAction()
		
		/**
		 * Beim Speichern und Anzeigen der Shopdatne
		 */
		public function shopdataAction()
		{
			
			if (isset($_REQUEST['submit']))
			{
				
				$this->shop->update_option('wpsg_shopdata_name', $_REQUEST['wpsg_shopdata_name'], false, true); 
				$this->shop->update_option('wpsg_shopdata_owner', $_REQUEST['wpsg_shopdata_owner'], false, true);
				$this->shop->update_option('wpsg_shopdata_tel', $_REQUEST['wpsg_shopdata_tel'], false, true);
				$this->shop->update_option('wpsg_shopdata_fax', $_REQUEST['wpsg_shopdata_fax'], false, true);
				$this->shop->update_option('wpsg_shopdata_email', $_REQUEST['wpsg_shopdata_email'], false, true);
				$this->shop->update_option('wpsg_shopdata_taxnr', $_REQUEST['wpsg_shopdata_taxnr'], false, true);
				$this->shop->update_option('wpsg_shopdata_ustidnr', $_REQUEST['wpsg_shopdata_ustidnr'], false, true);
				
				$this->shop->update_option('wpsg_shopdata_street', $_REQUEST['wpsg_shopdata_street'], false, true);
				$this->shop->update_option('wpsg_shopdata_zip', $_REQUEST['wpsg_shopdata_zip'], false, true);
				$this->shop->update_option('wpsg_shopdata_city', $_REQUEST['wpsg_shopdata_city'], false, true);
				
				$this->shop->update_option('wpsg_shopdata_bank_name', $_REQUEST['wpsg_shopdata_bank_name'], false, true);
				$this->shop->update_option('wpsg_shopdata_bank_owner', $_REQUEST['wpsg_shopdata_bank_owner'], false, true);
				$this->shop->update_option('wpsg_shopdata_bank_iban', $_REQUEST['wpsg_shopdata_bank_iban'], false, true);
				$this->shop->update_option('wpsg_shopdata_bank_bic', $_REQUEST['wpsg_shopdata_bank_bic'], false, true);
				
				$this->addBackendMessage(__('Shopdaten erfolgreich gespeichert.', 'wpsg'));
				
				$this->shop->update_option('wpsg_message_shopdata_change', false);
				
				if ($this->shop->get_option('wpsg_revocationform') != false && !array_key_exists('wpsg_message_shopdata', (array)$_SESSION['wpsg']['backendError']))
				{
				
					$this->shop->addBackendError('nohspc_'.wpsg_translate(
            			__('Die allgemeinen Daten des Shops haben sich verändert, sie sollten das <a href="#1#">Widerrufsformular</a> überprüfen bzw. neu generieren.', 'wpsg'),
						WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=widerrufsbelehrung'
					), 'wpsg_message_shopdata_change');
					
				}
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=shopdata');
				
			}
			
		} // public function shopdataAction()
		
		/**
		 * Lädt die Lizenz in die Datenbank wenn valide
		 */
		public function loadLicenceAction()
		{
		 
			if (file_exists($_FILES['wpsg_licence_file']['tmp_name']))
			{
				 
				if (!file_exists(WPSG_PATH.'/lib/.htpublic'))
				{
					
					$this->addBackendError(base64_decode('w5ZmZmVudGxpY2hlciBTY2hsw7xzc2VsIGV4aXN0aWVydCBuaWNodCE=')); // Öffentlicher Schlüssel existiert nicht!
					
				}
				else
				{
				
					if (!class_exists('Crypt_RSA')) 
					{

						@set_include_path(WPSG_PATH.'/lib/phpseclib0.3.0/'.PATH_SEPARATOR.get_include_path());
						require_once(WPSG_PATH.'/lib/phpseclib0.3.0/Crypt/RSA.php');
						
					}
					 
					$rsa = new Crypt_RSA();
					$load = $rsa->loadKey(file_get_contents(WPSG_PATH.'/lib/.htpublic'));
					
					if ($load === false)
					{
						
						$this->addBackendMessage(base64_decode('TGFkZW4gZGVzIMO2ZmZlbnRsaWNoZW4gU2NobMO8c3NlbHMgaXN0IGZlaGxnZXNjaGxhZ2VuLg==')); // Laden des öffentlichen Schlüssels ist fehlgeschlagen.
						
					}
					else
					{
				 
						$decrypt_key = $rsa->decrypt(base64_decode(file_get_contents($_FILES['wpsg_licence_file']['tmp_name'])));
						
						if ($decrypt_key === false)
						{
							
							$this->addBackendError(base64_decode('RW50c2NobMO8c3NlbG4gZmVobGdlc2NobGFnZW4=')); // Entschlüsseln fehlgeschlagen
							
						}
						else
						{
						
							$arKey = @unserialize($decrypt_key);
							  
							if (is_array($arKey) && $arKey['l'] < 3 && $this->shop->isMultiBlog())
							{
								
								$this->shop->update_option('wpsg_key', false, true);
								$this->addBackendError(base64_decode('RsO8ciBkaWUgVmVyd2VuZHVuZyBpbiBlaW5lciBNdWx0aWJsb2cgVW1nZWJ1bmcgaXN0IGRpZSBFbnRlcnByaXNlIExpemVueiBuw7Z0aWcu')); // Für die Verwendung in einer Multiblog Umgebung ist die Enterprise Lizenz nötig.
								
							}
							else
							{
							
								if (is_array($arKey) && $arKey['anwendung'] == 'wpShopGermany')
								{
				
									$this->shop->clearMessages();
									
									// Key ist gültig und nun installieren
									$this->shop->update_option('wpsg_key', file_get_contents($_FILES['wpsg_licence_file']['tmp_name']), true);
									$this->addBackendMessage(base64_decode('S2V5IHd1cmRlIGVyZm9sZ3JlaWNoIGluc3RhbGxpZXJ0')); // Key wurde erfolgreich installiert
									
								}
								else
								{
									
									$this->addBackendError(base64_decode('VW5nw7xsdGlnZSBMaXplbnpkYXRlaQ==')); // Ungültige Lizenzdatei
										
								}
								
							}
							
						}
						
					}
					
				}
									
				if ($this->shop->isMultiBlog()) die($this->redirect(WPSG_URL_WP.'wp-admin/network/plugins.php'));
				else die($this->redirect(WPSG_URL_WP.'wp-admin/plugins.php'));
				
			}
			else
			{
				
				$this->addBackendError(base64_decode('S2VpbmUgTGl6ZW56ZGF0ZWkgYW5nZWdlYmVu')); // Keine Lizenzdatei angegeben
				
			}
			
		} // public function loadLicenceAction()
				
		/**
		 * Verwaltung der Registrierung
		 */
		public function registrierungAction()
		{
									
			return $this->shop->callMod('wpsg_mod_core', 'admin_registrierung');
			
		} // public function registrierungAction()
				
		/**
		 * Gibt die Liste der Versandzonen zurück
		 */
		public function vz_listAction()
		{
			
			$this->shop->view['data'] = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_VZ."` ORDER BY `name` ASC");
			
			$this->shop->render(WPSG_PATH_VIEW.'/admin/versandzonen_list.phtml');
			
		} // public function vz_listAction()
		
		/**
		 * Migriert die alten Mehrwertsteuersätze die vor 3.5 existierten in die Länder und passt die Produkte an.
		 */
		public function migratemwstAction()
		{
			
			if (isset($_REQUEST['submit']))
			{
				 			
				// Mehrwertsteuersätze der Produkte
				if (wpsg_isSizedArray($_REQUEST['mwst']))
				{
				
					foreach ($_REQUEST['mwst'] as $tax_id => $tax_key)
					{
						
						if ($tax_id == 0)
						{
							
							// Das sind die Produkte mit MwSt Sätzen die nicht mehr exitierten
							$arProductIDs = $this->db->fetchAssocField("
								SELECT 
									P.`id` 
								FROM 
									`".WPSG_TBL_PRODUCTS."` AS P 
										LEFT JOIN `".WPSG_TBL_MWST."` AS M ON (P.`mwst` = M.`id`)
								WHERE
									M.`id` IS NULL AND 
									(P.`mwst_key` = '' OR P.`mwst_key` IS NULL)
							");
							
							$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array('mwst_key' => wpsg_q($tax_key)), " `id` IN (".implode(',', wpsg_q($arProductIDs)).") ");
							
						}
						else 
						{
							
							$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array('mwst_key' => wpsg_q($tax_key)), " (`mwst_key` = '' OR `mwst_key` IS NULL) AND `mwst` = '".wpsg_q($tax_id)."' ");
							
						}
						
					}
					
				}
				
				// Konfiguration speichern
				if (wpsg_isSizedArray($_REQUEST['conf']))
				{
					
					foreach ($_REQUEST['conf'] as $conf_key => $conf_value)
					{
						
						$this->shop->update_option($conf_key, $conf_value);
						
					}
					
				}
				
				// Zahlungsvarianten
				if (wpsg_isSizedArray($_REQUEST['pv']))
				{
					
					foreach ($_REQUEST['pv'] as $pv_id => $tax_key)
					{
						
						$this->db->UpdateQuery(WPSG_TBL_ZV, array('mwst_key' => wpsg_q($tax_key)), " `id` = '".wpsg_q($pv_id)."' ");
						
					}
					
				}
				
				// Versandarten
				if (wpsg_isSizedArray($_REQUEST['sv']))
				{
						
					foreach ($_REQUEST['sv'] as $sv_id => $tax_key)
					{
				
						$this->db->UpdateQuery(WPSG_TBL_VA, array('mwst_key' => wpsg_q($tax_key)), " `id` = '".wpsg_q($sv_id)."' ");
				
					}
						
				}
				
				$this->shop->removePersistentBackendError('wpsg_update_3.5_1');
				
				$this->shop->addBackendMessage(__('Migration der MwSt. Sätze erfolgreich durchgeführt.', 'wpsg'));
				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe');
				
			}
			
			$this->shop->view = array(
				'actionName' => 'hilfe',
				'subTemplate' => WPSG_PATH_VIEW.'/admin/migratemwst.phtml'
			);
			
			$arMwStTable = $this->db->fetchAssocField("SHOW TABLES LIKE '".WPSG_TBL_MWST."'");
			if (in_array(WPSG_TBL_MWST, $arMwStTable))
			{
			
				$this->shop->view['distinctProductTax'] = $this->db->fetchAssoc("
					SELECT
						M.*,
						COUNT(P.`mwst`) AS `count_product`
					FROM
						`".WPSG_TBL_PRODUCTS."` AS P
							LEFT JOIN `".WPSG_TBL_MWST."` AS M ON (P.`mwst` = M.`id`)
					WHERE
						P.`mwst_key` = '' OR P.`mwst_key` IS NULL
					GROUP BY 
						M.`id`	
				");

			}
			
			if ($this->shop->hasMod('wpsg_mod_userpayment')) 
			{
				
				$this->shop->view['arPaymentMethods'] = $this->db->fetchAssoc("
					SELECT
						PM.*
					FROM
						`".WPSG_TBL_ZV."` AS PM
					WHERE
						PM.`mwst_key` = '' OR PM.`mwst_key` IS NULL 
				");
			
			}
			
			if ($this->shop->hasMod('wpsg_mod_versandarten'))
			{
			
				$this->shop->view['arShippingMethods'] = $this->db->fetchAssoc("
					SELECT
						SM.*
					FROM
						`".WPSG_TBL_VA."` AS SM
					WHERE
						SM.`mwst_key` = '' OR SM.`mwst_key` IS NULL
				");
				
			}
			 			
			$this->shop->view['arConf'] = array();
			
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_paypal_mwst'] = __('Mehrwertsteuersatz für PayPal Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_autodebit_mwst'] = __('Mehrwertsteuersatz für Bankeinzugs Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_billsafe_mwst'] = __('Mehrwertsteuersatz für Billsafe Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_cab_mwst'] = __('Mehrwertsteuersatz für Click&Buy Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_debitpayment_mwst'] = __('Mehrwertsteuersatz für Nachnahme Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_flexipay_mwst'] = __('Mehrwertsteuersatz für Flexipay Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_giropay_giropay_mwst'] = __('Mehrwertsteuersatz für Giropay (Giropay) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_giropay_creditcard_mwst'] = __('Mehrwertsteuersatz für Giropay (Creditcard) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_giropay_directdebit_mwst'] = __('Mehrwertsteuersatz für Giropay (Lastschrift) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_invoice_type_mwst'] = __('Mehrwertsteuersatz der Gebühren für Zahlung mit Rechnung', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_klarna_mwst'] = __('Mehrwertsteuersatz für Klarna Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_creditcard_mwst'] = __('Mehrwertsteuersatz für Micropayment (Creditcard) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_creditcardreservation_mwst'] = __('Mehrwertsteuersatz für Micropayment (Creditcardreservation) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_directdebit_mwst'] = __('Mehrwertsteuersatz für Micropayment (Lastschrift) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_ebank2pay_mwst'] = __('Mehrwertsteuersatz für Micropayment (eBank2Pay) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_prepayment_mwst'] = __('Mehrwertsteuersatz für Micropayment (Vorkasse) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_call2pay_mwst'] = __('Mehrwertsteuersatz für Micropayment (Call2Pay) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_micropayment_handypay_mwst'] = __('Mehrwertsteuersatz für Micropayment (HandyPay) Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_prepayment_mwst'] = __('Mehrwertsteuersatz für Vorkasse Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_rechnungen_gutschrifttax'] = __('Mehrwertsteuersatz für Gebühren von Gutschriften', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_securepay_mwst'] = __('Mehrwertsteuersatz für Securepay Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_shs_mwst'] = __('Mehrwertsteuersatz für Gebühren Sparkasse Internetkasse Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_skrill_mwst'] = __('Mehrwertsteuersatz für Skrill Gebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_su_mwst'] = __('Mehrwertsteuersatz für Sofortüberweisungsgebühren', 'wpsg'); }
			if (wpsg_isSizedInt($this->get_option('wpsg_mod_paypal_mwst'))) { $this->shop->view['arConf']['wpsg_mod_willcollect_mwst'] = __('Mehrwertsteuersatz für Gebühren der Selbstabholung', 'wpsg'); }
			
			$this->shop->view['defaultCountry'] = $this->shop->getDefaultCountry();
			
			if (	!wpsg_isSizedArray($this->shop->view['distinctProductTax']) && 
					!wpsg_isSizedArray($this->shop->view['arPaymentMethods']) && 
					!wpsg_isSizedArray($this->shop->view['arShippingMethods']) &&
					!wpsg_isSizedArray($this->shop->view['arConf'])	)				
			{
				
				$this->shop->removePersistentBackendError("wpsg_update_3.5_1");
				$this->shop->addBackendError(__('Es gibt keine alten MwSt. Sätze zu migrieren.', 'wpsg'));
				
				$this->shop->view['subTemplate'] = WPSG_PATH_VIEW.'/admin/hilfe.phtml';
						
			}
			
			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');		
			
		}
		
		/**
		 * Wird aufgerufen wenn die Versandzonen verwaltet werden sollen
		 */
		public function vzAction()
		{
			
			if (isset($_REQUEST['submit']))
			{
				
				$this->shop->removePersistentBackendError('wpsg_update_3.5_2');
				
				$this->shop->addBackendMessage(__('Einstellungen der Versandzonen wurden erfolgreich gespeichert.', 'wpsg'));
				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=vz');
					
			}
			
			$this->shop->view['arVZ'] = $this->db->fetchAssocField("SELECT VZ.`id`, VZ.`name` FROM `".WPSG_TBL_VZ."` AS VZ WHERE 1 ORDER BY VZ.`name` ASC ", "id", "name");
			
			if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'add')
			{
				
				// Neue Zone anlegen
				$new_name = __('Anklicken um Bezeichnung zu ändern ...', 'wpsg');
				
				$vz_id = $this->db->ImportQuery(WPSG_TBL_VZ, array(
					'name' => wpsg_q($new_name)
				));
				
				$this->shop->addTranslationString('vz_'.$vz_id, $new_name);
				
				die($this->vz_listAction());
				
			}
			else if (@$_REQUEST['do'] == 'loadStandard')
			{
			
				$this->loadStandardLaenderVz();
			
				die($this->vz_listAction());
			
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'remove')
			{
				
				// Versandzone löschen
				$this->db->Query("DELETE FROM `".WPSG_TBL_VZ."` WHERE `id` = '".wpsg_q($_REQUEST['vz_id'])."'");
				
				die($this->vz_listAction());
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'inlinedit')
			{
				
				// Inline Edit
				$data = array();
				
				$data[$_REQUEST['field']] = wpsg_q($_REQUEST['value']);
				
				if ($_REQUEST['field'] == 'name')
				{
					$this->shop->addTranslationString('vz_'.$_REQUEST['vz_id'], $_REQUEST['value']);
				}
				
				$this->db->UpdateQuery(WPSG_TBL_VZ, $data, "`id` = '".wpsg_q($_REQUEST['vz_id'])."'");
				
				die(stripslashes($_REQUEST['value']));
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'save_plz')
			{
				
				$this->db->UpdateQuery(WPSG_TBL_VZ, array(
					'param' => trim($_REQUEST['textarea'])
				), "`id` = '".wpsg_q($_REQUEST['vz_id'])."'");
				
				die('1');
				
			}
			
		} // public function vzAction()
		 
		/**
		 * Ist für das Deinstallieren zuständig
		 */
		public function deinstallierenAction()
		{
			
			global $wpdb;
			
			if (isset($_REQUEST['submit']))
			{
				
				if ($_REQUEST['wpsg_deinstall_products'] == '1')
				{
					
					// Produkte löschen
					$this->db->Query("TRUNCATE TABLE `".WPSG_TBL_PRODUCTS."`");
					$this->db->Query("DELETE FROM `".WPSG_TBL_META."` WHERE `meta_table` = 'WPSG_TBL_PRODUCTS' ");
					
					$this->shop->addBackendMessage(__('Produkte erfolgreich gelöscht.', 'wpsg'));
					
				}
				
				if ($_REQUEST['wpsg_deinstall_customer'] == '1')
				{
					
					// Kunden löschen
					$this->db->Query("TRUNCATE TABLE `".WPSG_TBL_KU."`");
					$this->db->Query("DELETE FROM `".WPSG_TBL_META."` WHERE `meta_table` = 'WPSG_TBL_KU' ");
					
					$this->shop->addBackendMessage(__('Kunden erfolgreich gelöscht.', 'wpsg'));
					
				}
				
				if ($_REQUEST['wpsg_deinstall_order'] == '1')
				{
					
					// Bestellungen löschen
					$arOrder = wpsg_order::find(array());
					
					foreach ($arOrder as $oOrder)
					{
						
						$oOrder->delete();
						
					}
					
					$this->shop->addBackendMessage(__('Bestellungen erfolgreich gelöscht.', 'wpsg'));
					
				}
				
				if ($_REQUEST['wpsg_deinstall_incompleteorder'] == '1')
				{
				
					$arOrder = wpsg_order::find(array(
						'status' => wpsg_ShopController::STATUS_UNVOLLSTAENDIG
					));
					
					foreach ($arOrder as $oOrder)
					{
						
						$oOrder->delete();
						
					}
					
					$this->shop->addBackendMessage(__('Unvollständige Bestellungen erfolgreich gelöscht.', 'wpsg'));
					
				}
				
				if ($_REQUEST['wpsg_deinstall_core'] == '1')
				{
					
					// Tabellen löschen
					foreach ((array)get_defined_constants() as $const_key => $const)
					{
						
						if (preg_match('/^WPSG_TBL_(.*)/', $const_key))
						{
							
							$this->db->Query("DROP TABLE IF EXISTS `".$const."`");
							
						}
						
					}
										
					// Plugin deaktivieren
					deactivate_plugins('wpshopgermany/wpshopgermany.php');

					// Einstellungen löschen
					$this->db->Query("DELETE FROM `".$wpdb->prefix."options` WHERE `option_name` LIKE 'wpsg_%'");
					
					// Plugindaten löschen
					wpsg_rrmdir(WP_PLUGIN_DIR.'../wpshopgermany/');
					
					$this->shop->clearMessages();					
					$this->shop->redirect(WPSG_URL_WP.'wp-admin/plugins.php');
					
				}
				else
				{
				
					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&amp;subaction=deinstallieren');
					
				}
				
			}
			
			$this->shop->view['count_order_incomplete'] = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDER."` WHERE `status` = '".wpsg_q(wpsg_ShopController::STATUS_UNVOLLSTAENDIG)."' ");
			$this->shop->view['count_order'] = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDER."`");
			$this->shop->view['count_customer'] = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_KU."`");
			$this->shop->view['count_products'] = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_PRODUCTS."`");
			
		} // public function deinstallierenAction()
		
		/**
		 * Wird aufgerufen wenn die Länder verwaltet werden sollen
		 */
		public function laenderAction()
		{
			
			if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'saveNew')
			{
				
				if (!wpsg_isSizedString($_REQUEST['newland']['name']))
				{
					
					$this->shop->addBackendError(__('Bitte einen Namen für das neue Land angeben.', 'wpsg'));
					
				}
				else 
				{
					
					$land = $_REQUEST['newland'];
					
					$land_id = $this->db->ImportQuery(WPSG_TBL_LAND, array(						
						'name' => wpsg_q($land['name']),
						'kuerzel' => wpsg_q($land['kuerzel']),
						'vz' => wpsg_q($land['vz']),
						'mwst' => wpsg_q($land['mwst']),
						'mwst_a' => ((wpsg_tf($land['mwst_a']) >= 0 && wpsg_tf($land['mwst_a']) !== '')?wpsg_q(wpsg_tf($land['mwst_a'])):'NULL'),
						'mwst_b' => ((wpsg_tf($land['mwst_b']) >= 0 && wpsg_tf($land['mwst_b']) !== '')?wpsg_q(wpsg_tf($land['mwst_b'])):'NULL'),
						'mwst_c' => ((wpsg_tf($land['mwst_c']) >= 0 && wpsg_tf($land['mwst_c']) !== '')?wpsg_q(wpsg_tf($land['mwst_c'])):'NULL'),
						'mwst_d' => ((wpsg_tf($land['mwst_d']) >= 0 && wpsg_tf($land['mwst_d']) !== '')?wpsg_q(wpsg_tf($land['mwst_d'])):'NULL')
					));
					
					if (wpsg_isSizedInt($land['standard'])) $this->shop->update_option('wpsg_defaultland', $land_id);
					
					$this->shop->addTranslationString('land_'.$land_id, $land['name']);
					$this->shop->addTranslationString('landkrzl_'.$land_id, $land['kuerzel']);
					
					$this->shop->addBackendMessage(__('Land wurde erfolgreich gespeichert.', 'wpsg'));
					
				}
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=laender'); 
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'saveEdit')
			{
				
				$land = array();
				parse_str($_REQUEST['form_data'], $land);
				$land = $land['land'];
			
				if (!wpsg_isSizedInt($land['id'])) $this->shop->throwErrorCode('100_9');
				
				$this->db->UpdateQuery(WPSG_TBL_LAND, array(
					'name' => wpsg_q($land['name']),
					'kuerzel' => wpsg_q($land['kuerzel']),
					'vz' => wpsg_q($land['vz']),
					'mwst' => wpsg_q($land['mwst']),
					'mwst_a' => ((wpsg_tf($land['mwst_a']) >= 0 && wpsg_tf($land['mwst_a']) !== '')?wpsg_q(wpsg_tf($land['mwst_a'])):'NULL'),
					'mwst_b' => ((wpsg_tf($land['mwst_b']) >= 0 && wpsg_tf($land['mwst_b']) !== '')?wpsg_q(wpsg_tf($land['mwst_b'])):'NULL'),
					'mwst_c' => ((wpsg_tf($land['mwst_c']) >= 0 && wpsg_tf($land['mwst_c']) !== '')?wpsg_q(wpsg_tf($land['mwst_c'])):'NULL'),
					'mwst_d' => ((wpsg_tf($land['mwst_d']) >= 0 && wpsg_tf($land['mwst_d']) !== '')?wpsg_q(wpsg_tf($land['mwst_d'])):'NULL')						
				), " `id` = '".wpsg_q($land['id'])."' ");
				
				if (wpsg_isSizedInt($land['standard'])) $this->shop->update_option('wpsg_defaultland', $land['id']);
				
				$this->shop->addTranslationString('land_'.$land['id'], $land['name']);
				$this->shop->addTranslationString('landkrzl_'.$land['id'], $land['kuerzel']);
				
				$land_db = $this->db->fetchRow("
					SELECT
						L.`id` AS `id`,
						(IF (LENGTH(L.`kuerzel`) > 0, CONCAT(L.`name`, ' (', L.`kuerzel`, ')'), L.`name`)) AS `name`,
						VZ.`name` AS `vz`,
						(
							CASE L.`mwst` 
								WHEN '2' THEN '".__('keine MwSt. bei USt.IdNr.', 'wpsg')."'
								WHEN '1' THEN '".__('keine MwSt.', 'wpsg')."'
								ELSE '".__('mit MwSt.', 'wpsg')."'
								END
						) AS `mwst`,
						L.`mwst_a`, L.`mwst_b`, L.`mwst_c`, L.`mwst_d`
					FROM
						`".WPSG_TBL_LAND."` AS L 
							LEFT JOIN `".WPSG_TBL_VZ."` AS VZ ON (L.`vz` = VZ.`id`)
					WHERE
						L.`id` = '".wpsg_q($land['id'])."'
				");
				
				if ($this->shop->get_option('wpsg_defaultland') == $land['id']) $land_db['standard'] = '1';
				
				if (wpsg_tf($land_db['mwst_a']) >= 0 && wpsg_tf($land_db['mwst_a']) != '') $land_db['mwst_a'] = wpsg_ff(wpsg_tf($land_db['mwst_a']), '%'); else $land_db['mwst_a'] = '';
				if (wpsg_tf($land_db['mwst_b']) >= 0 && wpsg_tf($land_db['mwst_b']) != '') $land_db['mwst_b'] = wpsg_ff(wpsg_tf($land_db['mwst_b']), '%'); else $land_db['mwst_b'] = '';
				if (wpsg_tf($land_db['mwst_c']) >= 0 && wpsg_tf($land_db['mwst_c']) != '') $land_db['mwst_c'] = wpsg_ff(wpsg_tf($land_db['mwst_c']), '%'); else $land_db['mwst_c'] = '';
				if (wpsg_tf($land_db['mwst_d']) >= 0 && wpsg_tf($land_db['mwst_d']) != '') $land_db['mwst_d'] = wpsg_ff(wpsg_tf($land_db['mwst_d']), '%'); else $land_db['mwst_d'] = '';
				 
				header('Content-Type: application/json');
				
				die(json_encode($land_db));
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'eu_import')
			{
				
				// EU Import
				$this->loadEULaender();
				$this->shop->addBackendMessage(__('EU-Länder erfolgreich importiert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=laender');
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'import')
			{
								
				$this->loadStandardLaenderVz();
				$this->shop->addBackendMessage(__('Länder erfolgreich importiert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=laender');				
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'remove')
			{
				
				$this->db->Query("DELETE FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q($_REQUEST['land_id'])."' ");
				
				die("1");
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'edit')
			{
			
				$this->shop->view['vz'] = $this->db->fetchAssocField("SELECT `id`, `name` FROM `".WPSG_TBL_VZ."` ORDER BY `name` ASC", "id", "name");
				$this->shop->view['land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q($_REQUEST['land_id'])."' ");
				
				if (wpsg_tf($this->shop->view['land']['mwst_a']) >= 0 && wpsg_tf($this->shop->view['land']['mwst_a']) !== '') $this->shop->view['land']['mwst_a'] = wpsg_ff(wpsg_tf($this->shop->view['land']['mwst_a']), '%'); else $this->shop->view['land']['mwst_a'] = ''; 
				if (wpsg_tf($this->shop->view['land']['mwst_b']) >= 0 && wpsg_tf($this->shop->view['land']['mwst_b']) !== '') $this->shop->view['land']['mwst_b'] = wpsg_ff(wpsg_tf($this->shop->view['land']['mwst_b']), '%'); else $this->shop->view['land']['mwst_b'] = '';
				if (wpsg_tf($this->shop->view['land']['mwst_c']) >= 0 && wpsg_tf($this->shop->view['land']['mwst_c']) !== '') $this->shop->view['land']['mwst_c'] = wpsg_ff(wpsg_tf($this->shop->view['land']['mwst_c']), '%'); else $this->shop->view['land']['mwst_c'] = '';
				if (wpsg_tf($this->shop->view['land']['mwst_d']) >= 0 && wpsg_tf($this->shop->view['land']['mwst_d']) !== '') $this->shop->view['land']['mwst_d'] = wpsg_ff(wpsg_tf($this->shop->view['land']['mwst_d']), '%'); else $this->shop->view['land']['mwst_d'] = '';
								
				if ($this->shop->get_option('wpsg_defaultland') == $_REQUEST['land_id']) $this->shop->view['land']['standard'] = '1'; else $this->shop->view['land']['standard'] = '0';
				
				die($this->shop->render(WPSG_PATH_VIEW.'/admin/laender_edit.phtml'));
			
			}
			
			$this->shop->removePersistentBackendError('wpsg_update_3.5_3');
			
			$this->shop->view['vz'] = $this->db->fetchAssocField("SELECT `id`, `name` FROM `".WPSG_TBL_VZ."` ORDER BY `name` ASC", "id", "name");
			$this->shop->view['data'] = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_LAND."` ORDER BY `vz` ASC, `name` ASC");
					 	
		} // public function laenderAction()
		
		/**
		 * Importiert die EU-Länder aus der Liste
		 * Aktualisiert dabei bestehende
		 */
		public function loadEULaender()
		{
			 
			$handle = fopen(WPSG_PATH."/lib/data/wp_wpsg_laender.csv", "r");
			
			// Schauen ob die EU Versandzone existiert
			$nExists = $this->db->fetchOne("SELECT VZ.`id` FROM `".WPSG_TBL_VZ."` AS VZ WHERE VZ.`id` = '2' ");
			if (!wpsg_isSizedInt($nExists)) $this->db->ImportQuery(WPSG_TBL_VZ, array(
				'id' => '2', 
				'name' => __('EU', 'wpsg'),
				'innereu' => '1'				
			));
			
			while (($row = fgetcsv($handle, 1000, ";")) !== false)
			{
				 
				if (!in_array($row['3'], array(1, 2))) continue;
				
				$country_data = array(
					'id' => wpsg_q($row['0']),
					'name' => wpsg_q($row['1']),
					'kuerzel' => wpsg_q($row['2']),
					'vz' => wpsg_q($row['3']),
					'mwst' => wpsg_q($row['4']),
					'mwst_a' => ((wpsg_tf($row[5]) >= 0 && wpsg_tf($row[5]) !== '')?wpsg_q(wpsg_tf($row[5])):'NULL'),
					'mwst_b' => ((wpsg_tf($row[6]) >= 0 && wpsg_tf($row[6]) !== '')?wpsg_q(wpsg_tf($row[6])):'NULL'),
					'mwst_c' => ((wpsg_tf($row[7]) >= 0 && wpsg_tf($row[7]) !== '')?wpsg_q(wpsg_tf($row[7])):'NULL'),
					'mwst_d' => ((wpsg_tf($row[8]) >= 0 && wpsg_tf($row[8]) !== '')?wpsg_q(wpsg_tf($row[8])):'NULL')
				);
				
				$nExists = $this->db->fetchOne("SELECT L.`id` FROM `".WPSG_TBL_LAND."` AS L WHERE UPPER(L.`name`) = '".wpsg_q(strtoupper($country_data['name']))."' ");
												
				if (wpsg_isSizedInt($nExists))
				{
					
					unset($country_data['id']);
					$this->db->UpdateQuery(WPSG_TBL_LAND, $country_data, " `id` = '".wpsg_q($nExists)."' ");
					
				}
				else
				{
					
					// Checken ob die ID schon existiert.
					$idName = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q($country_data['id'])."' ");
					
					if (wpsg_isSizedInt($idName)) unset($country_data['id']);
					
					$this->db->ImportQuery(WPSG_TBL_LAND, $country_data);
					
				}
				
			}
			
		} // public function loadEULaender()
		
		/**
		 * Diese Funktion lädt die Standard Länder und Versandzonen
		 * Wird aus der Länderverwaltung und der Versandzonenverwaltung aufgerufen
		 */
		private function loadStandardLaenderVz()
		{ 
			
			// Standard Länder und Versandzonen laden
			$this->db->Query("DELETE FROM `".WPSG_TBL_VZ."`");
			$this->db->Query("DELETE FROM `".WPSG_TBL_LAND."`");
			
			// Versandzonen anlegen
			$this->db->ImportQuery(WPSG_TBL_VZ, array('id' => '1', 'name' => __('Inland', 'wpsg')));
			$this->db->ImportQuery(WPSG_TBL_VZ, array('id' => '2', 'name' => __('EU Länder', 'wpsg'), 'innereu' => '1'));
			$this->db->ImportQuery(WPSG_TBL_VZ, array('id' => '3', 'name' => __('Ausland', 'wpsg')));
			
			$this->shop->addTranslationString('vz_1', __('Inland', 'wpsg'));
			$this->shop->addTranslationString('vz_2', __('EU Länder', 'wpsg'));
			$this->shop->addTranslationString('vz_3', __('Ausland', 'wpsg'));
			
			$handle = fopen(WPSG_PATH."/lib/data/wp_wpsg_laender.csv", "r");
			
			while (($row = fgetcsv($handle, 1000, ";")) !== false)
			{
				
				$land_id = $this->db->ImportQuery(WPSG_TBL_LAND, array(
					'id' => wpsg_q($row['0']),
					'name' => wpsg_q($row['1']),
					'kuerzel' => wpsg_q($row['2']),
					'vz' => wpsg_q($row['3']),
					'mwst' => wpsg_q($row['4']),
					'mwst_a' => ((wpsg_tf($row[5]) >= 0 && wpsg_tf($row[5]) !== '')?wpsg_q(wpsg_tf($row[5])):'NULL'),
					'mwst_b' => ((wpsg_tf($row[6]) >= 0 && wpsg_tf($row[6]) !== '')?wpsg_q(wpsg_tf($row[6])):'NULL'),
					'mwst_c' => ((wpsg_tf($row[7]) >= 0 && wpsg_tf($row[7]) !== '')?wpsg_q(wpsg_tf($row[7])):'NULL'),
					'mwst_d' => ((wpsg_tf($row[8]) >= 0 && wpsg_tf($row[8]) !== '')?wpsg_q(wpsg_tf($row[8])):'NULL')
				));
									
				$this->shop->addTranslationString('land_'.$land_id, $row['1']);
				$this->shop->addTranslationString('landkrzl_'.$land_id, $row['2']);
					
			}
			
			$this->shop->update_option('wpsg_defaultland', '1');
			
		} // private function loadStandardLaenderVz()
		
		/**
		 * Speichert die Kundenvoreinstellungen
		 */
		public function customerpresetAction()
		{
			
			if (isset($_REQUEST['wpsg-submit']))
			{
				
				$this->shop->update_option('wpsg_customerpreset_shipping', $_REQUEST['wpsg_customerpreset_shipping']);
				$this->shop->update_option('wpsg_customerpreset_payment', $_REQUEST['wpsg_customerpreset_payment']);
				$this->shop->update_option('wpsg_defaultland', $_REQUEST['wpsg_defaultland']);
				$this->shop->update_option('wpsg_customerpreset_title', $_REQUEST['wpsg_customerpreset_title']);
				
				$this->addBackendMessage(__('Kundenvoreinstellungen erfolgreich gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=customerpreset');
								
			}
			
			$this->shop->view['arShipping'] = array();
			foreach ($this->shop->arShipping as $s_id => $s) $this->shop->view['arShipping'][$s['id']] = $s['name']; 
			
			$this->shop->view['arPayment'] = array();
			foreach ($this->shop->arPayment as $p_id => $p) $this->shop->view['arPayment'][$p['id']] = $p['name'];
			
			$this->shop->view['pflicht'] = $this->shop->get_option('wpsg_admin_pflicht');
			$this->shop->view['arTitle'] = (array)explode('|', $this->shop->view['pflicht']['anrede_auswahl']);
									
			$this->shop->view['arLander'] = $this->db->fetchAssocField("SELECT L.`id`, L.`name` FROM `".WPSG_TBL_LAND."` AS L ORDER BY `name` ASC ", "id", "name");
						
		} // public function customerpresetAction()
		
		/**
		 * Wird aufgerufen wenn die Pflichtfelder verwaltet werden sollen
		 */
		public function kundendatenAction()
		{

			$this->shop->view['pflicht'] = $this->get_option('wpsg_admin_pflicht');

			if (isset($_REQUEST['show']) && $_REQUEST['show'] == 'code')
			{
				
				$this->shop->view['id'] = $_REQUEST['kv_id'];
				$this->shop->view['field'] = $this->shop->view['pflicht']['custom'][$_REQUEST['kv_id']];
				
				die($this->shop->render(WPSG_PATH_VIEW.'/admin/kundendaten_codeinfo.phtml'));
				
			}
			
			if (isset($_REQUEST['submit'])) 
			{

				$this->update_option('wpsg_kundenvariablen_show', $_REQUEST['wpsg_kundenvariablen_show']);
				
				foreach ($_REQUEST['pflicht'] as $k => $v)
				{
					//wpsg_debug($v);
					if ($k == 'custom')
					{

						foreach ($_REQUEST['pflicht']['custom'] as $c_id => $c)
						{
							
							if ($c['del'] == '1') unset($this->shop->view['pflicht']['custom'][$c_id]);
							else
							{
								
								$this->shop->view['pflicht']['custom'][$c_id]['typ'] = $c['typ'];
								$this->shop->view['pflicht']['custom'][$c_id]['show'] = $c['show'];						
								$this->shop->view['pflicht']['custom'][$c_id]['auswahl'] = $c['auswahl'];
								
								$this->shop->addTranslationString('customervars_'.$c_id.'_auswahl', $c['auswahl']);
								
							}
														
						}
						
					}
					else
					{
						
						if ($k == 'anrede_auswahl')
						{
							
							$this->shop->addTranslationString('anrede_auswahl', $v);	
							
						}
						
						$this->shop->view['pflicht'][$k] = $v;
						
					}
					
				}

				$this->update_option('wpsg_admin_pflicht', $this->shop->view['pflicht']);
				
				$this->addBackendMessage(__('Kundenvariablen erfolgreich gespeichert.', 'wpsg'));
				
			}
			
			if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'add')
			{
								
				if (!is_array($this->shop->view['pflicht'])) $this->shop->view['pflicht'] = array();
				$this->shop->view['pflicht']['custom'][] = array(
					"name" => __('Neues benutzerdefiniertes Feld', 'wpsg'),
					"show" => '0',
					"typ" => '0',
					"auswahl" => ''
				);
				
				$this->update_option('wpsg_admin_pflicht', $this->shop->view['pflicht']);
				
				die($this->shop->render(WPSG_PATH_VIEW.'/admin/kundendaten_tab2.phtml'));
				
			}
			else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'inlinedit')
			{
				
				if ($_REQUEST['field'] == 'name')
				{
					
					$this->shop->view['pflicht']['custom'][$_REQUEST['field_id']]['name'] = $_REQUEST['value']; 
						
				}
				
				$this->update_option('wpsg_admin_pflicht', $this->shop->view['pflicht']);
				
				die(stripslashes($_REQUEST['value'])); 
				
			}
						
		} // public function pflichtAction()
		
		/**
		 * Konfiguration der E-Mail Einstellungen
		 */
		public function emailconfAction()
		{
			
			if (isset($_REQUEST['submit'])) 
			{
							
				$this->update_option('wpsg_htmlmail', $_REQUEST['wpsg_htmlmail']);
				
				wpsg_saveEMailConfig("global"); // Global
				wpsg_saveEMailConfig('adminmail'); // Admin Mail
				wpsg_saveEMailConfig('kundenmail'); // Kunden Mail
				wpsg_saveEMailConfig('status'); // Mail Statusänderung
				
				$this->shop->callMods('admin_emailconf_save');
				
				$this->shop->addBackendMessage(__('E-Mail Konfiguration erfolgreich gespeichert.', 'wpsg'));
				
			}
			
			if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'del_attach_file')
			{
				$this->update_option('wpsg_kundenmail_attachfile', '');
			}
				
		} // public function emailconfAction()
		
		/**
		 * Wird aufgerufen wenn die Seiten verwaltet werden sollen
		 */
		public function seitenAction()
		{

			$pages = get_pages();
			
			$arPages = array(
				'-1' => __('Neu anlegen und zuordnen', 'wpsg')
			);
			
			foreach ($pages as $k => $v)
			{
				$arPages[$v->ID] = $v->post_title.' (ID:'.$v->ID.')';
			}
			
			$this->shop->view['pages'] = $arPages;
			
		} // public function seitenAction()
		 
		/**
		 * Modulverwaltung
		 */
		public function moduleAction()
		{
			
			if (isset($_REQUEST['noheader']) && $_REQUEST['noheader'] == '1' && !isset($_REQUEST['submit']))
			{
				
				// Ajax Anfrage eines Moduls
				$this->shop->callMod($_REQUEST['modul'], 'be_ajax');
				die();
				
			}
									
			$this->shop->view = array(
				'actionName' => 'module',
				'subTemplate' => WPSG_PATH_VIEW.'/admin/module.phtml',
				'groups' => array()
			);
			
			$this->shop->view['global'] = false;
			if ($this->shop->isMultiBlog() && $this->shop->get_option('wpsg_multiblog_standalone', true) != '1') $this->shop->view['global'] = true;
									
			$this->shop->loadModule(true);

			if (isset($_REQUEST['submit'])) { $this->submitAction(); }
			
			foreach ($this->shop->arAllModule as $mod_key => $m)
			{
				
				$group = $m->group;
				
				if (trim($group) == '') $group = __('Sonstiges', 'wpsg');
				
				$this->shop->view['groups'][$group][$mod_key] = $m;
				
			}
			
			// Gruppen sortieren
			ksort($this->shop->view['groups']); 
			
			// Module in den Gruppen sortieren
			foreach ($this->shop->view['groups'] as $k => $g)
			{
				
				uasort($this->shop->view['groups'][$k], array($this->shop, 'cmp_mods_name'));
				
			}
						
			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
			
		} // public function moduleAction()
			
		/**
		 * Hilfe Seite
		 */
		public function hilfeAction()
		{
			
			$this->shop->view = array(
				'actionName' => 'hilfe',
				'subTemplate' => WPSG_PATH_VIEW.'/admin/hilfe.phtml'
			);
			
			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');			
			
		} // public function hilfeAction()
		
		/**
		 * Behandelt das Speichern der Widerrufsbelehrung
		 */
		public function widerrufsbelehrungAction()
		{
			
			if (isset($_REQUEST['submit']))
			{
				
				$this->shop->update_option('wpsg_ps_mailwiderruf', $_REQUEST['wpsg_ps_mailwiderruf']);
				$this->shop->addTranslationString('wpsg_ps_mailwiderruf', $_REQUEST['wpsg_ps_mailwiderruf']);
								
				if (file_exists($_FILES['wpsg_widerrufsformular']['tmp_name']))
				{
					
					if (!file_exists(WPSG_PATH_UPLOADS.'wpsg_revocation/')) mkdir(WPSG_PATH_UPLOADS.'wpsg_revocation/', 0775, true);
				
					$this->clearRevocationForm();
					
					move_uploaded_file($_FILES['wpsg_widerrufsformular']['tmp_name'], WPSG_PATH_UPLOADS.'wpsg_revocation/'.$_FILES['wpsg_widerrufsformular']['name']);
					$this->addBackendMessage(__('Widerrufsformular erfolgreich hochgeladen.', 'wpsg'));
				
					$this->shop->update_option('wpsg_revocationform', $_FILES['wpsg_widerrufsformular']['name']);
					
				}
				
				$this->shop->update_option('wpsg_widerrufsformular_kundenmail', $_REQUEST['wpsg_widerrufsformular_kundenmail']);
				
				if ($this->shop->hasMod('wpsg_mod_rechnungen'))
				{
					
					$this->shop->update_option('wpsg_widerrufsformular_invoice', $_REQUEST['wpsg_widerrufsformular_invoice']);
					
				}
				
				if ($this->shop->hasMod('wpsg_mod_auftragsbestaetigung'))
				{
					
					$this->shop->update_option('wpsg_widerrufsformular_orderconfirm', $_REQUEST['wpsg_widerrufsformular_orderconfirm']);
					
				}
								
				$this->addBackendMessage(__('Widerruf erfolgreich gespeichert.', 'wpsg'));
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=widerrufsbelehrung');
				
			}
			
			if (wpsg_isSizedString($_REQUEST['do']) && $_REQUEST['do'] == 'generateWiderrufsformular')
			{

				if (!file_exists(WPSG_PATH_UPLOADS.'wpsg_revocation/')) mkdir(WPSG_PATH_UPLOADS.'wpsg_revocation/', 0775, true);
				
				$this->clearRevocationForm();
				
				$this->shop->view['filename'] = WPSG_PATH_UPLOADS.'wpsg_revocation/widerrufsformular.pdf';				
				$this->shop->render(WPSG_PATH_VIEW.'/admin/musterwiderruf.pdf.phtml');
				
				$this->shop->update_option('wpsg_revocationform', 'widerrufsformular.pdf');
				
				$this->addBackendMessage(__('Widerrufsformular erfolgreich generiert.', 'wpsg'));				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=widerrufsbelehrung');
				
			}
			else if (wpsg_isSizedString($_REQUEST['do']) && $_REQUEST['do'] == 'removeWiderrufsformular')				
			{
				
				$bOK = unlink(WPSG_PATH_UPLOADS.'wpsg_revocation/'.$this->shop->get_option('wpsg_revocationform'));
				
				if ($bOK === true)
				{
				
					$this->shop->update_option('wpsg_revocationform', false);
				
					$this->addBackendMessage(__('Widerrufsformular erfolgreich gelöscht.', 'wpsg'));
										
				}
				else
				{
					
					$this->addBackendError(__('Widerrufsformular konnte nicht gelöscht werden.', 'wpsg')); 
			
				}
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=widerrufsbelehrung');
				
			}
									
			$revocationform = WPSG_PATH_UPLOADS.'wpsg_revocation/'.$this->shop->get_option('wpsg_revocationform');
			
			if (file_exists($revocationform) && is_file($revocationform))
			{
				
				$this->shop->view['revocationform'] = basename($revocationform);
				
			}
			
		} // public function widerrufsbelehrungAction()
		
		private function clearRevocationForm()
		{
			
			$bOK = @unlink(WPSG_PATH_UPLOADS.'wpsg_revocation/'.$this->shop->get_option('wpsg_revocationform'));
			$this->shop->update_option('wpsg_revocationform', false);
			
		} // private function clearRevocationForm()
		
		/**
		 * Zeigt die News im Backend an
		 */
		public function newsAction()
		{
			
			if (wpsg_isSizedInt($_REQUEST['reload']))
			{
				
				wpsg_news::getLatestNewsFromRSS();
				 
				$this->shop->addBackendMessage(__('Refresh der News erfolgreich durchgeführt.', 'wpsg'));								
				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=news');
				
			}
			else if (wpsg_isSizedString($_REQUEST['read']))
			{
				
				$news = wpsg_news::getNewsById(rawurldecode($_REQUEST['read']));
				
				if ($news === false)
				{
					
					$this->shop->addBackendError(__('News wurde nicht gefunden,', 'wpsg'));
					$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=news');
					
				}
				else
				{
				
					wpsg_news::markRead($_REQUEST['read']);
					$this->shop->redirect($news['url']);
					
				}
				
			}
			
			$this->shop->view = array(
				'actionName' => 'news',
				'subTemplate' => WPSG_PATH_VIEW.'/admin/news.phtml',
				'news' => wpsg_news::getLatestNews()
			);
			
			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
			
		} // public function newsAction()
		
		/**
		 * Zeigt Informationen zu dem Shop und aktivierten Modulen an
		 */
		public function ueberAction()
		{
			
			$this->shop->view = array(
				'actionName' => 'ueber',
				'subTemplate' => WPSG_PATH_VIEW.'/admin/ueber.phtml'
			);
				
			$this->shop->render(WPSG_PATH_VIEW.'/admin/index.phtml');
			
		} // public function ueberAction()
		
		/**
		 * Erweiterte Einstellungen
		 */
		public function extendedAction()
		{
			
			$this->shop->view['arGeoMode'] = array('0' => __('Immer anzeigen', 'wpsg'));
			
			if (isset($_SERVER['GEOIP_COUNTRY_CODE'])) $this->shop->view['arGeoMode'][1] = __('Anhand des Apache Moduls mod_geoip', 'wpsg');
			if (function_exists("geoip_country_code_by_name")) $this->shop->view['arGeoMode'][2] = __('Anhand der PECL Erweiterung php_geoip', 'wpsg');
									
			$this->shop->view['arGeoMode'][3] = __('Anhand der Browsersprache', 'wpsg');
			$this->shop->view['aRGeoMode'][4] = __('nicht anzeigen', 'wpsg');
			
		} // public function extendedAction()
		
		/**
		 * Wird beim absenden des Formulars aufgerufen
		 */
		public function submitAction()
		{
			
			global $wpdb;
			
			if (@$_REQUEST['subaction'] == 'konfiguration')
			{
				
				$this->update_option('wpsg_currency', $_REQUEST['wpsg_currency']);
				$this->update_option('wpsg_showincompleteorder', $_REQUEST['wpsg_showincompleteorder']);
				$this->update_option('wpsg_produkte_perpage', $_REQUEST['wpsg_produkte_perpage']);				
				$this->update_option('wpsg_emptyorder_clear', $_REQUEST['wpsg_emptyorder_clear']);
				$this->update_option('wpsg_order_perpage', $_REQUEST['wpsg_order_perpage']);
				$this->update_option('wpsg_skip_checkout2', $_REQUEST['wpsg_skip_checkout2']);
				$this->update_option('wpsg_afterinsert', $_REQUEST['wpsg_afterinsert']);
				$this->update_option('wpsg_afterorder', $_REQUEST['wpsg_afterorder']);
				$this->update_option('wpsg_format_knr', $_REQUEST['wpsg_format_knr']);
				$this->update_option('wpsg_order_knr', $_REQUEST['wpsg_order_knr']);
				$this->update_option('wpsg_customer_start', $_REQUEST['wpsg_customer_start']);			
				$this->update_option('wpsg_format_onr', $_REQUEST['wpsg_format_onr']);
				$this->update_option('wpsg_order_start', $_REQUEST['wpsg_order_start']);
				
				if (wpsg_isSizedString($_REQUEST['wpsg_backend_language']))
				{
					$this->update_option('wpsg_backend_language', $_REQUEST['wpsg_backend_language']);
				}
				
				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin');
				
			}
			else if (@$_REQUEST['subaction'] == 'extended')
			{
				
				$this->update_option('wpsg_salt', $_REQUEST['wpsg_salt']);
				$this->update_option('wpsg_options_nl2br', $_REQUEST['wpsg_options_nl2br']);
				$this->update_option('wpsg_debugModus', $_REQUEST['wpsg_debugModus']);
				
				if ($this->shop->hasMod('wpsg_mod_core')) $this->update_option('wpsg_debugURL', $_REQUEST['wpsg_debugURL']);
				
				$this->update_option('wpsg_referer_requesturi', $_REQUEST['wpsg_referer_requesturi']);
				$this->update_option('wpsg_ignoreuserview', $_REQUEST['wpsg_ignoreuserview']);
				$this->update_option('wpsg_classicupload', $_REQUEST['wpsg_classicupload']);
				$this->update_option('wpsg_content_filter_direct', $_REQUEST['wpsg_content_filter_direct']);
				$this->update_option('wpsg_options_no_rte_apply_filter', $_REQUEST['wpsg_options_no_rte_apply_filter']);
				$this->update_option('wpsg_options_nl2br_out', $_REQUEST['wpsg_options_nl2br_out']);
				$this->update_option('wpsg_impexp_clearlinebreak', $_REQUEST['wpsg_impexp_clearlinebreak']);
				$this->update_option('wpsg_removeWpAutoOp', $_REQUEST['wpsg_removeWpAutoOp']);
				$this->update_option('wpsg_removeWpTrimExcerpt', $_REQUEST['wpsg_removeWpTrimExcerpt']);
				$this->update_option('wpsg_autoraw', $_REQUEST['wpsg_autoraw']);
				$this->update_option('wpsg_nocache', $_REQUEST['wpsg_nocache']);
				$this->update_option('wpsg_autolineending', $_REQUEST['wpsg_autolineending']);
				$this->update_option('wpsg_geo_determination', $_REQUEST['wpsg_geo_determination']);
				
				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=extended');
				
			}
			else if (@$_REQUEST['subaction'] == 'presentation')
			{
				
				$this->update_option('wpsg_showMwstAlways', $_REQUEST['wpsg_showMwstAlways']);
				$this->update_option('wpsg_form_validation', $_REQUEST['wpsg_form_validation']);
				$this->update_option('wpsg_showArticelnumber', $_REQUEST['wpsg_showArticelnumber']);
				$this->update_option('wpsg_hideBasketCountrySelect', $_REQUEST['wpsg_hideBasketCountrySelect']);
				
				$this->shop->callMods('admin_presentation_submit');				
				
				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=presentation');
				
			}
			else if (@$_REQUEST['subaction'] == 'path')
			{
				
				$this->shop->update_option('wpsg_path_upload_multiblog', $_REQUEST['wpsg_path_upload_multiblog'], true);
				
				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=path');
				
			}
			else if (@$_REQUEST['subaction'] == 'loadsavesettings')
			{
				
				if (isset($_REQUEST['wpsg_do']) && $_REQUEST['wpsg_do'] == 'downloadsettings')
				{
					
					$arSettings = $this->db->fetchAssoc("
						SELECT
							*
						FROM
							`".$wpdb->prefix."options`
						WHERE
							(
								`option_name` LIKE 'wpsg_%' 
							) 
							AND
							(
								`option_name` != 'wpsg_installed' AND
								`option_name` != 'wpsg_modul' 							
							)
					"); 
					
					$doc = new DOMDocument('1.0');
					$doc->formatOutput = true;
					$doc->encoding = "utf-8";
					
					$node = $doc->createElement("wpsg");  
					
					$settings = $doc->createElement("settings");				
					foreach ($arSettings as $s)
					{
						
						$setting = $doc->createElement("option");
						wpsg_addAttributs($doc, $setting, array(
							"option_id" => $s['option_id'],
							"blog_id" => $s['blog_id'],
							"option_name" => $s['option_name'],
							"option_value" => $s['option_value'],
							"autoload" => $s['autoload']
						));
						$settings->appendChild($setting);
						
					}
					
					$node->appendChild($settings);
					$doc->appendChild($node);
					
					header('Cache-Control: private');
					header('Content-Type: application/download; charset=utf-8');
					header('Content-Disposition: filename=wpsg_settings_'.date('dmYHi').'.xml');	
					header('Pragma: public');
					
					session_cache_limiter('nocache');
					
					die($doc->saveXML());
				
				}

				if (file_exists($_FILES['wpsg_settings']['tmp_name']))
				{
					
					$xml = simplexml_load_file($_FILES['wpsg_settings']['tmp_name']);			        	
		        	
					if ($xml === false)
					{
						
						$this->shop->addBackendError(__('Keine gültige XML Einstellungsdatei angegeben!', 'wpsg'));
						
					}
					else
					{
					
						$path ="/wpsg/settings/option";			        	
			        	$res = $xml->xpath($path);
			        	
			        	foreach ($res as $k => $v)
			        	{
			        		
			        		$a = $v->attributes();
			        		
			        		$bExists = $this->db->fetchOne("SELECT `option_id` FROM `".$wpdb->prefix."options` WHERE `option_name` = '".wpsg_q(strval($a->option_name))."' ");
			        		
			        		if ($bExists > 0)
			        		{
			        		 
			        			$this->db->UpdateQuery($wpdb->prefix."options", array(
			        				"option_value" => wpsg_q(strval($a->option_value))
			        			), "`option_name` = '".wpsg_q(strval($a->option_name))."'"); 
			        			
			        		}
			        		else
			        		{
			        	 
			        			$this->db->ImportQuery($wpdb->prefix."options", array(
			        				"blog_id" => wpsg_q(strval($a->blog_id)),			        				
			        				"option_name" => wpsg_q(strval($a->option_name)),
			        				"option_value" => wpsg_q(strval($a->option_value)),
			        				"autoload" => wpsg_q(strval($a->autoload))			        				
			        			), true);
			        			
			        		} 
			        		
			        	}
			        	
			        	$this->shop->addBackendMessage(__('Einstellungen wurden erfolgreich importiert.', 'wpsg'));
			        	
					}
					
				}
				else
				{

					$this->shop->addBackendError(__('Bitte eine Einstellungsdatei angeben!', 'wpsg'));
					
				}	

				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=loadsavesettings');
				
			}
			else if (@$_REQUEST['subaction'] == 'includes')
			{ 
				
				$this->update_option('wpsg_load_css', $_REQUEST['wpsg_load_css']);
				$this->update_option('wpsg_load_jquery', $_REQUEST['wpsg_load_jquery']);
				$this->update_option('wpsg_load_thickbox_js', $_REQUEST['wpsg_load_thickbox_js']);
				$this->update_option('wpsg_load_thickbox_css', $_REQUEST['wpsg_load_thickbox_css']);
				$this->update_option('wpsg_load_validierung_js', $_REQUEST['wpsg_load_validierung_js']);
				$this->update_option('wpsg_load_validierung_css', $_REQUEST['wpsg_load_validierung_css']);
				
				$this->shop->callMods('admin_includes_save');
				
				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=includes');
				
			}
			else if (@$_REQUEST['subaction'] == 'blognetzwerk')
			{
				
				$this->update_option('wpsg_multiblog_standalone', $_REQUEST['wpsg_multiblog_standalone'], true);
				$this->update_option('wpsg_multiblog_sessionPath', $_REQUEST['wpsg_multiblog_sessionPath'], true);
								
				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=blognetzwerk');
				
			}
			else if (@$_REQUEST['subaction'] == 'kalkulation')
			{
				
				$this->update_option('wpsg_kleinunternehmer', $_REQUEST['wpsg_kleinunternehmer']);
				$this->update_option('wpsg_kleinunternehmer_text', $_REQUEST['wpsg_kleinunternehmer_text']);
				$this->update_option('wpsg_preisangaben', $_REQUEST['wpsg_preisangaben']);
				$this->update_option('wpsg_preisangaben_frontend', $_REQUEST['wpsg_preisangaben_frontend']);				
				$this->update_option('wpsg_hideemptyshipping', $_REQUEST['wpsg_hideemptyshipping']);
				$this->update_option('wpsg_hideemptypayment', $_REQUEST['wpsg_hideemptypayment']);
								
				$this->addBackendMessage(__('Einstellung gespeichert.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction='.$_REQUEST['subaction']);
				
			}
			else if (@$_REQUEST['subaction'] == 'access')
			{
				
				$this->addBackendMessage(__('Berechtigungen gespeichert.', 'wpsg'));
				
				if (wpsg_isSizedArray($_REQUEST['wpsg_cap']))
				{
					
					foreach ($_REQUEST['wpsg_cap'] as $role_name => $cap)
					{
						 
						$role_object = get_role($role_name);
												
						foreach ($cap as $cap_key => $cap_value)
						{
							
							if ($cap_value == '1')
							{
								
								$role_object->add_cap($cap_key);
								
							}
							else
							{
								
								$role_object->remove_cap($cap_key);
								
							}
							
						}
						
					}
					
				}
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction='.$_REQUEST['subaction']);
				
			}
			else if (@$_REQUEST['subaction'] == 'seiten')
			{
				
				// Seiten speichern
				$this->createPage(__('Warenkorb', 'wpsg'), 'wpsg_page_basket', $_REQUEST['wpsg_page_basket']);				
				$this->createPage(__('Versandkosten', 'wpsg'), 'wpsg_page_versand', $_REQUEST['wpsg_page_versand']);
				$this->createPage(__('AGB', 'wpsg'), 'wpsg_page_agb', $_REQUEST['wpsg_page_agb']);
				$this->createPage(__('Datenschutz', 'wpsg'), 'wpsg_page_datenschutz', $_REQUEST['wpsg_page_datenschutz']);
				$this->createPage(__('Widerrufsbelehrung', 'wpsg'), 'wpsg_page_widerrufsbelehrung', $_REQUEST['wpsg_page_widerrufsbelehrung']);				
				$this->update_option('wpsg_page_onlinedisputeresolution', $_REQUEST['wpsg_page_onlinedisputeresolution']);
				$this->createPage(__('Impressum', 'wpsg'), 'wpsg_page_impressum', $_REQUEST['wpsg_page_impressum']);
				
				$this->addBackendMessage(__('Seiteneinstellungen bearbeitet.', 'wpsg'));
				
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction='.$_REQUEST['subaction']);
				
			}
			else if (@$_REQUEST['action'] == 'module')
			{
			 
				$global = false;
				if ($this->shop->isMultiBlog() && $this->shop->get_option('wpsg_multiblog_standalone', true) != '1') $global = true;
				
				if ($this->get_option($_REQUEST['modul'], $global) > 0 && $_REQUEST['aktiv'] == '1' && array_key_exists($_REQUEST['modul'], $this->shop->arModule))
				{
					
					$this->shop->arModule[$_REQUEST['modul']]->settings_save();
					
					$this->shop->addBackendMessage(__('Moduleinstellungen gespeichert', 'wpsg'));
					
				}
				
				
				// Modul aktivieren wenn noch nicht aktiviert
				if ($_REQUEST['aktiv'] == '1' && $this->get_option($_REQUEST['modul'], $global) == false)				
				{	
					
					$init = base64_decode('aW5zdGFsbEZpcnN0'); //installFirst;
					
					$this->update_option($_REQUEST['modul'], time(), $global);
					$this->shop->arAllModule[$_REQUEST['modul']]->$init();
					$this->shop->arAllModule[$_REQUEST['modul']]->install();	
									
				}
				else if ($_REQUEST['aktiv'] == '0')
				{
					
					$this->update_option($_REQUEST['modul'], false, $global);
					
				}
 
				$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul='.$_REQUEST['modul']);
				
			}
			else 
			{
				
				if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'update')
				{
					
					wpsg_install();
					$this->addBackendMessage(__('Datenbank erfolgreich abgeglichen!', 'wpsg'));
					
					$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&subaction=allgemein');
					
				}
				
			}
			
		} // public function submitAction()
		
		/**
		 * Soll die Datenbank auf den neuesten Stand bringen
		 */
		public function updateAction()
		{ 
			
			include WPSG_PATH.'/lib/install.php';
						
			$this->shop->callMods('install');
						
			$this->addBackendMessage(__('Datenbank aktualisiert', 'wpsg'));
			
		} // public function updateAction()
		
		/**
		 * Zeigt die Hilfe für den Tooltip an
		 */
		private function loadHelpAction()
		{
			
			global $q_config;
			
			$page = $_REQUEST['field']; 
			
			$xml_content = $this->shop->get_url_content('http://trac.wpshopgermany.de/wiki/'.$page);

			if ($xml_content !== false && strlen(trim($xml_content)) > 0)
			{
			
				$doc = new DOMDocument();
				$doc->loadHTML($xml_content);
				
				$xpath = new DOMXPath($doc);
				$entries = $xpath->query('//div[@id="wikipage"]');
				
				foreach ($entries as $entry) {
	 
					$strReturn = $entry->ownerDocument->saveXml($entry);
					 
				}
				 
				$strReturn = preg_replace('/\"\//', '"http://trac.wpshopgermany.de/', $strReturn);
				
				$arLocales = $arLocales = $q_config['locale'];
				if (wpsg_isSizedArray($arLocales) && wpsg_isSizedString(get_locale()))
				{
				
					$iso_lang = array_search(get_locale(), $arLocales);
					
					if (wpsg_isSizedString($iso_lang) && preg_match('/&lt;localization_'.$iso_lang.'&gt;(.*)&lt;\/localization_'.$iso_lang.'&gt;/is', $strReturn))
					{

						$strReturn = preg_replace('/(.*)&lt;localization_'.$iso_lang.'&gt;/is', '', $strReturn);
						$strReturn = preg_replace('/&lt;\/localization_'.$iso_lang.'&gt;(.*)/is', '', $strReturn);
						
					}
				
					
				}
				
				// Andere Übersetzungen entfernen
				$strReturn = preg_replace('/&lt;localization_(.*)&gt;(.*)&lt;\/localization_(.*)&gt;/is', '', $strReturn);
				 
				//$strReturn .= '<a style="color:#FFFFFF; text-decoration:underline;" target="_blank" href="http://trac.wpshopgermany.de/wiki/'.$page.'">'.__('zur Hilfe Seite ...', 'wpsg').'</a><br /><br />';

			}
			else
			{

				$strReturn = __('Noch kein Hilfetext hinterlegt. Bitte versuchen Sie es später noch einmal.<br />Hilfe finden sie auch unter <a href="http://forum.maennchen1.de">http://forum.maennchen1.de</a>', 'wpsg');
				
			}
			 
			die($strReturn);
			
		} // private function loadHelpAction()
		
		/**
		 * Deaktiviert alle Plugins außer wpShopGermany und merkt sich die aktivierten Plugins
		 */
		public function plugintest_disableAction()
		{
			
			// Plugins vor dem Test
			$arPlugins = $this->shop->get_option('active_plugins');
									
			// Plugins vor dem Test speichern
			$this->shop->update_option('wpsg_plugintest_active_plugins', $arPlugins);
			
			// Alle Plugins außer wpShopGermany entfernen
			foreach ($arPlugins as $k => $p)
			{
				
				if (!preg_match('/(.*)wpshopgermany\.php(.*)/', $p)) unset($arPlugins[$k]);
				
			}
		 
			// Zurückspeichern
			$this->shop->update_option('active_plugins', $arPlugins);
			
			$this->shop->addBackendMessage(__('Es wurden alle Plugins bis auf wpShopGermany deaktiviert.', 'wpsg'));
			$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=ueber');
						
		} // public function plugintest_disableAction()
		
		/**
		 * Stellt die vorher mittels plugintest_disableAction deaktivierten Module wieder her
		 */
		public function plugintest_restoreAction()
		{
			
			$arPlugins_restore = $this->shop->get_option('wpsg_plugintest_active_plugins');
			
			if (!wpsg_isSizedArray($arPlugins_restore))
			{
				
				$this->shop->addBackendError(__('Plugins konnten nicht wieder hergestellt werden, da nicht gespeichert wurde welche Plugins aktiv waren.', 'wpsg'));
				
			}
			else
			{
								
				// Alte Plugins wieder herstellen
				$this->shop->update_option('active_plugins', $arPlugins_restore);
				
				$this->shop->update_option('wpsg_plugintest_active_plugins', false);
				
				$this->shop->addBackendMessage(__('Aktivierte Plugins wurden erfolgreich wieder hergesetellt.', 'wpsg'));
				
			}
			
			$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=ueber');
			
		} // public function plugintest_restoreAction()
		
		/**
		 * Installiert ein Modul
		 */
		public function installModul($modul_key)
		{
			
			$this->callMod('wpsg_mod_core', 'installModul', array($modul_key));
			
		} // private function installModul($modul_key)

		/**
		 * Import Funktion für die Daten aus Version 2
		 */
		private function importV2()
		{

			global $wpdb;

			error_reporting(E_ERROR); ini_set("display_errors", "1");
			
			// Zur Sicherheit ein paar Vorabprüfungen
			//$ProductCount = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_PRODUCTS."`");
			//if ($ProductCount > 0) { $this->addBackendError(__('Bitte löschen sie vor dem Import alle Produkte!', 'wpsg')); $this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe'); }
			
			$nOrderCount = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDER."` ");			
			if ($nOrderCount > 0) { $this->addBackendError(__('Bitte löschen sie vor dem Import alle Bestelldaten!', 'wpsg')); $this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe'); }
			
			$nCustomerCount = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_KU."` ");			
			if ($nCustomerCount > 0) { $this->addBackendError(__('Bitte löschen sie vor dem Import alle Kundendaten!', 'wpsg')); $this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe'); }
 
			if (isset($_REQUEST['submit_import']))
			{

				$_FILES['datei']['tmp_name'] = WPSG_PATH_CONTENT.'uploads/wpsg_upgrade.zip';
				
			}
			else if (!isset($_REQUEST['submit_import_db']))
			{
			
				if (!file_exists($_FILES['datei']['tmp_name'])) { $this->addBackendError(__('Kein Paket hochgeladen!', 'wpsg')); $this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe'); }
				
			}
			
			// Alte Optionen löschen
			//$this->db->Query("DELETE FROM `wp_options` WHERE `option_name` LIKE 'wpsg_%' AND `option_name` != 'wpsg_key' AND `option_name` != 'wpsg_installed' ");
			
			$arTables = $this->db->fetchAssocField("SHOW TABLES");
			
			if (in_array(WPSG_TBL_PRODUCTS, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PRODUCTS."`");
			if (in_array(WPSG_TBL_PRODUCTS_GROUP, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PRODUCTS_GROUP."`");
			if (in_array(WPSG_TBL_ORDER, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_ORDER."`");
			if (in_array(WPSG_TBL_KU, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_KU."`");
			if (in_array(WPSG_TBL_VZ, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_VZ."`");
			if (in_array(WPSG_TBL_LAND, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_LAND."`");
			if (in_array(WPSG_TBL_AT, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_AT."`");
			if (in_array(WPSG_TBL_PRODUCTS_AT, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PRODUCTS_AT."`");
			if (in_array(WPSG_TBL_OL, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_OL."`");
			if (in_array(WPSG_TBL_VA, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_VA."`");			
			if (in_array(WPSG_TBL_RECHNUNGEN, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_RECHNUNGEN."`");
			if (in_array(WPSG_TBL_GUTSCHEIN, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_GUTSCHEIN."`");			
			if (in_array(WPSG_TBL_PRODUCTS_REL, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PRODUCTS_REL."`");
			if (in_array(WPSG_TBL_EXPORTPROFILE, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_EXPORTPROFILE."`");
			if (in_array(WPSG_TBL_PRODUCTS_VARS, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PRODUCTS_VARS."`");
			if (in_array(WPSG_TBL_PRODUCTS_STICKY, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PRODUCTS_STICKY."`");
			if (in_array(WPSG_TBL_ZV, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_ZV."`");
			if (in_array(WPSG_TBL_VIDEOINDIV, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_VIDEOINDIV."`");
			if (in_array(WPSG_TBL_PDFINDIV, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PDFINDIV."`");
			if (in_array(WPSG_TBL_ORDERVARS, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_ORDERVARS."`");
			if (in_array(WPSG_TBL_ORDERCOND, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_ORDERCOND."`");
			if (in_array(WPSG_TBL_CABLOG, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_CABLOG."`");			
			if (in_array(WPSG_TBL_PAP, $arTables)) $this->db->Query("DELETE FROM `".WPSG_TBL_PAP."`");
			
			if (!isset($_REQUEST['submit_import_db']))
			{
				
				// Import aus Datei
				
				$mb = new wpsg_mod_basic();
				$path = $mb->getTmpFilePath().'/importV2/';
				
				if (file_exists($path)) wpsg_rrmdir($path);
				mkdir($path, 0777, true); 
				
				$zip = new ZipArchive();
				
				if ($zip->open($_FILES['datei']['tmp_name']) === true) 
				{
	
					$zip->extractTo($path);
	    			$zip->close();    			
					
				}
							
				// Verarbeitung der XML Datei
				$doc = new DOMDocument;
				$doc->Load($path.'/data.xml');
				
				$xpath = new DOMXPath($doc);
								
				// Versionsnummer prüfen
				$query = "//wpsg/settings/option[@option_name=\"wpshopgermany_version_installed\"]";
				$version = $xpath->query($query);
				 
				$version_node = $version->item(0);
				$version = $version_node->getAttribute("option_value");
				
				if ($version != "2.5.8")
				{
					
					$this->shop->addBackendError(__('Version des Exportes ist nicht kompatibel, bitte importieren Sie nur aus einem wpShopGermany aus der Version 2.5.8.', 'wpsg'));
					$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe');
					return false;
					
				}
				
				$query = "//wpsg/settings/option";
				$settings = $xpath->query($query);
				
			}
			else
			{
				
				if ($this->shop->isMultiBlog())
				{
				
					$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/';
					
				}
				else
				{
					
					$path = WP_CONTENT_DIR.'/uploads/';
					
				} 
				
			}
			
			$arSettingsMap = array(

				/* Allgemein */
				'wpsg_mwst_anteilig' => false,
				'wpsg_options_nl2br' => 'wpsg_options_nl2br', 
				'wpsg_options_rte_apply_filter' => 'wpsg_options_no_rte_apply_filter',
				'wpsg_order_format' => 'wpsg_format_onr',
				'wpsg_order_start' => 'wpsg_order_start',
				'wpsg_upload_classic' => 'wpsg_classicupload',
			
				/* Installierte Module */
				'mod_auftragbest' => 'wpsg_mod_auftragsbestaetigung',				
				'mod_bankeinzug' => 'wpsg_mod_autodebit',
				'mod_billsafe' => 'wpsg_mod_billsafe',
				'mod_cab' => 'wpsg_mod_cab',
				'mod_customerbudget' => 'wpsg_mod_customerbudget',
				'mod_nachnahme' => 'wpsg_mod_debitpayment',
				'mod_rabatt' => 'wpsg_mod_discount',
				'mod_downloadplus' => 'wpsg_mod_downloadplus',
				'mod_downloadprodukt' => 'wpsg_mod_downloadprodukt',
				'mod_exportplus' => 'wpsg_mod_export',
				'mod_freeshipping' => 'wpsg_mod_freeshipping',
				'mod_fuellmenge' => 'wpsg_mod_fuellmenge',
				'mod_gutschein' => 'wpsg_mod_gutschein',
				'mod_rechnung' => 'wpsg_mod_invoice_type',
				'mod_kundenkontakt' => 'wpsg_mod_kundenkontakt',
				'mod_kundenlogin' => 'wpsg_mod_kundenverwaltung',
				'mod_newsletter' => 'wpsg_mod_nlsatolo',
				'mod_orderupload' => 'wpsg_mod_orderupload',
				'mod_bestellvars' => 'wpsg_mod_ordervars',
				'mod_pap' => 'wpsg_mod_pap',
				'mod_paypal' => 'wpsg_mod_paypal',
				'mod_prepayment' => 'wpsg_mod_prepayment',
				'mod_produktgruppen' => 'wpsg_mod_productgroups',
				'mod_produktvars' => 'wpsg_mod_productvars',
				'mod_produktartikel' => 'wpsg_mod_produktartikel',
				'mod_produktbilder' => 'wpsg_mod_produktbilder',
				'mod_protectedshops' => 'wpsg_mod_protectedshops',
				'mod_rechnungen' => 'wpsg_mod_rechnungen',
				'mod_attribute' => 'wpsg_mod_produktattribute',
				'mod_shippingadress' => 'wpsg_mod_shippingadress',
				'mod_skrill' => 'wpsg_mod_skrill',
				'mod_stock' => 'wpsg_mod_stock',
				'mod_sb' => 'wpsg_mod_su',
				'mod_userpayment' => 'wpsg_mod_userpayment',
				'mod_variantenplus' => 'wpsg_mod_varianten',
				'mod_lieferanten' => 'wpsg_mod_versandarten',
				'mod_weight' => 'wpsg_mod_weight',
				'mod_selbstabholer' => 'wpsg_mod_willcollect',
			
				/* wpsg_mod_produktbilder */
				'wpshopgermany_produktbilder_tnwidth' => 'wpsg_mod_produktbilder_width',
				'wpshopgermany_produktbilder_tnheight' => 'wpsg_mod_produktbilder_height',
				'wpshopgermany_produktbilder_quality' => 'wpsg_mod_produktbilder_quality',
				'wpshopgermany_produktbilder_mode' => 'wpsg_mod_produktbilder_mode',
				
				/* wpsg_mod_kundenverwaltung */
				'wpsg_kundenlogin_salt' => 'wpsg_salt',
				'wpsg_kundenlogin_anfrage_betreff' => 'wpsg_kundenpwdrequest_betreff',
				'wpsg_kundenlogin_newpasswort_betreff' => 'wpsg_kundenpwd_betreff',
				'wpsg_kl_page' => 'wpsg_mod_kundenverwaltung_perpage',  
				'wpsg_kl_weber' => 'wpsg_mod_kundenverwaltung_aweber',
				'wpsg_kl_weber_meta_web_form_id' => 'wpsg_mod_kundenverwaltung_aweber_formid',
				'wpsg_kl_listname' => 'wpsg_mod_kundenverwaltung_aweber_listname',
				'wpsg_kl_meta_adtracking' => 'wpsg_mod_kundenverwaltung_aweber_metaAdtracking',
				'wpsg_kundenlogin_profil' => 'wpsg_page_mod_kundenverwaltung_profil',
				'wpsg_kundenlogin_register' => 'wpsg_page_mod_kundenverwaltung_registrierung',
				'wpsg_mod_kundenverwaltung_onlylogin' => 'wpsg_mod_kundenverwaltung_onlylogin',
			
				/* wpsg_mod_gutschein */
				'wpshopgermany_gutschein_size' => 'wpsg_mod_gutschein_size',
			
				/* wpsg_mod_pap */
				'wpsg_paplogin_pap_url' => 'wpsg_paplogin_pap_url',
				'wpsg_paplogin_admin' => 'wpsg_paplogin_admin',
				'wpsg_paplogin_passwort' => 'wpsg_paplogin_passwort',
				'wpsg_paplogin_register' => 'wpsg_paplogin_register',
				'wpsg_pap_registrierung' => 'wpsg_pap_registrierung',
				'wpsg_pap_include_profil' => false,
				'wpsg_pap_order_tracking' => 'wpsg_pap_order_tracking',
			
				/* wpsg_mod_export */
			
				/* Nicht kompatibel */
			
				/* wpsg_mod_customerbudget */
			
				/* Keine Einstellungen */
			
				/* wpsg_mod_versandarten */
			
				/* Keine Einstellungen */
				
				/* wpsg_mod_willcollect */
				'wpshopgermany_selbstabholer_rabgb' => 'wpsg_mod_willcollect_gebuehr', 
				'wpshopgermany_shipping_selbstabholer_name' => 'wpsg_mod_willcollect_adress',
				'wpshopgermany_shipping_selbstabholer_strnr' => 'wpsg_mod_willcollect_street',
				'wpshopgermany_shipping_selbstabholer_plzort' => 'wpsg_mod_willcollect_plzort',
			
				/* wpsg_mod_shippingadress */
				/* Keine Einstellungen */
			
				/* wpsg_mod_freeshipping */
				'wpshopgermany_freeshipping_value' => 'wpsg_mod_freeshipping_minvalue',
				'wpsg_mod_freeshipping_gutschein' => '', // TODO
			
				/* wpsg_mod_skrill */
				'wpsg_mod_skrill_bezeichnung' => 'wpsg_mod_skrill_bezeichnung',
				'wpsg_mod_skrill_recipient_description' => 'wpsg_mod_skrill_recipient_description',
				'wpsg_mod_skrill_email' => 'wpsg_mod_skrill_email',
				'wpsg_mod_skrill_id' => 'wpsg_mod_skrill_id',
				'wpsg_mod_skrill_gebuehr' => 'wpsg_mod_skrill_gebuehr',
				'wpsg_mod_skrill_currency' => 'wpsg_mod_skrill_currency',
				'wpsg_mod_skrill_autostart' => 'wpsg_mod_skrill_autostart',
				'wpsg_mod_skrill_code' => 'wpsg_mod_skrill_code',
				'wpsg_page_mod_skrill_success' => 'wpsg_page_mod_skrill_success',
				'wpsg_page_mod_skrill_success_url' => 'wpsg_page_mod_skrill_success_url',
				'wpsg_page_mod_skrill_error' => 'wpsg_page_mod_skrill_error',
				'wpsg_page_mod_skrill_error_url' => 'wpsg_page_mod_skrill_error_url',

				/* wpsg_mod_prepayment */
				'wpshopgermany_prepayment_rabgb' => 'wpsg_mod_prepayment_gebuehr',			
				'wpshopgermany_prepayment_inhaber' => 'wpsg_mod_prepayment_kinhaber',
				'wpshopgermany_prepayment_knr' => 'wpsg_mod_prepayment_knummer',
				'wpshopgermany_prepayment_bank' => 'wpsg_mod_prepayment_bank',
				'wpshopgermany_prepayment_blz' => 'wpsg_mod_prepayment_blz',
				'wpshopgermany_prepayment_ibanbic' => 'wpsg_mod_prepayment_iban',
				'wpshopgermany_prepayment_swift' => 'wpsg_mod_prepayment_swift',
				'wpshopgermany_prepayment_betreff' => 'wpsg_mod_prepayment_subject',
			
				/* wpsg_mod_paypal */
				'wpshopgermany_paypal_mail' => 'wpsg_mod_paypal_email',
				'wpshopgermany_paypal_sandbox' => 'wpsg_mod_paypal_sandbox',
				'wpshopgermany_paypal_rabgb' => 'wpsg_mod_paypal_gebuehr',
				'wpshopgermany_paypal_go' => 'wpsg_mod_paypal_autostart',
				'wpshopgermany_pp_pageconfirm' => 'wpsg_page_mod_paypal_success',
				'wpshopgermany_pp_pageconfirm_url' => false,
				'wpshopgermany_pp_pageerror' => 'wpsg_page_mod_paypal_error',
				'wpshopgermany_pp_pageerror_url' => false,
				'wpsg_paypal_currency' => 'wpsg_mod_paypal_currency',
				'wpsg_paypal_currency' => 'wpsg_mod_paypal_currency',				
							
				/* wpsg_mod_debitpayment */
				'wpshopgermany_shipping_nachnahme' => 'wpsg_mod_debitpayment_rabgeb',
			
				/* wpsg_mod_invoice_type */
				'wpshopgermany_rechnung_nachnahme' => 'wpsg_mod_invoice_type_gebuehr',
			
				/* wpsg_mod_su */
				'wpshopgermany_sb_rabgb' => 'wpsg_mod_su_gebuehr',
				'wpshopgermany_sb_user_id' => 'wpsg_mod_su_userid',
				'wpshopgermany_sb_project_id' => 'wpsg_mod_su_projectid',  
				'wpshopgermany_sb_projekt_password' => 'wpsg_mod_su_projectpassword',
				'wpshopgermany_sb_confirm_password' => 'wpsg_mod_su_noticepassword',
				'wpshopgermany_sb_hash' => 'wpsg_mod_su_hash',
				'wpshopgermany_sb_language_id' => 'wpsg_mod_su_language',
				'wpshopgermany_sb_currency_id' => 'wpsg_mod_su_currency',
				'wpshopgermany_sb_pageerror' => 'wpsg_page_mod_su_error',
				'wpshopgermany_sb_pageconfirm' => 'wpsg_page_mod_su_success',
				'wpsg_sb_go' => 'wpsg_mod_su_autostart',
			
				/* wpsg_mod_skrill */
				/* Modulkeys komplett gleich */
			
				/* wpsg_mod_userpayment */
				/* keine Optionen */
			
				/* wpsg_mod_debitpayment */
				'wpshopgermany_payment_bankeinzug' => 'wpsg_mod_autodebit_gebuehr',
			
				/* wpsg_mod_cap */
				'wpsg_cab_merchantid' => 'wpsg_mod_cab_merchantID',
				'wpsg_cab_mmskey' => 'wpsg_mod_cab_mmskryptkey',
				'wpsg_cab_projekttid' => 'wpsg_mod_cab_projectID',
				'wpsg_cab_mmsemail' => 'wpsg_mod_cab_mmsstatusmail',
				'wpsg_cab_secretKey' => 'wpsg_mod_cab_kryptkey',
				'wpsg_cab_rabgeb' => 'wpsg_mod_cab_gebuehr',
				'wpsg_cab_currency' => 'wpsg_mod_cab_currency',
				'wpsg_cab_auftragstext' => 'wpsg_mod_cab_auftragsbezeichnung',
				'wpsg_cab_sandbox' => 'wpsg_mod_cab_sandbox',
				'wpsg_cab_redirekt' => 'wpsg_mod_cab_currency',
				'wpshopgermany_cab_pageconfirm' => 'wpsg_mod_cab_success',
				'wpshopgermany_cab_pageerror' => 'wpsg_mod_cab_error',
				'wpshopgermany_cab_pageconfirm_url' => '',
				'wpshopgermany_cab_pageerror_url' => '',
			
				/* wpsg_mod_billsafe */
				'wpsg_billsafe_merchantid' => false,
				'wpsg_billsafe_lizenz' => 'wpsg_mod_billsafe_licence',
				'wpsg_billsafe_appkey' => false,
				'wpsg_billsafe_sandbox' => 'wpsg_mod_billsafe_sandbox',
				'wpsg_billsafe_lizenz_sandbox' => 'wpsg_mod_billsafe_licencesandbox',
				'wpsg_billsafe_rabgb' => 'wpsg_mod_billsafe_gebuehr',
				'wpsg_billsafe_go' => 'wpsg_mod_billsafe_autorun',
				'wpsg_billsafe_error' => 'wpsg_mod_billsafe_error',
				'wpsg_billsafe_erfolg' => 'wpsg_mod_billsafe_success',
				'wpsg_billsafe_logo' => 'wpsg_mod_billsafe_logo',
				'wpsg_billsafe_vorab' => 'wpsg_mod_billsafe_precheck',

				/* Rabatt */
				'wpsg_rabatt_produktrabatt' => 'wpsg_mod_discount_productdiscount',
				'wpsg_rabatt_produktgruppen' => 'wpsg_mod_discount_universal',
				'wpsg_rabatt_generell_von' => 'wpsg_mod_discount_universal_from',
				'wpsg_rabatt_generell_bis' => 'wpsg_mod_discount_universal_to',
				'wpsg_rabatt_generell_value' => 'wpsg_mod_discount_universal_value',
				'wpsg_rabatt_data' => 'wpsg_mod_discount_data',
	
				/* Rechnungen */
				'wpsg_rechnungen_adresszeile' => 'wpsg_rechnungen_adresszeile',
				'wpsg_rechnungen_url' => 'wpsg_rechnungen_url',
				'wpsg_rechnungen_auto' => 'wpsg_mod_rechnungen_auto',
				'wpsg_rechnungen_faelligkeit' => 'wpsg_rechnungen_faelligkeit',
				'wpsg_rechnungen_pbeschreibung' => 'wpsg_rechnungen_pbeschreibung',
				'wpsg_mod_rechnungen_showgutschriftrechnung' => 'wpsg_mod_rechnungen_showgutschriftrechnung',
				'wpsg_mod_rechnungen_showpv' => 'wpsg_mod_rechnungen_showpv',
				'wpsg_mod_rechnungen_showov' => 'wpsg_mod_rechnungen_showov',
				'wpsg_rechnungen_start' => 'wpsg_rechnungen_start',
				'wpsg_gutschrift_start' => 'wpsg_gutschrift_start',
				'wpsg_rechnungen_format' => 'wpsg_rechnungen_format',
				'wpsg_gutschrift_format' => 'wpsg_gutschrift_format',	

				/* Bestellupload */
			
				/* Zubehörprodukte  */
			
				/* Produktgruppen */
				'wpshopgermany_produktgruppen_page' => 'wpsg_productgroups_page',
				'wpsg_produktgruppen_sort' => 'wpsg_productgroups_order',
			
				/* Produktartikel */
			
				/* Fuellmengen */
				'wpshopgermany_fuellmenge_einheiten' => 'wpsg_mod_fuellmenge_einheit',
				'wpshopgermany_fuellmenge_bezug' => 'wpsg_mod_fuellmenge_bezug',
			
				/* Produktattribute */
			
				/* Lagerbestand */
				'wpshopgermany_stock_template' => 'wpsg_mod_stock_template',
				'wpshopgermany_stock_allow' => 'wpsg_mod_stock_allow',
			
				/* Downloadplus */
				'wpsg_dlplus_anpassung' => 'wpsg_mod_pdfdownload_range',
                'wpsg_dlplus_anpassung_bis' => 'wpsg_mod_pdfdownload_range_von',
                'wpsg_dlplus_anpassung_von' => 'wpsg_mod_pdfdownload_range_bis',
                'wpsg_dlplus_cronclear' => 'wpsg_mod_pdfdownload_cleanraiddownloads',
                'wpsg_dlplus_cronmail' => 'wpsg_pdfdownloadcronmail_empfaenger',                   
                'wpsg_dlplus_cronsend' => 'wpsg_mod_pdfdownload_autosend',
                'wpsg_dlplus_dokaforms' => 'wpsg_mod_pdfdownload_securitynote',
                'wpsg_dlplus_dokmodify' => 'wpsg_mod_pdfdownload_securitymod',
                'wpsg_dlplus_dokopenpwd' => 'wpsg_mod_pdfdownload_openpass',
                'wpsg_dlplus_dokprint' => 'wpsg_mod_pdfdownload_securityprint',
                'wpsg_dlplus_dokpwd' => 'wpsg_mod_pdfdownload_masterpass',
                'wpsg_dlplus_doksave' => 'wpsg_mod_pdfdownload_securitysave',
                'wpsg_dlplus_filename' => 'wpsg_mod_pdfdownload_filename',
			
				/* Seitenkonfiguration */
				'wpshopgermany_basketpage' => 'wpsg_page_basket',
				'wpshopgermany_agbpage' => 'wpsg_page_agb',
				'wpshopgermany_wrpage' => 'wpsg_page_widerrufsbelehrung',
				'wpshopgermany_dspage' => 'wpsg_page_datenschutz',
				'wpshopgermany_vkpage' => 'wpsg_page_versand',
				'wpshopgermany_imppage' => 'wpsg_page_impressum',

			); 
			
			$arSettingOld = array();

			// Ich bieg das hier etwas zusammen, da die Einstellungen einmal aus der Datenbank und einmal aus der XML Datei kommen können			
			if (!isset($_REQUEST['submit_import_db']))
			{

			
				// Import aus Datei				
				foreach ($settings as $entry) 
				{
					
					$blog_id = $entry->getAttribute("blog_id");
					$option_name = $entry->getAttribute("option_name");
					$option_value = $entry->getAttribute("option_value");
					$autoload = $entry->getAttribute("autoload");

					$arSettings[] = array(
						'blog_id' => $blog_id,
						'option_name' => $option_name,
						'option_value' => $option_value,
						'autoload' => $autoload
					);
					
				}
				
			}
			else
			{
				
				// Import direkt in der Datenbank
				$arSettings = $this->db->fetchAssoc("
					SELECT
						*
					FROM
						`".$wpdb->prefix."options`
					WHERE
						(
							`option_name` LIKE 'wpsg_%' OR
							`option_name` LIKE 'wpshopgermany_%' OR
							`option_name` LIKE 'mod_%'
						) 
						AND
						(
							`option_name` != 'wpshopgermany_installed' AND
							`option_name` != 'wpsg_mods_installed_mod_rechnungen' 							
						)
				");  
				
			}
			
			// Damit Fehler angezeigt werden aktivier ich den DEBUG Modus
			$this->shop->update_option('wpsg_debugModus', '1');
			
			foreach ($arSettings as $entry) 
			{
				
				$blog_id = $entry["blog_id"];
				$option_name = $entry["option_name"];
				$option_value = $entry["option_value"];
				$autoload = $entry["autoload"];
				
				if (!array_key_exists($option_name, $arSettingsMap))
				{
					
					$this->db->Query("DELETE FROM `".$wpdb->prefix."options` WHERE `option_name` = '".wpsg_q($option_name)."'");
					
					$this->db->ImportQuery($wpdb->prefix."options", array(
						'blog_id' => $blog_id,
						'option_name' => $option_name,
						'option_value' => $option_value,
						'autoload' => $autoload
					), true);
					//$this->shop->update_option($option_name, $option_value);
						
				}
				else if ($arSettingsMap[$option_name] !== false)
				{
				
					$this->db->Query("DELETE FROM `".$wpdb->prefix."options` WHERE `option_name` = '".wpsg_q($arSettingsMap[$option_name])."'");
					
					$this->db->ImportQuery($wpdb->prefix."options", array(
						'blog_id' => $blog_id,
						'option_name' => $arSettingsMap[$option_name],
						'option_value' => $option_value,
						'autoload' => $autoload
					), true);					
					//$this->shop->update_option($arSettingsMap[$option_name], $option_value);	
				
				}	 
     			
			} 
			
			// Spezielle Felder
			$wpsg_mod_downloadplus_text = array(
				0 => array(
					'aktiv' => $arSettings['wpsg_dlplus_watermark'],	
					'text' => $arSettings['wpsg_dlplus_watermark_text'], 
					'x' => $arSettings['wpsg_dlplus_watermark_x'],
					'y' => $arSettings['wpsg_dlplus_watermark_y'],
					'align' => $arSettings['wpsg_dlplus_watermark_center'],
					'bg' => $arSettings['wpsg_dlplus_watermark_bg'],
					'color' => $arSettings['wpsg_dlplus_watermark_color'],
					'alpha' => $arSettings['wpsg_dlplus_watermark_alpha'],
					'angle' => $arSettings['wpsg_dlplus_watermark_winkel'],
					'fontsize' => $arSettings['wpsg_dlplus_watermark_fontsize']					
				),
				1 => array(
					'aktiv' => $arSettings['wpsg_dlplus_text1'],
					'text' => $arSettings['wpsg_dlplus_text1_text'], 
					'x' => $arSettings['wpsg_dlplus_text1_x'],
					'y' => $arSettings['wpsg_dlplus_text1_y'],
					'align' => $arSettings['wpsg_dlplus_text1_center'],
					'bg' => $arSettings['wpsg_dlplus_text1_bg'],
					'color' => $arSettings['wpsg_dlplus_text1_color'],
					'alpha' => $arSettings['wpsg_dlplus_text1_alpha'],
					'angle' => $arSettings['wpsg_dlplus_text1_winkel'],
					'fontsize' => $arSettings['wpsg_dlplus_text1_fontsize']					
				),
				2 => array(
					'aktiv' => $arSettings['wpsg_dlplus_text2'],
					'text' => $arSettings['wpsg_dlplus_text2_text'], 
					'x' => $arSettings['wpsg_dlplus_text2_x'],
					'y' => $arSettings['wpsg_dlplus_text2_y'],
					'align' => $arSettings['wpsg_dlplus_text2_center'],
					'bg' => $arSettings['wpsg_dlplus_text2_bg'],
					'color' => $arSettings['wpsg_dlplus_text2_color'],
					'alpha' => $arSettings['wpsg_dlplus_text2_alpha'],
					'angle' => $arSettings['wpsg_dlplus_text2_winkel'],
					'fontsize' => $arSettings['wpsg_dlplus_text2_fontsize']					
				)
			);
			
			$this->shop->update_option('wpsg_mod_downloadplus_text', serialize($wpsg_mod_downloadplus_text));
			$this->shop->update_option('wpsg_mod_kundenverwaltung_showCheckoutRegisterzwand', $arSettings['wpsg_kl_register'] % 1);
			
			$this->shop->update_option('wpsg_installed', time(), true);
			
			// Module aktivieren, damit die Tabellen vorbereitet sind
			$this->shop->loadModule(true);
			foreach ($this->shop->arAllModule as $m_key => $m)
			{
			 
				if ($this->shop->get_option($m_key) > 0)
				{
					
					$init = base64_decode('aW5zdGFsbEZpcnN0'); //'installFirst';
					 
					$this->shop->arAllModule[$m_key]->$init();
					$this->shop->arAllModule[$m_key]->install();
					
				}
				
			} 
			
			// Welche Tabellen sind da?
			$arTables = $this->db->fetchAssocField("SHOW TABLES");
			
			if ($this->shop->isMultiBlog())
			{
				$target_path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/';
			}
			else
			{
				$target_path = WP_CONTENT_DIR.'/uploads/';
			}
			 
			if (!isset($_REQUEST['submit_import_db']))
			{
			
				// Verzeichnisse aus XML
				if (file_exists($path.'/wpsg_rechnungen/')) wpsg_copy(
					$path.'/wpsg_rechnungen/',
					$target_path.'/wpsg_rechnungen'
				);
				
				if (file_exists($path.'/wpsg_produktbilder/')) wpsg_copy(
					$path.'/wpsg_produktbilder/',
					$target_path.'/wpsg_produktbilder'
				);
								
				if (file_exists($path.'/produktfiles/')) wpsg_copy(
					$path.'/produktfiles/',
					$target_path.'/wpsg_produktfiles'
				);
				
			}
			else
			{
				
				// Verzeichnisse aus XML				
				if (file_exists($path.'/produktbilder/')) wpsg_copy(
					$path.'/produktbilder/',
					$target_path.'/wpsg_produktbilder'
				); 
				
				if (file_exists($path.'/produktfiles/')) wpsg_copy(
					$path.'/produktfiles/',
					$target_path.'/wpsg_produktfiles'
				);
				
			}
			 			
			// Tabellen
			$arTables_Import = array();
			
			if (!isset($_REQUEST['submit_import_db']))
			{
			
				// Import aus XML Datei
				
				$query = "//wpsg/*[@table_name]";
				$tables = $xpath->query($query);
			
				foreach ($tables as $t)
				{
					
					// Rows hinzufügen
					$rows = $t->getElementsByTagName("row");
					
					$arRows = array();
					
					foreach ($rows as $row_entry)
					{
					
						$row = array();
					
					  foreach ($row_entry->attributes as $attribute)
					  {
					  	
					  	$row[$attribute->name] = $attribute->value;
					  						  	
						}
						
						$arRows[] = $row;
						
					}
					 
					$arTables_Import[] = array(
						'name' => $t->getAttribute("table_name"),
						'rows' => $arRows
					);
					
				}
				
			}
			else
			{
				
				foreach ($arTables as $t)
				{
					
					if (preg_match('/\wpshopgermany\_/', $t))
					{
						
						$arTables_Import[] = array(
							'name' => $t,
							'rows' => $this->db->fetchAssoc("SELECT * FROM `".$t."`")
						);
						
					}
					
				}
				
			}
						
			foreach ($arTables_Import as $entry)
			{
				
				//$table_name = $entry->getAttribute("table_name");				
				//$rows = $entry->getElementsByTagName("row");
				
				$table_name = $entry['name'];
				$rows = $entry['rows'];
				 
				foreach ($rows as $row_entry)
				{
				
					if (preg_match('/wpshopgermany_products$/', $table_name)) // Produkte
					{
							
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'cdate' => wpsg_q($row_entry['cdate']),
							'name' => wpsg_q($row_entry['name']),
							'detailname' => wpsg_q($row_entry['detailname']),
							'anr' => wpsg_q($row_entry['anr']),
							'typ' => wpsg_q($row_entry['typ']),
							'preis' => wpsg_q($row_entry['preis']),
							'mwst_key' => 'c',
							'beschreibung' => wpsg_q($row_entry['beschreibung']),
							'pgruppe' => wpsg_q($row_entry['pgruppe']),
							'ptemplate_file' => wpsg_q($row_entry['ptemplate_file']),
							'deleted' => wpsg_q($row_entry['deleted']),
							'lang_parent' => wpsg_q($row_entry['lang_parent']),
							'lang_locale' => wpsg_q($row_entry['lang_locale']),
							'rabatt' => wpsg_q($row_entry['rabatt']),
							'posturl' => wpsg_q($row_entry['mod_impexp_posturl']),
							'posturl_verkauf' => wpsg_q($row_entry['mod_impexp_verkauf']),
							'posturl_bezahlung' => wpsg_q($row_entry['mod_impexp_bezahlung']),
							'produktvars' => wpsg_q($row_entry['produktvars']),
							'feinheit' => wpsg_q($row_entry['feinheit']),
							'fmenge' => wpsg_q($row_entry['fmenge']),
							'stock' => wpsg_q($row_entry['stock']),
							'stock_count' => wpsg_q($row_entry['stock_count']),
							'mod_varianten' => wpsg_q($row_entry['variantenplus']),
							'weight' => wpsg_q($row_entry['weight']),
							'partikel' => wpsg_q($row_entry['partikel']),
							'downloadplus' => wpsg_q($row_entry['downloadplus'])						
						);
						
						$this->db->ImportQuery(WPSG_TBL_PRODUCTS, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_order$/', $table_name)) // Bestellungen
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'onr' => wpsg_q($row_entry['onr']), 
							'cdate' => wpsg_q($row_entry['cdate']),
							'k_id' => wpsg_q($row_entry['k_id']),
							'ip' => wpsg_q($row_entry['ip']),
							'useragent' => wpsg_q($row_entry['useragent']),
							'comment' => wpsg_q($row_entry['comment']),
							'price_gesamt' => wpsg_q($row_entry['price_gesamt']),
							'price_shipping' => wpsg_q($row_entry['price_shipping']),
							'price_payment' => wpsg_q($row_entry['price_payment']),
							'price_rabatt' => wpsg_q($row_entry['price_rabatt']),
							'price_gs' => wpsg_q($row_entry['price_gs']),
							'mwst_payment' => wpsg_q($row_entry['mwst_payment']),
							'mwst_shipping' => wpsg_q($row_entry['mwst_shipping']),
							'type_shipping' => wpsg_q($row_entry['type_shipping']),
							'type_payment' => wpsg_q($row_entry['type_payment']),
							'shipping_vname' => wpsg_q($row_entry['shipping_vname']),
							'shipping_name' => wpsg_q($row_entry['shipping_name']),
							'shipping_strasse' => wpsg_q($row_entry['shipping_strasse']),
							'shipping_hausnr' => wpsg_q($row_entry['shipping_hausnr']),
							'shipping_plz' => wpsg_q($row_entry['shipping_plz']),
							'shipping_ort' => wpsg_q($row_entry['shipping_ort']),
							'shipping_land' => wpsg_q($row_entry['shipping_land']),
							'shipping_firma' => wpsg_q($row_entry['shipping_firma']),							
							'payed_date' => wpsg_q($row_entry['payed_date']),
							'bvars' => wpsg_q($row_entry['bvars']),
							'pvars' => wpsg_q($row_entry['pvars']),
							'status' => wpsg_q($row_entry['status']),
							'transaction' => wpsg_q($row_entry['transaction']),
							'dp_cron_planed' => wpsg_q($row_entry['dp_cron_planed']),
							'dp_cron_done' => wpsg_q($row_entry['dp_cron_done']),
							'gs_id' => wpsg_q($row_entry['gs_id']),
							'kleinunternehmer' => wpsg_q($row_entry['kleinunternehmer']),
							'custom_data' => wpsg_q($row_entry['']),
							'admincomment' => wpsg_q($row_entry['admincomment']),
							'language' => '', // Gab es früher nicht
							'mod_autodebit_name' => wpsg_q($row_entry['bname']),
							'mod_autodebit_blz' => wpsg_q($row_entry['bblz']),
							'mod_autodebit_inhaber' => wpsg_q($row_entry['binhaber']),
							'mod_autodebit_knr' => wpsg_q($row_entry['bnr']),
							'weight' => '', // Gab es früher nicht
							'mod_billsafe_token' => wpsg_q($row_entry['mod_billsafe_token']),
							'mod_billsafe_transaction_id' => wpsg_q($row_entry['mod_billsafe_transaction_id']),
							'cab_externalid' => wpsg_q($row_entry['cab_externalid']),
							'cab_requestTrackingID' => wpsg_q($row_entry['cab_requestTrackingID']),
							'cab_transactionID' => wpsg_q($row_entry['cab_transactionID']),
							'cab_transactionStatus' => wpsg_q($row_entry['cab_transactionStatus']),
							'cab_started' => wpsg_q($row_entry['cab_started']),
							'cab_lastupdate' => wpsg_q($row_entry['cab_lastupdate']),
							'cab_paylink' => wpsg_q($row_entry['cab_paylink']),
							'cab_repayed' => wpsg_q($row_entry['cab_repayed']),
						);
						
						$this->db->ImportQuery(WPSG_TBL_ORDER, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_attribute$/', $table_name) && in_array(WPSG_TBL_AT, $arTables)) // Produktattribute
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'name' => wpsg_q($row_entry['name']),
							'typ' => wpsg_q($row_entry['typ']),
							'auswahl' => '' // Gab es früher nicht
						);
						
						$this->db->ImportQuery(WPSG_TBL_AT, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_cab$/', $table_name) && in_array(WPSG_TBL_CABLOG, $arTables)) // Click & Buy Log
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'cdate' => wpsg_q($row_entry['cdate']),
							'extID' => wpsg_q($row_entry['extID']),
							'transID' => wpsg_q($row_entry['transID']),
							'eventID' => wpsg_q($row_entry['eventID']),
							'oldState' => wpsg_q($row_entry['oldState']),
							'newState' => wpsg_q($row_entry['newState'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_CABLOG, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_downloadplus$/', $table_name)) // Downloadplus
					{
						 
						//
						
					}
					else if (preg_match('/wpshopgermany_exportprofile$/', $table_name)) // Exportprofile
					{
						
					}
					else if (preg_match('/wpshopgermany_gutscheine$/', $table_name) && in_array(WPSG_TBL_GUTSCHEIN, $arTables)) // Gutscheine
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'code' => wpsg_q($row_entry['code']),
							'value' => wpsg_q($row_entry['value']),
							'o_id' => wpsg_q($row_entry['o_id']),
							'calc_typ' => wpsg_q($row_entry['calc_typ']),
							'cdate' => wpsg_q($row_entry['cdate']),
							'start_date' => wpsg_q($row_entry['start_date']),
							'end_date' => wpsg_q($row_entry['end_date']),
							'multi' => wpsg_q($row_entry['multi'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_GUTSCHEIN, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_kunden$/', $table_name)) // Kunden
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'knr' => '', // Neu
							'paypal_payer_id' => wpsg_q($row_entry['paypal_payer_id']),
							'title' => wpsg_q($row_entry['title']),
							'name' => wpsg_q($row_entry['name']),
							'vname' => wpsg_q($row_entry['vname']),
							'email' => wpsg_q($row_entry['email']),
							'firma' => wpsg_q($row_entry['firma']),
							'fax' => wpsg_q($row_entry['fax']),
							'strasse' => wpsg_q($row_entry['strasse']),
							'plz' => wpsg_q($row_entry['plz']),
							'ort' => wpsg_q($row_entry['ort']),
							'land' => wpsg_q($row_entry['land']),
							'tel' => wpsg_q($row_entry['tel']),
							'geb' => wpsg_q($row_entry['geb']),
							'ustidnr' => wpsg_q($row_entry['ustidnr']),
							'custom' => wpsg_q($row_entry['custom']),
							'passwort_saltmd5' => wpsg_q($row_entry['passwort_saltmd5']),
							'comment' => wpsg_q($row_entry['comment']),
							'budget' => wpsg_q($row_entry['budget']),
						);
						
						$this->db->ImportQuery(WPSG_TBL_KU, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_land$/', $table_name) && in_array(WPSG_TBL_LAND, $arTables)) // Länder
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'name' => wpsg_q($row_entry['bezeichnung']),
							'kuerzel' => wpsg_q($row_entry['kuerzel']),
							'vz' => wpsg_q($row_entry['vz']),
							'mwst' => wpsg_q($row_entry['mwst'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_LAND, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_lieferanten$/', $table_name) && in_array(WPSG_TBL_VA, $arTables)) // Lieferanten/Versandarten
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'name' => wpsg_q($row_entry['name']),
							'vz' => wpsg_q($row_entry['vz']),
							'hint' => '', // Neu
							'mwst' => '', // War früher Wert sollte überprüft werden !
							'mwst_laender' => '', // Gab es nicht
							'typ' => wpsg_q($row_entry['typ']),
							'kosten' => wpsg_q($row_entry['kosten']),
							'deleted' => wpsg_q($row_entry['deleted']),
							'aktiv' => '1'
						); 
						
						$this->db->ImportQuery(WPSG_TBL_VA, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_mwst$/', $table_name)) // Mehrwertsteuer
					{
						
						// Nix machen mit den Datensätzen
						
					}
					else if (preg_match('/wpshopgermany_orderlog$/', $table_name)) // Bestellprotokoll
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'o_id' => wpsg_q($row_entry['o_id']),
							'cdate' => wpsg_q($row_entry['cdate']),
							'title' => wpsg_q($row_entry['title']),
							'mailtext' => wpsg_q($row_entry['mailtext'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_OL, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_ordervars$/', $table_name) && in_array(WPSG_TBL_ORDERVARS, $arTables)) // Bestellvariablen
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'name' => wpsg_q($row_entry['name']),
							'typ' => wpsg_q($row_entry['typ']),
							'auswahl' => wpsg_q($row_entry['auswahl']),
							'pflicht' => wpsg_q($row_entry['pflicht']),
							'deleted' => '0' // Gab es früher nicht														
						);
						
						$this->db->ImportQuery(WPSG_TBL_ORDERVARS, $data_ins, true);
						
						// Übersetzte Bestellvariablen müssen manuell nachgetragen werden
						
					}
					else if (preg_match('/wpshopgermany_order_products$/', $table_name)) // PRodukt <-> Bestellung
					{
						
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'o_id' => wpsg_q($row_entry['o_id']),
							'p_id' => wpsg_q($row_entry['p_id']),
							'menge' => wpsg_q($row_entry['menge']),
							'price' => wpsg_q($row_entry['price']),
							'mwst' => '', // Die Zuordnung der ID gibt es im alten nicht
							'mwst_value' => wpsg_q($row_entry['mwst']),
							'mod_downloadprodukt_counter' => wpsg_q($row_entry['mod_downloadprodukt_counter']),
							'mod_vp_varkey' => wpsg_q($row_entry['mod_vp_varkey']),
							'weight' => '' // Gewicht wurde früher nicht erfasst
						);
						
						$this->db->ImportQuery(WPSG_TBL_ORDERPRODUCT, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_products_attribute$/', $table_name) && in_array(WPSG_TBL_PRODUCTS_AT, $arTables))  
					{
						
						$data_ins = array(
							'p_id' => wpsg_q($row_entry['p_id']),
							'a_id' => wpsg_q($row_entry['a_id']),
							'value' => wpsg_q($row_entry['value'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_PRODUCTS_AT, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_products_vari$/', $table_name))
					{
						
						// Entfällt 
						
					}
					else if (preg_match('/wpshopgermany_produktgruppen$/', $table_name) && in_array(WPSG_TBL_PRODUCTS_GROUP, $arTables))
					{
						
						// Produktgruppen
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'cdate' => wpsg_q($row_entry['cdate']),
							'name' => wpsg_q($row_entry['name']),
							'template_file' => wpsg_q($row_entry['template_file']),
							'infopage' => wpsg_q($row_entry['infopage']),
							'deleted' => wpsg_q($row_entry['deleted']),
							'rabatt' => wpsg_q($row_entry['rabatt'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_PRODUCTS_GROUP, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_produktsticky$/', $table_name) && in_array(WPSG_TBL_PRODUCTS_STICKY, $arTables))
					{
						
						// Produkt Sticky
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'produkt_id' => wpsg_q($row_entry['produkt_id']),
							'von' => wpsg_q($row_entry['von']),
							'bis' => wpsg_q($row_entry['bis'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_PRODUCTS_STICKY, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_produktvars$/', $table_name) && in_array(WPSG_TBL_PRODUCTS_VARS, $arTables))
					{
						
						// Produktvariablen
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'name' => wpsg_q($row_entry['name']),
							'typ' => wpsg_q($row_entry['typ']),
							'auswahl' => wpsg_q($row_entry['auswahl']),
							'pflicht' => wpsg_q($row_entry['pflicht'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARS, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_rechnungen$/', $table_name) && in_array(WPSG_TBL_RECHNUNGEN, $arTables))
					{
						
						// Rechnungen
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'o_id' => wpsg_q($row_entry['o_id']),
							'datum' => wpsg_q($row_entry['datum']),
							'storno' => wpsg_q($row_entry['storno']),
							'rnr' => wpsg_q($row_entry['rnr']),
							'gnr' => wpsg_q($row_entry['gnr'])
						);
						
						$this->db->ImportQuery(WPSG_TBL_RECHNUNGEN, $data_ins, true);
						
					}
					else if (preg_match('/wpshopgermany_zahlvarianten$/', $table_name) && in_array(WPSG_TBL_ZV, $arTables))
					{
						
						// Zahlvarianten
						$data_ins = array(
							'id' => wpsg_q($row_entry['id']),
							'name' => wpsg_q($row_entry['name']),
							'rabgeb' => wpsg_q($row_entry['rabgeb']),
							'hint' => '',
							'mwst' => '0',
							'mwst_laender' => '0',
							'aktiv' => '1'
						);
						
						$this->db->ImportQuery(WPSG_TBL_ZV, $data_ins, true);
						
					}
					
				}
				
			}
			
			// Alte Tabellen löschen
			if ($_REQUEST['tabledel'] == '1')
			{
				
				foreach ($arTables_Import as $t)
				{

					$this->db->Query("DROP TABLE IF EXISTS `".$t['name']."`");
					
				}
				 
				//if (file_exists($path.'/produktbilder/')) wpsg_rrmdir($path.'/produktbilder/');
				//if (file_exists($path.'/produktfiles/')) wpsg_rrmdir($path.'/produktfiles/');
				 
			}
			 
			$this->addBackendMessage(__('Import war erfolgreich, bitte prüfen Sie die Daten.', 'wpsg')); 
			$this->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=hilfe');
			
		} // private function importV2()

		/**
		 * Nach dem Update auf Version3 ist es durch den Export in die XML Datei zu einer serialisierung des schon serialisierten Strings gekommen
		 * Diese Funktion korrigiert dies
		 * Es betrifft folgende Schlüssel: 
		 * 
		 * wpsg_admin_pflicht
		 * wpsg_mod_discount_data
		 * wpsg_mod_downloadplus_text
		 * wpsg_mod_pdfdownload_text
		 * wpsg_mod_rechnungen_texte
		 * wpsg_rechnungen_footer
		 * 
		 * Aufgerufen wird sie im Backend bei den allgemeinen Einstellungen
		 */
		private function CheckAndCorrectSerOption()
		{
			
			$arOptions = array('wpsg_admin_pflicht', 'wpsg_mod_discount_data', 'wpsg_mod_downloadplus_text', 'wpsg_mod_pdfdownload_text', 'wpsg_mod_rechnungen_texte', 'wpsg_rechnungen_footer');
			
			foreach ($arOptions as $o)
			{
				
				$value = $this->shop->get_option($o);
				
				if ($value === false) continue; // Wert ist überhaupt nicht gesetzt, eventuell weil Modul nicht aktiviert
				
				if (!is_array($value) && (is_string($value) && preg_match('/^a\:\d+/', $value)))
				{
					
					$korrektur_value = @unserialize($value);
					
					if (is_array($korrektur_value)) $this->shop->update_option($o, $korrektur_value);
					
					 
				}
				 
			}
			
		} // public function CheckAndCorrectSerOption()
		
	} // class wpsg_AdminController extends wpsg_SystemController

?>