#!/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");
$remove_incident = $query->param("remove_incident");
$datetime = $query->param("date");
($date,$time) = split(" ",$datetime);
if ($remove_incident eq "true") {
    $removeIncidentRefs=$db_handle->prepare("delete from event_management_id where incident_id=\"$id\"");
    $removeIncidentRefs->execute();
    $removeIncidentAll=$db_handle->prepare("delete from event_management_data where incident_id=\"$id\"");
    $removeIncidentAll->execute();
}

                                                                                                                                                                                                  
#
# DB Query Parameters
#
$addIncident_query=$db_handle->prepare("update event_management_data set incident_name=\'$incident_name\', incident_status=\'$incident_status\', incident_update_time=\'$date\', incident_severity=\'$incident_severity\', incident_description=\'$incident_description\', incident_handler=\'$incident_handler\' where incident_id=\'$id\'");
$rc=$addIncident_query->execute();
                                                                                                                                                                                                  
                                                                                                                                                                                                  
#
# HTML SECTION
#
printtitle();
                                                                                                                                                                                                  
print <<EOF;
<span class='titlehead'><b>PIX Event Management</b></span>
<br><br>
<span class="main">
<a href="pix_event_create"><span class="bodylink">[ Create new incident ]</span></a>
<br><br>
EOF
$getAllEvents = "SELECT incident_id, incident_entry_time, incident_status, incident_name, incident_severity, incident_handler FROM event_management_data order by incident_entry_time";
$statement2 = $db_handle->prepare($getAllEvents) or die "Couldn't prepare query '$getAllEvents': $DBI::errstr\n";
$statement2->execute();
print <<EOF;
<table width="70%" cellpadding="0" cellspacing="0" border="0">
<td width="150" bgcolor="#5479d8"><span class="button">Incident Name</td>
<td width="75" bgcolor="#5479d8"><span class="button">Incident Handler</td>
<td width="50" bgcolor="#5479d8"><span class="button">Entry Time</td>
<td width="30" bgcolor="#5479d8"><span class="button">Severity</td>
<td width="30" bgcolor="#5479d8"><span class="button">Status</td>
<td width="75" bgcolor="#5479d8"><span class="button">Options</td>
<tr>
EOF
while (($incident_id, $incident_entry_time, $incident_status, $incident_name, $incident_severity, $incident_handler) = $statement2->fetchrow) {
print <<EOF;
<td width="150"><a href="pix_event_view?id=$incident_id"><span class="table">$incident_name</span></td>
<td width="75"><span class="main">$incident_handler</td>
<td width="50"><span class="main">$incident_entry_time</td>
<td width="30"><span class="main">$incident_severity</td>
<td width="30"><span class="main">$incident_status</td>
<td width="75"><a href="pix_event_view?id=$incident_id"><span class="bodylink">[ view ]</span></a> <a href="pix_event_edit?id=$incident_id"><span class="bodylink">[ edit ]</span></a> <a href="pix_event_management?remove_incident=true&id=$incident_id"><span class="bodylink">[ remove ]</span</a></td>
<tr>
EOF
}

print <<EOF;
</table>
EOF
$db_handle->disconnect();

