# This Perl CGI takes variables from the NKLA events.htm form. # It tests for basic input errors. When input is properly entered, # this script produces an acknowledgement html page and appends the # input to a file called dkpost.htm. The acknowledgement page has a # link to dkpost.htm. # # This script uses generic readin procedures that can handle GET and POST # methods and any number of variables. # # This script was created by Danny Krouk (dkrouk@ucla.edu). # First see if we're called by a GET or a POST, and get our data properly. # "GET"s pass data to us via arguments. # "POST"s pass data to us via an environment variable. if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } # Now digest the data, putting it into a more useful format. foreach $pair (@pairs) { ($key, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/\cM/\n/; # print "$key = $value
\n"; eval("\$$key = \"$value\""); $FORM{$key} = $value; } # Now let's generate a web page to display the data we've got. # make sure no fields are blank if (($FORM{fullname} eq "") || ($FORM{subtext} eq "") || ($FORM{killdate} eq "")) { &PrintNoInput; } # make sure email address is correct format elsif ($FORM{email} !~ /\w*@\w*/) { &PrintBadEma; } # make sure date is valid mm/dd/yy format elsif ($FORM{killdate} !~ /^\d{2}\/\d{2}\/96/) { &PrintBadDate; } # print acknowledgement else { ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime( time ); &PrintHeader; print "\n"; print "Submission Acknowledgement Page\n"; print "\n"; &PrintMast("LACom Submission Acknowledgement Page"); print "Thanks ", $FORM{fullname}, ",

\n"; print "Here is your message: ", $FORM{subtext}, ". It is a: ", $FORM{subtype}, "Announcement.

\n"; print "Your message will be posted until: ", $FORM{killdate}, "

\n"; print "Site vistors will be able to send you mail at: ", $FORM{email}, " .

\n"; print "You may view the submissions here

\n"; &PrintButts; &PrintFooter; &AppendSub; } # Append submission to events posting html page dkpost.htm sub AppendSub { open (SUBMISS, ">>dkpadv.htm"); print SUBMISS "


\n"; print SUBMISS "Event Information: $FORM{subtext}. Submission by, $FORM{fullname}. Submission type: $FORM{subtype} Announcement.\n"; print SUBMISS "For more information, contact $FORM{email}.\n"; print SUBMISS "This message will remain posted until $FORM{killdate}.\n"; print SUBMISS "\n"; close SUBMISS; } # 6.Does anyone know how to grab the system date and time in a perl script? # ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime( time ); sub PrintHeader { print "Content-Type: text/html\n\n"; } sub PrintMast { local($title) = @_; print "$title"; print "\n"; print "\n"; print "\n"; print "\n"; print "

$title

\n"; print "
\n"; } sub PrintButts { print "
\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } sub PrintFooter { print "\n"; print "\n"; } sub PrintNoInput { &PrintHeader; &PrintMast("Submission Error: Blank Field"); print "\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "You did not fill out all of the blanks in the form.\n"; print "

\n"; print "Please return to the submission page.\n"; &PrintFooter; } sub PrintBadEma { &PrintHeader; &PrintMast("Submission Error: Bad Email"); print "\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "You did not provide a valid email address.\n"; print "

\n"; print "Please return to the submission page.\n"; &PrintFooter; } sub PrintBadDate { &PrintHeader; &PrintMast("Submission Error: Bad Date"); print "\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "Please provide the date in the following format:.

\n"; print "MM/DD/YY

\n"; print "

\n"; print "Please return to the submission page.\n"; &PrintFooter; } exit;