Location: PHPKode > projects > Monyet > controllers/managenetrelation.php
<?php
//controller for netrelation
//FIXME: see selectCouple from ping, observer not tested
//
//this class is used to build network map
//agent as the node and ping monitoring as the vertices

Class ManageNetRelation extends Management {

	private $netrelation;

	public function __construct(){
		parent::__construct();
		$this->netrelation = new NetRelation();
	}

	public function showDetail(){
		parent::show();
	}
	//redirect show to the networkmap.php
	public function show(){
		$this->xml->addRedir('managenetworkmap/index');
		$this->xml->flush();
	}

	public function remove(){
		parent::remove();
	}

	public function removeItem(){
		$this->netrelation->remove($_POST['id']);
	}

	public function populateShowContent(){
		$array_column = array("Agents","Net","Ping Monitoring");	  
		$this->xml->addTable($this->netrelation->select($this->offset,$this->pglimit),
				  $array_column,'Table Map Network Relation',$this->navigator->getAccess($this),$this->offset,'rightcontent',0);
		$this->xml->addBreak('rightcontent',2);	
	}

	public function populateAddForm(){
		$netmapnet = new NetMapNet();
		$ping = new Ping();
		$this->xml->addSelectAction('Net',$netmapnet->selectCouple('id','name'),'','net_id',$this->getName().'/addSelect');
		$this->xml->addSelect('Agent',$this->netrelation->selectRemaining($netmapnet->getHead('id')),'','agent_id');
		$this->xml->addSelect('Ping Monitoring',$ping->selectCouple('agent_id','description'),'','ping_id');
	}
	public function populateEditForm(){
	   $this->netrelation->selectByID($_POST['id']);	 
		$netmapnet = new NetMapNet();
		$ping = new Ping();
		$this->xml->addSelect('Ping Monitoring',$ping->selectCouple('agent_id','description'),$this->netrelation->getPing(),'ping_id');

	}
	public function setEditCaption(){
		$this->xml->addText('Edit Net No. '.$_POST['itemnumber'],'headbox',1);
	}

	//return string to set the title
	public function getTitle(){
		return SITENAME.' -netrelation';
	}

	public function getFormPlace(){
		return 'panel';
	}

	public function editItem(){
	  	$array = array('ping'=>$_POST['ping_id']);	  
		return $this->netrelation->update($array,$_POST['id']);	  
	}

	public function getKeyVar(){
		return 'ping_id';
	}

	public function getTotal(){
		return $this->netrelation->getTotal();
	}

	public function addItem(){
		$array = array('',$_POST['agent_id'],$_POST['net_id'],$_POST['ping_id']);
		$this->netrelation->add($array);
	}

	public function checkAdd(){
		if($_POST['agent_id']==''){
			die('Hostname selection empty. Must be no agent left :)');
	  	}
	}
	//not implemented
	public function checkEdit(){
	}

	//parent + custome post add action here
	public function postAddAction(){
		parent::postAddAction();
		$this->xml->addRedirPOST($this->getName().'/addSelect','selected='.$_POST['net_id']);
	}
	//special derived class
	public function addSelect(){
		if(isset($_POST['selected'])){
			$this->xml->addSingleSelect('Agent',$this->netrelation->selectRemaining($_POST['selected']),'','agent_id','divselectagent_id');
		}
		$this->xml->flush();
	}

}
?>
Return current item: Monyet