<?php
	$categories_id_list = tep_get_categories_id_from_products_id($product_info['products_id']);

    $info_box_contents = array();
    $info_box_contents[] = array('text' => TABLE_HEADING_RELATIVE_PRODUCT);
    new contentBoxHeading($info_box_contents);


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

	$relative_products_raw = tep_db_query("SELECT ptc.products_id, p.products_image, p.products_price, pd.products_name, p.products_tax_class_id FROM ".TABLE_PRODUCTS_TO_CATEGORIES." ptc LEFT JOIN " .TABLE_PRODUCTS." p ON ptc.products_id = p.products_id LEFT JOIN " .TABLE_PRODUCTS_DESCRIPTION. " pd ON p.products_id = pd.products_id WHERE p.products_status = 1 AND pd.language_id = '" . (int)$languages_id ."' AND ptc.categories_id in ($categories_id_list) order by rand() LIMIT 6");



	while ($relative_products = tep_db_fetch_array($relative_products_raw)) {
		
		//$new_categories_query=tep_db_query("select distinct cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p2c.products_id =" . $relative_products['products_id'] . " and p2c.categories_id = cd.categories_id");

/*
			$sql='select p2c.categories_id from products_to_categories p2c where p2c.products_id ='.$relative_products['products_id'].' order by p2c.categories_id limit 1';
			$c_query = tep_db_query($sql);
			$c_result = tep_db_fetch_array($c_query);
			$cid=$c_result['categories_id'];
			$cid=soobic_get_categoryid($cid);
			
			$sql="select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id=".$cid." and language_id=4 limit 1";
			$new_categories_query=tep_db_query($sql);

		$new_categories = tep_db_fetch_array($new_categories_query);
*/		
		
		$relative_products['products_image']=str_replace('ebest24B','ebest24b',$relative_products['products_image']);
		$relative_products['products_image']=str_replace('ebest24A','ebest24a',$relative_products['products_image']);
		if(file_exists(DIR_FS_PRODUCTS_IMAGES.$relative_products['products_image'])==0)
			$picture_url = "nopicture.gif";
		else 
			$picture_url = 'products_images/'. $relative_products['products_image'];

	    $info_box_contents[$row][$col] = array('align' => 'center',
                                           'params' => 'class="smallText" width="33%" valign="top"',
                                           'text' => '<a href="' . "./products/".soobic_get_RootcategoryName(soobic_get_p_categoryid($relative_products['products_id']))."/".soobic_get_productName($relative_products['products_id']).".html" . '">' . tep_image(DIR_WS_IMAGES . $picture_url, $relative_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . "./products/".soobic_get_RootcategoryName(soobic_get_p_categoryid($relative_products['products_id']))."/".soobic_get_productName($relative_products['products_id']).".html" . '">' . $relative_products['products_name'] . '</a><br>' . $currencies->display_price($relative_products['products_price'], tep_get_tax_rate($relative_products['products_tax_class_id'])));

    $col ++;
    if ($col > 2) {
      $col = 0;
      $row ++;
    }
		
	}
	  new contentBox($info_box_contents);
?>