Diff for /loncom/interface/lonsupportreq.pm between versions 1.79.2.3 and 1.86

version 1.79.2.3, 2017/01/23 19:57:30 version 1.86, 2017/01/18 21:24:40
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 81  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 107  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 248  END Line 246  END
                   subj => 'Subject',                    subj => 'Subject',
                   detd => 'Detailed Description',                    detd => 'Detailed Description',
                   opfi => 'Optional file upload',                    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',                    fini => 'Finish',
                   clfm => 'Clear Form',                    clfm => 'Clear Form',
     );      );
Line 315  $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 351  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 379  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 542  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 568  ENDJS Line 567  ENDJS
         if ($homeserver) {          if ($homeserver) {
             unless ($helpform{'screenshot'} eq 'no') {              unless ($helpform{'screenshot'} eq 'no') {
                 my $max = 1048576;                  my $max = 1048576;
                 my $showmax = 1.00;  
                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {                  if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
                     $max *= $helpform{'maxsize'};                      $max *= $helpform{'maxsize'}; 
                     $showmax = $helpform{'maxsize'};  
                 }                  }
                 $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="flUpload" size="20" />'
                        ' <input type="file" name="screenshot" size="20" /><br />'.                      .'<input type="hidden" id="free_space" value="'.$max.'" />'
                        "\n".$html_lt{'uplf'}.$showmax."\n".                      .'<br />'."\n".$html_lt{'uplf'}."\n"
                        &Apache::lonhtmlcommon::row_closure();                      .&Apache::lonhtmlcommon::row_closure();
                 $num ++;                  $num ++;
                 $i = $num%2;                  $i = $num%2;
             }              }
Line 627  sub print_request_receipt { Line 624  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 833  sub print_request_receipt { Line 830  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 961  END Line 958  END
     my $fname;      my $fname;
   
     my $attachmentpath = '';      my $attachmentpath = '';
     my $showsize = '';      my $attachmentsize = '';
   
     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') {
                 my $attachmentsize = length($env{'form.screenshot'});                  $attachmentsize = length($env{'form.screenshot'});
                 my $max = 1048576;                  my $max = 1048576;
                 my $showmax = 1.00;  
                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {                  if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
                     $max *= $helpform{'maxsize'};                      $max *= $helpform{'maxsize'};
                     $showmax = $helpform{'maxsize'};  
                 }                  }
                 $showmax = '('.sprintf("%.2f",$showmax).' MB)';  
                 $showsize = $attachmentsize/1048576;  
                 $showsize = '('.sprintf("%.2f",$showsize).' MB)';  
                 if ($attachmentsize > $max) {                  if ($attachmentsize > $max) {
                     $displaymsg .= '<br /><span class="LC_warning">'.                      $displaymsg .= '<br /><span class="LC_warning">'.
                                    &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).'</span>';                                     &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 1 MB, and has therefore been discarded.',$attachmentsize).'</span>';
                 } else {                  } else {
                     $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');                      $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
                 }                  }
Line 995  END Line 986  END
     if ($attachmentpath =~ m-/([^/]+)$-) {      if ($attachmentpath =~ m-/([^/]+)$-) {
         $fname = $1;          $fname = $1;
         $displaymsg .= '<br />'          $displaymsg .= '<br />'
                       .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'                        .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
                           ,'<span class="LC_filename">'.$fname.'</span>&nbsp;'.$showsize,                            ,'<span class="LC_filename">'.$fname.'</span>'
                             ,$attachmentsize
                           ,$env{'user.name'}.':'.$env{'user.domain'}                            ,$env{'user.name'}.':'.$env{'user.domain'}
                        );                         );
         $supportmsg .= "\n";          $supportmsg .= "\n";
Line 1010  END Line 1002  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 1018  END Line 1010  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 1044  END Line 1038  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.3  
changed lines
  Added in v.1.86


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