<?php
/**
 * @package BILLETS
 * @link 	http://www.dioscouri.com
 * @license GNU/GPLv2
 */
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

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

/**
* 	BilletsController
*/
// ************************************************************************
class BilletsControllerTickets extends BilletsController {

	var $_type;
	var $_status;	
			
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct() {
		parent::__construct();
		global $mainframe;
		
		// set the type
		$this->_type = strval( htmlspecialchars( $mainframe->getUserStateFromRequest( "type", 'type', ' ' ) ) );

		// set the status
		$this->_status = strval( htmlspecialchars( $mainframe->getUserStateFromRequest( "status", 'status', 'open' ) ) );
				
		// Register Extra tasks
		$this->registerTask( 'view', 'view' );
		$this->registerTask( 'followup', 'followup' );
		$this->registerTask( 'nofollowup', 'followup' );
	}

	/**
	 * display 
	 * @return void
	 */
	function display() {
		JRequest::setVar( 'view', 'tickets' );
		JRequest::setVar( 'layout', 'default'  );

		parent::display();

	}

	/**
	 * display the ticket
	 * @return void
	 */
	function view() {
		JRequest::setVar( 'view', 'ticket' );
		JRequest::setVar( 'layout', 'default'  );
		parent::display();
	}

	/**
	 * change published value
	 * @return void
	 */
	function followup() {
		// JRequest::checkToken() or jexit( 'Invalid Token' );
		$model = $this->getModel( 'ticket' );
		$link = 'index.php?option='._THISCOMPONENT.'&controller=tickets&type='.$this->_type;
		
		if($model->followup()) {
			$msg = JText::_( _BILLETS_TICKET." '"._BILLETS_FOLLOWUP."' "._BILLETS_STATUS." "._BILLETS_CHANGED );
			$type = 'message';
		}
		else
		{
			$msg = JText::_( _BILLETS_TICKET." '"._BILLETS_FOLLOWUP."' "._BILLETS_STATUS." "._BILLETS_NOT." "._BILLETS_CHANGED )." - " .$model->getError();
			$type = 'error';
		}
		$this->setRedirect( JRoute::_( $link, false ), $msg, $type );
	}
		

	    
}
// ************************************************************************

?>