<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  if (isset($HTTP_GET_VARS['reviews_id']) && tep_not_null($HTTP_GET_VARS['reviews_id']) && isset($HTTP_GET_VARS['products_id']) && tep_not_null($HTTP_GET_VARS['products_id'])) {
    $review_check_query = tep_db_query("select count(*) as total from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.reviews_id = '" . (int)$HTTP_GET_VARS['reviews_id'] . "' and r.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' and r.reviews_status = 1");
    $review_check = tep_db_fetch_array($review_check_query);
		
		$image_width = REVIEWS_PAGE_IMAGE_WIDTH;
		$image_height = REVIEWS_PAGE_IMAGE_HEIGHT;

    if ($review_check['total'] < 1) {
      tep_redirect(tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params(array('reviews_id'))));
    }
  } else {
    tep_redirect(tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params(array('reviews_id'))));
  }

  tep_db_query("update " . TABLE_REVIEWS . " set reviews_read = reviews_read+1 where reviews_id = '" . (int)$HTTP_GET_VARS['reviews_id'] . "'");

  $review_query = tep_db_query("select rd.reviews_text, r.reviews_rating, r.reviews_id, r.customers_name, r.date_added, r.reviews_read, p.products_id, p.products_price, p.products_tax_class_id, p.products_image, p.products_model, pd.products_name from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where r.reviews_id = '" . (int)$HTTP_GET_VARS['reviews_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' and r.products_id = p.products_id and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '". (int)$languages_id . "'");
  $review = tep_db_fetch_array($review_query);

  if ($new_price = tep_get_products_special_price($review['products_id'])) {
    $products_price = '<del>' . $currencies->display_price($review['products_price'], tep_get_tax_rate($review['products_tax_class_id'])) . '</del> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($review['products_tax_class_id'])) . '</span>';
		$sale	= '<div class="sale"></div>';
  } else {
    $products_price = '<span class="productSpecialPrice">' . $currencies->display_price($review['products_price'], tep_get_tax_rate($review['products_tax_class_id'])) . '</span>';
		$sale	= '';
  }

  if (tep_not_null($review['products_model'])) {
    $products_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $review['products_id']) . '">'.$review['products_name'] . '</a> <mark class="smallText products_model">[' . $review['products_model'] . ']</mark>';
  } else {
    $products_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $review['products_id']) . '">'.$review['products_name'].'</a>';
  }

  	if (tep_not_null($review['products_image'])) {
		$p_pic =  ((REVIEWS_PAGE_SHOW_THUMBS == 'Show') ? '<div class="product_pic_wrapper" style="width:'.$image_width.'px;height:'.$image_height.'px;"><a class="product_img" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $review['products_id']) . '" style="width:'.$image_width.'px;height:'.$image_height.'px;">' .tep_image(DIR_WS_IMAGES . $review['products_image'], addslashes($review['products_name']), $reviews['products_name'], $image_width, $image_height, ' style="width:'.$image_width.'px;height:'.$image_height.'px;"') . '</a>'.$sale.'</div>' : '');
		}

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_REVIEWS_INFO);
  $current_page = FILENAME_REVIEWS;
  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()));

  require(DIR_WS_INCLUDES . 'template_top.php');
?>

<?php echo tep_draw_content_top();?>


<div class="contentContainer page_reviews_info">
  <div class="contentBlock">
      <ol id="product_info">
          			<li class="col_10"><?php echo $p_pic;?></li>  
								<?php if (($oscTemplate->hasBlocks('box_info_page')))	{ ?>
                <li class="col_12"><div class="bookmarks" style="width:<?php echo PROD_INFO_IMAGE_WIDTH;?>px;"><?php echo $oscTemplate->getBlocks('box_info_page');?></div></li>          		
								<?php	} ?>
                
                            
          			<li class="col_11">
                    <div class="info">
                      <h3 class="name"><?php echo $products_name; ?></h3>
                      <div class="price"><?php echo '<b>' .PRICE. '</b>' . $products_price; ?></div>
              
                      <div class="buttonSet"><?php echo tep_draw_button1_top();?><?php echo tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now')); ?><?php echo tep_draw_button1_bottom();?></div>
                      
                   </div>   
              	</li>
		</ol>
    <div class="clear"></div>
    <div class="grid__">
        <div class="contentInfoText prods_info extra">
            <div class="prods_info_mad">
              <div class="data data_add">
                  <div><b><?php echo sprintf(TEXT_REVIEW_BY, tep_output_string_protected($review['customers_name'])); ?></b>
                  <?php echo sprintf(TEXT_REVIEW_DATE_ADDED, tep_date_long($review['date_added'])); ?></div>
              </div>
              <div class="desc desc_padd"><?php echo tep_break_string(nl2br(tep_output_string_protected($review['reviews_text'])), 60, '-<br />');?></div>
              <div class="stars stars_padd"><?php echo sprintf(TEXT_REVIEW_RATING, tep_image(DIR_WS_IMAGES . 'icons/stars_' . $review['reviews_rating'] . '.png', sprintf(TEXT_OF_5_STARS, $review['reviews_rating'])).'<span>', sprintf(TEXT_OF_5_STARS, $review['reviews_rating'])) . '</span>'; ?></div>
  
        
           </div>     
        </div> 
                        <div class="buttonSet">
                            <span class="button_left"><?php echo tep_draw_button2_top();?><?php echo tep_draw_button(IMAGE_BUTTON_BACK, 'triangle-1-w', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params(array('reviews_id')))); ?><?php echo tep_draw_button2_bottom();?></span>
                
                            <span class="button_right"><?php echo tep_draw_button1_top();?><?php echo tep_draw_button(IMAGE_BUTTON_WRITE_REVIEW, 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, tep_get_all_get_params(array('reviews_id'))), 'primary'); ?><?php echo tep_draw_button1_bottom();?></span>
                        </div>
         
  </div>
	</div>
</div>

<?php echo tep_draw_content_bottom();?>

<?php
  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
