#!/usr/bin/perl
#
# Filename: myteam/submit.cgi
# URL: http://www.whockey.com/myteam/submit.cgi
#   by Andria Hunter (andria@whockey.com)
#   March 24, 2000
#
# This script is used to submit information for hockey team listings.
# The information in the submission form includes the country
# and year of the team, which is used to determine which
# directory the team submission will be placed in.  Each
# directory stores a counter file ($DATAFILE) which contains
# an integer that stores the next file name to use for that
# country (the initial value in the counter file should be 999999).
# Each time a new team listing is entered, this integer
# is increased by 1.
#
# After the year 2099, you should change the $cent= line in the
# GetDate subroutine.
#
# If you want team listings beyond the year 2004 to be submitted,
# some text in this form must be changed.  Search for 2004 to
# identify these sections of code.
#
# There are 3 different ways this script may be envoked:
#    1. With no command line arguments.
#    2. With form data (COMMAND=SUBMITTEAM).
#    3. With form default info (COMMAND=KNOWNDEFAULTS).
#
# Credits:
#   Some code in this script was borrowed from:
#     - Data file creation from wwwboard.pl (Matt Wright)
#     - Interface from comments.pl (Matt Kruse)
#
# ------------------------------------------------------------

# Variable Initialization
# -----------------------
$PAGENAME="index.html";
$DATAFILE="data.txt";
$BASEADDR="/www/whockey/myteam";
$BASEHTML="myteam";
$SCRIPTNAME="submit.cgi";
$EXT = "html";

# By default, these values are selected in the form.
$DEFAULTCOUNTRY = "usa";
$DEFAULTSEASON = "2000";

# 2 Subroutines from cgi-lib.pl
# -----------------------------
# Copyright 1994 Steven E. Brenner.  Unpublished work.
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus and Dave Dittrich.

sub ReadParse {
  local (*in) = @_ if @_;
  local ($i, $loc, $key, $val);

  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $in = $ENV{'QUERY_STRING'};
  }
  elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  }

  # Splits up a line of the form COMMAND=a&VAL1=b&VAL2=c
  # so that the left side of each equals sign is a new variable
  # with an initial value given on the right side of equals sign.
  @in = split(/&/,$in);
  foreach $i (0 .. $#in) {
    $in[$i] =~ s/\+/ /g;
    ($key, $val) = split(/=/,$in[$i],2);   # splits on the first =.
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
    $in{$key} .= $val;
  }

  return 1;  # just for fun
}

sub PrintHeader {
  return "Content-type: text/html\n\n";
}

# Make calls to the subroutines above
# -----------------------------------
# This reads in the information from the forms.

&ReadParse(*input);
print &PrintHeader;

# Subroutine to get date
# ---------------------------
sub GetDate {
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

  # Make sure all fields have 2 digits.
  if ($min < 10) {
    $min = "0$min";
  }
  if ($hour < 10) {
    $hour = "0$hour";
  }
  if ($mon < 10) {
     $mon = "0$mon";
  }
  if ($mday < 10) {
     $mday = "0$mday";
  }

  # In the year 2000, the year variable will store "100" so fix this
  # by subtracting 100 from all years after 1999. 
  if ($year > 99) {
    $year = $year - 100;
  }
  if ($year < 10) {
    $year = "0$year";
  }

  # Months are in range 0..11 so add 1, and then ensure 2 digits.
  $month = ($mon + 1);
  if ($month < 10) {
     $month = "0$month";
  }

  # This program will not work beyond the year 2099.
  $cent = "20";

  # To get date as "Oct 13, 1994 at 04:54"
  @months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  $DATE = "$months[$mon] $mday, $cent$year at $hour\:$min";

  # To get date as "94/10/13 04:54"
  # $short_date = "$year/$month/$mday $hour\:$min";
  # chop($short_date) if ($short_date =~ /\n$/);

  # To get date as "Thu Oct 13 04:54:34 1994"
  # $default_date = localtime;
}

# Subroutine to get file number
# -----------------------------
# Read the number from the datafile, and set $NUM variable to this value.

sub GetNumber {
  open(NUMBER,"$BASEADDR/$COUNTRY/$DATAFILE");
  $NUM = <NUMBER>;
  close(NUMBER);
  if ($NUM == 999999)  {
    $NUM = "1";
  }
  else {
    $NUM++;
  }
}

# Subroutine to increment file number
# -----------------------------------
# Print the value of the $NUM variable into the datafile.

sub IncNumber {
   open(NUM,">$BASEADDR/$COUNTRY/$DATAFILE") || die $!;
   print NUM "$NUM\n";
   close(NUM);
}

# Subroutine to check for empty responses
# ---------------------------------------
# This subroutine is called if someone has not entered all
# required fields in the form.

sub BadResponse {
  print <<EOF;
<HTML><HEAD>
<TITLE>Data Entry Error</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#0000A0">
<H1>Data Entry Error</H1>
<HR NOSHADE>
<P>
You have left some of the required data fields in the form blank.  The
only field that you are not required to fill in is the e-mail field.
All other fields must be filled.
<P>
Please go back and fill in all the required fields.  <B>Click the
"back" button on your web brower to return to the team photo submission
form.</B>
</P>
<HR NOSHADE>
</BODY>
</HTML>
EOF
  exit(0);
}

# Subroutine to print submission acknowledgement
# ----------------------------------------------
# This subroutine is called after the team photo has been
# successfully added to the listing.  It thanks the
# user for submitting the tournament.

sub PrintThankYou {
  print <<EOF;
<!-- Copyright 1998 Andria L Hunter. All Rights Reserved. -->
<!-- Created March 2000. andria\@whockey.com -->
<BASE HREF="http://www.whockey.com/">
<HTML><HEAD>
<TITLE>Thank You for your Submission</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#0000A0">
<CENTER>
<H1>Thank You for your Submission</H1>
</CENTER>
<HR NOSHADE>

<P>
The text that you have just entered for your team listing has been
successfully added to the women's hockey web.

<P>
To complete your team listing, you now need to send your team photo
(either JPG or GIF) as an attachment, by e-mail to
andria\@whockey.com.  When you send your e-mail, the subject of your
message must be <B>$COUNTRY/$SEASON/$NUM.$EXT</B>.  (Please write this
down, so you don't forget.)

<P>
The team picture will not show up right away, but the other information
that you have just submitted for your team is available immediately.
Please click below to review your listing.
<UL>
<LI>
<A HREF="$BASEHTML/$COUNTRY/$SEASON/$NUM.$EXT">$TEAMNAME</A>
- <I>$NAME</I>
</UL>

<P>
If any changes need to be made for your listing, please resubmit your
team's information, and send me e-mail (andria\@whockey.com) to tell
me to delete the older listing.

<P>
If you do not have a picture of your team in a computer file, please
e-mail me (subject of message should be
<B>$COUNTRY/$SEASON/$NUM.$EXT</B>), and I'll tell you where you can
send a photograph using regular mail.  When your photo arrives, I will
scan it in and add it to your team's web page.

<P>
Thanks!<BR>
The Women's Hockey Web
</P>

<HR NOSHADE>
<CENTER><H4>
[ <A HREF="$BASEHTML/">All Team Photo Listings</A> |
<A HREF="$BASEHTML/$COUNTRY/">Team Photo Listings for $UPPERCOUNTRY</A> ]<BR>
[ <A HREF="$BASEHTML/$SCRIPTNAME?COMMAND=KNOWNDEFAULTS\&country=$COUNTRY&season=$SEASON">
Submit Your Team Photo</A> ]
</H4></CENTER>

<!----------- BEGIN INDEX ----------->
<HR NOSHADE SIZE=3>
This page is maintained by &copy; 1998
<A HREF="andria/">Andria Hunter</A>
(<A HREF="guest/submit.html">andria\@whockey.com</A>).<BR><BR>
<TABLE BORDER=5 WIDTH=100%>
<TR BGCOLOR="#AABBCC">
<TH COLSPAN=4><FONT SIZE=+2>The Women's Hockey Web
- <A HREF="quick.html">
<FONT COLOR=RED>Quick Index</FONT></A><FONT SIZE=-2></TH>
</TR>
<TR BGCOLOR="#CCDDEE">
<TH WIDTH=33%>
Main Index:<BR>
<A HREF="general/">General Info</A><BR>
<A HREF="int/">International</A><BR>
<A HREF="country/">Country</A> |
<A HREF="univ/">University</A><BR>
<A HREF="profile/">Player Profiles</A><BR>
<A HREF="card/">Hockey Cards</A><BR>
<A HREF="links.html">Links</A> |
<A HREF="faq/">FAQ</A><BR>
<HR>Resources:<BR>
<A HREF="tourney/">Tournaments</A><BR>
<A HREF="school/">Hockey Schools</A><BR>
<TH>
Women's<BR>
<A HREF="http://www.whockey.com/">
<IMG SRC="gifs/whockey/sidelogo.gif" WIDTH=90 ALIGN=CENTER></A><BR>
Hockey Web<BR>
<TH>
Andria's<BR>
<A HREF="andria/">
<IMG SRC="gifs/small/Andria_magazine_92.gif" ALIGN=CENTER></A><BR>
Homepage<BR>
<TH>
Hockey Tips:<BR>
<A HREF="tip/shooting/">Shooting</A> |
<A HREF="tip/skating/">Skating</A><BR>
<A HREF="tip/playing/">Playing</A><BR>
<HR>Other Women's Sports:<BR>
<A HREF="inline/">Inline Hockey</A><BR>
<A HREF="roller/">Roller Hockey</A><BR>
<A HREF="ball/">Ball Hockey</A><BR>
<A HREF="broomball/">Broomball</A><BR>
<A HREF="ringette/">Ringette</A><BR>
</TH>
</TR>
</TABLE>
<!----------- END INDEX ----------->
<PRE>URL:  http://www.whockey.com/$BASEHTML/$SCRIPTNAME</PRE>
</BODY>
</HTML>
EOF
  exit(0);
}

# Subroutine to determine season range
# ------------------------------------
# This subroutine converts the $SEASON value which is a single
# integer (such as 1999) to a season range (1998 - 1999)
# variable called $SEASONRANGE.

sub GetSeasonRange {
  if ($SEASON eq '1995') {
     $SEASONRANGE = "1994 - 1995";
  }
  elsif ($SEASON eq '1996') {
     $SEASONRANGE = "1995 - 1996";
  }
  elsif ($SEASON eq '1997') {
     $SEASONRANGE = "1996 - 1997";
  }
  elsif ($SEASON eq '1998') {
     $SEASONRANGE = "1997 - 1998";
  }
  elsif ($SEASON eq '1999') {
     $SEASONRANGE = "1998 - 1999";
  }
  elsif ($SEASON eq '2000') {
     $SEASONRANGE = "1999 - 2000";
  }
  elsif ($SEASON eq '2001') {
     $SEASONRANGE = "2000 - 2001";
  }
  elsif ($SEASON eq '2002') {
     $SEASONRANGE = "2001 - 2002";
  }
  elsif ($SEASON eq '2003') {
     $SEASONRANGE = "2002 - 2003";
  }
  elsif ($SEASON eq '2004') {
     $SEASONRANGE = "2003 - 2004";
  }
  elsif ($SEASON eq '2005') {
     $SEASONRANGE = "2004 - 2005";
  }
  else {
     $SEASONRANGE = "UNDEFINED SEASON";
  }
}

# Subroutine to capitalize the Country
# ------------------------------------
# This subroutine converts the $COUNTRY value which is in
# lowercase string to an uppercase $UPPERCOUNTRY.  The lowercase
# is useful for directory names, but doesn't look good in the
# contents of the pages.

sub GetCountryCaps {
  if ($COUNTRY eq 'usa') {
     $UPPERCOUNTRY = "USA";
  }
  elsif ($COUNTRY eq 'canada') {
     $UPPERCOUNTRY = "Canada";
  }
  elsif ($COUNTRY eq 'europe') {
     $UPPERCOUNTRY = "Europe";
  }
  elsif ($COUNTRY eq 'asia') {
     $UPPERCOUNTRY = "Asia";
  }
  elsif ($COUNTRY eq 'australia') {
     $UPPERCOUNTRY = "Australia";
  }
  elsif ($COUNTRY eq 'other') {
     $UPPERCOUNTRY = "Other Country";
  }
  else {
     $UPPERCOUNTRY = "UNDEFINED COUNTRY";
  }
}

# Subroutine to create new listing
# --------------------------------
# This is the page that is created (using filename $NUM.$EXT)
# to store the information that has been entered for the
# team listing.

sub CreateListing {
  open(NEWFILE,">$BASEADDR/$COUNTRY/$SEASON/$NUM\.$EXT") || die $!;
  print NEWFILE "<!-- Copyright 1998 Andria L Hunter. All Rights Reserved. -->\n";
  print NEWFILE "<!-- Created March 2000. andria\@whockey.com -->\n";
  print NEWFILE "\n";
  print NEWFILE "<BASE HREF=\"http://www.whockey.com/\">\n";
  print NEWFILE "\n";
  print NEWFILE "<HTML><HEAD>\n";
  print NEWFILE "<TITLE>$TEAMNAME - $CITY</TITLE>\n";
  print NEWFILE "</HEAD>\n";
  print NEWFILE "\n";
  print NEWFILE "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#0000A0\">\n";
  print NEWFILE "<CENTER>\n";
  print NEWFILE "<H3>$TEAMNAME<BR>\n";
  print NEWFILE "$CITY<BR>\n";
  print NEWFILE "$SEASONRANGE</H3>\n";
  print NEWFILE "<IMG SRC=$BASEHTML/$COUNTRY/$SEASON/$NUM.jpg WIDTH=400>\n";
  print NEWFILE "</CENTER>\n";
  print NEWFILE "\n";
  print NEWFILE "<H4>Team Information</H4>\n";
  print NEWFILE "<PRE><FONT SIZE=2>\n";
  print NEWFILE "$DETAILS\n";
  print NEWFILE "\n";
  print NEWFILE "\n";
  print NEWFILE "</FONT></PRE>\n";
  print NEWFILE "\n";
  print NEWFILE "<H4>Additional Information</H4>\n";
  print NEWFILE "<PRE><FONT SIZE=2>\n";
  print NEWFILE "Team Name:       $TEAMNAME\n";
  print NEWFILE "Submitted by:    $NAME\n";
  if ($EMAIL ne '') {
    print NEWFILE "E-mail address:  $EMAIL\n";
  }
  print NEWFILE "Hockey Season:   $SEASONRANGE\n";
  print NEWFILE "City:            $CITY\n";
  print NEWFILE "Country:         $UPPERCOUNTRY\n";
  print NEWFILE "\n";
  print NEWFILE "Date submitted:  $DATE\n";
  print NEWFILE "</FONT></PRE>\n";
  print NEWFILE "\n";
  print NEWFILE "<HR NOSHADE>\n";
  print NEWFILE "<CENTER><H4>\n";
  print NEWFILE "[ <A HREF=$BASEHTML/>All Team Photo Listings</A> |\n";
  print NEWFILE "<A HREF=$BASEHTML/$COUNTRY/>Team Photo Listings for $UPPERCOUNTRY</A> ]<BR>\n";
  print NEWFILE "[ <A HREF=$BASEHTML/$SCRIPTNAME?COMMAND=KNOWNDEFAULTS\&country=$COUNTRY&season=$SEASON>\n";
  print NEWFILE "Submit Your Team Photo</A> ]\n";
  print NEWFILE "</H4></CENTER>\n";
  print NEWFILE "\n";
  print NEWFILE "<!----------- BEGIN INDEX ----------->\n";
  print NEWFILE "<HR NOSHADE SIZE=3>\n";
  print NEWFILE "This page is maintained by &copy; 1998\n";
  print NEWFILE "<A HREF=\"andria/\">Andria Hunter</A>\n";
  print NEWFILE "(<A HREF=\"guest/submit.html\">andria\@whockey.com</A>).<BR><BR>\n";
  print NEWFILE "<TABLE BORDER=5 WIDTH=100%>\n";
  print NEWFILE "<TR BGCOLOR=\"#AABBCC\">\n";
  print NEWFILE "<TH COLSPAN=4><FONT SIZE=+2>The Women's Hockey Web\n";
  print NEWFILE "- <A HREF=\"quick.html\">\n";
  print NEWFILE "<FONT COLOR=RED>Quick Index</FONT></A><FONT SIZE=-2></TH>\n";
  print NEWFILE "</TR>\n";
  print NEWFILE "<TR BGCOLOR=\"#CCDDEE\">\n";
  print NEWFILE "<TH WIDTH=33%>\n";
  print NEWFILE "Main Index:<BR>\n";
  print NEWFILE "<A HREF=\"general/\">General Info</A><BR>\n";
  print NEWFILE "<A HREF=\"int/\">International</A><BR>\n";
  print NEWFILE "<A HREF=\"country/\">Country</A> |\n";
  print NEWFILE "<A HREF=\"univ/\">University</A><BR>\n";
  print NEWFILE "<A HREF=\"profile/\">Player Profiles</A><BR>\n";
  print NEWFILE "<A HREF=\"card/\">Hockey Cards</A><BR>\n";
  print NEWFILE "<A HREF=\"links.html\">Links</A> |\n";
  print NEWFILE "<A HREF=\"faq/\">FAQ</A><BR>\n";
  print NEWFILE "<HR>Resources:<BR>\n";
  print NEWFILE "<A HREF=\"tourney/\">Tournaments</A><BR>\n";
  print NEWFILE "<A HREF=\"school/\">Hockey Schools</A><BR>\n";
  print NEWFILE "<TH>\n";
  print NEWFILE "Women's<BR>\n";
  print NEWFILE "<A HREF=\"http://www.whockey.com/\">\n";
  print NEWFILE "<IMG SRC=\"gifs/whockey/sidelogo.gif\" WIDTH=90 ALIGN=CENTER></A><BR>\n";
  print NEWFILE "Hockey Web<BR>\n";
  print NEWFILE "<TH>\n";
  print NEWFILE "Andria's<BR>\n";
  print NEWFILE "<A HREF=\"andria/\">\n";
  print NEWFILE "<IMG SRC=\"gifs/small/Andria_magazine_92.gif\" ALIGN=CENTER></A><BR>\n";
  print NEWFILE "Homepage<BR>\n";
  print NEWFILE "<TH>\n";
  print NEWFILE "Hockey Tips:<BR>\n";
  print NEWFILE "<A HREF=\"tip/shooting/\">Shooting</A> |\n";
  print NEWFILE "<A HREF=\"tip/skating/\">Skating</A><BR>\n";
  print NEWFILE "<A HREF=\"tip/playing/\">Playing</A><BR>\n";
  print NEWFILE "<HR>Other Women's Sports:<BR>\n";
  print NEWFILE "<A HREF=\"inline/\">Inline Hockey</A><BR>\n";
  print NEWFILE "<A HREF=\"roller/\">Roller Hockey</A><BR>\n";
  print NEWFILE "<A HREF=\"ball/\">Ball Hockey</A><BR>\n";
  print NEWFILE "<A HREF=\"broomball/\">Broomball</A><BR>\n";
  print NEWFILE "<A HREF=\"ringette/\">Ringette</A><BR>\n";
  print NEWFILE "</TH>\n";
  print NEWFILE "</TR>\n";
  print NEWFILE "</TABLE>\n";
  print NEWFILE "<!----------- END INDEX ----------->\n";
  print NEWFILE "<PRE>URL:  http://www.whockey.com/$BASEHTML/$COUNTRY/$SEASON/$NUM.$EXT</PRE>\n";
  print NEWFILE "</BODY>\n";
  print NEWFILE "</HTML>\n";
  close(NEWFILE);
}

# Subroutine to create a link to listing
# --------------------------------------
sub CreateLink {
  open(MAIN,"$BASEADDR/$COUNTRY/$PAGENAME") || die $!;
  @main = <MAIN>;
  close(MAIN);

  open(MAIN,">$BASEADDR/$COUNTRY/$PAGENAME") || die $!;
  foreach $main_line (@main) {
    if ($main_line =~ /<!--begin $SEASON/) {
      print MAIN "$main_line";
      #print MAIN "$DATE\n";
      if ($EMAIL ne '') {
         print MAIN "<A HREF=\"$BASEHTML/$COUNTRY/$SEASON/$NUM\.$EXT\">$TEAMNAME</A>\n";
         print MAIN "- <I><A HREF=\"mailto:$EMAIL\">$NAME</A></I><BR>\n\n";
      }
      else {
         print MAIN "<A HREF=\"$BASEHTML/$COUNTRY/$SEASON/$NUM\.$EXT\">$TEAMNAME</A>\n";
         print MAIN "- <I>$NAME</I><BR>\n\n";
      }
    }
    else {
      print MAIN "$main_line";
    }
  }
  close(MAIN);
}

# Subroutine to print debug information
# -------------------------------------
sub PrintDebug {
$HELLO = $ENV{'QUERY_STRING'};
print <<EOF;
Query String:      $HELLO<BR>
Data File:         $NUM<BR>
New listing:       $BASEADDR/$COUNTRY/$SEASON/$NUM\.$EXT<BR>
Command:           $COMMAND<BR>
Team Name:         $TEAMNAME<BR>
Name:              $NAME<BR>
Email:             $EMAIL<BR>
City:              $CITY<BR>
Season:            $SEASON<BR>
Season Range:      $SEASONRANGE<BR>
Country:           $COUNTRY<BR>
Uppercase Country: $UPPERCOUNTRY<BR>
Details:           $DETAILS<BR>
Date:              $DATE<BR>
EOF
}

# Subroutine to print team listing submission form
# ---------------------------
sub PrintForm {

  # The $DEFAULTSEASON should appear 'selected' in the form.

  $SEASON1995 = "<OPTION VALUE=1995> 1995";
  $SEASON1996 = "<OPTION VALUE=1996> 1996";
  $SEASON1997 = "<OPTION VALUE=1997> 1997";
  $SEASON1998 = "<OPTION VALUE=1998> 1998";
  $SEASON1999 = "<OPTION VALUE=1999> 1999";
  $SEASON2000 = "<OPTION VALUE=2000> 2000";
  $SEASON2001 = "<OPTION VALUE=2001> 2001";
  $SEASON2002 = "<OPTION VALUE=2002> 2002";
  $SEASON2003 = "<OPTION VALUE=2003> 2003";
  $SEASON2004 = "<OPTION VALUE=2004> 2004";

  if ($DEFAULTSEASON eq '1995') {
    $SEASON1995 = "<OPTION VALUE=1995 SELECTED> 1995";
  }
  elsif ($DEFAULTSEASON eq '1996') {
    $SEASON1996 = "<OPTION VALUE=1996 SELECTED> 1996";
  }
  elsif ($DEFAULTSEASON eq '1997') {
    $SEASON1997 = "<OPTION VALUE=1997 SELECTED> 1997";
  }
  elsif ($DEFAULTSEASON eq '1998') {
    $SEASON1998 = "<OPTION VALUE=1998 SELECTED> 1998";
  }
  elsif ($DEFAULTSEASON eq '1999') {
    $SEASON1999 = "<OPTION VALUE=1999 SELECTED> 1999";
  }
  elsif ($DEFAULTSEASON eq '2000') {
    $SEASON2000 = "<OPTION VALUE=2000 SELECTED> 2000";
  }
  elsif ($DEFAULTSEASON eq '2001') {
    $SEASON2001 = "<OPTION VALUE=2001 SELECTED> 2001";
  }
  elsif ($DEFAULTSEASON eq '2002') {
    $SEASON2002 = "<OPTION VALUE=2002 SELECTED> 2002";
  }
  elsif ($DEFAULTSEASON eq '2003') {
    $SEASON2003 = "<OPTION VALUE=2003 SELECTED> 2003";
  }
  elsif ($DEFAULTSEASON eq '2004') {
    $SEASON2004 = "<OPTION VALUE=2004 SELECTED> 2004";
  }

  # The $DEFAULTCOUNTRY should appear 'selected' in the form.

  $COUNTRYUSA = "<OPTION VALUE=usa> USA";
  $COUNTRYCAN = "<OPTION VALUE=canada> Canada";
  $COUNTRYEUR = "<OPTION VALUE=europe> Europe";
  $COUNTRYASI = "<OPTION VALUE=asia> Asia";
  $COUNTRYAUS = "<OPTION VALUE=australia> Australia";
  $COUNTRYOTH = "<OPTION VALUE=other> Other";

  if ($DEFAULTCOUNTRY eq 'usa') {
    $COUNTRYUSA = "<OPTION VALUE=usa SELECTED> USA";
  }
  elsif ($DEFAULTCOUNTRY eq 'canada') {
    $COUNTRYCAN = "<OPTION VALUE=canada SELECTED> Canada";
  }
  elsif ($DEFAULTCOUNTRY eq 'europe') {
    $COUNTRYEUR = "<OPTION VALUE=europe SELECTED> Europe";
  }
  elsif ($DEFAULTCOUNTRY eq 'asia') {
    $COUNTRYASI = "<OPTION VALUE=asia SELECTED> Asia";
  }
  elsif ($DEFAULTCOUNTRY eq 'australia') {
    $COUNTRYAUS = "<OPTION VALUE=australia SELECTED> Australia";
  }
  elsif ($DEFAULTCOUNTRY eq 'other') {
    $COUNTRYOTH = "<OPTION VALUE=other SELECTED> Other";
  }

print <<EOF;
<!-- Copyright 1998 Andria L Hunter. All Rights Reserved. -->
<!-- Created March 2000. andria\@whockey.com -->

<BASE HREF="http://www.whockey.com/">

<HTML><HEAD>
<TITLE>Women's Hockey Team Photo Submission Form</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#0000A0">

<CENTER>
<TABLE WIDTH=475 CELLSPACING=0 CELLPADDING=15 BGCOLOR=DARKBLUE>
<TD ALIGN=CENTER><IMG SRC="gifs/whockey/maintitle.jpg" WIDTH=300>
</TD>

<TD BGCOLOR=DARKBLUE>
<FONT SIZE=+3 COLOR=WHITE FACE=arial,univers,helvetica>
YOUR TEAM<BR>PHOTO<BR>SUBMISSION<BR>FORM</FONT>
</TD>
</TABLE>
</CENTER>

<CENTER>
<H3>[ <A HREF="$BASEHTML/">View Team Photo Listings</A> ]</H3>
</CENTER>

<HR NOSHADE>
<P>
If you would like to submit your team's photo, please fill
out the form below, and then press the "SEND" button.
You will then be instructed as to how to send your photo
using regular e-mail.
</P>

<HR NOSHADE>
<P>
<FORM METHOD=POST ACTION="http:$BASEHTML/$SCRIPTNAME">
<INPUT TYPE=HIDDEN NAME=COMMAND VALUE=SUBMITTEAM>
<H3>Enter your team info here...</H3>

<P>Your Name &#160;
<INPUT TYPE=TEXT SIZE=30 NAME=name>&#160; <FONT COLOR=RED>(required)</FONT>

<P>Your Email &#160;
<INPUT TYPE=TEXT SIZE=30 NAME=email>

<!-- ALH NOTE: New field (teamname)... -->
<P>Team Name &#160;
<FONT COLOR=RED>(required)</FONT><BR>
<INPUT TYPE=TEXT SIZE=60 NAME=teamname>

<P>Team Location (enter city and state/province) &#160;
<FONT COLOR=RED>(required)</FONT>
<INPUT TYPE=TEXT SIZE=60 NAME=city>

<P>Picture for season ending in this year:
<SELECT NAME=season>
    $SEASON1995
    $SEASON1996
    $SEASON1997
    $SEASON1998
    $SEASON1999
    $SEASON2000
    $SEASON2001
    $SEASON2002
    $SEASON2003
    $SEASON2004
</SELECT>

<P>My team is in this country:
<SELECT NAME=country>
    $COUNTRYUSA
    $COUNTRYCAN
    $COUNTRYEUR (includes Russia)
    $COUNTRYASI
    $COUNTRYAUS
    $COUNTRYOTH
</SELECT>

<P>Details about your team <FONT COLOR=RED>(required)</FONT><BR>
(name of league, your team roster, legend for your team
photo, how your team did, contact information for new players wishing
to join your team, team goals for upcoming seasons, and any other
information.  Enter as much information as you wish.)<BR>
<TEXTAREA NAME=details ROWS=10 COLS=50></TEXTAREA>

<P>
<INPUT TYPE=SUBMIT VALUE="  Send  ">&#160;&#160;&#160;&#160;
<INPUT TYPE=RESET VALUE="Erase">
</FORM>

<!----------- BEGIN INDEX ----------->
<HR NOSHADE SIZE=3>
This page is maintained by &copy; 1998
<A HREF="andria/">Andria Hunter</A>
(<A HREF="guest/submit.html">andria\@whockey.com</A>).<BR><BR>
<TABLE BORDER=5 WIDTH=100%>
<TR BGCOLOR="#AABBCC">
<TH COLSPAN=4><FONT SIZE=+2>The Women's Hockey Web
- <A HREF="quick.html">
<FONT COLOR=RED>Quick Index</FONT></A><FONT SIZE=-2></TH>
</TR>
<TR BGCOLOR="#CCDDEE">
<TH WIDTH=33%>
Main Index:<BR>
<A HREF="general/">General Info</A><BR>
<A HREF="int/">International</A><BR>
<A HREF="country/">Country</A> |
<A HREF="univ/">University</A><BR>
<A HREF="profile/">Player Profiles</A><BR>
<A HREF="card/">Hockey Cards</A><BR>
<A HREF="links.html">Links</A> |
<A HREF="faq/">FAQ</A><BR>
<HR>Resources:<BR>
<A HREF="tourney/">Tournaments</A><BR>
<A HREF="school/">Hockey Schools</A><BR>
<TH>
Women's<BR>
<A HREF="http://www.whockey.com/">
<IMG SRC="gifs/whockey/sidelogo.gif" WIDTH=90 ALIGN=CENTER></A><BR>
Hockey Web<BR>
<TH>
Andria's<BR>
<A HREF="andria/">
<IMG SRC="gifs/small/Andria_magazine_92.gif" ALIGN=CENTER></A><BR>
Homepage<BR>
<TH>
Hockey Tips:<BR>
<A HREF="tip/shooting/">Shooting</A> |
<A HREF="tip/skating/">Skating</A><BR>
<A HREF="tip/playing/">Playing</A><BR>
<HR>Other Women's Sports:<BR>
<A HREF="inline/">Inline Hockey</A><BR>
<A HREF="roller/">Roller Hockey</A><BR>
<A HREF="ball/">Ball Hockey</A><BR>
<A HREF="broomball/">Broomball</A><BR>
<A HREF="ringette/">Ringette</A><BR>
</TH>
</TR>
</TABLE>
<!----------- END INDEX ----------->
<PRE>URL:  http://www.whockey.com/$BASEHTML/$SCRIPTNAME</PRE>
</FONT>
</BODY>
</HTML>
EOF
}

# Start with the main program
# ---------------------------
# Assign variables to each value that comes from the form.

$COMMAND=$input{'COMMAND'};
$NAME=$input{'name'};
$EMAIL=$input{'email'};
$TEAMNAME=$input{'teamname'};
$CITY=$input{'city'};
$SEASON=$input{'season'};
$COUNTRY=$input{'country'};
$DETAILS=$input{'details'};

&GetDate;

# Script entered without parameters
# ---------------------------------
# Display the form to submit a team photo.

if ($COMMAND eq '') {
  &PrintForm;
  exit(0);
}

# Script entered with known country default
# -----------------------------------------
# In this case we want to print the form, but we want the default country
# to come from the $COUNTRY parameter, and the default season to come from
# the $SEASON parameter (if there is something in these parameters).

if ($COMMAND eq 'KNOWNDEFAULTS') {
  if ($COUNTRY ne '') {
    $DEFAULTCOUNTRY = $COUNTRY;
  }
  if ($SEASON ne '') {
    $DEFAULTSEASON = $SEASON;
  }
  &PrintForm;
  exit(0);
}

# Submit a Team Photo
# -------------------
# The user has clicked on the "submit" button on the form
# if we get to here.

if ($COMMAND eq 'SUBMITTEAM') {

  # Make sure all required input fields have been filled
  if ($NAME eq '' || $CITY eq '' || $TEAMNAME eq ' ' ||
      $SEASON eq '' || $COUNTRY eq '' || $DETAILS eq '') {
    &BadResponse;
  }

  # Get the Data Number for this country.
  &GetNumber;

  # Increment the Data Number for this country.
  &IncNumber;

  # Print Debug information. (uncomment this to print debug info)
  # &PrintDebug;

  # Create the new file and write information to it
  &GetSeasonRange;
  &GetCountryCaps;
  &CreateListing;

  # Open the listing page for this country, and add link
  &CreateLink;

  # Print the HTML code for the page that the user will go to
  # after entering the team photo information.
  &PrintThankYou;

  exit(0);
}

# CATCH-ALL
# ---------
# The $COMMAND value is not known.

print <<EOF;
<HTML><HEAD>
<TITLE>Script Error</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#0000A0">
<H1>Script Error</H1>
<P>
Either an error has occurred in the script or you have tried to take an
action that is not complete yet.  Oops.  Try again.
<P>
The value of the 'COMMAND' variable is:<BR>
$COMMAND
</P>
<HR NOSHADE>
EOF
exit(0);
