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

	class p4a_Application
	{
		var $controls_collection;
		var $div_collection;
		var $title;
		var $css_style;
		var $has_control;
		var $theme;
		var $id_html_collection;
		
		function p4a_Application( $_p4a_name="PHP(4)Application", $_theme="bluetheme")
		{
			$this->title = $_p4a_name;
			$this->theme = $_theme;
			$this->onStart();
		}

		function onStart()
		{
		}

		function setTheme( $_t)
		{
			$this->theme = $_t;
		}

		function findNextID( $_ct)
		{
			if (!isset($this->id_html_collection[$_ct]))
				$this->id_html_collection[$_ct]=0;
			$id = ++$this->id_html_collection[$_ct];
			
			return $id;
		}
		
		function addControl( $_c, $_name, $_t, $_l)
		{
			switch( $_c->type)
			{
				case "plainbutton":
					$id = "plainbutton";
					if (!isset($this->has_control['plainbutton']))
						$this->has_control['plainbutton']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;
				case "listview":
					$id = "listview";
					if (!isset($this->has_control['listview']))
						$this->has_control['listview']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;
				case "form":
					$id = "form";
					if (!isset($this->has_control['form']))
						$this->has_control['form']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;
				case "simpleform":
					$id = "simpleform";
					if (!isset($this->has_control['simpleform']))
						$this->has_control['simpleform']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;
				case "panel":
					$id = "panel";
					if (!isset($this->has_control['panel']))
						$this->has_control['panel']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'>".$_c->flush(0)."</div>";
					break;
				case "label":
					$id = "label";
					if (!isset($this->has_control['label']))
						$this->has_control['label']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;
				case "barmenu":
					$id = "barmenu";
					if (!isset($this->has_control['barmenu']))
						$this->has_control['barmenu']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;
				default:
					$id = "default";
					if (!isset($this->has_control['default']))
						$this->has_control['default']=1;
					$_c->id_html = $id.$this->findNextID($_c->type);
					$this->div_collection[ $_name] ="<div id='".$_c->id_html."' style='position:absolute;top:".$_t.";left:".$_l."'></div>";
					break;

			}
			$this->controls_collection[ $_name] = $_c;
		}

		function style_collector()
		{
			$style = file( P4A_PATH_P4A."/themes/".$this->theme."/".$this->theme.".css");
			$cad="";
			foreach($style as $l)
				$cad.=$l;

			return $cad;
		}

		function flush( $_ev=0)
		{
			if ($_ev==1)
			{
				$body='';
				foreach( $this->controls_collection as $k => $c)
					$body.=$c->flush(1);
				return $body;
			}
			$this->css_style = $this->style_collector();


			$body = '<html><head><title>'.$this->title.'</title>';
			$body .= '<style type="text/css">'.$this->css_style.'</style>';

			$body .= '</head>';
			$body .= '<body>';
			//añadir cuerpo de la aplicación
			foreach( $this->controls_collection as $k => $c)
			{
				if (isset($this->div_collection[$k]))
				{
					$body.=$this->div_collection[$k]."\n";
					if ($c->type!='panel')
						$body.=$c->flush();
				}
				else
					$body.=$c->flush();
			}

			//añadir iframe de eventos
			$body .= "<iframe style='width:0px; height:0px' marginwidth=0 marginheight=0 frameborder='no' id='p4a_eventFrame'>";
			$body .= "</iframe>";

			$body .= "</body></html>";

			if ($_ev)
				$body.="parent.innerHTML=".$body;

			echo $body;
		}

		function event_handler( $_event_name)
		{
			return $respuesta;
		}
	}
?>
Return current item: PHP 4 Applications