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 Apache::lonlocal; sub handler { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; if ($r->header_only) { return OK; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','origurl','function']); my $action = $ENV{'form.action'}; my $function = $ENV{'form.function'}; my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'}); if ($action eq 'process') { &print_request_receipt($r,$origurl,$function); } else { &print_request_form($r,$origurl,$function); } return OK; } sub print_request_form { my ($r,$origurl,$function) = @_; 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'}; $uhost = $ENV{'request.host'}; $uname = $ENV{'user.name'}; $udom = $ENV{'user.domain'}; $uhome = $ENV{'user.home'}; $urole = $ENV{'request.role'}; $usec = $ENV{'request.course.sec'}; $cid = $ENV{'request.course.id'}; $server = $ENV{'SERVER_NAME'}; 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; } if ($cdom && $cnum) { my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum); $ctitle = $csettings{'description'}; $ccode = $csettings{'internal.coursecode'}; $sectionlist = $csettings{'internal.sectionnums'}; } if ($ENV{'environment.critnotification'}) { $email = $ENV{'environment.critnotification'}; } if (!$email && $ENV{'environment.notification'}) { $email = $ENV{'environment.notification'}; } if ($ENV{'environment.lastname'}) { $lastname = $ENV{'environment.lastname'}; } if ($ENV{'environment.firstname'}) { $firstname = $ENV{'environment.firstname'}; } my @sections = split/,/,$sectionlist; my %groupid = (); foreach (@sections) { my ($sec,$grp) = split/:/,$_; $groupid{$sec} = $grp; } my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'}; my $codedom = $defdom; my %coursecodes = (); my %codes = (); my @codetitles = (); my %cat_titles = (); my %cat_order = (); my $caller = 'global'; my $totcodes = 0; my $format_reply; if ($cdom) { $codedom = $cdom; } if ($cnum) { $coursecodes{$cnum} = $ccode; if ($ccode eq '') { $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes); } else { $coursecodes{$cnum} = $ccode; $caller = $cnum; $totcodes ++; } } else { $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes); } if ($totcodes > 0) { $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); } $r->print(< LON-CAPA support request $scripttag $bodytag
END if (defined($ENV{'user.name'})) { $r->print(< END } $r->print(<
Name:
END my $fullname = ''; if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { $fullname = "$firstname $lastname"; $r->print("$fullname"); } else { if (defined($firstname) && $firstname ne '') { $fullname = $firstname; } elsif (defined($lastname) && $lastname ne '') { $fullname= " $lastname"; } $r->print('
'); } $r->print(<

E-mail address:


username/domain:
END my $udom_input = ''; my $uname_input = ''; if (defined($uname) && defined($udom)) { $r->print('username: '.$uname.'  domain: '.$udom.$udom_input.$uname_input); } else { my $udomform = ''; my $unameform = ''; if (defined($udom)) { $udomform = 'domain: '.$udom.$udom_input; } elsif (defined($uname)) { $unameform = 'username: '.$uname.'  '.$uname_input; } if ($udomform eq '') { $udomform = 'domain: '; $udomform .= &Apache::loncommon::select_dom_form('','udom'); } if ($unameform eq '') { $unameform= 'username  '; } $r->print($unameform.$udomform.'
Enter the username you use to log-in to your LON-CAPA system, and choose your domain.'); } $r->print(<

URL of page:
http://$server$origurl

Phone #:


Course Details:
END if ($coursecodes{$cnum}) { foreach (@codetitles) { $r->print(''.$_.': '.$codes{$cnum}{$_}.'; '); } $r->print(' '); } else { $r->print('Enter institutional course code:  '); } if ($ctitle) { $r->print('
Title: '.$ctitle.''); } else { $r->print('
Enter course title:  '); } $r->print(<

Section Number:
END if ($sectionlist) { $r->print(""); } else { $r->print(""); } $r->print(<

Subject

Detailed description:

Optional file upload:

Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size).

Finish:
   
END 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','screenshot'); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars); my $supportmsg = 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: $ENV{'form.description'} 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(< LON-CAPA support request recorded $bodytag

A support request has been sent to $to

END } else { $to = $admin; if ($to =~ m/^[^\@]+\@[^\@]+$/) { $r->print(< LON-CAPA support request recorded $bodytag

A support request has been sent to $to

END } else { $r->print(< LON-CAPA support request recorded $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 or administrator at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University. END $to = 'helpdesk@lon-capa.org'; } 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); $msg->send('sendmail'); %ENV=%oldENV; undef(%oldENV); if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) { unlink($attachmentpath); } $r->print(qq| Your support request contained the following information:

Information supplied
$displaymsg

Additional information recorded
|); foreach (@envvars) { unless($ENV{$_} eq '') { $r->print("$_: $ENV{$_}, "); } } $r->print("
"); } sub retrieve_instcodes { my ($coursecodes,$codedom,$totcodes) = @_; my %courses = &Apache::lonnet::courseiddump($codedom,'.',1); foreach my $course (keys %courses) { if ($courses{$course} =~ m/^[^:]*:([^:]+)$/) { $$coursecodes{$course} = &Apache::lonnet::unescape($1); $totcodes ++; } } return $totcodes; } 1;