<?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();


?>
	  <tr>
		<td width="25%" align="left">
		<table border="0" width="100%" cellspacing="0" cellpadding="2">
		<tr>
			<td class="headerNavigation1" colspan="3" height="34">
			<table cellpadding="0" cellspacing="5" border="0" width="100%">
				<tr ><td  class="infoBoxNavigationContent" valign="middle"><?php echo '<b>'.TABLE_HEADING_FEATURED_PRODUCTS.'</b>';?></td>
				</tr>
			</table>
			</td>	
		</tr>
		<?php
			if (!isset($array)){	
				  $featured_query = "select p.products_id, pd.products_name, pd.products_description, p.products_image_1,p.products_title_1,p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id left join " . TABLE_FEATURED . " f on p.products_id = f.products_id and pd.language_id = '" . $languages_id . "' where p.products_status = '1' and f.status = '1' order by rand($mtm) limit 4";
				  $featured_result_query = tep_db_query($featured_query);
				  while ($featured_result = tep_db_fetch_array($featured_result_query)) {
					$array[] = array('id' => $featured_result['products_id'],
												  'name' => $featured_result['products_name'],
												  'image' => $featured_result['products_image_1'],
												  'title'=>$featured_result['products_title_1'],
												  'price' => $featured_result['products_price'],
												  'specials_price' => $featured_result['specials_new_products_price'],
												  'tax_class_id' => $featured_result['products_tax_class_id'],
												  'products_description' => $featured_result['products_description'],
												  'date_added' => tep_date_long($featured_result['products_date_added']),
												  'manufacturer' => $featured_result['manufacturers_name']);
				  }
			}
		
		  if (sizeof($array) == '0') {
		?>
		  <tr>
			<td class="main"><?php echo TEXT_NO_FEATURED_PRODUCTS; ?></td>
		  </tr>
		  <?php
 /* } else {
    for($i=0; $i<sizeof($featured_products_array); $i++) {
      if ($featured_products_array[$i]['specials_price']) {
        $products_price = '<s>' .  $currencies->display_price($featured_products_array[$i]['price'], tep_get_tax_rate($featured_products_array[$i]['tax_class_id']),1,true) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($featured_products_array[$i]['specials_price'], tep_get_tax_rate($featured_products_array[$i]['tax_class_id'])) . '</span>';
      } else {
        $products_price = $currencies->display_price($featured_products_array[$i]['price'], tep_get_tax_rate($featured_products_array[$i]['tax_class_id']),1,true);
      }*/
?>
		<?php
		  } else {
			for($z=0; $z<sizeof($array); $z++) {
			  if ($array[$z]['specials_price']) {
				$products_price = '<s>' .  $currencies->display_price($array[$z]['price'], tep_get_tax_rate($array[$z]['tax_class_id']),1,true) . '</s>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($array[$z]['specials_price'], tep_get_tax_rate($array[$z]['tax_class_id'])) . '</span>';
			  } else {
				$products_price = $currencies->display_price($array[$z]['price'], tep_get_tax_rate($array[$z]['tax_class_id']),1,true);
			  }
			  if(strlen(strip_tags($array[$z]['products_description']))>150)
			  		$description=substr(strip_tags($array[$z]['products_description']),0,150)."...";
				else 
					$description=strip_tags($array[$z]['products_description'],'<br>');
		?>
		
		<!-- <tr>
    <td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products_array[$i]['id'], 'NONSSL') . '">' . tep_image(DIR_WS_IMAGES . $featured_products_array[$i]['image'], $featured_products_array[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
    <td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products_array[$i]['id'], 'NONSSL') . '"><b><u>' . $featured_products_array[$i]['name'] . '</u></b></a><br>' . TEXT_DATE_ADDED . ' ' . $featured_products_array[$i]['date_added'] . '<br>' . TEXT_MANUFACTURER . ' ' . $featured_products_array[$i]['manufacturer'] . '<br><br>' . TEXT_PRICE . ' ' . $products_price; ?></td>
    <td align="right" valign="middle" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_FEATURED_PRODUCTS, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $featured_products_array[$i]['id'], 'NONSSL') . '">' . tep_template_image_button('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</a>'; ?></td>
  </tr> -->
<?php
     // if (($i+1) != sizeof($featured_products_array)) {
?>
		  <tr class="infoContentPage">
		  	<td align="left" width="15%" valign="top">
				<table cellpadding="0" cellspacing="2" border="0" width="100%">
				<tr>
					<td width="<?php echo SMALL_IMAGE_WIDTH + 10; ?>" valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $array[$z]['id'], 'NONSSL') . '">' . tep_product_small_image($array[$z]['image'], $array[$z]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>'; ?></td>
				</tr>
				<tr><td class="main" align="center"><?php echo TEXT_PRICE. ' ' .$products_price;?></td></tr>
				</table>
			</td>
			<td align="left" valign="top" width="60%">
			<table cellpadding="0" cellspacing="2" border="0" width="100%">
				<tr><td valign="top" class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $array[$z]['id'], 'NONSSL') . '"><font  class="mainText"><b>' . $array[$z]['name'] . '</b></font></a>'; ?></td></tr>
				<tr><td valign="top" class="main" height="30"><?php echo $description; ?></td></tr>
				<?php if(HIDE_FEATURED_PRODUCT_ID=="Yes"){?>
				<tr><td class="infoboxContentDetails" valign="top"><?php echo '<b>'.TEXT_ID.'#'.$array[$z]['id'].'</b>';?></td></tr>
				<?php }?>
				<tr><td class="main" valign="top"><?php echo '<br><a href="' . tep_href_link(FILENAME_FEATURED_PRODUCTS, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $array[$z]['id'], 'NONSSL') . '">' . tep_template_image_button('button_details.gif', IMAGE_BUTTON_DETAILS) . '</a>';?></td></tr>
			</table>
			</td>
			<?php 
				  $category_query=tep_db_query("select pc.categories_id from ".TABLE_PRODUCTS_TO_CATEGORIES." pc, ".TABLE_PRODUCTS." p where p.products_id=pc.products_id and p.products_id='".$array[$z]['id']."'");
				  $category_array=tep_db_fetch_array($category_query);
				  $similar_products_query=tep_db_query("select pd.products_name,pd.products_id from ".TABLE_PRODUCTS_DESCRIPTION ." pd, ".TABLE_PRODUCTS_TO_CATEGORIES." pc where pc.products_id=pd.products_id and pc.categories_id='".$category_array["categories_id"]."' and pd.products_id!='".$array[$z]['id']."' group by pd.products_id limit 5");
			?>
			<td align="left" class="main" valign="top" width="25%">
				<table cellpadding="0" cellspacing="2" border="0">
					<?php if(tep_db_num_rows($similar_products_query)){?>
					<tr><td class="infoBoxNavigation"><?php echo '<b>'.TEXT_HEADING_SIMILAR_PRODUCTS.'</b>';?></td></tr><tr><td></td></tr>
					<?php while($similar_products_array=tep_db_fetch_array($similar_products_query)){?>
						<tr><td valign="middle" class="infoboxSimilar"><?php echo '- <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'products_id=' . $similar_products_array['products_id'], 'NONSSL') . '">' . $similar_products_array['products_name'] . '</b></a>';?></td></tr>
					<?php } 
					}?>	
				</table>
			</td>
		  </tr>
		<?php
			  if (($z+1) != sizeof($array)) {
		?>
		  <tr>
			<td colspan="3" class="main"></td>
		  </tr>
		<?php
			  }
			}
		  }
		?>
		</table>
</td>
</tr>
