<?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();
?>
<!-- best_sellers //-->
<?php
	$template_html='<tr>
						<td width="{{INITIAL_WIDTH}}"></td><td class="{{CLASS}}" valign="top">{{SPACER}}{{ICON}}</td><td class="{{CLASS}}" valign="top"><a href={{LINK_1}}> {{NAME}}</a></td>
					</tr>
					<tr>
						<td height="5"></td>
					</tr>
					';
  if ($cPath) {
    $best_sellers_query = tep_db_query("select distinct p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and (c.categories_id = '" . $current_category_id . "' OR c.parent_id = '" . $current_category_id . "') order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
  } else {
    $best_sellers_query = tep_db_query("select p.products_id, pd.products_name, p.products_ordered from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' order by p.products_ordered DESC, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
  }

  if (tep_db_num_rows($best_sellers_query) >= MIN_DISPLAY_BESTSELLERS) {
	$replace_array=array();
	$replace_array["INITIAL_WIDTH"]=$INITIAL_WIDTH;
	$replace_array["CLASS"]="infoBoxNavigation";
	$replace_array["SPACER"]=tep_draw_separator('pixel_trans.gif',10,1);
	
	$replace_html=$template_html;
	
	reset($replace_array);
	while(list($key,)=each($replace_array)){
		$replace_html=str_replace("{{" . $key . "}}",$replace_array[$key],$replace_html);
	}
?>
<tr>
	<td>
<?php
	if(!defined('BOX_HEADING_BESTSELLERS'))define('BOX_HEADING_BESTSELLERS', 'Best Sellers');
	$info_box_contents = array();
	$info_box_contents[] = array('text'  => BOX_HEADING_BESTSELLERS );
	new infoBoxHeading($info_box_contents, true, true);
	
	$best_seller_string = '';
    $rows = 0;
    $info_box_contents = array();
    while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
		$rows++;
		$replace_string=$replace_html;
		$replace_string=str_replace("{{LINK_1}}",tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id'], 'NONSSL'),$replace_string);
		$replace_string=str_replace("{{NAME}}",$best_sellers['products_name'],$replace_string);
		$replace_string=str_replace("{{ICON}}",tep_row_number_format($rows) .'.&nbsp;',$replace_string);
		$best_seller_string.=$replace_string;;
    }
	
	$info_box_contents = array();
	$info_box_contents[] = array('align' => 'center',
							  'text'  => '<table border="0" cellpadding="0" cellspacing="0" width="100%">' . $best_seller_string . '</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>
<?php
}
?>
<!-- best_sellers_eof //-->

