Location: PHPKode > scripts > PHP 4 Applications > php-4-applications/p4a_label.php
<?php
	require_once("p4a_constants.php");
	require_once("p4a_control.php");

class p4a_Label extends p4a_Control
{
	var $text;
	var $image;
	var $align;
	var $htag;
	var $font_size;

	function p4a_Label( $_t='', $_w=0, $_h=0)
	{
		$this->text = $_t;
		$this->type = "label";
		if ($_w>0)
			$this->width=$_w;
		if ($_h>0)
			$this->height=$_h;

		$this->align = 'center';
	}

	function changeLabel( $_l)
	{
		$this->text = $_l;
	}

	function setHTag( $_t)
	{
		$this->htag = $_t;
	}

	function setFontSize( $_fs)
	{
		$this->font_size = $_fs;
	}

	function setImage( $_i, $_w=0)
	{
		$this->image = $_i;
		$this->image_w = $_w;
	}

	function setAlign( $_a='center')
	{
		$this->align = $_a;
	}


	function convert( $_v)
	{
		// convierte entidades habituales html
		$_v = htmlentities( $_v, ENT_QUOTES);

		// convierte saltos de lĂ­nea en "\\n" aptos para javascript (usando innerHTML='...')

		$_v = preg_replace("(\r\n|\n|\r)", "<br>", $_v);
		
		return $_v;

	}

	function flush( $_ev)
	{
		if (!$_ev)
			$da="";
		else
			$da="parent.";

		$js = "<script language='JavaScript'>";
		$js .= $da.$this->id_html.".className='clsLabel';";

		if (isset($this->font_size))
			$js .= $da.$this->id_html.".style.fontSize='".$this->font_size."px';";

		$js .= $da.$this->id_html.".innerHTML='";

		if (strlen($this->image)>0)
		{
			$js .= "<img src=\"".$this->image."\" ";
			if ($this->image_w)
				$js .= " width=\"".$this->image_w."\">";
			else
				$js .=">";
		}

		if ($this->htag)
			$js .= "<h".$this->htag.">";

		$js .= $this->convert($this->text);

		if ($this->htag)
			$js .= "</h".$this->htag.">";

		$js .= "';\n";

		if ($this->width)
			$js .= $da.$this->id_html.".style.width = '".$this->width."px';\n";
		if ($this->height)
			$js .= $da.$this->id_html.".style.height = '".$this->height."px';\n";
		$js .= $da.$this->id_html.".style.align='".$this->align."';\n";
		$js .= "</script>";

		return $js;
	}
}

?>
Return current item: PHP 4 Applications