Index: /mods/wpsg_mod_si.class.php
===================================================================
--- /mods/wpsg_mod_si.class.php	(revision 5517)
+++ /mods/wpsg_mod_si.class.php	(revision 5517)
@@ -0,0 +1,243 @@
+<?php
+
+	/**
+	 * 	Modul fÃŒr die Zahlungsart SofortIdent
+ 	 */
+	class wpsg_mod_si extends wpsg_mod_basic
+	{
+		
+		var $lizenz = 2; 
+		var $id = 13; 
+		var $url = false; 
+		var $hilfeURL = 'http://wpshopgermany.de/?p=3770983';
+				
+		const HASH_MD5 = '0';
+		const HASH_SHA1 = '1';
+		const HASH_SHA256 = '2';
+		const HASH_SHA512 = '3';
+		
+		/**
+		 * Constructor
+		 */
+		public function __construct()
+		{
+			
+			parent::__construct(); 
+			
+			$this->name = __('SOFORT Ident','wpsg');
+			$this->group = __('Sonstiges','wpsg');
+			$this->desc = __('','wpsg');
+			
+		} // public function __construct()
+		
+		public function install() 
+		{
+						
+			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
+			
+			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS." (
+			  	wpsg_mod_si_check INT(1) NOT NULL,
+				wpsg_mod_si_minage INT(11) NOT NULL
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+				
+			dbDelta($sql);
+			
+			// Voreinstellungen
+			
+			$this->shop->checkDefault('wpsg_mod_si_hashalgo', self::HASH_SHA1);
+			$this->shop->checkDefault('wpsg_mod_si_minAge', 18);
+								 		
+		} //function install()
+		
+		public function settings_edit()
+		{
+		 
+			$this->shop->view['wpsg_mod_si']['returnURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_si', 'return', array('order_id' => '-USER_VARIABLE_0-'));
+			
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_si/settings_edit.phtml');
+		
+		} // public function settings_edit()
+		
+		public function settings_save() 
+		{
+			
+			$this->shop->update_option('wpsg_mod_si_user_id', $_REQUEST['wpsg_mod_si_user_id']);
+			$this->shop->update_option('wpsg_mod_si_project_id', $_REQUEST['wpsg_mod_si_project_id']);
+			
+			$this->shop->update_option('wpsg_mod_si_project_pwd', $_REQUEST['wpsg_mod_si_project_pwd']);
+			$this->shop->update_option('wpsg_mod_si_hashalgo', $_REQUEST['wpsg_mod_si_hashalgo']);
+			
+			$this->shop->update_option('wpsg_mod_si_minAge', $_REQUEST['wpsg_mod_si_minAge']);
+			
+		} // public function settings_save() 
+		  
+		public function produkt_edit_allgemein(&$produkt_data)
+		{
+				
+			if (isset($_REQUEST['wpsg_lang'])) return;
+				
+			$this->shop->view['wpsg_mod_si']['check'] = wpsg_getStr($produkt_data['wpsg_mod_si_check']); 
+			$this->shop->view['wpsg_mod_si']['minAge'] = ((wpsg_isSizedInt($produkt_data['wpsg_mod_si_minage']))?$produkt_data['wpsg_mod_si_minage']:$this->shop->get_option('wpsg_mod_si_minAge'));
+				
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_si/produkt_edit_allgemein.phtml');
+				
+		} // public function produkt_edit_sidebar(&$produkt_data)
+		
+		public function produkt_save_before(&$produkt_data)
+		{
+				
+			$produkt_data['wpsg_mod_si_check'] = wpsg_getStr($_REQUEST['wpsg_mod_si']['check']);
+			$produkt_data['wpsg_mod_si_minage'] = wpsg_getStr($_REQUEST['wpsg_mod_si']['minAge']);
+				
+		} // public function produkt_save_before(&$produkt_data)
+		 
+		public function canFinishOrder($temp_order_id)
+		{
+			
+			if ($this->isRestrictedOrder($temp_order_id) === true) return -2;
+			
+		} // public function canFinishOrder($temp_order_id)
+		
+		public function canNotOrder($temp_order_id) 
+		{ 
+			
+			if ($this->isRestrictedOrder($temp_order_id))
+			{
+				
+				$this->shop->view['wpsg_mod_si']['modul'] = $this;				
+				$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_si/cannotorder.phtml');
+								
+			}
+			
+		} // public function canNotOrder($temp_order_id)
+		
+		/* Modulfunktionen */
+		
+		public function returnRedirect()
+		{
+			 
+			$arLocalHashData = array(
+				$this->shop->get_option('wpsg_mod_si_user_id'), $this->shop->get_option('wpsg_mod_si_project_id'), wpsg_getStr($_REQUEST['firstname']), wpsg_getStr($_REQUEST['lastname']), wpsg_getStr($_REQUEST['street']), wpsg_getStr($_REQUEST['city']), wpsg_getStr($_REQUEST['zipcode']), wpsg_getStr($_REQUEST['birthday']),
+				wpsg_getStr($_REQUEST['address_country_id']), wpsg_getStr($_REQUEST['bank_code']), wpsg_getStr($_REQUEST['account_country_id']), wpsg_getStr($_REQUEST['order_id']),
+				wpsg_getStr($_REQUEST['user_variable_1']), wpsg_getStr($_REQUEST['user_variable_2']), wpsg_getStr($_REQUEST['user_variable_3']), wpsg_getStr($_REQUEST['user_variable_4']),
+				wpsg_getStr($_REQUEST['user_variable_5']), wpsg_getStr($_REQUEST['agecheck_result'])
+			);
+			
+			$hash = $this->getSendHash($arLocalHashData);
+			
+			if ($hash === $_REQUEST['agecheck_hash'])
+			{
+				
+				$oOrder = wpsg_order::getInstance($_REQUEST['order_id']);
+				
+				if (wpsg_isSizedString($_REQUEST['agecheck_result'], 'valid') && wpsg_isSizedInt($_REQUEST['age']))
+				{
+										
+					$bValid = true;
+					
+					foreach ($oOrder->getOrderProducts() as $oOrderProduct)
+					{
+					
+						$oProduct = $oOrderProduct->getProduct();
+					
+						if (wpsg_isSizedInt($oProduct->wpsg_mod_si_check))
+						{
+								
+							if ($oProduct->wpsg_mod_si_minage > $_REQUEST['age'])
+							{
+								
+								$this->shop->addFrontendError(wpsg_translate(__('FÃŒr Produkte #1# benÃ¶tigen Sie ein Mindestalter von #2# Jahren', 'wpsg'), $oProduct->getProductName(), $oProduct->wpsg_mod_si_minage));
+								$bValid = false;
+								
+							}
+															
+						}
+					
+					}
+				
+					$oOrder->setMeta('wpsg_mod_si_age', $_REQUEST['age']);
+					
+				}
+				else
+				{
+					
+					die(__('Fehler beim HASH Abgleich. Bitte Projektpasswort und Hash Algorithmus auf beiden Seiten ÃŒberprÃŒfen.', 'wpsg'));
+					
+				}
+				
+				if ($bValid === true) $this->shop->addFrontendMessage(__('Ihr Alter wurde erfolgreich ÃŒberprÃŒft und Sie kÃ¶nnen die Bestellung nun abschlieÃen.', 'wpsg')); 
+				
+				$oOrder->log(__('RÃŒckgabe der SOFORT Ident Alterverifizierung', 'wpsg'), print_r($_REQUEST, 1));
+								
+			}
+			
+			$this->shop->redirect($this->shop->getURL(wpsg_ShopController::URL_OVERVIEW)); 
+			
+		} // public function returnRedirect()
+		
+		public function getSendHash($arParam)
+		{
+			
+			$arHash = array_values($arParam);
+			$arHash[] = $this->shop->get_option('wpsg_mod_si_project_pwd');
+			 
+			$algo = '';
+			
+			switch ($this->shop->get_option('wpsg_mod_si_hashalgo'))
+			{
+				
+				case self::HASH_MD5: $algo = 'md5'; break;
+				case self::HASH_SHA1: $algo = 'sha1'; break;
+				case self::HASH_SHA256: $algo = 'sha256'; break;
+				case self::HASH_SHA512: $algo = 'sha512'; break;
+				
+				default: die(__('UngÃŒltiger HASH Algoritmus', 'wpsg'));
+				
+			}
+
+			$data_implode = implode('|', $arHash);
+			$hash = hash($algo, $data_implode);
+			
+			return $hash;
+			
+		} // public function getSendHash()
+		
+		/**
+		 * Gibt true zurÃŒck, wenn fÃŒr die Bestellung ein Altersabgleich durchgefÃŒhrt werden muss
+		 * Wurde der Check bereits durchgefÃŒhrt wird auch false zurÃŒckgegeben
+		 * @param Integer $order_id Id der Bestellung
+		 * @return Boolean true|false Ob ein Check noch nÃ¶tig ist
+		 */
+		public function isRestrictedOrder($order_id)
+		{
+			
+			$oOrder = wpsg_order::getInstance($order_id);
+			$min_age = 0;
+			 			
+			foreach ($oOrder->getOrderProducts() as $oOrderProduct)
+			{
+				
+				$oProduct = $oOrderProduct->getProduct();
+				
+				if (wpsg_isSizedInt($oProduct->wpsg_mod_si_check)) 
+				{
+			
+					$product_minAge = $oProduct->wpsg_mod_si_minage;
+					if (!wpsg_isSizedInt($product_minAge)) $product_minAge = $this->shop->get_option('wpsg_mod_si_minAge'); 					
+					
+					if ($min_age < $product_minAge) $min_age = $product_minAge;
+										
+				}
+								
+			} 
+			
+			if ($min_age === 0) return false;
+			
+			if (!wpsg_isSizedInt($oOrder->getMeta('wpsg_mod_si_age')) || $oOrder->getMeta('wpsg_mod_si_age') < $min_age) return true;
+			else return false;
+			
+		} // public function isRestrictedOrder($order_id)
+		
+	} // class wpsg_mod_si extends wpsg_mod_basic
+	
+?>
Index: /system/conf.php
===================================================================
--- /system/conf.php	(revision 5515)
+++ /system/conf.php	(revision 5517)
@@ -21,4 +21,5 @@
 		"user_views", "bildertest.phtml",
 		"user_mods",
+		"mod_si", "wpsg_mod_si.class.php", "wpsg_mod_si",
 		"mod_customernr", "mod_customernr.class.php",
 		"translation.php",
Index: /system/module.php
===================================================================
--- /system/module.php	(revision 5515)
+++ /system/module.php	(revision 5517)
@@ -38,4 +38,13 @@
 			'hide' => true
 		),		
+		'wpsg_mod_si' => array(
+				'modulname' => 'wpsg_mod_si',
+				'files' => array(
+						'mods/wpsg_mod_si.class.php',
+						'views/mods/mod_si'
+				),
+				'url' => '',
+				'hide' => true
+		),
 		/*
 		'wpsg_mod_ordercondition' => array(
Index: /views/mods/mod_si/cannotorder.phtml
===================================================================
--- /views/mods/mod_si/cannotorder.phtml	(revision 5517)
+++ /views/mods/mod_si/cannotorder.phtml	(revision 5517)
@@ -0,0 +1,45 @@
+<?php
+
+	/**
+	 * Integration in die Bestellzusammenfassung
+	 */
+
+	$bic = wpsg_getStr($this->view['basket']['checkout']['mod_autodebit_bic'], '');
+
+	$arParam = array(
+		'user_id' => $this->get_option('wpsg_mod_si_user_id'), // Ihre Kundennummer bei SOFORT, z.B. "12345"
+		'project_id' => $this->get_option('wpsg_mod_si_project_id'), // Ihre Projektnummer des SOFORT Ident Projekts, z.B. "54321"
+		'firstname' => $this->view['basket']['checkout']['vname'], // Vorname des Kunden, z.B. "Max"
+		'lastname' => $this->view['basket']['checkout']['name'], // Nachname des Kunden, z.B. "Mustermann"
+		'street' => $this->view['basket']['checkout']['strasse'], // StraÃe und Hausnummer des Kunden, z.B. "Unter den Linden 77"
+		'city' => $this->view['basket']['checkout']['ort'], // Wohnort des Kunden, z.B. "Berlin"
+		'zipcode' => $this->view['basket']['checkout']['plz'], // PLZ des Kunden, z.B. "10117"
+		'birthday' => date('Y-m-d', strtotime($this->view['basket']['checkout']['plz'])), // Geburtsdatum des Kunden im Format YYYY-MM-DD, z.B. "1978-09-24"
+		'address_country_id' => $this->view['basket']['land']['kuerzel'], // 2-stellige AbkÃŒrzung des Landes des Kunden im ISO-3166-1 Format, z.B. "DE"
+		'bank_code' => $bic, // BIC (DEPRECATED: oder Bankleitzahl) der Bankfiliale des Kunden
+		'account_country_id' => $this->view['basket']['land']['kuerzel'], // 2-stellige AbkÃŒrzung des Landes der Bankfiliale des Kunden im ISO-3166-1 Format, z.B. "DE"
+		'user_variable_0' => $this->view['temp_order_id'], // Kundenvariable (optional), z.B. "123456"
+		'user_variable_1' => '', // Kundenvariable (optional)
+		'user_variable_2' => '', //	Kundenvariable (optional)
+		'user_variable_3' => '', //	Kundenvariable (optional)
+		'user_variable_4' => '', //	Kundenvariable (optional)
+		'user_variable_5' => '' //	Kundenvariable (optional) 
+	);
+
+	$arParam['hash'] = $this->view['wpsg_mod_si']['modul']->getSendHash($arParam);
+	 
+?>
+
+</form>
+
+<form method="post" id="wpsg_mod_si_form" action="https://www.sofort.com/payment/agecheck">
+    	
+    <?php foreach ($arParam as $key => $value) { ?>
+    <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>" />
+    <?php } ?>
+    	
+   	<input type="submit" value="<?php echo __('Altersverifizierung', 'wpsg'); ?>" />
+    
+</form>
+
+<form method="post" action="<?php echo $this->getURL(wpsg_ShopController::URL_BASKET); ?>">
Index: /views/mods/mod_si/produkt_edit_allgemein.phtml
===================================================================
--- /views/mods/mod_si/produkt_edit_allgemein.phtml	(revision 5517)
+++ /views/mods/mod_si/produkt_edit_allgemein.phtml	(revision 5517)
@@ -0,0 +1,27 @@
+<?php
+
+	/**
+	 * Integration des Moduls SOFORT Ident in die allgemeinen Einstellungen eines Produktes
+	 */
+
+?>
+<?php echo wpsg_drawForm_Checkbox('wpsg_mod_si[check]', __('SOFORT Ident PrÃŒfung erforderlich', 'wpsg'), $this->view['wpsg_mod_si']['check'], array('id' => 'wpsg_mod_si_checkbox')); ?>
+
+<div id="wpsg_mod_si_age" style="display:none;">
+	<?php echo wpsg_drawForm_Input('wpsg_mod_si[minAge]', __('Mindestalter', 'wpsg'), $this->view['wpsg_mod_si']['minAge']); ?><br />
+</div>
+
+<script type="application/javascript">/* <![CDATA[ */
+
+	jQuery(document).ready(function() {
+
+		jQuery('#wpsg_mod_si_checkbox').bind('change', function() {
+
+			if (jQuery(this).prop('checked') == true) jQuery('#wpsg_mod_si_age').show();
+			else jQuery('#wpsg_mod_si_age').hide();
+			
+		} ).change();
+		
+	} );
+
+/* ]]> */</script>
Index: /views/mods/mod_si/settings_edit.phtml
===================================================================
--- /views/mods/mod_si/settings_edit.phtml	(revision 5517)
+++ /views/mods/mod_si/settings_edit.phtml	(revision 5517)
@@ -0,0 +1,28 @@
+<?php
+
+	/**
+	 * Template fÃŒr die Einstellungen des Moduls "SOFORT Ident"
+	 */
+
+?>
+
+<?php echo wpsg_drawForm_Input('wpsg_mod_si_user_id', __('Kundennummer bei SOFORT Ident', 'wspg'), $this->get_option('wpsg_mod_si_user_id'), array('help' => 'wpsg_mod_si_user_id')); ?>
+<?php echo wpsg_drawForm_Input('wpsg_mod_si_project_id', __('Projektnummer bei SOFORT Ident', 'wspg'), $this->get_option('wpsg_mod_si_project_id'), array('help' => 'wpsg_mod_si_project_id')); ?>
+
+<br />
+
+<?php echo wpsg_drawForm_Input('wpsg_mod_si_project_pwd', __('Projektpasswort', 'wpsg'), $this->get_option('wpsg_mod_si_project_pwd'), array('help' => 'wpsg_mod_si_project_pwd')); ?>
+<?php echo wpsg_drawForm_Select('wpsg_mod_si_hashalgo', __('HASH Algorithmus', 'wpsg'), array(
+	wpsg_mod_si::HASH_MD5 => __('MD5', 'wpsg'),
+	wpsg_mod_si::HASH_SHA1 => __('SHA1', 'wpsg'),
+	wpsg_mod_si::HASH_SHA256 => __('SHA256', 'wpsg'),
+	wpsg_mod_si::HASH_SHA512 => __('SHA512', 'wpsg'),
+), $this->get_option('wpsg_mod_si_hashalgo'), array('help' => 'wpsg_mod_si_hashalgo')); ?>
+
+<br />
+
+<?php echo wpsg_drawForm_Input('wpsg_mod_si_minAge', __('Mindestalter (Produktvorgabe)', 'wpsg'), $this->get_option('wpsg_mod_si_minAge'), array('help' => 'wpsg_mod_si_minAge')); ?>
+
+<br />
+
+<?php echo wpsg_drawForm_Input('', __('RÃŒcksprung-URL', 'wpsg'), $this->view['wpsg_mod_si']['returnURL'], array('readonly' => true, 'help' => 'wpsg_mod_si_returnURL')); ?>
