Diff for /loncom/interface/lonsupportreq.pm between versions 1.9 and 1.61

version 1.9, 2004/09/13 13:31:52 version 1.61, 2010/12/02 23:05:42
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::Types;
 use MIME::Lite;  use MIME::Lite;
   use CGI::Cookie();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonnet();  use Apache::lonhtmlcommon;
   use Apache::lonnet;
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonacc();
   use Apache::courseclassifier;
   use LONCAPA qw(:DEFAULT :match);
    
   
 sub handler {  sub handler {
     my ($r) = @_;      my ($r) = @_;
Line 17  sub handler { Line 48  sub handler {
     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 = $env{'form.function'};
       my $origurl = $env{'form.origurl'};
       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 32  sub handler { Line 70  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);
     if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {      $function = &Apache::loncommon::get_users_function() if (!$function);
         $tablecolor = '#CCCCFF';      $ccode = '';
     }      $os = $env{'browser.os'};
     $os = $ENV{'browser.os'};      $browser = $env{'browser.type'};
     $browser = $ENV{'browser.type'};      $bversion = $env{'browser.version'};
     $bversion = $ENV{'browser.version'};      $uhost = $env{'request.host'};
     $uhost = $ENV{'request.host'};      if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
     $uname = $ENV{'user.name'};          $public = 1;
     $udom = $ENV{'user.domain'};      } else {
     $uhome = $ENV{'user.home'};          $uname = $env{'user.name'};
     $urole = $ENV{'request.role'};          $udom = $env{'user.domain'};
     $usec = $ENV{'request.course.sec'};      }
     $cid = $ENV{'request.course.id'};      $uhome = $env{'user.home'};
     $server = $ENV{'SERVER_NAME'};      $urole = $env{'request.role'};
     my $scripttag = (<<END);      $usec = $env{'request.course.sec'};
       $cid = $env{'request.course.id'};
       $formname = 'logproblem';
       my $machine = &Apache::lonnet::absolute_url();
       if ($origurl =~ m-^https?://-) {
           $server = $origurl;
       } else {
           $server = $machine.$origurl;
       }
       my $showserver = $server;
       $showserver =~ 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() {  function validate() {
     if (document.logproblem.email.value.indexOf("\@") == -1) {      if (validmail(document.logproblem.email) == false) {
         alert("You must enter a valid e-mail address");          alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}.");
         return          return;
       }
       if (document.logproblem.subject.value == '') {
           alert("$lt{'rsub'}.");
           return;
       }
       if (document.logproblem.description.value == '') {
           alert("$lt{'rdes'}.");
           return;
     }      }
     document.logproblem.submit();      document.logproblem.submit();
 }  }
   
 END  END
     if ($cid =~ m/_/) {      $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
         ($cdom,$cnum) = split/_/,$cid;      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 67  END Line 158  END
         $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 ($env{'environment.permanentemail'}) {
     }          $email = $env{'environment.permanentemail'};
     if (!$email && $ENV{'environment.notification'}) {      } elsif ($env{'environment.critnotification'}) {
         $email = $ENV{'environment.notification'};          $email = $env{'environment.critnotification'};
     }      } elsif ($env{'environment.notification'}) {
     if ($ENV{'environment.lastname'}) {          $email = $env{'environment.notification'};
         $lastname = $ENV{'environment.lastname'};      }
     }      if ($env{'environment.lastname'}) {
     if ($ENV{'environment.firstname'}) {          $lastname = $env{'environment.lastname'};
         $firstname = $ENV{'environment.firstname'};      }
     }      if ($env{'environment.firstname'}) {
     my @sections = split/,/,$sectionlist;          $firstname = $env{'environment.firstname'};
     my %groupid = ();      }
     foreach (@sections) {      my @sections = split(/,/,$sectionlist);
         my ($sec,$grp) = split/:/,$_;      my %groupid;
       foreach my $section (@sections) {
           my ($sec,$grp) = split(/:/,$section);
         $groupid{$sec} = $grp;          $groupid{$sec} = $grp;
     }      }
     my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
     my $codedom = $defdom;                                                   'useremail','useraccount']);
     my %coursecodes = ();      if ($env{'form.origurl'} eq '/adm/createaccount') {
     my %codes = ();          if ($email eq '') {
     my @codetitles = ();              if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
     my %cat_titles = ();                  $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
     my %cat_order = ();              }
     my %idlist = ();          }
     my %idnums = ();          if ($uname eq '') {
     my %idlist_titles = ();              if ($env{'form.useraccount'} =~ /^$match_username$/) {
                   $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
               }
           }
       }
       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 = '';      my $jscript = '';
           my $loaditems = qq|
     if ($cdom) {  function initialize_codes() {
         $codedom = $cdom;      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 '') {          if ($ccode eq '') {
             my $numtypes = @codetitles;              $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
             &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);              if ($format_reply eq 'ok') {
             &javascript_code_selections($numtypes,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);                  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 = '<script type="text/javascript">'."\n$scripttag\n$jscript\n".
 <head>   '</script>';
  <title>LON-CAPA support request</title>      my %add_entries = (topmargin    => "0",
 <script>         marginheight => "0",
 $scripttag         onLoad       =>"initialize_codes()",);
 $jscript  
 </script>      
 </head>      $r->print(&Apache::loncommon::start_page('Support Request',$js,
 $bodytag         { 'function'    => $function,
  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">   'add_entries' => \%add_entries,
   <tr>   'only_body'   => 1,}));
    <td>      if ($r->uri eq '/adm/helpdesk') {
     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">          &print_header($r,$origurl);
      <tr>      }
       <td>      my @css = ('LC_evenrow_value','LC_oddrow_value');
        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">      my $num = 1;
         <tr>      my $i = $num%2;
          <td>      $r->print('<form method="post" name="logproblem" enctype="multipart/form-data">'."\n");
   <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">      my $output = &Apache::lonhtmlcommon::start_pick_box().
            <form method="post" name="logproblem" enctype="multipart/form-data">                   &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n";
            <tr>  
             <td width="140" bgcolor="$tablecolor">  
              <table width="140" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td align="right"><b>Name:</b>  
                </td>  
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
 END  
     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,'"<>&').'" />';
     } 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,'"<>&').'" />';
     }      }
     $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.gif" /><br />      $num ++;
             </td>      $i = $num%2;
            </tr>      if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
            <tr>          $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]).
             <td width="140" bgcolor="$tablecolor">                     '<input type="text" size="50" name="cc" value="" /><br />'."\n".
              <table width="140" border="0" cellpadding="8" cellspacing="0">                     &Apache::lonhtmlcommon::row_closure();
               <tr>          $num ++;
                <td align="right"><b>E-mail address:</b>          $i = $num%2;
                </td>      }
               </tr>      $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]);
              </table>      my $udom_input = '<input type="hidden" name="udom" value="'.
             </td>                       &HTML::Entities::encode($udom,'"<>&').'" />';
             <td width="100%" valign="top">      my $uname_input = '<input type="hidden" name="uname" value="'.
              <table width="100%" border="0" cellpadding="8" cellspacing="0">                        &HTML::Entities::encode($uname,'"<>&').'" />'; 
               <tr>      if (($env{'user.name'} =~ /^$match_username$/) && 
                <td>          ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
                 <input type="text" size="20" name="email" value="$email" /><br />          $output .= '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input.$uname_input;
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <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>  
                <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 />';
           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');
         }          }
         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>                 $showserver.'<input type="hidden" name="sourceurl" value="'.
            </tr>                 &HTML::Entities::encode($server,'"<>&').'" />'.
            <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.gif" /><br />                 '<input type="text" size="15" name="phone" /><br />'.
             </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},'"<>&').'" />';
             </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="" />';
               <tr>  
                <td>  
                 http://$server$origurl<input type="hidden" name="origurl" value="http://$server$origurl" />  
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
            <tr>  
             <td width="100%" colspan="2" bgcolor="#000000">  
              <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>  
                <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.gif" /><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}{$_}.';&nbsp;');  
         }          }
         $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="" />';
               } 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'}."\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="" />';
           }
     }      }
     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.gif" /><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" />';
     }      }
     $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" wrap="virtual"></textarea>'.
              <img src="/adm/lonMisc/blackdot.gif" /><br />                 &Apache::lonhtmlcommon::row_closure();
             </td>      $num ++;
            </tr>      $i = $num%2; 
            <tr>      if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
             <td width="140" bgcolor="$tablecolor">          $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
              <table width="140" border="0" cellpadding="8" cellspacing="0">                     ' <input type="file" name="screenshot" size="20" /><br />'.$lt{'uplf'}."\n".
               <tr>          &Apache::lonhtmlcommon::row_closure();
                <td align="right"><b>Subject</b>          $num ++;
                </td>          $i = $num%2; 
               </tr>  
              </table>  
             </td>  
             <td width="100%" valign="top">  
              <table width="100%" border="0" cellpadding="8" cellspacing="0">  
               <tr>  
                <td>  
                 <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.gif" /><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.gif" /><br />  
     </td>  
    </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);      $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
            <tr>      $output .= <<END;
             <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="button" value="Submit Request Form" onClick="validate()"/> &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();
       $r->print(<<END);
   $output
   </form>
   <br />
   END
       $r->print(&Apache::loncommon::end_page());
     return;      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 @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');      my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
       my @cookievars = ('lonID');
   
     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);  
     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};      my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
     my $to =  $Apache::lonnet::perlvar{'lonSupportEMail'};      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 $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','screenshot');  
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);  
   
     my $supportmsg = qq|  
 Name: $ENV{'form.username'}  
 Email: $ENV{'form.email'}  
 Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}  
 Tel: $ENV{'form.phone'}  
 Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}  
 Subject: $ENV{'form.subject'}  
 Description: $ENV{'form.description'}  
 URL: $ENV{'form.origurl'}  
 Date/Time: $reporttime  
   
     |;      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
     my $descrip = $ENV{'form.description'};      my $coursecode = $env{'form.coursecode'};
     $descrip =~ s#\n#<br />#g;      if ($coursecode eq '') {
     my $displaymsg = qq|          my $totcodes = 0;
 <font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $ENV{'form.username'}</font><br />          my %coursecodes;
 <font color="$fontcolor">Email: </font><font color="$vlinkcolor">$ENV{'form.email'}</font><br />          $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
 <font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$ENV{'form.uname'} - $ENV{'form.udom'}</font><br />          my $coursecode;
 <font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$ENV{'form.phone'}</font><br />          my @standardnames = &Apache::loncommon::get_standard_codeitems();
 <font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}</font><br />          if ($totcodes > 0) {
 <font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$ENV{'form.subject'}</font><br />              $coursecode = &Apache::courseclassifier::instcode_from_selectors($defdom); 
 <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />          } 
 <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$ENV{'form.origurl'}</font><br />          if ($coursecode eq '') {
 <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />              foreach my $item (@standardnames) {
     |;                  if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
                       $coursecode .= $env{'form.'.$item};
     if ($to =~ m/^[^\@]+\@[^\@]+$/) {                  }
         $r->print(<<END);              }
 <html>          }
 <head>      }
  <title>LON-CAPA support request recorded</title>      my %lt = &Apache::lonlocal::texthash (
 </head>                   username    => 'Name',
 $bodytag                   email       => 'E-mail',
  <h3>A support request has been sent to $to</h3>                   cc          => 'Cc',
 END                   user        => 'Username/domain',
     } else {                   phone       => 'Phone',
         $to = $admin;                   crsi        => 'Course Information',
         if ($to =~ m/^[^\@]+\@[^\@]+$/) {                   subject     => 'Subject',
             $r->print(<<END);                   description => 'Description',
 <html>                   sourceurl   => 'URL',
 <head>                   date        => 'Date/Time',
  <title>LON-CAPA support request recorded</title>                   secn        => 'Section',
 </head>                   asup        => 'A support request has been sent to',
 $bodytag                   warn        => 'Warning: Problem with support e-mail address',
  <h3>A support request has been sent to $to</h3>                   your        => 'Your support request contained the following information',
 END                   sect        => 'section',
                    info        => 'Information supplied',
                    adin        => 'Additional information recorded',
       );
   
       my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist);
       if ((defined($env{'user.name'})) && (defined($env{'form.cc'}))) {
           my @ccs;
           if ($env{'form.cc'} =~ /,/) {
               @ccs = split(/,/,$env{'form.cc'});
         } else {          } else {
             $r->print(<<END);              $env{'form.cc'} =~ s/^\s+//;
 <html>              $env{'form.cc'} =~ s/\s+$//;
 <head>              @ccs = $env{'form.cc'};
  <title>LON-CAPA support request recorded</title>          }
 </head>          foreach my $cc (@ccs) {
 $bodytag              $cc =~ s/^\s+//g;
  <h3>Warning: Problem with support e-mail address</h3>              $cc =~ s/\s+$//g;
 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 or administrator at your institution. Instead a copy has been sent to the LON-CAPA support team at Michigan State University.               if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
 END                  if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
                       push(@ok_ccs,$cc);
                   }
               } elsif ($cc ne '') {
                   if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
                       push(@bad_ccs,$cc);
                   }
               }
           }
           if (@ok_ccs > 0) {
              $okcclist = join(', ',@ok_ccs); 
           } 
           if (@bad_ccs == 1) {
               $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0];
           } elsif (@bad_ccs > 1) {
               my $bad_cc_string = join(', ',@bad_ccs);
               $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string;
           }
       }
       $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
   
   END
       my $displaymsg;
       foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
           if ($env{'form.'.$item} ne '') {
               if ($item eq 'description') {
                   my $descrip = $env{'form.description'};
                   $descrip =  &cleanup_html($descrip);
                   $descrip =~ s|[\n\r\f]|<br />|g;
                   $displaymsg .= 
                       '<span class="LC_helpform_receipt_cat">'.
                       "$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') {
                   $displaymsg .=
                       '<span class="LC_helpform_receipt_cat">'.
                       "$lt{$item}</span>: $okcclist<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
       if ($r->uri eq '/adm/helpdesk') {
           &print_header($r,$url,'process');
       }
       my $bad_email = 0;
       if ($to =~ /,/) {
           my @ok_email; 
           foreach my $email (split(/,/,$to)) {
               if ($email =~ m/^[^\@]+\@[^\@]+$/) {
                   if (!grep(/^\Q$email\E$/,@ok_email)) {
                       push(@ok_email,$email);
                   }
               }
           }
           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;
           }
       }
       if ($bad_email) {
           $r->print('
    <h3>'.$lt{'warn'}.'</h3>'.
   &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 <b>not</b> been sent to the LON-CAPA support staff or administrator at your institution.',$to).' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.')); 
             $to = 'helpdesk@lon-capa.org';              $to = 'helpdesk@lon-capa.org';
       } else {
           $r->print('<h3>'.$lt{'asup'}.' '.$to.'</h3>');
       }
       if (defined($env{'form.email'})) {
           $env{'form.email'} =~ s/^\s+//;
           $env{'form.email'} =~ s/\s+$//;
           if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
               $from = $env{'form.email'};
         }          }
     }      }
     if (defined($ENV{'form.email'})) {  
         if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {      if (defined($env{'form.cc'})) {
             $from = $ENV{'form.email'};          if ($badccmsg) {
               $displaymsg .= $badccmsg;
         }          }
     }      }
   
     my $subject = $ENV{'form.subject'};      my $subject = $env{'form.subject'};
     $subject =~ s#(`)#'#g;      $subject =~ s/(`)/'/g;
     $subject =~ s#\$#\(\$\)#g;      $subject =~ s/\$/\(\$\)/g;
     $supportmsg =~ s#(`)#'#g;      $supportmsg =~ s/(`)/'/g;
     $supportmsg =~ s#\$#\(\$\)#g;      $supportmsg =~ s/\$/\(\$\)/g;
     $displaymsg =~ s#(`)#'#g;      $displaymsg =~ s/(`)/'/g;
     $displaymsg =~ s#\$#\(\$\)#g;      $displaymsg =~ s/\$/\(\$\)/g;
     my $fname;      my $fname;
   
     my $attachmentpath = '';      my $attachmentpath = '';
     my $attachmentsize = '';      my $attachmentsize = '';
     if (defined($ENV{'user.name'})) {      if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public')
         if ($ENV{'form.screenshot.filename'}) {          && ($env{'user.domain'} ne 'public')) {
             $attachmentsize = length($ENV{'form.screenshot'});          if ($env{'form.screenshot.filename'}) {
               $attachmentsize = length($env{'form.screenshot'});
             if ($attachmentsize > 131072) {              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.";                  $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 {              } else {
                 $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');                  $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-/([^/]+)$-) {      if ($attachmentpath =~ m-/([^/]+)$-) {
         $fname = $1;          $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'}";          $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";          $supportmsg .= "\n";
         foreach (@envvars) {          foreach my $var (@cookievars) {
             $supportmsg .= "$_: $ENV{$_}\n";              $supportmsg .= "$var: $cookies{$var}\n";
           }
           foreach my $var(@ENVvars) {
               $supportmsg .= "$var: $ENV{$var}\n";
           }
           foreach my $var (@envvars) {
               $supportmsg .= "$var: $env{$var}\n";
         }          }
     }      }
     
Line 612  END Line 766  END
                  Type    =>'TEXT',                   Type    =>'TEXT',
                  Data    => $supportmsg,                   Data    => $supportmsg,
                  );                   );
       if (@ok_ccs > 0) {
           my $cc_string = join(', ',@ok_ccs);
           $msg->add("Cc" => $cc_string);
       }
       if ($bcc ne '') {
           $msg->add("Bcc" => $bcc);
       }
       $msg->add('Content-type','text/plain; charset=UTF-8');
   
     if ($attachmentpath) {      if ($attachmentpath) {
         my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);          my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
Line 622  END Line 784  END
   
     } else {      } else {
         my $envdata = '';          my $envdata = '';
         foreach (@envvars) {          foreach my $var (@cookievars) {
             $envdata .= "$_: $ENV{$_}\n";              $envdata .= "$var: $cookies{$var}\n";
         }          }
         foreach (@loncvars) {          foreach my $var (@ENVvars) {
             $envdata .= "$_: $ENV{$_}\n";              $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',          $msg->attach(Type => 'TEXT',
                      Data => $envdata);                       Data => $envdata);
     }      }
   
 ### Send it:  ### 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  
     my %oldENV=%ENV;  
     undef(%ENV);  
     $msg->send('sendmail');      $msg->send('sendmail');
     %ENV=%oldENV;  
     undef(%oldENV);  
   
     if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {      if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
         unlink($attachmentpath);          unlink($attachmentpath);
     }      }
     $r->print(qq|      $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
  <b>Your support request contained the following information</b>:<br /><br />      $r->print('<div style="width:620px;">'.
  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">                &Apache::lonhtmlcommon::start_pick_box().
   <tr>                &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
    <td>                &Apache::lonhtmlcommon::row_closure().
     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">                &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
      <tr>      my $envmsg;
       <td>      foreach my $var (@cookievars) {
        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">          if ($cookies{$var} ne '') {
         <tr>              $envmsg.= '<span class="LC_helpform_receipt_cat">'.
          <td>                        $var.'</span>:&nbsp;'.$cookies{$var}.', ';
           <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">          }
            <tr>      }
             <td width="140" bgcolor="$tablecolor">      foreach my $var (@ENVvars) {
              <table width="140" border="0" cellpadding="8" cellspacing="0">          if ($ENV{$var} ne '') {
               <tr>              $envmsg .= '<span class="LC_helpform_receipt_cat">'.
                <td align="right"><b>Information supplied</b>                         $var.'</span>:&nbsp;'.$ENV{$var}.', ';
                </td>          }
               </tr>      }
              </table>      foreach my $var (@envvars) {
             </td>          if ($env{$var} ne '') { 
             <td width="100%" valign="top">              $envmsg .= '<span class="LC_helpform_receipt_cat">'.
              <table width="100%" border="0" cellpadding="8" cellspacing="0">                         $var.'</span>:&nbsp;'.$env{$var}.', ';
               <tr>          }
                <td>$displaymsg</td>      }
               </tr>      $envmsg =~ s/, $//;
              </table>      $r->print($envmsg."\n".
             </td>                &Apache::lonhtmlcommon::row_closure(1)."\n".
            </tr>                &Apache::lonhtmlcommon::end_pick_box().
            <tr>                "</div>\n".
             <td width="100%" colspan="2" bgcolor="#000000">                &Apache::loncommon::end_page());
              <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>  
                <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) {  
         unless($ENV{$_} eq '') {   
             $r->print("$_:&nbsp;<font color='$vlinkcolor'>$ENV{$_}</font>, ");  
         }  
     }  
     $r->print("  
                </td>  
               </tr>  
              </table>  
             </td>  
            </tr>  
           </table>  
          </td>  
         </tr>  
        </table>  
       </td>  
      </tr>  
     </table>  
    </td>  
   </tr>  
  </table>  
     ");  
 }  }
   
 sub retrieve_instcodes {  sub print_header {
     my ($coursecodes,$codedom,$totcodes) = @_;      my ($r,$origurl,$command) = @_;
     my %courses = &Apache::lonnet::courseiddump($codedom,'.',1);      my $location=&Apache::loncommon::lonhttpdurl("/adm");
     foreach my $course (keys %courses) {      my ($component_url);
         if ($courses{$course} =~ m/^[^:]*:([^:]+)$/) {      my $helpdesk_link = '<a href="javascript:validate()">';
             $$coursecodes{$course} = &Apache::lonnet::unescape($1);      if ($command eq 'process') {
             $totcodes ++;          $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',
                                            );
       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.');
     }      }
     return $totcodes;      if ($origurl eq '') {
 }          $origurl = 'javascript:history.go(-1)';
   
 sub build_code_selections {  
     my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;  
     my %idarrays = ();  
     for (my $i=1; $i<@{$codetitles}; $i++) {  
         %{$idarrays{$$codetitles[$i]}} = ();  
     }  
     foreach my $cid (sort keys %{$codes}) {  
         &recurse_list($cid,$codetitles,$codes,0,\%idarrays);  
     }  
     for (my $num=0; $num<@{$codetitles}; $num++) {  
         if ($num == 0) {  
             my @contents = ();  
             my @contents_titles = ();  
             &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);  
             if (defined($$cat_titles{$$codetitles[0]})) {  
                 foreach (@contents) {  
                     push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};  
                 }  
             }  
             $$idlist{$$codetitles[0]} = join('","',@contents);  
             $$idnums{$$codetitles[0]} = scalar(@contents);  
             if (defined($$cat_titles{$$codetitles[0]})) {  
                 $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);  
             }  
         } elsif ($num == 1) {  
             %{$$idlist{$$codetitles[1]}} = ();  
             %{$$idlist_titles{$$codetitles[1]}} = ();  
             foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {  
                 my @sorted_a = ();  
                 my @sorted_a_titles = ();  
                 &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);  
                 if (defined($$cat_titles{$$codetitles[1]})) {  
                     foreach (@sorted_a) {  
                         push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};  
                     }  
                 }  
                 $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);  
                 $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);  
                 if (defined($$cat_titles{$$codetitles[1]})) {  
                     $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);  
                 }  
             }  
         } elsif ($num == 2) {  
             %{$$idlist{$$codetitles[2]}} = ();  
             %{$$idlist_titles{$$codetitles[2]}} = ();  
             foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {  
                 %{$$idlist{$$codetitles[2]}{$key_a}} = ();  
                 %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();  
                 foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {  
                     my @sorted_b = ();  
                     my @sorted_b_titles = ();  
                     &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);  
                     if (defined($$cat_titles{$$codetitles[1]})) {  
                         foreach (@sorted_b) {  
                             push @sorted_b_titles, $$cat_titles{$$codetitles[1]}{$_};  
                         }  
                     }  
                     $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);  
                     $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);  
                     if (defined($$cat_titles{$$codetitles[2]})) {  
                         $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);  
                     }  
                 }  
             }  
         } elsif ($num == 3) {  
             %{$$idlist{$$codetitles[3]}} = ();  
             foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {  
                 %{$$idlist{$$codetitles[3]}{$key_a}} = ();  
                 foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {  
                     %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();  
                     foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {  
                         my @sorted_c = ();  
                         &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);  
                         $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);  
                         $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);  
                     }  
                 }  
             }  
         } elsif ($num == 4) {  
             %{$$idlist{$$codetitles[4]}} = ();  
             foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {  
                 %{$$idlist{$$codetitles[4]}{$key_a}} = ();  
                 foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {  
                     %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();  
                     foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {  
                         %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();  
                         foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {  
                             my @sorted_d = ();  
                             &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);  
                             $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);  
                             $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);  
                         }  
                     }  
                 }  
             }  
         }  
     }      }
 }      $r->print(<<END);
   <table width="620" border="0" cellspacing="0" cellpadding="0" height="55">   <tr height="50">    <td width='5'>&nbsp;</td>
 sub sort_cats {     <td>
     my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;      <fieldset>
     my @unsorted = @{$idsarrayref};        <legend>
     if (defined($$cat_order{$$codetitles[$num]})) {          <img src="$location/lonIcons/minilogo.gif" height="20" width="29" valign="bottom" />
         foreach (@{$$cat_order{$$codetitles[$num]}}) {          LON-CAPA $lt{'headline'}
             if (grep/^$_$/,@unsorted) {        </legend>
                 push @{$sorted}, $_;   <table id="LC_helpmenu_links">
             }     <tr>
         }      <td align="center"><span class="LC_nobreak"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" valign="middle" />&nbsp;<b><a href="/adm/loginproblems.html">$lt{'login'}</a></b>&nbsp;</span></td>
     } else {      <td align="center"><span class="LC_nobreak">&nbsp;<b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" valign="middle" />&nbsp;$lt{'ask'}</a></b>&nbsp;</span></td>$getstartlink
         @{$sorted} = sort (@unsorted);      <td align="center"><span class="LC_nobreak">&nbsp;<b><a href="$origurl" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" valign="middle" />&nbsp;$lt{'back'}</a></b>&nbsp;</span></td>
      </tr>
    </table>
   </fieldset>
     </td>
     <td width='5'>&nbsp;</td>
    </tr>
    <tr height='5'>
     <td colspan='3' height='5'>&nbsp;</td>
    </tr>
   END
       if  ($command ne 'process') {
           $r->print('
    <tr>
     <td colspan="3">'.$reviewtext.' '
   .&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.').'<br />'
   .'<font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '
   .&mt('Contact your instructor instead.')
   .'</font><br /><br />
     </td>
    </tr>');
     }      }
       $r->print('
   </table>');
       return;
 }  }
   
   sub get_domain {
 sub recurse_list {      my $codedom;
     my ($cid,$codetitles,$codes,$num,$idarrays) = @_;      if (exists($env{'form.codedom'})) {
     if ($num == 0) {          $codedom = $env{'form.codedom'};
         if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {      } elsif ($env{'request.course.id'}) {
             push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};          $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
         }      } elsif ($env{'request.role.domain'}) {
     } elsif ($num == 1) {          $codedom = $env{'request.role.domain'};
         if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {      } else {
             if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {          $codedom = &Apache::lonnet::default_login_domain();
                 push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};  
             }  
         } else {  
             @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");  
         }  
     } elsif ($num == 2) {  
         if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {  
             if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {  
                 if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {  
                     push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};  
                 }  
             } else {  
                 @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");  
             }  
         } else {  
             %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();  
             @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");  
         }  
     } elsif ($num == 3) {  
         if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {  
             if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {  
                 if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {  
                     if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {  
                         push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};  
                     }  
                 } else {  
                     @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");  
                 }  
             } else {  
                 %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();  
                 @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");  
             }  
         } else {  
             %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();  
             %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();  
             @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");  
         }  
     } elsif ($num == 4) {  
         if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {  
             if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {  
                 if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {  
                     if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {  
                         if (!grep/^$$codes{$cid}{$$codetitles[4]}$/,@{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}) {  
                             push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};  
                         }  
                     } else {  
                         @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");  
                     }  
                 } else {  
                     %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();  
                     @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");  
                 }  
             } else {  
                 %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();  
                 %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();  
                 @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");  
             }  
         } else {  
             %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();  
             %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();  
             %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();  
             @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");  
         }  
     }  
     $num ++;  
     if ($num <@{$codetitles}) {  
         &recurse_list($cid,$codetitles,$codes,$num,$idarrays);  
     }      }
       return $codedom;
 }  }
   
 sub javascript_code_selections {  sub cleanup_html {
     my ($numcats,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;      my ($incoming) = @_;
     $$script_tag .= <<END;      my $outgoing;
 function courseSet(caller) {      if ($incoming ne '') {
     var idyr = document.forms.logproblem.idyear.selectedIndex          $outgoing = $incoming;
     var idsem  = document.forms.logproblem.idsem.selectedIndex          $outgoing =~ s/\#/&#035;/g;
     var iddept = document.forms.logproblem.iddept.selectedIndex          $outgoing =~ s/\&/&#038;/g;
     var idclass = document.forms.logproblem.idclass.selectedIndex          $outgoing =~ s/</&#060;/g;
     var idyears = new Array("$$idlist{$$codetitles[0]}");          $outgoing =~ s/>/&#062;/g;
     var idsems = new Array ($$idnums{$$codetitles[0]});          $outgoing =~ s/\(/&#040/g;
     var idsemlongs = new Array ($$idnums{$$codetitles[0]});          $outgoing =~ s/\)/&#041;/g;
     var idcodes = new Array ($$idnums{$$codetitles[0]});          $outgoing =~ s/"/&#034;/g;
     var idcourses = new Array ($$idnums{$$codetitles[0]});          $outgoing =~ s/'/&#039;/g;
     var idsections = new Array ($$idnums{$$codetitles[0]})          $outgoing =~ s/\$/&#036;/g;
 END  
     my @sort_a = split/","/,$$idlist{$$codetitles[0]};   
     for (my $j=0; $j<@sort_a; $j++) {  
         $$script_tag .= qq| idsems[$j] = new Array("$$idlist{$$codetitles[1]}{$sort_a[$j]}")\n|;  
         $$script_tag .= qq| idsemlongs[$j] = new Array("$$idlist_titles{$$codetitles[1]}{$sort_a[$j]}")\n|;  
         $$script_tag .= qq| idcodes[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;  
         $$script_tag .= qq| idcourses[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;  
         $$script_tag .= qq| idsections[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;  
         my @sort_b = split/","/,$$idlist{$$codetitles[1]}{$sort_a[$j]};  
         for (my $k=0; $k<@sort_b; $k++) {  
             my $idcode_entry = $$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};  
             $$script_tag .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;  
             $$script_tag .= qq| idcourses[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;  
             $$script_tag .= qq| idsections[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;  
             my @sort_c = split/","/,$$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};  
             for (my $l=0; $l<@sort_c; $l++) {  
                 my $idcourse_entry = $$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};  
                 $$script_tag .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;  
                 $$script_tag .= qq| idsections[$j][$k][$l] = new Array($$idnums{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]})\n|;  
                 my @sort_d = split/","/,$$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};  
                 for (my $m=0; $m<@sort_d; $m++) {  
                     my $idsecentry = $$idlist{$$codetitles[4]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]}{$sort_d[$m]};  
                     $$script_tag .= qq| idsections[$j][$k][$l][$m] = new Array("$idsecentry")\n|;  
                 }  
             }  
         }  
     }      }
     $$script_tag .= (<<END_OF_BLOCK);      return $outgoing;
  if (caller == "semester") {  
    document.forms.logproblem.iddept.length = 0  
    document.forms.logproblem.idclass.length = 0  
    document.forms.logproblem.idsec.length = 0  
    document.forms.logproblem.iddept.options[0] = new Option("<-Pick sem.","-1",true,true)  
    document.forms.logproblem.idclass.options[0] = new Option("<-Pick dept.","-1",true,true)  
    document.forms.logproblem.idsec.options[0] = new Option("Pick course first (above)","-1",true,true)  
    if (idyr == 0) {  
     document.forms.logproblem.idsem.length = 0  
     document.forms.logproblem.idsem.options[0] = new Option("<-Pick year","-1",true,true)  
    }  
    else {  
     document.forms.logproblem.idsem.length = 0  
     document.forms.logproblem.idsem.options[0] = new Option("Select","-1",true,true)  
     for (var i=0; i<idsems[idyr-1].length; i++) {  
       document.forms.logproblem.idsem.options[i+1] = new Option(idsemlongs[idyr-1][i],idsems[idyr-1][i],false,false)  
     }  
    }  
    document.forms.logproblem.idsem.selectedIndex = 0;  
  }  
  if (caller == "dept") {  
    document.forms.logproblem.iddept.length = 0  
    document.forms.logproblem.idclass.length = 0  
    document.forms.logproblem.idsec.length = 0  
    document.forms.logproblem.idclass.options[0] = new Option("<-Pick dept.","-1",true,true)  
    document.forms.logproblem.idsec.options[0] = new Option("Pick course first (above)","-1",true,true)  
    if (idsem == 0) {  
      document.forms.logproblem.iddept.options[0] = new Option("<-Pick sem.","-1",true,true)  
      document.forms.logproblem.iddept.options[0] = new Option("<-Pick sem.","-1",true,true)  
    }  
    else {  
     document.forms.logproblem.iddept.options[0] = new Option("Select","-1",true,true)      
     for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {  
       document.forms.logproblem.iddept.options[i+1] = new Option(idcodes[idyr-1][idsem-1][i],idcodes[idyr-1][idsem-1][i],false,false)  
     }  
    }  
    document.forms.logproblem.iddept.selectedIndex = 0  
  }  
  if (caller == "course") {  
    document.forms.logproblem.idclass.length = 0  
    document.forms.logproblem.idsec.length = 0  
    document.forms.logproblem.idsec.options[0] = new Option("Pick course first (above)","-1",true,true)  
    if (iddept == 0) {  
      document.forms.logproblem.idclass.options[0] = new Option("<-Pick dept.","-1",true,true)  
    }  
    else {  
     document.forms.logproblem.idclass.options[0] = new Option("Select","-1",true,true)  
     for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {  
       document.forms.logproblem.idclass.options[i+1] = new Option(idcourses[idyr-1][idsem-1][iddept-1][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)  
     }  
    }  
    document.forms.logproblem.idclass.selectedIndex = 0  
  }  
 }  
 END_OF_BLOCK  
 }  }
   
 1;  1;

Removed from v.1.9  
changed lines
  Added in v.1.61


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