<html>
<head>
<title>SNMP Trap Acknowlegement</title>
</head>
<body>
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'nagios', 'nagios123')
   or die('Could not connect: ' . mysql_error());
//echo 'Connected successfully';
mysql_select_db('snmptt') or die('Could not select database');

if(isset($_GET['host'])){
        if($_POST['request']=='acknowledge'){
                $update = "UPDATE snmptt set acknowledged=1 where id in (" . implode(",",$_POST['id']).")";
                //echo $update;
                mysql_query($update) or die('Update Failed You Fool: ' . mysql_error());
                echo "Traps Acknowledged";
        }
        $query = "SELECT id,eventname,category,severity,traptime,formatline from snmptt where hostname='".$_GET['host']."' and acknowledged <> 1";
        $result = mysql_query($query) or die('Select Traps Failed: ' . mysql_error());
        if(mysql_num_rows($result) > 0){
                echo "<h1>New Traps for host " . $_GET['host'] . "</h1>";
                echo "<form name='traps' method='post' action='trapack.php?host=" . $_GET['host'] . "'>";
                echo "<input type='hidden' name='request' value='acknowledge'>";
                echo "<table border='1'>\n\t<tr>\n\t\t<td>Event Name</td>\n\t\t<td>Catagory</td>\n\t\t<td>Severity</td>\n\t\t<td>Trap Time</td>\n\t\t<td>Format Line</td>\n\t\t<td>Acknowledge</td>\n\t</tr>\n";    
                while ($line = mysql_fetch_array($result, MYSQL_ASSOC)){
                        echo "\t<tr>\n\t\t<td>".$line['eventname']."</td>\n\t\t<td>".$line['category']."</td>\n\t\t<td>".$line['severity']."</td>\n\t\t<td>".$line['traptime']."</td>\n\t\t<td>".$line['formatline']."</td>\n\t\t<td><input type='checkbox' name='id[]' value='" . $line['id'] . "'></td>\n\t</tr>\n";
                }
                echo "\t<tr><td></td><td></td><td></td><td></td><td></td><td><input type='submit' value='Acknowledge'></td>\n";
                echo "</form>";
                echo "</table>";
        }else{
                print "<h3>No Traps Exist For This Host.</h3>";
        }
        
}else {
        print "<h3>Incorrect GET PARAMETERS</h3>";        
}
        
// Closing connection
mysql_close($link);
?>

</body>
</html>