<?php

/**
 *
 * @author Peter Csubak (chuby)
 * @copyright Peter Csubak (chuby)
 */
class PButton extends PComponent{

	/** @CProperty */
	protected $text;
	/** @CProperty */
	protected $disabled;
	/** @CProperty */
	protected $name;
	/** @CProperty */
	protected $type;
	/** @CProperty */
	protected $style;
	
	public static $evtOnClick = 1;
	public static $evtOnMouseOver = 2;
	public static $evtOnMouseOut = 3;
	public static $evtOnDoubleClick = 4;
	
	public function __construct($text = "", $disabled = false, $name = "", $type = "button", $id = "", $cssclass = "", $style = "", $evtslock = ""){
		$this->text = $text;
		$this->disabled = $disabled;
		$this->name = $name;
		$this->type = $type;
		$this->id = $id;
		$this->cssclazz = $cssclass;
		$this->style = $style;
		$this->eventsLock = $evtslock;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setText($text){
		$this->text = $text;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getText(){
		return $this->text;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setDisabled($disabled){
		$this->disabled = $disabled;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getDisabled(){
		return $this->disabled;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setName($name){
		$this->name = $name;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getName(){
		return $this->name;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setType($type){
		$this->type = $type;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getType(){
		return $this->type;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setStyle($style){
		$this->style = $style;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getStyle(){
		return $this->style;
	}
	
	public function render(){
		$res = "<button";
		
		if ($this->id != ""){
			$res .= " id=\"".$this->id."\"";
		}
		
		if ($this->cssclazz != ""){
			$res .= " class=\"".$this->cssclazz."\"";
		}
		
		if ($this->style != ""){
			$res .= " style=\"".$this->style."\"";
		}
		
		if (is_array($this->activeEvents)){
			foreach ($this->activeEvents as $evtTypes){
				if ($evtTypes == self::$evtOnClick){   //TYPE			SENDEDFROM			BINDEDTO				LOCK
					$res .= " onclick=\"sendAjaxEvent('AjaxOnClick', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnDoubleClick){
					$res .= " ondblclick=\"sendAjaxEvent('AjaxOnDoubleClick', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnMouseOut){
					$res .= " onmouseout=\"sendAjaxEvent('AjaxOnMouseOut', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
				if ($evtTypes == self::$evtOnMouseOver){
					$res .= " onmouseover=\"sendAjaxEvent('AjaxOnMouseOver', '".$this->id."', '".$this->bindedTo."', '".$this->eventsLock."')\"";
				}
			}
		}
		
		if ($this->disabled){
			$res .= " disabled=\"disabled\"";
		}
		
		if ($this->name != ""){
			$res .= " name=\"".$this->name."\"";
		}
		
		if ($this->type != ""){
			$res .= " type=\"".$this->type."\"";
		}else{
			$res .= " type=\"button\"";
		}
		
		$res .= " value=\"".$this->text."\"";
		
		$res .= ">".$this->text."</button>";
		
		return $res;
	}
	
}
?>