--- loncom/interface/lonsupportreq.pm 2019/08/28 02:17:10 1.79.2.7 +++ loncom/interface/lonsupportreq.pm 2019/07/23 13:58:53 1.96 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Helpdesk request form # -# $Id: lonsupportreq.pm,v 1.79.2.7 2019/08/28 02:17:10 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.96 2019/07/23 13:58:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,8 +29,6 @@ package Apache::lonsupportreq; use strict; -use MIME::Types; -use MIME::Lite; use CGI::Cookie(); use Apache::Constants qw(:common); use Apache::loncommon(); @@ -321,10 +319,9 @@ $jscript $loaditems // ]]> + ENDJS - if ($knownuser) { - $js .="\n".''; - } elsif ($recaptcha_version >=2) { + if ($recaptcha_version >=2) { $js.= "\n".''."\n"; } my %add_entries = ( @@ -402,7 +399,7 @@ ENDJS } } } - unless ($helpform{'user'} eq 'no') { + unless (($helpform{'user'} eq 'no') || ($env{'request.lti.login'})) { $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]); my $udom_input = '&').'" />'."\n"; @@ -439,12 +436,14 @@ ENDJS } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; + $i = $num%2; + } + unless ($env{'request.lti.login'}) { + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]). + $server."\n".'&').'" />'."\n". + &Apache::lonhtmlcommon::row_closure(); } - $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]). - $server."\n".'&').'" />'."\n". - &Apache::lonhtmlcommon::row_closure(); unless ($helpform{'phone'} eq 'no') { my $reqd; if ($helpform{'phone'} eq 'req') { @@ -456,7 +455,7 @@ ENDJS $num ++; $i = $num%2; } - unless ($helpform{'course'} eq 'no') { + unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) { $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]); if ($totcodes > 0) { my $numtitles = @codetitles; @@ -531,7 +530,7 @@ ENDJS $num ++; $i = $num%2; } - unless ($helpform{'section'} eq 'no') { + unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) { $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]); if ($sectionlist) { $output .= "
' - .'' + .' ' + .'' .'
'."\n".$html_lt{'uplf'}.$showmax."\n" .&Apache::lonhtmlcommon::row_closure(); $num ++; @@ -702,10 +701,10 @@ sub print_request_receipt { unless ($helpform{'phone'} eq 'no') { $formvars{'phone'} = 1; } - unless ($helpform{'section'} eq 'no') { + unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) { $formvars{'section'} = 1; } - unless ($helpform{'course'} eq 'no') { + unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) { $formvars{'course'} = 1; } unless ($helpform{'cc'} eq 'no') { @@ -714,7 +713,7 @@ sub print_request_receipt { unless ($helpform{'screenshot'} eq 'no') { $formvars{'screenshot'} = 1; } - my $coursecode; + my ($coursecode,$sourceurl); if ($formvars{'course'}) { $coursecode = $env{'form.coursecode'}; if ($coursecode eq '') { @@ -812,7 +811,15 @@ sub print_request_receipt { $badccmsg .= '
'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs)); } } - $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'"; + if ($env{'request.lti.login'}) { + if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) { + $env{'form.user'} = "'".$env{'user.name'}.':'.$env{'user.domain'}."'"; + } + $sourceurl = &Apache::lonnet::absolute_url().$url; + } else { + $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'"; + $sourceurl = $env{'form.sourceurl'}; + } if ($formvars{'course'}) { $env{'form.crsi'} = $env{'form.title'}; if ($coursecode ne '') { @@ -851,7 +858,7 @@ sub print_request_receipt { } $supportmsg .= "$lt{'subject'}: $env{'form.subject'} $lt{'description'}: $env{'form.description'} -$lt{'sourceurl'}: $env{'form.sourceurl'} +$lt{'sourceurl'}: $sourceurl $lt{'date'}: $reporttime "; @@ -885,6 +892,7 @@ $lt{'date'}: $reporttime next if ($helpform{$item} eq 'no'); } next if (($item eq 'crsi') && ($helpform{'course'} eq 'no')); + next if (($item eq 'user') && ($env{'request.lti.login'})); my $showitem = $env{'form.'.$item}; $showitem = &Apache::loncommon::cleanup_html($showitem); $displaymsg .= @@ -1037,6 +1045,18 @@ END if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) { $cookies{'lonLinkID'} = $1; } + my $lti_info; + if (($env{'request.lti.login'}) && ($env{'request.course.id'})) { + my $ltidom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if ($ltidom) { + my %lti = &Apache::lonnet::get_domain_lti($ltidom,'provider'); + if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') { + if ($lti{$env{'request.lti.login'}}{'consumer'}) { + $lti_info = "LTI consumer: ".$lti{$env{'request.lti.login'}}{'consumer'}."\n"; + } + } + } + } if ($attachmentpath =~ m-/([^/]+)$-) { $fname = $1; $displaymsg .= '
' @@ -1054,6 +1074,9 @@ END foreach my $var (@envvars) { $supportmsg .= "$var: $env{$var}\n"; } + if ($lti_info) { + $supportmsg .= $lti_info; + } } my $cc_string; @@ -1077,6 +1100,9 @@ END foreach my $var (@loncvars) { $attachment_text .= "$var: $env{$var}\n"; } + if ($lti_info) { + $attachment_text .= $lti_info; + } } if ($addtext) { @@ -1089,39 +1115,9 @@ END } } - my $msg = MIME::Lite->new( - From => $from, - To => $to, - Subject => $subject, - Type =>'TEXT', - Data => $supportmsg, - ); - if ($homeserver) { - if (@ok_ccs > 0) { - my $cc_string = join(', ',@ok_ccs); - $msg->add("Cc" => $cc_string); - } - } - 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 - ); - - } elsif ($attachment_text ne '') { - $msg->attach(Type => 'TEXT', - Data => $attachment_text); - } - -### 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);