--- loncom/interface/lonsupportreq.pm 2004/07/09 21:08:24 1.4 +++ loncom/interface/lonsupportreq.pm 2004/07/13 17:35:58 1.5 @@ -2,16 +2,13 @@ package Apache::lonsupportreq; use strict; use lib qw(/home/httpd/lib/perl); +use MIME::Types; +use MIME::Lite; use Apache::Constants qw(:common); use Apache::loncommon(); use Apache::lonnet(); -use localenroll; use Apache::lonlocal; -use Mail::Send; -# use MIME::Lite; -# use MIME::Types; - sub handler { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); @@ -38,6 +35,9 @@ sub print_request_form { my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server); my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1); my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg'); + if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) { + $tablecolor = '#CCCCFF'; + } $os = $ENV{'browser.os'}; $browser = $ENV{'browser.type'}; $bversion = $ENV{'browser.version'}; @@ -49,7 +49,17 @@ sub print_request_form { $usec = $ENV{'request.course.sec'}; $cid = $ENV{'request.course.id'}; $server = $ENV{'SERVER_NAME'}; - my $scripttag; + my $scripttag = (< +function validate() { + if (document.logproblem.email.value.indexOf("\@") == -1) { + alert("You must enter a valid e-mail address"); + return + } + document.logproblem.submit(); +} + +END if ($cid =~ m/_/) { ($cdom,$cnum) = split/_/,$cid; } @@ -77,11 +87,6 @@ sub print_request_form { my ($sec,$grp) = split/:/,$_; $groupid{$sec} = $grp; } - $r->print(< - - LON-CAPA support request -END my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'}; my $codedom = $defdom; my %coursecodes = (); @@ -128,7 +133,7 @@ $bodytag - + +END + if (defined($ENV{'user.name'})) { + $r->print(< + + + + + + +END + } + $r->print(<
@@ -249,7 +254,7 @@ END
- $server$origurl + http://$server$origurl
@@ -300,9 +305,9 @@ END END if ($coursecodes{$cnum}) { foreach (@codetitles) { - $r->print(''.$_.': '.$codes{$cnum}{$_}); + $r->print(''.$_.': '.$codes{$cnum}{$_}.'; '); } - $r->print('. '); + $r->print(' '); } else { $r->print('Enter institutional course code:  '); @@ -344,7 +349,7 @@ END if ($_ eq $groupid{$_} || $groupid{$_} eq '') { $r->print("
+ + + + +
Optional file upload: +
+
+ + + + +
+
Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size). +
+
+
+
@@ -424,7 +459,7 @@ END
-   +     @@ -445,49 +480,25 @@ END
END - - -# What do we know about this user? -# foreach (sort keys %ENV) { -# if ($_ =~ m/^browser/) { -# $r->print("key is $_, value is $ENV{$_}"); -# } elsif ($_ =~ m/^environment/) { -# $r->print("key is $_, value is $ENV{$_}"); -# } elsif ($_ =~ m/^request/) { -# $r->print("key is $_, value is $ENV{$_}"); -# } elsif ($_ =~ m/^user\.(domain|home|name)/) { -# $r->print("key is $_, value is $ENV{$_}"); -# } elsif ($_ =~ /^[A-Z]/) { -# $r->print("key is $_, value is $ENV{$_}"); -# } -# } - return + return; } sub print_request_receipt { my ($r,$url,$function) = @_; my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role'); + my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id'); + my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1); + my $admin = $Apache::lonnet::perlvar{'lonAdminMail'}; my $to = $Apache::lonnet::perlvar{'lonSupportEMail'}; + my $from = $admin; my $reporttime = &Apache::lonlocal::locallocaltime(time); my $fontcolor = &Apache::loncommon::designparm($function.'.font'); my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink'); my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg'); - my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description'); + my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description','screenshot'); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars); -# if ($ENV{'request.course.fn'}) { -# my $formdatafile = $ENV{'request.course.fn'}.'.formdata'; -# if (-e $formdatafile) { -# open(FILE,"<$formdatafile"); -# my @buffer =; -# close(FILE); -# foreach (@buffer) { -# print STDERR $_; -# } -# } -# } - my $supportmsg = qq| Name: $ENV{'form.username'} Email: $ENV{'form.email'} @@ -500,6 +511,20 @@ URL: $ENV{'form.origurl'} Date/Time: $reporttime |; + my $descrip = $ENV{'form.description'}; + $descrip =~ s#\n#
#g; + my $displaymsg = qq| +Name: $ENV{'form.username'}
+Email: $ENV{'form.email'}
+Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}
+Tel: $ENV{'form.phone'}
+Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}
+Subject: $ENV{'form.subject'}
+Description: $descrip
+URL: $ENV{'form.origurl'}
+Date/Time: $reporttime
+ |; + if ($to =~ m/^[^\@]+\@[^\@]+$/) { $r->print(< @@ -518,28 +543,86 @@ END $bodytag

Warning: Problem with support e-mail address

-As the e-mail address provided for this LON-CAPA server ($to) does not appear to be a valid e-mail address, your support request has not been sent to the LON-CAPA support staff at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University. +As the e-mail address provided for this LON-CAPA server ($to) does not appear to be a valid e-mail address, your support request has not been sent to the LON-CAPA support staff at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University. END } - my $msg = new Mail::Send; - $msg->to($to); -# if (defined($ENV{'form.email'})) { -# if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { -# $msg->from($ENV{'form.email'}); -# } -# } - $msg->subject('[LON-CAPA] - support request'); - # ->open can cause an sh launch which can pass all of %ENV allong + if (defined($ENV{'form.email'})) { + if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { + $from = $ENV{'form.email'}; + } + } + + my $subject = $ENV{'form.subject'}; + $subject =~ s#(`)#'#g; + $subject =~ s#\$#\(\$\)#g; + $supportmsg =~ s#(`)#'#g; + $supportmsg =~ s#\$#\(\$\)#g; + $displaymsg =~ s#(`)#'#g; + $displaymsg =~ s#\$#\(\$\)#g; + my $fname; + + my $attachmentpath = ''; + my $attachmentsize = ''; + if (defined($ENV{'user.name'})) { + if ($ENV{'form.screenshot.filename'}) { + $attachmentsize = length($ENV{'form.screenshot'}); + if ($attachmentsize > 131072) { + $displaymsg .= "
The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded."; + } else { + $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests'); + } + } + } + + if ($attachmentpath =~ m-/([^/]+)$-) { + $fname = $1; + $displaymsg .= "
An uploaded screenshot file - $fname ($attachmentsize bytes) was included in the request sent by $ENV{'user.name'} from LON-CAPA domain: $ENV{'user.domain'}"; + $supportmsg .= "\n"; + foreach (@envvars) { + $supportmsg .= "$_: $ENV{$_}\n"; + } + } + + my $msg = MIME::Lite->new( + From => $from, + To => $to, + Subject => $subject, + Type =>'TEXT', + Data => $supportmsg, + ); + + if ($attachmentpath) { + my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath); + $msg->attach(Type => $type, + Path => $attachmentpath, + Filename => $fname + ); + + } else { + my $envdata = ''; + foreach (@envvars) { + $envdata .= "$_: $ENV{$_}\n"; + } + foreach (@loncvars) { + $envdata .= "$_: $ENV{$_}\n"; + } + $msg->attach(Type => 'TEXT', + Data => $envdata); + } + +### Send it: + # ->send can cause an sh launch which can pass all of %ENV along # which can be to large for /bin/sh's little mind my %oldENV=%ENV; undef(%ENV); - if (my $fh = $msg->open()) { - print $fh $supportmsg; - $fh->close; - } + $msg->send('sendmail'); %ENV=%oldENV; undef(%oldENV); - $r->print(<print(qq| Your support request contained the following information:

@@ -563,22 +646,19 @@ END -
- +
-END - my @textmsg = split/\n/,$supportmsg; - foreach my $line (@textmsg) { - $line =~ s|^||; - $line =~ s|:|:|; - $r->print("$line
"); - } - $r->print('
$displaymsg
- + + + +
+
+
+ @@ -589,10 +669,11 @@ END
Additional information recorded
- '); + |); foreach (@envvars) { - $r->print("$_: print("$_: $ENV{$_}, "); + } } $r->print("