<?php
/*
Freeway eCommerce
http://www.openfreeway.org
Copyright (c) 2007 ZacWare

  Categories Functions
*/

////
// Return a product's category
// TABLES: products_to_categories

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();


function tep_get_products_category_id($products_id) 
	{
    global $FSESSION;

    $the_products_category_query = tep_db_query("select products_id, categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . tep_db_input($products_id) . "'" . " order by products_id,categories_id");
    $the_products_category = tep_db_fetch_array($the_products_category_query);

    return $the_products_category['categories_id'];//46=10
	}
  
function tep_get_parent_id($the_products_category) 
	{
    global $FSESSION;
    $the_parent_id_query= tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id= '" . tep_db_input($the_products_category) . "'");

    $the_parent_id = tep_db_fetch_array($the_parent_id_query);
    return $the_parent_id['parent_id'];//4
	}
	
	
	
function tep_get_parent_cat_id($the_parent_id) 
	{
    global $FSESSION;
    $the_parent_cat_id_query= tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id= '" . tep_db_input($the_parent_id) . "'");

    $the_parent_cat_id = tep_db_fetch_array($the_parent_cat_id_query);
    return $the_parent_cat_id['parent_id'];
	}
	

function tep_get_plan_id($the_parent_id) 
	{
    global $FSESSION;
    $the_plan_id_query= tep_db_query("select plan_id from " . TABLE_CATEGORIES . " where categories_id= '" . tep_db_input($the_parent_id) . "'");

    $the_plan_id = tep_db_fetch_array($the_plan_id_query);
    return $the_plan_id['plan_id'];
	}
  
function tep_get_categories_name($the_products_category) 
	{
	global $FSESSION;
	$the_categories_name_query= tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . tep_db_input($the_products_category) . "' and language_id= '" . (int)$FSESSION->languages_id . "'");

	$the_categories_name = tep_db_fetch_array($the_categories_name_query);
	return $the_categories_name['categories_name'];
	}
	
function tep_get_categories_heading_title($the_products_category) 
	{
	global $FSESSION;
	$the_categories_title_query= tep_db_query("select categories_heading_title from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . tep_db_input($the_products_category) . "' and language_id= '" . (int)$FSESSION->languages_id . "'");

	$the_categories_title = tep_db_fetch_array($the_categories_title_query);
	return $the_categories_title['categories_heading_title'];
	}
	
function tep_get_categories_parent_name($the_parent_id) 
	{
	global $FSESSION;
	$the_categories_parent_name_query= tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . tep_db_input($top_cat_id) . "' and language_id= '" . (int)$FSESSION->languages_id . "'");

	$the_categories_parent_name = tep_db_fetch_array($the_categories_parent_name_query);
	return $the_categories_parent_name['categories_name'];
	}

function tep_get_categories_venue($the_products_category) 
	{
	global $FSESSION;
	$the_categories_venue_query= tep_db_query("select concert_venue from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . tep_db_input($the_products_category) . "' and language_id= '" . (int)$FSESSION->languages_id . "'");

	$the_categories_venue = tep_db_fetch_array($the_categories_venue_query);
	return $the_categories_venue['concert_venue'];
	}
  
function tep_get_categories_date($the_products_category) 
	{
	global $FSESSION;
	$the_categories_date_query= tep_db_query("select concert_date from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . tep_db_input($the_products_category) . "' and language_id= '" . (int)$FSESSION->languages_id . "'");

	$the_categories_date = tep_db_fetch_array($the_categories_date_query);
	return $the_categories_date['concert_date'];
	}
  
function tep_get_categories_time($the_products_category) 
	{
	global $FSESSION;
	$the_categories_time_query= tep_db_query("select concert_time from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . tep_db_input($the_products_category) . "' and language_id= '" . (int)$FSESSION->languages_id . "'");

	$the_categories_time = tep_db_fetch_array($the_categories_time_query);
	return $the_categories_time['concert_time'];
	}

function categories_lookup()
	{
    
    global $id;
    
	$heading_name = $heading_venue = $heading_date = $heading_time = $heading_title ='';
    
	$cat_id=tep_get_products_category_id($id);
	$my_parent_id=tep_get_parent_id($cat_id);
	
	$top_cat_id=tep_get_parent_cat_id($my_parent_id);
	$my_plan_id=tep_get_plan_id($cat_id);
	$sub=tep_get_plan_id($top_cat_id);

		if($my_plan_id==9)
		{//GA categories where top categories are SHOWs
		$heading_name=tep_get_categories_name($cat_id);
		$heading_venue=tep_get_categories_venue($cat_id);
		$heading_date=tep_get_categories_date($cat_id);
		$heading_time=tep_get_categories_time($cat_id);
		$heading_title=tep_get_categories_heading_title($cat_id);
		
		//if GA products are in a sub category
			// $heading_name=tep_get_categories_name($my_parent_id);
			// $heading_venue=tep_get_categories_venue($my_parent_id);
			// $heading_date=tep_get_categories_date($my_parent_id);
			// $heading_time=tep_get_categories_time($my_parent_id);
		
		}else{
			if($my_parent_id==0){
			$heading_name=tep_get_categories_name($cat_id);
			$heading_title=tep_get_categories_heading_title($cat_id);
			$heading_venue=tep_get_categories_venue($cat_id);
			$heading_date=tep_get_categories_date($cat_id);
			$heading_time=tep_get_categories_time($cat_id);
			}else{
			$heading_name=tep_get_categories_name($my_parent_id);
			$heading_title=tep_get_categories_heading_title($my_parent_id);
			$heading_venue=tep_get_categories_venue($my_parent_id);
			$heading_date=tep_get_categories_date($my_parent_id);
			$heading_time=tep_get_categories_time($my_parent_id);
			}
		}
			
		if($sub==4){		
		$heading_name=tep_get_categories_name($top_cat_id);
		$heading_title=tep_get_categories_heading_title($top_cat_id);
		//$heading_name=tep_get_categories_name($top_cat_id).' '.tep_get_categories_name($my_parent_id) ;
		//sub
		$heading_venue=tep_get_categories_venue($top_cat_id);
		$heading_date=tep_get_categories_date($top_cat_id);
		$heading_time=tep_get_categories_time($top_cat_id);
		}
  
    return array($heading_name, $heading_venue,  $heading_date, $heading_time, $heading_title);   
    
	}    
  
?>