<?php

class ReturnView extends Slot {

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

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

	function init() {
		if(isset($this->Target[2]) && $this->Target[2] =='capture') {   makecapture();			exit;	 }
		
		if(!empty($this->Request)) {
			
			
		if ($this->validateForm()) {
			$this->Action->processEvent($this->SectionID,'open',array($this->Request),$this) and
			header('Location: '.$this->Home.'/productreturninformation/1'.$this->SID) and
			$this->flag=1;
		}			
		}
	if (isset($this->Target[2]))  $this->Target[2] ==1?	$this->flag=1:	$this->flag=0; 
	}

	function fillElements() {
				if ($this->flag==1) {
					$this->TempFillEls['thanks'][0] = array();
				}
				else {
				$this->TempFillEls['describe'][0] = array();

					$this->TempFillEls['firstName'] = !empty($this->Request['firstName'])? $this->Request['firstName']: '';
					$this->TempFillEls['lastName'] = !empty($this->Request['lastName'])? $this->Request['lastName']: '';
					$this->TempFillEls['address1'] = !empty($this->Request['address1'])? $this->Request['address1']: '';
					$this->TempFillEls['address2'] = !empty($this->Request['address2'])? $this->Request['address2']: '';
					$this->TempFillEls['city'] = !empty($this->Request['city'])? $this->Request['city']: '';
					$this->TempFillEls['zipcode'] = !empty($this->Request['zipcode'])? $this->Request['zipcode']: '';
					$this->TempFillEls['phone'] = !empty($this->Request['phone'])? $this->Request['phone']: '';
					$this->TempFillEls['email'] = !empty($this->Request['email'])? $this->Request['email']: '';
					$this->TempFillEls['unit'] = !empty($this->Request['unit'])? $this->Request['unit']: '';
					$this->TempFillEls['date'] = !empty($this->Request['date'])? $this->Request['date']: '';
					$this->TempFillEls['store'] = !empty($this->Request['store'])? $this->Request['store']: '';

				}
		$this->country = $this->Action->Server->getGuide('country',true);
		$this->state = $this->Action->Server->getGuide('state', true); 
//		$this->TempFillEls['country'] = inputSelect('country', $this->country, '250');
//		$this->TempFillEls['state'] = inputSelect('state', mergeArrays(array('0' => 'Please select'),$this->state), '0');
		$this->TempFillEls['country'] = inputSelect('country', $this->country,    !empty($this->Request['country'])? $this->Request['country']: '250' );
		$this->TempFillEls['state'] = inputSelect('state', mergeArrays(array('0' => 'Please select'),$this->state),   !empty($this->Request['state'])? $this->Request['state']: '0'    );

		$path = $this->Home."/productreturninformation/";
		$this->TempFillEls['callback_true']  = $path."1";
		$this->TempFillEls['callback_false'] = $path."2";
		
		if(count($this->errors) > 0) $this->errors['header'] = $this->globalLangContent['error_view']['header_error'];
		foreach($this->errors as $k => $v) 
				$this->TempFillEls[$k.'_error'] = '<strong class=star>'.$v.'</strong><p>' ;
		
	}

	function validateForm() {
		if($_SESSION["vercode"] != $this->getRequestField('vercode') ) $this->errors['vercode'] = 'Security code is wrong';
		if( !validate(@$this->Request['firstName']) ||
			!validate(@$this->Request['lastName']) ||
			!validate(@$this->Request['address1']) ||
			!validate(@$this->Request['city'])		||
			!validate(@$this->Request['zipcode']) ||
			!validate(@$this->Request['phone']) ||
			!is_Email(@$this->Request['email']) ||
			!validate(@$this->Request['unit']) ||
			!validate(@$this->Request['date']) ||
			!validate(@$this->Request['store'])	) return FALSE;
		if(sizeof($this->errors) > 0) return FALSE;
		return TRUE;
	}

}
?>