<?php

class RequestCatView 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);
//		global $ROOT_PATH;
		if(isset($this->Target[2]) && $this->Target[2] =='capture') {   makecapture();			exit;	 }
//		$this->Action->processEvent($this->SectionID,'open_describe',array('id' => $this->ModuleID),$this);
	//	if(empty($this->PreparedTemplates['_error'])) $this->describe = $this->PreparedTemplates;
//		$this->PreparedTemplates = array();
//		$ref = getenv('HTTP_REFERER');
		if(!empty($this->Request)) {
/*			include_once($ROOT_PATH.'/CURL/class.curl.php');
			$fields = array();
			foreach($this->Request as $key => $value) $fields[] = $key.'='.$value;
			$post = implode('&',$fields);
			$c = new curl("http://oaweb7.atn-night-vision.com/addwaruser.php3");
			$c->setopt(CURLOPT_FOLLOWLOCATION, 0);
			$c->setopt(CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; msie6xpv1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)");
			$c->setopt(CURLOPT_POST, 1);
			$c->setopt(CURLOPT_POSTFIELDS, $post);
			$c->setopt(CURLOPT_VERBOSE, 0);
			$c->setopt(CURLOPT_HEADER, 1);
			$c->setopt(CURLOPT_RETURNTRANSFER, true);
			$result = $c->exec();
			if(!empty($c->m_header['Location'][0])) {
				switch($c->m_header['Location'][0]) {
					case $this->Home.'/onlinewarrantyregistration/1':
						$this->Action->processEvent($this->SectionID,'open2',array($this->Request),$this);
						header('Location: '.$this->Home.'/onlinewarrantyregistration/1'.$this->SID);
						$this->TempFillEls['text'] = 'You are successfully registered in our warranty database!<br>Thank you for being our client!';
						$this->flag=1;
					break;
					case $this->Home.'/onlinewarrantyregistration/2':
						header('Location: '.$this->Home.'/onlinewarrantyregistration/2'.$this->SID);
						$this->TempFillEls['text'] = 'Sorry, our database is on a heavy load now.<br>Please try again in a minute.';
						$this->flag=0;
					break;
					default: header('Location: '.$this->Home.'/onlinewarrantyregistration'.$this->SID); break;
				}
 			}
			$c->close();
*/
			if ($this->validateForm()) {
				$this->Action->processEvent($this->SectionID,'open3',array($this->Request),$this);
				header('Location: '.$this->Home.'/requestcatalog/1'.$this->SID);
				$this->flag=1;
			}
		}
	if (isset($this->Target[2]))  $this->Target[2] ==1?	$this->flag=1:	$this->flag=0; 
	}

	function fillElements() {
/*			$this->TempFillEls['describe'] = array();
			$this->TempFillEls['describe'][0]['title'][0]['sys_name'] = strtoupper($this->describe['sys_name']);
			$this->TempFillEls['describe'][0]['title'][0]['color'] = $this->describe['color']['name'];
			$this->TempFillEls['describe'][0]['color'] = $this->describe['color']['name'];
*///			foreach($this->describe['contents'] as $key => $value) {
				if ($this->flag==1) {
					$this->TempFillEls['thanks'][0] = array();
/*					$this->TempFillEls['describe'][0]['descr'][$key] = array(
					'color' => $this->describe['color']['name'],
					'top_name' => !empty($value['name'])? array(array('color' => $this->describe['color']['name'],'header' => strtoupper($value['name']))) : array(),
					'top_noname' => !empty($value['name'])? array() : array(array('color' => $this->describe['color']['name'])),
					'text' => 'You are successfully registered in our warranty database!<br>Thank you for being our client!',
					);
*/				
				}
				else {
				$this->TempFillEls['describe'][0] = array();

					$this->TempFillEls['snail'] = !empty($this->Request['snail'])? $this->Request['snail']: '';
					$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->country = $this->Action->Server->getGuide('country',true);
		$this->state = $this->Action->Server->getGuide('state', true); 
		$this->choice = $this->Action->Server->getGuide('choice', true); 
		$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'    );
		$this->TempFillEls['choice'] = inputSelect('choice', mergeArrays(array('0' => 'Please select'),$this->choice),   !empty($this->Request['choice'])? $this->Request['choice']: '0'    );
		
		$path = $this->Home."/requestcatalog/";
		$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']) ||
			$this->getRequestField('choice') ==0 ) return FALSE;
		if(sizeof($this->errors) > 0) return FALSE;
		return TRUE;
	}
	
}
?>