#!/usr/bin/perl
#
# PIX Logging Architecture
# [ Kristof Philipsen ]
#
# This file is part of PIX Logging Architecture
#
# PIX Logging Architecture is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PIX Logging Architecture is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                                                                                                                                                                                    
                                                                                                                                                                                    
use DBI;
use CGI;
                                                                                                                                                                                    
                                                                                                                                                                                    
#
# include configuration
#
require "conf.pl";      # General Configuration
require "subs.pl";      # Subroutines
                                                                                                                                                                                    
                                                                                                                                                                                    
#
# Make Database Connection
#
db_connect();
                                                                                                                                                                                    
                                                                                                                                                                                    
#
# Get CGI Parameters
#
$query = new CGI;
$id = $query->param("id");
$pix_id = $query->param("pix_id");
$type = $query->param("type");
$remove_pix = $query->param("remove_pix");
$datetime = $query->param("date");
($date,$time) = split(" ",$datetime);
                                                                                                                                                                                    
if ($remove_pix eq "true") {
   $remove_prepare = "delete from event_management_id where incident_id like \"$id\" and incident_pix_id like \"$pix_id\" and incident_pix_id_type like \"$type\"";
   $remove_id = $db_handle->prepare($remove_prepare) or die "Couldn't prepare query '$remove_prepare': $DBI::errstr\n";
   $rc=$remove_id->execute();
}

#
# HTML SECTION
#
printtitle();
print <<EOF;
<span class='titlehead'><b>PIX Event Management > Incident Details</b></span>
<br><br>
EOF
$getAllEvents = "SELECT incident_id, incident_entry_time, incident_status, incident_update_time, incident_name, incident_severity, incident_handler, incident_description FROM event_management_data where incident_id like \"$id\"";
$statement2 = $db_handle->prepare($getAllEvents) or die "Couldn't prepare query '$getAllEvents': $DBI::errstr\n";
$statement2->execute();
while (($incident_id, $incident_entry_time, $incident_status, $incident_update_time, $incident_name, $incident_severity, $incident_handler, $incident_description) = $statement2->fetchrow) {
print <<EOF;
<table width="150" cellpadding="0" cellspacing="0">
<td width="150" bgcolor="#5479d8"><span class="button">PIX Incident Details</td>
</table>
<br><br>
<table width="600" cellpadding="0" cellspacing="0">
<td width="200"><span class="main">Incident Name:</td>
<td width="400"><span class="main"><b>$incident_name</b></td>
<tr>
<td width="200"><span class="main">Incident Entry Time:</td>
<td width="400"><span class="main">$incident_entry_time</td>
<tr>
<td width="200"><span class="main">Incident Update Time:</td>
<td width="400"><span class="main">$incident_update_time</td>
<tr>
<td width="200"><span class="main">Incident Handler:</td>
<td width="400"><span class="main">$incident_handler</td>
<tr>
<td width="200"><span class="main">Incident Severity:</td>
<td width="400"><span class="main">$incident_severity</td>
<tr>
<td width="200"><span class="main">Incident Status:</td>
<td width="400"><span class="main">$incident_status</td>
<tr>
<td width="200" align="left" valign="top"><span class="main">Incident Description:</td>
<td width="400"><span class="main">$incident_description</td>
<tr>
<tr>
</table>
<br><br>
EOF
}
print <<EOF;
<table width="150" cellpadding="0" cellspacing="0">
<td width="150" bgcolor="#5479d8"><span class="button">PIX Incident Logs</td>
</table>
<br><br>
<table width="600" cellpadding="0" cellspacing="0">
<td bgcolor="#d9d9d9"><span class="main"><b>Incident Log Entry Time</td>
<td bgcolor="#d9d9d9"><span class="main"><b>PIX Log ID</td>
<td bgcolor="#d9d9d9"><span class="main"><b>Entry Description</td>
<td bgcolor="#d9d9d9"><span class="main"><b>Options</td>
<tr>
EOF
$getAllLogs = "select incident_entry_time, incident_pix_id_type, incident_pix_id, incident_pix_id_description from event_management_id where incident_id=\"$id\" order by incident_entry_time";
$statement3 = $db_handle->prepare($getAllLogs) or die "Couldn't prepare query '$getAllLogs': $DBI::errstr\n";
$statement3->execute();
while (($incident_entry_time, $incident_pix_id_type, $incident_pix_id, $incident_pix_id_description) = $statement3->fetchrow) {
print <<EOF;
<td><span class="main">$incident_entry_time</td>
<td><span class="main">$incident_pix_id/$incident_pix_id_type</td>
<td><span class="main">$incident_pix_id_description</td>
EOF
if ($incident_pix_id_type eq "traffic") {
print <<EOF;
<td><span class="main"><a href="pix_traffic_id?id=$incident_pix_id"><span class="bodylink">[ view ]</span></a>
<a href="pix_event_view?remove_pix=true&type=$incident_pix_id_type&pix_id=$incident_pix_id&id=$id"><span class="bodylink">[ remove ]</span></a></td>
<tr>
EOF
} 
if ($incident_pix_id_type eq "ids") {
print <<EOF;
<td><span class="main"><a href="pix_ids_id?id=$incident_pix_id"><span class="bodylink">[ view ]</span></a>
<a href="pix_event_view?remove_pix=true&type=$incident_pix_id_type&pix_id=$incident_pix_id&id=$id"><span class="bodylink">[ remove ]</span></a></td>
<tr>
EOF
}
}
print <<EOF;
</table>
<br><br>
EOF
$db_handle->disconnect();

