<?php

class ReturnAction extends Action {

	var $Pages = array( /* Return */
		'13' => array(
			'scheme' => 'default',
			'forward_scheme' => 'default',
		),
	);

	function __construct($name='ReturnAction') {
		parent::__construct($name);
	}

	function sendSupport($array) { 
		global $REGISTRY;
		$array = $array[0];
		$formtype = $array['formtype'];
		$requesttype = $array['type'];
		$array['formtype'] = ($formtype=="turbinesupport") ? "Turbine Repair Support ":"Welding Systems Support ";
		$array['type'] = ($requesttype == "1") ? "Service/Support":"Sales";
		if ( $formtype == "turbinesupport"){
			if ( $requesttype =="1") 
				$this->MailBroker->sendMail('support', array($REGISTRY['Core']['turbinesupport']), $array);
					else $this->MailBroker->sendMail('support', array($REGISTRY['Core']['turbinesupportsales']), $array);
		} else {	//weldingsupport
			if ( $requesttype =="1") 
				$this->MailBroker->sendMail('support', array($REGISTRY['Core']['weldingsupport']), $array);
					else $this->MailBroker->sendMail('support', array($REGISTRY['Core']['weldingsupportsales']), $array);
		}
	}

	function addtocart($array) { 
		global $Server;
		$handler = $Server->getHandler(10);	
		!empty($array) or $array = array();
		foreach($array as $key => $value) {
			$found = 0;
			foreach($handler->cart->cartlineitems->data as $index => $li) {
				if($value['id']==$li->product->id) {
					$found = 1;
					if($handler->cart->cartlineitems->data[$index]->qty < 999)
							$handler->cart->cartlineitems->data[$index]->qty++;
				}
			}
			if(!$found) {
				$handler->cart->continue = getenv('HTTP_REFERER');
				$product = new Product();
				$product->prices = new ObjectsList();
				$product->prices->type = new Price();
				$product->shipcosts = new ObjectsList();
				$product->shipcosts->type = new ShipCost();
				$product->id = (int)$value['id'];
				$handler->DB->initObject($product);
				$product->prices->data[0]->value=$value['amount'];
				if($product->is_active) {
					$sale = 0;
					$real_price = 0;
					foreach($product->prices->data as $idx => $price) {
						if(empty($price->value) || !is_numeric($price->value) || (double)$price->value < 0.01 || $price->current==0) $sale = 0;
						else {
							$real_price = $price->value;
							$sale = 1;
							break;
						}
					}
					if($sale) {
						$LI = clone $handler->cart->cartlineitems->type;
						$LI->product = clone $product;
						$LI->qty = 1;
						$LI->price = $real_price;
						$handler->cart->cartlineitems->data[] = clone $LI;
					}
				}
			}
		}

		if(!empty($array)) {
			$handler->cart->total = 0;
			foreach($handler->cart->cartlineitems->data as $index => $li) {
				$handler->cart->total += $li->price*$li->qty;
			}
		}
//--------SetOrder
		$handler->order->_error = '';
		$handler->order = $handler->createOrder();
		$handler->order->customer->first_name=$array[0]['firstName'];
		$handler->order->customer->last_name=$array[0]['lastName'];		
		$handler->order->customer->phone=$array[0]['phone'];
		$handler->order->customer->email=$array[0]['email'];
		$handler->order->notes=$array[0]['notes'];
		return $handler->order;
	}


	
}
?>