<?php 
class ControllerReviewInfo extends Controller { 
	function index() {
		$config   =& $this->locator->get('config');
		$currency =& $this->locator->get('currency');
		$database =& $this->locator->get('database');
		$language =& $this->locator->get('language');
		$image    =& $this->locator->get('image');
		$module   =& $this->locator->get('module');
		$request  =& $this->locator->get('request');
		$response =& $this->locator->get('response');
		$tax      =& $this->locator->get('tax');
		$template =& $this->locator->get('template');
		$url      =& $this->locator->get('url');
				  
    	$language->load('controller/review_info.php');
 		
		$review_info = $database->getRow("select r.review_id, r.author, r.rating, r.text, p.product_id, pd.name, p.price, p.tax_class_id, i.filename, r.date_added from review r left join product p on(r.product_id = p.product_id) left join product_description pd on(p.product_id = pd.product_id) left join image i on(p.image_id = i.image_id) where r.review_id = '" . (int)$request->get('review_id') . "' and p.status = '1' and pd.language_id = '" . (int)$language->getId() . "' order by r.date_added desc");
    	
		if ($review_info) {
	  		$template->set('title', $language->get('heading_title', $review_info['name'], $review_info['author']));
 
      		$view = $this->locator->create('template');

      		$view->set('heading_title', $language->get('heading_title', $review_info['name'], $review_info['author']));

      		$view->set('text_enlarge', $language->get('text_enlarge'));
      		$view->set('text_author', $language->get('text_author'));
      		$view->set('text_date_added', $language->get('text_date_added'));
      		$view->set('text_rating', $language->get('text_rating'));
      		$view->set('text_out_of', $language->get('text_out_of', $review_info['rating']));

      		$view->set('button_reviews', $language->get('button_reviews'));
      		$view->set('button_write', $language->get('button_write'));

      		$view->set('name', $review_info['name']);

      		$view->set('price', $currency->format($tax->calculate($review_info['price'], $review_info['tax_class_id'], $config->get('config_tax'))));
			
			$view->set('popup', $image->href($review_info['filename']));
      		$view->set('thumb', $image->resize($review_info['filename'], $config->get('config_image_width'), $config->get('config_image_height')));
      		
      		$view->set('author', $review_info['author']);

      		$view->set('text', nl2br($review_info['text']));

      		$view->set('rating', $review_info['rating']);

      		$view->set('date_added', date($language->get('date_format_long'), strtotime($review_info['date_added'])));
      
	  		$query = array(
	    		'product_id' => $review_info['product_id'],
				'review_id'  => $request->get('review_id')
	  		);
	  
      		$view->set('review', $url->href('review', FALSE, $query));

      		$query = array(
        		'product_id' => $review_info['product_id'],
        		'review_id'  => $request->get('review_id')
      		); 

      		$view->set('write', $url->href('review_write', FALSE, $query));
	  
	  		$template->set('content', $view->fetch('content/review_info.tpl'));
	  
	  		$template->set($module->fetch());
	
      		$response->set($template->fetch('layout.tpl'));	  
    	} else {
      		$template->set('title', $language->get('text_error'));

      		$view = $this->locator->create('template');

      		$view->set('heading_title', $language->get('text_error'));

      		$view->set('text_error', $language->get('text_error'));

      		$view->set('button_continue', $language->get('button_continue'));

      		$view->set('continue', $url->href('home'));
	  
	  		$template->set('content', $view->fetch('content/error.tpl'));
	  
	  		$template->set($module->fetch());
	
      		$response->set($template->fetch('layout.tpl'));   	  
    	}
  	}
}
?>
