#!/usr/local/bin/perl
###################################################################
$logBeginString = " Game Duration: ";
$logBeginString2 = " NOTICE: Game over";
$logBeginString3 = " Soccer game over.";
$logEndString = " HRP(";
$logEndString2 = " Highest Rating:";
$leadingSpaces = 2;
$maxLogAwardsLineCount = 12;
###################################################################
###################################################################
# Import the module that contains the CGI parsing libraries.
use CGI::Lite;
# Import the module that contains MySQL functionality.
use Mysql;
# Import the scoremaster libraries
require "lib.pl";
# Parse the contents of the HTML form and store them in %in.
$cgi = new CGI::Lite;
%in = $cgi->parse_form_data;
###################################################################
###################################################################
&printHeader;
if(($in{'game'} ne "")) {
&displayBoxScore($in{'game'});
}
else {
&printError("Game ID was not specified.");
}
&printFooter;
###################################################################
###################################################################
sub displayBoxScore {
my($game) = $_[0];
my($dbString, @rows, @lines);
&printLocalHeader("Powerball Box Score");
if(!($dbh = Mysql->connect($hostname, $database, $user_r, $password_r))) {
printError("Could not connect to the database.");
return(0);
}
# Retrieve data about this game
if(!&getMatchInfo($game)) {
&printError("Match not found!");
}
$league = $matchLeague;
&getLeagueInfo($league);
&getAllTeamInfo($league);
print "
\n";
print "\n";
print "\n";
print "| $fontOpenLeague:$fontClose | \n";
print "$fontOpen$leagueName$fontClose | \n";
print "
\n";
print "\n";
print "| $fontOpenGame ID:$fontClose | \n";
print "$fontOpen$game$fontClose | \n";
print "
\n";
print "\n";
print "| $fontOpenRound:$fontClose | \n";
print "$fontOpen$matchWeek$fontClose | \n";
print "
\n";
if($matchComplete ne "Y") {
print "\n";
print "| $fontOpenMatchup:$fontClose | \n";
print "$fontOpen $teams{$matchTeam1} vs $teams{$matchTeam2} $fontClose | \n";
print "
\n";
}
print "
\n";
if($matchComplete eq "Y") {
print "\n";
print "\n";
print "| $fontOpenScore:$fontClose | \n";
print "$fontOpen\n";
if($matchScore1 >= $matchScore2) {
print "$teams{$matchTeam1} $matchScore1, $teams{$matchTeam2} $matchScore2\n";
}
else {
print "$teams{$matchTeam2} $matchScore2, $teams{$matchTeam1} $matchScore1\n";
}
if($matchOT eq "Y") {
print "(Overtime)\n";
}
if($matchForfeit eq "Y") {
print "(Forfeit)\n";
}
print "$fontClose | \n";
print "
\n";
print "\n";
print "| $fontOpenMVP:$fontClose | \n";
print "$fontOpen", &checkNull($matchMVP), "$fontClose | \n";
print "
\n";
print "\n";
print "| $fontOpenComments:$fontClose | \n";
print "$fontOpen", &checkNull($matchComments), "$fontClose | \n";
print "
\n";
print "
\n";
}
if(!open(FILE, "$logDir/$matchLogFile")) {
&printError("Log file not found: $logDir/$matchLogFile");
}
@lines = ;
close(FILE);
&parseScoringSummary(\@lines);
print "\n";
&parsePlayerStats(\@lines);
print "\n";
&printMenu($league);
}
###################################################################
###################################################################
sub parseScoringSummary {
my($lines) = $_[0];
my($line, $goalFlag, $scorer, $scoreFlag, $wScore, $jScore);
print "\n";
print "\n";
print "| $fontOpen Warbirds $fontClose | \n";
print "$fontOpen Javelins $fontClose | \n";
print "$fontOpen Scorer $fontClose | \n";
print "$fontOpen Assist $fontClose | \n";
print "
\n";
$goalFlag = 0;
$scoreFlag = 0;
foreach $line(@{$lines}) {
if(($goalFlag == 1) && ($scoreFlag == 1)) {
if($line =~ /^ Assist! by (.*)/) {
$assist = $1;
}
print "\n";
print "| $fontOpen$wScore$fontClose | \n";
print "$fontOpen$jScore$fontClose | \n";
print "$fontOpen$scorer$fontClose | \n";
print "$fontOpen", &checkNull($assist), "$fontClose | \n";
print "
\n";
$goalFlag = 0;
$scoreFlag = 0;
$scorer = "";
$assist = "";
}
if(($goalFlag == 1) &&
($line =~ /^ SCORE: Warbirds:(\d+) Javelins:(\d+)/)) {
$scoreFlag = 1;
$wScore = $1;
$jScore = $2;
}
if(($line =~ /^ Enemy Goal! by (.*)/) ||
($line =~ /^ Team Goal! by (.*)/)) {
$goalFlag = 1;
$scorer = $1;
}
}
print "
\n";
}
###################################################################
###################################################################
sub parsePlayerStats {
my($lines) = $_[0];
my($logLocationCode, $logSeparatorCount, @logAwards, $fieldDefineLine, $logAwardsLineWrapCount);
$logLocationCode = 0;
print "\n";
foreach $line(@{$lines}) {
# Begin stats section
if((($line =~ /^$logBeginString/) ||
($line =~ /^$logBeginString2/) ||
($line =~ /^$logBeginString3/))) {
splice(@displayedLinesTemp, 0, @displayedLinesTemp);
push(@displayedLinesTemp, "$line");
$logLocationCode = 1;
next;
}
# First line of stats section = column headings
elsif($logLocationCode == 1) {
# Print these things verbatim without moving ahead
if(($line =~ /^$logBeginString/) ||
($line =~ /^$logBeginString2/) ||
($line =~ /^$logBeginString3/) ) {
push(@displayedLinesTemp, "$line");
next;
}
@columnHeadings = split(/ /, $line);
push(@displayedLinesTemp, "$line");
$logLocationCode = 2;
next;
}
# Field define line
elsif($logLocationCode == 2) {
$logLocationCode = 3;
$fieldDefineLine = $line;
push(@displayedLinesTemp, "$line");
next;
}
elsif($logLocationCode == 3) {
if($line =~ /^$fieldDefineLine/) {
$logLocationCode = 4;
}
push(@displayedLinesTemp, "$line");
next;
}
elsif($logLocationCode == 4) {
if($line =~ /^$fieldDefineLine/) {
$logLocationCode = 5;
}
push(@displayedLinesTemp, "$line");
next;
}
elsif($logLocationCode == 5) {
if((($line =~ /^ (\w|\s)+\:/) ||
($line =~ /^ (.+)\(.+\)\:/)) &&
($line !~ /^ (.+)\(\d+\) killed by:/)) {
if(@wrappedLines > 0) {
foreach $wl(@wrappedLines) {
push(@displayedLinesTemp, "$line");
}
splice(@wrappedLines, 0, @wrappedLines);
}
push(@displayedLinesTemp, "$line");
}
else {
$logAwardsLineWrapCount++;
push(@wrappedLines, $line);
if($logAwardsLineWrapCount > 4) {
$logLocationCode = 6;
#print "\n";
}
}
}
}
foreach $dl(@displayedLinesTemp) {
print $dl;
}
if($logLocationCode > 0) {
print "\n";
}
print "\n";
foreach $line(@logAwards) {
print $line;
}
print "\n";
print "\n";
return(1);
}
###################################################################