File:  [LON-CAPA] / loncom / interface / coursecatalog.pm
Revision 1.31: download - view: text, annotated - select for diffs
Fri Jun 20 13:45:12 2008 UTC (16 years ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Localization:
Optimized &mt() calls for "Note for students"

    1: # The LearningOnline Network with CAPA
    2: # Handler for displaying the course catalog interface
    3: #
    4: # $Id: coursecatalog.pm,v 1.31 2008/06/20 13:45:12 bisitz Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::coursecatalog;
   30: 
   31: use strict;
   32: use lib qw(/home/httpd/lib/perl);
   33: use Apache::Constants qw(:common);
   34: use Apache::loncommon;
   35: use Apache::lonhtmlcommon;
   36: use Apache::lonnet;
   37: use Apache::lonlocal;
   38: use Apache::courseclassifier;
   39: use Apache::lonacc;
   40: use LONCAPA;
   41: 
   42: sub handler {
   43:     my ($r) = @_;
   44:     &Apache::loncommon::content_type($r,'text/html');
   45:     $r->send_http_header;
   46:     if ($r->header_only) {
   47:         return OK;
   48:     }
   49:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   50:     my $lonidsdir=$r->dir_config('lonIDsDir');
   51:     if ($handle ne '') {
   52:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   53:     }
   54:     &Apache::lonacc::get_posted_cgi($r);
   55:     &Apache::lonlocal::get_language_handle($r);
   56:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']);
   57: 
   58:     my $codedom = &Apache::lonnet::default_login_domain();
   59: 
   60:     if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) { 
   61:         $codedom = $env{'user.domain'};
   62:         if ($env{'request.role.domain'} ne '') {
   63:             $codedom = $env{'request.role.domain'};
   64:         }
   65:     }
   66:     my $formname = 'coursecatalog';
   67:     if ($env{'form.showdom'} ne '') {
   68:         if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
   69:             $codedom = $env{'form.showdom'};
   70:         }
   71:     }
   72:     my $domdesc = &Apache::lonnet::domain($codedom,'description');
   73:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   74:     if ($env{'form.coursenum'} ne '' && &user_is_known()) {
   75:         &course_details($r,$codedom,$formname,$domdesc);
   76:     } else {
   77:         my $catlinks = &category_breadcrumbs($codedom);
   78:         my $catjs = <<"ENDSCRIPT";
   79: 
   80: function setCatDepth(depth) {
   81:     document.coursecats.catalog_maxdepth.value = depth;
   82:     document.coursecats.submit();
   83:     return;
   84: }
   85: 
   86: ENDSCRIPT
   87:         my $numtitles;
   88:         if ($env{'form.currcat_0'} eq 'instcode::0') {
   89:             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
   90:                                                    $catlinks,$catjs);
   91:             if ($env{'form.state'} eq 'listing') {
   92:                 $r->print(&print_course_listing($codedom,$numtitles));
   93:             }
   94:         } else {
   95:             my (%add_entries);
   96:             $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
   97:             &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
   98:             if ($env{'form.currcat_0'} ne '') {
   99:                 $r->print(&print_course_listing($codedom));
  100:             }
  101:         }
  102:     }
  103:     $r->print(&Apache::loncommon::end_page());
  104:     return OK;
  105: }
  106: 
  107: sub course_details {
  108:     my ($r,$codedom,$formname,$domdesc) = @_;
  109:     my $output;
  110:     my %add_entries = (topmargin    => "0",
  111:                        marginheight => "0",);
  112:     my $start_page =
  113:         &Apache::loncommon::start_page('Course Catalog','',
  114:                                            {
  115:                                              'add_entries' => \%add_entries,
  116:                                              'no_inline_link'   => 1,});
  117:     $r->print($start_page);
  118:     if ($env{'form.numtitles'} > 0) {
  119:         &Apache::lonhtmlcommon::add_breadcrumb
  120:                 ({href=>"/adm/coursecatalog",
  121:                   text=>"Select courses"});
  122:     }
  123:     &Apache::lonhtmlcommon::add_breadcrumb
  124:              ({href=>"javascript:document.$formname.submit()",
  125:               text=>"Course listing"},
  126:              {text=>"Course details"});
  127:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
  128:     $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
  129:               '<form name="'.$formname.'" method="post">'.
  130:               &print_course_listing($codedom).'<br /><br />');
  131:     $r->print('<a href = "javascript:document.coursecatalog.submit()">'.
  132:               &mt('Back to course listing').'</a>'.
  133:               '<input type="hidden" name="sortby" value="'.
  134:               $env{'form.sortby'}.'" />'.
  135:               '<input type="hidden" name="state" value="listing" /></form>');
  136: }
  137: 
  138: sub instcode_course_selector {
  139:     my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
  140:     my %coursecodes = ();
  141:     my %codes = ();
  142:     my @codetitles = ();
  143:     my %cat_titles = ();
  144:     my %cat_order = ();
  145:     my %idlist = ();
  146:     my %idnums = ();
  147:     my %idlist_titles = ();
  148:     my %by_year;
  149:     my %by_sem;
  150:     my %by_dept;
  151:     my %cat_items;
  152:     my $caller = 'global';
  153:     my $format_reply;
  154:     my $totcodes = 0;
  155:     my $jscript = '';
  156:     my ($numtitles,$lasttitle);
  157:     my %add_entries = (topmargin    => "0",
  158:                        marginheight => "0",);
  159:     my $js;
  160:     $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
  161:     if ($totcodes > 0) {
  162:         $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
  163:         if ($format_reply eq 'ok') {
  164:             my $numtypes = @codetitles;
  165:             &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
  166:             my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
  167:             my $longtitles_str = join('","',@{$longtitles});
  168:             my $allidlist = $idlist{$codetitles[0]};
  169:             $numtitles = @codetitles;
  170:             $lasttitle = $numtitles;
  171:             if ($numtitles > 4) {
  172:                 $lasttitle = 4;
  173:             }
  174:             if ($numtitles == 0) {
  175:                 if (!defined($env{'form.state'})) {
  176:                     $env{'form.state'} = 'listing';
  177:                 }
  178:             } else {
  179:                 my @data = ('top');
  180:                 for (my $k=0; $k<$lasttitle; $k++) {
  181:                     my $cat = $codetitles[$k];
  182:                     my $level = 1;
  183:                     $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
  184:                 }
  185:                 $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
  186:                 $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
  187:                 if ($env{'form.state'} eq 'listing') {
  188:                     $jscript .= '
  189: function setElements() {
  190: ';
  191:                     for (my $i=0; $i<@codetitles-1; $i++) {
  192:                         if ($env{'form.'.$codetitles[$i]} != -1) {
  193:                             $jscript .= '
  194:     for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
  195:         if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
  196:             document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
  197:         }
  198:     }
  199: ';
  200:                         }
  201:                     }
  202:                     $jscript .= '   courseSet()'."\n";
  203:                     if ($env{'form.'.$codetitles[-1]} != -1) {
  204:                         $jscript .= '
  205:     for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
  206:         if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
  207:             document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
  208:         }
  209:     }
  210: ';
  211:                     }
  212:                     $jscript .= '}';
  213:                 }
  214:             }
  215:             if ($env{'form.state'} eq 'listing') {
  216:                 $jscript .= qq|
  217: function changeSort(caller) {
  218:     document.$formname.sortby.value = caller;
  219:     document.$formname.submit();
  220: }
  221: function setCourseId(caller) {
  222:    document.$formname.coursenum.value = caller;
  223:    document.$formname.submit(); 
  224: }\n|;
  225:             }
  226:         }
  227:         $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
  228:               '</script>';
  229:         if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
  230:             $add_entries{'onLoad'} = 'setElements()';
  231:         }
  232:         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
  233:         my $cat_maxdepth = $env{'form.catalog_maxdepth'};
  234:         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
  235:                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
  236:                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
  237:                   '<input type="hidden" name="currcat_0" value="instcode::0" />');
  238:         if ($numtitles > 0) {
  239:             $r->print('<br /><b>'.&mt('Choose which course(s) to list.').'</b><br />');
  240:             $r->print('<table><tr>');
  241:             for (my $k=0; $k<$lasttitle-1; $k++) {
  242:                 my (@items,@unsorted);
  243:                 if (ref($cat_items{$codetitles[$k]}) eq 'ARRAY') {
  244:                     @unsorted = @{$cat_items{$codetitles[$k]}};
  245:                 }
  246:                 &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
  247:                 my @longitems;
  248:                 if (defined($cat_titles{$codetitles[$k]})) {
  249:                     foreach my $item (@items) {
  250:                         push(@longitems,$cat_titles{$codetitles[$k]}{$item});
  251:                     }
  252:                 } else {
  253:                     @longitems = @items;
  254:                 }
  255:                 $r->print('<td align="center">'.$codetitles[$k].'<br />'."\n".
  256:                           '<select name="'.$codetitles[$k].'" onChange="courseSet()"');
  257:                 $r->print('>'."\n".'<option value="0" />All'."\n");
  258:                 for (my $i=0; $i<@items; $i++) {
  259:                     if ($longitems[$i] eq '') {
  260:                         $longitems[$i] = $items[$i];
  261:                     }
  262:                     $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
  263:                 }
  264:                 $r->print('</select></td>');
  265:             }
  266:             $r->print('<td align="center">'.$codetitles[$lasttitle-1].'<br />'."\n".
  267:                       '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
  268:                       '<option value="0">All'."\n".
  269:                       '</option>'."\n".'</select>'."\n".
  270:                  '</td>'
  271:                 );
  272:             my $show_selfenroll_status;
  273:             if ($env{'form.showselfenroll'}) {
  274:                 $show_selfenroll_status = 'checked="checked" ';
  275:             }
  276:             if (&user_is_dc($codedom)) {
  277:                 my $showdetails_status;
  278:                 if ($env{'form.showdetails'}) {
  279:                     $showdetails_status = 'checked="checked" ';
  280:                 }
  281:                 $r->print('<td></td><td><label><input type="checkbox" name="showdetails" value="1" '.$showdetails_status.'/>'.&mt('Show full details for each course (DC only)').'</label><br /><label><input type="checkbox" name="showselfenroll" value="1" '.$show_selfenroll_status.'/>'.&mt('Only show courses which allow self-enrollment').'</label></td>');
  282:             } else {
  283:                 $r->print('<td></td><td><br /><label><input type="checkbox" name="showselfenroll" value="1" '.$show_selfenroll_status.'/>'.&mt('Only show courses which allow self-enrollment').'</label></td>');
  284:             }
  285:             $r->print('</tr></table>');
  286:             if ($numtitles > 4) {
  287:                 $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
  288:                 '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
  289:             }
  290:             $r->print('<br />');
  291:         }
  292:         $r->print('<input type="hidden" name="coursenum" value="" /><input type="hidden" name="sortby" value="" /><input type="hidden" name="state" value="listing" /><input type="hidden" name="form.currcat_0" value="instcode::0" />');
  293:         if ($numtitles > 0) {
  294:             $r->print('<input type="submit" name="catalogfilter" value="'.&mt('Display courses').'" />');
  295:         }
  296:         $r->print('<input type="hidden" name="numtitles" value="'.
  297:                   $numtitles.'" /></form>');
  298:         if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
  299:             $r->print('<br />');
  300:         }
  301:     } else {
  302:         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
  303:         my $cat_maxdepth = $env{'form.catalog_maxdepth'};
  304:         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
  305:                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
  306:                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
  307:                   '<input type="hidden" name="currcat_0" value="instcode::0" />');
  308:         $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
  309:     }
  310:     return $numtitles;
  311: }
  312: 
  313: sub cat_header {
  314:     my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles) = @_;
  315:     my $start_page =
  316:         &Apache::loncommon::start_page('Course Catalog',$js,
  317:                                        {
  318:                                          'add_entries' => $add_entries,
  319:                                          'no_inline_link'   => 1,});
  320:     $r->print($start_page);
  321:     if ($env{'form.state'} eq 'listing') {
  322:         if ($numtitles > 0) {
  323:             &Apache::lonhtmlcommon::add_breadcrumb
  324:                 ({href=>"/adm/coursecatalog",
  325:                   text=>"Select courses"},
  326:                  {text=>"Course listing"});
  327:         } else {
  328:             &Apache::lonhtmlcommon::add_breadcrumb
  329:             ({text=>"Course listing"});
  330:         }
  331:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
  332:     } else {
  333:         &Apache::lonhtmlcommon::add_breadcrumb
  334:         ({href=>"/adm/coursecatalog",
  335:           text=>"Select courses"});
  336:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
  337:     }
  338:     $r->print('<table border="0"><tr>'.
  339:               '<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
  340:               '<td><b>'.&mt('Domain:').'</b></td><td>'.
  341:               &Apache::loncommon::select_dom_form($codedom,'showdom','',1).
  342: 	      '&nbsp;<input type="submit" name="godom" value="Go"></td></form></tr><tr>'.
  343: 	      '<form name="coursecats" method="post" action="/adm/coursecatalog">'.
  344:               $catlinks.'</form></tr></table>');
  345:     return;
  346: }
  347: 
  348: sub category_breadcrumbs {
  349:     my ($dom) = @_;
  350:     my %domconfig =
  351:         &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
  352:     my (@cats,@trails,%allitems,%idx,@jsarray);
  353:     &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails,
  354:                                            \%allitems,\%idx,\@jsarray);
  355:     my $currdepth = 0;
  356:     my $deeper = 0;
  357:     my $currcat_str;
  358:     if ($env{'form.catalog_maxdepth'} ne '') {
  359:         $currdepth = $env{'form.catalog_maxdepth'};
  360:         if ($env{'form.currcat_'.$currdepth} eq '') {
  361:             $deeper = $currdepth;
  362:         } else {
  363:             $deeper = $currdepth + 1;
  364:         }
  365:     }
  366:     $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
  367:     my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
  368:     for (my $i=0; $i<$deeper; $i++) {
  369:         $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
  370:         my ($cattitle,$shallower);
  371:         if ($i == 0) {
  372:             $cattitle = &mt('Main Categories');
  373:         } else {
  374:             $shallower = $i-1;
  375:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
  376:             $cattitle = $cat;
  377:         }
  378:         $catlinks .= '<td valign="top"><a href="javascript:setCatDepth('."'$shallower'".')">'.$cattitle.'</a>-&gt;</td>';
  379:     }
  380:     if ($deeper == 0) {
  381:         $catlinks .= '<td>'.&mt('Main Categories').':&nbsp;';
  382:         if (ref($cats[0]) eq 'ARRAY') {
  383:             if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) {
  384:                 $catlinks .= &mt('Official courses (with institutional codes)').
  385:                              '<input type="hidden" name="currcat_0" value="instcode::0">';
  386:                 $env{'form.currcat_0'} = 'instcode::0';
  387:             } else {
  388:                 $catlinks .= '<select name="currcat_0">'."\n";
  389:                 if (@{$cats[0]} > 1) {
  390:                     my $selstr;
  391:                     if ($env{'form.currcat_0'} eq '') {
  392:                         $selstr = ' selected="selected" ';
  393:                     }
  394:                     $catlinks .= '<option value=""'.$selstr.'>'.&mt('Select').'</option>'."\n";
  395:                 }
  396:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
  397:                     my $name = $cats[0][$i];
  398:                     my $item = &escape($name).'::0';
  399:                     my $selstr;
  400:                     if ($env{'form.currcat_'.$i} eq $item) {
  401:                         $selstr = ' selected="selected" ';
  402:                     }
  403:                     $catlinks .= '<option value="'.$item.'"'.$selstr.'>';
  404:                     if ($name eq 'instcode') {
  405:                         $catlinks .= &mt('Official courses (with institutional codes)');
  406:                     } else {
  407:                         $catlinks .= $name;
  408:                     }
  409:                     $catlinks .= '</option>'."\n";
  410:                 }
  411:                 $catlinks .= '</select>'."\n".
  412:                              '&nbsp;<input type="submit" name="gocats" value="Go" />';
  413:             }
  414:         } else {
  415:             $catlinks .= &mt('Official courses (with institutional codes)').
  416:                          '<input type="hidden" name="currcat_0" value="instcode::0">';
  417:             $env{'form.currcat_0'} = 'instcode::0';
  418:         }
  419:     } else {
  420:         my ($cat,$container,$depth);
  421:         if ($env{'form.currcat_'.$currdepth} eq '') {
  422:             my $shallower = $currdepth - 1;
  423:             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
  424:         } else {
  425:             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
  426:         }
  427:         my $deeper = $depth +1;
  428:         my $currcat = $cat;
  429:         if ($cat eq 'instcode') {
  430:             $currcat = &mt('Official courses (with institutional codes)');
  431:         }
  432:         $catlinks .= '<td>'.$currcat;
  433:         if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
  434:             $catlinks .= ':&nbsp;<select name="currcat_'.$deeper.'">'.
  435:                          '<option value="" selected="selected">'.&mt('Select').'</option>';
  436:             for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
  437:                 my $name = $cats[$deeper]{$cat}[$k];
  438:                 my $item = &escape($name).':'.&escape($cat).':'.$deeper;
  439:                 $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
  440:             }
  441:             $catlinks .= '</select>'."\n".
  442:                          '&nbsp;<input type="submit" name="gocats" value="Go" />';
  443:         }
  444:     }
  445:     $catlinks .= $currcat_str.'</td></tr></table></td>';
  446:     return $catlinks;
  447: }
  448: 
  449: sub user_is_dc {
  450:     my ($codedom) = @_;
  451:     if (exists($env{'user.role.dc./'.$codedom.'/'})) {
  452:         my $livedc = 1;
  453:         my $now = time;
  454:         my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
  455:         if ($start && $start>$now) { $livedc = 0; }
  456:         if ($end   && $end  <$now) { $livedc = 0; }
  457:         return $livedc;
  458:     }
  459:     return;
  460: }
  461: 
  462: sub recurse_options {
  463:     my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
  464:     if (ref($currlist) eq 'HASH') {
  465:         $level ++;
  466:         foreach my $key (sort(keys(%{$currlist}))) {
  467:             $$data[$level-1]= $key;
  468:             &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
  469:         }
  470:     } else {
  471:         $level --;
  472:         my @contents = split(/","/,$currlist);
  473:         foreach my $item (@contents) {
  474:             if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
  475:                 push(@{$cat_options->{$cat}},$item);
  476:             }
  477:             if ($level == 3) {
  478:                 if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
  479:                     push(@{$by_year->{$data->[1]}->{$currkey}},$item);                 
  480:                 }
  481:                 if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
  482:                     push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
  483:                 }
  484:                 if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
  485:                     push(@{$by_dept->{$currkey}},$item);
  486:                 }
  487: 
  488:             }
  489:         }
  490:     }
  491:     return $level;
  492: }
  493: 
  494: sub build_javascript {
  495:     my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
  496:     my @unsorted = keys(%{$by_year});
  497:     my @sorted_yrs; 
  498:     &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
  499:     my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
  500:                  'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
  501:                  'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
  502:     for (my $i=0; $i<@sorted_yrs; $i++) {
  503:         my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
  504:         $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
  505:         if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
  506:             @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
  507:             my @sorted_depts;
  508:             &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
  509:             $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
  510:             for (my $j=0; $j<@sorted_depts; $j++) {
  511:                 $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
  512:                 $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
  513:             }
  514:         }
  515:     }
  516:     @unsorted = keys(%{$by_sem});
  517:     my @sorted_sems;
  518:     &Apache::courseclassifier::sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
  519:     $output .=  'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
  520:                 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
  521:                 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
  522:     for (my $i=0; $i<@sorted_sems; $i++) {
  523:         my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
  524:         $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
  525:         if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
  526:             @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
  527:             my @sorted_depts;
  528:             &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
  529:             $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
  530:             for (my $j=0; $j<@sorted_depts; $j++) {
  531:                 $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
  532:             }
  533:         }
  534:     }
  535:     @unsorted = keys(%{$by_dept});
  536:     my @sorted_deps;
  537:     &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
  538:     $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n"; 
  539:     for (my $k=0; $k<@sorted_deps; $k++) {
  540:         $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
  541:     }
  542:     return $output;
  543: }
  544: 
  545: sub search_official_courselist {
  546:     my ($domain,$numtitles) = @_;
  547:     my $instcode;
  548:     if (defined($numtitles) && $numtitles == 0) {
  549:         $instcode = '.+';
  550:     } else {
  551:         my (%codedefaults,@code_order);
  552:         my $defaults_result = 
  553:             &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
  554:                                                     \@code_order);
  555:         if ($defaults_result eq 'ok') {
  556:             $instcode ='^';
  557:             foreach my $item (@code_order) {
  558:                 if ($env{'form.'.$item} eq '0' ) {
  559:                     $instcode .= $codedefaults{$item}; 
  560:                 } else {
  561:                     $instcode .= $env{'form.'.$item};
  562:                 }
  563:             }
  564:             $instcode .= '$';
  565:         } else {
  566:             $instcode = '.';
  567:         }
  568:     }
  569:     my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
  570:                                                 undef,undef,'Course',1,
  571:                                                 $env{'form.showselfenroll'});
  572:     return %courses;
  573: }
  574: 
  575: sub search_courselist {
  576:     my ($domain) = @_;
  577:     my $cat_maxdepth = $env{'form.catalog_maxdepth'};
  578:     my $filter = $env{'form.currcat_'.$cat_maxdepth};
  579:     if (($filter eq '') && ($cat_maxdepth > 0)) {
  580:         my $shallower = $cat_maxdepth - 1;
  581:         $filter = $env{'form.currcat_'.$shallower};
  582:     }
  583:     my %courses;
  584:     if ($filter ne '') {
  585:         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',
  586:                                                  undef,undef,'Course',1,
  587:                                                  $env{'form.showselfenroll'},$filter);
  588:     }
  589:     return %courses;
  590: }
  591: 
  592: sub print_course_listing {
  593:     my ($domain,$numtitles) = @_;
  594:     my $output;
  595:     my %courses;
  596:     my $knownuser = &user_is_known();
  597:     my $details = $env{'form.coursenum'};
  598:     if (&user_is_dc($domain)) {
  599:         if ($env{'form.showdetails'}) {
  600:             $details = 1;
  601:         }
  602:     }
  603:     if ($env{'form.coursenum'} ne '') {
  604:         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
  605:                                                  $env{'form.coursenum'},
  606:                                                  undef,undef,'Course',1);
  607:         if (keys(%courses) == 0) {
  608:             $output .= &mt('The courseID provided does not match a course in this domain.');
  609:             return $output;
  610:         }
  611:     } else {
  612:         if ($env{'form.currcat_0'} eq 'instcode::0') {
  613:             %courses = &search_official_courselist($domain,$numtitles);
  614:         } else {
  615:             %courses = &search_courselist($domain);
  616:         }
  617:         if (keys(%courses) == 0) {
  618:             $output = &mt('No courses match the criteria you selected.');
  619:             return $output;
  620:         }
  621:         if ($knownuser && !$env{'form.showdetails'}) {
  622:             $output = '<b>'.&mt('Note for students:').'</b> '
  623:                      .&mt('If you are officially enrolled in a course but the course is not listed in your LON-CAPA courses, click the "Show more details" link for the specific course and check the default access dates and/or automated enrollment settings.')
  624:                      .'<br /><br />';
  625:         }
  626:     }
  627:     my $now = time;
  628:     my %domconfig =
  629:         &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
  630:     $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig);
  631:     $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);
  632:     return $output;
  633: }
  634: 
  635: sub construct_data_table {
  636:     my ($knownuser,$courses,$details,$usersections,$now,$domconfig) = @_;
  637:     my %sortname;
  638:     if (($details eq '') || ($env{'form.showdetails'})) {
  639:         $sortname{'Code'} = 'code';
  640:         $sortname{'Title'} = 'title';
  641:         $sortname{'Owner(s)'} = 'owner';
  642:     }
  643:     my $output = &Apache::loncommon::start_data_table().
  644:                  &Apache::loncommon::start_data_table_header_row();
  645:     my @coltitles = ('Count','Code','Sections','Crosslisted','Title','Owner(s)');
  646:     if (ref($usersections) eq 'HASH') {
  647:        $coltitles[1] = 'Your Section';
  648:     }
  649:     foreach my $item (@coltitles) {
  650:         $output .= '<th>';
  651:         if (defined($sortname{$item})) {
  652:             $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
  653:         } elsif ($item eq 'Count') {
  654:             $output .= '&nbsp;&nbsp;';
  655:         } else {
  656:             $output .= &mt($item);
  657:         }
  658:         $output .= '</th>';
  659:     }
  660:     if ($knownuser) {
  661:         if ($details) {
  662:             $output .=
  663:               '<th>'.&mt('Default Access Dates for Students').'</th>'.
  664:               '<th>'.&mt('Student Counts').'</th>'.
  665:               '<th>'.&mt('Auto-enrollment of <br />registered students').'</th>';
  666:         } else {
  667:             $output .= '<th>'.&mt('Details').'</th>';
  668:         }
  669:     }
  670:     $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
  671:     &Apache::loncommon::end_data_table_header_row();
  672:     my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
  673:                                             $usersections);
  674:     my %Sortby;
  675:     foreach my $course (sort(keys(%{$courses}))) {
  676:         if ($env{'form.sortby'} eq 'code') {
  677:             push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
  678:         } elsif ($env{'form.sortby'} eq 'owner') {
  679:             push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
  680:         } else {
  681:             my $clean_title = $courseinfo{$course}{'title'};
  682:             $clean_title =~ s/\W+//g;
  683:             if ($clean_title eq '') {
  684:                 $clean_title = $courseinfo{$course}{'title'};
  685:             }
  686:             push(@{$Sortby{$clean_title}},$course);
  687:         }
  688:     }
  689:     my @sorted_courses;
  690:     if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) {
  691:         @sorted_courses = sort(keys(%Sortby));
  692:     } else {
  693:         @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
  694:     }
  695:     my $count = 1;
  696:     foreach my $item (@sorted_courses) {
  697:         foreach my $course (@{$Sortby{$item}}) {
  698:             $output.=&Apache::loncommon::start_data_table_row(); 
  699:             $output.=&courseinfo_row($courseinfo{$course},$knownuser,
  700:                                      $details,\$count,$now,$course);
  701:             $output.=&Apache::loncommon::end_data_table_row();
  702:         }
  703:     }
  704:     $output .= &Apache::loncommon::end_data_table();
  705:     return $output;
  706: }
  707: 
  708: sub build_courseinfo_hash {
  709:     my ($courses,$knownuser,$details,$usersections) = @_;
  710:     my %courseinfo;
  711:     my $now = time;
  712:     foreach my $course (keys(%{$courses})) {
  713:         my $descr;
  714:         if (ref($courses->{$course}) eq 'HASH') {
  715:             $descr = $courses->{$course}{'description'}; 
  716:         }
  717:         my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
  718:         $cleandesc=~s/'/\\'/g;
  719:         $cleandesc =~ s/^\s+//;
  720:         my ($cdom,$cnum)=split(/\_/,$course);
  721:         my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types,
  722:             $selfenroll_start,$selfenroll_end,@owners,%ownernames);
  723:         if (ref($courses->{$course}) eq 'HASH') {
  724:             $descr = $courses->{$course}{'description'};
  725:             $instcode =  $courses->{$course}{'inst_code'};
  726:             $singleowner = $courses->{$course}{'owner'};
  727:             $ttype =  $courses->{$course}{'type'};
  728:             $selfenroll_types = $courses->{$course}{'selfenroll_types'};
  729:             $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
  730:             $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
  731:             push(@owners,$singleowner);
  732:             if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
  733:                 foreach my $item (@{$courses->{$course}{'co-owners'}}) {
  734:                     push(@owners,$item);
  735:                 }
  736:             }
  737:         }
  738:         foreach my $owner (@owners) {
  739:             my ($ownername,$ownerdom) = @_; 
  740:             if ($owner =~ /:/) {
  741:                 ($ownername,$ownerdom) = split(/:/,$owner);
  742:             } else {
  743:                 $ownername = $owner;
  744:                 if ($owner ne '') {
  745:                     $ownerdom = $cdom;
  746:                 }
  747:             }
  748:             if ($ownername ne '' && $ownerdom ne '') {
  749:                 my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
  750:                 $ownernames{$ownername.':'.$ownerdom} = \%namehash; 
  751:             }
  752:         }
  753:         $courseinfo{$course}{'cdom'} = $cdom;
  754:         $courseinfo{$course}{'cnum'} = $cnum;
  755:         $courseinfo{$course}{'code'} = $instcode;
  756:         my @lastnames;
  757:         foreach my $owner (keys(%ownernames)) {
  758:             if (ref($ownernames{$owner}) eq 'HASH') {
  759:                 push(@lastnames,$ownernames{$owner}{'lastname'});
  760:             }
  761:         }
  762:         $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
  763:         $courseinfo{$course}{'title'} = $cleandesc;
  764:         $courseinfo{$course}{'owner'} = $singleowner;
  765:         $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
  766:         $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
  767:         $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
  768: 
  769:         my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
  770:         my @classids;
  771:         my @crosslistings;
  772:         my ($seclist,$numsec) = 
  773:             &identify_sections($coursehash{'internal.sectionnums'});
  774:         if (ref($usersections) eq 'HASH') {
  775:             if (ref($usersections->{$course}) eq 'ARRAY') {
  776:                 $seclist = join(', ',@{$usersections->{$course}});
  777:             }
  778:         }
  779:         $courseinfo{$course}{'seclist'} = $seclist;
  780:         my ($xlist_items,$numxlist) = 
  781:             &identify_sections($coursehash{'internal.crosslistings'});
  782:         my $showsyllabus = 1; # default is to include a syllabus link
  783:         if (defined($coursehash{'showsyllabus'})) {
  784:             $showsyllabus = $coursehash{'showsyllabus'};
  785:         }
  786:         $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
  787:         if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
  788:             ($knownuser && ($details == 1))) {
  789:             $courseinfo{$course}{'counts'} =  &count_students($cdom,$cnum,$numsec);
  790:             $courseinfo{$course}{'autoenrollment'} =
  791:                 &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
  792:                                  $instcode,\@owners,$cdom,$cnum);
  793: 
  794:             my $startaccess = '';
  795:             my $endaccess = '';
  796:             my $accessdates;
  797:             if ( defined($coursehash{'default_enrollment_start_date'}) ) {
  798:                 $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
  799:             }
  800:             if ( defined($coursehash{'default_enrollment_end_date'}) ) {
  801:                 $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
  802:                 if ($coursehash{'default_enrollment_end_date'} == 0) {
  803:                     $endaccess = "No ending date";
  804:                 }
  805:             }
  806:             if ($startaccess) {
  807:                 $accessdates .= &mt('<i>From:</i> ').$startaccess.'<br />';
  808:             }
  809:             if ($endaccess) {
  810:                 $accessdates .= &mt('<i>To:</i> ').$endaccess.'<br />';
  811:             }
  812:             $courseinfo{$course}{'access'} = $accessdates;
  813:         }
  814:         if ($xlist_items eq '') {
  815:             $xlist_items = &mt('No');
  816:         }
  817:         $courseinfo{$course}{'xlist'} = $xlist_items;
  818:     }
  819:     return %courseinfo;
  820: }
  821: 
  822: sub count_students {
  823:     my ($cdom,$cnum,$numsec) = @_;
  824:     my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
  825:     my %student_count = (
  826:                            Active => 0,
  827:                            Future => 0,
  828:                            Expired => 0,
  829:                        );
  830:     my %idx;
  831:     $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
  832:     my %status_title = &Apache::lonlocal::texthash(
  833:                            Expired => 'Previous access',
  834:                            Active => 'Current access',
  835:                            Future => 'Future access',
  836:                        );
  837: 
  838:     while (my ($student,$data) = each(%$classlist)) {
  839:         $student_count{$data->[$idx{'status'}]} ++;
  840:     }
  841: 
  842:     my $countslist = &mt('[quant,_1,section]',$numsec).':<br />';
  843:     foreach my $status ('Active','Future') {
  844:         $countslist .= '<nobr>'.$status_title{$status}.': '.
  845:                        $student_count{$status}.'</nobr><br />';
  846:     }
  847:     return $countslist;
  848: }
  849: 
  850: sub courseinfo_row {
  851:     my ($info,$knownuser,$details,$countref,$now,$course) = @_;
  852:     my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
  853:         $accessdates,$showsyllabus,$counts,$autoenrollment,$output);
  854:     if (ref($info) eq 'HASH') {
  855:         $cdom = $info->{'cdom'};
  856:         $cnum = $info->{'cnum'};
  857:         $title = $info->{'title'};
  858:         $ownerlast = $info->{'ownerlastnames'};
  859:         $code = $info->{'code'};
  860:         $owner = $info->{'owner'};
  861:         $seclist = $info->{'seclist'};
  862:         $xlist_items = $info->{'xlist'};
  863:         $accessdates = $info->{'access'};
  864:         $counts = $info->{'counts'};
  865:         $autoenrollment = $info->{'autoenrollment'};
  866:         $showsyllabus = $info->{'showsyllabus'};
  867:     } else {
  868:         $output = '<td colspan="8">'.&mt('No information available for [_1].',
  869:                                          $code).'</td>';
  870:         return $output;
  871:     }
  872:     $output .= '<td>'.$$countref.'</td>'.
  873:                '<td>'.$code.'</td>'.
  874:                '<td>'.$seclist.'</td>'.
  875:                '<td>'.$xlist_items.'</td>'.
  876:                '<td>'.$title.'&nbsp;<font size="-2">';
  877:     if ($showsyllabus) {
  878:         $output .= &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom);
  879:     } else {
  880:         $output .= '&nbsp;';
  881:     }
  882:     $output .= '</font></td>'.
  883:                '<td>'.$ownerlast.'</td>';
  884:     if ($knownuser) {
  885:         if ($details) {
  886:             $output .=
  887:                '<td>'.$accessdates.'</td>'. 
  888:                '<td>'.$counts.'</td>'.
  889:                '<td>'.$autoenrollment.'</td>';
  890:         } else {
  891:             $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
  892:         }
  893:     }
  894:     my $selfenroll;
  895:     if ($info->{'selfenroll_types'}) {
  896:         my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
  897:         my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
  898:         if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
  899:             if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
  900:                 $output .= '<td>'.&mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>').'</td>';
  901:             } else { 
  902:                 $output .= '<td><a href="/adm/selfenroll?cid='.$course.'">'.&mt('Enroll in course').'</a></td>';
  903:             }
  904:             $selfenroll = 1;
  905:         }
  906:     }
  907:     if (!$selfenroll) {
  908:         $output .= '<td>&nbsp;</td>';
  909:     }
  910:     $$countref ++;
  911:     return $output;
  912: }
  913: 
  914: sub identify_sections {
  915:     my ($seclist) = @_;
  916:     my @secnums;
  917:     if ($seclist =~ /,/) {
  918:         my @sections = split(/,/,$seclist);
  919:         foreach my $sec (@sections) {
  920:             $sec =~ s/:[^:]*$//;
  921:             push(@secnums,$sec);
  922:         }
  923:     } else {
  924:         if ($seclist =~ m/^([^:]+):/) {
  925:             my $sec = $1;
  926:             if (!grep(/^\Q$sec\E$/,@secnums)) {
  927:                 push(@secnums,$sec);
  928:             }
  929:         }
  930:     }
  931:     @secnums = sort {$a <=> $b} @secnums;
  932:     my $seclist = join(', ',@secnums);
  933:     my $numsec = @secnums;
  934:     return ($seclist,$numsec);
  935: }
  936: 
  937: sub get_valid_classes {
  938:     my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
  939:     my $response;
  940:     my %validations;
  941:     @{$validations{'sections'}} = ();
  942:     @{$validations{'xlists'}} = ();
  943:     my $totalitems = 0;
  944:     if ($seclist) {
  945:         foreach my $sec (split(/, /,$seclist)) {
  946:             my $class = $crscode.$sec;
  947:             if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
  948: 							 $class) eq 'ok') {
  949:                 if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
  950:                     push(@{$validations{'sections'}},$sec);
  951:                     $totalitems ++;
  952:                 }
  953:             }
  954:         }
  955:     }
  956:     if ($xlist_items) {
  957:         foreach my $item (split(/, /,$xlist_items)) {
  958:             if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
  959: 							 $item) eq 'ok') {
  960:                 if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
  961:                     push(@{$validations{'xlists'}},$item);
  962:                     $totalitems ++;
  963:                 }
  964:             }
  965:         }
  966:     }
  967:     if ($totalitems > 0) {
  968:         if (@{$validations{'sections'}}) {
  969:             $response = &mt('Sections: ').
  970:                         join(', ',@{$validations{'sections'}}).'<br />';
  971:         }
  972:         if (@{$validations{'xlists'}}) {
  973:             $response .= &mt('Courses: ').
  974:                         join(', ',@{$validations{'xlists'}});
  975:         }
  976:     }
  977:     return $response;
  978: }
  979: 
  980: sub javascript_select_filler {
  981:     my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
  982:     my $output = <<END;
  983: function courseSet() {
  984:     var longtitles = new Array ("$longtitles_str");
  985:     var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
  986:     var valsem  = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
  987:     var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
  988:     var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
  989:     var idyears = new Array("$allidlist");
  990:     var idyr = -1;
  991:     var idsem = -1;
  992:     var iddept = -1;
  993:     document.$formname.Number.length = 0;
  994: 
  995:     $scripttext
  996: 
  997:     selYear = document.$formname.Year.selectedIndex-1;
  998:     selSemester = document.$formname.Semester.selectedIndex-1;
  999:     selDepartment = document.$formname.Department.selectedIndex-1;
 1000:     if (selYear == -1) {
 1001:         if (selSemester == -1) {
 1002:             if (selDepartment > -1) {
 1003:                 document.$formname.Number.options[0] =  new Option('All','0',false,false);
 1004:                 for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
 1005:                     document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
 1006: 
 1007:                 }
 1008:             } 
 1009:             else {
 1010:                 document.$formname.Number.options[0] = new Option("All","0",true,true);
 1011:             }
 1012:         }
 1013:         else {
 1014:             if (selDepartment > -1) {
 1015:                 for (var i=0; i<idcse_by_sem_sems.length; i++) {
 1016:                     if (idcse_by_sem_sems[i] == valsem) {
 1017:                         idsem = i;
 1018:                     }
 1019:                 }
 1020:                 if (idsem != -1) {
 1021:                     for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
 1022:                         if (idcse_by_sem_dept[idsem][i] == valdept) {
 1023:                             iddept = i;
 1024:                         }
 1025:                     }
 1026:                 }
 1027:                 if (iddept != -1) {
 1028:                     document.$formname.Number.options[0] =  new Option('All','0',false,false);
 1029:                     for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
 1030:                         document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
 1031:                     }
 1032:                 }
 1033:                 else {
 1034:                     document.$formname.Number.options[0] =  new Option('No courses','0',true,true);
 1035:                 }
 1036:             }
 1037:             else {
 1038:                 document.$formname.Number.options[0] = new Option("All","0",true,true);
 1039:             }
 1040:         }
 1041:     }
 1042:     else {
 1043:         if (selSemester == -1) {
 1044:             if (selDepartment > -1) {
 1045:                 for (var i=0; i<idcse_by_yr_year.length; i++) {
 1046:                     if (idcse_by_yr_year[i] == valyr) {
 1047:                         idyr = i;
 1048:                     }
 1049:                 }
 1050:                 if (idyr != -1) {      
 1051:                     for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
 1052:                         if (idcse_by_yr_dept[idyr][i] == valdept) {
 1053:                             iddept = i;
 1054:                         }
 1055:                     }
 1056:                 }
 1057:                 if (iddept != -1) {
 1058:                     document.$formname.Number.options[0] =  new Option('All','0',false,false);
 1059:                     for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
 1060:                         document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
 1061:                     }
 1062:                 } 
 1063:                 else {
 1064:                     document.$formname.Number.options[0] =  new Option('No courses','0',true,true);
 1065:                 }
 1066:             }
 1067:             else {
 1068:                 document.$formname.Number.options[0] = new Option("All","0",true,true);
 1069:             }
 1070:         }
 1071:         else {
 1072:             if (selDepartment > -1) {
 1073:                 for (var k=0; k<idyears.length; k++) {
 1074:                     if (idyears[k] == valyr) {
 1075:                         idyr = k;
 1076:                     }
 1077:                 }
 1078:                 if (idyr != -1) {
 1079:                     for (var k=0; k<idsems[idyr].length; k++) {
 1080:                         if (idsems[idyr][k] == valsem) {
 1081:                             idsem = k;
 1082:                         }
 1083:                     }
 1084:                 }
 1085:                 if (idsem != -1) {
 1086:                     for (var k=0; k<idcodes[idyr][idsem].length; k++) {
 1087:                         if (idcodes[idyr][idsem][k] == valdept) {
 1088:                             iddept = k;
 1089:                         }
 1090:                     }
 1091:                 }
 1092:                 if (iddept != -1) {
 1093:                     document.$formname.Number.options[0] =  new Option('All','0',false,false);
 1094:                     for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
 1095:                         var display = idcourses[idyr][idsem][iddept][i];
 1096:                         if (longtitles[3] == 1) {
 1097:                             if (idcourseslongs[idyr][idsem][iddept][i] != "") {
 1098:                                 display = idcourseslongs[idyr][idsem][iddept][i]
 1099:                             }
 1100:                         }
 1101:                         document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
 1102:                     }
 1103:                 } 
 1104:                 else {
 1105:                     document.$formname.Number.options[0] =  new Option('No courses','0',true,true);
 1106:                 }
 1107:             } 
 1108:             else {
 1109:                 document.$formname.Number.options[0] =  new Option('All','0',true,true);
 1110:             }
 1111:         }
 1112:         document.$formname.Number.selectedIndex = 0
 1113:     }
 1114: }
 1115: END
 1116:     return $output;
 1117: }
 1118: 
 1119: sub autoenroll_info {
 1120:     my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
 1121:     my $autoenrolldates = &mt('Not enabled');
 1122:     if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
 1123:         my ($autostart,$autoend);
 1124:         if ( defined($coursehash->{'internal.autostart'}) ) {
 1125:             $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
 1126:         }
 1127:         if ( defined($coursehash->{'internal.autoend'}) ) {
 1128:             $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
 1129:         }
 1130:         if ($coursehash->{'internal.autostart'} > $now) {
 1131:             if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
 1132:                 $autoenrolldates = &mt('Not enabled');
 1133:             } else {
 1134:                 my $valid_classes = 
 1135:                    &get_valid_classes($seclist,$xlist_items,$code,
 1136:                                       $owners,$cdom,$cnum);
 1137:                 if ($valid_classes ne '') {
 1138:                     $autoenrolldates = &mt('Not enabled<br />Starts: ').
 1139:                                        $autostart.'<br />'.$valid_classes;                }
 1140:             }
 1141:         } else {
 1142:             if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
 1143:                 $autoenrolldates = &mt('Not enabled<br />Ended: ').$autoend;
 1144:             } else {
 1145:                 my $valid_classes = &get_valid_classes($seclist,$xlist_items,
 1146:                                                        $code,$owners,$cdom,$cnum);
 1147:                 if ($valid_classes ne '') {
 1148:                     $autoenrolldates = &mt('Currently enabled<br />').
 1149:                                        $valid_classes;
 1150:                 }
 1151:             }
 1152:         }
 1153:     }
 1154:     return $autoenrolldates;
 1155: }
 1156: 
 1157: sub user_is_known {
 1158:     my $known = 0;
 1159:     if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public' 
 1160:         && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
 1161:         $known = 1;
 1162:     }
 1163:     return $known;
 1164: }
 1165: 
 1166: 1;

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