<?php
/**
 * Main Administrator Component File
 * This defines what controller to use and what task to execute.
 *
 * @package     NoNumber! Extension Manager
 * @version     1.4.0
 *
 * @author      Peter van Westen <peter@nonumber.nl>
 * @link        http://www.nonumber.nl
 * @copyright   Copyright (C) 2010 NoNumber! All Rights Reserved
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

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

// Load Language
// Loads English language file as fallback (for undefined stuff in other language file)
require_once JPATH_PLUGINS.DS.'system'.DS.'nonumberelements'.DS.'elements'.DS.'loadlanguage.php';
JElementLoadLanguage::loadLanguage( 'com_nonumbermanager' );

// Place install messages
$session =& JFactory::getSession();
$msgs = JRequest::getVar( 'msgs', '', 'default', 'none', 4 );
if ( $msgs != '' && !( strpos( $msgs, '<dl id="system' ) === false ) ) {
	$session->set( 'application.nn_msgs', $msgs );
	header('Location: index.php?option=com_nonumbermanager');
	exit;
}
echo $session->get( 'application.nn_msgs' );
$session->set( 'application.nn_msgs', '' );

// Version check
require_once JPATH_PLUGINS.DS.'system'.DS.'nonumberelements'.DS.'helpers'.DS.'versions.php';
$versions = NNVersions::instance();
$version = '';
$xml = JApplicationHelper::parseXMLInstallFile( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_nonumbermanager'.DS.'com_nonumbermanager.xml' );
if ( $xml && isset( $xml['version'] ) ) {
	$version = $xml['version'];
}
$versions->setMessage( $version, 'version_nonumbermanager', 'http://www.nonumber.nl/versions', 'http://www.nonumber.nl/nonumbermanager/download' );

// Set the controller page
require_once JPATH_COMPONENT.DS.'controllers'.DS.'default'.'.php';

// Create a new class of classname and set the default task: display
$controller = new NoNumberManagerController( array( 'default_task'=>'display' ) );

// Perform the Request task
$controller->execute( JRequest::getVar( 'task' ) );

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

echo '<p style="text-align:center;">'.JText::_( 'NoNumber! Extension Manager' );
if ( $version ) {
	echo ' v'.$version;
}
echo ' - Copyright (C) 2010 NoNumber! All Rights Reserved</p>';