<?php
/**
 * @version $Id$
 * @package    Contact_Enhanced
 * @author     Douglas Machado {@link http://ideal.fok.com.br}
 * @author     Created on 28-Jul-09
 * @license		GNU/GPL, see license.txt
 * Contact Enhanced  is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */

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

/**
 * Renders a SQL element
 *
 * @package 	Contact_Enhanced
 * @since		1.5.7.1
 */

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

	function fetchElement($name, $value, &$node, $control_name)
	{
		$db		= & JFactory::getDBO();
		$db->setQuery($node->attributes('query'));
		$key 	= ($node->attributes('key_field') ? $node->attributes('key_field') : 'value');
		$val 	= ($node->attributes('value_field') ? $node->attributes('value_field') : $name);
		$result	= $db->loadObjectList();

		$opt[0]	= new stdClass();
		$opt[0]->$key	= '';
		$opt[0]->$val	= JText::_('Please select one') ;

		$result	= array_merge((array)$opt,$result);
				
		return JHTML::_('select.genericlist', $result , ''.$control_name.'['.$name.']', 'class="inputbox"', $key, $val, $value, $control_name.$name);
	}
}
