<?php
/**
 * Input
 * @date 13.07.2006
 * @name Input
 * @author Margo Poolak <margo 'dot' poolak 'at' mail 'dot' ee>
 * @copyright Copyright &copy;2006 Margo Poolak. All Rights Reserved.
 * @version 2.0
 * @package System.Web.UI.HtmlControls
 * @category 
 * 
 * Generates the html input fields text, password, checkbox, radio etc.
 *
 */
class Input extends HtmlControl
{
	protected $_types;
	function __construct($type = 'text')
	{
		$this->_types = array
		(
		'text',
		'password',
		'checkbox',
		'radio',
		'submit',
		'reset',
		'file',
		'hidden',
		'button'
		);
		/*
		* Checks the allowed html input type
		*/
		if(in_array($type,$this->_types))
			$this->_attribute['type'] = $type;
		else
			trigger_error("Not supported HTML input type <b>$type</b>",E_USER_ERROR);		
		
	}	
	/*
	* Sets element attribute selected
	* 
	*/	
	function setSelected()
	{
		switch($this->_attribute['type'])
		{
			case 'checkbox':
				$this->_attribute['checked'] = 'checked';
			break;
			case 'radio':
				$this->_attribute['checked'] = 'checked';
			break;			
			default:
				$this->_attribute['selected'] = 'selected';
		}
	}
	/*
	*
	*/	
	function render()
	{
		foreach($this->_attribute as $key=>$value)
		{
			$output[]= $key.'="'.$value.'"';
		}
		$html = '<input '.implode($output,' ').' />';
		return $html;
	}
}
?>