<?php

/**
 *
 * @author Peter Csubak (chuby)
 * @copyright Peter Csubak (chuby)
 */
class PCell extends PComponent{
	
	/** @CProperty */
	protected $style;
	/** @CProperty */
	protected $align;
	/** @CProperty */
	protected $valign;
	/** @CProperty */
	protected $colspan;
	/** @CProperty */
	protected $rowspan;
	/** @CProperty */
	protected $content;
	
	public static $evtOnClick = 1;
	public static $evtOnMouseOver = 2;
	public static $evtOnMouseOut = 3;
	public static $evtOnDoubleClick = 4;
	
	public function __construct($content = "", $align = "", $valign = "", $colspan = 0, $rowspan = 0, $id = "", $cssclass = "", $style = "", $evtslock = ""){
		$this->align = $align;
		$this->valign = $valign;
		$this->id = $id;
		$this->cssclazz = $cssclass;
		$this->style = $style;
		$this->content = $content;
		$this->colspan = $colspan;
		$this->rowspan = $rowspan;
		$this->eventsLock = $evtslock;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setStyle($style){
		$this->style = $style;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getStyle(){
		return $this->style;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setAlign($align){
		$this->align = $align;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getAlign(){
		return $this->align;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setVAlign($valign){
		$this->valign = $valign;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getVAlign(){
		return $this->valign;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setColspan($colspan){
		$this->colspan = $colspan;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getColspan(){
		return $this->colspan;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setRowspan($rowspan){
		$this->rowspan = $rowspan;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getRowspan(){
		return $this->rowspan;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function setContent($content){
		$this->content = $content;
	}
	
	/**
	 * 
	 * @deprecated 
	 */
	public function getContent(){
		return $this->content;
	}
	
	public function render(){
		$res = "<td";
		
		if ($this->id != ""){
			$res .= " id=\"".$this->id."\"";
		}
		
		if ($this->cssclazz != ""){
			$res .= " class=\"".$this->cssclazz."\"";
		}
		
		if ($this->style != ""){
			$res .= " style=\"".$this->style."\"";
		}
		
		if ($this->align != ""){
			$res .= " align=\"".$this->align."\"";
		}
		
		if ($this->valign != ""){
			$res .= " valign=\"".$this->valign."\"";
		}
		
		if ($this->colspan != ""){
			$res .= " colspan=\"".$this->colspan."\"";
		}
		
		if ($this->rowspan != ""){
			$res .= " rowspan=\"".$this->rowspan."\"";
		}
		
		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 (is_object($this->content) && ($this->content instanceof PComponent)){
			$res .= ">".$this->content->render()."</td>";
		}elseif(is_array($this->content)){
			$res .= ">";
			foreach ($this->content as $cont){
				if ($cont instanceof PComponent){
					$res .= $cont->render();
				}else{
					$res .= $cont;
				}
			}
			$res .= "</td>";
		}else{
			$res .= ">".$this->content."</td>";
		}
		
		return $res;
	}

}
?>