<?php

class ServiceShippingView 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);  printArray($this->Target); exit;
		if(isset($this->Target[2]) && $this->Target[2] =='capture') {   makecapture();			exit;	 }
		if ((!empty($this->Request)) && $this->validateForm() ) {
			if(!empty($this->Request) && isset($this->Target[2]) && ($this->Target[2]==1)) {		// Button Google Checkout or Paypal Pressed
					$this->Action->processEvent($this->SectionID,'open5',array($this->Request),$this);
			exit;
			}
			if(!empty($this->Request) && isset($this->Target[2]) && $this->Target[2]==2) {		// Button "Add to Cart" Pressed 
					$this->Action->processEvent($this->SectionID,'open5',array($this->Request),$this) and
					$this->Action->processEvent($this->SectionID,'add',array($this->Request),$this)	and 
					header("Location: ".$this->Home.'/ShoppingCart'.$this->SID);
			}
		}
		$this->Action->processEvent($this->SectionID,'open_product',array(),$this);
	}

	function fillElements() {
		if ($this->flag==1) {
			$this->TempFillEls['thanks'][0] = array();
		}
		else {
			$this->TempFillEls['describe'][0] = array();
			$this->TempFillEls['id'] = $this->PreparedTemplates['id'];
			$this->TempFillEls['firstName'] = !empty($this->Request['firstName'])? $this->Request['firstName']: '';
			$this->TempFillEls['lastName'] = !empty($this->Request['lastName'])? $this->Request['lastName']: '';
			$this->TempFillEls['rma'] = !empty($this->Request['rma'])? $this->Request['rma']: '';
			$this->TempFillEls['custnum'] = !empty($this->Request['custnum'])? $this->Request['custnum']: '';
			$this->TempFillEls['amount'] = !empty($this->Request['amount'])? $this->Request['amount']: '';
			$this->TempFillEls['phone'] = !empty($this->Request['phone'])? $this->Request['phone']: '';
			$this->TempFillEls['email'] = !empty($this->Request['email'])? $this->Request['email']: '';
			$this->TempFillEls['notes'] =  !empty($this->Request['notes'])? $this->Request['notes']: '';
			$this->TempFillEls['name'] = $this->PreparedTemplates['name'];
			$this->TempFillEls['return_url'] = $this->Home.'/rma';
			
		}
		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['rma']) ||
			!validate(@$this->Request['amount']) ||
			!validate(@$this->Request['phone']) ||
			!is_Email(@$this->Request['email']) ) return FALSE;
		if(sizeof($this->errors) > 0) return FALSE;
		return TRUE;
	}

}
?>