<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
?>

<?php
$modules_template = 'featured';
$ilosc_col = MAX_DISPLAY_COLUMN_FEATURED_PRODUCTS;
$max_display = 1;
$modul_query = tep_db_query("select configuration_id, max_display from " . TABLE_MODULES_CONFIGURATION . " WHERE configuration_title = '".$modules_template."'");
$moduls = tep_db_fetch_array($modul_query);
$max_display=$moduls['max_display'];
$max_wiersz =  $max_display/$ilosc_col;
$szer_tab = round(100/$ilosc_col,0) ;


  $featured_products_category_id = $current_category_id;

  list($usec, $sec) = explode(' ', microtime());
  srand( (float) $sec + ((float) $usec * 100000) );
  $mtm= rand();
  //TotalB2B start

  $featured_products_query = tep_db_query("
  SELECT distinct p.products_id, pd.products_name, p.products_image, p.products_quantity, p.products_price, p.products_tax_class_id, c.categories_status, 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 and pd.language_id = '" . $languages_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)
    LEFT JOIN ". TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON (p.products_id = p2c.products_id)
    LEFT JOIN ". TABLE_CATEGORIES." c ON (p2c.categories_id = c.categories_id)
  WHERE c.categories_status='1' AND p.products_status = '1' AND f.status = '1' AND c.categories_id = '".$featured_products_category_id."'
    order by rand() DESC limit " . $max_display);

//  $featured_products_query = tep_db_query("  SELECT distinct p.products_id, pd.products_name, products_quantity, p.products_image, p.products_tax_class_id, s.status as specstat, s.specials_new_products_price, p.products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where c.categories_status='1' and p.products_status = '1' and f.status = '1' AND c.categories_id = '".$featured_products_category_id."' order by rand() DESC limit " . $max_display);

  //TotalB2B end

  $query_special_prices_hide_result = SPECIAL_PRICES_HIDE;
  $special_hide = $query_special_prices_hide_result;

  if (tep_db_num_rows($featured_products_query) > 0) {
    ?>

    <!-- featured products //-->
    <table border="0" width="100%" cellspacing="0" cellpadding="0" class="templateinfoBox">
<tr>
  <td class="modulesBox" align="center">
   <table border="0" width="100%" cellspacing="0" cellpadding="1">
   <tr>
   <?php
   include (bts_select('modules', $modules_template));
   ?>
   <?php
   $ile = tep_db_num_rows($featured_products_query)-($row*$ilosc_col);
   if ($ile < $ilosc_col && $ile != 0) {
      $roznica = $ilosc_col - $ile;
	  for($index=0;$index<$roznica;$index++)
	  {
	    if ($index == $roznica-1) {
	    echo '<td width="'.$szer_tab.'%">'.tep_draw_separator('pixel_trans.gif', '100%', '1').'</td>';
		} else {
		echo '<td width="'.$szer_tab.'%">'.tep_draw_separator('pixel_trans.gif', '100%', '1').'</td>';
		echo '<td>'.tep_draw_separator('pixel_trans.gif', '1', '1').'</td>';
		}
	  }
   }
   ?>
   </tr>
   </table>
  </td>
 </tr>
    </table>
    <?php
  }
?>
<!-- featured_products_eof //-->