This script is designed to handle user input regarding golf courses. It checks the information entered against its database of known sites. If it is a new entry, it adds the site to the database. If the entry already exists and all the data matches, it rerecords the information. If the new information doesn't match, it sends an e-mail to me with the old data and new data for comparison.

#!/usr/bin/perl
$home=$ENV{"HOME"};
require "$home/lib/cgi-lib.pl";

&ReadParse;
$yard_fill = $par_fill = "";
$ending = "</font></td>\n";
$estart = "<td><font size=-1><input type= \"text\" size= \"8\" name= \"";
$noestart = "<td><font size=-1><input type= \"hidden\" name= \"";
$yard = "a_holelength\" value= ";
$par = "b_holepar\" value= ";
$handicap = "c_holehandicap\"></font></td>\n";
$own = "d_holeownscore\"></font></td>\n";
$club = "e_holeclubused\"></font></td>\n";
$putts = "f_holenumputts\"></font></td>\n";
$gir = "g_holegir\"></font></td>\n";
$fairway = "h_holefairway\"></font></td></tr>\n";

# This portion of the script is used to parse out the
# information that has been entered by the referring page
foreach $key (sort keys %in)
{
$in{$key} =~ s/[+=#!;><&\*`\-|]|exec|Exec|EXEC|cmd|Cmd|CMD//g;
}
if(!$in{"dirname"})
{
print "Location: http://generic.com/pchart/login.html", "\n\n";
}
if($in{"button"} ne "Continue")
{
$tripped = 1;
}
if($in{"button"} ne "Skip")
{
$input_string = $in{"coursestate"}."=".$in{"coursecity"}."=".$in{"coursename"}."=".$in{"courserate"};
$db= "coursedb.txt";
open (DB,$db); # opens the coursedb.txt file
@db=<DB>;
close (DB);
$szdb="" . @db;
$course_found = 0;
$list_location = 0;
$dbcount = 0;
while($dbcount < $szdb) # This section checks to see if the course already exists.
{
if($db[$dbcount] =~ /$in{"coursestate"}/)
{
if($db[$dbcount] =~ /$in{"coursecity"}/)
{
if($db[$dbcount] =~ /$in{"coursename"}/)
{
$course_found = 1;$list_location = $dbcount;
}
}
}
$dbcount++;
}
$write_count = 1;
while($write_count <= 18)
{
# This section sets up the golf course pars
# it checks for front and back 9, and places
# the par in the appropriate place.
if($write_count <= 9)
{
$par_string = "par0" . $write_count; $yard_string = "yard0" . $write_count;
}
else
{
$par_string = "par" . $write_count; $yard_string = "yard" . $write_count;
}
$input_string .= "=" . $in{"$par_string"} . "=" . $in{"$yard_string"};
$write_count ++;
}
if($course_found)
{
# This sections handles scenarios of the course already existing
# If it has different values than what is already there
# it will send me an e-mail letting me know the values.
if(!$input_string eq $db[$list_location])
{
open(MAIL, "|smtpsend");
print MAIL <<end_of_text;
To: scot\@vquill.com
From: "course.cgi" <scot\@vquill.com>
Subject: Duplicate courses, different values.

Old Course Info: $db[$list_location]

New Course Info: $input_string
end_of_text
close(MAIL);
}
}
else # Otherwise, go ahead and write the data
{
open(DBAGAIN, ">>" . $db);
print DBAGAIN $input_string . "\n";
close(DBAGAIN);
}
}
if(!$tripped) # This section generates the HTML allowing you to enter another course
{
$dirname = $in{"dirname"};
open(FORM, "NewForm.html");
@file = <FORM>;
close(FORM);
$trip = 0;
$count = $hole = 1;
print &PrintHeader;
print $file[0] . "\n" . $file[1] . "\n" . $file[2] . "\n" . $file[3] . "\n";
print "<input type=\"hidden\" value=\"$dirname\" name=\"dirname\">\n";
while($count <= 18)
{
$hole = $count;
print "<tr align= \"center\"><td><font size=-2>$hole</font></td>";
if($count <= 9)
{
$par_string = "par0" . $count; $par_fill = $in{"$par_string"}; $yard_string = "yard0" . $count; $yard_fill = $in{"$yard_string"}; $hole = "0" . $count;
}
else
{
$par_string = "par" . $count; $par_fill = $in{"$par_string"}; $yard_string = "yard" . $count; $yard_fill = $in{"$yard_string"};
}
print $noestart . $hole . $yard . $yard_fill . ">" . $yard_fill. $ending;
print $noestart . $hole . $par . $par_fill . ">" . $par_fill . $ending;
print $estart . $hole . $handicap;
print $estart . $hole . $own;
print $estart . $hole . $club;
print $estart . $hole . $putts;
print $estart . $hole . $gir;
print $estart . $hole . $fairway;
$count++;
}
print $file[4];
print "</form><!--#exec cmd=\"/address\"-->\n</body></HTML>";
}
elsif($in{"button"} ne "Skip")
{
$file = "http://generic.com/pchart/parnhole.html";
open(FORM, $file);
@file = <FORM>;
$trip = 0;
$count = 0;
$szfile = "" . @file;
print &PrintHeader;
while($count < $szfile)
{
if($file[$count] =~ /<\/body|<\/body/)
{
&address;
}
print $file[$count];
if ($file[$count] =~ /<form/ && $trip == 0)
{
print "<input type=\"hidden\" VALUE=\"$dirname\" name=\"dirname\">\n";
$trip = 1;
}
if($file[$count] =~ /<body|<body/)
{
&navad;
}
$count++;
}
close (FORM);
}
else
{
$file = "http://generic.com/pchart/form.html";
open(FORM, $file);
@file = <FORM>;
$trip = 0;
$count = 0;
$szfile = "" . @file;
print &PrintHeader;
while($count < $szfile)
{
if($file[$count] =~ /<\/body|<\/body/)
{
&address;
}
print $file[$count];
if ($file[$count] =~ /<form/ && $trip == 0)
{
print "<input type=\"hidden\" VALUE=\"$dirname\" name=\"dirname\">\n";
$trip = 1;
}
if($file[$count] =~ /<body|<body/)
{
&navad;
}
$count++;
}
close (FORM);
}
exit(0);


Back    Home