<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
  /////////////////////////////////////////////////////////////////////////
  FADE-IN dla SPECIAL.PHP
  zastosowanie funkcji new fadeshow(nazwa tablicy, szerokosc, wysokosc, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)
  dopasowanie do oscGold - Julek Krysiak - (C) Copyright !!!!

  trzeba zdefiniowac:
  fadebgcolor - kolor tla obrazka
  tlocolor - kolor tla napisow
  ewentualnie w funkcji fadeshow paramtery j.w.
  /////////////////////////////////////////////////////////////////////////

*/
if ( SPECIAL_PRICES_HIDE == 'false' ) {
$query_price_to_guest_result = ALLOW_GUEST_TO_SEE_PRICES;

$boxHeading = BOX_HEADING_SPECIALS;
$corner_left = 'rounded';
$corner_right = 'rounded';
$boxContent_attributes = ' align="center"';
$szerokosc = SMALL_IMAGE_WIDTH+10;
$wysokosc = SMALL_IMAGE_HEIGHT+10;

$box_base_name = 'specials_fade';
$box_id = $box_base_name . 'Box';
$boxLink = '<a class="boxLink" href="' . tep_href_link(FILENAME_SPECIALS) . '">' .tep_image(DIR_WS_TEMPLATES . 'images/infobox/arrow_right.gif') .'</a>';

if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
	$display_nb = 1;
  } else {
	$display_nb = 0;
}

if (!isset($customer_id)) $customer_id = 0;
	$customer_group = tep_get_customers_groups_id();
    $rp_query = tep_db_query("select p.products_id, 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_RANDOM_SELECT_SPECIALS);
	$ilosc_produktow = tep_db_num_rows($rp_query);
    if ($ilosc_produktow > 1) {

      $i = 0;
      while ($random_product = tep_db_fetch_array($rp_query)) {

      $random_product['products_price'] = tep_xppp_getproductprice($random_product['products_id']);
      $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);
      $query_special_prices_hide_result = SPECIAL_PRICES_HIDE;

      if ($random_product['products_image'] != ''){

            $random_product['products_image'] = str_replace('%5B','[',$random_product['products_image']);
            $random_product['products_image'] = str_replace('%5D',']',$random_product['products_image']);
            $random_product['products_image'] = str_replace('%20',' ',$random_product['products_image']);

            $test = file_exists(DIR_WS_IMAGES . $random_product['products_image']);
            if (!$test) {
                $pausecontentf[$i] .=  DIR_WS_IMAGES . 'default.gif';
               } else {
                $pausecontentf[$i] .=  DIR_WS_IMAGES . $random_product['products_image'];
                // ***********************************************************************************************
                if (ICON_POKAZUJ == '1') {
                    $typ = '';
                    if (ICON_OCZEKIWANY == '1') {
                        for ($xi = 0; $xi < count($oczekiwane); $xi++) {
                            if ($oczekiwane[$xi] == $random_product['products_id']) { $typ = 'oczekiwany'; }
                        }
                    }
                    if (ICON_POLECANY == '1') {
                        if ($typ == '') {
                            for ($xi = 0; $xi < count($polecane); $xi++) {
                                if ($polecane[$xi] == $random_product['products_id']) { $typ = 'polecany'; }
                            }
                        }
                    }
                    if (ICON_PROMOCJA == '1') {
                        if ($typ == '') {
                            for ($xi = 0; $xi < count($promocje); $xi++) {
                                if ($promocje[$xi] == $random_product['products_id']) { $typ = 'promocja'; }
                            }
                        }
                    }
                    if (ICON_NOWOSC == '1') {
                        if ($typ == '') {
                            $product_query = tep_db_query("select products_date_added from " . TABLE_PRODUCTS . " where products_id = '" . (int)$random_product['products_id'] . "'");
                            $product = tep_db_fetch_array($product_query);
                            $data_prod = strtotime($product['products_date_added']);
                            $data_dzis = strtotime(date("Y-m-d"));
                            $czas_nowosci = $data_dzis - (MAX_DISPLAY_TIME_NEW_PRODUCTS * (60*60*24));
                            if ($data_prod >= $czas_nowosci) {
                               $typ = 'nowosc'; }
                    }
                    }

                    if ($typ != '') {
                        $image_dod[$i] = DIR_WS_TEMPLATES .'icon/'.$language.'/'.$typ . '.gif';
                        } else {
                        $image_dod[$i] = '';
                    }
                }
                // koniec
                // *****************************************************************************************
            }

            $obraz = getimagesize($pausecontentf[$i]);      //tworzy tablice z rozmiarami obrazka

            $szei = $szerokosc / $obraz[0];
            $wysi = $wysokosc / $obraz[1];
            if ($szei <= $wysi) {
                $szerokosc_ostateczna[$i] = ($obraz[0] * $szei)-2;
                $wysokosc_ostateczna[$i] = ($obraz[1] * $szei)-2;
               } else {
                $szerokosc_ostateczna[$i] = ($obraz[0] * $wysi)-2;
                $wysokosc_ostateczna[$i] = ($obraz[1] * $wysi)-2;
            }

           $lin[$i]=tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']);	// tworzy link produktu
           $nazwa_produk[$i] = osc_trunc_string($random_product['products_name'], 50, 1);	// tworzy nazwe produktu
           $nazwa_produk[$i] = str_replace('"','`',$nazwa_produk[$i]);
           $nazwa_produk[$i] = str_replace("'","`",$nazwa_produk[$i]);

           if ((($query_price_to_guest_result=='true') && !(tep_session_is_registered('customer_id'))) || ((tep_session_is_registered('customer_id')))) {
              $kwota[$i] = '<span class="boxText"><s>' . $currencies->display_price($random_product['products_id'], $random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '<%2Fs><%2Fspan><br><span class="productSpecialPrice">' . $currencies->display_price_nodiscount($random_product['products_id'], $random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id']),1,$display_nb) . '<%2Fspan>';
            } else {
              $kwota[$i] = '<span class="boxText"><b>' .PRICES_LOGGED_IN_TEXT. '<%2Fb><%2Fspan>';
           }
           $i++;
      }
    }
    $tablica_spec_fade = '';
	$tablica_spec_fade .= 'var fadeimages=new Array();';
	$tablica_spec_fade .= 'var tlocolor = "#ffffff";';
	$tablica_spec_fade .= 'var szerokosc = "'.$szerokosc.'";';
	$tablica_spec_fade .= 'var wysokosc = "'.$wysokosc.'";'."\n";

	$i = 0;
	while ($pausecontentf[$i]) {
		$tablica_spec_fade .= "fadeimages[".$i."] = ['".$pausecontentf[$i]."','".$lin[$i]."','','" . $szerokosc_ostateczna[$i] . "','" . $wysokosc_ostateczna[$i] . "','" . $nazwa_produk[$i] . "','" . str_replace('</span>','<%2Fspan>',$kwota[$i]) . "','".$image_dod[$i]."'];"."\n";
		$i++;
	}

	$boxContent = '<script type="text/javascript" language="javascript" src="includes/javascript/specials_fade.js"></script>'."\n";
	if ($ilosc_produktow > 1) {
		if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
	 	    $display_wys = 120;
	 	  } else {
		    $display_wys = 93;
	    }
		$wysokosc_pola = $wysokosc + $display_wys;
		$szerokosc_pola = 160;
		$boxContent .= "<script type='text/javascript' language='javascript'>".$tablica_spec_fade."new fadeshow(fadeimages, " . $szerokosc_pola . ", " . $wysokosc_pola . ", 0, 5000, 0, 'R');</script>";
	    $boxContent .= "<noscript><span class='smallText'>Brak obslugi JavaScript</span><br><br></noscript>";
		$boxContent .= '<br><a class="boxLink" href="'.tep_href_link(FILENAME_SPECIALS).'"><b>'.WHATS_NEW_ALL.'</b></a>';
	}

    include (bts_select('boxes', $box_base_name)); // BTS 1.5

    $boxLink = '';

    $boxContent_attributes = '';
}
}
?>