Diff for /loncom/interface/lonsupportreq.pm between versions 1.4 and 1.5

version 1.4, 2004/07/09 21:08:24 version 1.5, 2004/07/13 17:35:58
Line 2  package Apache::lonsupportreq; Line 2  package Apache::lonsupportreq;
   
 use strict;  use strict;
 use lib qw(/home/httpd/lib/perl);  use lib qw(/home/httpd/lib/perl);
   use MIME::Types;
   use MIME::Lite;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonnet();  use Apache::lonnet();
 use localenroll;  
 use Apache::lonlocal;  use Apache::lonlocal;
   
 use Mail::Send;  
 # use MIME::Lite;  
 # use MIME::Types;  
   
 sub handler {  sub handler {
     my ($r) = @_;      my ($r) = @_;
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
Line 38  sub print_request_form { Line 35  sub print_request_form {
     my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);      my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);      my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);
     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');      my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
       if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {
           $tablecolor = '#CCCCFF';
       }
     $os = $ENV{'browser.os'};      $os = $ENV{'browser.os'};
     $browser = $ENV{'browser.type'};      $browser = $ENV{'browser.type'};
     $bversion = $ENV{'browser.version'};      $bversion = $ENV{'browser.version'};
Line 49  sub print_request_form { Line 49  sub print_request_form {
     $usec = $ENV{'request.course.sec'};      $usec = $ENV{'request.course.sec'};
     $cid = $ENV{'request.course.id'};      $cid = $ENV{'request.course.id'};
     $server = $ENV{'SERVER_NAME'};      $server = $ENV{'SERVER_NAME'};
     my $scripttag;      my $scripttag = (<<END);
   <script>
   function validate() {
       if (document.logproblem.email.value.indexOf("\@") == -1) {
           alert("You must enter a valid e-mail address");
           return
       }
       document.logproblem.submit();
   }
   </script>
   END
     if ($cid =~ m/_/) {      if ($cid =~ m/_/) {
         ($cdom,$cnum) = split/_/,$cid;          ($cdom,$cnum) = split/_/,$cid;
     }      }
Line 77  sub print_request_form { Line 87  sub print_request_form {
         my ($sec,$grp) = split/:/,$_;          my ($sec,$grp) = split/:/,$_;
         $groupid{$sec} = $grp;          $groupid{$sec} = $grp;
     }      }
     $r->print(<<END);  
 <html>  
  <head>  
   <title>LON-CAPA support request</title>  
 END  
     my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};      my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};
     my $codedom = $defdom;      my $codedom = $defdom;
     my %coursecodes = ();      my %coursecodes = ();
Line 128  $bodytag Line 133  $bodytag
         <tr>          <tr>
          <td>           <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
            <form method="post" name="logproblem" onSubmit="return validate()">             <form method="post" name="logproblem" enctype="multipart/form-data">
            <tr>             <tr>
             <td width="140" bgcolor="$tablecolor">              <td width="140" bgcolor="$tablecolor">
              <table width="140" border="0" cellpadding="8" cellspacing="0">               <table width="140" border="0" cellpadding="8" cellspacing="0">
Line 249  END Line 254  END
              <table width="100%" border="0" cellpadding="8" cellspacing="0">               <table width="100%" border="0" cellpadding="8" cellspacing="0">
               <tr>                <tr>
                <td>                 <td>
                 $server$origurl<input type="hidden" name="origurl" value="$server$origurl" />                  http://$server$origurl<input type="hidden" name="origurl" value="http://$server$origurl" />
                </td>                 </td>
               </tr>                </tr>
              </table>               </table>
Line 300  END Line 305  END
 END  END
     if ($coursecodes{$cnum}) {      if ($coursecodes{$cnum}) {
         foreach (@codetitles) {          foreach (@codetitles) {
             $r->print('<i>'.$_.'</i>:&nbsp;'.$codes{$cnum}{$_});              $r->print('<i>'.$_.'</i>:&nbsp;'.$codes{$cnum}{$_}.';&nbsp;');
         }          }
         $r->print('.&nbsp;<input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');          $r->print('&nbsp;<input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
     } else {      } else {
         $r->print('Enter institutional course code:&nbsp;          $r->print('Enter institutional course code:&nbsp;
                   <input type="text" name="coursecode" size="15" value="" />');                    <input type="text" name="coursecode" size="15" value="" />');
Line 344  END Line 349  END
             if ($_ eq $groupid{$_} || $groupid{$_} eq '') {              if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
                 $r->print("<option value=\"$_\" />$_");                  $r->print("<option value=\"$_\" />$_");
             } else {              } else {
                 $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_}");                  $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_})");
             }              }
         }          }
         $r->print("</select>");          $r->print("</select>");
Line 410  END Line 415  END
              <img src="/adm/lonMisc/blackdot.gif" /><br />               <img src="/adm/lonMisc/blackdot.gif" /><br />
     </td>      </td>
    </tr>     </tr>
   END
       if (defined($ENV{'user.name'})) {
           $r->print(<<END);
              <tr>
               <td width="140" bgcolor="$tablecolor">
                <table width="140" border="0" cellpadding="8" cellspacing="0">
                 <tr>
                  <td align="right"><b>Optional file upload:</b>
                  </td>
                 </tr>
                </table>
               </td>
               <td width="100%" valign="top">
                <table width="100%" border="0" cellpadding="8" cellspacing="0">
                 <tr>
                  <td>
                   <input type="file" name="screenshot" size="20" /><br />Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size).
                  </td>
                 </tr>
                </table>
               </td>
              </tr>
              <tr>
               <td width="100%" colspan="2" bgcolor="#000000">
                <img src="/adm/lonMisc/blackdot.gif" /><br />
               </td>
              </tr>
   END
       }
       $r->print(<<END);
            <tr>             <tr>
             <td width="140" bgcolor="$tablecolor">              <td width="140" bgcolor="$tablecolor">
              <table width="140" border="0" cellpadding="8" cellspacing="0">               <table width="140" border="0" cellpadding="8" cellspacing="0">
Line 424  END Line 459  END
               <tr>                <tr>
                <td>                 <td>
                 <input type="hidden" name="action" value="process" />                  <input type="hidden" name="action" value="process" />
                 <input type="submit" value="Submit Request Form" /> &nbsp;                  <input type="button" value="Submit Request Form" onClick="validate()"/> &nbsp;
                </td>                 </td>
                <td>&nbsp;</td>                 <td>&nbsp;</td>
                <td>                 <td>
Line 445  END Line 480  END
   </tr>    </tr>
  </table>   </table>
 END  END
       return;
   
 # What do we know about this user?  
 #    foreach (sort keys %ENV) {  
 #        if ($_ =~ m/^browser/) {  
 #            $r->print("key is $_, value is $ENV{$_}");  
 #        } elsif ($_ =~ m/^environment/) {  
 #            $r->print("key is $_, value is $ENV{$_}");  
 #        } elsif ($_ =~ m/^request/) {  
 #            $r->print("key is $_, value is $ENV{$_}");  
 #        } elsif ($_ =~ m/^user\.(domain|home|name)/) {  
 #            $r->print("key is $_, value is $ENV{$_}");  
 #        } elsif ($_ =~ /^[A-Z]/) {  
 #            $r->print("key is $_, value is $ENV{$_}");  
 #        }  
 #    }  
     return  
 }  }
   
 sub print_request_receipt {  sub print_request_receipt {
     my ($r,$url,$function) = @_;      my ($r,$url,$function) = @_;
     my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role');      my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role');
       my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
   
     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);      my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
       my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
     my $to =  $Apache::lonnet::perlvar{'lonSupportEMail'};      my $to =  $Apache::lonnet::perlvar{'lonSupportEMail'};
       my $from = $admin;
     my $reporttime = &Apache::lonlocal::locallocaltime(time);      my $reporttime = &Apache::lonlocal::locallocaltime(time);
     my $fontcolor = &Apache::loncommon::designparm($function.'.font');      my $fontcolor = &Apache::loncommon::designparm($function.'.font');
     my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');      my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');      my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
     my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description');      my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description','screenshot');
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
   
 #    if ($ENV{'request.course.fn'}) {  
 #        my $formdatafile = $ENV{'request.course.fn'}.'.formdata';  
 #        if (-e $formdatafile) {  
 #            open(FILE,"<$formdatafile");  
 #            my @buffer =<FILE>;  
 #            close(FILE);  
 #            foreach (@buffer) {  
 #                print STDERR $_;  
 #            }   
 #        }  
 #    }  
   
     my $supportmsg = qq|      my $supportmsg = qq|
 Name: $ENV{'form.username'}  Name: $ENV{'form.username'}
 Email: $ENV{'form.email'}  Email: $ENV{'form.email'}
Line 500  URL: $ENV{'form.origurl'} Line 511  URL: $ENV{'form.origurl'}
 Date/Time: $reporttime  Date/Time: $reporttime
   
     |;      |;
       my $descrip = $ENV{'form.description'};
       $descrip =~ s#\n#<br />#g;
       my $displaymsg = qq|
   <font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $ENV{'form.username'}</font><br />
   <font color="$fontcolor">Email: </font><font color="$vlinkcolor">$ENV{'form.email'}</font><br />
   <font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$ENV{'form.uname'} - $ENV{'form.udom'}</font><br />
   <font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$ENV{'form.phone'}</font><br />
   <font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}</font><br />
   <font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$ENV{'form.subject'}</font><br />
   <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
   <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$ENV{'form.origurl'}</font><br />
   <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
       |;
   
     if ($to =~ m/^[^\@]+\@[^\@]+$/) {      if ($to =~ m/^[^\@]+\@[^\@]+$/) {
         $r->print(<<END);          $r->print(<<END);
 <html>  <html>
Line 518  END Line 543  END
 </head>  </head>
 $bodytag  $bodytag
  <h3>Warning: Problem with support e-mail address</h3>   <h3>Warning: Problem with support e-mail address</h3>
 As the e-mail address provided for this LON-CAPA server ($to) does not appear to be a valid e-mail address, your support request has not been sent to the LON-CAPA support staff at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University.   As the e-mail address provided for this LON-CAPA server ($to) does not appear to be a valid e-mail address, your support request has <b>not</b> been sent to the LON-CAPA support staff at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University. 
 END  END
     }      }
     my $msg = new Mail::Send;      if (defined($ENV{'form.email'})) {
     $msg->to($to);          if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
 #    if (defined($ENV{'form.email'})) {              $from = $ENV{'form.email'};
 #        if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {          }
 #            $msg->from($ENV{'form.email'});      }
 #        }  
 #    }      my $subject = $ENV{'form.subject'};
     $msg->subject('[LON-CAPA] - support request');      $subject =~ s#(`)#'#g;
     # ->open can cause an sh launch which can pass all of %ENV allong      $subject =~ s#\$#\(\$\)#g;
       $supportmsg =~ s#(`)#'#g;
       $supportmsg =~ s#\$#\(\$\)#g;
       $displaymsg =~ s#(`)#'#g;
       $displaymsg =~ s#\$#\(\$\)#g;
       my $fname;
   
       my $attachmentpath = '';
       my $attachmentsize = '';
       if (defined($ENV{'user.name'})) {
           if ($ENV{'form.screenshot.filename'}) {
               $attachmentsize = length($ENV{'form.screenshot'});
               if ($attachmentsize > 131072) {
                   $displaymsg .= "<br />The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.";
               } else {
                   $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
               }
           }
       }
   
       if ($attachmentpath =~ m-/([^/]+)$-) {
           $fname = $1;
           $displaymsg .= "<br />An uploaded screenshot file - $fname ($attachmentsize bytes) was included in the request sent by $ENV{'user.name'} from LON-CAPA domain: $ENV{'user.domain'}";
           $supportmsg .= "\n";
           foreach (@envvars) {
               $supportmsg .= "$_: $ENV{$_}\n";
           }
       }
    
       my $msg = MIME::Lite->new(
                    From    => $from,
                    To      => $to,
                    Subject => $subject,
                    Type    =>'TEXT',
                    Data    => $supportmsg,
                    );
   
       if ($attachmentpath) {
           my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
           $msg->attach(Type     => $type,
                        Path     => $attachmentpath,
                        Filename => $fname
                        );
   
       } else {
           my $envdata = '';
           foreach (@envvars) {
               $envdata .= "$_: $ENV{$_}\n";
           }
           foreach (@loncvars) {
               $envdata .= "$_: $ENV{$_}\n";
           }
           $msg->attach(Type => 'TEXT',
                        Data => $envdata);
       }
   
   ### Send it:
       # ->send can cause an sh launch which can pass all of %ENV along
     # which can be to large for /bin/sh's little mind      # which can be to large for /bin/sh's little mind
     my %oldENV=%ENV;      my %oldENV=%ENV;
     undef(%ENV);      undef(%ENV);
     if (my $fh = $msg->open()) {      $msg->send('sendmail');
  print $fh $supportmsg;  
         $fh->close;  
     }  
     %ENV=%oldENV;      %ENV=%oldENV;
     undef(%oldENV);      undef(%oldENV);
     $r->print(<<END);  
       if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {
           unlink($attachmentpath);
       }
       $r->print(qq|
  <b>Your support request contained the following information</b>:<br /><br />   <b>Your support request contained the following information</b>:<br /><br />
  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">   <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
   <tr>    <tr>
Line 563  END Line 646  END
             <td width="100%" valign="top">              <td width="100%" valign="top">
              <table width="100%" border="0" cellpadding="8" cellspacing="0">               <table width="100%" border="0" cellpadding="8" cellspacing="0">
               <tr>                <tr>
                <td>                 <td>$displaymsg</td>
 END  
     my @textmsg = split/\n/,$supportmsg;  
     foreach my $line (@textmsg) {  
         $line =~ s|^|<font color="$fontcolor">|;  
         $line =~ s|:|:</font><font color="$vlinkcolor">|;  
         $r->print("$line</font><br />");  
     }  
     $r->print('</td>  
               </tr>                </tr>
              </table>               </table>
             </td>              </td>
            </tr>             </tr>
            <tr>             <tr>
             <td width="130" bgcolor="'.$tablecolor.'">              <td width="100%" colspan="2" bgcolor="#000000">
              <table width="130" border="0" cellpadding="8" cellspacing="0">               <img src="/adm/lonMisc/blackdot.gif" /><br />
               </td>
              </tr>
              <tr>
               <td width="140" bgcolor="$tablecolor">
                <table width="140" border="0" cellpadding="8" cellspacing="0">
               <tr>                <tr>
                <td align="right"><b>Additional information recorded</b>                 <td align="right"><b>Additional information recorded</b>
                </td>                 </td>
Line 589  END Line 669  END
              <table width="100%" border="0" cellpadding="8" cellspacing="0">               <table width="100%" border="0" cellpadding="8" cellspacing="0">
               <tr>                <tr>
                <td>                 <td>
     ');      |);
     foreach (@envvars) {      foreach (@envvars) {
         $r->print("$_:&nbsp;<font color='$vlinkcolor>$ENV{$_}</font>, ");          unless($ENV{$_} eq '') { 
         $supportmsg .= "$_: $ENV{$_}\n";              $r->print("$_:&nbsp;<font color='$vlinkcolor'>$ENV{$_}</font>, ");
           }
     }      }
     $r->print("      $r->print("
                </td>                 </td>

Removed from v.1.4  
changed lines
  Added in v.1.5


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