<?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();
        
if ( (!isset($featured_categories_category_id)) || ($featured_categories_category_id == '0') ) 
	{		
	// $featured_categories_query = tep_db_query("select c.categories_status, c.manufacturers_id, c.categories_id, cd.categories_name,cd.categories_heading_title, c.categories_image, c.parent_id, cd.categories_description, cd.concert_venue,cd.concert_date,cd.concert_time,c.date_id 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 sort_order, cd.categories_id");
	// }
	//We get the actual server date
		$serverDate = date(EVENTS_DATE_FORMAT,getServerDate(false));
		$expires=" and cd.concert_date >'" . $serverDate . "' ";
	
	$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' ".$expires." ".$page." and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$FSESSION->languages_id . "' order by sort_order, cd.categories_id");
	}

  $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'];	
		$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'];
		}
		
		$featured_categories_content .= '
		  <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']) . '">' . 
						tep_image(DIR_WS_IMAGES . $cat_image, $featured_categories['categories_name'], '', '') . 
					'<div class="featured-overlay">
				  <div class="featured-info"><h2 class="wow fadeInUp">' . $featured_categories['categories_name'] . '</h2></div>
				</div>
			</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 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>";
  }
?>