#!/usr/local/bin/perl

# Created by: Timothy Zane 
# Date:	   : 28 June 1996 
# Programmer : Timothy Zane
# E-mail: zanetim@auburn.campus.mci.net



# Get the input from form
read(STDIN,$input_buffer,$ENV{'CONTENT_LENGTH'});
$buffer=$input_buffer;

# Define variables
$recipient = "nrotc\@mail.auburn.edu";
$mailprog = '/usr/lib/sendmail';

# Print out a content for HTTP compatibility
print "Content-type: text/html\n\n";




#split the name-value pairs
@pairs = split(/&/,$buffer);


#foreach $pair (@pairs)
#{
#    ($name, $value) = split(/=/, $pair);
#
#    # Un-Webify plus signs and %-encoding
#    $value =~ tr/+/ /;
#    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
#    $FORM{$name} = $value;
#}


# Print a title and heading
print "<Head><Title>Thank you</Title></Head>";
print "<Body><H1>Thank you</H1><p>";
print "<h4>The following information has been sent to NROTC\n\n</h4><p>"; 


# This variable is used to make sure "I would like more information"
# is printed only once

$count = 0;

foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 


    #  Remove underscore from name and value

    $name =~ s/_/ /g;
    $value =~ s/_/ /g;
    if ($name eq "I would like more info on")
      { 
        if ($count == 0) 
          {print "<h4>I would like more information on:</h4>";}
	$count = 1;
        print "$value<p>";
      }
    else

     { if ($name eq "enroll")
        {print "<h4>I intend to enroll:</h4>$value";}
       else
        { 
       if (!($value eq ""))
             {print "$name = $value\n<p>";}
         }
     }
}


#Mail the results to NROTC
 
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Subject: NROTC INFO\n";
print MAIL "\n";
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 

    #  Remove underscore from name and value

    $name =~ s/_/ /g;
    $value =~ s/_/ /g; 
    print MAIL "$name = $value\n"; 
}

close (MAIL);


