--- loncom/interface/lonsupportreq.pm 2015/06/09 21:22:57 1.79 +++ loncom/interface/lonsupportreq.pm 2016/09/14 21:15:09 1.84 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.79 2015/06/09 21:22:57 damieng 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'}; @@ -145,7 +151,7 @@ sub print_request_form { subj => 'Subject', detd => 'Detailed Description', opfi => 'Optional file upload', - uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)', + uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (1 MB max.)', fini => 'Finish', clfm => 'Clear Form', ); @@ -275,7 +281,11 @@ $jscript $loaditems // ]]> + ENDJS + if ($recaptcha_version >=2) { + $js.= "\n".''."\n"; + } my %add_entries = ( style => "margin-top:0px;margin-bottom:0px;", onload => "initialize_codes();", @@ -329,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(); @@ -343,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 = ''; @@ -504,26 +513,24 @@ 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]). - '
'. - "\n".$html_lt{'uplf'}."\n". - &Apache::lonhtmlcommon::row_closure(); + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]) + .' ' + .'' + .'
'."\n".$html_lt{'uplf'}."\n" + .&Apache::lonhtmlcommon::row_closure(); $num ++; $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; @@ -843,9 +850,9 @@ END if ((defined($env{'user.name'})) && (!$public)) { if ($homeserver && $env{'form.screenshot.filename'}) { $attachmentsize = length($env{'form.screenshot'}); - if ($attachmentsize > 131072) { + if ($attachmentsize > 1048576) { $displaymsg .= '
'. - &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize).''; + &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 1 MB, and has therefore been discarded.',$attachmentsize).''; } else { $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests'); } @@ -878,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"; @@ -918,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);