<?php

//global $Debug;$Debug = true;
class SubscribeView extends Slot {

	var $ModuleID = 13;
	var $SectionID = 13;
	var $flag = -1;	

	function __construct($pquery) {
		parent::__construct($pquery);
		$this->Cache = 0;
		$this->Passing = TRUE;
	}

	function init() {  //printArray($this->Request);exit;
		if(!empty($this->Request)) {
			if ( $this->validateForm()) {
				$this->Action->processEvent($this->SectionID,'addsubscribe',array($this->Request),$this) and
				header('Location: '.$this->Home.'/welding-systems-dimetrics-power-sources-gold-track-vii/goldtrack-vii-thank-you'.$this->SID);
			}
		}
		if (isset($this->Target[2])) { 
			$this->Target[2] =='goldtrack-vii-thank-you'? $this->flag=1: $this->flag=0; 
		}
	}

	function fillElements() {
		if ($this->flag==1 ) { 
			$this->TempFillEls['thanks'][0] = array(); 	
		} elseif ($this->flag==0 ) {	
				$this->TempFillEls['name'] = !empty(	$this->Request['name'])? $this->Request['name']: '';
				$this->TempFillEls['email'] = !empty(		$this->Request['email'])? $this->Request['email']: '';
		} else {  //printArray($this->Request);exit;
				$this->TempFillEls['describe'][0] = array( 'name' => !empty(	$this->Request['name'])? $this->Request['name']: '',
														   'email' => !empty(	$this->Request['email'])? $this->Request['email']: '',
														  ); 
		} 

		$path = $this->Home."/welding-systems-dimetrics-power-sources-gold-track-vii/";
		$this->TempFillEls['callback_true']  = $path."1";
		$this->TempFillEls['callback_false'] = $path."2";

		foreach($this->errors as $k => $v) 
				$this->TempFillEls['describe'][0][$k.'_error'] = '<strong class=star>'.$v.'</strong><p>' ;
	}

	function validateForm() { //printArray($this->Request);exit;
		if (!validate(@$this->Request['name']))
		{
			$this->errors['name'] = "Name is wrong";
		}		
		if (!is_Email(@$this->Request['email'])) 
		{
			$this->errors['email'] = "Please enter valid email address";
		}
		if(count($this->errors) > 0) return FALSE;
		return TRUE;
	}
}
?>