<?php 
 class NewsletterController extends BasicController{
 	private $companyId				= null;
 	
 /********************************************************************
 * default constructor
 *******************************************************************/ 		
	public function __construct($_postVars, $_getVars) {
		parent :: __construct($_postVars, $_getVars);	
		$this->manager 						= new NewsletterManager();
		$this->companyId					= (int)$this->configInstance->getConstant('companyid');	
		#Util::vardump($this->postVars);die;
	}
	public function btnSignOut_onClick(){
		$post = $this->cleanPost($this->postVars);
		$result = $this->manager->removeClientFromNewsletter($post['email'],$this->companyId);
		if($result == 0){
			$this->info = "Sie sind nicht in unserem Newsletter vertreten";
		}
		elseif($result == -1){
			$this->error = "Es ist ein Fehler aufgetreten";
		}else{
			$this->success = "Sie wurden erfolgreich aus dem Newsletter ausgetragen";
		}
		$this->show();
	}
	public function btnSignIn_onClick(){
		$post = $this->cleanPost($this->postVars);		
		$error = $this->manager->checkNewsletter($this->companyId,$post);
		
		if(empty($error)){
			$result = $this->manager->insertClientToNewsletter($post,$this->companyId);
			
			if((is_numeric($result) && $result > 0) || $result == null){
				$this->success = "Sie wurden erfolgreich in unseren Newsletter eingetragen";
			}else{
				$this->error = "Es ist ein Fehler aufgetreten. Wir konnten Sie leider nicht in unseren Newsletter aufnehemen";
			}
		}else{
			$this->error = $error;
		}
		$this->show();
	}
	public function show () {
		$this->smartyInstance->assign('TPL_INCLUDE', $this->templatePath.$this->template);
		$this->smartyInstance->load_filter('output','trimwhitespace');
		$this->smartyInstance->display('page_body.tpl');
	}
	public function isValid () {
		return true;
	}
	public function showPrintable () {
		$this->show();
	}
 }
?>