<?php
add_action( 'vc_before_init', 'rockon_event_WITHVS' );
function rockon_event_WITHVS() {
   vc_map( array(
      "name" => __("Rockon Event",'rockon'),
      "base" => "rockon_event_shortchode",
      "class" => "",
      "category" => __('Content','rockon'),
      'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'),
      'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'),
      "params" => array(
		array(
            "type" => "textfield",
            "holder" => "div",
            "class" => "",
            "heading" => __("Title",'rockon'),
            "param_name" => "title",
            "value" => __("Event of the month",'rockon'),
            "description" => __("Title text Here.",'rockon')
         ),
		  array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Number Of Post",'rockon'),
            "param_name" => "no_of_post",
            "value" => array('6','12','18','24','30','36','42','48'),
            "description" => __("Choose no of post.",'rockon')
         ),
		 array(
            "type" => "dropdown",
            "holder" => "div",
            "class" => "",
            "heading" => __("Show Custom Post As",'rockon'),
            "param_name" => "event_look",
            "value" => array('simple','slider'),
            "description" => ''
         )
      )
   ) );
}
add_shortcode( 'rockon_event_shortchode', 'rockon_event_shortchode_func' );
function rockon_event_shortchode_func( $atts ) { // New function parameter $content is added!
   extract( shortcode_atts( array(
	  'title' => 'Title',	
	  'no_of_post' => '8',
	  'event_look' => 'simple',
   ), $atts ) );
   global $post;
   $i = 0;
   $result = $src = $date = $Ftime = $Ttime = $map = $ln_mon = '';
   if($event_look == 'simple'){
	   $result .= '<div class="row">
		<div class="col-lg-12 col-md-12 col-sm-12">';	
		$today = date('m/d/Y');
		$argrs = array(
			'post_type' => 'rockon_event',
			'meta_key'  => 'rockon_event_sysdate',
			'meta_query' => array(
				array(
					'key' => 'rockon_event_sysdate',
					'value' => $today,
					'compare' => '>='
				)
			),
			'orderby'   => 'meta_value',
			'order'     => 'ASC',
			'posts_per_page' => $no_of_post
		);
		$query = new WP_Query( $argrs );
		if($query->have_posts()):	
			while($query->have_posts()) : $query->the_post();
			$result .= '<div class="col-lg-6 col-md-6 col-sm-6">
			<div class="rock_main_event">
			  <div class="rock_main_event_image">';
				if (has_post_thumbnail($post->ID)){	
					$src = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) , 'full' );
					$thumb_w = '540';
					$thumb_h = '307';
					$image = aq_resize($src, $thumb_w, $thumb_h, true);
				}else{
					$image = ROCKON_PATH.'/images/no_image.jpg';
				}
				$date = get_post_meta( $post->ID, 'rockon_event_sysdate', true );
				$Ftime = get_post_meta( $post->ID, 'rockon_event_systimefrom', true );
				$Ttime =  get_post_meta( $post->ID, 'rockon_event_systimeto', true );
				$desc =  get_post_meta( $post->ID, 'rockon_event_sysdesc', true );
				$loc =  get_post_meta( $post->ID, 'rockon_event_sysloaction', true );
				$map =  get_post_meta( $post->ID, 'rockon_event_syscomma', true );
				//$map = explode(',',$map);
				global $rockon_data;
				if(isset($rockon_data['rockon_language']))
					setlocale(LC_TIME, $rockon_data['rockon_language']);
				$ln_mon = strftime("%B",strtotime($date));
			  $result .= '<img src="'.esc_url($image).'" alt="" /><div class="rock_main_event_image_overlay">
				</div>
			  </div>
			  <div class="rock_main_event_detail">
				<div class="rock_event_date">
				  <div class="event_date">
					<h1>'.date('d',strtotime($date)).'</h1>
					<p>'.esc_attr($ln_mon).'</p>
				  </div>
				</div>
				<h2><a href="'.esc_url(get_the_permalink($post->ID)).'">'.__(get_the_title($post->ID),'rockon').'</a></h2>
				<div class="blog_entry_meta">
				  <ul>
					<li><a href=""><i class="fa fa-clock-o"></i> '.esc_attr($Ftime).' - '.esc_attr($Ttime).'</a></li>
					<li><a href="'.esc_url('https://maps.google.com/maps?q='.$map).'" target="_blank"><i class="fa fa-map-marker"></i> '.__(esc_attr($loc),'rockon').'</a></li>
				  </ul>
				</div>
				<p>'.esc_attr($desc).'</p>
			  </div>
			</div>
		  </div>';
		  $i++;
			if($i%2 == 0){
				$result .= '<div class="clearfix"></div>';
			}
		  endwhile; 
		endif;
	   $result .= '</div></div>';	
   }else{
   $i = 0;
   $cls = 'class="active"';
   $today = date('m/d/Y');
	$argrs = array(
		'post_type' => 'rockon_event',
		'meta_key'  => 'rockon_event_sysdate',
		'meta_query' => array(
			array(
				'key' => 'rockon_event_sysdate',
				'value' => $today,
				'compare' => '>='
			)
		),
		'orderby'   => 'meta_value',
		'order'     => 'ASC',
		'posts_per_page' => $no_of_post
	);
	$query = new WP_Query( $argrs );
	 $result .= '<div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
          <div class="rock_heading_div">
            <div class="rock_heading">
              <h1>'.__(esc_attr($title),'rockon').'</h1>
              <p>X</p>
            </div>
          </div>
          <div class="rock_event">
            <div class="rock_event_tab">
              <ul>';
		if($query->have_posts()):	
			while($query->have_posts()) : $query->the_post();
				$date = get_post_meta( $post->ID, 'rockon_event_sysdate', true );
				global $rockon_data;
				if(isset($rockon_data['rockon_language']))
					setlocale(LC_TIME, $rockon_data['rockon_language']);
				$ln_mon = strftime("%B",strtotime($date));
                 $result .= '<li><a href="#tab'.$i.'" '.$cls.'>
                  <p class="rock_event_date">'.date('d',strtotime($date)).'</p>
                  <p class="rock_event_month">'.esc_attr($ln_mon).'</p>
                  </a></li>';
				  $i++;
				  $cls = '';
		   endwhile; 
		endif;
        $result .= '</ul>
            </div>';
		$i = 0;
		if($query->have_posts()):	
			while($query->have_posts()) : $query->the_post();
				$desc =  get_post_meta( $post->ID, 'rockon_event_sysdesc', true );
				$result .= '<div class="rock_event_tab_content_main">
					  <div id="tab'.$i.'" class="rock_event_tab_content">
						<div class="row">
						  <div class="col-lg-7 col-md-12 col-sm-12">'; 
				if (has_post_thumbnail($post->ID))
				{	
					$thumb = get_post_thumbnail_id($post->ID);
					$thumb_w = '674';
					$thumb_h = '487';
					$src = wp_get_attachment_url($thumb, 'full');
					$image = aq_resize($src, $thumb_w, $thumb_h, true);
					$result .= '<img class="animated fadeInLeft" src="'.esc_url($image).'" alt="">';
				}else{
					$result .= '<img src="'.ROCKON_PATH.'/images/no_image.jpg" class="rockon_nothumservices" class="animated fadeInLeft" alt="">';
				}
				$date = get_post_meta( $post->ID, 'rockon_event_sysdate', true );
				$Ftime = get_post_meta( $post->ID, 'rockon_event_systimefrom', true );
				$Ttime =  get_post_meta( $post->ID, 'rockon_event_systimeto', true );
				$loc =  get_post_meta( $post->ID, 'rockon_event_sysloaction', true );
				$map =  get_post_meta( $post->ID, 'rockon_event_syscomma', true );
				$result .= '</div>
						  <div class="col-lg-5 col-md-12 col-sm-12">
							<div class="rock_event_detail animated fadeInLeft">
							  <h1><a href="'.esc_url(get_the_permalink($post->ID)).'">'.__(get_the_title($post->ID),'rockon').'</a></h1>
							  <p>'.esc_attr($desc).'</p>
							  <div class="blog_entry_meta">
							  <ul>
								<li><a href=""><i class="fa fa-clock-o"></i> '.esc_attr($Ftime).' - '.esc_attr($Ttime).'</a></li>
								<li><a href="'.esc_url('https://maps.google.com/maps?q='.$map).'" target="_blank"><i class="fa fa-map-marker"></i> '.__(esc_attr($loc),'rockon').'</a></li>
							  </ul>
							</div>
							</div>
						  </div>
						</div>
					  </div>
					</div>';
			$i++;
		  endwhile; 
		endif;
      $result .= '<div class="clearfix"></div>
          </div>
        </div>
      </div>';
   }
   return $result;   
}
?>