#!/usr/bin/perl

$ext = '300';

$l = 'ncaalog400';
$reshand = 'ncaaresults';

if (-e "football/hoopla/$l") {
    $count = 1;
    open (LOG, "football/hoopla/$l") or die "Can't open log file:$!\n";
    while ($line = <LOG>) {
        chop $line;
        ($first[$count], $last[$count], $bet[$count]) = split /\t/, $line;
        if (($first[$count] ne '') and ($last[$count] ne '')) {
        $count += 1;
    }
    }
}
else {
    print "Content-type: text/html\n\n";

    print <<"HTML code";

<html>
<head>
<title>HooPLA Competition</title>
<head>
<body>

Sorry, no one has made picks for the competition yet.

</body>
</html>

HTML code
}

for $x (1..$#first) {
    $handle[$x] = join '',$first[$x],$last[$x],$ext,$bet[$x];
    $handle[$x] =~ tr/A-Z/a-z/;
}

for $x (1..$#handle) {
    open (HAND, "football/hoopla/$handle[$x]") or die "Can't open $x file:$!\n";
    $count = 1;
    while ($line = <HAND>) {
	chop $line;
	$Game[$x][$count] = $line;
	$count += 1;
    }
}

if (-e "football/hoopla/$reshand") {
    open (RES, "football/hoopla/$reshand") or die "Can't open file:$!\n";
    $count = 1;
    while ($line = <RES>) {
        chop $line;
        ($winner[$count], $loser[$count]) = split /\t/, $line;
        $count += 1;
    }
}

for $x (1..$#Game) {
    for $y (1..$#{$Game[$x]}) {
	if ($Game[$x][$y] eq $winner[$y]) {
	    $temp = join '',"<b>",$Game[$x][$y],"</b>";
	    $Game[$x][$y] = $temp;
	    $temp = '';
	}
        else {
            $switch = 0;
            for $z (1..$#loser) {
                if ($Game[$x][$y] eq $loser[$z]) {
                    $switch = 1;
                }
            }
            if ($switch == 1) {
                $temp = join '',"<font color=#FF0000>",$Game[$x][$y],"</font>";
                $Game[$x][$y] = $temp;
                $temp = '';
            }
        }
    }
}

print "Content-type: text/html\n\n";

print <<"HTML code";

<html>
<head>
<title>HooPLA Picks</title>
<head>
<body>

HTML code

    print "<TABLE width=500>\n";

sub headers {
    print "<TR><TD><b><center>$region</center></b>";
    for $x (1..$#first) {
	print "<TD>|<TD><center>$first[$x]</center>";
    }
    print "\n";

    print "<TR><TD><b><center></center></b>";
    for $x (1..$#last) {
	print "<TD>|<TD><center>$last[$x]</center>";
    }
    print "\n";

    print "<TR><TD><hr>";
    for $x (1..$#last) {
	print "<TD><TD><hr>";
    }
}

sub underline {
    print "<TR><TD><hr>";
    for $x (1..$#last) {
	print "<TD><TD><hr>";
    }
    print "\n";
}

$region="Midwest";
$round="First Round";

headers;

for $y (1..8) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
	print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="West";

headers;

for $y (9..16) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="South";

headers;

for $y (17..24) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="East";

headers;

for $y (25..32) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$round="Second Round";
$region="Midwest";

headers;

for $y (33..36) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="West";

headers;

for $y (37..40) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="South";

headers;

for $y (41..44) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="East";

headers;

for $y (45..48) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$round="Semifinals";
$region="Midwest";

headers;

for $y (49..50) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="West";

headers;

for $y (51..52) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="South";

headers;

for $y (53..54) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="East";

headers;

for $y (55..56) {
    print "<TR><TD><b><center>$round</center></b>";
    for $x (1..$#last) {
        print "<TD><TD><center>$Game[$x][$y]</center>";
    }
    print "\n";
}

underline;

$region="Regional Finals";
headers;

print "<TR><TD><b><center>Midwest</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][57]</center>";
}
print "\n";
print "<TR><TD><b><center>West</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][58]</center>";
}
print "\n";
print "<TR><TD><b><center>South</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][59]</center>";
}
print "\n";
print "<TR><TD><b><center>East</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][60]</center>";
}
print "\n";

underline;

$region="Final Four";
headers;

print "<TR><TD><b><center>Semifinals</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][61]</center>";
}
print "\n";
print "<TR><TD><b><center>Semifinals</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][62]</center>";
}
print "\n";
print "<TR><TD><b><center>Championship</center></b>";
for $x (1..$#last) {
    print "<TD><TD><center>$Game[$x][63]</center>";
}
print "\n";

underline;

print "</TABLE>\n";

print "</body>\n";
print "</html>\n";









