Diff for /loncom/interface/lonsupportreq.pm between versions 1.79.2.10 and 1.90

version 1.79.2.10, 2022/01/19 13:57:19 version 1.90, 2017/01/23 19:51:52
Line 29 Line 29
 package Apache::lonsupportreq;  package Apache::lonsupportreq;
   
 use strict;  use strict;
 use MIME::Types;  
 use MIME::Lite;  
 use CGI::Cookie();  use CGI::Cookie();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::loncommon();  use Apache::loncommon();
Line 69  sub handler { Line 67  sub handler {
         }          }
     }      }
     my $origurl = $env{'form.origurl'};      my $origurl = $env{'form.origurl'};
     if ($origurl =~ m{^https?://[^/]+(.*)$}) {      $origurl =~ s{^https?://}{};
         $origurl = $1;  
     }  
     $origurl =~ s/(`)//g;      $origurl =~ s/(`)//g;
     $origurl =~ s/\$/\(\$\)/g;      $origurl =~ s/\$/\(\$\)/g;
     my $command = $env{'form.command'};      my $command = $env{'form.command'};
Line 153  sub print_request_form { Line 149  sub print_request_form {
         }          }
     }      }
   
       my %coursecodes;
     my %codes;      my %codes;
     my @codetitles;      my @codetitles;
     my %cat_titles;      my %cat_titles;
Line 160  sub print_request_form { Line 157  sub print_request_form {
     my %idlist;      my %idlist;
     my %idnums;      my %idnums;
     my %idlist_titles;      my %idlist_titles;
       my $caller = 'global';
     my $totcodes = 0;      my $totcodes = 0;
       my $format_reply;
     my $jscript = '';      my $jscript = '';
     my $loaditems = qq|      my $loaditems = qq|
 function initialize_codes() {  function initialize_codes() {
Line 168  function initialize_codes() { Line 167  function initialize_codes() {
 }  }
     |;      |;
     unless ($helpform{'course'} eq 'no') {      unless ($helpform{'course'} eq 'no') {
         my $instcats = &Apache::lonnet::get_dom_instcats($codedom);          $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
         if (ref($instcats) eq 'HASH') {          if ($totcodes > 0) {
             if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&              $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
                 (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {              if ($format_reply eq 'ok') {
                 %codes = %{$instcats->{'codes'}};  
                 @codetitles = @{$instcats->{'codetitles'}};  
                 %cat_titles = %{$instcats->{'cat_titles'}};  
                 %cat_order = %{$instcats->{'cat_order'}};  
                 $totcodes = scalar(keys(%codes));  
             }  
             if ($totcodes > 0) {  
                 my $numtypes = @codetitles;                  my $numtypes = @codetitles;
                 &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);                  &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);                  my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
Line 321  $jscript Line 313  $jscript
 $loaditems  $loaditems
 // ]]>  // ]]>
 </script>  </script>
   <script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>
 ENDJS  ENDJS
     if ($knownuser) {      if ($recaptcha_version >=2) {
         $js .="\n".'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>';  
     } elsif ($recaptcha_version >=2) {  
         $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";          $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
     }      }
     my %add_entries = (      my %add_entries = (
Line 393  ENDJS Line 384  ENDJS
     $i = $num%2;      $i = $num%2;
     if ($knownuser) {      if ($knownuser) {
         if ($homeserver) {          if ($homeserver) {
             my $ip = &Apache::lonnet::get_requestor_ip($r);              unless ($helpform{'cc'} eq 'no') {
             my %setters;  
             my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =  
                 &Apache::loncommon::blockcheck(\%setters,'com',$ip);  
             unless (($helpform{'cc'} eq 'no') || ($by_ip)) {  
                 $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).                  $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
                            '<input type="text" size="50" name="cc" value="" /><br />'."\n".                             '<input type="text" size="50" name="cc" value="" /><br />'."\n".
                            &Apache::lonhtmlcommon::row_closure();                             &Apache::lonhtmlcommon::row_closure();
Line 587  ENDJS Line 574  ENDJS
                 }                  }
                 $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';                  $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
                 $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])                  $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
                     .' <input type="file" name="screenshot" class="LC_flUpload" size="20" />'                      .' <input type="file" name="screenshot" class="flUpload" size="20" />'
                     .'<input type="hidden" id="LC_free_space" value="'.$max.'" />'                      .'<input type="hidden" id="free_space" value="'.$max.'" />'
                     .'<br />'."\n".$html_lt{'uplf'}.$showmax."\n"                      .'<br />'."\n".$html_lt{'uplf'}.$showmax."\n"
                     .&Apache::lonhtmlcommon::row_closure();                      .&Apache::lonhtmlcommon::row_closure();
                 $num ++;                  $num ++;
Line 667  sub print_request_receipt { Line 654  sub print_request_receipt {
             return;              return;
         }          }
     }      }
     my $ip = &Apache::lonnet::get_requestor_ip($r);      my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
     my %setters;  
     my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =  
         &Apache::loncommon::blockcheck(\%setters,'com',$ip);  
     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','SERVER_ADDR','SERVER_NAME');  
     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');      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 @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
     my @cookievars;      my @cookievars = ('lonID');
     if ($ENV{'SERVER_PORT'} == 443) {  
         @cookievars = ('lonLinkID');  
     } else {  
         @cookievars = ('lonID');  
     }  
   
     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};      my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};      my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
     my $defdom = &get_domain();      my $defdom = &get_domain();
       my ($to,$bcc,$addtext) =
           &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                                    $defdom,$origmail);
     my $from = $admin;      my $from = $admin;
     my %helpform;      my %helpform;
     my %domconfig =      my %domconfig =
Line 716  sub print_request_receipt { Line 697  sub print_request_receipt {
     unless ($helpform{'course'} eq 'no') {      unless ($helpform{'course'} eq 'no') {
         $formvars{'course'} = 1;          $formvars{'course'} = 1;
     }      }
     unless (($helpform{'cc'} eq 'no') || ($by_ip)) {      unless ($helpform{'cc'} eq 'no') {
         $formvars{'cc'} = 1;          $formvars{'cc'} = 1;
     }      }
     unless ($helpform{'screenshot'} eq 'no') {      unless ($helpform{'screenshot'} eq 'no') {
Line 727  sub print_request_receipt { Line 708  sub print_request_receipt {
         $coursecode = $env{'form.coursecode'};          $coursecode = $env{'form.coursecode'};
         if ($coursecode eq '') {          if ($coursecode eq '') {
             my $totcodes = 0;              my $totcodes = 0;
             my $instcats = &Apache::lonnet::get_dom_instcats($defdom);              my %coursecodes;
             if (ref($instcats) eq 'HASH') {              $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom);
                 if (ref($instcats->{'codes'}) eq 'HASH') {  
                     $totcodes = scalar(keys(%{$instcats->{'codes'}}));  
                 }  
             }  
             my @standardnames = &Apache::loncommon::get_standard_codeitems();              my @standardnames = &Apache::loncommon::get_standard_codeitems();
             if ($totcodes > 0) {              if ($totcodes > 0) {
                 my $noregexps = 1;                  my $noregexps = 1;
Line 901  $lt{'date'}: $reporttime Line 878  $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 .= '<span class="LC_helpform_receipt_cat">'.      $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";                     $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
   
Line 950  END Line 900  END
         &print_header($r,$url,'process');          &print_header($r,$url,'process');
     }      }
     my $bad_email = 0;      my $bad_email = 0;
     my ($to,$bcc,$addtext) =  
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',  
                                                  $dom_in_effect,$origmail,  
                                                  $requname,$requdom,  
                                                  $reqemail);  
     if ($to =~ /,/) {      if ($to =~ /,/) {
         my @ok_email;           my @ok_email; 
         foreach my $email (split(/,/,$to)) {          foreach my $email (split(/,/,$to)) {
Line 992  END Line 937  END
     }      }
     $r->print(&Apache::loncommon::confirmwrapper($message));      $r->print(&Apache::loncommon::confirmwrapper($message));
   
     if ($reqemail ne '') {      if (defined($env{'form.email'})) {
         $from = $reqemail;          $env{'form.email'} =~ s/^\s+//;
           $env{'form.email'} =~ s/\s+$//;
           if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
               $from = $env{'form.email'};
           }
     }      }
   
     if (defined($env{'form.cc'})) {      if (defined($env{'form.cc'})) {
Line 1042  END Line 991  END
     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {      if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
         $cookies{'lonID'} = $1;          $cookies{'lonID'} = $1;
     }      }
     if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) {  
         $cookies{'lonLinkID'} = $1;  
     }  
     if ($attachmentpath =~ m-/([^/]+)$-) {      if ($attachmentpath =~ m-/([^/]+)$-) {
         $fname = $1;          $fname = $1;
         $displaymsg .= '<br />'          $displaymsg .= '<br />'
Line 1059  END Line 1006  END
         foreach my $var(@ENVvars) {          foreach my $var(@ENVvars) {
             $supportmsg .= "$var: $ENV{$var}\n";              $supportmsg .= "$var: $ENV{$var}\n";
         }          }
         $supportmsg .= "REMOTE_ADDR: $ip\n";  
         foreach my $var (@envvars) {          foreach my $var (@envvars) {
             $supportmsg .= "$var: $env{$var}\n";              $supportmsg .= "$var: $env{$var}\n";
         }          }
Line 1080  END Line 1026  END
         foreach my $var (@ENVvars) {          foreach my $var (@ENVvars) {
             $attachment_text .= "$var: $ENV{$var}\n";              $attachment_text .= "$var: $ENV{$var}\n";
         }          }
         $attachment_text .= "REMOTE_ADDR: $ip\n";  
         foreach my $var (@envvars) {          foreach my $var (@envvars) {
             $attachment_text .= "$var: $env{$var}\n";              $attachment_text .= "$var: $env{$var}\n";
         }          }
         foreach my $var (@loncvars) {          foreach my $var (@loncvars) {
             $attachment_text .= "$var: $env{$var}\n";              $attachment_text .= "$var: $env{$var}\n";
         }          }
           $attachment_text = $envdata;
     }      }
   
     if ($addtext) {      if ($addtext) {
Line 1099  END Line 1045  END
         }          }
     }      }
   
     my $msg = MIME::Lite->new(      # Compose and send a MIME email
                  From    => $from,      &Apache::loncommon::mime_email($from, $to, $subject, $supportmsg, $cc_string, $bcc, 
                  To      => $to,                                      $attachmentpath, $fname, $attachment_text);
                  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');  
   
     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {      if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
         unlink($attachmentpath);          unlink($attachmentpath);
Line 1155  END Line 1071  END
                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';                         $var.'</span>:&nbsp;'.$ENV{$var}.', ';
         }          }
     }      }
     if ($ip ne '') {  
         $envmsg .= '<span class="LC_helpform_receipt_cat">'.  
                    'REMOTE_ADDR</span>:&nbsp;'.$ip.', ';  
     }  
     foreach my $var (@envvars) {      foreach my $var (@envvars) {
         if ($env{$var} ne '') {           if ($env{$var} ne '') { 
             $envmsg .= '<span class="LC_helpform_receipt_cat">'.              $envmsg .= '<span class="LC_helpform_receipt_cat">'.

Removed from v.1.79.2.10  
changed lines
  Added in v.1.90


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>