/***********************************************/
/* Random Category Images v 1.3 /
/* coded /
/* by Bo Biene /
/***********************************************/
define('EMPTY_CAT_IMAGE', 'empty.gif');
function get_random_cat_image($category_id, $count = 0)
{
srand ((double)microtime()*1000000);
$retun_val;
if($category_id > 0 && tep_count_products_in_category_without_sub($category_id) > 0 && $count < 10)
{
$randInt = rand(1,10);
$randStart = $randInt -1;
$produkt_query = tep_db_query( "select p.products_image as img from products p ".
"LEFT OUTER JOIN products_to_categories ptc ON ".
"p.products_id = ptc.products_id ".
"WHERE LENGTH(p.products_image) > 0 ".
"AND ptc.categories_id = ".$category_id);
while($result = tep_db_fetch_array($produkt_query))
{
$retun_val = $result['img'];
if(rand(1,10) > 8)
break;
}
if(!(tep_not_null($retun_val)) && tep_has_category_subcategories($category_id))
{
$retun_val = get_random_cat_image_from_child($category_id,$count);
}
}
else if($category_id > 0 && tep_has_category_subcategories($category_id) && $count < 10)
{
$retun_val = get_random_cat_image_from_child($category_id,$count);
}
else
{
$retun_val = EMPTY_CAT_IMAGE;
}
return $retun_val;
}
function get_random_cat_image_from_child($category_id,$count = 0)
{
$retun_val;
$category_query = tep_db_query("select categories_id as ID from ". TABLE_CATEGORIES ." WHERE parent_id = ". $category_id ." LIMIT 0,". rand(1,10) );
while($ids = tep_db_fetch_array($category_query))
{
$id = $ids['ID'];
$retun_val = get_random_cat_image($id, $count++);
if((tep_not_null($retun_val)) && $retun_val != EMPTY_CAT_IMAGE)
break;
}
return $retun_val;
}
//Changed from osCommerce
function tep_count_products_in_category_without_sub($category_id, $include_inactive = false)
{
$products_count = 0;
if ($include_inactive == ftrue) {
$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");
} else {
$products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'");
}
$products = tep_db_fetch_array($products_query);
return $products['total'];
}
?>
Numeri civici - fd-bolletta lampade