#!/usr/bin/perl
use constant;
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

my $alumdbfile = "alumdb.csv";
my $collegedbfile = "collegedb.csv";

print <<HTML;
Content-type: text/html\n\n


<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<TITLE>Roncallialum.com - Alumni Search Results</TITLE>
<meta name="generator" content="RedHat Linux 7.1 and Perl">
<meta name="keywords" content="roncallialum.com, roncalli high school, roncalli catholic high school, roncalli, manitowoc roncalli, manitowoc, wisconsin">
<meta name="author" content="Michael J. Matczynski">
<SCRIPT>
    function clearSearch()
{
    document.search._lname.value = ""
    document.search._fname.value = ""
    document.search._school.value = ""
    document.search._major.value = ""

}
</SCRIPT>

</HEAD>
<BODY>
HTML

open(DBFILE, $alumdbfile) or die "The file $alumdbfile could not be found.\n";
open(COLFILE, $collegedbfile) or die "The file $collegedbfile could not be found.\n";

my ($_fname, $_lname, $_school, $_major, $_year);
$_fname = param ('_fname');
$_lname = param ('_lname');
$_school = param ('_school');
$_major = param ('_major');
$_year = param ('_year');

print <<HTML;
<FORM ACTION="./search.pl" NAME="search" METHOD="GET">
<table border=1 cellspacing=2 cellpadding=2 width=400>
<td colspan=3 bgcolor="navy"><h2><font color="#0099CC">Roncalli Alumni Search</font></h2></td><tr>
<td>Last: </td><td><INPUT TYPE="TEXT"  NAME="_lname" VALUE="$_lname" SIZE="20"></td><td rowspan=4><INPUT TYPE="SUBMIT" VALUE="Search"><BR><BR>
<INPUT TYPE="BUTTON" NAME="resetme" VALUE=" Reset  " onclick="clearSearch()"></td><tr>
<td>First: </td><td><INPUT TYPE="TEXT"  NAME="_fname" VALUE="$_fname" SIZE="20"></td><tr>
<td>School: </td><td><INPUT TYPE="TEXT"  NAME="_school" VALUE="$_school" SIZE="20"></td><tr>
<td>Major: </td><td><INPUT TYPE="TEXT"  NAME="_major" VALUE="$_major" SIZE="20"></td><tr>
</table>
</FORM>
<p>
<FORM ACTION="./search.pl" NAME="browse" METHOD="GET">
<input type="hidden" name="_year" value="2001">
<table border=1 cellspacing=2 cellpadding=2 width=400>
<td colspan=2 bgcolor="navy"><h2><font color="#0099CC">Browse By Year...</font></h2></td><tr>
<td></td><td><input type="submit" value="2001 Graduates"></td><tr>
</table>
</form>
<p>
<table border=1 cellspacing=2 cellpadding=2 width=90%>
<td colspan=4 bgcolor="navy"><h2><font color="#0099CC">Search Results:</font></h2></td><tr>
HTML

    my $totalmatch = 0;

my $firsttime = 1;


while(<DBFILE>)
{
    # remove the top record, which is header info
    if ($firsttime == 1)
    {
	$firsttime = 0;
	next;
    }
    my $record = $_;

    my ($lname, $fname, $school, $major, $year, $email);

    # split record against tab characters
    ($lname, $fname, $school, $major, $year, $email) = split(/\t/, $record);

    my $searchcount = 0;
    my $searchfound = 0;

    if ($_fname ne "")
    {
	$searchcount++;
	if (lc($fname) =~ lc($_fname)) { $searchfound++; }
    }    
    if ($_lname ne "")
    {
	$searchcount++;
	if (lc($lname) =~ lc($_lname)) { $searchfound++; }
    }
    if ($_school ne "") 
    {
	$searchcount++;
	if (lc($school) =~ lc($_school)) { $searchfound++; }
    }
    if ($_major ne "") 
    {
	$searchcount++;
	if (lc($major) =~ lc($_major)) { $searchfound++; }
    }
    if ($_year ne "")
    {
	$searchcount++;
	if  (($year) =~ ($_year))
	{
	    $searchfound++;
	}
    }

    if($searchcount == 0)
    {
	# exit loop, nothing in search boxes
	print "<td colspan=4>Please fill in one or more fields</td><tr>";
	last;
    }

    if($searchfound == $searchcount)
    {
	$totalmatch++;

	my ($city, $state, $colwebaddr);

	seek(COLFILE, 0, 0);
	while(<COLFILE>)
	{
	    my $colrecord = $_;
	    if( lc($colrecord) =~ lc($school) )
	    {
		my $temp;
		($temp, $city, $state, $colwebaddr) = split(/\t/, $colrecord);
		last;
	    }
	}
    
print <<HTML;
<td colspan=4 bgcolor="navy"><b><font color="#0099CC">$lname, $fname - $year</font></b><tr>
<td rowspan=2> </td><td><a href="http://$colwebaddr">$school</a></td><td>$city</td><td>$year</td><tr>
                    <td>$major</td><td>$state</td><td><a href="mailto:$email">$email</a></td><tr>
HTML
    }

}

print qq(
</TABLE>
<p>
<b><center>Matches found: $totalmatch</b>
<BR>
<br>
<center>
[ <a href="http://www.roncallialum.com/">Home</a> | Alumni Search | <a href="http://www.roncallialum.com/disc9_frm.htm">Boards</a> | <a href="http://www.roncallialum.com/Faqs.htm">FAQs</a> | <a href="http://www.roncallialum.com/Links.htm">Links</a> | <a href="http://www.roncallialum.com/Geeks.htm">Geeks</a> ]
</center>
<br>
<br>
This alumni search includes technology that was designed, developed, and implemented by Michael J. Matczynski and <a href="http://www.zingtech.com/">Zingtech (www.zingtech.com)</a>. <br>
Database content created and updated with the help of Matthew Wolff.<br>
Any modification without prior written consent of Zingtech is strictly prohibited.<br>
(C) 2001 Michael J. Matczynski</center>);

print end_html();
print qq(<font color="#FFFFFF">);