--- loncom/interface/lonsupportreq.pm 2019/08/28 02:17:10 1.79.2.7 +++ loncom/interface/lonsupportreq.pm 2017/10/13 19:59:11 1.92 @@ -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.92 2017/10/13 19:59:11 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'}; @@ -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); @@ -321,10 +313,9 @@ $jscript $loaditems // ]]> + ENDJS - if ($knownuser) { - $js .="\n".''; - } elsif ($recaptcha_version >=2) { + if ($recaptcha_version >=2) { $js.= "\n".''."\n"; } my %add_entries = ( @@ -583,8 +574,8 @@ ENDJS } $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(); $num ++; @@ -676,6 +667,9 @@ sub print_request_receipt { my $admin = $Apache::lonnet::perlvar{'lonAdminMail'}; my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'}; my $defdom = &get_domain(); + my ($to,$bcc,$addtext) = + &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', + $defdom,$origmail); my $from = $admin; my %helpform; my %domconfig = @@ -719,12 +713,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; @@ -893,33 +883,6 @@ $lt{'date'}: $reporttime } } } - - my ($requname,$requdom,$reqemail); - foreach my $field ('uname','udom','email') { - $env{'form.'.$field} =~ s/^\s+//; - $env{'form.'.$field} =~ s/\s+$//; - } - if ($env{'form.uname'} =~ /^$match_username$/) { - $requname = $env{'form.uname'}; - } - if ($env{'form.udom'} =~ /^$match_domain$/) { - $requdom = $env{'form.udom'}; - } - if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { - $reqemail = $env{'form.email'}; - } - - my $dom_in_effect; - unless ($env{'user.domain'} eq 'public') { - $dom_in_effect = $env{'user.domain'}; - } - if ($dom_in_effect eq '') { - $dom_in_effect = $requdom; - } - if ($dom_in_effect eq '') { - $dom_in_effect = $defdom; - } - $displaymsg .= ''. $lt{'date'}.': '.$reporttime.'
'."\n"; @@ -942,11 +905,6 @@ END &print_header($r,$url,'process'); } my $bad_email = 0; - my ($to,$bcc,$addtext) = - &Apache::loncommon::build_recipient_list(undef,'helpdeskmail', - $dom_in_effect,$origmail, - $requname,$requdom, - $reqemail); if ($to =~ /,/) { my @ok_email; foreach my $email (split(/,/,$to)) { @@ -984,8 +942,12 @@ END } $r->print(&Apache::loncommon::confirmwrapper($message)); - if ($reqemail ne '') { - $from = $reqemail; + if (defined($env{'form.email'})) { + $env{'form.email'} =~ s/^\s+//; + $env{'form.email'} =~ s/\s+$//; + if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) { + $from = $env{'form.email'}; + } } if (defined($env{'form.cc'})) { @@ -1089,39 +1051,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);