--- loncom/interface/lonsupportreq.pm 2019/08/03 23:40:16 1.79.2.5 +++ loncom/interface/lonsupportreq.pm 2017/01/18 21:24:40 1.86 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Helpdesk request form # -# $Id: lonsupportreq.pm,v 1.79.2.5 2019/08/03 23:40:16 raeburn Exp $ +# $Id: lonsupportreq.pm,v 1.86 2017/01/18 21:24:40 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(); @@ -69,9 +67,7 @@ sub handler { } } my $origurl = $env{'form.origurl'}; - if ($origurl =~ m{^https?://[^/]+(.*)$}) { - $origurl =~ $1; - } + $origurl =~ s{^https?://}{}; $origurl =~ s/(`)//g; $origurl =~ s/\$/\(\$\)/g; my $command = $env{'form.command'}; @@ -83,7 +79,7 @@ sub handler { } return OK; } - + sub print_request_form { my ($r,$origurl,$function) = @_; my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid, @@ -109,7 +105,7 @@ sub print_request_form { } } } - if (($env{'user.name'} =~ /^$match_username$/) && + if (($env{'user.name'} =~ /^$match_username$/) && ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) { $knownuser = 1; } else { @@ -153,6 +149,7 @@ sub print_request_form { } } + my %coursecodes; my %codes; my @codetitles; my %cat_titles; @@ -160,7 +157,9 @@ sub print_request_form { my %idlist; my %idnums; my %idlist_titles; + my $caller = 'global'; my $totcodes = 0; + my $format_reply; my $jscript = ''; my $loaditems = qq| function initialize_codes() { @@ -168,17 +167,10 @@ function initialize_codes() { } |; unless ($helpform{'course'} eq 'no') { - my $instcats = &Apache::lonnet::get_dom_instcats($codedom); - if (ref($instcats) eq 'HASH') { - if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') && - (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) { - %codes = %{$instcats->{'codes'}}; - @codetitles = @{$instcats->{'codetitles'}}; - %cat_titles = %{$instcats->{'cat_titles'}}; - %cat_order = %{$instcats->{'cat_order'}}; - $totcodes = scalar(keys(%codes)); - } - if ($totcodes > 0) { + $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom); + if ($totcodes > 0) { + $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order); + if ($format_reply eq 'ok') { my $numtypes = @codetitles; &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles); my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles); @@ -254,7 +246,7 @@ END subj => 'Subject', detd => 'Detailed Description', opfi => 'Optional file upload', - uplf => 'Upload a file (e.g., a screenshot) relevant to your help request', + uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (1 MB max.)', fini => 'Finish', clfm => 'Clear Form', ); @@ -321,6 +313,7 @@ $jscript $loaditems // ]]> + ENDJS if ($recaptcha_version >=2) { $js.= "\n".''."\n"; @@ -357,7 +350,7 @@ ENDJS unless ($helpform{'username'} eq 'no') { my ($reqd,$namefield,$fullname); if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) { - $fullname = "$firstname $lastname"; + $fullname = "$firstname $lastname"; $namefield = $fullname.'&').'" />'."\n"; } else { if (defined($firstname) && $firstname ne '') { @@ -385,7 +378,7 @@ ENDJS &HTML::Entities::encode($email,'"<>&').'" />'."\n"; unless ($shownsubmit) { $output .= $topsubmit; - } + } $output .= &Apache::lonhtmlcommon::row_closure(); $num ++; $i = $num%2; @@ -548,7 +541,7 @@ ENDJS $output .= ''."\n". ''."\n"; - } else { + } else { $output .= ''."\n"; } $output .= &Apache::lonhtmlcommon::row_closure(); @@ -574,16 +567,14 @@ ENDJS if ($homeserver) { unless ($helpform{'screenshot'} eq 'no') { my $max = 1048576; - my $showmax = 1.00; if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) { - $max *= $helpform{'maxsize'}; - $showmax = $helpform{'maxsize'}; + $max *= $helpform{'maxsize'}; } - $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')'; - $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]). - '
'. - "\n".$html_lt{'uplf'}.$showmax."\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; } @@ -633,7 +624,7 @@ sub print_request_receipt { if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) { $public = 1; } - my $lonhost = $r->dir_config('lonHostID'); + my $lonhost = $r->dir_config('lonHostID'); unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('login',$lonhost); @@ -663,12 +654,7 @@ sub print_request_receipt { my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME'); my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role'); my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id'); - my @cookievars; - if ($ENV{'SERVER_PORT'} == 443) { - @cookievars = ('lonLinkID'); - } else { - @cookievars = ('lonID'); - } + my @cookievars = ('lonID'); my $admin = $Apache::lonnet::perlvar{'lonAdminMail'}; my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; @@ -719,12 +705,8 @@ sub print_request_receipt { $coursecode = $env{'form.coursecode'}; if ($coursecode eq '') { my $totcodes = 0; - my $instcats = &Apache::lonnet::get_dom_instcats($defdom); - if (ref($instcats) eq 'HASH') { - if (ref($instcats->{'codes'}) eq 'HASH') { - $totcodes = scalar(keys(%{$instcats->{'codes'}})); - } - } + my %coursecodes; + $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom); my @standardnames = &Apache::loncommon::get_standard_codeitems(); if ($totcodes > 0) { my $noregexps = 1; @@ -848,7 +830,7 @@ sub print_request_receipt { } if ($formvars{'course'}) { $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n"; - } + } $supportmsg .= "$lt{'subject'}: $env{'form.subject'} $lt{'description'}: $env{'form.description'} $lt{'sourceurl'}: $env{'form.sourceurl'} @@ -976,24 +958,18 @@ END my $fname; my $attachmentpath = ''; - my $showsize = ''; - + my $attachmentsize = ''; if ((defined($env{'user.name'})) && (!$public)) { if ($homeserver && $env{'form.screenshot.filename'}) { unless ($helpform{'screenshot'} eq 'no') { - my $attachmentsize = length($env{'form.screenshot'}); + $attachmentsize = length($env{'form.screenshot'}); my $max = 1048576; - my $showmax = 1.00; if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) { $max *= $helpform{'maxsize'}; - $showmax = $helpform{'maxsize'}; } - $showmax = '('.sprintf("%.2f",$showmax).' MB)'; - $showsize = $attachmentsize/1048576; - $showsize = '('.sprintf("%.2f",$showsize).' MB)'; if ($attachmentsize > $max) { $displaymsg .= '
'. - &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).''; + &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'); } @@ -1006,14 +982,13 @@ END if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) { $cookies{'lonID'} = $1; } - if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) { - $cookies{'lonLinkID'} = $1; - } + if ($attachmentpath =~ m-/([^/]+)$-) { $fname = $1; $displaymsg .= '
' - .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].' - ,''.$fname.' '.$showsize, + .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].' + ,''.$fname.'' + ,$attachmentsize ,$env{'user.name'}.':'.$env{'user.domain'} ); $supportmsg .= "\n"; @@ -1027,7 +1002,7 @@ END $supportmsg .= "$var: $env{$var}\n"; } } - + my $cc_string; if ($homeserver) { if (@ok_ccs > 0) { @@ -1035,20 +1010,22 @@ END } } - my $attachment_text = ''; + my $attachment_text; unless ($homeserver && $attachmentpath) { + my $envdata = ''; foreach my $var (@cookievars) { - $attachment_text .= "$var: $cookies{$var}\n"; + $envdata .= "$var: $cookies{$var}\n"; } foreach my $var (@ENVvars) { - $attachment_text .= "$var: $ENV{$var}\n"; + $envdata .= "$var: $ENV{$var}\n"; } foreach my $var (@envvars) { - $attachment_text .= "$var: $env{$var}\n"; + $envdata .= "$var: $env{$var}\n"; } foreach my $var (@loncvars) { - $attachment_text .= "$var: $env{$var}\n"; + $envdata .= "$var: $env{$var}\n"; } + $attachment_text = $envdata; } if ($addtext) { @@ -1061,39 +1038,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);