<?php
// error_reporting(E_ALL);
class ContactView extends Slot {

	var $ModuleID = 15;
	var $SectionID = 13;

	var $flag = -1;	
	protected $metas = array();

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

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

	function fillElements() {
		switch($this->Scheme) {
			case 'notfound': $this->fillnotFound(); break;
			default: $this->fillSelect(); break;
		}
	}
	
	function fillnotFound() {}
	
	function fillSelect() {
				if ($this->flag==1 ) { 
						$this->TempFillEls['thanks'][0] = array(); 	
				} elseif ( $this->flag==0 ) {	
						$this->TempFillEls['sorry'][0] = array(); 	
						$this->TempFillEls['subject'] = !empty($this->Request['subject'])? 	$this->Request['subject']: '';
						$this->TempFillEls['fullName'] =!empty($this->Request['fullName'])? $this->Request['fullName']: '';
						$this->TempFillEls['company'] = !empty($this->Request['company'])? 	$this->Request['company']: '';
						$this->TempFillEls['address'] = !empty($this->Request['address'])? 	$this->Request['address']: '';
						$this->TempFillEls['city'] = 	!empty($this->Request['city'])? 	$this->Request['city']: '';
						$this->TempFillEls['state'] = 	!empty($this->Request['state'])?	$this->Request['state']: '';
						$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['model'] = 	!empty($this->Request['model'])? 	$this->Request['model']: '';
						$this->TempFillEls['serial'] = 	!empty($this->Request['serial'])? 	$this->Request['serial']: '';
						$this->TempFillEls['question'] =!empty($this->Request['question'])? $this->Request['question']: '';
						$this->TempFillEls['captcha_link'] =  $this->sHome.$_SERVER['REQUEST_URI']."/captcha";
				} else {
						$this->TempFillEls['describe'][0] = array(
							'subject' 	=>	!empty($this->Request['subject'])? 	$this->Request['subject']: '',
							'fullName' 	=>	!empty($this->Request['fullName'])? $this->Request['fullName']: '',
							'company' 	=>	!empty($this->Request['company'])? 	$this->Request['company']: '',
							'address' 	=>	!empty($this->Request['address'])? 	$this->Request['address']: '',
							'city' 		=> 	!empty($this->Request['city'])? 	$this->Request['city']: '',
							'state' 	=> 	!empty($this->Request['state'])?	$this->Request['state']: '',
							'zipcode' 	=>	!empty($this->Request['zipcode'])? 	$this->Request['zipcode']: '',
							'phone' 	=> 	!empty($this->Request['phone'])? 	$this->Request['phone']: '',
							'email' 	=> 	!empty($this->Request['email'])? 	$this->Request['email']: '',
							'model' 	=> 	!empty($this->Request['model'])? 	$this->Request['model']: '',
							'serial' 	=> 	!empty($this->Request['serial'])? 	$this->Request['serial']: '',
							'question' 	=>	!empty($this->Request['question'])? $this->Request['question']: '',
							'captcha_link' => $this->sHome.$_SERVER['REQUEST_URI']."/captcha",
						);
				 } 
		$path = $this->Home."/".$this->Target[1]."/";
		$this->TempFillEls['callback_true']  = $path."1";
		$this->TempFillEls['callback_false'] = $path."2";
		if(count($this->errors) > 0) $this->errors['header'] = 'There are some errors.';
		foreach($this->errors as $k => $v) 
				$this->TempFillEls['describe'][0][$k.'_error'] = '<br><strong class=ms-formvalidation>'.$v.'</strong>' ;
	}
	
	function validateForm() {
//		if(                                 $_SESSION["vercode"] != $this->getRequestField('captchavercode')) $this->errors['captchavercode'] = 'Verification word is wrong';
		if (!isset($_SESSION["vercode"]) || empty($_SESSION["vercode"]) || strcmp($_SESSION["vercode"], $this->getRequestField('captchavercode')) !== 0)	$this->errors['captchavercode'] = 'Verification word is wrong';
			
		if(	!validate(@$this->Request['company'])) 	$this->errors['company'] = 	"The company you enterted is not valid";
		if(	!validate(@$this->Request['address']) ) $this->errors['address'] = 	"The address you enterted is not valid";
		if(	!validate(@$this->Request['city'])	) 	$this->errors['city'] = 	"The city you enterted is not valid";
		if(	!validate(@$this->Request['state'])	)	$this->errors['state'] = 	"The state you enterted is not valid";
		if(	!validate(@$this->Request['zipcode']) ) $this->errors['zipcode'] = 	"The zipcode you enterted is not valid";
		if(	!validate(@$this->Request['phone']) ) 	$this->errors['phone'] = 	"The phone you enterted is not valid";
		if(	!is_Email(@$this->Request['email']) ) 	$this->errors['email'] = 	"The email you enterted is not valid";
		if(	empty($this->Request['question'])) 		$this->errors['question'] = "The question you enterted is not valid";
			
		if(sizeof($this->errors) > 0) return FALSE;
		return TRUE;
	}
	
}
?>
