<?php
/*
  $Id: product_listing.php,v 1.44 2003/06/09 22:49:59 hpdl Exp $
  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com
  Copyright (c) 2003 osCommerce
  Released under the GNU General Public License
*/
//echo "sql===".$listing_sql;
  $listing_split = new splitPageResults($listing_sql, 24, 'p.products_id');
  $listing_query = tep_db_query($listing_split->sql_query);
  if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) )
  {
	 echo '<div class="centertoptext">' .$listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS); 
	 echo '  '.TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))).'</div>'; ?>
<table width="645"  border="0" cellpadding="0" cellspacing="0" bgcolor="#EFEFEF">
  <tr>
    <td align="left"><img src="images/jiao1.gif" width="10" height="10"></td>
    <td align="right"><img src="images/jiao2.gif" width="10" height="10"></td>
  </tr>
</table>
<?
$lines=ceil(tep_db_num_rows($listing_query)/4);

	for($i = 1; $i <= $lines; $i++)
	{
?>
	
<table width="645" border="0" cellpadding="0" cellspacing="0" bgcolor="#EFEFEF">
          <tr>
<?
		for($j = 1; $j <= 4; $j++)
		{
			$listing = tep_db_fetch_array($listing_query);
			if (isset($listing['products_name']))
			{
			$isspecial=0;
			if ($new_price = tep_get_products_special_price($listing['products_id'])) 
			{
			$isspecial=1;
			  $products_price =  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '<span class="productSpecialPrice_r">' . $currencies->display_price($new_price, tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
			  $products_price2 = '<s style="font-size:12px">'.$currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s><span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
			} 
			else
			{
			  $products_price = $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']));
			  $products_price2=$products_price;
			}

			$tepproducts_name=str_replace('+',' + ',$listing['products_name']);
			$tepproducts_name=str_replace('/',' / ',$tepproducts_name);
			$tepproducts_name=str_replace('  /  ',' / ',$tepproducts_name);
			$tepproducts_name=str_replace('  +  ',' + ',$tepproducts_name);
			if(strlen($tepproducts_name)>60){
				$pos=strpos($tepproducts_name," ",61);
				if ($pos)
				{
					$str_product_name=substr_replace($tepproducts_name," ...",$pos);
				}
				else
				{
					$str_product_name=$tepproducts_name;
				}
			
			}
			else{
				$str_product_name=$tepproducts_name;
			}
			?>
			<td width="25%" height="165" >
			
				<table  border="0" align="center" cellpadding="0" cellspacing="0" class="pro_table" style="table-layout:fixed;">
					<tr>
					<td valign="top"onMouseOver="this.style.background='url(images/pro_tb_bg_yellow.gif)'" onMouseOut="this.style.background='url(images/pro_tb_bg.gif)'" style="width:158px; ">
					<div class="pro_pic" <? if ($listing['products_status']==0) echo 'style="background:url(./images/soldout.jpg) no-repeat 4px 4px;"';?>><a href="<? echo tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']);?>"><img src="images/products_images/<?=$listing['products_image']?>"  alt="<? echo $listing[products_name];?>" width="90" height="90" vspace="10" border="0"></a></div>
					<div style=''><a class="pro_namea" href="<? echo tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']);?>"  title="<?=$listing[products_name]?>"><?=$str_product_name?></a></div>
					<?
					if ($listing['products_price']>0)
					{?>
						<div class="pro_price">
						<?php if ($isspecial==0)
						echo $products_price2;
						else
						echo $products_price2;
						?>
						</div>
					<?
					}
					
					if ($listing['products_status'])
					{?>
						<div class="pro_addtocart"><a href="<? echo tep_href_link(FILENAME_DEFAULT, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'sort=2a&action=buy_now&products_id=' . $listing['products_id']);?>"><img src="<?=DIR_WS_LANGUAGES.$language?>/images/addtocart.gif"  border="0"></a></div>
					<?
					} ?>
					</td>
				      </tr>
			      </table>
			</td>
		<?
		}else{
			echo '<td width="25%" height="165" >&nbsp;</td>';
			}
		}
		?>
			  </tr>
		</table>
	<?
	}
	
	echo '
	<table width="645"  border="0" cellpadding="0" cellspacing="0" bgcolor="#EFEFEF">
		<tr>
		<td align="left"><img src="images/jiao3.gif" width="10" height="10"></td>
		<td align="right"><img src="images/jiao4.gif" width="10" height="10"></td>
		</tr>
	</table>
	';
		
}else {

    $list_box_contents = array();

    $list_box_contents[0] = array('params' => 'class="productListing-odd"');
    $list_box_contents[0][] = array('params' => 'class="productListing-data"',
                                   'text' => TEXT_NO_PRODUCTS);

    new productListingBox($list_box_contents);

  }

if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) )
{
	echo '<div class="centertoptext">' .$listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS);
	echo '  ' . TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))).'</div>';
}
?>
