File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.14: download - view: text, annotated - select for diffs
Sat Dec 18 23:58:34 2004 UTC (19 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Add some links and preamble to display of support request form, when helpdesk is called from log-in page. Change default color.

    1: package Apache::lonsupportreq;
    2: 
    3: use strict;
    4: use lib qw(/home/httpd/lib/perl);
    5: use MIME::Types;
    6: use MIME::Lite;
    7: use Apache::Constants qw(:common);
    8: use Apache::loncommon();
    9: use Apache::lonnet();
   10: use Apache::lonlocal;
   11: 
   12: sub handler {
   13:     my ($r) = @_;
   14:     &Apache::loncommon::content_type($r,'text/html');
   15:     $r->send_http_header;
   16: 
   17:     if ($r->header_only) {
   18:         return OK;
   19:     }
   20:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
   21:     if ($r->uri eq '/adm/helpdesk') {
   22:         &Apache::loncommon::get_posted_cgi($r);
   23:     }
   24:     my $function = $ENV{'form.function'};
   25:     my $origurl = &Apache::lonnet::unescape($ENV{'form.origurl'});
   26:     my $action = $ENV{'form.action'};
   27: 
   28:     if ($action eq 'process') {
   29:         &print_request_receipt($r,$origurl,$function);
   30:     } else {
   31:         &print_request_form($r,$origurl,$function);
   32:     }
   33:     return OK;
   34: }
   35:     
   36: sub print_request_form {
   37:     my ($r,$origurl,$function) = @_;
   38:     my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,$cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server);
   39:     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0",marginheight="0"',1);
   40:     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
   41:     if (($tablecolor eq '') || ($tablecolor eq '#FFFFFF')) {
   42:         $tablecolor = '#EEEE99';
   43:     }
   44:     $ccode = '';
   45:     $os = $ENV{'browser.os'};
   46:     $browser = $ENV{'browser.type'};
   47:     $bversion = $ENV{'browser.version'};
   48:     $uhost = $ENV{'request.host'};
   49:     $uname = $ENV{'user.name'};
   50:     $udom = $ENV{'user.domain'};
   51:     $uhome = $ENV{'user.home'};
   52:     $urole = $ENV{'request.role'};
   53:     $usec = $ENV{'request.course.sec'};
   54:     $cid = $ENV{'request.course.id'};
   55:     $server = $ENV{'SERVER_NAME'};
   56:     my $scripttag = (<<'END');
   57: function validate() {
   58:     if (validmail(document.logproblem.email) == false) {
   59:         alert("The e-mail address you entered: "+document.logproblem.email.value+" is not a valid e-mail address.");
   60:         return;
   61:     }
   62:     document.logproblem.submit();
   63: }
   64: 
   65: function validmail(field) {
   66:     var str = field.value;
   67:     if (window.RegExp) {
   68:         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
   69:         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
   70:         var reg1 = new RegExp(reg1str);
   71:         var reg2 = new RegExp(reg2str);
   72:         if (!reg1.test(str) && reg2.test(str)) {
   73:             return true;
   74:         }
   75:         return false;
   76:     }
   77:     else
   78:     {
   79:         if(str.indexOf("@") >= 0) {
   80:             return true;
   81:         }
   82:         return false;
   83:     }
   84: }
   85: END
   86:     if ($cid =~ m/_/) {
   87:         ($cdom,$cnum) = split/_/,$cid;
   88:     }
   89:     if ($cdom && $cnum) {
   90:         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
   91:         $ctitle = $csettings{'description'};
   92:         $ccode = $csettings{'internal.coursecode'};
   93:         $sectionlist = $csettings{'internal.sectionnums'};
   94:     }
   95:     if ($ENV{'environment.critnotification'}) {
   96:         $email = $ENV{'environment.critnotification'};
   97:     }
   98:     if (!$email && $ENV{'environment.notification'}) {
   99:         $email = $ENV{'environment.notification'};
  100:     }
  101:     if ($ENV{'environment.lastname'}) {
  102:         $lastname = $ENV{'environment.lastname'};
  103:     }
  104:     if ($ENV{'environment.firstname'}) {
  105:         $firstname = $ENV{'environment.firstname'};
  106:     }
  107:     my @sections = split/,/,$sectionlist;
  108:     my %groupid = ();
  109:     foreach (@sections) {
  110:         my ($sec,$grp) = split/:/,$_;
  111:         $groupid{$sec} = $grp;
  112:     }
  113:     my $defdom = $Apache::lonnet::perlvar{'lonDefDomain'};
  114:     my $codedom = $defdom;
  115:     my %coursecodes = ();
  116:     my %codes = ();
  117:     my @codetitles = ();
  118:     my %cat_titles = ();
  119:     my %cat_order = ();
  120:     my %idlist = ();
  121:     my %idnums = ();
  122:     my %idlist_titles = ();
  123:     my $caller = 'global';
  124:     my $totcodes = 0;
  125:     my $format_reply;
  126:     my $jscript = '';
  127:     
  128:     if ($cdom) {
  129:         $codedom = $cdom;
  130:     }
  131:     if ($cnum) {
  132:         $coursecodes{$cnum} = $ccode;
  133:         if ($ccode eq '') {
  134:             $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
  135:         } else {
  136:             $coursecodes{$cnum} = $ccode;
  137:             $caller = $cnum;
  138:             $totcodes ++;
  139:         }
  140:     } else { 
  141:         $totcodes = &retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
  142:     }
  143:     if ($totcodes > 0) {
  144:         $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
  145:         if ($ccode eq '') {
  146:             my $numtypes = @codetitles;
  147:             &build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
  148:             &javascript_code_selections($numtypes,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
  149:         }
  150:     }
  151:     $r->print(<<ENDHEAD);
  152: <html>
  153: <head>
  154:  <title>LON-CAPA support request</title>
  155: <script>
  156: $scripttag
  157: $jscript
  158: </script>
  159: </head>
  160: $bodytag
  161: ENDHEAD
  162:     if ($r->uri() eq '/adm/helpdesk') {
  163:         &print_header($r,$origurl);
  164:     }
  165:     $r->print(<<"END");
  166:  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  167:   <tr>
  168:    <td>
  169:     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  170:      <tr>
  171:       <td>
  172:        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
  173:         <tr>
  174:          <td>
  175: 	  <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
  176:            <form method="post" name="logproblem" enctype="multipart/form-data">
  177:            <tr>
  178:             <td width="140" bgcolor="$tablecolor">
  179:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  180:               <tr>
  181:                <td align="right"><b>Name:</b>
  182:                </td>
  183:               </tr>
  184:              </table>
  185:             </td>
  186:             <td width="100%" valign="top">
  187:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  188:               <tr>
  189:                <td>
  190: END
  191:     my $fullname = '';
  192:     if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
  193:         $fullname = "$firstname $lastname"; 
  194:         $r->print("$fullname<input type=\"hidden\" name=\"username\" value=\"$fullname\" />");
  195:     } else {
  196:         if (defined($firstname) && $firstname ne '') {
  197:             $fullname = $firstname;
  198:         } elsif (defined($lastname) && $lastname ne '') {
  199:             $fullname= " $lastname";
  200:         }
  201:         $r->print('<input type="text" size="20" name="username" value="'.$fullname.'" /><br />');
  202:     }
  203:     $r->print(<<END);
  204:                </td>
  205:               </tr>
  206:              </table>
  207:             </td>
  208:            </tr>
  209:            <tr>
  210:             <td width="100%" colspan="2" bgcolor="#000000">
  211:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  212:             </td>
  213:            </tr>
  214:            <tr>
  215:             <td width="140" bgcolor="$tablecolor">
  216:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  217:               <tr>
  218:                <td align="right"><b>E-mail address:</b>
  219:                </td>
  220:               </tr>
  221:              </table>
  222:             </td>
  223:             <td width="100%" valign="top">
  224:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  225:               <tr>
  226:                <td>
  227:                 <input type="text" size="20" name="email" value="$email" /><br />
  228:                </td>
  229:               </tr>
  230:              </table>
  231:             </td>
  232:            </tr>
  233:            <tr>
  234:             <td width="100%" colspan="2" bgcolor="#000000">
  235:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  236:             </td>
  237:            </tr>
  238:            <tr>
  239:             <td width="140" bgcolor="$tablecolor">
  240:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  241:               <tr>
  242:                <td align="right"><b>username/domain:</b>
  243:                </td>
  244:               </tr>
  245:              </table>
  246:             </td>
  247:             <td width="100%" valign="top">
  248:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  249:               <tr>
  250:                <td>
  251: END
  252:     my $udom_input = '<input type="hidden" name="udom" value="'.$udom.'" />';
  253:     my $uname_input = '<input type="hidden" name="uname" value="'.$uname.'" />'; 
  254:     if (defined($uname) && defined($udom)) {
  255:         $r->print('<i>username</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>domain</i>:&nbsp;'.$udom.$udom_input.$uname_input);
  256:     } else {
  257:         my $udomform = '';
  258:         my $unameform = '';
  259:         if (defined($udom)) {
  260:             $udomform = '<i>domain</i>:&nbsp;'.$udom.$udom_input;
  261:         } elsif (defined($uname)) {
  262:             $unameform = '<i>username</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
  263:         }
  264:         if ($udomform eq '') {
  265:             $udomform = '<i>domain</i>:&nbsp;';
  266:             $udomform .= &Apache::loncommon::select_dom_form('','udom');
  267:         }
  268:         if ($unameform eq '') {
  269:             $unameform= '<i>username</i>:&nbsp;<input type="text" size="20" name="loncname" value="'.$uname.'" />&nbsp;&nbsp;';
  270:         }
  271:         $r->print($unameform.$udomform.'<br />Enter the username you use to log-in to your LON-CAPA system, and choose your domain.');
  272:     }
  273:     $r->print(<<END);
  274:                </td>
  275:               </tr>
  276:              </table>
  277:             </td>
  278:            </tr>
  279:            <tr>
  280:             <td width="100%" colspan="2" bgcolor="#000000">
  281:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  282:             </td>
  283:            </tr>
  284:            <tr>
  285:             <td width="140" bgcolor="$tablecolor">
  286:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  287:               <tr>
  288:                <td align="right"><b>URL of page:</b>
  289:                </td>
  290:               </tr>
  291:              </table>
  292:             </td>
  293:             <td width="100%" valign="top">
  294:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  295:               <tr>
  296:                <td>
  297:                 http://$server$origurl<input type="hidden" name="sourceurl" value="http://$server$origurl" />
  298:                </td>
  299:               </tr>
  300:              </table>
  301:             </td>
  302:            </tr>
  303:            <tr>
  304:             <td width="100%" colspan="2" bgcolor="#000000">
  305:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  306:             </td>
  307:            </tr>
  308:            <tr>
  309:             <td width="140" bgcolor="$tablecolor">
  310:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  311:               <tr>
  312:                <td align="right"><b>Phone #:</b>
  313:                </td>
  314:               </tr>
  315:              </table>
  316:             </td>
  317:             <td width="100%" valign="top">
  318:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  319:               <tr>
  320:                <td>
  321:                 <input type="text" size="15" name="phone"><br>
  322:                </td>
  323:               </tr>
  324:              </table>
  325:             </td>
  326:            </tr>
  327:            <tr>
  328:             <td width="100%" colspan="2" bgcolor="#000000">
  329:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  330:             </td>
  331:            </tr>
  332:            <tr>
  333:             <td width="140" bgcolor="$tablecolor">
  334:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  335:               <tr>
  336:                <td align="right"><b>Course Details:</b>
  337:                </td>
  338:               </tr>
  339:              </table>
  340:             </td>
  341:             <td width="100%" valign="top">
  342:              <table border="0" cellpadding="3" cellspacing="3">
  343:               <tr>
  344:                <td>
  345: END
  346:     if ($cnum) { 
  347:         if ($coursecodes{$cnum}) {
  348:             foreach (@codetitles) {
  349:                 $r->print('<i>'.$_.'</i>:&nbsp;'.$codes{$cnum}{$_}.';&nbsp;');
  350:             }
  351:             $r->print('&nbsp;<input type="hidden" name="coursecode" value="'.$coursecodes{$cnum}.'" />');
  352:         } else {
  353:             $r->print('Enter institutional course code:&nbsp;
  354:                   <input type="text" name="coursecode" size="15" value="" />');
  355:         }
  356:     } else {
  357:         if ($totcodes > 0) {
  358:             my $numtitles = @codetitles;
  359:             if ($numtitles == 0) {
  360:                 $r->print('Enter institutional course code:&nbsp;
  361:                   <input type="text" name="coursecode" size="15" value="" />');
  362:             } else {
  363:                 my $lasttitle = $numtitles;
  364:                 if ($numtitles > 4) {
  365:                     $lasttitle = 4;
  366:                 } 
  367:                 $r->print('<table><tr><td>'.$codetitles[0].'<br />'."\n".
  368:                       '<select name="'.$codetitles[0].'" onChange="courseSet('."'$codetitles[0]'".')">'."\n".
  369:                       ' <option value="-1" />Select'."\n");
  370:                 my @items = ();
  371:                 if ($idlist{$codetitles[0]} =~ /","/) {
  372:                     @items = split/","/,$idlist{$codetitles[0]};
  373:                 } else {
  374:                     $items[0] = $idlist{$codetitles[0]};
  375:                 }
  376:                 foreach (@items) {
  377:                     $r->print(' <option value="'.$_.'" />'.$_);
  378:                 }
  379:                 $r->print('</select></td>');
  380:                 for (my $i=1; $i<$numtitles; $i++) {
  381:                     $r->print('<td>'.$codetitles[$i].'<br />'."\n".
  382:                      '<select name="'.$codetitles[$i].'" onChange="courseSet('."'$codetitles[$i]'".')">'."\n".
  383:                      '<option value="-1">&lt;-Pick '.$codetitles[$i-1].'</option>'."\n".
  384:                      '</select>'."\n".
  385:                      '</td>'
  386:                     );
  387:                 }
  388:                 $r->print('</tr></table>');
  389:                 if ($numtitles > 4) {
  390:                     $r->print('<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
  391:                           '<select name="'.$codetitles[$numtitles].'" onChange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
  392:                           '<option value="-1">&lt;-Pick '.$codetitles[$numtitles-1].'</option>'."\n".
  393:                           '</select>'."\n");
  394:                 }
  395:             }
  396:         } else {
  397:             $r->print('Enter institutional course code:&nbsp;
  398:                   <input type="text" name="coursecode" size="15" value="" />');
  399:         }
  400:     }
  401:     if ($ctitle) {
  402:         $r->print('<br /><i>Title</i>:&nbsp;'.$ctitle.'<input type="hidden" name="title" value="'.$ctitle.'" />');
  403:     } else {
  404:         $r->print('<br />Enter course title:&nbsp;
  405:                  <input type="text" name="title" size="25" value="" />');
  406:     }
  407:     $r->print(<<END);
  408:                </td>
  409:               </tr>
  410:              </table>
  411:             </td>
  412:            </tr>
  413:            <tr>
  414:             <td width="100%" colspan="2" bgcolor="#000000">
  415:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  416:             </td>
  417:            </tr>
  418:            <tr>
  419:             <td width="140" bgcolor="$tablecolor">
  420:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  421:               <tr>
  422:                <td align="right"><b>Section Number: </b>
  423:                </td>
  424:               </tr>
  425:              </table>
  426:             </td>
  427:             <td width="100%" valign="top">
  428:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  429:               <tr>
  430:                <td>
  431: END
  432:     if ($sectionlist) {
  433:         $r->print("<select name=\"section\">");
  434:         foreach (sort keys %groupid) {
  435:             if ($_ eq $groupid{$_} || $groupid{$_} eq '') {
  436:                 $r->print("<option value=\"$_\" />$_");
  437:             } else {
  438:                 $r->print("<option value=\"$_\" />$_ - (LON-CAPA sec: $groupid{$_})");
  439:             }
  440:         }
  441:         $r->print("</select>");
  442:     } else {
  443:         $r->print("<input type=\"text\" name=\"section\" size=\"10\"/>");
  444:     }
  445:     $r->print(<<END);
  446:                </td>
  447:               </tr>
  448:              </table>
  449:             </td>
  450:            </tr>
  451:            <tr>
  452:             <td width="100%" colspan="2" bgcolor="#000000">
  453:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  454:             </td>
  455:            </tr>
  456:            <tr>
  457:             <td width="140" bgcolor="$tablecolor">
  458:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  459:               <tr>
  460:                <td align="right"><b>Subject</b>
  461:                </td>
  462:               </tr>
  463:              </table>
  464:             </td>
  465:             <td width="100%" valign="top">
  466:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  467:               <tr>
  468:                <td>
  469:                 <input type="text" size="40" name="subject">
  470:                </td>
  471:               </tr>
  472:              </table>
  473:             </td>
  474:            </tr>
  475:            <tr>
  476:             <td width="100%" colspan="2" bgcolor="#000000">
  477:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  478:             </td>
  479:            </tr>
  480:            <tr>
  481:             <td width="140" bgcolor="$tablecolor">
  482:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  483:               <tr>
  484:                <td align="right"><b>Detailed description:</b>
  485:                </td>
  486:               </tr>
  487:              </table>
  488:             </td>
  489:             <td width="100%" valign="top">
  490:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  491:               <tr>
  492:                <td>
  493:                 <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>
  494:                </td>
  495:               </tr>
  496:              </table>
  497:             </td>
  498:            </tr>
  499:            <tr>
  500: 	    <td width="100%" colspan="2" bgcolor="#000000">
  501:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  502: 	    </td>
  503: 	   </tr>
  504: END
  505:     if (defined($ENV{'user.name'})) {
  506:         $r->print(<<END);
  507:            <tr>
  508:             <td width="140" bgcolor="$tablecolor">
  509:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  510:               <tr>
  511:                <td align="right"><b>Optional file upload:</b>
  512:                </td>
  513:               </tr>
  514:              </table>
  515:             </td>
  516:             <td width="100%" valign="top">
  517:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  518:               <tr>
  519:                <td>
  520:                 <input type="file" name="screenshot" size="20" /><br />Upload a file (e.g., a screenshot) relevant to your support request (128 KB max. size).
  521:                </td>
  522:               </tr>
  523:              </table>
  524:             </td>
  525:            </tr>
  526:            <tr>
  527:             <td width="100%" colspan="2" bgcolor="#000000">
  528:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  529:             </td>
  530:            </tr>
  531: END
  532:     }
  533:     $r->print(<<END);
  534:            <tr>
  535:             <td width="140" bgcolor="$tablecolor">
  536:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  537:               <tr>
  538:                <td align="right"><b>Finish:</b>
  539:                </td>
  540:               </tr>
  541:              </table>
  542:             </td>
  543:             <td width="100%" valign="top">
  544:              <table border="0" cellpadding="8" cellspacing="0">
  545:               <tr>
  546:                <td>
  547:                 <input type="hidden" name="action" value="process" />
  548:                 <input type="button" value="Submit Request Form" onClick="validate()"/> &nbsp;
  549:                </td>
  550:                <td>&nbsp;</td>
  551:                <td>
  552:                 <input type="reset" value="Clear Form">
  553:                </td>
  554:               </tr>
  555:              </table>
  556:             </td>
  557:            </tr>
  558:           </table>
  559:          </td>
  560:         </tr>
  561:        </table>
  562:       </td>
  563:      </tr>
  564:     </table>
  565:    </td>
  566:   </tr>
  567:  </table>
  568: </form>
  569: </body>
  570: </html>
  571: END
  572:     return;
  573: }
  574: 
  575: sub print_request_receipt {
  576:     my ($r,$url,$function) = @_;
  577:     my @envvars = ('lonID','HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME','browser.os','browser.type','browser.version','user.home','request.role');
  578:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
  579: 
  580:     my $bodytag = &Apache::loncommon::bodytag('',$function,'topmargin="0" marginheight="0"',1);
  581:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
  582:     my $to =  $Apache::lonnet::perlvar{'lonSupportEMail'};
  583:     my $from = $admin;
  584:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
  585:     my $fontcolor = &Apache::loncommon::designparm($function.'.font');
  586:     my $vlinkcolor = &Apache::loncommon::designparm($function.'.vlink');
  587:     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
  588:     my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
  589:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
  590: 
  591:     my $supportmsg = qq|
  592: Name: $ENV{'form.username'}
  593: Email: $ENV{'form.email'}
  594: Username/domain: $ENV{'form.uname'} - $ENV{'form.udom'}
  595: Tel: $ENV{'form.phone'}
  596: Course Information: $ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}
  597: Subject: $ENV{'form.subject'}
  598: Description: $ENV{'form.description'}
  599: URL: $ENV{'form.sourceurl'}
  600: Date/Time: $reporttime
  601: 
  602:     |;
  603:     my $descrip = $ENV{'form.description'};
  604:     $descrip =~ s#\n#<br />#g;
  605:     my $displaymsg = qq|
  606: <font color="$fontcolor">Name:</font><font color="$vlinkcolor"> $ENV{'form.username'}</font><br />
  607: <font color="$fontcolor">Email: </font><font color="$vlinkcolor">$ENV{'form.email'}</font><br />
  608: <font color="$fontcolor">Username/domain: </font><font color="$vlinkcolor">$ENV{'form.uname'} - $ENV{'form.udom'}</font><br />
  609: <font color="$fontcolor">Tel: </font><font color="$vlinkcolor">$ENV{'form.phone'}</font><br />
  610: <font color="$fontcolor">Course Information: </font><font color="$vlinkcolor">$ENV{'form.title'} - $ENV{'form.coursecode'} - section: $ENV{'form.section'}</font><br />
  611: <font color="$fontcolor">Subject: </font><font color="$vlinkcolor">$ENV{'form.subject'}</font><br />
  612: <font color="$fontcolor">Description: </font><font color="$vlinkcolor">$descrip</font><br />
  613: <font color="$fontcolor">URL: </font><font color="$vlinkcolor">$ENV{'form.sourceurl'}</font><br />
  614: <font color="$fontcolor">Date/Time: </font><font color="$vlinkcolor">$reporttime</font><br />
  615:     |;
  616:     $r->print(<<"END");
  617: <html>
  618: <head>
  619:  <title>LON-CAPA support request recorded</title>
  620: </head>
  621: $bodytag
  622: END
  623:     if ($r->uri eq '/adm/helpdesk') {
  624:         &print_header($r,$url,'process');
  625:     }
  626:     if ($to =~ m/^[^\@]+\@[^\@]+$/) {
  627:         $r->print("<h3>A support request has been sent to $to</h3>");
  628:     } else {
  629:         $to = $admin;
  630:         if ($to =~ m/^[^\@]+\@[^\@]+$/) {
  631:             $r->print("<h3>A support request has been sent to $to</h3>");
  632: END
  633:         } else {
  634:             $r->print(<<END);
  635:  <h3>Warning: Problem with support e-mail address</h3>
  636: 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. 
  637: END
  638:             $to = 'helpdesk@lon-capa.org';
  639:         }
  640:     }
  641:     if (defined($ENV{'form.email'})) {
  642:         if ($ENV{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
  643:             $from = $ENV{'form.email'};
  644:         }
  645:     }
  646: 
  647:     my $subject = $ENV{'form.subject'};
  648:     $subject =~ s#(`)#'#g;
  649:     $subject =~ s#\$#\(\$\)#g;
  650:     $supportmsg =~ s#(`)#'#g;
  651:     $supportmsg =~ s#\$#\(\$\)#g;
  652:     $displaymsg =~ s#(`)#'#g;
  653:     $displaymsg =~ s#\$#\(\$\)#g;
  654:     my $fname;
  655: 
  656:     my $attachmentpath = '';
  657:     my $attachmentsize = '';
  658:     if (defined($ENV{'user.name'})) {
  659:         if ($ENV{'form.screenshot.filename'}) {
  660:             $attachmentsize = length($ENV{'form.screenshot'});
  661:             if ($attachmentsize > 131072) {
  662:                 $displaymsg .= "<br />The uploaded screenshot file ($attachmentsize bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.";
  663:             } else {
  664:                 $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
  665:             }
  666:         }
  667:     }
  668: 
  669:     if ($attachmentpath =~ m-/([^/]+)$-) {
  670:         $fname = $1;
  671:         $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'}";
  672:         $supportmsg .= "\n";
  673:         foreach (@envvars) {
  674:             $supportmsg .= "$_: $ENV{$_}\n";
  675:         }
  676:     }
  677:  
  678:     my $msg = MIME::Lite->new(
  679:                  From    => $from,
  680:                  To      => $to,
  681:                  Subject => $subject,
  682:                  Type    =>'TEXT',
  683:                  Data    => $supportmsg,
  684:                  );
  685: 
  686:     if ($attachmentpath) {
  687:         my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
  688:         $msg->attach(Type     => $type,
  689:                      Path     => $attachmentpath,
  690:                      Filename => $fname
  691:                      );
  692: 
  693:     } else {
  694:         my $envdata = '';
  695:         foreach (@envvars) {
  696:             $envdata .= "$_: $ENV{$_}\n";
  697:         }
  698:         foreach (@loncvars) {
  699:             $envdata .= "$_: $ENV{$_}\n";
  700:         }
  701:         $msg->attach(Type => 'TEXT',
  702:                      Data => $envdata);
  703:     }
  704: 
  705: ### Send it:
  706:     # ->send can cause an sh launch which can pass all of %ENV along
  707:     # which can be to large for /bin/sh's little mind
  708:     my %oldENV=%ENV;
  709:     undef(%ENV);
  710:     $msg->send('sendmail');
  711:     %ENV=%oldENV;
  712:     undef(%oldENV);
  713: 
  714:     if ($attachmentpath =~ m#$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+#) {
  715:         unlink($attachmentpath);
  716:     }
  717:     $r->print(qq|
  718:  <b>Your support request contained the following information</b>:<br /><br />
  719:  <table width="580" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  720:   <tr>
  721:    <td>
  722:     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  723:      <tr>
  724:       <td>
  725:        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
  726:         <tr>
  727:          <td>
  728:           <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
  729:            <tr>
  730:             <td width="140" bgcolor="$tablecolor">
  731:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  732:               <tr>
  733:                <td align="right"><b>Information supplied</b>
  734:                </td>
  735:               </tr>
  736:              </table>
  737:             </td>
  738:             <td width="100%" valign="top">
  739:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  740:               <tr>
  741:                <td>$displaymsg</td>
  742:               </tr>
  743:              </table>
  744:             </td>
  745:            </tr>
  746:            <tr>
  747:             <td width="100%" colspan="2" bgcolor="#000000">
  748:              <img src="/adm/lonMisc/blackdot.gif" /><br />
  749:             </td>
  750:            </tr>
  751:            <tr>
  752:             <td width="140" bgcolor="$tablecolor">
  753:              <table width="140" border="0" cellpadding="8" cellspacing="0">
  754:               <tr>
  755:                <td align="right"><b>Additional information recorded</b>
  756:                </td>
  757:               </tr>
  758:              </table>
  759:             </td>
  760:             <td width="100%" valign="top">
  761:              <table width="100%" border="0" cellpadding="8" cellspacing="0">
  762:               <tr>
  763:                <td>
  764:     |);
  765:     foreach (@envvars) {
  766:         unless($ENV{$_} eq '') { 
  767:             $r->print("$_:&nbsp;<font color='$vlinkcolor'>$ENV{$_}</font>, ");
  768:         }
  769:     }
  770:     $r->print("
  771:                </td>
  772:               </tr>
  773:              </table>
  774:             </td>
  775:            </tr>
  776:           </table>
  777:          </td>
  778:         </tr>
  779:        </table>
  780:       </td>
  781:      </tr>
  782:     </table>
  783:    </td>
  784:   </tr>
  785:  </table>
  786: </body>
  787: </html>
  788:     ");
  789: }
  790: 
  791: sub print_header {
  792:     my ($r,$origurl,$action) = @_;
  793:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  794:     my $tablecolor = '#EEEE99';
  795:     my ($component_url);
  796:     my $helpdesk_link = '<a href="javascript:validate()">';
  797:     if ($action eq 'process') {
  798:         $helpdesk_link = '<a href="/adm/helpdesk">';
  799:     }
  800:     my %lt = &Apache::lonlocal::texthash (
  801:                                            login => 'Log-in help',
  802:                                            ask   => 'Ask helpdesk',
  803:                                            getst => 'Getting started guide',
  804:                                            back =>  'Back to last location'
  805:                                          );  
  806:     $r->print(<<END);
  807: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55">   <tr height="50">    <td width='5'>&nbsp;</td>
  808:    <td>
  809:     <fieldset><legend><img src="$location/lonIcons/minilogo.gif" height='20' width='29' valign='bottom' />&nbsp;&nbsp;<b><font size="+1">LON-CAPA help/support</font></b></legend>
  810:  <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
  811:   <tr>
  812:    <td>
  813:     <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  814:      <tr>
  815:       <td>
  816:        <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ffffff">
  817:         <tr>
  818:          <td>
  819:           <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff">
  820:            <tr bgcolor="$tablecolor">
  821:             <td align="center"><img src="$location/help/gif/smallHelp.gif" border="0" alt="(Login help)" valign="middle" />&nbsp;<b><a href="/adm/loginproblems.html">$lt{'login'}</a></td>
  822:             <td align="center">&nbsp;<b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="(Ask helpdesk)" valign="middle" />&nbsp;$lt{'ask'}</a></b>&nbsp;</td>
  823:             <td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>
  824:             <td align="center">&nbsp;<b><a href="$origurl" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="(Back to last location)" valign="middle" />&nbsp;$lt{'back'}</a></b>&nbsp;</td>
  825:            </tr>
  826:           </table>
  827:          </td>
  828:         </tr>
  829:        </table>
  830:       </td>
  831:      </tr>
  832:     </table>
  833:    </td>
  834:   </tr>
  835:  </table>
  836: </fieldset>
  837:   </td>
  838:   <td width='5'>&nbsp;</td>
  839:  </tr>
  840:  <tr height='5'>
  841:   <td colspan='3' height='5'>&nbsp;</td>
  842:  </tr>
  843: END
  844:     unless ($action eq 'process') {
  845:         $r->print('
  846:  <tr>
  847:   <td colspan="3">'.&mt('
  848: Please read the "Log-in help" and "Getting started guide" if you can not log-in').'.  '.&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('Note').':</b> '.&mt('Student questions about course content should be directed to the course instructor').'.</font><br /><br />
  849:   </td>
  850:  </tr>');
  851:     }
  852:     $r->print('
  853: </table>');
  854:     return;
  855: }
  856: 
  857: sub retrieve_instcodes {
  858:     my ($coursecodes,$codedom,$totcodes) = @_;
  859:     my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.');
  860:     foreach my $course (keys %courses) {
  861:         if ($courses{$course} =~ m/^[^:]*:([^:]+)/) {
  862:             $$coursecodes{$course} = &Apache::lonnet::unescape($1);
  863:             $totcodes ++;
  864:         }
  865:     }
  866:     return $totcodes;
  867: }
  868: 
  869: sub build_code_selections {
  870:     my ($codes,$codetitles,$cat_titles,$cat_order,$idlist,$idnums,$idlist_titles) = @_;
  871:     my %idarrays = ();
  872:     for (my $i=1; $i<@{$codetitles}; $i++) {
  873:         %{$idarrays{$$codetitles[$i]}} = ();
  874:     }
  875:     foreach my $cid (sort keys %{$codes}) {
  876:         &recurse_list($cid,$codetitles,$codes,0,\%idarrays);
  877:     }
  878:     for (my $num=0; $num<@{$codetitles}; $num++) {
  879:         if ($num == 0) {
  880:             my @contents = ();
  881:             my @contents_titles = ();
  882:             &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[0]}},\@contents);
  883:             if (defined($$cat_titles{$$codetitles[0]})) {
  884:                 foreach (@contents) {
  885:                     push @contents_titles, $$cat_titles{$$codetitles[0]}{$_};
  886:                 }
  887:             }
  888:             $$idlist{$$codetitles[0]} = join('","',@contents);
  889:             $$idnums{$$codetitles[0]} = scalar(@contents);
  890:             if (defined($$cat_titles{$$codetitles[0]})) {
  891:                 $$idlist_titles{$$codetitles[0]} = join('","',@contents_titles);
  892:             }
  893:         } elsif ($num == 1) {
  894:             %{$$idlist{$$codetitles[1]}} = ();
  895:             %{$$idlist_titles{$$codetitles[1]}} = ();
  896:             foreach my $key_a (keys %{$idarrays{$$codetitles[1]}}) {
  897:                 my @sorted_a = ();
  898:                 my @sorted_a_titles = ();
  899:                 &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[1]}{$key_a}},\@sorted_a);
  900:                 if (defined($$cat_titles{$$codetitles[1]})) {
  901:                     foreach (@sorted_a) {
  902:                         push @sorted_a_titles, $$cat_titles{$$codetitles[1]}{$_};
  903:                     }
  904:                 }
  905:                 $$idlist{$$codetitles[1]}{$key_a} = join('","',@sorted_a);
  906:                 $$idnums{$$codetitles[1]}{$key_a} = scalar(@sorted_a);
  907:                 if (defined($$cat_titles{$$codetitles[1]})) {
  908:                     $$idlist_titles{$$codetitles[1]}{$key_a} = join('","',@sorted_a_titles);
  909:                 }
  910:             }
  911:         } elsif ($num == 2) {
  912:             %{$$idlist{$$codetitles[2]}} = ();
  913:             %{$$idlist_titles{$$codetitles[2]}} = ();
  914:             foreach my $key_a (keys %{$idarrays{$$codetitles[2]}}) {
  915:                 %{$$idlist{$$codetitles[2]}{$key_a}} = ();
  916:                 %{$$idlist_titles{$$codetitles[2]}{$key_a}} = ();
  917:                 foreach my $key_b (keys %{$idarrays{$$codetitles[2]}{$key_a}}) {
  918:                     my @sorted_b = ();
  919:                     my @sorted_b_titles = ();
  920:                     &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[2]}{$key_a}{$key_b}},\@sorted_b);
  921:                     if (defined($$cat_titles{$$codetitles[1]})) {
  922:                         foreach (@sorted_b) {
  923:                             push @sorted_b_titles, $$cat_titles{$$codetitles[1]}{$_};
  924:                         }
  925:                     }
  926:                     $$idlist{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b);
  927:                     $$idnums{$$codetitles[2]}{$key_a}{$key_b} = scalar(@sorted_b);
  928:                     if (defined($$cat_titles{$$codetitles[2]})) {
  929:                         $$idlist_titles{$$codetitles[2]}{$key_a}{$key_b} = join('","',@sorted_b_titles);
  930:                     }
  931:                 }
  932:             }
  933:         } elsif ($num == 3) {
  934:             %{$$idlist{$$codetitles[3]}} = ();
  935:             foreach my $key_a (keys %{$idarrays{$$codetitles[3]}}) {
  936:                 %{$$idlist{$$codetitles[3]}{$key_a}} = ();
  937:                 foreach my $key_b (keys %{$idarrays{$$codetitles[3]}{$key_a}}) {
  938:                     %{$$idlist{$$codetitles[3]}{$key_a}{$key_b}} = ();
  939:                     foreach my $key_c (keys %{$idarrays{$$codetitles[3]}{$key_a}{$key_b}}) {
  940:                         my @sorted_c = ();
  941:                         &sort_cats($num,$cat_order,$codetitles,\@{$idarrays{$$codetitles[3]}{$key_a}{$key_b}{$key_c}},\@sorted_c);
  942:                         $$idlist{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = join('","',@sorted_c);
  943:                         $$idnums{$$codetitles[3]}{$key_a}{$key_b}{$key_c} = scalar(@sorted_c);
  944:                     }
  945:                 }
  946:             }
  947:         } elsif ($num == 4) {
  948:             %{$$idlist{$$codetitles[4]}} = ();
  949:             foreach my $key_a (keys %{$idarrays{$$codetitles[4]}}) {
  950:                 %{$$idlist{$$codetitles[4]}{$key_a}} = ();
  951:                 foreach my $key_b (keys %{$idarrays{$$codetitles[4]}{$key_a}}) {
  952:                     %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}} = ();
  953:                     foreach my $key_c (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}}) {
  954:                         %{$$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}} = ();
  955:                         foreach my $key_d (keys %{$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}}) {
  956:                             my @sorted_d = ();
  957:                             &sort_cats($num,$cat_order,$codetitles,$idarrays{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d},\@sorted_d);
  958:                             $$idlist{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = join('","',@sorted_d);
  959:                             $$idnums{$$codetitles[4]}{$key_a}{$key_b}{$key_c}{$key_d} = scalar(@sorted_d);
  960:                         }
  961:                     }
  962:                 }
  963:             }
  964:         }
  965:     }
  966: }
  967: 
  968: sub sort_cats {
  969:     my ($num,$cat_order,$codetitles,$idsarrayref,$sorted) = @_;
  970:     my @unsorted = @{$idsarrayref};
  971:     if (defined($$cat_order{$$codetitles[$num]})) {
  972:         foreach (@{$$cat_order{$$codetitles[$num]}}) {
  973:             if (grep/^$_$/,@unsorted) {
  974:                 push @{$sorted}, $_;
  975:             }
  976:         }
  977:     } else {
  978:         @{$sorted} = sort (@unsorted);
  979:     }
  980: }
  981: 
  982: 
  983: sub recurse_list {
  984:     my ($cid,$codetitles,$codes,$num,$idarrays) = @_;
  985:     if ($num == 0) {
  986:         if (!grep/^$$codes{$cid}{$$codetitles[0]}$/,@{$$idarrays{$$codetitles[0]}}) {
  987:             push @{$$idarrays{$$codetitles[0]}}, $$codes{$cid}{$$codetitles[0]};
  988:         }
  989:     } elsif ($num == 1) {
  990:         if (defined($$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}})) {
  991:             if (!grep/^$$codes{$cid}{$$codetitles[1]}$/,@{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}) {
  992:                 push @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}}, $$codes{$cid}{$$codetitles[1]};
  993:             }
  994:         } else {
  995:             @{$$idarrays{$$codetitles[1]}{$$codes{$cid}{$$codetitles[0]}}} = ("$$codes{$cid}{$$codetitles[1]}");
  996:         }
  997:     } elsif ($num == 2) {
  998:         if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}})) {
  999:             if (defined($$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
 1000:                 if (!grep/^$$codes{$cid}{$$codetitles[2]}$/,@{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}) {
 1001:                     push @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}}, $$codes{$cid}{$$codetitles[2]};
 1002:                 }
 1003:             } else {
 1004:                 @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
 1005:             }
 1006:         } else {
 1007:             %{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}} = ();
 1008:             @{$$idarrays{$$codetitles[2]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ("$$codes{$cid}{$$codetitles[2]}");
 1009:         }
 1010:     } elsif ($num == 3) {
 1011:         if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}})) {
 1012:             if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
 1013:                 if (defined($$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
 1014:                     if (!grep/^$$codes{$cid}{$$codetitles[3]}$/,@{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}) {
 1015:                         push @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}}, $$codes{$cid}{$$codetitles[3]};
 1016:                     }
 1017:                 } else {
 1018:                     @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
 1019:                 }
 1020:             } else {
 1021:                 %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
 1022:                 @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
 1023:             }
 1024:         } else {
 1025:             %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}} = ();
 1026:             %{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
 1027:             @{$$idarrays{$$codetitles[3]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ("$$codes{$cid}{$$codetitles[3]}");
 1028:         }
 1029:     } elsif ($num == 4) {
 1030:         if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}})) {
 1031:             if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}})) {
 1032:                 if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}})) {
 1033:                     if (defined($$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}})) {
 1034:                         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]}}}) {
 1035:                             push @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}}, $$codes{$cid}{$$codetitles[4]};
 1036:                         }
 1037:                     } else {
 1038:                         @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
 1039:                     }
 1040:                 } else {
 1041:                     %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
 1042:                     @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
 1043:                 }
 1044:             } else {
 1045:                 %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
 1046:                 %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
 1047:                 @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[4]}");
 1048:             }
 1049:         } else {
 1050:             %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}} = ();
 1051:             %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}} = ();
 1052:             %{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[2]}}} = ();
 1053:             @{$$idarrays{$$codetitles[4]}{$$codes{$cid}{$$codetitles[0]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[1]}}{$$codes{$cid}{$$codetitles[3]}}} = ("$$codes{$cid}{$$codetitles[3]}");
 1054:         }
 1055:     }
 1056:     $num ++;
 1057:     if ($num <@{$codetitles}) {
 1058:         &recurse_list($cid,$codetitles,$codes,$num,$idarrays);
 1059:     }
 1060: }
 1061: 
 1062: sub javascript_code_selections {
 1063:     my ($numcats,$script_tag,$idlist,$idnums,$idlist_titles,$codetitles) = @_;
 1064:     my $numtitles = @{$codetitles};
 1065:     my @seltitles = (); 
 1066:     for (my $j=0; $j<$numtitles; $j++) {
 1067:         $seltitles[$j] = 'id'.$$codetitles[$j];
 1068:     }
 1069:     my $seltitle_str = join('","',@seltitles);
 1070:     $$script_tag .= <<END;
 1071: function courseSet(caller) {
 1072:     var ids = new Array ("$seltitle_str");
 1073:     var formitems = new Array ($numtitles);
 1074:     var idyr = document.forms.logproblem.Year.selectedIndex
 1075:     var idsem  = document.forms.logproblem.Semester.selectedIndex
 1076:     var iddept = document.forms.logproblem.Department.selectedIndex
 1077:     var idclass = document.forms.logproblem.Number.selectedIndex
 1078:     var idyears = new Array("$$idlist{$$codetitles[0]}");
 1079:     var idsems = new Array ($$idnums{$$codetitles[0]});
 1080:     var idsemlongs = new Array ($$idnums{$$codetitles[0]});
 1081:     var idcodes = new Array ($$idnums{$$codetitles[0]});
 1082:     var idcourses = new Array ($$idnums{$$codetitles[0]});
 1083: END
 1084:     my @sort_a = split/","/,$$idlist{$$codetitles[0]}; 
 1085:     for (my $j=0; $j<@sort_a; $j++) {
 1086:         $$script_tag .= qq| idsems[$j] = new Array("$$idlist{$$codetitles[1]}{$sort_a[$j]}")\n|;
 1087:         $$script_tag .= qq| idsemlongs[$j] = new Array("$$idlist_titles{$$codetitles[1]}{$sort_a[$j]}")\n|;
 1088:         $$script_tag .= qq| idcodes[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
 1089:         $$script_tag .= qq| idcourses[$j] = new Array($$idnums{$$codetitles[1]}{$sort_a[$j]})\n|;
 1090:         my @sort_b = split/","/,$$idlist{$$codetitles[1]}{$sort_a[$j]};
 1091:         for (my $k=0; $k<@sort_b; $k++) {
 1092:             my $idcode_entry = $$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
 1093:             $$script_tag .= qq| idcodes[$j][$k] = new Array("$idcode_entry")\n|;
 1094:             $$script_tag .= qq| idcourses[$j][$k] = new Array($$idnums{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]})\n|;
 1095:             my @sort_c = split/","/,$$idlist{$$codetitles[2]}{$sort_a[$j]}{$sort_b[$k]};
 1096:             for (my $l=0; $l<@sort_c; $l++) {
 1097:                 my $idcourse_entry = $$idlist{$$codetitles[3]}{$sort_a[$j]}{$sort_b[$k]}{$sort_c[$l]};
 1098:                 $$script_tag .= qq| idcourses[$j][$k][$l] = new Array("$idcourse_entry")\n|;
 1099:             }
 1100:         }
 1101:     }
 1102:     $$script_tag .= (<<END_OF_BLOCK);
 1103:  if (caller == "Year") {
 1104:    document.forms.logproblem.Department.length = 0
 1105:    document.forms.logproblem.Number.length = 0
 1106:    document.forms.logproblem.Department.options[0] = new Option("<-Pick Semester.","-1",true,true)
 1107:    document.forms.logproblem.Number.options[0] = new Option("<-Pick Department","-1",true,true)
 1108:    if (idyr == 0) {
 1109:     document.forms.logproblem.Semester.length = 0
 1110:     document.forms.logproblem.Semester.options[0] = new Option("<-Pick Year","-1",true,true)
 1111:    }
 1112:    else {
 1113:     document.forms.logproblem.Semester.length = 0
 1114:     document.forms.logproblem.Semester.options[0] = new Option("Select","-1",true,true)
 1115:     for (var i=0; i<idsems[idyr-1].length; i++) {
 1116:       document.forms.logproblem.Semester.options[i+1] = new Option(idsemlongs[idyr-1][i],idsems[idyr-1][i],false,false)
 1117:     }
 1118:    }
 1119:    document.forms.logproblem.Semester.selectedIndex = 0;
 1120:  }
 1121:  if (caller == "Semester") {
 1122:    document.forms.logproblem.Department.length = 0
 1123:    document.forms.logproblem.Number.length = 0
 1124:    document.forms.logproblem.Number.options[0] = new Option("<-Pick Department.","-1",true,true)
 1125:    if (idsem == 0) {
 1126:      document.forms.logproblem.Department.options[0] = new Option("<-Pick Semester.","-1",true,true)
 1127:      document.forms.logproblem.Department.options[0] = new Option("<-Pick Semester","-1",true,true)
 1128:    }
 1129:    else {
 1130:     document.forms.logproblem.Department.options[0] = new Option("Select","-1",true,true)    
 1131:     for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
 1132:       document.forms.logproblem.Department.options[i+1] = new Option(idcodes[idyr-1][idsem-1][i],idcodes[idyr-1][idsem-1][i],false,false)
 1133:     }
 1134:    }
 1135:    document.forms.logproblem.Department.selectedIndex = 0
 1136:  }
 1137:  if (caller == "Department") {
 1138:    document.forms.logproblem.Number.length = 0
 1139:    if (iddept == 0) {
 1140:      document.forms.logproblem.Number.options[0] = new Option("<-Pick Department.","-1",true,true)
 1141:    }
 1142:    else {
 1143:     document.forms.logproblem.Number.options[0] = new Option("Select","-1",true,true)
 1144:     for (var i=0; i<idcourses[idyr-1][idsem-1][iddept-1].length; i++) {
 1145:       document.forms.logproblem.Number.options[i+1] = new Option(idcourses[idyr-1][idsem-1][iddept-1][i],idcourses[idyr-1][idsem-1][iddept-1][i],false,false)
 1146:     }
 1147:    }
 1148:    document.forms.logproblem.Number.selectedIndex = 0
 1149:  }
 1150: }
 1151: END_OF_BLOCK
 1152: }
 1153: 
 1154: 1;

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