<?php
/*
 osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare 

Released under the GNU General Public License
*/
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
<!-- reviews //-->
<tr>
	<td>
<?php
	if(!defined('BOX_HEADING_REVIEWS'))define('BOX_HEADING_REVIEWS', 'Reviews');
	$info_box_contents = array();
	$info_box_contents[] = array('text'  => BOX_HEADING_REVIEWS );
	// new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_REVIEWS, '', 'NONSSL'));
	new infoBoxHeading($info_box_contents, true, true); 
	
	$customer_exists = '';
	if(tep_session_is_registered('customer_id'))
	$customer_exists = "OR(p.restrict_to_customers like '%," . $customer_id . ",%' OR p.restrict_to_groups like '%," . $customers_groups_id . ",%')";
	$random_select = "select r.reviews_id, r.reviews_rating, substring(rd.reviews_text, 1, 100) as reviews_text, p.products_id, p.products_image_1,p.products_title_1 from " . TABLE_REVIEWS . " r left join " . TABLE_PRODUCTS . " p on r.products_id = p.products_id, " . TABLE_REVIEWS_DESCRIPTION . " rd where p.products_status = '1' and rd.reviews_id = r.reviews_id and r.admin_review='N' and languages_id = '" . $languages_id . "'" . 
				" and (" . 
						"(p.restrict_to_customers = '' OR ISNULL(p.restrict_to_customers))" . 
						"and(p.restrict_to_groups = '' OR ISNULL(p.restrict_to_groups))" . $customer_exists . ")";
	if ($HTTP_GET_VARS['products_id']) {
		$random_select .= " and p.products_id = '" . tep_db_input(tep_db_prepare_input($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);
	
	if ($random_product) {
		// display random review box
		$random_product['products_name'] = tep_get_products_name($random_product['products_id']);
		//$review = htmlspecialchars($random_product['reviews_text']);
		//$review = tep_break_string($review, 15, '-<br>');
		$review = $random_product['reviews_text'];
		
		$info_box_contents = array();
		$info_box_contents[] = array('align' => 'center',
									 'text'  => '<table border="0" cellspacing="2" cellpadding="5"><tr><td class="infoBoxNavigationContent" ><div align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $random_product['products_id'] . '&amp;reviews_id=' . $random_product['reviews_id'], 'NONSSL') . '">' . tep_product_small_image($random_product['products_image_1'], $random_product['products_title_1']) . '</a></div><a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $random_product['products_id'] . '&amp;reviews_id=' . $random_product['reviews_id'], 'NONSSL') . '">' . strip_tags($review)  .  ' ..</a><br><div align="center">' . tep_image(DIR_WS_IMAGES . 'stars_' . $random_product['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_product['reviews_rating'])) . '</div></td></tr></table>');
		new infoBox($info_box_contents);
	} elseif ($HTTP_GET_VARS['products_id']) {
		// display 'write a review' box
		$info_box_contents = array();
		$info_box_contents[] = array('align' => 'center',
									 'text'  => '<table border="0" cellspacing="2" cellpadding="5"><tr><td class="infoBoxNavigationContent"><a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . tep_db_prepare_input($HTTP_GET_VARS['products_id']), 'NONSSL') . '">' . BOX_REVIEWS_WRITE_REVIEW  .'</a></td></tr><tr><td  align="center" class="infoBoxNavigationContent"><a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'products_id=' . tep_db_prepare_input($HTTP_GET_VARS['products_id']), 'NONSSL') . '">' . tep_template_image_button( 'button_write_review.gif', IMAGE_BUTTON_WRITE_REVIEW) . '</a></td></tr></table>');
		new infoBox($info_box_contents);
	} else {
		// display 'no reviews' box
		$info_box_contents = array();
		$info_box_contents[] = array('align' => 'center',
									 'text'  => '<table border="0" cellspacing="2" cellpadding="5"><tr><td class="infoBoxNavigationContent">' . BOX_REVIEWS_NO_REVIEWS . '</td></tr></table>');
		new infoBox($info_box_contents);
	}
	$info_box_contents = array();
	$info_box_contents[] = array('align' => 'left',
	'text'  => tep_draw_separator('pixel_trans.gif', '100%', '1')
							  );
	new infoboxFooter($info_box_contents, true, true); 
?>
	</td>
</tr>	  
<!-- reviews_eof //-->
