#!/usr/local/bin/perl # report.pl # Author: Alan Levine #> # Generates a web page format of report # submitted by users of the Writing HTML # tutorial. This script will return an # HTML formatted version for the web page # data as well as sending a copy to their # instructor via email. # #< # perl modules require("CGI.pm"); # Load CGI.pm library to handle input and objects use CGI qw(:standard :cgi-lib); use CGI::Carp qw(fatalsToBrowser); # parse form variables to array &ReadParse; # print return html header print header; ############################################# # Get the current date/time # first pull in the time (undef,$min,$hour,$mday,$mon,$year,$wday) = localtime(time); # arrays for months and days by name @months = qw(January February March April May June July August September October November December); @days = qw(Sun Mon Tue Wed Thu Fri Sat); #convert year $year = $year + 1900; # adjust to 12 hour clock if ($hour > 12) { $hour = $hour - 12; $ampm = 'PM'; } elsif ($hour > 12) { $ampm = 'PM'; } else { $ampm = 'AM'; } # pad with 0s $hour = sprintf("%02d", $hour); $min = sprintf("%02d", $min); #construct the final date string for later use $date_str = "$days[$wday], $months[$mon] $mday, $year at $hour:$min $ampm"; ############################################# # send as email if checked if ($in{'rep_email'} eq "y") { &send_email }; if ($in{'rep_web'} eq "y") { # create web page if checked &send_web; } elsif ($in{'rep_email'} ne "y") { # send error message if no options were checked &send_err; } exit; # ----------------------------------------------------- # subroutine for sending email version of report sub send_email { if (!($in{'instructor'} =~ /pele.bigu.edu/)) { # This is the template's default address # which is fake, so we proceed only if it is different # This is the file path for the sendmail program # which may be different on different web sites $mail_thing = "/usr/sbin/sendmail"; # send the mail string open(SENDMAIL, "| /$mail_thing -t -n "); print SENDMAIL <<"End_of_Mail"; From: $in{'email'} To: $in{'instructor'} Reply-to: $in{'email'} Subject: Volcano Web Report from $in{'name'} ------------------ 8< ---------------------------------- This Volcano Web report was written on $date_str and sent from IP $ENV{"REMOTE_ADDR"} -------------------------------------- student information -------------------------------------- NAME : $in{'name'} EMAIL : $in{'email'} CODE : $in{'pass'} -------------------------------------- volcano report -------------------------------------- VOLCANO : $in{'vname'} LOCATION - LATITUDE : $in{'vlat'} LOCATION - LONGITUDE : $in{'vlong'} TYPE : $in{'vtype'} ACTIVITY : $in{'active'} : $in{'vdate'} FEATURES : $in{'note1'} : $in{'note2'} : $in{'note3'} : $in{'note4'} : $in{'note5'} OTHER INFORMATION : $in{'info'} -------------------------------------- sources -------------------------------------- REFERENCES : $in{'ref1'} : $in{'ref2'} : $in{'ref3'} ======================================= this report was created as an example of the Writing HTML tutorial at http://www.mcli.dist.maricopa.edu/tut/ ======================================= End_of_Mail ; } # write a response page if we are doing email only if ($in{'rep_web'} ne "y") { print <<"end_html";

Volcano Report Submitted

Your report on $in{'vname'} has been submitted by e-mail to your instructor.

end_html } } # ----------------------------------------------------- # subroutine for writing report to web page sub send_web { print <<"end_html";

Volcano Report Form

end_html # feedback for message if it was sent to instructor if ($in{'rep_email'} eq "y") { print '"; } print '
student information
name $in{'name'}
email $in{'email'}
volcano report
volcano name $in{'vname'}
location latitude= $in{'vlat'}
longitude=$in{'vlong'}
type $in{'vtype'}
activity $in{'active'}
date of last known eruption = $in{'vdate'}
features $in{'note1'}
$in{'note2'}
$in{'note3'}
$in{'note4'}
$in{'note5'}
more info $in{'info'}
sources
references
  1. $in{'ref1'}
  2. $in{'ref2'}
  3. $in{'ref3'}
report stats
date $date_str
copies'; print "report sent by email to $in{'instructor'}
'; ; } # ----------------------------------------------------- # subroutine for writing error message for no input sub send_err { print <<'end_html';

Volcano Report Form Error

You must check at least one of the format options listed under send report. Please use your web brower back button to return to the form and choose whether you wish this report to be generated as a web page, sent as email to your instructor, or both.

end_html }