<?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 BilletsControllerAddons extends BilletsController {

	var $_type;
			
	/**
	 * 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', 'lang' ) ) );
		
		// Register Extra tasks
		$this->registerTask( 'unpublish', 'publish' );
		$this->registerTask( 'uploadaddon', 'uploadAddon' );		
		$this->registerTask( 'uninstall', 'uninstallAddon' );
	}

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

		parent::display();

	}

	/**
	 * display the editsource form
	 * @return void
	 */
	function edit() {
		JRequest::setVar( 'view', 'addon' );
		JRequest::setVar( 'layout', 'editsource'  );
		// JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

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

	/**
	* uploadAddon
	*/
	// ************************************************************************	
	function uploadAddon( ) {
		// JRequest::checkToken() or jexit( 'Invalid Token' );
		$model = $this->getModel( 'addons' );
		$link = 'index.php?option='._THISCOMPONENT.'&controller=addons&type='.$this->_type;
		
		if($model->uploadAddon()) {
			$msg = JText::_( _BILLETS_ADDONINSTALLED );
			$type = 'message';
		} else {
			$msg = JText::_( _BILLETS_ADDONINSTALLFAILED )." - " .$model->getError();
			$type = 'error';
		}
		$this->setRedirect( JRoute::_( $link, false ), $msg, $type );

	} // end uploadAddon
	// ************************************************************************	

	/**
	* uploadAddon
	*/
	// ************************************************************************	
	function uninstallAddon( ) {
		// JRequest::checkToken() or jexit( 'Invalid Token' );
		$model = $this->getModel( 'addons' );

		// $link = 'index.php?option='._THISCOMPONENT.'&controller=addons&type='.$this->_type;
		
		$model->uninstallAddon();
		
		// $this->setRedirect( JRoute::_( $link, false ), $msg, $type );

	} // end uninstallAddon
	// ************************************************************************	
		
	    
}
// ************************************************************************

?>