--- loncom/interface/lonsupportreq.pm 2015/06/18 20:19:06 1.80
+++ loncom/interface/lonsupportreq.pm 2016/09/14 21:15:09 1.84
@@ -1,5 +1,5 @@
#
-# $Id: lonsupportreq.pm,v 1.80 2015/06/18 20:19:06 musolffc Exp $
+# $Id: lonsupportreq.pm,v 1.84 2016/09/14 21:15:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,8 +27,6 @@
package Apache::lonsupportreq;
use strict;
-use MIME::Types;
-use MIME::Lite;
use CGI::Cookie();
use Apache::Constants qw(:common);
use Apache::loncommon();
@@ -79,18 +77,18 @@ sub handler {
}
return OK;
}
-
+
sub print_request_form {
my ($r,$origurl,$function) = @_;
- my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
+ my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
- $formname,$public,$homeserver);
+ $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
+ $captcha,$recaptcha_version);
$function = &Apache::loncommon::get_users_function() if (!$function);
$ccode = '';
$os = $env{'browser.os'};
$browser = $env{'browser.type'};
$bversion = $env{'browser.version'};
- $uhost = $env{'request.host'};
if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
$public = 1;
} else {
@@ -105,6 +103,14 @@ sub print_request_form {
}
}
}
+ if (($env{'user.name'} =~ /^$match_username$/) &&
+ ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
+ $knownuser = 1;
+ } else {
+ my $lonhost = $r->dir_config('lonHostID');
+ ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
+ &Apache::loncommon::captcha_display('login',$lonhost);
+ }
if ($homeserver) {
$uhome = $env{'user.home'};
$urole = $env{'request.role'};
@@ -277,6 +283,9 @@ $loaditems
ENDJS
+ if ($recaptcha_version >=2) {
+ $js.= "\n".''."\n";
+ }
my %add_entries = (
style => "margin-top:0px;margin-bottom:0px;",
onload => "initialize_codes();",
@@ -330,8 +339,8 @@ ENDJS
&Apache::lonhtmlcommon::row_closure();
$num ++;
$i = $num%2;
- if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
- if ($homeserver) {
+ if ($knownuser) {
+ if ($homeserver) {
$output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
'
'."\n".
&Apache::lonhtmlcommon::row_closure();
@@ -344,8 +353,7 @@ ENDJS
&HTML::Entities::encode($udom,'"<>&').'" />'."\n";
my $uname_input = '&').'" />'."\n";
- if (($env{'user.name'} =~ /^$match_username$/) &&
- ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
+ if ($knownuser) {
$output .= ''.$html_lt{'unme'}.': '.$uname.' '.$html_lt{'doma'}.': '.$udom.$udom_input.$uname_input;
} else {
my $udomform = '';
@@ -505,7 +513,7 @@ ENDJS
&Apache::lonhtmlcommon::row_closure();
$num ++;
$i = $num%2;
- if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
+ if ($knownuser) {
if ($homeserver) {
$output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
.' '
@@ -516,16 +524,13 @@ ENDJS
$i = $num%2;
}
} else {
- my $lonhost = $r->dir_config('lonHostID');
- my ($captchaform,$error) =
- &Apache::loncommon::captcha_display('login',$lonhost);
- if ($captchaform) {
+ if ($captcha_form) {
$output .= &Apache::lonhtmlcommon::row_title(
''.
&mt('Validation').
' *'
,undef,$css[$i]).
- $captchaform."\n".
+ $captcha_form."\n".
&Apache::lonhtmlcommon::row_closure();
$num ++;
$i = $num%2;
@@ -880,33 +885,15 @@ END
}
}
- my $msg = MIME::Lite->new(
- From => $from,
- To => $to,
- Subject => $subject,
- Type =>'TEXT',
- Data => $supportmsg,
- );
+ my $cc_string;
if ($homeserver) {
if (@ok_ccs > 0) {
- my $cc_string = join(', ',@ok_ccs);
- $msg->add("Cc" => $cc_string);
+ $cc_string = join(', ',@ok_ccs);
}
}
- if ($bcc ne '') {
- $msg->add("Bcc" => $bcc);
- }
- $msg->attr("content-type" => "text/plain");
- $msg->attr("content-type.charset" => "UTF-8");
-
- if ($homeserver && $attachmentpath) {
- my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
- $msg->attach(Type => $type,
- Path => $attachmentpath,
- Filename => $fname
- );
- } else {
+ my $attachment_text;
+ unless ($homeserver && $attachmentpath) {
my $envdata = '';
foreach my $var (@cookievars) {
$envdata .= "$var: $cookies{$var}\n";
@@ -920,12 +907,12 @@ END
foreach my $var (@loncvars) {
$envdata .= "$var: $env{$var}\n";
}
- $msg->attach(Type => 'TEXT',
- Data => $envdata);
+ $attachment_text = $envdata;
}
-
-### Send it:
- $msg->send('sendmail');
+
+ # Compose and send a MIME email
+ &Apache::loncommon::mime_email($from, $to, $subject, $supportmsg, $cc_string, $bcc,
+ $attachmentpath, $fname, $attachment_text);
if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
unlink($attachmentpath);