#!/usr/local/bin/perl
require "/home/todd/toddweb.env";
require "$PAGEHOMEDIR/weblib.lib";
@months=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
@days=(Sun,Mon,Tue,Wed,Thu,Fri,Sat);
&ReadParse;
$BODYENHANCE=" bgcolor=#FFFFFF";
&htmlopen("Fan Mail to Todd Rundgren|");
if($ENV{CONTENT_LENGTH}){
($sec,$min,$hour,$day,$mon,$year,$wday)=gmtime(time);
$date=sprintf("%s %s %d, %d %2d:%02d:%02d GMT",$days[$wday],$months[$mon],$day,$year+1900,$hour,$min,$sec);
$in{Address}=~s/\r//g;
$in{Message}=~s/\r\n/\n/mg;
$in{Message}=~s/\r/\n/mg;
$in{Message}=~s/%22/"/mg;
$MAIL=<<EOF;
Name: $in{Name}
Date: $date
E-mail: $in{Email}
Home Address:\n$in{Address}

$in{Message}
EOF
if(!$in{MessagePrivate}){
$LOG="";
$LOG.="Name: $in{Name}\n" unless $in{NamePrivate};
$LOG.="Date: $date\n";
$LOG.="E-mail: $in{Email}\n" unless $in{EmailPrivate};
$LOG.="Home Address:\n$in{Address}\n" unless $in{AddressPrivate};
$LOG.="\n$in{Message}\n";
}
$LOGINFO=$LOG?$LOG:"None";
if($in{Confirmed}){
	print "Mail sent!<hr>\n";
	open(MAIL,">>$PAGEHOMEDIR/fanmail/mail");
	print MAIL $MAIL,"="x72,"\n";
	close(MAIL);
	if($LOG){
		open(LOG,">>$PAGEHOMEDIR/fanmail/log");
		print LOG $LOG,"="x72,"\n";
		close(LOG);
		system("touch $PAGEHOMEDIR/articles/fanmail.art");
	}
}
else{
print <<EOF;
<pre>
Mail that will be sent to Todd:
$MAIL
<hr>
Information that will be placed in the public log:
$LOGINFO
<hr>
</pre>
EOF
$in{Message}=~s/"/%22/g;
print <<EOF;
<form action=$weblib::URL method=POST>
<input type=submit value="Send My Fan Mail">
<input name=Name value="$in{Name}" type=hidden>
<input name=NamePrivate value="$in{NamePrivate}" type=hidden>
<input name=Email value="$in{Email}" type=hidden>
<input name=EmailPrivate value="$in{EmailPrivate}" type=hidden>
<input name=Address value="$in{Address}" type=hidden>
<input name=AddressPrivate value="$in{AddressPrivate}" type=hidden>
<input name=Message value="$in{Message}" type=hidden>
<input name=MessagePrivate value="$in{MessagePrivate}" type=hidden>
<input name=Confirmed value=1 type=hidden>
</form>
<hr>
If you wish to make corrections, use your browsers "Back" function, edit your
message and submit again.
EOF
exit;
}
}
@stat=stat("$PAGEHOMEDIR/fanmail/log");
($sec,$min,$hour,$day,$mon,$year,$wday)=gmtime($stat[9]);
$date=sprintf("%s %s %d, %d %2d:%02d:%02d GMT",$days[$wday],$months[$mon],$day,$year+1900,$hour,$min,$sec);
print <<EOF;
Here's a way to get your fan mail and comments to Todd.
<br>
Just fill out the
form below, indicate your privacy preferences and the message will be sent
to Todd.
<br>
Unless you indicate otherwise, messages are placed in a public viewing area
for other visitors to see as well.<br>
You'll be shown the message as it will go out and be allowed to confirm it
before actually sending it.
Messages are batched up and sent once a week (on Friday).
<hr>
See the <a href=/$HTMLPATH/fanmail.txt>Fan Mail so far</a> (Last modified: $date)
<hr>
<form action=$weblib::URL method=POST>
<input type=submit value="Show My Fan Mail Before Sending"><input type=reset value="Clear All Fields">
<br>
EOF
print &htmltable("","border");
print &htmlrowdata("Your Name","<input name=Name size=30>","<input name=NamePrivate type=checkbox>Keep my name out of the log");
print &htmlrowdata("Your E-mail Address","<input name=Email size=30>","<input type=checkbox name=EmailPrivate>Keep my E-mail address out of the log");
print &htmlrowdata("Home Mailing address","<textarea name=Address rows=6 cols=30></textarea>","<input type=checkbox name=AddressPrivate checked>Keep my home address out of the log");
print &htmlrowdata("Your Message to Todd<br><input type=checkbox name=MessagePrivate>Keep whole message out of the log","2y<textarea name=Message rows=20 cols=60 wrap=hard></textarea>");
print &htmltableend;
print "</form>\n";
print $PAGETAIL;
&htmlclose;
