Diff for /loncom/interface/lonsupportreq.pm between versions 1.1 and 1.67.2.1

version 1.1, 2004/07/03 18:49:42 version 1.67.2.1, 2013/01/04 19:07:17
Line 1 Line 1
   #
   # $Id$
   #
   # Copyright Michigan State University Board of Trustees
   #
   # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   #
   # LON-CAPA is free software; you can redistribute it and/or modify
   # it under the terms of the GNU General Public License as published by
   # the Free Software Foundation; either version 2 of the License, or
   # (at your option) any later version.
   #
   # LON-CAPA is distributed in the hope that it will be useful,
   # but WITHOUT ANY WARRANTY; without even the implied warranty of
   # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   # GNU General Public License for more details.
   #
   # You should have received a copy of the GNU General Public License
   # along with LON-CAPA; if not, write to the Free Software
   # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   #
   # /home/httpd/html/adm/gpl.txt
   #
   # http://www.lon-capa.org/
   #
   
 package Apache::lonsupportreq;  package Apache::lonsupportreq;
   
 use strict;  use strict;
 use lib qw(/home/httpd/lib/perl);  use MIME::Types;
   use MIME::Lite;
   use CGI::Cookie();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::loncommon;  use Apache::loncommon();
   use Apache::lonhtmlcommon;
 use Apache::lonnet;  use Apache::lonnet;
 use localenroll;  
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonacc();
 use Mail::Send;  use Apache::courseclassifier;
 # use MIME::Lite;  use LONCAPA qw(:DEFAULT :match);
 # use MIME::Types;  use HTML::Entities;
   
 sub handler {  sub handler {
     my $r = shift;      my ($r) = @_;
     $r->content_type('text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
   
     if ($r->header_only) {      if ($r->header_only) {
         return OK;          return OK;
     }      }
       if ($r->uri eq '/adm/helpdesk') {
    &Apache::lonlocal::get_language_handle($r);
       }
   
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
       if ($r->uri eq '/adm/helpdesk') {
           &Apache::lonacc::get_posted_cgi($r);
       }
       my $function;
       if ($env{'form.function'}) {
           if (($env{'form.function'} eq 'norole')  ||
               ($env{'form.function'} eq 'student') ||
               ($env{'form.function'} eq 'admin')   ||
               ($env{'form.function'} eq 'author')) {
               $function = $env{'form.function'};
           }
       }
       my $origurl = $env{'form.origurl'};
       $origurl =~ s{^https?://}{};
       $origurl =~ s/(`)//g;
       $origurl =~ s/\$/\(\$\)/g;
       my $command = $env{'form.command'};
   
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','origurl','function']);      if ($command eq 'process') {
     my $action = $ENV{'form.action'};  
     my $function = $ENV{'form.function'};  
     my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'});  
     if ($action eq 'process') {  
         &print_request_receipt($r,$origurl,$function);          &print_request_receipt($r,$origurl,$function);
     } else {      } else {
         &print_request_form($r,$origurl,$function);          &print_request_form($r,$origurl,$function);
Line 35  sub handler { Line 81  sub handler {
           
 sub print_request_form {  sub print_request_form {
     my ($r,$origurl,$function) = @_;      my ($r,$origurl,$function) = @_;
     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,
     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);          $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');          $formname,$public,$homeserver);
     $os = $ENV{'browser.os'};      $function = &Apache::loncommon::get_users_function() if (!$function);
     $browser = $ENV{'browser.type'};      $ccode = '';
     $bversion = $ENV{'browser.version'};      $os = $env{'browser.os'};
     $uhost = $ENV{'request.host'};      $browser = $env{'browser.type'};
     $uname = $ENV{'user.name'};      $bversion = $env{'browser.version'};
     $udom = $ENV{'user.domain'};      $uhost = $env{'request.host'};
     $uhome = $ENV{'user.home'};      if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
     $urole = $ENV{'request.role'};          $public = 1;
     $usec = $ENV{'request.course.sec'};      } else {
     $cid = $ENV{'request.course.id'};          if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
     $server = $ENV{'SERVER_NAME'};              $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
     my $scripttag;                                                        $env{'user.domain'});
     if ($cid =~ m/_/) {              if ($homeserver eq 'no_host') {
         ($cdom,$cnum) = split/_/,$cid;                  undef($homeserver); 
               } else {
                   $uname = $env{'user.name'};
                   $udom = $env{'user.domain'};
               }
           }
       }
       if ($homeserver) {
           $uhome = $env{'user.home'};
           $urole = $env{'request.role'};
           $usec = $env{'request.course.sec'};
           $cid = $env{'request.course.id'};
       }
       $formname = 'logproblem';
       my $machine = &Apache::lonnet::absolute_url();
       my $sourceurl = $machine.$origurl;
       $server = $machine.&cleanup_html($origurl);
       $server =~ s/\?.*$//;
       my %lt = &Apache::lonlocal::texthash (
                     email => 'The e-mail address you entered',
                     notv => 'is not a valid e-mail address',
                     rsub => 'You must include a subject',
                     rdes => 'You must include a description',
                     name => 'Name',
                     subm => 'Submit Request',
                     emad => 'Your e-mail address',
                     emac => 'Cc', 
                     unme => 'username',
                     doma => 'domain',
                     entu => 'Enter the username you use to log-in to LON-CAPA',
                     chdo => 'Choose your LON-CAPA domain',
                     entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
                     urlp => 'URL of page',
                     phon => 'Phone',
                     crsd => 'Course Details',
                     enin => 'Enter institutional course code',
                     pick => 'Pick',
                     enct => 'Enter course title',
                     secn => 'Section Number',
                     sele => 'Select',
                     titl => 'Title',
                     lsec => 'LON-CAPA sec',
                     subj => 'Subject',
                     detd => 'Detailed Description',
                     opfi => 'Optional file upload',
                     uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
                     fini => 'Finish',
                     clfm => 'Clear Form',
       );
       my $scripttag = (<<"END");
   function validate() {
       if (validmail(document.logproblem.email) == false) {
           alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}.");
           return;
       }
       if (document.logproblem.subject.value == '') {
           alert("$lt{'rsub'}.");
           return;
       }
       if (document.logproblem.description.value == '') {
           alert("$lt{'rdes'}.");
           return;
       }
       document.logproblem.submit();
   }
   
   END
       $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
       if ($cid) {
           $cdom = $env{'course.'.$cid.'.domain'};
           $cnum = $env{'course.'.$cid.'.num'};
     }      }
     if ($cdom && $cnum) {      if ($cdom && $cnum) {
         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);          my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
Line 59  sub print_request_form { Line 175  sub print_request_form {
         $ccode = $csettings{'internal.coursecode'};          $ccode = $csettings{'internal.coursecode'};
         $sectionlist = $csettings{'internal.sectionnums'};          $sectionlist = $csettings{'internal.sectionnums'};
     }      }
     if ($ENV{'environment.critnotification'}) {  
         $email = $ENV{'environment.critnotification'};      if ($homeserver) {
     }          if ($env{'environment.permanentemail'}) {
     if (!$email && $ENV{'environment.notification'}) {              $email = $env{'environment.permanentemail'};
         $email = $ENV{'environment.notification'};          } elsif ($env{'environment.critnotification'}) {
     }              $email = $env{'environment.critnotification'};
     if ($ENV{'environment.lastname'}) {          } elsif ($env{'environment.notification'}) {
         $lastname = $ENV{'environment.lastname'};              $email = $env{'environment.notification'};
           }
           if ($env{'environment.lastname'}) {
               $lastname = $env{'environment.lastname'};
           }
           if ($env{'environment.firstname'}) {
               $firstname = $env{'environment.firstname'};
           }
     }      }
     if ($ENV{'environment.firstname'}) {      my @sections = split(/,/,$sectionlist);
         $firstname = $ENV{'environment.firstname'};      my %groupid;
     }      foreach my $section (@sections) {
     my @sections = split/,/,$sectionlist;          my ($sec,$grp) = split(/:/,$section);
     my %groupid = ();  
     foreach (@sections) {  
         my ($sec,$grp) = split/:/,$_;  
         $groupid{$sec} = $grp;          $groupid{$sec} = $grp;
     }      }
     $r->print(<<END);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
 <html>                                                   'useremail','useraccount']);
  <head>      if ($env{'form.origurl'} eq '/adm/createaccount') {
   <title>LON-CAPA support request</title>          if ($email eq '') {
 END              if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
     my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};                  $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
     my $codedom = $defdom;              }
     my %coursecodes = ();          }
     my %codes = ();          if ($uname eq '') {
     my @codetitles = ();              if ($env{'form.useraccount'} =~ /^$match_username$/) {
     my %cat_titles = ();                  $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
     my %cat_order = ();              }
           }
       }
       my $codedom = &get_domain();
       my $details_title;
       if ($codedom) {
           $details_title = '<br />('.$codedom.')';
       }
       my %coursecodes;
       my %codes;
       my @codetitles;
       my %cat_titles;
       my %cat_order;
       my %idlist;
       my %idnums;
       my %idlist_titles;
     my $caller = 'global';      my $caller = 'global';
     my $totcodes = 0;      my $totcodes = 0;
     my $format_reply;      my $format_reply;
           my $jscript = '';
     if ($cdom) {      my $loaditems = qq|
         $codedom = $cdom;  function initialize_codes() {
     }      return;
   }
       |;
     if ($cnum) {      if ($cnum) {
         $coursecodes{$cnum} = $ccode;          $coursecodes{$cnum} = $ccode;
         if ($ccode eq '') {          if ($ccode eq '') {
             $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);              $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
         } else {          } else {
             $coursecodes{$cnum} = $ccode;              $coursecodes{$cnum} = $ccode;
             $caller = $cnum;              $caller = $cnum;
             $totcodes ++;              $totcodes ++;
         }          }
     } else {       } else { 
         $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);          $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
     }      }
     if ($totcodes > 0) {      if ($totcodes > 0) {
         $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);          if ($ccode eq '') {
               $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);
                   my $longtitles_str = join('","',@{$longtitles});
                   my $allidlist = $idlist{$codetitles[0]};
                   $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
                   $jscript .= $scripttext;
                   $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
                   $loaditems = '';
               }
           }
     }      }
     $r->print(<<END);  
 <html>      my $js = <<"ENDJS";
 <head>  <script type="text/javascript">
  <title>LON-CAPA support request</title>  // <![CDATA[
 $scripttag  $scripttag
 </head>  $jscript
 $bodytag  $loaditems
  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">  // ]]>
   <tr>  </script>
    <td>  ENDJS
     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">      my %add_entries = (
      <tr>                         style    => "margin-top:0px;margin-bottom:0px;",
       <td>                         onload   => "initialize_codes();",
        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">                        );
         <tr>  
          <td>      
   <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">      $r->print(&Apache::loncommon::start_page('Support Request',$js,
            <form method="post" name="logproblem" onSubmit="return validate()">         { 'function'    => $function,
            <tr>   'add_entries' => \%add_entries,
             <td width="140" bgcolor="$tablecolor">   'only_body'   => 1,}));
              <table width="140" border="0" cellpadding="8" cellspacing="0">      if ($r->uri eq '/adm/helpdesk') {
               <tr>          &print_header($r,$origurl);
                <td align="right"><b>Name:</b>      }
                </td>      my @css = ('LC_evenrow_value','LC_oddrow_value');
               </tr>      my $num = 1;
              </table>      my $i = $num%2;
             </td>      my $formtype;
             <td width="100%" valign="top">      if ($homeserver) {
              <table width="100%" border="0" cellpadding="8" cellspacing="0">          $formtype = ' enctype="multipart/form-data"';
               <tr>      }
                <td>      $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
 END      my $output = &Apache::lonhtmlcommon::start_pick_box().
                    &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n";
     my $fullname = '';      my $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"; 
         $r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");          $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
     } else {      } else {
         if (defined($firstname) && $firstname ne '') {          if (defined($firstname) && $firstname ne '') {
             $fullname = $firstname;              $fullname = $firstname;
         } elsif (defined($lastname) && $lastname ne '') {          } elsif (defined($lastname) && $lastname ne '') {
             $fullname= " $lastname";              $fullname = " $lastname";
         }          }
         $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" /><br />');          $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
     }      }
     $r->print(<<END);      $output .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$lt{'subm'}.'" onclick="validate()" />&nbsp;'.
                </td>                  &Apache::lonhtmlcommon::row_closure()."\n";
               </tr>      $num ++;
              </table>      $i = $num%2;
             </td>      $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]).
            </tr>                 '<input type="text" size="20" name="email" value="'.
            <tr>                 &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
             <td width="100%" colspan="2" bgcolor="#000000">                 &Apache::lonhtmlcommon::row_closure();
              <img src="/adm/lonMisc/blackdot.jpg" /><br />      $num ++;
             </td>      $i = $num%2;
            </tr>      if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
            <tr>          if ($homeserver) { 
             <td width="140" bgcolor="$tablecolor">              $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]).
              <table width="140" border="0" cellpadding="8" cellspacing="0">                         '<input type="text" size="50" name="cc" value="" /><br />'."\n".
               <tr>                         &Apache::lonhtmlcommon::row_closure();
                <td align="right"><b>E-mail address:</b>              $num ++;
                </td>              $i = $num%2;
               </tr>          }
              </table>      }
             </td>      $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]);
             <td width="100%" valign="top">      my $udom_input = '<input type="hidden" name="udom" value="'.
              <table width="100%" border="0" cellpadding="8" cellspacing="0">                       &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
               <tr>      my $uname_input = '<input type="hidden" name="uname" value="'.
                <td>                        &HTML::Entities::encode($uname,'"<>&').'" />'."\n"; 
                 <input type="text" size="20" name="email" value="$email" /><br />      if (($env{'user.name'} =~ /^$match_username$/) && 
                </td>          ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
               </tr>          $output .= '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input.$uname_input;
              </table>  
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <img src="/adm/lonMisc/blackdot.jpg" /><br />  
             </td>  
            </tr>  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>username/domain:</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
 END  
     my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';  
     my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />';   
     if (defined($uname) && defined($udom)) {  
         $r->print('<i>username</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>domain</i>:&nbsp;'.$udom.$udom_input.$uname_input);  
     } else {      } else {
         my $udomform = '';          my $udomform = '';
         my $unameform = '';          my $unameform = '';
         if (defined($udom)) {          if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
             $udomform = '<i>domain</i>:&nbsp;'.$udom.$udom_input;              $output .= $lt{'entu'};
         } elsif (defined($uname)) {          } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
             $unameform = '<i>username</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;              $output .= $lt{'chdo'};
           } else {
               $output .= $lt{'entr'};
           }
           $output .= '<br />'."\n";
           if (!$public) {
               if ($env{'user.domain'} =~ /^$match_domain$/) {
                   $udomform = '<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input;
               } elsif ($env{'user.name'} =~ /^$match_username$/) {
                   $unameform = '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
               }
         }          }
         if ($udomform eq '') {          if ($udomform eq '') {
             $udomform = '<i>domain</i>:&nbsp;';              $udomform = '<i>'.$lt{'doma'}.'</i>:&nbsp;';
             $udomform .= &Apache::loncommon::select_dom_form('','udom');              $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
         }          }
         if ($unameform eq '') {          if ($unameform eq '') {
             $unameform= '<i>username</i>:&nbsp;<input type="text" size="20" name="loncname" value="'.$uname.'" />&nbsp;&nbsp;';              $unameform= '<i>'.$lt{'unme'}.'</i>:&nbsp;<input type="text" size="20" name="uname" value="'.$uname.'" />&nbsp;&nbsp;';
         }          }
         $r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');          $output .= $unameform.$udomform;
     }      }
     $r->print(<<END);      $output .= &Apache::lonhtmlcommon::row_closure();
                </td>      $num ++;
               </tr>      $i = $num%2;
              </table>      $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]).
             </td>                 $server."\n".'<input type="hidden" name="sourceurl" value="'.
            </tr>                 &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
            <tr>                 &Apache::lonhtmlcommon::row_closure().
             <td width="100%" colspan="2" bgcolor="#000000">                 &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_evenrow_value').
              <img src="/adm/lonMisc/blackdot.jpg" /><br />                 '<input type="text" size="15" name="phone" /><br />'."\n".
             </td>                 &Apache::lonhtmlcommon::row_closure();
            </tr>      $num ++;
            <tr>      $i = $num%2; 
             <td width="140" bgcolor="$tablecolor">      $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]);
              <table width="140" border="0" cellpadding="8" cellspacing="0">      if ($cnum) {
               <tr>          if ($coursecodes{$cnum}) {
                <td align="right"><b>URL of page:</b>              foreach my $item (@codetitles) {
                </td>                  $output .= '<i>'.$item.'</i>:&nbsp;'.$codes{$cnum}{$item}.';&nbsp;';
               </tr>              }
              </table>              $output .= '&nbsp;<input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />'."\n";
             </td>          } else {
             <td width="100%" valign="top">              $output .= $lt{'enin'}.':&nbsp;
              <table width="100%" border="0" cellpadding="8" cellspacing="0">                    <input type="text" name="coursecode" size="15" value="" />'."\n";
               <tr>  
                <td>  
                 $server$origurl<input type="hidden" name="origurl" value="$server$origurl" />  
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <img src="/adm/lonMisc/blackdot.jpg" /><br />  
             </td>  
            </tr>  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Phone #:</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
                 <input type="text" size="15" name="phone"><br>  
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <img src="/adm/lonMisc/blackdot.jpg" /><br />  
             </td>  
            </tr>  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Course Details:</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table border="0" cellpadding="3" cellspacing="3">  
               <tr>  
                <td>  
 END  
     if ($coursecodes{$cnum}) {  
         foreach (@codetitles) {  
             $r->print('<i>'.$_.'</i>:&nbsp;'.$codes{$cnum}{$_});  
         }          }
         $r->print('.&nbsp;<input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');  
     } else {      } else {
         $r->print('Enter institutional course code:&nbsp;          if ($totcodes > 0) {
                   <input type="text" name="coursecode" size="15" value="" />');              my $numtitles = @codetitles;
               if ($numtitles == 0) {
                   $output .= $lt{'enin'}.':&nbsp;
                     <input type="text" name="coursecode" size="15" value="" />'."\n";
               } else {
                   my @standardnames = &Apache::loncommon::get_standard_codeitems();
                   my $lasttitle = $numtitles;
                   if ($numtitles > 4) {
                       $lasttitle = 4;
                   } 
                   $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
                         '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
                         ' <option value="-1">'.$lt{'sele'}."</option>\n";
                   my @items = ();
                   my @longitems = ();
                   if ($idlist{$codetitles[0]} =~ /","/) {
                       @items = split(/","/,$idlist{$codetitles[0]});
                   } else {
                       $items[0] = $idlist{$codetitles[0]};
                   }
                   if (defined($idlist_titles{$codetitles[0]})) {
                       if ($idlist_titles{$codetitles[0]} =~ /","/) {
                           @longitems = split(/","/,$idlist_titles{$codetitles[0]});
                       } else {
                           $longitems[0] = $idlist_titles{$codetitles[0]};
                       }
                       for (my $i=0; $i<@longitems; $i++) {
                           if ($longitems[$i] eq '') {
                               $longitems[$i] = $items[$i];
                           }
                       }
                   } else {
                       @longitems = @items;
                   }
                   for (my $i=0; $i<@items; $i++) {
                       $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
                   }
                   $output .= '</select></td>';
                   for (my $i=1; $i<$numtitles; $i++) {
                       $output .= '<td>'.$codetitles[$i].'<br />'."\n".
                        '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
                        '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
                        '</select>'."\n".
                        '</td>'."\n";
                   }
                   $output .= '</tr></table>';
                   if ($numtitles > 4) {
                       $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
                             '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
                             '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
                             '</select>'."\n";
                   }
               }
           } else {
               $output .= $lt{'enin'}.':&nbsp;
                     <input type="text" name="coursecode" size="15" value="" />'."\n";
           }
     }      }
     if ($ctitle) {      if ($ctitle) {
         $r->print('<br /><i>Title</i>:&nbsp;'.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');          $output .= '<br /><i>'.$lt{'titl'}.'</i>:&nbsp;'.$ctitle.
                      '<input type="hidden" name="title" value="'.
                      &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
     } else {      } else {
         $r->print('<br />Enter course title:&nbsp;          $output .= '<br />'.$lt{'enct'}.':&nbsp;
                  <input type="text" name="title" size="15" value="" />');                   <input type="text" name="title" size="25" value="" />'."\n";
     }      }
     $r->print(<<END);      $output .= &Apache::lonhtmlcommon::row_closure();
                </td>      $num ++;
               </tr>      $i = $num%2;
              </table>      $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]);
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <img src="/adm/lonMisc/blackdot.jpg" /><br />  
             </td>  
            </tr>  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Section Number: </b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
 END  
     if ($sectionlist) {      if ($sectionlist) {
         $r->print("<select name=\"section\">");          $output .= "<select name=\"section\"\n>".
         foreach (sort keys %groupid) {                     "  <option value=\"\" selected=\"selected\">$lt{'sele'}</option>\n";
             if ($_ eq $groupid{$_} || $groupid{$_} eq '') {          foreach my $id (sort(keys(%groupid))) {
                 $r->print("<option value=\"$_\" />$_");              if ($id eq $groupid{$id} || $groupid{$id} eq '') {
                   $output .= "  <option value=".
                              &HTML::Entities::encode($id,'"<>&').
                              " >$id</option>\n";
             } else {              } else {
                 $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_}");                  $output .= "  <option value=".
                              &HTML::Entities::encode($id,'"<>&').
                              " >$id - ($lt{'lsec'}: $groupid{$id})</option>\n";
             }              }
         }          }
         $r->print("</select>");          $output .= "</select>";
     } else {      } else {
         $r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");          $output .= '<input type="text" name="section" size="10" />'."\n";
     }      }
     $r->print(<<END);      $output .= &Apache::lonhtmlcommon::row_closure();
                </td>      $num ++;
               </tr>      $i = $num%2; 
              </table>      $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value').
             </td>                 '  <input type="text" size="40" name="subject" />'."\n".
            </tr>                 &Apache::lonhtmlcommon::row_closure().
            <tr>                 &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value').
             <td width="100%" colspan="2" bgcolor="#000000">                 '  <textarea rows="10" cols="45" name="description" style="word-wrap:normal;">'.
              <img src="/adm/lonMisc/blackdot.jpg" /><br />                 '</textarea>'."\n".
             </td>                 &Apache::lonhtmlcommon::row_closure();
            </tr>      $num ++;
            <tr>      $i = $num%2; 
             <td width="140" bgcolor="$tablecolor">      if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
              <table width="140" border="0" cellpadding="8" cellspacing="0">          if ($homeserver) {
               <tr>              $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
                <td align="right"><b>Subject</b>                         ' <input type="file" name="screenshot" size="20" /><br />'.
                </td>                         "\n".$lt{'uplf'}."\n".
               </tr>                         &Apache::lonhtmlcommon::row_closure();
              </table>              $num ++;
             </td>              $i = $num%2;
             <td width="100%" valign="top">          }
              <table width="100%" border="0" cellpadding="8" cellspacing="0">      }
               <tr>      $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
                <td>      $output .= <<END;
                 <input type="text" size="40" name="subject">  
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <img src="/adm/lonMisc/blackdot.jpg" /><br />  
             </td>  
            </tr>  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Detailed description:</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
                 <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>  
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
            <tr>  
     <td width="100%" colspan="2" bgcolor="#000000">  
              <img src="/adm/lonMisc/blackdot.jpg" /><br />  
     </td>  
    </tr>  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Finish:</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table border="0" cellpadding="8" cellspacing="0">               <table border="0" cellpadding="8" cellspacing="0">
               <tr>                <tr>
                <td>                 <td>
                 <input type="hidden" name="action" value="process" />                  <input type="hidden" name="command" value="process" />
                 <input type="submit" value="Submit Request Form" /> &nbsp;                  <input type="button" value="$lt{'subm'}" onclick="validate()" /> &nbsp;
                </td>                 </td>
                <td>&nbsp;</td>                 <td>&nbsp;</td>
                <td>                 <td>
                 <input type="reset" value="Clear Form">                  <input type="reset" value="$lt{'clfm'}" />
                </td>                 </td>
               </tr>                </tr>
              </table>               </table>
             </td>  
            </tr>  
           </table>  
          </td>  
         </tr>  
        </table>  
       </td>  
      </tr>  
     </table>  
    </td>  
   </tr>  
  </table>  
 END  END
       $output .= &Apache::lonhtmlcommon::row_closure(1);
       $output .= &Apache::lonhtmlcommon::end_pick_box();
 # What do we know about this user?      $r->print(<<END);
 #    foreach (sort keys %ENV) {  $output
 #        if ($_ =~ m/^browser/) {  </form>
 #            $r->print("key is $_, value is $ENV{$_}");  <br />
 #        } elsif ($_ =~ m/^environment/) {  END
 #            $r->print("key is $_, value is $ENV{$_}");      $r->print(&Apache::loncommon::end_page());
 #        } elsif ($_ =~ m/^request/) {      return;
 #            $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 = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);      my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
     my $to =  $Apache::lonnet::perlvar{'lonSupportEMail'};      my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
       my @cookievars = ('lonID');
   
       my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
       my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
       my $defdom = &get_domain();
       my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                                         $defdom,$origmail);
       my $from = $admin;
       my $bcc;
       my %domconfig =
            &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
       if (ref($domconfig{'contacts'}) eq 'HASH') {
           if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
               if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
                   my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
                   if ($bccmail ne '') {
                       my @bccs = split(/,/,$bccmail);
                       my @ok_bccs;
                       foreach my $bcc (@bccs) {
                           $bcc =~ s/^\s+//g;
                           $bcc =~ s/\s+$//g;
                           if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
                               if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
                                   push(@ok_bccs,$bcc);
                               }
                           }
                       }
                       if (@ok_bccs > 0) {
                           $bcc = join(', ',@ok_bccs);
                       }
                   }
               }
           }
       }
     my $reporttime = &Apache::lonlocal::locallocaltime(time);      my $reporttime = &Apache::lonlocal::locallocaltime(time);
     my $fontcolor = &Apache::loncommon::designparm($function.'.font');      my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
     my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');  
     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');  
     my @formvars = ('username','email','uname','udom','origurl','phone','section','coursecode','title','subject','description');  
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
       my $coursecode = $env{'form.coursecode'};
       if ($coursecode eq '') {
           my $totcodes = 0;
           my %coursecodes;
           $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
           my @standardnames = &Apache::loncommon::get_standard_codeitems();
           if ($totcodes > 0) {
               my $noregexps = 1;
               $coursecode = 
                   &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
           } 
           if ($coursecode eq '') {
               foreach my $item (@standardnames) {
                   if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
                       $coursecode .= $env{'form.'.$item};
                   }
               }
           }
       }
       my %lt = &Apache::lonlocal::texthash (
                    username    => 'Name',
                    email       => 'E-mail',
                    cc          => 'Cc',
                    user        => 'Username/domain',
                    phone       => 'Phone',
                    crsi        => 'Course Information',
                    subject     => 'Subject',
                    description => 'Description',
                    sourceurl   => 'URL',
                    date        => 'Date/Time',
                    secn        => 'Section',
                    warn        => 'Warning: Problem with support e-mail address',
                    your        => 'Your support request contained the following information',
                    sect        => 'section',
                    info        => 'Information supplied',
                    adin        => 'Additional information recorded',
       );
   
       my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$public,$homeserver);
       if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
           $public = 1;
       } else {
           if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
               $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
                                                         $env{'user.domain'});
           }
       }
   
 #    if ($ENV{'request.course.fn'}) {      if (($homeserver) && (defined($env{'form.cc'}))) {
 #        my $formdatafile = $ENV{'request.course.fn'}.'.formdata';          my @ccs;
 #        if (-e $formdatafile) {          if ($env{'form.cc'} =~ /,/) {
 #            open(FILE,"<$formdatafile");              @ccs = split(/,/,$env{'form.cc'});
 #            my @buffer =<FILE>;          } else {
 #            close(FILE);              $env{'form.cc'} =~ s/^\s+//;
 #            foreach (@buffer) {              $env{'form.cc'} =~ s/\s+$//;
 #                print STDERR $_;              @ccs = $env{'form.cc'};
 #            }           }
 #        }          foreach my $cc (@ccs) {
 #    }              $cc =~ s/^\s+//g;
               $cc =~ s/\s+$//g;
     my $supportmsg = qq|              if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
 Name: $ENV{'form.username'}                  if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
 Email: $ENV{'form.email'}                      push(@ok_ccs,$cc);
 Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}                  }
 Tel: $ENV{'form.phone'}              } elsif ($cc ne '') {
 Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}                  if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
 Subject: $ENV{'form.subject'}                      push(@bad_ccs,$cc);
 Description: $ENV{'form.description'}                  }
 URL: $ENV{'form.origurl'}              }
 Date/Time: $reporttime          }
           if (@ok_ccs > 0) {
              $okcclist = join(', ',@ok_ccs); 
           } 
           if (@bad_ccs == 1) {
               if ($bad_ccs[0] ne '') {
                   $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&cleanup_html($bad_ccs[0]);
               }
           } elsif (@bad_ccs > 1) {
               $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &cleanup_html(join(', ',@bad_ccs));
           }
       }
       $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
       $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
       my $supportmsg = <<END;
   $lt{'username'}: $env{'form.username'}
   $lt{'email'}: $env{'form.email'}
   $lt{'cc'}: $okcclist
   $lt{'user'}: $env{'form.user'}
   $lt{'phone'}: $env{'form.phone'}
   $lt{'crsi'}: $env{'form.crsi'}
   $lt{'subject'}: $env{'form.subject'}
   $lt{'description'}: $env{'form.description'}
   $lt{'sourceurl'}: $env{'form.sourceurl'}
   $lt{'date'}: $reporttime
   
     |;  
     if ($to =~ m/^[^\@]+\@[^\@]+$/) {  
         $r->print(<<END);  
 <html>  
 <head>  
  <title>LON-CAPA support request recorded</title>  
 </head>  
 $bodytag  
  <h3>A support request has been sent to $to</h3>  
 END  END
     } else {       my $displaymsg;
         $to = 'helpdesk@lon-capa.org';      foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
         $r->print(<<END);          if ($env{'form.'.$item} ne '') {
 <html>              if ($item eq 'description') {
 <head>                  my $descrip = $env{'form.description'};
  <title>LON-CAPA support request recorded</title>                  $descrip =  &cleanup_html($descrip);
 </head>                  $descrip =~ s|[\n\r\f]|<br />|g;
 $bodytag                  $displaymsg .= 
  <h3>Warning: Problem with support e-mail address</h3>                      '<span class="LC_helpform_receipt_cat">'.
 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.                       "$lt{$item}</span>: $descrip<br />\n";
               } elsif ($item eq 'sourceurl') {
                   my $showurl = $env{'form.sourceurl'};
                   $showurl =~ s/\?.*$//;
                   $showurl =  &cleanup_html($showurl);
                   $displaymsg .= 
                       '<span class="LC_helpform_receipt_cat">'.
                       "$lt{$item}</span>: $showurl<br />\n";
               } elsif ($item eq 'cc') {
                   if ($okcclist) {
                       my $showcclist = &cleanup_html($okcclist);
                       $displaymsg .=
                           '<span class="LC_helpform_receipt_cat">'.
                           "$lt{$item}</span>: $showcclist<br />\n";
                   }
               } else {
                   my $showitem = $env{'form.'.$item};
                   $showitem = &cleanup_html($showitem);
                   $displaymsg .= 
                       '<span class="LC_helpform_receipt_cat">'.
                       "$lt{$item}</span>: $showitem<br />\n";
               }
           }
       }
       $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
                      $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
   
       my $start_page = 
    &Apache::loncommon::start_page('Support request recorded',undef,
          {'function'    => $function,
    'add_entries' => {
       topmargin    => "0",
       marginheight => "0",
    },
    'only_body'   => 1,});
   
       $r->print(<<"END");
   $start_page
   <form name="logproblem">
   <input type="hidden" name="command" value="result" />
   </form>
 END  END
       if ($r->uri eq '/adm/helpdesk') {
           &print_header($r,$url,'process');
     }      }
     my $msg = new Mail::Send;      my $bad_email = 0;
     $msg->to($to);      if ($to =~ /,/) {
 #    if (defined($ENV{'form.email'})) {          my @ok_email; 
 #        if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {          foreach my $email (split(/,/,$to)) {
 #            $msg->from($ENV{'form.email'});              if ($email =~ m/^[^\@]+\@[^\@]+$/) {
 #        }                  if (!grep(/^\Q$email\E$/,@ok_email)) {
 #    }                      push(@ok_email,$email);
     $msg->subject('[LON-CAPA] - support request');                  }
     if (my $fh = $msg->open()) {              }
         print $fh $supportmsg;          }
         $fh->close;          if (@ok_email > 0) {
               $to = join(',',@ok_email);
           } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
               $to = $admin;
           } else {
               $bad_email = 1;
           }
       } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
           if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
               $to = $admin;
           } else {
               $bad_email = 1;
           }
     }      }
     $r->print(<<END);  
  <b>Your support request contained the following information</b>:<br /><br />      my $message;
  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">      if (!$bad_email) {
   <tr>          $message = &Apache::lonhtmlcommon::confirm_success(
    <td>              &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">      } else {
      <tr>          $message = &Apache::lonhtmlcommon::confirm_success(
       <td>              $lt{'warn'}.'<br />'
        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">             .&mt('As the e-mail address provided for this LON-CAPA server ([_1]) does not appear to be a valid e-mail address, your support request has [_2]not[_3] been sent to the LON-CAPA support staff or administrator at your institution.','<tt>'.$to.'</tt>','<b>','</b>')
         <tr>             .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1); 
          <td>          $to = 'helpdesk@lon-capa.org';
           <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">  
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Information supplied</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <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>      $r->print(&Apache::loncommon::confirmwrapper($message));
               </tr>  
              </table>      if (defined($env{'form.email'})) {
             </td>          $env{'form.email'} =~ s/^\s+//;
            </tr>          $env{'form.email'} =~ s/\s+$//;
            <tr>          if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
             <td width="130" bgcolor="'.$tablecolor.'">              $from = $env{'form.email'};
              <table width="130" border="0" cellpadding="8" cellspacing="0">          }
               <tr>  
                <td align="right"><b>Additional information recorded</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
     ');  
     foreach (@envvars) {  
         $r->print("$_:&nbsp;<font color='$vlinkcolor>$ENV{$_}</font>, ");  
         $supportmsg .= "$_: $ENV{$_}\n";  
     }      }
     $r->print("  
                </td>      if (defined($env{'form.cc'})) {
               </tr>          if ($badccmsg) {
              </table>              $displaymsg .= $badccmsg;
             </td>          }
            </tr>      }
           </table>  
          </td>      my $subject = $env{'form.subject'};
         </tr>      $subject =~ s/(`)/'/g;
        </table>      $subject =~ s/\$/\(\$\)/g;
       </td>      $supportmsg =~ s/(`)/'/g;
      </tr>      $supportmsg =~ s/\$/\(\$\)/g;
     </table>      $displaymsg =~ s/(`)/'/g;
    </td>      $displaymsg =~ s/\$/\(\$\)/g;
   </tr>      my $fname;
   
       my $attachmentpath = '';
       my $attachmentsize = '';
       if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public')
           && ($env{'user.domain'} ne 'public')) {
           if ($homeserver && $env{'form.screenshot.filename'}) {
               $attachmentsize = length($env{'form.screenshot'});
               if ($attachmentsize > 131072) {
                   $displaymsg .= '<br />'.&mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize);
               } else {
                   $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
               }
           }
       }
   
       my %cookies;
       my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
       if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
           $cookies{'lonID'} = $1;
       }
   
       if ($attachmentpath =~ m-/([^/]+)$-) {
           $fname = $1;
           $displaymsg .= '<br />'
                         .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
                             ,'<span class="LC_filename">'.$fname.'</span>'
                             ,$attachmentsize
                             ,$env{'user.name'}.':'.$env{'user.domain'}
                          );
           $supportmsg .= "\n";
           foreach my $var (@cookievars) {
               $supportmsg .= "$var: $cookies{$var}\n";
           }
           foreach my $var(@ENVvars) {
               $supportmsg .= "$var: $ENV{$var}\n";
           }
           foreach my $var (@envvars) {
               $supportmsg .= "$var: $env{$var}\n";
           }
       }
    
       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
                        );
   
       } else {
           my $envdata = '';
           foreach my $var (@cookievars) {
               $envdata .= "$var: $cookies{$var}\n";
           }
           foreach my $var (@ENVvars) {
               $envdata .= "$var: $ENV{$var}\n";
           }
           foreach my $var (@envvars) {
               $envdata .= "$var: $env{$var}\n";
           }
           foreach my $var (@loncvars) {
               $envdata .= "$var: $env{$var}\n";
           }
           $msg->attach(Type => 'TEXT',
                        Data => $envdata);
       }
   
   ### Send it:
       $msg->send('sendmail');
   
       if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
           unlink($attachmentpath);
       }
       $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
       $r->print('<div style="width:620px;">'.
                 &Apache::lonhtmlcommon::start_pick_box().
                 &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
                 &Apache::lonhtmlcommon::row_closure().
                 &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
       my $envmsg;
       foreach my $var (@cookievars) {
           if ($cookies{$var} ne '') {
               $envmsg.= '<span class="LC_helpform_receipt_cat">'.
                         $var.'</span>:&nbsp;'.$cookies{$var}.', ';
           }
       }
       foreach my $var (@ENVvars) {
           if ($ENV{$var} ne '') {
               $envmsg .= '<span class="LC_helpform_receipt_cat">'.
                          $var.'</span>:&nbsp;'.$ENV{$var}.', ';
           }
       }
       foreach my $var (@envvars) {
           if ($env{$var} ne '') { 
               $envmsg .= '<span class="LC_helpform_receipt_cat">'.
                          $var.'</span>:&nbsp;'.$env{$var}.', ';
           }
       }
       $envmsg =~ s/, $//;
       $r->print($envmsg."\n".
                 &Apache::lonhtmlcommon::row_closure(1)."\n".
                 &Apache::lonhtmlcommon::end_pick_box().
                 "</div>\n".
                 &Apache::loncommon::end_page());
   }
   
   sub print_header {
       my ($r,$origurl,$command) = @_;
       my $location=&Apache::loncommon::lonhttpdurl("/adm");
       my ($component_url);
       my $helpdesk_link = '<a href="javascript:validate()">';
       if ($command eq 'process') {
           $helpdesk_link = '<a href="/adm/helpdesk">';
       }
       my %lt = &Apache::lonlocal::texthash (
                                              login    => 'Log-in help',
                                              ask      => 'Ask helpdesk',
                                              getst    => 'Getting started guide',
                                              back     =>  'Back to last location',
                                              headline => 'help/support',
                                              stud     => 'Students',
                                              ifyo     => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
                                              cont     => 'Contact your instructor instead.',
                                            );
       my ($getstartlink,$reviewtext);
       if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
           $getstartlink = qq|<td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
           $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
       } else {
           $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
       }
       my $linkback;
       if ($origurl eq '') {
           $linkback = 'javascript:history.go(-1)';
       } else {
           $linkback = &HTML::Entities::encode($origurl,'"<>&');
       }
       $r->print(<<"END");
   <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
    <tr>
      <td width="5" height="50">&nbsp;</td>
      <td height="50">
       <fieldset>
         <legend>
           <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
           LON-CAPA $lt{'headline'}
         </legend>
    <table id="LC_helpmenu_links">
      <tr>
       <td align="center"><span class="LC_nobreak"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" style="vertical-align:middle" />&nbsp;<b><a href="/adm/loginproblems.html">$lt{'login'}</a></b>&nbsp;</span></td>
       <td align="center"><span class="LC_nobreak">&nbsp;<b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" style="vertical-align:middle" />&nbsp;$lt{'ask'}</a></b>&nbsp;</span></td>$getstartlink
       <td align="center"><span class="LC_nobreak">&nbsp;<b><a href="$linkback" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" style="vertical-align:middle" />&nbsp;$lt{'back'}</a></b>&nbsp;</span></td>
      </tr>
  </table>   </table>
     ");  </fieldset>
     </td>
     <td width="5">&nbsp;</td>
    </tr>
    <tr>
     <td colspan="3" height="5">&nbsp;</td>
    </tr>
   END
       if  ($command ne 'process') {
           my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
                             '<b>','</b>');
           $r->print(<<"END");
    <tr>
     <td colspan="3">$reviewtext 
     $lt{'ifyo'}<br />
   <span style="font-size:90%;"><b>$lt{'stud'}</b>: 
   $stuwarn $lt{'cont'}</span>
   <br /><br />
     </td>
    </tr>
   END
       }
       $r->print('
   </table>');
       return;
 }  }
   
 sub retrieve_instcodes {  sub get_domain {
     my ($coursecodes,$codedom,$totcodes) = @_;      my $codedom;
     my %courses = &Apache::lonnet::courseiddump($codedom,'.',1);      if (exists($env{'form.codedom'})) {
     foreach my $course (keys %courses) {          if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
         if ($courses{$course} =~ m/^[^:]*:([^:]+)$/) {              return $env{'form.codedom'};
             $$coursecodes{$course} = &Apache::lonnet::unescape($1);  
             $totcodes ++;  
         }          }
     }      }
     return $totcodes;      if ($env{'request.course.id'}) {
           $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       } elsif ($env{'request.role.domain'}) {
           $codedom = $env{'request.role.domain'};
       } else {
           $codedom = &Apache::lonnet::default_login_domain();
       }
       return $codedom;
   }
   
   sub cleanup_html {
       my ($incoming) = @_;
       my $outgoing;
       if ($incoming ne '') {
           $outgoing = $incoming;
           $outgoing =~ s/;/&#059;/g;
           $outgoing =~ s/\#/&#035;/g;
           $outgoing =~ s/\&/&#038;/g;
           $outgoing =~ s/</&#060;/g;
           $outgoing =~ s/>/&#062;/g;
           $outgoing =~ s/\(/&#040/g;
           $outgoing =~ s/\)/&#041;/g;
           $outgoing =~ s/"/&#034;/g;
           $outgoing =~ s/'/&#039;/g;
           $outgoing =~ s/\$/&#036;/g;
           $outgoing =~ s{/}{&#047;}g;
           $outgoing =~ s/=/&#061;/g;
           $outgoing =~ s/\\/&#092;/g
       }
       return $outgoing;
 }  }
   
 1;  1;

Removed from v.1.1  
changed lines
  Added in v.1.67.2.1


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