<?php
/**
 * @version		3.0.0
 * @package		JomLand TicketCenter
 * @copyright	Copyright (C) 2010 JomLand.com. All rights reserved.
 * @license		GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

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

class JLTicketCenterViewEvents extends JViewLegacy
{

	function display($tpl = null)
	{
		$mainframe = JFactory::getApplication();

		$task =  JRequest::getVar('task');

		if ($task=='guest'){
			$this->guest($tpl);
		}

		if ($task=='csv'){
			$this->csv($tpl);
		}
		
		if ($task=='deleteTicket'){
			$this->deleteTicket($tpl);
		}
	}


	private function guest($tpl){

		$app = JFactory::getApplication();

		$pparams = new JLTicketCenterHelperSetup;

		$tickets = $this->get('GuestList');

		$this->assignRef('tickets',$tickets);
		$this->assignRef('params', $pparams);

		$this->setLayout('guest_list');

		parent::display($tpl);
	}

	private function csv(){

		$app = JFactory::getApplication();

		$pparams = new JLTicketCenterHelperSetup;

		$tickets = $this->get('GuestList');

		if(empty($tickets)){
			echo "No tickets found";
			return;
		}

		if(file_exists(JPATH_ADMINISTRATOR.'/components/com_jlticketcenter/helpers/jlticketcenter_pro_helper.php')){
			JLoader::import('components.com_jlticketcenter.helpers.jlticketcenter_pro_helper',JPATH_ADMINISTRATOR);
			JLTicketCenterPro::orderCSV($tickets,$pparams );
		}

		die;
	}


	function deleteTicket(){
		$ticket_line_id = JRequest::get();
		
		$tickets_model = JModelLegacy::getInstance('EventsTicketsType','JLTicketCenterModel');
		if ($tickets_model->deleteLine($ticket_line_id['id'])){
			echo 'true';
		}else{
			echo 'false';
		}
		
		
	}


}//EOC