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

<?php

$modules_template = 'new_products';
$ilosc_col = MAX_DISPLAY_COLUMN_NEW_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) ;

//TotalB2B start
if ( (!isset($new_products_category_id)) || ($new_products_category_id == '0') ) {
    $new_products_query = tep_db_query("
      select distinct p.products_id, p.products_image, p.products_quantity, p.products_tax_class_id, p.manufacturers_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p
        LEFT JOIN " . TABLE_SPECIALS . " s ON p.products_id = s.products_id
        LEFT JOIN ". TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id
        LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id
        LEFT JOIN " . TABLE_CATEGORIES . " c ON c.categories_id = p2c.categories_id
      WHERE c.categories_status='1' AND p.products_status = '1' AND pd.language_id = '" . (int)$languages_id . "' AND DATE_SUB(CURDATE(),INTERVAL " . MAX_DISPLAY_TIME_NEW_PRODUCTS . " DAY) <= p.products_date_added 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;
  }
    $new_products_query = tep_db_query("
      select distinct p.products_id, p.products_image, p.products_quantity, p.products_tax_class_id, p.manufacturers_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p
        LEFT JOIN " . TABLE_SPECIALS . " s ON p.products_id = s.products_id
        LEFT JOIN ". TABLE_PRODUCTS_DESCRIPTION . " pd ON p.products_id = pd.products_id
        LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id
        LEFT JOIN " . TABLE_CATEGORIES . " c ON c.categories_id = p2c.categories_id
      WHERE c.categories_status='1' AND p.products_status = '1' AND c.categories_id in (" . $new_products_category_id_list . ") AND pd.language_id = '" . (int)$languages_id . "' AND DATE_SUB(CURDATE(),INTERVAL " . MAX_DISPLAY_TIME_NEW_PRODUCTS . " DAY) <= p.products_date_added order by rand() 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($new_products_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_PRODUCTS_NEW) . '">' . sprintf(TABLE_HEADING_NEW_PRODUCTS, strftime('%B')).'</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));
            $ile = tep_db_num_rows($new_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
}
?>
<!-- new_products_eof //-->