--- loncom/interface/lonsupportreq.pm 2014/01/17 17:08:04 1.76 +++ loncom/interface/lonsupportreq.pm 2015/06/23 02:42:34 1.81 @@ -1,5 +1,5 @@ # -# $Id: lonsupportreq.pm,v 1.76 2014/01/17 17:08:04 bisitz 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(); @@ -116,11 +114,13 @@ sub print_request_form { my $sourceurl = $machine.$origurl; $server = $machine.&Apache::loncommon::cleanup_html($origurl); $server =~ s/\?.*$//; - my %lt = &Apache::lonlocal::texthash ( + my %js_lt = &Apache::lonlocal::texthash ( email => 'The e-mail address you entered', notv => 'is not a valid e-mail address', rsub => 'You must include a subject', rdes => 'You must include a description', + ); + my %html_lt = &Apache::lonlocal::texthash ( name => 'Name', subm => 'Submit Request', emad => 'Your e-mail address', @@ -143,22 +143,24 @@ 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', ); + &js_escape(\%js_lt); + &html_escape(\%html_lt); my $scripttag = (<<"END"); function validate() { if (validmail(document.logproblem.email) == false) { - alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}."); + alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}."); return; } if (document.logproblem.subject.value == '') { - alert("$lt{'rsub'}."); + alert("$js_lt{'rsub'}."); return; } if (document.logproblem.description.value == '') { - alert("$lt{'rdes'}."); + alert("$js_lt{'rdes'}."); return; } document.logproblem.submit(); @@ -271,6 +273,7 @@ $jscript $loaditems // ]]> + ENDJS my %add_entries = ( style => "margin-top:0px;margin-bottom:0px;", @@ -299,7 +302,7 @@ ENDJS &mt('(All fields marked with * are required.)'). ''. &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n"; + &Apache::lonhtmlcommon::row_title($html_lt{'name'},undef,$css[$num])."\n"; my $fullname = ''; if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { $fullname = "$firstname $lastname"; @@ -312,11 +315,14 @@ ENDJS } $output .= '&').'" />'."\n"; } - $output .= '      '. + $output .= '      '. &Apache::lonhtmlcommon::row_closure()."\n"; $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]). + $output .= &Apache::lonhtmlcommon::row_title( + ''. + $html_lt{'emad'}.' *' + ,undef,$css[$i]). '&').'" />
'."\n". &Apache::lonhtmlcommon::row_closure(); @@ -324,61 +330,61 @@ ENDJS $i = $num%2; if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { if ($homeserver) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]). + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]). '
'."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; } } - $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]); my $udom_input = '&').'" />'."\n"; my $uname_input = '&').'" />'."\n"; if (($env{'user.name'} =~ /^$match_username$/) && ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { - $output .= ''.$lt{'unme'}.': '.$uname.'  '.$lt{'doma'}.': '.$udom.$udom_input.$uname_input; + $output .= ''.$html_lt{'unme'}.': '.$uname.'  '.$html_lt{'doma'}.': '.$udom.$udom_input.$uname_input; } else { my $udomform = ''; my $unameform = ''; if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { - $output .= $lt{'entu'}; + $output .= $html_lt{'entu'}; } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { - $output .= $lt{'chdo'}; + $output .= $html_lt{'chdo'}; } else { - $output .= $lt{'entr'}; + $output .= $html_lt{'entr'}; } $output .= '
'."\n"; if (!$public) { if ($env{'user.domain'} =~ /^$match_domain$/) { - $udomform = ''.$lt{'doma'}.': '.$udom.$udom_input; + $udomform = ''.$html_lt{'doma'}.': '.$udom.$udom_input; } elsif ($env{'user.name'} =~ /^$match_username$/) { - $unameform = ''.$lt{'unme'}.': '.$uname.'  '.$uname_input; + $unameform = ''.$html_lt{'unme'}.': '.$uname.'  '.$uname_input; } } if ($udomform eq '') { - $udomform = ''.$lt{'doma'}.': '; + $udomform = ''.$html_lt{'doma'}.': '; $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n"; } if ($unameform eq '') { - $unameform= ''.$lt{'unme'}.'  '; + $unameform= ''.$html_lt{'unme'}.'  '; } $output .= $unameform.$udomform; } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]). + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]). $server."\n".'&').'" />'."\n". &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_evenrow_value'). + &Apache::lonhtmlcommon::row_title("$html_lt{'phon'}",undef,'LC_evenrow_value'). '
'."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]); if ($cnum) { if ($coursecodes{$cnum}) { foreach my $item (@codetitles) { @@ -386,14 +392,14 @@ ENDJS } $output .= ' &').'" />'."\n"; } else { - $output .= $lt{'enin'}.':  + $output .= $html_lt{'enin'}.':  '."\n"; } } else { if ($totcodes > 0) { my $numtitles = @codetitles; if ($numtitles == 0) { - $output .= $lt{'enin'}.':  + $output .= $html_lt{'enin'}.':  '."\n"; } else { my @standardnames = &Apache::loncommon::get_standard_codeitems(); @@ -403,7 +409,7 @@ ENDJS } $output .= ''."\n"; } @@ -440,30 +446,30 @@ ENDJS if ($numtitles > 4) { $output .= '

'.$codetitles[$numtitles].'
'."\n". ''."\n"; } } } else { - $output .= $lt{'enin'}.':  + $output .= $html_lt{'enin'}.':  '."\n"; } } if ($ctitle) { - $output .= '
'.$lt{'titl'}.': '.$ctitle. + $output .= '
'.$html_lt{'titl'}.': '.$ctitle. '&').'" />'."\n"; } else { - $output .= '
'.$lt{'enct'}.':  + $output .= '
'.$html_lt{'enct'}.':  '."\n"; } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]); if ($sectionlist) { $output .= ""; @@ -482,21 +488,28 @@ ENDJS $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; - $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value'). - ' '."\n". + $output .= &Apache::lonhtmlcommon::row_title( + ''. + $html_lt{'subj'}.' *' + ,undef,'LC_oddrow_value'). + ''."\n". &Apache::lonhtmlcommon::row_closure(). - &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value'). - ' '."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { if ($homeserver) { - $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]). - '
'. - "\n".$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; } @@ -505,25 +518,28 @@ ENDJS my ($captchaform,$error) = &Apache::loncommon::captcha_display('login',$lonhost); if ($captchaform) { - $output .= &Apache::lonhtmlcommon::row_title(&mt('Validation'),undef, - $css[$i])."\n". + $output .= &Apache::lonhtmlcommon::row_title( + ''. + &mt('Validation'). + ' *' + ,undef,$css[$i]). $captchaform."\n". &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; } } - $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]); + $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]); $output .= <
'.$codetitles[0].'
'."\n". '
'.$codetitles[$i].'
'."\n". ''."\n". '
-   +     - +
@@ -827,8 +843,9 @@ END if ((defined($env{'user.name'})) && (!$public)) { if ($homeserver && $env{'form.screenshot.filename'}) { $attachmentsize = length($env{'form.screenshot'}); - if ($attachmentsize > 131072) { - $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); + if ($attachmentsize > 1048576) { + $displaymsg .= '
'. + &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'); } @@ -861,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"; @@ -901,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);