<?php
/*
	osConcert Seat Booking Software
    http://www.osconcert.com
    Copyright (c) 2021 osConcert
	
	Released under the GNU General Public License 
*/

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

require_once(DIR_WS_INCLUDES . 'functions/categories_lookup.php');


	$category['categories_image']='theatre.png';
	//about images
	if (($category['categories_image'] == 'NULL') or ($category['categories_image'] == '')) //Warning: Illegal string offset
	{

		$cat_image="theatre.png";	

	}else
	{
		$cat_image=$category['categories_image'];
	}

	$page=" and c.parent_id = '0'";
	
	

	$sql_order_by = FEATURED_CATEGORIES_ORDERBY;
	
	//  and c.date_id>0
	//and  c.date_id !=''

	$featured_categories_query = tep_db_query("select * from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status > '0'".$page." and  c.categories_id = cd.categories_id and cd.language_id = '" . (int)$FSESSION->languages_id . "' order by c." .$sql_order_by . " ASC");
	
	$num_featured_categories = tep_db_num_rows($featured_categories_query);

	if ($num_featured_categories > 0) 
	{
		while ($featured_categories = tep_db_fetch_array($featured_categories_query)) 
		{
			$heading_name=$featured_categories['categories_name'];
			$categories_description = $featured_categories['categories_description'];
			//$categories_description = ltrim(substr($categories_description, 0, 75) . '...'); //Trims and Limits the desc
			$cPath_new = tep_get_path($featured_categories['categories_id']);
			$cPath_end = $featured_categories['categories_id'];
			$heading_title = $featured_categories["categories_heading_title"];
			$heading_venue=$featured_categories['concert_venue'];
			$concert_date = $featured_categories['concert_date'];
			$concert_time = $featured_categories['concert_time'];
			$categories_GA = $featured_categories['categories_GA'];
			$categories_quantity_remaining = $featured_categories['categories_quantity_remaining'];
			
			// Format the date and time if they are valid
        if (!empty($concert_date) && strtotime($concert_date)) {
            $formatted_date = format_heading_date($concert_date);
        }
        if (!empty($concert_time) && strtotime($concert_time)) {
            $formatted_time = format_heading_time($concert_time);
        }
		

		$col=0;
		
			if($categories_GA==1 && HIDE_GA_ONLY_QTY=='no')
			{//this is a GA category with master quantity
				$count=$categories_quantity_remaining;
			}else
			{
				
				$countGA_query = tep_db_query("select parent_id,products_quantity,product_type,products_ordered FROM " . TABLE_PRODUCTS . "  WHERE  parent_id = '" . $cPath_end . "'");
				while ($result = tep_db_fetch_array($countGA_query)) 
				{
				$products_status=$result['products_status'];
				$product_type=$result['product_type'];
				$products_quantity=$result['products_quantity'];
				$products_ordered=$result['products_ordered'];
				}
				$status=0;
				//count seats reserved
				if (SUBCATEGORY_COUNT == 'reserved')
				{
				$status=0;
				$count_text=RESERVED;
				}
				if (SUBCATEGORY_COUNT == 'remaining')
				{
				$status=1;
				$count_text=REMAINING;
				}

				$count_query = tep_db_query("select 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 ($product_type=='P')
				{
				$count=$sub_count;
				} 
				elseif ($product_type=='G') 
				{	
					//count seats reserved
					if (SUBCATEGORY_COUNT == 'reserved')
					{
					$status=0;
					$count_text=RESERVED;
					$count= $products_ordered;
					}
					if (SUBCATEGORY_COUNT == 'remaining')
					{
					$status=1;
					$count_text=REMAINING;
					$count= $products_quantity;
					}
				}
			}
		
		
		if (($featured_categories['categories_image'] == 'NULL') or ($featured_categories['categories_image'] == '')) 
		{
		$cat_image="theatre.png";	
		}else{
		$cat_image=$featured_categories['categories_image'];
		}
		//Featured Buttons
		if(FEATURED_CATEGORY_BUTTONS=='yes')
		{
		$button="btn btn-primary";
		$featured_categories_content .= '
		<div class="col-lg-3 col-md-4 col-sm-6" style="text-align:center;border: red 0px solid;">
								<div class="featured-item">
									  <a class="' . $button . '" href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $featured_categories['categories_id']) . '">
									  <h2 style="font-size:14px">' . $heading_name . '</h2>
									  <h6>' . $formatted_date . '</h6>
									  <h6>' . $formatted_time . '</h6>
									  </a>
								</div>
								</div>
		';
		}
		else
		{
		$featured_categories_content .= '
		<div class="col-lg-3 col-md-4 col-sm-6">
		<div class="featured-item">
		<a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $featured_categories['categories_id']) . '">
		<img src="'.DIR_WS_IMAGES . $cat_image.'" alt="'.$heading_name.'" class="img-fluid  rounded">
		<div class="featured-overlay">
		<div class="featured-info">
		<h3>' . $heading_name . '</h3>
		<h5>' . $formatted_date . '</h5>
		<h5>' . $formatted_time . '</h5>
		</div>
		</div>
		</a>
		</div>
		<h6 class="fc_date">' . $heading_name . '</h6>
		<h6 class="fc_date">' . $formatted_date . '</h6>
		<h6 class="fc_date">' . $formatted_time . '</h6>
		</div>
		';
		}
		$col ++;
	}

if(SHOW_MAIN_FEATURED_CATEGORIES == 'true')
{ 
if(DISABLE_OVERLAY =='yes')
{
?>

<style>#featured .featured-overlay {opacity: 0;}</style>
<?php
}
//echo '<div class="text-center"><a class="btn btn-primary" href="search_events.php">Search</a></div><br>'; 
?>
<section id="featured">
<div class="container featured" data-aos="fade-up">
<div class="row gy-4">
<?php 
echo $featured_categories_content; 
?>

</div>
</div>
</section>
<?php
	}
}
else
{
echo "<h4 class=\"text-center\">";
echo TEXT_NO_FEATURED_CATEGORIES;
echo "</h4>";
}
?>