<?php 
/*
	osConcert, Online Seat Booking 
	http://www.osconcert.com
	
	Copyright (c) 2009-2014 osConcert
	
	Released under the GNU General Public License 
	
*/	
// Check to ensure this file is included in osConcert!
defined('_FEXEC') or die();

		$cPath = $current_category_id;
		$categories_query = tep_db_query("select * from " . TABLE_CATEGORIES . " where categories_id = '" .$cPath ."'");
		while ($categories = tep_db_fetch_array($categories_query)) 
		{
			$parent_id = $categories['parent_id'];
			$status = $categories['categories_status'];
			$plan_id = $categories['plan_id'];
			$date_id = $categories["date_id"];
			$date = strtotime($categories["date_id"]);
			$thedate= date(EVENTS_DATE_FORMAT, $date);
			$image = $categories['categories_image'];
			$spacer="&nbsp;&nbsp;&nbsp;&nbsp;";
		}
		//do we need this anymore?
		// if($plan_id==2)
		// {
			// $image_width = SUBCATEGORY_IMAGE_WIDTH;
			// $image_height = SUBCATEGORY_IMAGE_HEIGHT;
			// }else{
			// $image_width = HEADING_IMAGE_WIDTH;
			// $image_height = HEADING_IMAGE_HEIGHT;
		// }
		if($image=='')
		{
			$image='pixel_trans.gif';
		}
		
		if ($parent_id==0)
		{			
			$cat = $cPath; 
			}
			else
			{
			$cat = (int)$parent_id;
		}
		// this selects from both category tables for this page
		$concert_query = tep_db_query("SELECT * FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd  WHERE c.categories_id=cd.categories_id and c.categories_id= '" . $cat . "' and cd.language_id = '" . (int)$FSESSION->languages_id . "'");
		while ($result = tep_db_fetch_array($concert_query)) 
		{
			$categories_name = $result['categories_name'];
			$categories_heading = $result['categories_heading_title'];
			$cvenue = $result['concert_venue'];
			$cdesc = $result['categories_description'];
			//$cdate = $result['concert_date'];
			$ctime=$result['concert_time'];
			$cdate = strtotime($result["concert_date"]);
			//$concert_date = date(EVENTS_DATE_FORMAT, $cdate);
			
			
				if(EVENTS_DATE_FORMAT=='d-m-Y')
				{
				$concert_date = date('d M, Y', $cdate);
				}
				if(EVENTS_DATE_FORMAT=='m-d-Y')
				{
				$concert_date = date('M d, Y', $cdate);
				}
				if(EVENTS_DATE_FORMAT=='Y-m-d')
				{
				$concert_date = date('Y, d M,', $cdate);
				}
			if (strtotime($concert_date)>strtotime(0)) 
			{ 
			}
			else
			{
			$concert_date = $result['concert_date'];
			}
			
		}
	?>
    
<?php 
	######################################################
	$id=$products_id;
	require_once(DIR_WS_INCLUDES . 'functions/categories_lookup.php');
	#####################################################
	// // call the new function
	list($heading_name, $heading_venue,  $heading_date, $heading_time) = categories_lookup();

	######################################################	
	//categories details here
	require_once(DIR_WS_TEMPLATES .'performance.php');
	//you want it part of the current template??
	//require_once(DIR_WS_TEMPLATES.TEMPLATE_NAME.'/content/performance.php');
	// new code get all parents
	tep_get_parent_categories($result_check,$cPath);
	// set the variable
	$show_the_plan=1;

	if(is_array($result_check))
	{
		foreach($result_check as $key => $value)
		{
			$parent_categories_query = tep_db_query("select categories_status from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$value. "'");
			while ($parent_categories = tep_db_fetch_array($parent_categories_query)) 
			{
			if ($parent_categories['categories_status'] == 0) $show_the_plan=0;
			}
		}
	}

	if ($status !=0 && $show_the_plan==1)
	{
			
	if(($plan_id==3) or ($plan_id==2) or ($plan_id==0))	
	//if($plan_id<9)
	{
	//require_once(DIR_WS_INCLUDES.'seatplan.php');
	require_once(DIR_WS_TEMPLATES.TEMPLATE_NAME.'/content/seatplan.php');
	}
	require_once(DIR_WS_TEMPLATES.TEMPLATE_NAME.'/content/products_ga.php');
	

	}else
	{//allow BO to see the plan
		echo "<h4>" . EVENT_DISABLED_MESSAGE . "</h4>";
			if (($_SESSION['BoxOffice']== 999)or($_SESSION['customer_country_id']==999))
			{
				//require_once(DIR_WS_INCLUDES.'seatplan.php');
				require_once(DIR_WS_TEMPLATES.TEMPLATE_NAME.'/content/seatplan.php');
				require_once(DIR_WS_TEMPLATES.TEMPLATE_NAME.'/content/products_ga.php');
			}
	}
	//print_r($show_the_plan);
	
    if (isset($cPath) && strpos('_', $cPath)) 
	{
		
		// check to see if there are deeper categories within the current category
		$category_links = array_reverse($cPath_array);
		for($i=0, $n=sizeof($category_links); $i<$n; $i++) 
		{
			$categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status > '0' and c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$FSESSION->languages_id . "'");
			$categories = tep_db_fetch_array($categories_query);
			if ($categories['total'] < 1) 
			{
			// do nothing, go through the loop
			} else 
			{
			$categories_query = tep_db_query("select * from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status > '0' and c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$FSESSION->languages_id . "' order by sort_order, cd.categories_id");
			break; // we've found the deepest category the customer is in
			}
		}
    
    }else
	{
	$system = date('Hi');
	$today = date('Ymd');//date("F j, Y, g:i a");

    }
	//show the sub category grid
	if(SHOW_SUBCATEGORIES=='yes')
	{
		
	$categories_query = tep_db_query("select * from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status > '0' and c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$FSESSION->languages_id . "' order by c.sort_order, cd.categories_id");
	

	$num_categories = tep_db_num_rows($categories_query);

		if ($num_categories > 0) 
		{
			$counter = 0;
			$col = 0;

			while ($categories = tep_db_fetch_array($categories_query)) 
			{
				
			//$categories_description = $featured_categories['categories_description'];	
			//$categories_description = ltrim(substr($categories_description, 0, 75) . '...'); //Trims and Limits the desc
			$counter++;
			
			$cPath_new = tep_get_path($categories['categories_id']);
			$cPath_end = $categories['categories_id'];

			//count seats reserved
			if (SUBCATEGORY_COUNT == 'reserved')
			{
			$status=0;
			$count_text=RESERVED;
			}
			if (SUBCATEGORY_COUNT == 'remaining')
			{
			$status=1;
			$count_text=REMAINING;
			}
			
			if (($categories['categories_image'] == 'NULL') or ($categories['categories_image'] == '')) 
			{
			//$cat_image="theatre.png";
			$cat_image=$category['categories_image'];
			}else
			{
			$cat_image=$categories['categories_image'];
			}


			$button="breadcrumb-link";
			$br="<br>";
			$img=tep_image(DIR_WS_IMAGES . $cat_image, '', SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT);

			$countGA_query = tep_db_query("select products_quantity,product_type,products_ordered FROM " . TABLE_PRODUCTS . "  WHERE  parent_id = '" . $cPath_end . "'");
			while ($result = tep_db_fetch_array($countGA_query)) 
			{
			$type=$result['product_type'];
			$quantity=$result['products_quantity'];
			$ordered=$result['products_ordered'];
			}

			$count_query = tep_db_query("select products_status,products_quantity,product_type,products_ordered FROM " . TABLE_PRODUCTS . "  WHERE products_status = '" . $status . "' and parent_id = '" . $cPath_end . "'");
			$sub_count = tep_db_num_rows($count_query);

			if ($type=='P')
			{
			$count=$sub_count;
			} else 
			{
			if (SUBCATEGORY_COUNT == REMAINING)
			{
			$count= $quantity;
			} 
			if (SUBCATEGORY_COUNT == RESERVED)
			{
			$count= $ordered;
			}
			}

			$date = strtotime($categories["date_id"]);
			$thedate=$categories['concert_date'];

			$width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';

			
			//MAX_DISPLAY_CATEGORIES_PER_ROW?
			$categories_content .= '
			<div class="col-lg-4 col-md-4" style="text-align:center;border: red 0px solid;">
			<div class="portfolio-item">
			<div class="portfolio-overlay">
			<div class="portfolio-info">
			<a class="' . $button . '" href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . $img .  $br  . $categories['categories_name'] . '</a><br><span class="small">' . $thedate . '</span><br></a>
			</div>
			</div>
			</div>
			</div>
			';
			$col ++;
			}
		}
	}
	?>
		<div class="container">
		<div class="container-fluid">
		<div class="row no-gutters">
		<?php 
		echo $categories_content; 
		?>
		</div>
		</div>
		</div>
		<?php 
		if(SHOW_MAIN_FEATURED_CATEGORIES == 'true')
	{
		require_once(DIR_WS_MODULES  . FILENAME_FEATURED_CATEGORIES);
	}
		 ?>  
		
		<?php //require('useful_info.php'); ?>
		<?php //echo "Hello"; ?>