<?php

class ContentAction extends Action {

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

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

	function sendEfq($array) {
		global $REGISTRY;
		$array = $array[0];
		$this->MailBroker->sendMail('efq',array($REGISTRY['Core']['efqemail']),$array);
	}

	function sendRfq($array) {
		global $REGISTRY;
		$array = $array[0];
		$this->MailBroker->sendMail('rfq',array($REGISTRY['Core']['rfq']),$array);
	}
	
	function sendFeedback($array) {
		global $REGISTRY;
		$array = $array[0];
		$this->MailBroker->sendMail('feedback',array($REGISTRY['Core']['adminemail']),$array);
	}
	
	function sendReg($array) {
		global $REGISTRY;
		$array = $array[0];
		$this->MailBroker->sendMail('warrantyreg',array($REGISTRY['Core']['warrantyemail']),$array);
	}
	
	function sendExpadv($array) {
		global $REGISTRY;
		$array = $array[0];
		$this->MailBroker->sendMail('askexpert',array($REGISTRY['Core']['askexpert']),$array);
	}
	
	function sendRma($array) {
		global $REGISTRY;
		$array = $array[0];
		$this->MailBroker->sendMail('return',array($REGISTRY['Core']['adminemail']),$array);
	}
	
	
	function addtocart($array) { // printArray($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->files = new ObjectsList();
				$product->files->type = new ProductFile();
				$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) $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'];
		if (!empty($array[0]['rma-rmanumber']))
			$array[0]['notes'] = "RMA Number: ".$array[0]['rma-rmanumber'].".  ".$array[0]['notes'];
		if (!empty($array[0]['rma-customernumber']))
			$array[0]['notes'] = " Customer Number: ".$array[0]['rma-customernumber'].".  ".$array[0]['notes'];
		$handler->order->notes=$array[0]['notes'];
		return $handler->order;
	}

	

	
	
	
}
?>
