# /*   $Id: bcnuqrylib.pl,v 1.4 1999/11/10 10:47:46 jap Exp $
#
# *    Copyright (c) 1998 John Phillips
# *
# *    You may distribute under the terms of the Artistic License
# *
# */
#

sub selectform {

$first="SELECTED";
$logselect="<SELECT SIZE=2 MULTIPLE NAME=\"logfile\">";
foreach $logfile (reverse sort (@displog)) {
	$logselect .= "<OPTION $first VALUE=$logfile>$logfile" ;
	$first="";
	}
$logselect .="</SELECT>";

$hostselect="<SELECT NAME=\"host\"> <OPTION  VALUE=\.*>All";
foreach $host (sort (@hosts)) {
	$hostselect .= "<OPTION  VALUE=$host>$host" ;
	}
$hostselect .="</SELECT>";

$agentselect="<SELECT NAME=\"agent\"> <OPTION  VALUE=\.*>All";
foreach $agent (sort (@agentlog)) {
	$agentselect .= "<OPTION  VALUE=$agent>$agent" ;
	}
$agentselect .="</SELECT>";

$form = <<"Endofform";

</TABLE>
<H2>Please select criteria for query</H2>
<TABLE BORDER=0>
<FORM METHOD="POST"> 
<TR><TH $DEFCELL>Date</TH><TH $DEFCELL>System</TH><TH $DEFCELL>Agent</TH></TR>
<TR>
<TD>$logselect</TD>
<TD>$hostselect</TD>
<TD>$agentselect</TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="normal" VALUE="0" CHECKED>normal
<TD><INPUT TYPE="checkbox" NAME="errors" VALUE="9" CHECKED>errors
<TD><INPUT TYPE="checkbox" NAME="warnings" VALUE="5-8" CHECKED>warnings
<TR>
<TH>Record Limit
<TD><SELECT NAME=\"limit\"> 
<OPTION  VALUE=$QRYLIMIT>$QRYLIMIT
<OPTION  VALUE=100>100
<OPTION  VALUE=250>250
<OPTION  VALUE=500>500
</SELECT>
<TD ALIGN=CENTER $CELL><INPUT TYPE="submit" NAME="submit" VALUE="View"></TR>
</FORM>
</TABLE>
<P>
Endofform

return ($form);
}


sub gethist {

open (HIST,"$DATA/$inlogfile.log") || &bcnuerror("Query", "can't open $DATA/$inlogfile.log");

while (<HIST>)
	{
	
	@rec = split(":",$_);

	$type	= $rec[1];
	$host   = $rec[2];
	$ag     = $rec[4];
	$time   = $rec[5];

	if ( ($host =~ /^$inhost$/) && ($ag =~ /$inagent$/) && ($type =~ /[$innormal$inerrors$inwarnings]/)) {
#	if ( ($host =~ /^$inhost$/) && (grep($ag,@inagent)) && ($type =~ /[$innormal$inerrors$inwarnings]/)) {

		@record{$host.$ag.$time} = $_;
		return if $readrecs == $inlimit;
		$readrecs++;
		}
	}
return;
}

sub gethistrec {

open (HIST,"$DATA/$inlogfile.log") || &bcnuerror("Query", "can't open $DATA/$inlogfile.log");

$indtime =~ s/%20/ /;

while (<HIST>)
	{
	
	@rec = split(":",$_);

	$host   = $rec[2];
	$ag     = $rec[4];
	$time   = $rec[5];

	if ( ($host =~ /^$inhost$/) && ($ag =~ /$inagent/) && ($time =~ /$indtime/)) {

		$rec = $_;
		return $rec;
		}
	}
return 0;
}

1;
