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

Class ManagePing extends Management {
	private $ping;

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

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

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

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

	public function populateShowContent(){
		$array_column = array("Hostname","Protocol","Start Time","Finish Time","Warning Threshold","Critical Threshold");	  
		$this->xml->addTable($this->ping->select($this->offset,$this->pglimit),
				  $array_column,'Table Ping Performance Monitoring',$this->navigator->getAccess($this),$this->offset,'rightcontent',0);
	}

	public function populateAddForm(){
		$arrayping = $this->ping->selectRemaining();
		if(sizeof($arrayping)==0){
			die('NOTE: No Agent left to be ping-monitored');
		}
		$this->xml->addSelect('Hostname',$arrayping,'','agent_id');
		$this->xml->addSelect('Protocol',array('tcp'=>'tcp','udp'=>'udp','icmp'=>'icmp'),'icmp','proto');
		$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->ping->selectByID($_POST['id']);	  
		$this->xml->addSelect('Protocol',array('tcp'=>'tcp','udp'=>'udp','icmp'=>'icmp'),$this->ping->getProto(),'proto');
		$this->xml->addTextField('Start Time',$this->ping->getStartTime(),'start','text');
		$this->xml->addTextField('Finish Time',$this->ping->getFinishTime(),'finish','text');
		$this->xml->addTextField('Green Line',$this->ping->getGreenLine(),'green','text');
		$this->xml->addTextField('Red Line',$this->ping->getRedLine(),'red','text');
	}

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

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

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

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

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

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

	public function addItem(){
		$array = array($_POST['agent_id'],$_POST['proto'],$_POST['green'],$_POST['red'],$_POST['start'],$_POST['finish'],);
		$this->ping->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 Ping Monitoring for Agent ID '.$_POST['agent_id'],'note',0);
		$arrayping = $this->ping->selectRemaining();
		if(sizeof($arrayping)==0){
			$this->xml->addText(null,'panel',0);
		}else{
			$this->xml->addRedir($this->getName().'/add');
		}
	}
	
}
?>
Return current item: Monyet