<?php
/**
* @version      $Id: website_new_opinion.php
* @package      Easyshop
* @copyright    Copyright (C) 2005 - 2011 TA-EDV
* @license      proprietary
* @author       Richard Kammermayer <rk@ta-edv.de>
* Easyshop is a web shop system
*/

include_once './core/shop_opinion.class.php';

class website_new_opinion {
	private $base_object;
	private $layout_object;
	
	public function __construct($base_object, $layout_object) {
		$this->base_object = $base_object;
		$this->layout_object = $layout_object;
	}
		
	function run() {
		$data = array(
			'state' => 0
		);
				
		// create opinion
		if (isset($_POST['customer_field'])) {
			$form_data = $_POST['customer_field'];
			if (
					$form_data['opinion_rang1'] &&
					$form_data['opinion_rang2'] &&
					$form_data['opinion_rang3'] &&
					$form_data['opinion_text'] &&
					$form_data['user_firstname'] &&
					$form_data['user_surename'] &&
					$form_data['user_email'] &&
					$form_data['user_address']
			) {
				$opinion_object = new Shop_opinion($this->base_object);
				$result = $opinion_object->create($form_data);
				if ($result) {
						$data['state'] = 1;
						header('Location: /Kundenbewertung_abschluss/');
				} else {
					
						$data['state'] = 3;
						$data['form_data'] = $form_data;

				}
			}
			else {
				$data['state'] = 2;
				$data['form_data'] = $form_data;
			}
		}
		
		$this->layout_object->assign('data', $data);

		return $this->layout_object->_fetch('content_new_opinion.tpl');
	}
}