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

class TopMenu
{
	var $name;

	function TopMenu( $_n, & $_app)
	{
		$menu = new p4a_BarMenu();
		$menu->setMainOption("option1","Option One", "topmenu_op1");
		$menu->setMainOption("option2","Option Two", "topmenu_op2");

		$menu->setSelected("option1");

		$_app->addControl( $menu, $_n, 0, 0);
		$this->name = $_n;
	}

	function event_handler( $_ev, & $_app)
	{
		$answer = "";
		switch( $_ev['event'])
		{
			case "topmenu_op1":
				$_app->controls_collection[$this->name]->setSelected('option1');
				$_app->controls_collection['panel01']->setVisible( 1);
				$_app->controls_collection['panel02']->setVisible( 0);

				$answer .= $_app->controls_collection['panel01']->flush(1);
				$answer .= $_app->controls_collection['panel02']->flush(1);

				$answer .= $_app->controls_collection[$this->name]->flush(1);
				break;
			case "topmenu_op2":
				$_app->controls_collection[$this->name]->setSelected('option2');
				$_app->controls_collection['panel01']->setVisible( 0);
				$_app->controls_collection['panel02']->setVisible( 1);

				$answer .= $_app->controls_collection['panel01']->flush(1);
				$answer .= $_app->controls_collection['panel02']->flush(1);

				$answer .= $_app->controls_collection[$this->name]->flush(1);
				break;
		}

		return $answer;
	}
}

class Panel_base
{
	var $panel;
	var $name;
	var $fname;
	var $lname;

	function Panel_base( $_n, & $_app, $_v)
	{
		$this->name = $_n;
		$this->panel = new p4a_Panel( $this->name, 700, 600);
		$this->panel->setGridStatus( P4A_PANEL_GRIDLAYOUT);

		$this->PutControls();

		$this->panel->setVisible( $_v);

		$_app->addControl( $this->panel, $this->name, 30, 0);
	}

	function PutControls()
	{
	}

	function event_handler( $_ev, & $_app)
	{
		$answer = "";
		switch( substr($_ev['event'],7))
		{
			case "_inse":
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->setStatus( P4A_FORMSTATUS_INSERTING);
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				break;
			case "_upda":
				$_upd='';
				foreach( $_ev as $cn => $v)
					if (substr( $cn, 0, 2)=="c_")
						$_upd[substr($cn,2)]=$v;
					
				if ($_app->controls_collection[$this->name]->controls_collection[$this->fname]->getStatus()==P4A_FORMSTATUS_INSERTING)
					$ins=1;
				else
					$ins=0;
				$r = $_app->controls_collection[$this->name]->controls_collection[$this->fname]->update( $_upd);

				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->lname]->flush(1);
				if ($ins==1)
					$answer .= "<script language='JavaScript'>alert('Data inserted');</script>";
				else
					$answer .= "<script language='JavaScript'>alert('Data updated');</script>";
				break;
			case "_dele":
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->delete();
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->lname]->flush(1);
				break;
			case "_canc":
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->setStatus( 
					($_app->controls_collection[$this->name]->controls_collection[$this->fname]->getStatus() | P4A_FORMSTATUS_EDITION) & (~P4A_FORMSTATUS_INSERTING));
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				break;
			case "_next":
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->next();
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				break;
			case "_prev":
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->previous();
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				break;
			case "_unlo":
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->setFilter("");
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				break;
			case "_col":
				$_app->controls_collection[$this->name]->controls_collection[$this->lname]->changeOrder( $_ev['column']);
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->lname]->flush(1);
				break;
			case "_row":
				$_f = "field1='".$_app->controls_collection[$this->name]->controls_collection[$this->lname]->data[$_ev['rownumber']]['field1']."'";
				$_app->controls_collection[$this->name]->controls_collection[$this->fname]->setFilter($_f);
				$answer .= $_app->controls_collection[$this->name]->controls_collection[$this->fname]->flush(1);
				break;
			case "_lprev":
				$_app->controls_collection[$this->name]->controls_collection[$this->lname]->previous();
				$answer .=$_app->controls_collection[$this->name]->controls_collection[$this->lname]->flush(1);
				break;
			case "_lnext":
				$_app->controls_collection[$this->name]->controls_collection[$this->lname]->next();
				$answer .=$_app->controls_collection[$this->name]->controls_collection[$this->lname]->flush(1);
				break;
			default:
				$answer .= $_app->flush(1);
				break;
		}

		return $answer;
	}
}

class Panel1 extends Panel_base
{
	function PutControls()
	{

		/********************      ONE LABEL **************************/

		$label = new p4a_Label("This is a label Title");
		$label->setFontSize('12');
		$label->setImage("labelimage.ico", "30");
		$label->setAlign("center");
		$this->panel->addControl( $label, "label01", 1, 1);

		/*********************   ONE DATA SOURCE **********************/

		$ds = new p4a_DataSource("p4aex_db", "p4aex_us", "", "tableexample");

		/*********************   ONE LIST VIEW ***********************/

		$list = new p4a_ListView("160");
		$list->setSource( $ds);

		$list->setColumn( "field1", "Field One (click for change order)");
		$list->setColumn( "field2", "Field Two (click for change order)");
		$list->setColumn( "field3", "Field Three (click for change order)");
		$list->setDscn( "field3", "Field Three Description", "tablereferenced", "description", "field3");

		//Set events

		$list->setonClickColumn( "panel01_col");
		$list->setonClickRow( "panel01_row");
		$list->setonClickNext( "panel01_lnext", "Next rows");
		$list->setonClickPrev( "panel01_lprev", "Prev rows");

		$list->setNumRows( 4);

		$list->setFilter( "");

		$this->lname = "listExample";
		$this->panel->addControl( $list, $this->lname, 1, 1);

		/************************   ONE DATA FORM **********************/

		$form = new p4a_Form();
		$form->setSource( $ds);
		$form->setField( "field1", "Field One (Primary)", "text", 6, 0);
		$form->setField( "field2", "Field Two", "text", 30);

		// ********* Combo

		$form->setField( "field3", "Field Three", "text", 15, 1, "tablereferenced", "description", "field3");
		$form->setTextArea( "field4", "Field Four");

		$form->setNumCols( 1);

		$form->setonClickInsert( "panel01_inse", "Insert");
		$form->setonClickUpdate( "panel01_upda", "Save");
		$form->setonClickDelete( "panel01_dele", "Delete");
		$form->setonClickCancel( "panel01_canc", "Cancel");
		$form->setonClickNext( "panel01_next", "Next");
		$form->setonClickPrevious( "panel01_prev", "Previous");
		$form->setonClickUnlock( "panel01_unlo", "unlock");

		$form->setFilter("");

		$this->fname = "formExample";
		$this->panel->addControl( $form, $this->fname, 0, 0);
	}
}

class Panel2 extends Panel_base
{
	function PutControls()
	{
		/********************      ONE MORE LABEL **************************/

		$label = new p4a_Label("This is another label Title");
		$label->setFontSize('14');
		$label->setImage("labelimage2.ico", "30");
		$label->setAlign("center");
		$this->panel->addControl( $label, "label01", 1, 1);

		/*********************   ONE MORE DATA SOURCE **********************/

		$ds = new p4a_DataSource("p4aex_db", "p4aex_us", "", "tableexample2");

		/*********************   ONE LIST VIEW ***********************/

		$list = new p4a_ListView("220");
		$list->setSource( $ds);

		$list->setColumn( "field1", "Field One 2");
		$list->setColumn( "field2", "Field Two 2");
		$list->setColumn( "field3", "Field Three 2");
		$list->setDscn( "field3", "Field Three Description", "tablereferenced2", "description", "field3");

		//Set events

		$list->setonClickColumn( "panel02_col");
		$list->setonClickRow( "panel02_row");
		$list->setonClickNext( "panel02_lnext", "Next rows");
		$list->setonClickPrev( "panel02_lprev", "Prev rows");

		$list->setNumRows( P4A_NUM_RECORDS_MULTIOCURRENCY);

		$list->setFilter( "");

		$this->lname = "listExample";
		$this->panel->addControl( $list, $this->lname, 1, 1);

		/************************   ONE DATA FORM **********************/

		$form = new p4a_Form();
		$form->setSource( $ds);
		$form->setField( "field1", "Field One (Primary)", "text", 6, 0);
		$form->setField( "field2", "Field Two", "text", 30);

		// ********* Combo

		$form->setField( "field3", "Field Three", "text", 15, 1, "tablereferenced2", "description", "field3");
		$form->setTextArea( "field4", "Field Four");

		$form->setNumCols( 1);

		$form->setonClickInsert( "panel02_inse", "Insert");
		$form->setonClickUpdate( "panel02_upda", "Save");
		$form->setonClickDelete( "panel02_dele", "Delete");
		$form->setonClickCancel( "panel02_canc", "Cancel");
		$form->setonClickNext( "panel02_next", "Next");
		$form->setonClickPrevious( "panel02_prev", "Previous");
		$form->setonClickUnlock( "panel02_unlo", "unlock");

		$form->setFilter("");

		$this->fname = "formExample";
		$this->panel->addControl( $form, $this->fname, 0, 0);
	}

}
?>
Return current item: PHP 4 Applications