Location: PHPKode > scripts > PHP 4 Applications > php-4-applications/p4a_panel.php
<?php

	require_once("p4a_constants.php");
	require_once("p4a.php");

class p4a_Panel extends p4a_Application
{
	var $type;
	var $width;
	var $height;
	var $id_html;
	var $visible;
	var $gridStatus;
	var $gridType;

	function p4a_Panel( $_name, $_w=0, $_h=0)
	{
		$this->name = $_name;
		$this->type = "panel";
		$this->title = $_name;
		$this->visible = 1;
		if ($_w>0)
			$this->width=$_w;
		if ($_h>0)
			$this->height=$_h;			
	}

	function setGridStatus( $_o=P4A_PANEL_GRIDLAYOUT, $_t=P4A_PANEL_TOPDOWN)
	{
		$this->gridStatus = $_o;	
		$this->gridType = $_t;
	}

	function setVisible( $_v)
	{
		$this->visible = $_v;
	}

	function getVisible()
	{
		return $this->visible;
	}

	function addControl( $_c, $_name, $_t=0, $_l=0)
	{
		switch($this->gridStatus)
		{
			case P4A_PANEL_GRIDABSOLUTE:
				$st= "style='position:absolute;top:".$_t.";left:".$_l."'";
				break;
			case P4A_PANEL_GRIDRELATIVE:
				$st= "style='position:relative;top:".$_t.";left:".$_l."'";
				break;
			default:
				$st = "";
				break;
		}
		switch( $_c->type)
		{
			case "plainbutton":
				$id = "plainbutton";
				if (!isset($this->has_control['plainbutton']))
					$this->has_control['plainbutton']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
			case "listview":
				$id = "listview";
				if (!isset($this->has_control['listview']))
					$this->has_control['listview']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
			case "form":
				$id = "form";
				if (!isset($this->has_control['form']))
					$this->has_control['form']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
			case "simpleform":
				$id = "simpleform";
				if (!isset($this->has_control['simpleform']))
					$this->has_control['simpleform']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
			case "label":
				$id = "label";
				if (!isset($this->has_control['label']))
					$this->has_control['label']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
			case "barmenu":
				$id = "barmenu";
				if (!isset($this->has_control['barmenu']))
					$this->has_control['barmenu']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
			default:
				$id = "default";
				if (!isset($this->has_control['default']))
					$this->has_control['default']=1;
				$_c->id_html = $this->name.$id.$this->findNextID($_c->type);
				if(!empty($st))
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' ".$st."></div>";
				else
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."'></div>";
				break;
		}
		$this->controls_collection[ $_name] = $_c;
	}

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

		$body = '';

		if ($this->visible==0)
			$body .= "<script language='JavaScript'>".$da.$this->id_html.".style.display='none';</script>";
		else
			$body .= "<script language='JavaScript'>".$da.$this->id_html.".style.display='';</script>";

		$body .= "<script language='JavaScript'>".$da.$this->id_html.".className='clsPanel';\n";
		
		if ($this->width)
			$body .= $da.$this->id_html.".style.width = '".$this->width."px';\n";
		if ($this->height)
			$body .= $da.$this->id_html.".style.height = '".$this->height."px';\n";
			
		$body .= "</script>";
		
		//aƱadir cuerpo del panel

		switch( $this->gridStatus)
		{
			case P4A_PANEL_GRIDRELATIVE:
			case P4A_PANEL_GRIDABSOLUTE:
				foreach( $this->controls_collection as $k => $c)
					if (isset($this->div_collection[$k]))
					{
						if (!$_ev)
						{
							$body.=$this->div_collection[$k]."\n";
							//if ($this->visible==1)
								$body.=$c->flush(0);
						}
						else
						{
							//if ($this->visible==1)
								$body.=$c->flush(1);
						}
					}
					else
					{
						//if ($this->visible==1)
							$body.=$c->flush( $_ev);
					}
				break;
			case P4A_PANEL_GRIDLAYOUT:
				switch( $this->gridType)
				{
					case P4A_PANEL_TOPDOWN:
						$body .= "<center><table>";
						foreach( $this->controls_collection as $k => $c)
							if (isset($this->div_collection[$k]))
							{
								if (!$_ev)
								{
									$body.="<tr><td>".$this->div_collection[$k]."</td></tr>";
									//if ($this->visible==1)
										$body.=$c->flush(0);
								}
								else
								{
									//if ($this->visible==1)
										$body.=$c->flush(1);
								}
							}
							else
							{
								//if ($this->visible==1)
									$body.=$c->flush( $_ev);
							}
						$body .= "</table></center>";
					break;
				}
				break;
		}

		return $body;
	}
}

?>
Return current item: PHP 4 Applications