scratchpad
lakeTrout
Here's almost the ENTIRE delete script that pertains to <a href="/?node_id=679583">this question</a>
<code>
#!/usr/bin/perl
use CGI qw(:standard); #faster, more legible
use CGI::Carp qw(fatalsToBrowser);
#Paths
$path = "/just/my/path/here/";
$Date = `date`;chop $Date;
#########################
$mailProgram = '/usr/lib/sendmail -t -eq';
$recipient = "me\@here.com";
# . $FORM{manageremail};
######################### Files
$logfile = "tempfile_ext.tmp";
$logfileOrig = "logfile_ext.log";
chmod 777, $logfile;
chmod 777, $logfileOrig;
$message = "<b>Thank you for your edit.</b> <p> <a href=admin.html>Back to Admin Screen</a>";
$message2 = "<b>Thank you for your submission.</b> <p> <a href=index.html>Back to Home</a>";
# Get the input from the form
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# 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/%0D%0A/<br>/g;
$value =~ s/%09//g;
$value =~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
## Grammartize checkbox values
if ($value eq "on") {
$value = $name;
}
$FORM{$name} = $value;
}
my $linenumber = $FORM{linenumber};
#print OUTFILE "Param check $linenumber";
my $currentline = 0;
# Program Logic
&makelog;
&thankyou;
&mailMessage;
&mailMessage2;
# Program Logic done, just subroutines now.
# Print an HTML page with variable data.
sub thankyou {
if ($linenumber){
print "Content-Type: text/html\n\n";
open(THANKS, "thanks.html") || die "thanks.html: $!";
while (<THANKS>) {
s/%message%/$message/g;
print $_;
}
close(THANKS);
}
else
{
print "Content-Type: text/html\n\n";
open(THANKS, "thanks.html") || die "thanks.html: $!";
while (<THANKS>) {
s/%message%/$message2/g;
print $_;
}
close(THANKS);
}
}
# Append form data to tab delimited log file.
sub makelog {
#copy existing logfile to tempfile, while skipping edited record
open (LOGFILE, ">$logfile") or die("Can't Open Log File at $logfile");
open (ORIG, "<$logfileOrig") or die("Can't Open Log File at $logfileOrig");
while (my $origLine = <ORIG>) {
$currentline ++;
print LOGFILE $origLine unless $currentline == $linenumber;
}
close (ORIG);
close (LOGFILE);
rename $logfile, $logfileOrig if $linenumber;
}
#Send message to recipient
open (MAIL, "|$mailProgram -t $recipient") || die "Can't open $mailprogram!\n";
print MAIL ("From: $FORM{owner_email}\n");
print MAIL ("$message\n");
close (MAIL);
#Here's how I generate the mail message - primitive, but works
sub mailMessage {
$message = <<"EOS";
SUBJECT: External
Bulletin Title:
$FORM{bulletin_title}
Bulletin Summary:
$FORM{bulletin_summary}
EOS
}
# Send message to submitter
open (MAIL, "|$mailProgram -t $FORM{owner_email}") || die "Can't open $mailprogram!\n";
print MAIL ("From: XXXXXXXX\n");
print MAIL ("$message2\n");
close (MAIL);
sub mailMessage2 {
$message2 = <<"EOS";
SUBJECT: External Submission Confirmation
Thank you stuff.....
EOS
}
</code>