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

<?php

$modules_template = 'default_specials';
$ilosc_col = MAX_DISPLAY_COLUMN_DEFAULT_SPECIALS;
$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) ;

if (!isset($customer_id)) $customer_id = 0;
$boxContent = '';
$customer_group = tep_get_customers_groups_id();

if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
   $default_specials_query = tep_db_query("select distinct p.products_id, products_quantity, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c  where c.categories_status='1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' and ((s.customers_id = '" . $customer_id . "' and s.customers_groups_id = '0') or (s.customers_id = '0' and s.customers_groups_id = '" . $customer_group . "') or (s.customers_id = '0' and s.customers_groups_id = '0')) order by RAND() limit " . $max_display);
} else {
  $subcategories_array = array();
  tep_get_subcategories($subcategories_array, $new_products_category_id);
  $new_products_category_id_list = tep_array_values_to_string($subcategories_array);
  if ($new_products_category_id_list =='') {
    $new_products_category_id_list .= $new_products_category_id;
  } else {
    $new_products_category_id_list .= ',' . $new_products_category_id;
  }
   $default_specials_query = tep_db_query("select distinct p.products_id, products_quantity, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c  where c.categories_status='1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and c.categories_id in (" . $new_products_category_id_list . ") and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' and ((s.customers_id = '" . $customer_id . "' and s.customers_groups_id = '0') or (s.customers_id = '0' and s.customers_groups_id = '" . $customer_group . "') or (s.customers_id = '0' and s.customers_groups_id = '0')) order by RAND() limit " . $max_display);
}

$query_special_prices_hide_result = SPECIAL_PRICES_HIDE;
$special_hide = $query_special_prices_hide_result;

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

<!-- new_products //-->
<table border="0" width="100%" cellspacing="0" cellpadding="0" class="templateinfoBox">
 <tr>
  <td class="main" style="padding-bottom:1px">
   <?php
   $info_box_contents = array();
   $info_box_contents[] = array('text' => '<a class="headerNavigationFeatured" href="' . tep_href_link(FILENAME_SPECIALS) . '">' . BOX_HEADING_SPECIALS . '</a>');
   new contentBoxHeading($info_box_contents);
   ?>
  </td>
 </tr>
<tr>
  <td align="center" style="padding-bottom:5px">
   <table border="0" width="100%" cellspacing="0" cellpadding="1">
   <tr>
   <?php
   include (bts_select('modules', $modules_template));
   ?>
   <?php
   if (isset($row) && isset($col)) {
	   $ile = tep_db_num_rows($default_specials_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
}
?>
<!-- new_products_eof //-->