<?php

/*

Template Name: Events Page

*/

session_start();

$months = array(

    'January',

    'February',

    'March',

    'April',

    'May',

    'June',

    'July ',

    'August',

    'September',

    'October',

    'November',

    'December',

);

$today = date('Y-m-d');

$args = array(

    'post_type' => 'events_block',

    'posts_per_page' => -1,

   'meta_key' => 'st_date', //name of meta field

   'orderby' => 'meta_value', 

   'order' => 'DESC', // you can modify it as per your use

   'meta_query' => array(

		array(

			'key'       => 'st_featured',

			'value'     => 1,

			)

		)

);

$featured_events = get_posts( $args );

$args2 = array(

    'post_type' => 'events_block',

    'posts_per_page' => -1,

   'meta_key' => 'st_date', //name of meta field

   'orderby' => 'meta_value', 

   'order' => 'DESC', // you can modify it as per your use

   'meta_query' => array(

		array(

			'key'       => 'st_date',

			'value'     => $today,

            'compare' => '>='

			)

		)

);

$upcoming_events = get_posts( $args2 );

$title2 = get_the_title();

$title2 = str_replace('<br>','',$title2);

$parent_id = wp_get_post_parent_id(get_the_ID());

$parent_meta = get_post_meta($parent_id);

$st_banner = $parent_meta['st_banner'][0];

$banner_url = wp_get_attachment_url( $st_banner, 'full' );

if($banner_url == '')

	$banner_url = 'images/banners/subBanner.jpg';

$categories=get_categories(

    array( 'child_of' => 10,'orderby' => 'slug' )

);

?>

<!DOCTYPE html

	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

	<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0" />

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<meta prefix="og: http://ogp.me/ns#" property="og:image"

		content="https://imas.org.sg/banner.jpg" />

	<meta name="format-detection" content="telephone=no">

	<title><?php echo get_bloginfo( 'name' ); ?></title>

	

	<base href="<?php echo get_template_directory_uri(); ?>/">

		

	<link rel="Shortcut Icon" href="images/favicon.ico" type="image/x-icon" />

	<link rel="Bookmark" href="images/favicon.ico" type="image/x-icon" />

	<link rel="icon" href="images/favicon.ico" type="image/x-icon" />

	<link href="css/conferenceFont.css" rel="stylesheet" type="text/css" />

	<link href="css/iconfont.css" rel="stylesheet" type="text/css" />

	<link href="css/layout.css" rel="stylesheet" type="text/css" />

	<link href="css/nav.css" rel="stylesheet" type="text/css" />

	<link href="css/template.css" rel="stylesheet" type="text/css" />

	<link href="css/cont.css" rel="stylesheet" type="text/css" />

	

	

	<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>

	<link href="js/gallery/jquery.fancybox.css" rel="stylesheet" type="text/css" />

	<script type="text/javascript" src="js/gallery/jquery.fancybox.min.js"></script>

	<script type="text/javascript" src="js/default.js"></script>

	  <?php wp_head(); ?>

	  <style>

	

		i.blue {

			color:#007dc5;

			font-weight:normal

		}

		

		.filtering {

			display: inline-block;

			padding:8px 25px;

			color:#fff;

			background-color: #c6c8ca;

			margin-right: 10px;

		}

		

		.selected {

			background-color: #000;

			color:#fff;

		}	

		 

		  #eventlisting {

			  margin-bottom: 60px;

		  }

		  

		  .filterRow {

			  margin: 0px;

			  margin-bottom: 30px;

		  }

		  

		  .eventBox {

			  margin: 5px;

		  }		 

		  

		  @media (max-width: 768px) {

			  

			  .filtering, {

				  padding:4px 10px;

				  margin-bottom: 10px;

			  }

		  }

	  </style>

	 

<?php include_once('ga.php'); ?></head>

<body class="subPage">

	<?php include_once('h.php'); ?>

	<div class="subBanner" style="background-image: url(<?php echo $banner_url; ?>);">

		<div class="bannerShadow"></div>

		<div class="wideContainer">

			<div class="container">

				<div class="content">

					<h3>

						<?php echo $title2; ?>

					</h3>

				</div>

			</div>

		</div>

	</div>

	

	<div class="subPageWrap">

		<div class="subPageColumnWrap container">

			<div class="column left">

	

				<?php include_once('sidebar_nav.php'); ?>

			</div>

			<div class="column main">

				<div class="column center">

					<div class="breadcrumb"><?php echo breadcrumb_gen(get_the_ID());?></div>

					<h2 class="ptitle"><?php echo $title2; ?></h2>					

					<div class="page-cont">

						

               <div class="">

			<div class="eventList">

					<?php foreach($featured_events as $f): ?>

					<?php

					$url = wp_get_attachment_url( get_post_thumbnail_id($f->ID), 'full' );

					

					

					$post_meta = get_post_meta($f->ID);

						

					$date = $post_meta['st_date'][0];

					$date = date('j M Y',strtotime($date));

					$link = get_permalink($f->ID);

					

					$banner_url = '';

					$st_banner = $post_meta['st_image'][0];

					$banner_url = wp_get_attachment_url( $st_banner, 'full' );

					

					if($banner_url != '')

						$url = $banner_url;

					

					?>

					<div class="row">

						<div class="fullwidth">

							<div class="eventBox featured">

								<div class="inner1">

									<a href="<?php echo $link;?>"><img src="<?php echo $url; ?>"></a>

								</div>

								<div class="inner">

									<h3 class="ellipsisLines2"><a href="<?php echo $link;?>"><?php echo ($f->post_title); ?></a></h3>

									<div class="txt ellipsisLines3"><?php echo $f->post_excerpt; ?></div>

									<div class="date"><strong><?php echo $date; ?></strong></div>

									<a href="<?php echo $link;?>" class="btnEnter btnCube btnSmall"><i class=" icon-arrow-right"></i></a>

								</div>

								<br clear="all">

							</div>

						</div>

						

					</div>

					<?php endforeach; ?>

				</div>

			<div class="filterRow">

				<div class="row">

					<div class="container">

						<div class="col-lg-12">

							<br>

								<input type="hidden" name="selected_ids" id="selected_ids">

						<div class="filtering selected" id="fALL" onClick="show_all();return false;">ALL</div>	

	<span class="btnFilter" id="upcoming_btn" onClick="upcoming();">Upcoming</span>

							<span class="btnFilter" id="past_btn" onClick="past();">Past</span>						

						<?php foreach($categories as $cc): ?>

						<div class="filtering" id="f<?php echo $cc->term_id;?>" onClick="select_div('f<?php echo $cc->term_id;?>');return false"><?php echo $cc->name; ?></div>

						<?php endforeach; ?>

						<br clear="all">

						<br clear="all">						

						

							<select class="year" id="year_field" onChange="select_date();">

								<option value="">Year</option>

								<?php for($i=date('Y');$i>date('Y')-18;$i--): ?>

								<option value="<?php echo $i; ?>"><?php echo $i; ?></option>

								<?php endfor ;?>

							</select>

							<select class="ymonthear" id="month_field" onChange="select_date();">

								<option value="">Month</option>

								<?php foreach($months as $key=>$b): ?>

								<option value="<?php echo $key+1; ?>"><?php echo $b; ?></option>

								<?php endforeach ;?>

							</select>

							<input type="hidden" id="showall" value="1">

							<input type="hidden" id="upcoming" value="0">

							<input type="hidden" id="past" value="0">

							<input type="hidden" id="year">

							<input type="hidden" id="month">

						</div>

					</div>

				</div>

			</div>

			<div class="container">

			

			

				<div id="eventlisting"></div>

				

				<div class="eventList eventList2">

				

	       			</div>

				</div>

			</div>

		</div>

					</div>

				</div>

			</div>

		</div>

	</div>

	<div id="footerWrap">

		<div class="wideContainer">

	

			<div class="linksWrap">

				<div class="container">

					<div class="row">

						<div class="col-lg-2 col-md-12">

							<div class="logo">

								<a href="http://www.imas.org.sg" target="_blank">

									<img src="images/imaslogo.png" />

								</a>

							</div>

						</div>

						<div class="col-lg-2 col-md-6 footer_link">

						<?php if ( is_active_sidebar( 'footer-1' ) ): ?>

						<?php dynamic_sidebar( 'footer-1' ); ?>

						<?php endif; ?>

						</div>

						<div class="col-lg-2 col-md-6 footer_link">

						<?php if ( is_active_sidebar( 'footer-2' ) ): ?>

						<?php dynamic_sidebar( 'footer-2' ); ?>						

						<?php endif; ?>

						</div>

	

						<div class="col-lg-2 col-md-6 footer_link">

						<?php if ( is_active_sidebar( 'footer-3' ) ): ?>

							<?php dynamic_sidebar( 'footer-3' ); ?>

						<?php endif; ?>

						</div>

						

						<div class="col-lg-2 col-md-6">

							<h5><span>Contact Us</span></h5>	

							<?php $address = get_custom('address'); ?><?php echo nl2br($address); ?><br /><br><b>Email:</b> <a href="mailto:enquiries@imas.org.sg">enquiries@imas.org.sg</a><br>

							<b>Tel:</b> +65 6223 9353<br />

							<b>Fax:</b> +65 6223 9352

						</div>

					</div>

				</div>

			</div>

	

			<div class="copyright">

				<div class="txt"><?php echo get_custom('footer_copyright') ; ?></div><div class="floatRight ">

     		  <?php if ( is_active_sidebar( 'footer-4' ) ): ?>

							<?php dynamic_sidebar( 'footer-4' ); ?>

						<?php endif; ?>

     		  

      		      </div>

			</div>

	

	

		</div>

	</div>

   

	<link href="css/custom.css" rel="stylesheet" type="text/css" />

  	<script>

	

	var $j = jQuery.noConflict();

		

	 var page = 0;	

	var arr = [];

	 function show_all()

	 {

		 $j('#upcoming').val(0);		 

		 $j('#past').val('');	 

		 $j('#showall').val(1);

		$j('#upcoming_btn').removeClass('active');

		$j('.filtering').removeClass('selected');

		$j('#past_btn').removeClass('active');

		$j('#fALL').addClass('selected');

		 $j('#selected_ids').val('');

		$j('#year_field').val('');

		$j('#month_field').val('');

		$j('#year').val('');

		$j('#month').val('');

		 get_events();

	 }

	 function select_div(id)
	 {			 

	 
		$j('#eventlisting').html('');
		$j('#showall').val(0);

		$j('.filtering').removeClass('selected');

		$j('#upcoming_btn').removeClass('active');

		$j('.filtering').removeClass('selected');

		$j('#past_btn').removeClass('active');

		$j('#'+id).addClass('selected');

		$j('#'+id).addClass('selected1');

		$j('#past').val(0);

		 

		 id = id.replace('f','');

		 $j('#selected_ids').val(id);

		 get_events(1);

		 

	 }

	

	function upcoming()

	{		

		$j('#showall').val(0);

		$j('#upcoming').val(1);

		$j('.filtering').removeClass('selected');

		$j('#past').val('');

		$j('#upcoming_btn').addClass('active');

		$j('#past_btn').removeClass('active');		

		$j('#fALL').removeClass('selected');

		$j('#selected_ids').val('');

		$j('#year_field').val('');

		$j('#month_field').val('');

		$j('#year').val('');

		$j('#month').val('');

		get_events();

		

	}

		

	

	function past()

	{		

		$j('#showall').val(0);

		$j('#upcoming').val('');

		$j('.filtering').removeClass('selected');

		$j('#past').val(1);

		$j('#past_btn').addClass('active');

		$j('#upcoming_btn').removeClass('active');	

		$j('#fALL').removeClass('selected');		

		$j('#eventlisting').html('');

		$j('#selected_ids').val('');

		get_events();

		$j("html, body").animate({ scrollTop: 0 }, "fast");



	}

		

	function select_date()

	{

		$j('.eventList2').html('');

		$j('#upcoming_btn').removeClass('active');

		$j('#past_btn').removeClass('active');

		$j('#upcoming').val('');

		$j('#past').val('');

		$j('#upcoming').val('');

		$j('#past').val('');

		$j('#year').val('');

		$j('#month').val('');

		

		var year = $j('#year_field').val();

		$j('#year').val(year);

		var month = $j('#month_field').val();

		$j('#month').val(month);

		

		get_events();

	}

		

function get_events(clear='',page='')

{

	if(page == 2)

		$j('#upcoming_btn1').hide();

	

	if(page == '')

		page = 1;

	

	if(clear != 1)
	{

		page = 1; 

		$j('#eventlisting').html('');

	}

	

	var upcoming = $j('#upcoming').val();

	var past = $j('#past').val();

	var year = $j('#year').val();

	var month = $j('#month').val();

	var selected_ids = $j('#selected_ids').val();

	var showall = $j('#showall').val();

	

	

	$j.post( "<?php echo home_url();?>/get_events.php", { page:page, upcoming: upcoming, past: past, year: year, month: month,selected_ids: selected_ids,showall: showall })

	  .done(function( data ) {

		

		if(data != '')

		{

		

			$j('#eventlisting').append(data);	

		}

		

		

	  },"json");

		

}

		

	


if(window.location.hash) {
  // Fragment exists
	
 $j('#eventlisting').html('');
  var h = window.location.hash;

   if(h == '#conference')
	select_div('f11');

   if(h == '#digital_summit')
	select_div('f24');

} else {
	
	get_events();		
}

	</script>

    <?php wp_footer(); ?>

</body>

</html>