<?php
/*
 * ARI Framework Lite
 *
 * @package		ARI Framework Lite
 * @version		1.0.0
 * @author		ARI Soft
 * @copyright	Copyright (c) 2009 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

defined('_JEXEC') or die ('Restricted access');

require_once dirname(__FILE__) . '/../kernel/class.AriKernel.php';

require_once JPATH_ADMINISTRATOR . '/components/com_arismartcontent/defines.php';
require_once JPATH_ADMINISTRATOR . '/components/com_arismartcontent/models/providersource.php';

AriKernel::import('Xml.XmlHelper');
AriKernel::import('Utils.Utils');
AriKernel::import('Parameters.ParametersHelper');
AriKernel::import('Web.JSON.JSONHelper');

class JElementCategorysourcetypes extends JElement
{
	var	$_name = 'Categorysourcetypes';

	function fetchElement($name, $value, &$node, $control_name)
	{
		$category = AriXmlHelper::getAttribute($node, 'category');
		$onChangeHandler = AriXmlHelper::getAttribute($node, 'onchange');
		$sourceTypeModel = AriModel::getInstance('Providersourcetype', 'AriSmartContentModel');
		$types = $sourceTypeModel->getSourceTypesByCategory($category);
		
		$attrs = array('class="inputbox"');
		
		if ($onChangeHandler)
			$attrs[] = sprintf('onchange="%1$s"',
				$onChangeHandler);

		return JHTML::_(
			'select.genericlist', 
			$types,
			$control_name . '[' . $name . ']', 
			join(' ', $attrs), 
			'SystemName', 
			'FullName', 
			$value,
			$control_name . $name);
	}
}