<?php
/**
 * NoNumber! Extension Manager Form View Template
 *
 * @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' );

// Import modal
JHTML::_( 'behavior.modal' );
// Import html tooltips
JHTML::_( 'behavior.tooltip' );

$model =& $this->getModel();

$exts = array();
foreach( $model->extensions as $alias => $extension ) {
	if ( $alias != 'all' ) {
		$exts[] = "{ name: '".$extension->name."', id: '".$extension->id."', alias: '".$extension->alias."' }";
	}
}

$document =& JFactory::getDocument();
$document->addScript( JURI::root( true ).'/administrator/components/com_nonumbermanager/js/script.js' );
$script= "
	var nn_extensions = [ ".implode( ', ', $exts )." ];

	window.addEvent( 'domready', function() {
		nnManager.load_extensions();
	});

	/* NoNumber! Extension Manager language strings */
	var NN_NONESELECTED =			'".JText::_( 'No Items selected' )."';
	var NN_AREYOUSURE =				'".JText::_( 'Are you sure?' )."';
	var NN_UPTODATE =				'".JText::_( 'Already up-to-date' )."';
	var NN_DOWNGRADE =				'".JText::_( 'Downgrade' )."';
	var NN_INSTALLING =				'".JText::_( 'Installing' )."';
	var NN_UPDATING =				'".JText::_( 'Updating' )."';
	var NN_REINSTALLING =			'".JText::_( 'Reinstalling' )."';
	var NN_DOWNGRADING =			'".JText::_( 'Downgrading' )."';
	var NN_MAYTAKEAWHILE =			'".JText::_( 'may take a while' )."';
	var NN_EXTENSIONSINSTALLED =	'".JText::_( 'Extensions installed' )."';
	var NN_CLEANCACHE =				'".JText::_( 'Clean cache' )."';
	var NN_EXTENSIONSUPDATED =		'".JText::_( 'Extensions updated' )."';
	var NN_INSTALLATIONFAILED =		'".JText::_( 'Installation failed' )."';
	var NN_DESCRIPTION =			'".JText::_( 'Description' )."';
	var NN_CHANGELOG =				'".JText::_( 'Changelog' )."';
	var NN_TOKEN =					'".JUtility::getToken()."';
";
$document->addScriptDeclaration( $script );

echo JText::_( 'Extension Management (description)' );
?>
<p></p>
<form action="<?php echo JRoute::_( str_replace( '&page=licenses', '', $this->request_url ) ) ?>" method="post" name="adminForm" id="adminForm">
	<table class="adminlist nonumbermanager">
		<thead>
			<?php
				$this->outputCodeRow( $model->extensions['all'], $model->_host, count( $model->extensions )-1 );
			?>
			<tr>
				<th width="20">&nbsp;</th>
				<th width="20">&nbsp;</th>
				<th width="200" style="text-align:left;"><?php echo JText::_( 'Extension' ); ?></th>
				<th width="20">&nbsp;</th>
				<th width="50"><?php echo JText::_( 'Installed' ); ?></th>
				<th width="50"><?php echo JText::_( 'Version' ); ?></th>
				<th width="100"><?php echo JText::_( 'Install or Update' ); ?></th>
				<th width="20">&nbsp;</th>
				<th style="text-align:left;"><?php echo JText::_( 'Comment' ); ?></th>
				<th width="100" style="text-align:left;"><?php echo JText::_( 'License code' ); ?></th>
				<th width="20">&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<?php
				$i = 0;
				$this->outputCodeRow( $model->extensions['nonumbermanager'], $model->_host, $i++ );
				foreach( $model->extensions as $alias => $extension ) {
					if ( $alias != 'all' && $alias != 'nonumbermanager' ) {
						$this->outputCodeRow( $extension, $model->_host, $i++ );
					}
				}
			?>
		</tbody>
	</table>
	<input type="hidden" id="license_host" value="<?php echo $model->_host; ?>" />
	<input type="hidden" name="task" value="" />
</form>
<?php
	$xml = JApplicationHelper::parseXMLInstallFile( JPATH_SITE.str_replace( '/', DS, '/plugins/system/nonumberelements.xml' ) );
	if ( $xml && isset( $xml['version'] ) ) {
		echo '<p style="color:#999999;">NoNumber! Elements: v.'.$xml['version'].'</p>';
	}