--- loncom/interface/lonsupportreq.pm 2017/01/23 01:56:26 1.79.2.2 +++ loncom/interface/lonsupportreq.pm 2015/06/23 02:42:34 1.81 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.79.2.2 2017/01/23 01:56:26 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.81 2015/06/23 02:42:34 musolffc 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,$uname,$udom,$uhome,$urole,$usec,$email,$cid, + my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid, $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server, - $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error, - $captcha,$recaptcha_version); + $formname,$public,$homeserver); $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,14 +103,6 @@ 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'}; @@ -153,7 +143,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', ); @@ -269,7 +259,7 @@ function initialize_codes() { my $allidlist = $idlist{$codetitles[0]}; $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist); $jscript .= $scripttext; - $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles); + $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles); $loaditems = ''; } } @@ -283,10 +273,8 @@ $jscript $loaditems // ]]> + ENDJS - if ($recaptcha_version >=2) { - $js.= "\n".''."\n"; - } my %add_entries = ( style => "margin-top:0px;margin-bottom:0px;", onload => "initialize_codes();", @@ -340,7 +328,7 @@ ENDJS &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - if ($knownuser) { + if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { if ($homeserver) { $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]). '
'."\n". @@ -354,7 +342,8 @@ ENDJS &HTML::Entities::encode($udom,'"<>&').'" />'."\n"; my $uname_input = '&').'" />'."\n"; - if ($knownuser) { + if (($env{'user.name'} =~ /^$match_username$/) && + ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { $output .= ''.$html_lt{'unme'}.': '.$uname.'  '.$html_lt{'doma'}.': '.$udom.$udom_input.$uname_input; } else { my $udomform = ''; @@ -514,23 +503,27 @@ ENDJS &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - if ($knownuser) { + if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 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 { - if ($captcha_form) { + my $lonhost = $r->dir_config('lonHostID'); + my ($captchaform,$error) = + &Apache::loncommon::captcha_display('login',$lonhost); + if ($captchaform) { $output .= &Apache::lonhtmlcommon::row_title( ''. &mt('Validation'). ' *' ,undef,$css[$i]). - $captcha_form."\n". + $captchaform."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; @@ -850,9 +843,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'); } @@ -885,33 +878,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"; @@ -925,12 +900,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);