<?php
$tab_wys = SMALL_IMAGE_HEIGHT+10;
$tab_szer = SMALL_IMAGE_WIDTH+10;

$szerokosc = SMALL_IMAGE_WIDTH+10;
$wysokosc = SMALL_IMAGE_HEIGHT+10;

$row = 0;
$col = 1;
$info_box_contents = array(); 

while ($listing = tep_db_fetch_array($listing_query)) { 
	$listing['products_name'] = tep_get_products_name($listing['products_id']); 
    $listing['products_name'] = osc_trunc_string($listing['products_name'], 50, 1);


	if ($listing['products_quantity']  > 0) {
		if ($listing['products_price'] > 0) {
			$form_start = ((USE_SHOP_AS_CATALOG == 'true') ? '' : '<form name="buy_now_' . $listing['products_id'] . '" method="post" action="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now', 'NONSSL') . '">');
			$form_koniec = ((USE_SHOP_AS_CATALOG == 'true') ? '' : '</form>');
			$przcisk_kup = '<input type="hidden" name="products_id" value="' . $listing['products_id'] . '">'.((CZY_ZAMAWIANA_ILOSC == 1) ? '' : '<input type="hidden" name="quantity" value="1">') . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_IN_CART . ' ' . $listing['products_name']);
			$ilosc = ENTRY_CANTIDAD.'&nbsp;&nbsp;<input type="text" name="quantity" value="1" maxlength="4" size="2">';
		} else {
		    $form_start = '';
			$form_koniec = '';
			$przcisk_kup = '';
			$ilosc = '';
		}
	} else {
		if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
		    $form_start = '';
			$form_koniec = '';		
			$przcisk_kup = ' '.tep_image_button('button_sold.gif').'';
			$ilosc = '';
		} else {
			$form_start = ((USE_SHOP_AS_CATALOG == 'true') ? '' : '<form name="buy_now_' . $listing['products_id'] . '" method="post" action="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now', 'NONSSL') . '">');
			$form_koniec = ((USE_SHOP_AS_CATALOG == 'true') ? '' : '</form>');		
			$przcisk_kup = '<input type="hidden" name="products_id" value="' . $listing['products_id'] . '">'.((CZY_ZAMAWIANA_ILOSC == 1) ? '' : '<input type="hidden" name="quantity" value="1">') . tep_image_submit('button_buy_now.gif', IMAGE_BUTTON_IN_CART . ' ' . $listing['products_name']);
			$ilosc = ENTRY_CANTIDAD.'&nbsp;&nbsp;<input type="text" name="quantity" value="1" maxlength="4" size="2">';
		}
	}
	
    if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
 	    $display_nb = 1;
 	  } else {
	    $display_nb = 0;
    }		

    //TotalB2B start
    if ($new_price = tep_get_products_special_price($listing['products_id']) ) {
        $listing_org['products_price'] = tep_xppp_getproductprice($listing['products_id']);
        $listing['products_price'] = $new_price;

        if ($listing['products_price'] > 0) {
            if ($special_hide == 'false') {
               $query_price_to_guest_result = ALLOW_GUEST_TO_SEE_PRICES;
               if ((($query_price_to_guest_result=='true') && !(tep_session_is_registered('customer_id'))) || ((tep_session_is_registered('customer_id')))) {
                  $cena_produktu = '<span class="smallText">'. TABLE_HEADING_PRICE . ':</span>&nbsp;<span class="smallText"><s>' . $currencies->display_price($listing['products_id'], $listing_org['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s></span><br><span class="productSpecialPrice">' . $currencies->display_price_nodiscount($listing['products_id'], $listing['products_price'],tep_get_tax_rate($listing['products_tax_class_id']),1,$display_nb) .'</span>';
               } else {
                  $cena_produktu = '<span class="smallText">'. TABLE_HEADING_PRICE . ':</span><br><span class="Cena">' . PRICES_LOGGED_IN_TEXT . '</span>';
               }
           } else {
                $cena_produktu = '<span class="Cena">' . $currencies->display_price($listing['products_id'], $listing_org['products_price'], tep_get_tax_rate($listing['products_tax_class_id']),1,$display_nb) .'</span>';
            }
        } else {
             $cena_produktu = '<span class="smallText"><b>'.TEMPORARY_NO_PRICE.'</b></span>';
        }
    } else {
        $listing['products_price'] = tep_xppp_getproductprice($listing['products_id']);
        if ($listing['products_price'] > 0) {
            $cena_produktu = '<span class="smallText">'. TABLE_HEADING_PRICE . ':<br></span><span class="Cena">' . $currencies->display_price($listing['products_id'],$listing['products_price'],tep_get_tax_rate($listing['products_tax_class_id']),1,$display_nb).'</span>';
        } else {
            $cena_produktu = '<span class="smallText"><b>'.TEMPORARY_NO_PRICE.'</b></span>';
        }
    }
    //TotalB2B end & TotalB2B end
	
  echo '
  <td width="'.$szer_tab.'%" align="center" valign="top" height="100%" class="TableFrame">'.$form_start.'
	<div align="center" style="height:45px;padding:5px">';
		if (isset($HTTP_GET_VARS['manufacturers_id'])) {
		  echo '<a class="ProductTile" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . osc_trunc_string($listing['products_name'],50, 1) . '</a>';
		} else {
		  echo '<a class="ProductTile" href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . osc_trunc_string($listing['products_name'], 50, 1) . '</a>';
		}
	echo '</div>
	<div align="center">'.
	  (($listing['products_image'] != '') ? 
	   (isset($HTTP_GET_VARS['manufacturers_id']) ?
		  tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,'',$wysokosc,$szerokosc,$listing['products_id'],tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']),true) :
		  tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,'',$wysokosc,$szerokosc,$listing['products_id'],tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']),true) 
	   ) : '').'
	</div>
	<div align="center" style="padding:5px">'.$cena_produktu .'</div>';
	if (CZY_ZAMAWIANA_ILOSC == 1 && USE_SHOP_AS_CATALOG != 'true') { echo '
	  <div align="center" class="smallText"'.(($ilosc != '') ? ' style="padding:6px;"' : '').'>'.$ilosc.'</div>';
	}
    echo '<div align="center">';
	  if (isset($HTTP_GET_VARS['manufacturers_id'])) {
	   echo '<a class="ProductTile" href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">'.tep_image_button('small_view.gif').'</a>&nbsp;&nbsp;';
	  } else {
	    echo '<a class="ProductTile" href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">'.tep_image_button('small_view.gif').'</a>&nbsp;&nbsp;';
	  }
      echo ((USE_SHOP_AS_CATALOG == 'true') ? '' : $przcisk_kup).'
	</div>
  '.$form_koniec.'</td>';	

    $col ++;
    if ($col > $ilosc_col) {
		$span= 0;
        $col = 1;
        $row ++;
		    $span = ($ilosc_col * 2) - 1;
        if ($row < $max_wiersz) {
          echo '
          </tr>
          <tr>
           <td colspan="'.$span.'" width="100%" height="5"></td>
          </tr>
          <tr>';
        } else {
          echo '
          '
          ;
        }
	  } else {
		echo '
        <td width="5" height="100%">'.tep_draw_separator('pixel_trans.gif', '5', '1').'</td>';
    }
}

?>