<?php
/**
 * @package BILLETS
 * @link 	http://www.dioscouri.com
 * @license GNU/GPLv2
 */

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

// Component Definitions
DEFINE("_BILLETS_DSCVERSION", '1.0');
DEFINE("_THISCOMPONENT", $option);
DEFINE("_THISCOMPONENTNAME", substr ( _THISCOMPONENT, 4 ) );

// include stylesheet and script
JHTML::_('stylesheet', _THISCOMPONENTNAME.'.css', 'components/'._THISCOMPONENT.'/assets/css/');
JHTML::_('script', _THISCOMPONENTNAME.'.js', 'components/'._THISCOMPONENT.'/assets/js/');

// include the language file
if (file_exists(JPATH_COMPONENT_SITE.DS.'languages'.DS.$lang->getBackwardLang().'.php')) {
      include_once(JPATH_COMPONENT_SITE.DS.'languages'.DS.$lang->getBackwardLang().'.php');
} else {
      include_once(JPATH_COMPONENT_SITE.DS.'languages'.DS.'english.php');
}

// Require the base controller
require_once( JPATH_COMPONENT_SITE.DS.'controller.php' );

// Require the base class
require_once( JPATH_COMPONENT_SITE.DS._THISCOMPONENTNAME.'.class.php' );

// Require specific controller if requested
if($controller = JRequest::getWord('controller')) {
    $path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
    if (file_exists($path)) {
        require_once $path;
    } else {
        $controller = '';
    }
}

// Create the controller
$classname    = 'BilletsController'.$controller;
$controller   = new $classname( );

$user 	= &JFactory::getUser();
if ($user->id != 0) {
	// Perform the requested task
	$controller->execute( JRequest::getVar( 'task' ) );
} else {
	$link = 'index.php';
	$msg = JText::_( _BILLETS_PLEASELOGINFIRST );
	$controller->setRedirect( $link, $msg, 'notice' );
}

// Redirect if set by the controller
$controller->redirect();

?>