#!/usr/local/bin/perl

###########################################################

# The script processes the output from the TROUBLE REPORT

# form for FMO computer services web pages. Specifically,

# it verifies that any required fields are completed, and

# if they are, it mails the results to a specified set of

# email addresses.

###########################################################

sub BEGIN {

unshift( @INC, "../../../Perl/lib" );

}

use CGI;

use Text::Wrap;

# km 5/99 added include but its also part of this file

require 'c:\inetpub\wwwroot\cgi-bin\sendmail.pl';

#require 'c:\inetpub\wwwroot\cgi-bin\parsform.pl';

$SMTP_SERVER = 'mailhost.u.washington.edu';

#

# List of fields from the trouble report form that are required

# before the submission will be mailed

#

@REQ_FIELDS = ( "NAME", "EMAIL", "BUILDING", "DESCRIPTION" );

#

# A comma delimited list of email addresses to whom the trouble

# report should be sent. Make sure to enclose each entry in

# single quotes ('...'). Otherwise, with double quotes, the @

# in email addresses would need to be backslashified

#

@RECIPIENT_LIST = ('root@kilauea.fmo.washington.edu');

#

# What the subject for the email sent should be

#

$SUBJECT_LINE = "Trouble Report Form From FMO Web";

#

# The name (and possibly location) of the mail program. This should

# be 'blat'. If it is changed to something else, other code will

# need to be changed. If you think you are swanky enough to change

# the default mailer, feel free to locate the code that needs changing,

# as well.

#

$MAILPROG = "blat";

#

# Default Home Page.

#

$HOME="http://128.95.82.17/ufo";

#

# The name (and relative location if not the 'current' directory)

# of the trouble report form cgi script.

#

$TROUBLE_FORM="trouble_form.pl";

#

# A special module that forces printed lines to be wrapped at

# the specified value (if possible). For extra long TEXT AREA

# submissions

#

$Text::Wrap::columns = 60;

$FAIL = 1;

$LOCK_EX = 2; $LOCK_UN = 8; # For flock( )

$query = new CGI;

print $query->header;

print $query->start_html( -title => "FMO Computer Services Trouble Form" );

foreach $field ( $query->param ) {

$in{$field} = $query->param( $field );

}

#km 6/99 3 lines

#if (!(&parse_form)) {

# &error(&RedirectOnFailure);

#}

foreach $field (@REQ_FIELDS) {

if (!($in{$field})) { &RedirectOnFailure; }

}

 

if (!$in{"PHONE"} && !$in{"EXT"}) { &RedirectOnFailure; }

$in{"DESCRIPTION"} =~ tr/\n+/\n/;

$in{"DESCRIPTION"} = wrap( '', '', $in{"DESCRIPTION"} );

&SendMail;

&RedirectOnSuccess;

print $query->end_html; exit;

 

##################################################

# After successfully emailing the form, we do this

##################################################

sub RedirectOnSuccess {

# km 6/99

$Mybody = join(" ",$in{"NAME"}, "in", $in{"BUILDING"}, "Room:", $in{"ROOM"}, "with Phone:", $in{"PHONE"}, "ext:", $in{"EXT"}, "with e-mail address:", $in{"EMAIL"}, "says:", $in{"DESCRIPTION"});

print <<EOF;

<CENTER> <H3> The Following fields are designed to show you

what we are sending on to the the Staff at <br>

Computer Services. </H3> <br>

</CENTER>

EOF

print "YOUR NAME: ", $in{"NAME"}, "\n";

print "BUILDING: ", $in{"BUILDING"}, "<br>\n";

print "ROOM: ", $in{"ROOM"}, "\n";

print "PHONE: ", $in{"PHONE"}, "\n";

print "ext: ", $in{"EXT"}, "<br>\n";

print "EMAIL: ", $in{"EMAIL"}, "<br>\n";

print "YOUR DESCRIPTION: ", $in{"DESCRIPTION"}, "<br>\n";

# print "Test DESCRIPTION: ", $Mybody, "<br>\n";

print <<EOF;

<CENTER> <H3> This Form HAS been Successfully Sent <br>

</H3> <br>

<p>

You may use the blue navigation buttons<br>

at the top of this page to move to a <br>

different page.

</CENTER>

EOF

}

###################################################

# If not all req'd fields are completed, we do this

###################################################

sub RedirectOnFailure {

print "I am sorry, but you have not completed the following";

print " <B>required</B>:<br>";

print "<UL>";

foreach $field (@REQ_FIELDS) {

if (!$in{$field}) { print "<LI> $field </LI>"; }

}

if (!$in{"PHONE"} && !$in{"EXT"}) {

print "<LI> A PHONE NUMBER AND/OR AN EXTENSION </LI>";

}

print "<FORM METHOD=POST ACTION=\"$TROUBLE_FORM\">\n";

foreach $field (keys( %in )) {

print "<INPUT TYPE=HIDDEN NAME=\"$field\" VALUE=\"$in{$field}\">\n";

}

# added t-body km 5/99

 

print "<br><br>";

print "<INPUT TYPE=SUBMIT VALUE=\"Try Again\">\n";

print "</FORM>\n";

print $query->end_html; exit;

}

 

sub SendMail {

$RECIPIENT_LIST = join( ',', @RECIPIENT_LIST );

 

$| = 1; # make pipes "hot" or we'll get things in the wrong order

# added Mybody km 6/99

$Mybody = join(" ",$in{"NAME"}, "in", $in{"BUILDING"}, "Room:", $in{"ROOM"}, "with Phone:", $in{"PHONE"}, "ext:", $in{"EXT"}, "with e-mail address:", $in{"EMAIL"}, "says:", $in{"DESCRIPTION"});

&send_email($SUBJECT_LINE, $in{"EMAIL"}, 'fmocs@u.washington.edu', '', '', $Mybody, '', '');

#&send_email($SUBJECT_LINE, $in{"EMAIL"}, 'fmocs@u.washington.edu', '', '', #$in{"DESCRIPTION"}, '', '');

# across the pipe.

#This doesn't work in windows only Unix

#**************************************************************

# open( MAIL, "| $MAILPROG - -s \"$SUBJECT_LINE\" -t \"$RECIPIENT_LIST\" -q" )

# or die "Cannot open mail. Form not sent\n";

#

#

#system #"mailto:kmingea\@u.washington&subject=Hello%20World,&body=How%20are%20%0D";

# print MAIL "NAME: ", $in{"NAME"}, "\n";

# print MAIL "BUILDING: ", $in{"BUILDING"}, " ";

# if ($in{"ROOM"}) { print MAIL "ROOM: ", $in{"ROOM"}; }

# print MAIL "\n";

# print MAIL "PHONE: ";

# if ($in{"PHONE"}) { print MAIL $in{"PHONE"}, " "; }

# if ($in{"EXT"}) { print MAIL "ext: ", $in{"EXT"}; }

# print MAIL "\n";

# print MAIL "PROBLEM: ", $in{"DESCRIPTION"}, "\n";

#

 

# print MAIL "\cZ"; # closes BLAT pipe

# close MAIL;

}

sub DieOnError {

print "<B> An Unexpected Error Has Occured.</B> <br>\n";

print "Please report the problem to <A HREF=\"MAILTO:$ERROR_HANDLER\"> ";

print "$ERROR_HANDLER </A>, and <A HREF=\"$HOME\"> click ";

print "here </A> to return to the FMO homepage.";

print $query->end_html; exit;

}

 

 

# Added KM 6/23/99

sub open_file {

local ($filevar, $filemode, $filename) = @_;

open ($filevar, $filemode . $filename) ||

die ("Can't open $filename");

}

sub read_from_file {

local ($filevar) = @_;

<$filevar>;

}

sub print_to_file {

local ($filevar, $line) = @_;

print $filevar ($line);

}