<?php

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

/**
 * Renders a categories element
 *
 * @package 	MooFAQ
 * @subpackage	module
 * @since		1.5
 */

class JElementMultiplesections extends JElement
{
	/**
	* Element name
	*
	* @access	protected
	* @var		string
	*/
	var	$_name = 'Multiplesections';

	function fetchElement($name, $value, &$node, $control_name)
	{
		$db = &JFactory::getDBO();

		$section	= $node->attributes('section');
		$class		= $node->attributes('class');
		if (!$class) {
			$class = "inputbox";
		}
		$attribs	= 'class="'.$class.'" ';
		if (!isset ($section)) {
			// alias for section
			$section = $node->attributes('scope');
			if (!isset ($section)) {
				$section = 'content';
			}
		}
		$ctrl	= $control_name .'['. $name .']';

		if ($m = $node->attributes('multiple'))
		{
			$attribs	.= ' multiple="multiple" ';
			$ctrl		.= '[]';
			//$value		= implode( '|', )
		}
		
		$query = 'SELECT id, title FROM #__sections WHERE published = 1 AND scope = "content" ORDER BY title';
		$db->setQuery($query);
		$options = $db->loadObjectList();
		array_unshift($options, JHTML::_('select.option', '', '- '.JText::_('None').' -', 'id', 'title'));

		return JHTML::_('select.genericlist',  $options, $ctrl, $attribs, 'id', 'title', $value, $control_name.$name );
	}
}