<?php

class GovRequestView 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);
		if(isset($this->Target[2]) && $this->Target[2] =='capture') {   makecapture();			exit;	 }
		if(!empty($this->Request)) {
			if ($this->validateForm()) {
				$this->Action->processEvent($this->SectionID,'sendgovrequest',array($this->Request),$this);
				header('Location: '.$this->Home.'/rfq/1'.$this->SID);
				$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();
					$this->TempFillEls['date'] = inputText('date', '' , 19, '" style="width: 130px;" readonly', 19);
				}
				else {
					$this->TempFillEls['describe'][0] = array();
					$this->TempFillEls['date'] = !empty(		$this->Request['date'])?   inputText('date', $this->Request['date'] , 19, '" style="width: 130px;" readonly', 19):  inputText('date', '' , 19, '" style="width: 130px;" readonly', 19) ;
					$this->TempFillEls['agencytype'] = !empty($this->Request['agencytype'])? $this->Request['agencytype']: '';
					$this->TempFillEls['govagency'] = !empty($this->Request['govagency'])? $this->Request['govagency']: '';					
					$this->TempFillEls['firstName'] = !empty($this->Request['firstName'])? $this->Request['firstName']: '';
					$this->TempFillEls['lastName'] = !empty($this->Request['lastName'])? $this->Request['lastName']: '';
					$this->TempFillEls['title'] = !empty($this->Request['title'])? $this->Request['title']: '';
					$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['fax'] = !empty($this->Request['fax'])? $this->Request['fax']: '';
					$this->TempFillEls['email'] = !empty($this->Request['email'])? $this->Request['email']: '';
					$this->TempFillEls['budget'] = !empty($this->Request['budget'])? $this->Request['budget']: '';
					$this->TempFillEls['sworn'] = !empty($this->Request['sworn'])? $this->Request['sworn']: '';
					$this->TempFillEls['grantName'] = !empty($this->Request['grantName'])? $this->Request['grantName']: '';
					$this->TempFillEls['listunits'] = !empty($this->Request['listunits'])? $this->Request['listunits']: '';
					$this->TempFillEls['howhear'] = !empty($this->Request['howhear'])? $this->Request['howhear']: '';
					$this->TempFillEls['comments'] = !empty($this->Request['comments'])? $this->Request['comments']: '';
				}
		$this->state = $this->Action->Server->getGuide('state', true); 
		$this->TempFillEls['state'] = inputSelect('state', mergeArrays(array('0' => 'Please select'),$this->state),   !empty($this->Request['state'])? $this->Request['state']: '0'    );
		$this->TempFillEls['request'] =  inputSelect('request', array('1' => 'Samples', '0' => 'Price Quote', '2' => 'Grant help'),   !empty($this->Request['request'])? $this->Request['request']: '0'   );
		$this->TempFillEls['question1'] =  inputSelect('question1', array('0' => '', '1' => 'yes', '2' => 'no'),   !empty($this->Request['question1'])? $this->Request['question1']: '0'   );
		$this->TempFillEls['question2'] =  inputSelect('question2', array('0' => '', '1' => 'yes', '2' => 'no'),   !empty($this->Request['question2'])? $this->Request['question2']: '0'   );
		$this->TempFillEls['available'] =  inputSelect('available', array('0' => '', '1' => 'yes', '2' => 'no'),   !empty($this->Request['available'])? $this->Request['available']: '0'   );

		$this->TempFillEls['granttype'] =  inputSelect('granttype', array('0' => '', '1' => 'Local', '2' => 'State', '3' => 'Federal'),   !empty($this->Request['granttype'])? $this->Request['granttype']: '0'   );
		
		
		
		$path = $this->Home."/rfq/";
		$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['date'])      ||
			!validate(@$this->Request['agencytype'])||
			!validate(@$this->Request['govagency']) ||
			!validate(@$this->Request['firstName']) ||
			!validate(@$this->Request['lastName'])  ||
			!validate(@$this->Request['title'])     ||
			!validate(@$this->Request['address1'])  ||
			!validate(@$this->Request['city'])		||
			!validate(@$this->Request['zipcode'])   ||
			!validate(@$this->Request['phone'])     ||
			!validate(@$this->Request['date'])      ||
			!is_Email(@$this->Request['email'])     ||
			!validate(@$this->Request['howhear']) ) return FALSE;
		if(sizeof($this->errors) > 0) return FALSE;
		return TRUE;
	}
	
}
?>