<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
$boxHeading = BOX_HEADING_REVIEWS;
$corner_left = 'rounded';
$corner_right = 'rounded';
$boxContent_attributes = ' align="center"'; 
$boxLink = '<a class="boxLink" href="' . tep_href_link(FILENAME_REVIEWS) . '">' .tep_image(DIR_WS_TEMPLATES . 'images/infobox/arrow_right.gif') .'</a>';
$box_base_name = 'reviews'; // for easy unique box template setup (added BTSv1.2)

$box_id = $box_base_name . 'Box';  // for CSS styling paulm (editted BTSv1.2)

$random_select = "select r.reviews_id, r.reviews_rating, p.products_id, p.products_image, pd.products_name from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = r.products_id and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and r.approved = '1'";

if (isset($HTTP_GET_VARS['products_id'])) {
    $random_select .= " and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'";
}

$random_select .= " order by r.reviews_id desc limit " . MAX_RANDOM_SELECT_REVIEWS;
$random_product = tep_random_select($random_select);

$boxContent = '<div class="rev_kont">';

if ($random_product) {

$review_query = tep_db_query("select substring(reviews_text, 1, 60) as reviews_text from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$random_product['reviews_id'] . "' and languages_id = '" . (int)$languages_id . "'");

$reviews_text = tep_db_fetch_array($review_query);
$reviews_text = tep_break_string(tep_output_string_protected($reviews_text['reviews_text']), 15, '-<br>');

$szerokosc = SMALL_IMAGE_WIDTH+10;
$wysokosc = SMALL_IMAGE_HEIGHT+10;

if ($random_product['products_image'] != ''){
    $boxContent .= '<div class="rev_img">';
    $boxContent .= tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,'',$wysokosc,$szerokosc,$random_product['products_id'],tep_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $random_product['products_id'] . '&reviews_id=' . $random_product['reviews_id']),true);	
    $boxContent .= '</div>';
}

$boxContent .= '<div class="rev_text">';
$boxContent .= '<a class="boxLink" href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $random_product['products_id'] . '&reviews_id=' . $random_product['reviews_id']) . '">' . $reviews_text . ' ..</a>';
$boxContent .= '</div><div class="rev_wart">';
$boxContent .= tep_image(DIR_WS_TEMPLATES . 'images/misc/stars_' . $random_product['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_product['reviews_rating']));
$boxContent .= '</div>';

} elseif (isset($HTTP_GET_VARS['products_id'])) {

$boxContent .= '<div class="rev_on"><br><a class="boxLink" href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . $HTTP_GET_VARS['products_id']) . '">' . BOX_REVIEWS_WRITE_REVIEW .'</a</div>';

} else {

$boxContent .= BOX_REVIEWS_NO_REVIEWS;

}

$boxContent .= '</div>';

include (bts_select('boxes', $box_base_name)); // BTS 1.5

$boxLink = '';

?>