<?
require_once 'config.php';
if(!$is_admin){
header("Location: ".$_SERVER['HTTP_REFERER']);
}
if(!isset($_GET['machine'])){
if(!isset($_POST)){
die();
}
else {
$mid=$_POST['mid'];
foreach($_POST['service'] as $service){
if(isset($service['id'])){
$temp= new MLService($service['id']);
if(isset($service['del'])){
$temp->delete();
}
else {
$temp->loadFromArray($service);
$temp->save();
}
}
}
}
}
else {
$mid=$_GET['machine'];
}
$machine=new MLMachine($mid);
if($_POST){
$news=$_POST['service']['new'];
if($news['display']!=""){
$temp=new MLService();
$temp->loadFromArray($news);
$machine->updateService($temp);
}
$machine=new MLMachine($mid);
}
//$services=getServicesOfMachine($mid);
$services=$machine->getServices();
?>
<html>
<body>
<form action='edit.php' method='post'>
<table align='center'>
<thead>
<tr>
<td colspan='7' style='text-align:center' >Services for <?php echo $machine->getDisplay()." ( ".$machine->getHost()." )"; ?></td>
</tr>
</thead>
<tr>
<td>Display</td>
<td>Protocol</td>
<td>Port</td>
<td>Interval</td>
<td>Count</td>
<td>Service Name</td>
<td>Del</td>
</tr>
<?php foreach($services as $service): ?>
<tr>
<td><input type='text' name='<?php echo "service[".$service->getID()."][display]"; ?>' value='<?php echo $service->getDisplay(); ?>' /> </td>
<td><?php echo getListOfProtocols($service->getID(),$service->getProtocol()) ?> </td>
<td><input type='text' name='<?php echo "service[".$service->getID()."][port]"; ?>' value='<?php echo $service->getPort(); ?>' /> </td>
<td><input type='text' name='<?php echo "service[".$service->getID()."][interval]"; ?>' value='<?php echo $service->getINterval(); ?>' /> </td>
<td>
<input type='text' name='<?php echo "service[".$service->getID()."][count]"; ?>' value='<?php echo $service->getCount(); ?>' />
<input type='hidden' name='<?php echo "service[".$service->getID()."][id]"; ?>' value='<?php echo $service->getID(); ?>' />
</td>
<td><input type='text' name='<?php echo "service[".$service->getID()."][service_name]"; ?>' value='<?php echo $service->getServiceName(); ?>' /> </td>
<td><input type='checkbox' name='<?php echo "service[".$service->getID()."][del]"; ?>' /> </td>
</tr>
<?php endforeach ?>
<tr>
<td colspan='7'><hr/></td>
</tr>
<tr>
<td><input type='text' name="service[new][display]"/> </td>
<td><?php echo getListOfProtocols('new','http') ?> </td>
<td><input type='text' name="service[new][port]"/> </td>
<td><input type='text' name="service[new][interval]"/> </td>
<td>
<input type='text' name='service[new][count]' />
<input type='hidden' name='service[new][mid]' value='<?php echo $mid?>' />
</td>
<td><input type='text' name='<?php echo "service[new][service_name]"; ?>' /> </td>
<td></td>
</tr>
<tfoot>
<tr>
<td colspan='4'><input type='submit' value="Update" /></td>
</tr>
</tfoot>
</table>
<input type='hidden' name='mid' value='<?php echo $mid?>' />
</form>
</body>
</html>