<?php
/**
 * HtmlControl
 *
 * @date 21.03.2007
 * @name HtmlControl
 * @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 
 * 
 * This is UI control component
 */
class HtmlControl extends Control
{
	protected $_attribute;
	protected $_tagName;
	/*
	*
	*/
	function __construct()
	{
	}
	/*
	* Sets the element tag name
	* @parameter element name 'table','td', 'img', 'div' etc
	*/
	function setTagName($name)
	{
		$this->_tagName = $name;
	}
	/*
	* 
	*/
	function getTagName($name)
	{
		return $$this->_tagName;
	}	
	/*
	* @returns boolean is the attribute allready set or not
	*/
	function issetAttribute($name)
	{
		if($this->_attribute[$name] == '')
			return false;
		else
			return true;
	}
	/*
	* @param string css class name
	* @return 
	*/	
	public function setClass($class)
	{
		$this->_attribute['class'] = $class;
	}	
	/*
	* @param string id
	* @return 
	*/	
	public function setID($id)
	{
		$this->_attribute['id'] = $id;
	}	
	/*
	* @param
	* @return 
	*/	
	function setTitle($value)
	{
		$this->_attribute['title'] = $value;
	}
	/*
	* @param string alternative image text
	* @return 
	*/	
	function setAlt($value)
	{
		$this->_attribute['alt'] = utf8_encode($value);
	}
	/*
	* @param 
	* @return alternative text
	*/	
	function getAlt()
	{
		if(isset($this->attribute['alt']))
			return $this->_attribute['alt'];
		return;
	}	
	/*
	* @param
	* @return 
	*/	
	function setAccessKey($key)
	{
		if(strlen($key)>1)
			trigger_error('Access key can be only one char',E_USER_ERROR);
		$this->_attribute['accesskey'] = $key;
		$this->setTitle("Shortcut key ALT+$key");
	}
	/*
	* @param
	* @return 
	*/	
	function setText($value)
	{
		$this->_attribute['value'] = utf8_encode($value);
	}
	/*
	* @param
	* @return 
	*/	
	public function getText()
	{
		return $this->_attribute['value'];
	}	
	/*
	* @param
	* @return 
	*/	
	function setDisabled()
	{
		$this->_attribute['disabled'] = 'disabled';
	}
	/*
	* Sets onload, onClick event to the item
	* @parameter string event name onLoad, onClick
	* @parameter string action javascript alert etc.
	*/
	public function setEvent($event,$action)
	{
		$this->_attribute[$event] = $action;
	}
	/*
	* @param
	* @return 
	*/	
	public function isAutoComplete()
	{
		$this->_attribute['autocomplete'] = 'on';
	}
	/*
	*
	*/
	public function getName()
	{
		if(isset($this->_attribute['name']))
		{
			return $this->_attribute['name'];
		}
		return;
	}
	/*
	* @param
	* @return 
	*/	
	public function setName($name)
	{
		$this->_attribute['name'] = $name;
		$this->_attribute['id'] = $name;		
	}
	/*
	* @param
	* @return 
	*/	
	function setCssClass($class)
	{
		$this->_attribute['class'] = $class;
	}
	/*
	* @param
	* @return 
	*/	
	function setMaxLength($maxlength)
	{
		$this->_attribute['maxlength'] = $maxlength;
		$this->_attribute['size'] = $maxlength;
	}
	/*
	* @param
	* @return 
	*/
	function setSize($size)
	{
		$this->_attribute['size'] = $size;
	}
	/*
	* @param
	* @return 
	*/	
	function setStyle($style)
	{
		$this->_attribute['style'] = $style;
	}
	/*
	* @param
	* @return 
	*/	
	function setType($type)
	{
		$this->_attribute['type'] = $type;
	}
	/*
	* @param
	* @return 
	*/	
	function setSrc($src)
	{
		$this->_attribute['src'] = $src;
	}
	/*
	* @param
	* @return 
	*/	
	function setCellpadding($value)
	{
		$this->_attribute['cellpadding'] = $value;
	}
	/*
	* @param
	* @return 
	*/	
	function setCellspacing($value)
	{
		$this->_attribute['cellspacing'] = $value;
	}
	/*
	* Sets the width
	* @param integer of the width
	*/
	function setWidth($width)
	{
		$this->_attribute['width'] = $width;
	}
	/*
	* @param
	* @return 
	*/	
	function renderAttributes()
	{
		$param = '';
		if(isset($this->_attribute))
		{
			foreach($this->_attribute as $key=>$value)
			{
				$output[]= $key.'="'.$value.'"';
			}	
			$param .= implode($output,' ');
			return $param;
		}
	}
	/*
	* Returns all the attributes
	* @returns array attributes
	*/
	public function getAttributes()
	{
		return $this->_attribute;
	}
	/*
	*
	*/
	public function setAttributes($attributes)
	{
		if(is_array($attributes))
			$this->_attribute = $attributes;
	}
	/*
	*
	*/
	function renderBody()
	{
		return '<'.$this->tagName.' '.$this->renderAttributes().'>'.$this->Text.'</'.$this->tagName.'>';
	}
}
?>