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 = (<<END);
<script>
function validate() {
if (document.logproblem.email.value.indexOf("\@") == -1) {
alert("You must enter a valid e-mail address");
return
}
document.logproblem.submit();
}
</script>
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(<<END);
<html>
<head>
<title>LON-CAPA support request</title>
$scripttag
</head>
$bodytag
<table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<form method="post" name="logproblem" enctype="multipart/form-data">
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Name:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
END
my $fullname = '';
if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
$fullname = "$firstname $lastname";
$r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");
} else {
if (defined($firstname) && $firstname ne '') {
$fullname = $firstname;
} elsif (defined($lastname) && $lastname ne '') {
$fullname= " $lastname";
}
$r->print('<input type="text" size="20" name="username" value="'.$fullname.'" /><br />');
}
$r->print(<<END);
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>E-mail address:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<input type="text" size="20" name="email" value="$email" /><br />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>username/domain:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
END
my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';
my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />';
if (defined($uname) && defined($udom)) {
$r->print('<i>username</i>: '.$uname.' <i>domain</i>: '.$udom.$udom_input.$uname_input);
} else {
my $udomform = '';
my $unameform = '';
if (defined($udom)) {
$udomform = '<i>domain</i>: '.$udom.$udom_input;
} elsif (defined($uname)) {
$unameform = '<i>username</i>: '.$uname.' '.$uname_input;
}
if ($udomform eq '') {
$udomform = '<i>domain</i>: ';
$udomform .= &Apache::loncommon::select_dom_form('','udom');
}
if ($unameform eq '') {
$unameform= '<i>username</i>: <input type="text" size="20" name="loncname" value="'.$uname.'" /> ';
}
$r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');
}
$r->print(<<END);
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>URL of page:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
http://$server$origurl<input type="hidden" name="origurl" value="http://$server$origurl" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Phone #:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<input type="text" size="15" name="phone"><br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Course Details:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table border="0" cellpadding="3" cellspacing="3">
<tr>
<td>
END
if ($coursecodes{$cnum}) {
foreach (@codetitles) {
$r->print('<i>'.$_.'</i>: '.$codes{$cnum}{$_}.'; ');
}
$r->print(' <input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
} else {
$r->print('Enter institutional course code:
<input type="text" name="coursecode" size="15" value="" />');
}
if ($ctitle) {
$r->print('<br /><i>Title</i>: '.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');
} else {
$r->print('<br />Enter course title:
<input type="text" name="title" size="15" value="" />');
}
$r->print(<<END);
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Section Number: </b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
END
if ($sectionlist) {
$r->print("<select name=\"section\">");
foreach (sort keys %groupid) {
if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
$r->print("<option value=\"$_\" />$_");
} else {
$r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_})");
}
}
$r->print("</select>");
} else {
$r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");
}
$r->print(<<END);
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Subject</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<input type="text" size="40" name="subject">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Detailed description:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
END
if (defined($ENV{'user.name'})) {
$r->print(<<END);
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Optional file upload:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<input type="file" name="screenshot" size="20" /><br />Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size).
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
END
}
$r->print(<<END);
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Finish:</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
<input type="hidden" name="action" value="process" />
<input type="button" value="Submit Request Form" onClick="validate()"/>
</td>
<td> </td>
<td>
<input type="reset" value="Clear Form">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
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#<br />#g;
my $displaymsg = qq|
<font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $ENV{'form.username'}</font><br />
<font color="$fontcolor">Email: </font><font color="$vlinkcolor">$ENV{'form.email'}</font><br />
<font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$ENV{'form.uname'} - $ENV{'form.udom'}</font><br />
<font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$ENV{'form.phone'}</font><br />
<font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}</font><br />
<font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$ENV{'form.subject'}</font><br />
<font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
<font color="$fontcolor">URL: </font><font color="$vlinkcolor">$ENV{'form.origurl'}</font><br />
<font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
|;
if ($to =~ m/^[^\@]+\@[^\@]+$/) {
$r->print(<<END);
<html>
<head>
<title>LON-CAPA support request recorded</title>
</head>
$bodytag
<h3>A support request has been sent to $to</h3>
END
} else {
$to = $admin;
if ($to =~ m/^[^\@]+\@[^\@]+$/) {
$r->print(<<END);
<html>
<head>
<title>LON-CAPA support request recorded</title>
</head>
$bodytag
<h3>A support request has been sent to $to</h3>
END
} else {
$r->print(<<END);
<html>
<head>
<title>LON-CAPA support request recorded</title>
</head>
$bodytag
<h3>Warning: Problem with support e-mail address</h3>
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 <b>not</b> 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 .= "<br />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 .= "<br />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|
<b>Your support request contained the following information</b>:<br /><br />
<table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Information supplied</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>$displaymsg</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000">
<img src="/adm/lonMisc/blackdot.gif" /><br />
</td>
</tr>
<tr>
<td width="140" bgcolor="$tablecolor">
<table width="140" border="0" cellpadding="8" cellspacing="0">
<tr>
<td align="right"><b>Additional information recorded</b>
</td>
</tr>
</table>
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
<td>
|);
foreach (@envvars) {
unless($ENV{$_} eq '') {
$r->print("$_: <font color='$vlinkcolor'>$ENV{$_}</font>, ");
}
}
$r->print("
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
");
}
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;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>