<?php
/**
* @version		3.0.0
* @package		JomLand TicketCenter
* @copyright	Copyright (C) 2010 JomLand.com. All rights reserved.
* @link 		www.jomland.com
* @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

class JLTicketCenterViewEvent extends JViewLegacy
{
	public function display(){
		$task = JRequest::getVar('task','outputJson');

		if ($task=='outputJson'){
			self::outputJson();
		}
	}
	
	public function outputJson(){
		$events_json  = array();

		$session = JFactory::getSession();
		$events  = $session->get('JLTC_events');
		$itemid = $session->get('JLTC_Itemid');
		if (!empty($events)){
			foreach ($events as $event){
				$this_event = array();
				
				$this_event['id'] =  $event->id; 
				$this_event['title'] =  $event->event_name;//;//->format('H:i');
				$this_event['start'] =  str_replace(' ', 'T', $event->event_date);
				if ($event->event_end > '0000-00-00 00:00:00'){
					$this_event['end'] =$event->event_end;  
				}
				$this_event['url'] =  JROUTE::_('index.php?option=com_jlticketcenter&view=tickets&id='.$event->id.'&Itemid='.$itemid,false);
				$this_event['allDay'] =  false;
				
				$events_json[] = $this_event;
			}
		}
		
		//$session->clear('JLTC_events');
		//$session->clear('JLTC_Itemid');
		
		echo json_encode($events_json);
		die;
	}
} // EOC VIEW