#!/srvtools/http/bin/perl
# Falke Bruinsma (falke@innersource.com)
# Inner Source Computer Services, Inc. (http://www.innersource.com)
#

require 'cgi-lib.pl';
require 'defines.pl';

MAIN:
{
  if (not &ReadParse(*input)) {
    CgiError("Error", "Parameters were expected and none were given.");
    exit;
  }
  print &PrintHeader;
  print <<EOF;
<HTML>
<HEAD> 
<TITLE>Submitted New Entry</TITLE>
</HEAD>
<BODY>
<H2>Thank you!</H2>
<HR><P>
Your info has been submitted and will be added to the database after
being reviewed...
<HR>
Back to:
<A HREF="$home/homepages/index.html">Student Homepage Directory</A> |
<A HREF="$home/index.html">
The Student Center Main Page</A> |
<A HREF="$home/hub.html">
Student HUB</A>

</BODY>
</HTML>
EOF
  submit_event();
  if ($notify) { notify(); }
}

sub submit_event {
  if ($input{'lastname'} eq '') { $input{'lastname'} = $E_LASTNAME;}
  if ($input{'firstname'} eq '') { $input{'firstname'} = $E_FIRSTNAME; }
  if ($input{'url'} eq 'http://') { $input{'url'} = $E_URL; }
  if ($input{'title'} eq '') { $input{'title'} = $E_TITLE; }
  if ($input{'email'} eq '') { $input{'email'} = $E_EMAIL; }
  if ($input{'dob'} eq '') { $input{'dob'} = $E_DOB; }
  if ($input{'sex'} eq '') { $input{'sex'} =  $E_SEX; }
  if ($input{'state'} eq '') { $input{'state'} = $E_STATE; }
  if ($input{'info'} eq '') { $input{'info'} = $E_INFO; }

  if (!open (LIST, ">>$submit_file")) {
    print $ErrorMessage;
    exit(1);
  }
  print LIST "$input{'lastname'}\n$input{'firstname'}\n$input{'url'}\n";
  print LIST "$input{'title'}\n$input{'email'}\n$input{'dob'}\n";
  print LIST "$input{'sex'}\n$input{'state'}\n$input{'info'}\n\n";
  close(LIST);
}

sub notify {
  open (LIST, $tmpfile);
  print LIST "From: $input{'email'}\n";
  print LIST "Subject: new entry\n\n";
  print LIST "$input{'lastname'}\n$input{'firstname'}\n$input{'url'}\n";
  print LIST "$input{'title'}\n$input{'email'}\n$input{'dob'}\n";
  print LIST "$input{'sex'}\n$input{'state'}\n$input{'info'}\n\n";
  close(LIST);
  system "mail $user < $tmpfile > /dev/null";
  rmdir $tmpfile;
}

