<?php
/*
  osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

	Freeway eCommerce
	http://www.openfreeway.org
	Copyright (c) 2007 ZacWare
	
Featured Categories for osConcert by cartZone UK 
Copyright (c) 2009-2014 osConcert
	
Released under the GNU General Public License 
*/

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

	// $SERVER_DATE_TIME = getServerDate(true);
	// $serverDate = date(EVENTS_DATE_FORMAT,getServerDate(false));
	// $categories_expiry_query = tep_db_query("select * from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status > '0' and cd.concert_date>".$serverDate." and c.categories_id = cd.categories_id");
	// $expiry=$serverDate;
	// if($expiry<$SERVER_DATE_TIME)
	// {
		// tep_change_category_status_off($category_id);
	// }


	
	 if (isset($_GET['date_start_unix']) && is_numeric($_GET['date_start_unix']) && $_GET['date_start_unix'] > 0){
		 $start   =  " and cd.concert_date_unix >= '" . $_GET['date_start_unix']."' ";
		 $start_text = "From ". $_GET['date_start'];
		 
	 }else{
		 //$messageStack->add('featured_categories_bydate',TEXT_NO_FEATURED_CATEGORIES_START);
		 //echo $messageStack->output('featured_categories_bydate'); 
		 $start = "";
		 $start_text = "All events ";
	 }
	 
	 if (isset($_GET['date_end_unix']) && is_numeric($_GET['date_end_unix']) && $_GET['date_end_unix'] > 0)
	 {
		 $end   = " and cd.concert_date_unix <= '" . $_GET['date_end_unix'] ."' ";
		 $end_text = " to " . $_GET['date_end'];
	 }else
	 {
		 $end = "";
		 $end_text = "";
	 }
	 
	 
	$unix = $_SERVER['REQUEST_TIME'];
	
	//$serverDate = date(EVENTS_DATE_FORMAT,getServerDate(false));
	$expires=" and cd.concert_date_unix >'" . $unix . "' ";
	
	$page=" and c.parent_id = '" . (int)$current_category_id . "'";
	//$page="";
	$featured_categories_query = tep_db_query("select * from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status > '0' " . $start . $end .  " ".$expires." ".$page." and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$FSESSION->languages_id . "' order by cd.concert_date_unix");
	
  $num_featured_categories = tep_db_num_rows($featured_categories_query);

  if ($num_featured_categories > 0) 
  {
    $counter = 0;
    $col = 0;
	
	while ($featured_categories = tep_db_fetch_array($featured_categories_query)) 
	{
		$categories_description = $featured_categories['categories_description'];
		
		$date = strtotime($featured_categories['concert_date']);
		$concert_date=date(EVENTS_DATE_FORMAT, $date);
		
		$categories_description = ltrim(substr($categories_description, 0, 75) . '...'); //Trims and Limits the desc
		$counter++;

		if (($featured_categories['categories_image'] == 'NULL') or ($featured_categories['categories_image'] == '')) 
		{
			$cat_image="theatre.png";
		}else{
			$cat_image=$featured_categories['categories_image'];
		}
		$button="btn btn-primary";
		$featured_categories_content .= '

		  
		  <div class="col-lg-3 col-md-4" 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']) . '">' . $concert_date . '</a>
			</div>
			</div>
			';
		$col ++;
	}

	if(SHOW_MAIN_FEATURED_CATEGORIES == true)
	{
	?>
	<?php if(DISABLE_OVERLAY=='yes')
	{
	?>
	<style>
	#featured .featured-overlay {
	display:none;
	}
	</style>
	<?php
	}
	?>
	<section id="featured" class="wow fadeInUp">
	<div class="container">
	<div class="container-fluid">
	<div class="row"><h3>
	 <?php 
	echo $start_text . $end_text; 
	?>
	</h3>
	</div>
	<div class="row no-gutters">
    <?php 
	echo $featured_categories_content; 
	?>
	</div>
	</div>
	</div>
	</section>
	<?php
	}
	?>
 
  <?php
  }
  else
  {
	echo "<p style=\"text-align:center\">";
	echo TEXT_NO_FEATURED_CATEGORIES;
	echo "</p>";
  }
?>
		  <!--<div class="col-lg-3 col-md-4">
			<div class="featured-item wow fadeInUp" rel="show_hide_'.$featured_categories['manufacturers_id'].'">
			  <a href="' . tep_href_link(FILENAME_DEFAULT, 'cPath=' . $featured_categories['categories_id']) . '"><div class="featured-overlay">
				  <div class="featured-info"><h2 class="wow fadeInUp">' . $featured_categories['concert_date'] . '</h2></div>
				</div>
			</a>
			</div>
		  </div>-->