<?php

	/**
	 * Integriert die Anmeldung für das Satollo Newsletter Plugin in den Shop
	 * @author daniel
	 */
	class wpsg_mod_nlsatolo extends wpsg_mod_basic 
	{

		var $lizenz = 1;
		var $id = 600;
		
		/**
		 * Costructor
		 */
		public function __construct()
		{
			
			parent::__construct();
			
			$this->name = __('Satollo Newsletter', 'wpsg');
			$this->group = __('Sonstiges', 'wpsg');
			$this->desc = __('Ermöglicht die Anmeldung an das "<a href="http://wordpress.org/extend/plugins/newsletter/">Newsletter</a>" Plugin von Satollo.', 'wpsg');
						
		} // public function __construct()
		
		public function order_done(&$order_id, &$done_view) 
		{ 

			if (isset($_SESSION['wpsg']['wpsg_mod_nlsatolo']))
			{
				
				global $newsletter;
			  			
				if (function_exists("newsletter_subscribe"))
				{
					
					// Version <= 1.5.9
					
					newsletter_subscribe($done_view['basket']['checkout']['email'], $done_view['basket']['checkout']['vname'].' '.$done_view['basket']['checkout']['name']);
					$this->addFrontendMessage(__("Sie wurden erfolgreich in unseren Newsletter eingetragen.", "wpsg"));
					
				}
				else if (get_class($newsletter) == "Newsletter")
				{
				
					// Version >= 2.5.0
					
					$_REQUEST['na'] = 's';
					$_REQUEST['nn'] = $done_view['basket']['checkout']['vname'];
					$_REQUEST['ns'] = $done_view['basket']['checkout']['name'];
					$_REQUEST['ne'] = $done_view['basket']['checkout']['email'];
 
					$newsletter->hook_init();
					
					$this->shop->addFrontendMessage(__("Sie wurden erfolgreich in unseren Newsletter eingetragen.", "wpsg"));
					
				}
				else
				{
					
					$this->shop->addFrontendError(__('Sie wurden nicht zum Newsletter angemeldet, da das Plugin "newsletter" nicht installiert ist.', 'wpsg'));
				
				}
				
			} 
						
		} // public function order_done(&$order_id)
		
		public function basket_save_done(&$o_id, &$k_id, &$oBasket)
		{
			
			global $newsletter;
						
			$arBasket = $oBasket->toArray();
			
			if ($arBasket['checkout']['wpsg_mod_nlsatolo'] == '1')
			{
				
				if (function_exists("newsletter_subscribe"))
				{
					
					// Version <= 1.5.9
					newsletter_subscribe($arBasket['checkout']['email'], $arBasket['checkout']['vname'].' '.$arBasket['checkout']['name']);
					$this->shop->addFrontendMessage(__("Sie wurden erfolgreich in unseren Newsletter eingetragen.", "wpsg"));
					
				}
				else if (get_class($newsletter) == "Newsletter")
				{
					//für Versionen >= 3.0.2
					if (version_compare(NEWSLETTER_VERSION, '3.0.2') >= 0)
					{

						global $newsletter;
						
						$user = array(
							'email' 	=> $arBasket['checkout']['email'],
							'name' 		=> $arBasket['checkout']['vname'],
							'surname' 	=> $arBasket['checkout']['name'],
							'status'	=> 'C'
						);
						
						$newsletter->save_user($user);

					} 
					else 
					{

						//für Version >= 2.5.0
						$_REQUEST['na'] = 's';
						$_REQUEST['nn'] = $arBasket['checkout']['vname'];
						$_REQUEST['ns'] = $arBasket['checkout']['name'];
						$_REQUEST['ne'] = $arBasket['checkout']['email'];
						 
						$newsletter->hook_init();
						 
					}
					$this->shop->addFrontendMessage(__("Sie wurden erfolgreich in unseren Newsletter eingetragen.", "wpsg"));
				}
				else
				{
					
					$this->shop->addFrontendError(__('Sie wurden nicht zum Newsletter angemeldet, da das Plugin "newsletter" nicht installiert ist.', 'wpsg'));
					
				}
				
			}
			
		} // public function basket_save_done(&$o_id, &$k_id, &$oBasket)
				 
		public function checkout_customer_inner()
		{
			
			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_nlsatolo/checkout_customer_inner.phtml');
			
		} // public function checkout_inner_prebutton()
		
		public function clearSession() 
		{
			 
			unset($_SESSION['wpsg']['wpsg_mod_nlsatolo']);
			
		} // public function clearSession()
				
	} // class wpsg_mod_nlsatolo extends wpsg_mod_basic

?>