<?php 
class ControllerAccountNewsletter extends Controller {  
	function index() {
		$customer =& $this->locator->get('customer');
		$database =& $this->locator->get('database');
		$language =& $this->locator->get('language');
		$module   =& $this->locator->get('module');
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$session  =& $this->locator->get('session');
		$template =& $this->locator->get('template');
		$url      =& $this->locator->get('url');
					
		if (!$customer->isLogged()) {
	  		$session->set('redirect', $url->ssl('account_newsletter'));
	  
	  		$response->redirect($url->ssl('account_login'));
    	} 
		
		$language->load('controller/account_newsletter.php');
    
		$template->set('title', $language->get('heading_title'));
				
		if ($request->isPost()) {
			$database->query("update customer set newsletter = '" . (int)$request->get('newsletter', 'post') . "' where customer_id = '" . (int)$customer->getId() . "'");
			
			$session->set('message', $language->get('text_message'));
			
			$response->redirect($url->href('account_newsletter'));
		}
		
    	$view = $this->locator->create('template');

    	$view->set('heading_title', $language->get('heading_title'));

    	$view->set('text_yes', $language->get('text_yes'));
		$view->set('text_no', $language->get('text_no'));
		$view->set('text_newsletter', $language->get('text_newsletter'));
		
		$view->set('entry_newsletter', $language->get('entry_newsletter'));
		
		$view->set('button_continue', $language->get('button_continue'));
		$view->set('button_back', $language->get('button_back'));

    	$view->set('action', $url->ssl('account_newsletter'));
		
		$view->set('newsletter', $customer->getNewsLetter());
		
		$view->set('back', $url->ssl('account'));
		
		$template->set('content', $view->fetch('content/account_newsletter.tpl'));
	
			$template->set($module->fetchAccount());	
    	$response->set($template->fetch('layout.tpl')); 
  	}
}
?>