package Apache::lonsupportreq;
use strict;
use lib qw(/home/httpd/lib/perl);
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');
$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');
$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;
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;
}
$r->print(<<END);
<html>
<head>
<title>LON-CAPA support request</title>
END
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" onSubmit="return validate()">
<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>
$server$origurl<input type="hidden" name="origurl" value="$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>
<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="submit" value="Submit Request Form" />
</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
# 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
}
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 $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
my $to = $Apache::lonnet::perlvar{'lonSupportEMail'};
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');
&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 =<FILE>;
# close(FILE);
# foreach (@buffer) {
# print STDERR $_;
# }
# }
# }
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
|;
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 = 'helpdesk@lon-capa.org';
$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 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');
if (my $fh = $msg->open()) {
print $fh $supportmsg;
$fh->close;
}
$r->print(<<END);
<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>
END
my @textmsg = split/\n/,$supportmsg;
foreach my $line (@textmsg) {
$line =~ s|^|<font color="$fontcolor">|;
$line =~ s|:|:</font><font color="$vlinkcolor">|;
$r->print("$line</font><br />");
}
$r->print('</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="130" bgcolor="'.$tablecolor.'">
<table width="130" 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) {
$r->print("$_: <font color='$vlinkcolor>$ENV{$_}</font>, ");
$supportmsg .= "$_: $ENV{$_}\n";
}
$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>