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

Class ManageAutomate extends Management {
	private $agent;
	private $automate;

	public function __construct(){
		parent::__construct();
		$this->agent = new Agent();
		$this->automate = new Automate();
	}

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

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

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

	public function populateShowContent(){
		$array_column = array("Hostname","Caller","Script");	  
		$array = $this->automate->select($this->offset,$this->pglimit);
		$result = array();
		for($i=0;$i<sizeof($array);$i++){
			$tmp = new StdClass();
			$tmp->itemid = $array[$i]->itemid;
			$tmp->description = $array[$i]->description;
			$caller = $array[$i]->caller;
			if($caller[0]=='p'){
				$tmp->caller = "Ping";
			}else{
				$servmon = new ServiceMon();
				$servdef = new ServicesDef();
				$servmon->selectByID($caller);
				$servdef->selectByID($servmon->getService());
				$tmp->caller = "Service ".$servdef->getName();
			}
			$tmp->script = $array[$i]->script;
			$result[] = $tmp;
		}
		$this->xml->addTable($result,$array_column,'Table Agent Automation',$this->navigator->getAccess($this),$this->offset,'rightcontent',0);
	}

	public function populateAddForm(){
		$this->xml->addSelectAction('Hostname',$this->agent->selectCouple('id','description'),'','agent_id',$this->getName().'/addSelect');
		$this->agent->selectByID($this->agent->getHead('id'));
		$this->xml->addSelect('Caller',$this->agent->getAvailableMonitoring(),'','caller');
		$this->xml->addTextField('Script',null,'myfile','file');
	}
	public function populateEditForm(){
		$this->automate->selectByID($_POST['id']);	  
		$this->xml->addSelectAction('Hostname',$this->agent->selectCouple('id','description'),$this->automate->getAgentID(),'agent_id',$this->getName().'/addSelect');
		$this->agent->selectByID($this->automate->getAgentID());
		$this->xml->addSelect('Caller',$this->agent->getAvailableMonitoring(),$this->automate->getCaller(),'caller');
		$this->xml->addTextField('New Script',null,'myfile','file');
	}

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

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

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

	public function editItem(){
		$array = array();
		if($_POST['myfile']!=''){	  
			$str = $_POST['myfile'];
			//FIXME: linux specific slashes, windows should be '\\'
			$arraystr = explode('/',$str);
			$file = $arraystr[(sizeof($arraystr)-1)];
	
			$filetemp = REPO.'/'.$file;
			if(file_exists($filetemp)){
				die('File with the same name has already uploaded!');
			}
			while(!file_exists(REPO.'/a'.$file)){
				sleep(1);
			}
			rename(REPO.'/a'.$file,$filetemp);
			$array['script'] = $file;
		}
		$array['agent'] = $_POST['agent_id'];
		$array['caller'] = $_POST['caller'];	  
		return $this->automate->update($array,$_POST['id']);	  
	}

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

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

	public function addItem(){
		$str = $_POST['myfile'];
		//FIXME: linux specific slashes, windows should be '\\'
		$arraystr = explode('/',$str);
		$file = $arraystr[(sizeof($arraystr)-1)];
	
	
		$filetemp = REPO.'/'.$file;
		if(file_exists($filetemp)){
			die('File with the same name has already uploaded!');
		}
		while(!file_exists(REPO.'/a'.$file)){
			sleep(1);
		}
		rename(REPO.'/a'.$file,$filetemp);
		$array = array('',$_POST['caller'],$file,$_POST['agent_id']);
		$this->automate->add($array);
	}

	public function checkAdd(){
	}
	public function checkEdit(){
	}
	//spesific method
	public function addSelect(){
		if(isset($_POST['agent_id'])){
			$this->agent->selectByID($_POST['agent_id']);
			$this->xml->addSingleSelect($this->agent->getAvailableMonitoring(),'','caller','divselectcaller');
		}
		$this->xml->flush();
	}
}
?>
Return current item: Monyet