Diff for /loncom/interface/lonsupportreq.pm between versions 1.79.2.5 and 1.88

version 1.79.2.5, 2019/08/03 23:40:16 version 1.88, 2017/01/23 18:30:30
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 83  sub handler { Line 79  sub handler {
     }      }
     return OK;      return OK;
 }  }
      
 sub print_request_form {  sub print_request_form {
     my ($r,$origurl,$function) = @_;      my ($r,$origurl,$function) = @_;
     my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,      my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
Line 109  sub print_request_form { Line 105  sub print_request_form {
             }              }
         }          }
     }      }
     if (($env{'user.name'} =~ /^$match_username$/) &&      if (($env{'user.name'} =~ /^$match_username$/) && 
         ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {          ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
         $knownuser = 1;          $knownuser = 1;
     } else {      } else {
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 ($recaptcha_version >=2) {      if ($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";
Line 357  ENDJS Line 350  ENDJS
     unless ($helpform{'username'} eq 'no') {      unless ($helpform{'username'} eq 'no') {
         my ($reqd,$namefield,$fullname);          my ($reqd,$namefield,$fullname);
         if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {          if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
             $fullname = "$firstname $lastname";              $fullname = "$firstname $lastname"; 
             $namefield = $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";              $namefield = $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
         } else {          } else {
             if (defined($firstname) && $firstname ne '') {              if (defined($firstname) && $firstname ne '') {
Line 385  ENDJS Line 378  ENDJS
                &HTML::Entities::encode($email,'"<>&').'" />'."\n";                 &HTML::Entities::encode($email,'"<>&').'" />'."\n";
     unless ($shownsubmit) {      unless ($shownsubmit) {
         $output .= $topsubmit;          $output .= $topsubmit;
     }      } 
     $output .= &Apache::lonhtmlcommon::row_closure();      $output .= &Apache::lonhtmlcommon::row_closure();
     $num ++;      $num ++;
     $i = $num%2;      $i = $num%2;
Line 548  ENDJS Line 541  ENDJS
             $output .= '</select></div>'."\n".              $output .= '</select></div>'."\n".
                        '<div id="LC_helpdesk_section" style="display:none">'.                         '<div id="LC_helpdesk_section" style="display:none">'.
                        '<input type="text" name="sectiontxt" size="10" /></div>'."\n";                         '<input type="text" name="sectiontxt" size="10" /></div>'."\n";
         } else {          } else { 
             $output .= '<input type="text" name="section" size="10" />'."\n";              $output .= '<input type="text" name="section" size="10" />'."\n";
         }          }
         $output .= &Apache::lonhtmlcommon::row_closure();          $output .= &Apache::lonhtmlcommon::row_closure();
Line 576  ENDJS Line 569  ENDJS
                 my $max = 1048576;                  my $max = 1048576;
                 my $showmax = 1.00;                  my $showmax = 1.00;
                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {                  if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
                     $max *= $helpform{'maxsize'};                      $max *= $helpform{'maxsize'}; 
                     $showmax = $helpform{'maxsize'};                      $showmax = $helpform{'maxsize'};
                 }                  }
                 $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" size="20" /><br />'.                      .' <input type="file" name="screenshot" class="flUpload" size="20" />'
                        "\n".$html_lt{'uplf'}.$showmax."\n".                      .'<input type="hidden" id="free_space" value="'.$max.'" />'
                        &Apache::lonhtmlcommon::row_closure();                      .'<br />'."\n".$html_lt{'uplf'}.$showmax."\n"
                       .&Apache::lonhtmlcommon::row_closure();
                 $num ++;                  $num ++;
                 $i = $num%2;                  $i = $num%2;
             }              }
Line 633  sub print_request_receipt { Line 627  sub print_request_receipt {
     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {      if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
         $public = 1;          $public = 1;
     }      }
     my $lonhost = $r->dir_config('lonHostID');      my $lonhost = $r->dir_config('lonHostID'); 
     unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {      unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
         my ($captcha_chk,$captcha_error) =           my ($captcha_chk,$captcha_error) = 
             &Apache::loncommon::captcha_response('login',$lonhost);              &Apache::loncommon::captcha_response('login',$lonhost);
Line 663  sub print_request_receipt { Line 657  sub print_request_receipt {
     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');      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 @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'};
Line 719  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 848  sub print_request_receipt { Line 833  sub print_request_receipt {
     }      }
     if ($formvars{'course'}) {      if ($formvars{'course'}) {
         $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";          $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
     }      } 
     $supportmsg .= "$lt{'subject'}: $env{'form.subject'}      $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
 $lt{'description'}: $env{'form.description'}  $lt{'description'}: $env{'form.description'}
 $lt{'sourceurl'}: $env{'form.sourceurl'}  $lt{'sourceurl'}: $env{'form.sourceurl'}
Line 977  END Line 962  END
   
     my $attachmentpath = '';      my $attachmentpath = '';
     my $showsize = '';      my $showsize = '';
       
     if ((defined($env{'user.name'})) && (!$public)) {      if ((defined($env{'user.name'})) && (!$public)) {
         if ($homeserver && $env{'form.screenshot.filename'}) {          if ($homeserver && $env{'form.screenshot.filename'}) {
             unless ($helpform{'screenshot'} eq 'no') {              unless ($helpform{'screenshot'} eq 'no') {
Line 988  END Line 973  END
                     $max *= $helpform{'maxsize'};                      $max *= $helpform{'maxsize'};
                     $showmax = $helpform{'maxsize'};                      $showmax = $helpform{'maxsize'};
                 }                  }
                 $showmax = '('.sprintf("%.2f",$showmax).' MB)';                  $showmax = '('.sprintf("%.2f",$showmax).' MB)'; 
                 $showsize = $attachmentsize/1048576;                  $showsize = $attachmentsize/1048576;
                 $showsize = '('.sprintf("%.2f",$showsize).' MB)';                  $showsize = '('.sprintf("%.2f",$showsize).' MB)';
                 if ($attachmentsize > $max) {                  if ($attachmentsize > $max) {
Line 1006  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 1027  END Line 1010  END
             $supportmsg .= "$var: $env{$var}\n";              $supportmsg .= "$var: $env{$var}\n";
         }          }
     }      }
    
     my $cc_string;      my $cc_string;
     if ($homeserver) {      if ($homeserver) {
         if (@ok_ccs > 0) {          if (@ok_ccs > 0) {
Line 1035  END Line 1018  END
         }          }
     }      }
   
     my $attachment_text = '';      my $attachment_text;
     unless ($homeserver && $attachmentpath) {      unless ($homeserver && $attachmentpath) {
           my $envdata = '';
         foreach my $var (@cookievars) {          foreach my $var (@cookievars) {
             $attachment_text .= "$var: $cookies{$var}\n";              $envdata .= "$var: $cookies{$var}\n";
         }          }
         foreach my $var (@ENVvars) {          foreach my $var (@ENVvars) {
             $attachment_text .= "$var: $ENV{$var}\n";              $envdata .= "$var: $ENV{$var}\n";
         }          }
         foreach my $var (@envvars) {          foreach my $var (@envvars) {
             $attachment_text .= "$var: $env{$var}\n";              $envdata .= "$var: $env{$var}\n";
         }          }
         foreach my $var (@loncvars) {          foreach my $var (@loncvars) {
             $attachment_text .= "$var: $env{$var}\n";              $envdata .= "$var: $env{$var}\n";
         }          }
           $attachment_text = $envdata;
     }      }
   
     if ($addtext) {      if ($addtext) {
Line 1061  END Line 1046  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);

Removed from v.1.79.2.5  
changed lines
  Added in v.1.88


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