Location: PHPKode > projects > Monyet > controllers/managesnmpmon.php
<?php

Class ManageSNMPMon extends Management {
	private $snmpmon;

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

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

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

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

	public function populateShowContent(){
		$array_column = array("Agent","SNMP","User","Password","Start Time","Finish Time","Warning","Critical");	  
		$this->xml->addTable($this->snmpmon->select($this->offset,$this->pglimit),
				  $array_column,'Table SNMP Monitoring',$this->navigator->getAccess($this),$this->offset,'rightcontent',0);
	}

	public function populateAddForm(){
		$snmpdef = new SNMPDef();
		$this->xml->addSelectAction('Service',$snmpdef->selectCouple('id','name'),'','snmpdef_id',$this->getName().'/addSelect');
		$this->xml->addSelect('Agent',$this->snmpmon->selectRemaining($snmpdef->getHead('id')),'','agent_id');
		$this->xml->addTextField('Username',null,'username','text');
		$this->xml->addTextField('Password',null,'password','text');
		$this->xml->addTextField('Start Time',null,'start','text');
		$this->xml->addTextField('Finish Time',null,'finish','text');
		$this->xml->addTextField('Green Line',null,'green','text');
		$this->xml->addTextField('Red Line',null,'red','text');
	}
	public function populateEditForm(){
		$this->snmpmon->selectByID($_POST['id']);	  
		$this->xml->addTextField('Username',$this->snmpmon->getUser(),'username','text');
		$this->xml->addTextField('Password',$this->snmpmon->getPassword(),'password','text');
		$this->xml->addTextField('Start Time',$this->snmpmon->getStartTime(),'start','text');
		$this->xml->addTextField('Finish Time',$this->snmpmon->getFinishTime(),'finish','text');
		$this->xml->addTextField('Green Line',$this->snmpmon->getGreenLine(),'green','text');
		$this->xml->addTextField('Red Line',$this->snmpmon->getRedLine(),'red','text');
	}

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

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

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

	public function editItem(){
		$array = array('starttime'=>$_POST['start'],'finishtime'=>$_POST['finish'],'username'=>$_POST['username'],
						 'password'=>$_POST['password'],'red'=>$_POST['red'],'green'=>$_POST['green']);	  
		return $this->snmpmon->update($array,$_POST['id']);	  
	}

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

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

	public function addItem(){
	  	$array = array('',$_POST['agent_id'],$_POST['snmpdef_id'],$_POST['username'],$_POST['password'],$_POST['green'],$_POST['red'],
						 $_POST['start'],$_POST['finish']);
		$this->snmpmon->add($array);
	}

	public function checkAdd(){
		if(($_POST['green']!=0)||($_POST['red']!=0)){
			if($_POST['green']!=''){
				if($_POST['red']!=''){
					if($_POST['red']<=$_POST['green']){
						die('Red Threshold should be higher than green one');	  
					}
				}else{
					die('Red threshold value should be defined also');
				}
			}
		}
	}
	public function checkEdit(){
		$this->checkAdd();
	}
	//redefine post add action 
	public function postAddAction(){
		$this->xml->addText('Adding SNMP Monitoring for Agent ID '.$_POST['agent_id'],'note',0);
	}
	//special derived class
	public function addSelect(){
		if(isset($_POST['snmpdef_id'])){
			$this->xml->addSingleSelect($this->snmpmon->selectRemaining($_POST['snmpdef_id']),'','agent_id','divselectagent_id');
		}
		$this->xml->flush();
	}
}
?>
Return current item: Monyet