<?php
class ControllerModuleSlideprod extends Controller {
	protected function index($setting) {
		$this->language->load('module/slideprod'); 
		
		$this->document->addScript('catalog/view/javascript/jquery/slideprod/jquery.jshowoff.min.js');
		if ($this->config->get('slideprod_theme') == 'light') {
		$this->document->addStyle('catalog/view/javascript/jquery/slideprod/jshowoff.css');
		} else {
		$this->document->addStyle('catalog/view/javascript/jquery/slideprod/jshowoff-dark.css');
		}

      	$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['button_cart'] = $this->language->get('button_cart');
		
		$this->load->model('catalog/product'); 
		
		$this->load->model('tool/image');

		$this->data['products'] = array();

		$products = explode(',', $this->config->get('slideprod_product'));	
		
		$this->data['theme']		 = $this->config->get('slideprod_theme');
		$this->data['effect']		 = $this->config->get('slideprod_effect');
		$this->data['hoverpause']	 = $this->config->get('slideprod_hoverpause');
        $this->data['speed'] 		 = $this->config->get('slideprod_speed');
		$this->data['changespeed'] 	 = $this->config->get('slideprod_changespeed');
        $this->data['controls']		 = $this->config->get('slideprod_controls');	
		$this->data['links']		 = $this->config->get('slideprod_links');

		foreach ($products as $product_id) {
			$product_info = $this->model_catalog_product->getProduct($product_id);
			
			if ($product_info) {
				if ($product_info['image']) {
					$image = $this->model_tool_image->resize($product_info['image'], $setting['image_width'], $setting['image_height']);
				} else {
					$image = false;
				}

				if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
					$price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
				} else {
					$price = false;
				}
						
				if ((float)$product_info['special']) {
					$special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
				} else {
					$special = false;
				}
				
				if ($this->config->get('config_review_status')) {
					$rating = $product_info['rating'];
				} else {
					$rating = false;
				}
					
				$this->data['products'][] = array(
					'product_id' => $product_info['product_id'],
					'thumb'   	 => $image,
					'name'    	 => $product_info['name'],
					'description' => mb_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, 280) . '..',
					'price'   	 => $price,
					'special' 	 => $special,
					'rating'     => $rating,
					'reviews'    => sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']),
					'href'    	 => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
				);
			}
		}

		if ($setting['position'] == 'content_top' or $setting['position'] == 'content_bottom') {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/slideprod.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/slideprod.tpl';
			} else {
				$this->template = 'default/template/module/slideprod.tpl';
			}
		} else {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/slideprod_side.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/slideprod_side.tpl';
			} else {
				$this->template = 'default/template/module/slideprod_side.tpl';
			}
		}

		$this->render();
	}
}
?>