<?php
defined('_JEXEC') or die('Restricted access');

JevHtmlBootstrap::framework();
if (JevJoomlaVersion::isCompatible("3.0") || JComponentHelper::getParams(JEV_COM_COMPONENT)->get("fixjquery", 1))
{
	JEVHelper::script("components/com_jevents/assets/js/jQnc.js");
	// this script should come after all the URL based scripts in Joomla so should be a safe place to know that noConflict has been set
	JFactory::getDocument()->addScriptDeclaration("checkJQ();");
}

JHTML::stylesheet("com_jevents/bootstrap.css", array(), true);
JHTML::stylesheet("com_jevents/bootstrap-responsive.css", array(), true);
JHTML::stylesheet("components/com_jevents/assets/css/jquery.resizableColumns.css");
JEVHelper::script("components/com_jevents/assets/js/store.min.js");
//JEVHelper::script("components/com_jevents/assets/js/jquery.resizableColumns.min.js");
JEVHelper::script("components/com_jevents/assets/js/jquery.resizableColumns.js");

$data = $this->data;

$Itemid = JEVHelper::getItemid();
$compparams = JComponentHelper::getParams("com_jevents");

$app = JFactory::getApplication('site');
$params = $app->getParams();
$active = $app->getMenu()->getActive();
if ($active)
{
	$params->merge($active->params);
}

$infields = explode("||", $compparams->get("columns", "TITLE_LINK|Title Link|Title"));
$cols = array();
$titles = array();
foreach ($infields as $infield)
{
	$parts = explode("|", $infield);
	$cols[] = $parts[0];
	$titles[] = $parts[2];
}
if(JRequest::getVar('type')) {
	$tab_default = JRequest::getVar('type');
} else {
	$tab_default = 'upcoming';
}

?>
<div class="tabs">
	<ul class="nav">

		<li class="tab <?php if('upcoming'==$tab_default) echo 'active';?>" rel="upcoming">
			<a href="#"><i class="fa fa-cube"></i>Upcoming</a>
		</li>

		<li class="tab <?php if('happening'==$tab_default) echo 'active';?>" rel="happening">
			<a href="#"><i class="fa fa-bookmark"></i>Happening</a>
		</li>

		<li class="tab <?php if('expired'==$tab_default) echo 'active';?>" rel="expired">
			<a href="#"><i class="fa fa-user"></i>Expired</a>
		</li>

	</ul>
</div>
<div class="lists_event">
	<div class="row">
		<?php
		$template = "";
		foreach ($cols as $col)
		{
			$template .= "<div class='eventlist_col ".$col."'>{{xx:$col}}</div>";
		}
//var_dump($data['rows'][0]);
		$items = $data['rows'];
		for($i=0;$i<count($items);$i++) {
			//var_dump($items[$i]);
			$str_begin = strtotime($items[$i]->_startrepeat);
			$str_end = strtotime($items[$i]->_endrepeat);
			$str_now = strtotime(date("F j, Y, g:i a"));
			//echo $str_now;
			if($str_now<$str_begin) {
				$str = 'upcoming';
			} elseif($str_now>=$str_begin && $str_now<=$str_end) {
				$str = 'happening';
			} elseif($str_now>$str_end){
				$str = 'expired';
			}
			$arr_images = "";
			preg_match_all('/(<img[^>]+>)/i',$items[$i]->_description,$arr_images);
			//var_dump($arr_images[0]);
			?>
			<div class="col-md-4 col-sm-6 col-xs-12 <?php echo $str;?> item <?php if($str==$tab_default) echo 'active';?>">
				<div class="">
					<div class="inner">
						<div class="thumb">
							<?php if(count($arr_images[0])) echo $arr_images[0][0];?>
						</div>
						<h2>
							<?php
							//[ob_countdown date="2016-09-17 15:44:33"]
							$rowlink = $items[$i]->viewDetailLink($items[$i]->yup(), $items[$i]->mup(), $items[$i]->dup(), false);
							?>
							<a href="<?php echo JRoute::_($rowlink); ?>"><?php echo $items[$i]->_title;?></a>
						</h2>
						<div class="description">
							<?php echo strip_tags($items[$i]->_description);?>
						</div>
						<div class="info clear">
							<div class="day">
								<span><?php echo date("d", strtotime($items[$i]->_startrepeat));?></span><?php echo date("M", strtotime($items[$i]->_startrepeat));?>
							</div>
							<div class="time clear">
								<span class="timer">
									<i class="fa fa-clock-o" aria-hidden="true"></i>
									<?php echo date("H:s", strtotime($items[$i]->_startrepeat));?> - <?php echo date("H:s", strtotime($items[$i]->_endrepeat));?>
								</span>
								<span class="location">
									<i class="fa fa-map-marker"></i>
									<?php echo $items[$i]->_location;?>
								</span>
							</div>
						</div>
					</div>
				</div>
			</div>
			<?php
		}

		?>
	</div>
</div>
<script>
	(function ($) {
		$("table.eventlist").resizableColumns(
			{store: window.store}
		);
	})(jevjq);
</script>

