#!/usr/bin/perl
#
# print header stuff
#
print "Content-type: text/html", "\n\n";
print "<html>\n";
print "<body background=\"nevada.gif\">\n";
#
#define stuff to send email with
#
require TripodMail;
$mail = new TripodMail;
#
#define stuff to grab data entered on form
#
require TripodCGI;
use CGI;
$cgi = new CGI;
#
#get users email address, subject of letter and letters text
#
#
# $formname name of disk file with model on how to send email
# this file must exist or we cant send the email
#
$formname=$cgi->param('formname');
$frommail=$cgi->param('frommail');
$replyto=$cgi->param('replyto');
$subject=$cgi->param('subject');
$text=$cgi->param('text');
$title=$cgi->param('title');
$file_prefix=$cgi->param('file_prefix');
$debugflag=$cgi->param('debugflag');
if ($debugflag eq 'y' ) {
   print "debug_flag='$debugflag'<br>\n";
   print "replyto='$replyto'<br>\n";
   print "formname='$formname'<br>\n";
   print "frommail='$frommail'<br>\n";
   print "subject='$subject'<br>\n";
   print "text='$text'<br>\n";
   print "file_prefix='$file_prefix'<br>\n";
   print "title='$title'<br>\n";
}
if ( !  -e $formname ) {
   print "ERROR mail form file '$formname' does not exist<p>\n";
   print "ERROR to fix either<p>\n";
   print "<ol>\n";
   print "<li>Some idiot deleted the file $formname so someone must recreate the file\n";
   print "<li>The program has a bug and you must get the programmer to fix it.\n";
   print "</ol>\n";
   print "</html>\n";
   return;
}
#
#if the variable $text is null or blank
# its the 1st time the program has been run
# and we must display the form, or the 
# user has clicked on the submit button with
# out entering any text. againg we must display the
# form
&display_form();
print "</html>\n";
exit;

sub display_form {
 #print "<p><a name=\"#top\">\n";
 #print "$title<p>\n";
 print "<form action=\"bccmail3.pl\">\n";
 &dump_files;
 print "From: <input type=\"text\" size=\"60\" name=\"frommail\" value=\"$frommail\"><br>\n";
 print "Reply-To: <input type=\"text\" size=\"60\" name=\"replyto\" value=\"$replyto\">\n";
 print "<br>\n";
 print "Subject: <input type=\"text\" size=\"60\" name=\"subject\" value=\"$subject\">\n";
 print "<p>\n";
 print "<input type=\"submit\" name=submit value=\"SUBMIT\"> \n";
 print "<p>\n";
 print "<textarea name=\"text\" cols=\"79\" rows=\"20\">\n";
 print "$text";
 print "</textarea>\n";
 print "<hr>\n";
 print "<p>\n";
 print "<input type=\"reset\" name=reset value=\"CLEAR MENU\">\n";
 print "<input type=\"hidden\" name=\"formname\" value=\"$formname\">\n";
 print "<input type=\"hidden\" name=\"title\" value=\"$title\">\n";
 print "<input type=\"hidden\" name=\"debugflag\" value=\"$debugflag\"\n>";
 print "</form>\n";
 print "</html>\n";
 return;
}
 sub dump_files {
 $the_file_name=$file_prefix;
 if ( -f $the_file_name ) {
    print "Send an E-Mail to all of $title<p>\n";
    print "<input type=\"hidden\" name=\"thefile\" value=\"$file_prefix\">\n";
    return;
 }
 else {
    print "ERROR!<br>\n";
    print "the file<br>\n";
    print "<blockquote>\n";
    print "$the_file_name\n";
    print "</blockquote>\n";
    print "does not exist!<br>\n";
    print "ERROR!<br>\n";
    print "have the moron who runs this site create it!<p>\n";
    exit;
 }
}