Annotation of loncom/interface/coursecatalog.pm, revision 1.49

1.17      albertel    1: # The LearningOnline Network with CAPA
                      2: # Handler for displaying the course catalog interface
                      3: #
1.49    ! schafran    4: # $Id: coursecatalog.pm,v 1.48 2009/02/07 22:03:45 raeburn Exp $
1.1       raeburn     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;
1.7       raeburn    35: use Apache::lonhtmlcommon;
1.1       raeburn    36: use Apache::lonnet;
                     37: use Apache::lonlocal;
1.6       raeburn    38: use Apache::courseclassifier;
1.1       raeburn    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:     }
1.21      albertel   49:     my $handle = &Apache::lonnet::check_for_valid_session($r);
1.8       raeburn    50:     my $lonidsdir=$r->dir_config('lonIDsDir');
1.21      albertel   51:     if ($handle ne '') {
1.8       raeburn    52:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
                     53:     }
1.1       raeburn    54:     &Apache::lonacc::get_posted_cgi($r);
                     55:     &Apache::lonlocal::get_language_handle($r);
1.38      raeburn    56:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     57:                                             ['sortby','showdom']);
1.28      raeburn    58: 
                     59:     my $codedom = &Apache::lonnet::default_login_domain();
1.19      raeburn    60: 
                     61:     if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) { 
                     62:         $codedom = $env{'user.domain'};
                     63:         if ($env{'request.role.domain'} ne '') {
                     64:             $codedom = $env{'request.role.domain'};
                     65:         }
                     66:     }
1.7       raeburn    67:     my $formname = 'coursecatalog';
1.28      raeburn    68:     if ($env{'form.showdom'} ne '') {
                     69:         if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
                     70:             $codedom = $env{'form.showdom'};
                     71:         }
                     72:     }
1.20      albertel   73:     my $domdesc = &Apache::lonnet::domain($codedom,'description');
1.7       raeburn    74:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.35      raeburn    75: 
                     76:     my %domconfig =
                     77:         &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
1.36      raeburn    78:     my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash);
1.35      raeburn    79:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                     80:         $cathash = $domconfig{'coursecategories'}{'cats'};
                     81:     } else {
                     82:         $cathash = {};
                     83:     }
1.36      raeburn    84:     my $subcats;
                     85:     if ($env{'form.withsubcats'}) {
                     86:         $subcats = \%subcathash;
                     87:     }
1.35      raeburn    88:     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
1.36      raeburn    89:                                            \%idx,\@jsarray,$subcats);
1.8       raeburn    90:     if ($env{'form.coursenum'} ne '' && &user_is_known()) {
1.35      raeburn    91:         &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
1.7       raeburn    92:     } else {
1.46      raeburn    93:         my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom,@cats);
1.28      raeburn    94:         my $catjs = <<"ENDSCRIPT";
                     95: 
                     96: function setCatDepth(depth) {
                     97:     document.coursecats.catalog_maxdepth.value = depth;
1.36      raeburn    98:     if (depth == '') {
                     99:         document.coursecats.currcat_0.value = '';
                    100:     }
1.28      raeburn   101:     document.coursecats.submit();
                    102:     return;
                    103: }
                    104: 
1.33      raeburn   105: function changeSort(caller) {
                    106:     document.$formname.sortby.value = caller;
                    107:     document.$formname.submit();
                    108: }
1.40      raeburn   109: 
1.33      raeburn   110: function setCourseId(caller) {
                    111:     document.$formname.coursenum.value = caller;
                    112:     document.$formname.submit();
1.37      raeburn   113: }
                    114: 
                    115: ENDSCRIPT
1.41      raeburn   116:         $catjs .= &courselink_javascript(); 
1.28      raeburn   117:         my $numtitles;
                    118:         if ($env{'form.currcat_0'} eq 'instcode::0') {
                    119:             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
                    120:                                                    $catlinks,$catjs);
                    121:             if ($env{'form.state'} eq 'listing') {
                    122:                 $r->print(&print_course_listing($codedom,$numtitles));
                    123:             }
                    124:         } else {
                    125:             my (%add_entries);
1.46      raeburn   126:             if ($selitem) {
                    127:                 $catjs .= <<ENDJS;
                    128: function check_selected() {
                    129:     if (document.coursecats.$selitem.options[document.coursecats.$selitem.selectedIndex].value == "") {
                    130:         alert('Choose a subcategory to display');
                    131:         return false;
                    132:     }
                    133: }
                    134: ENDJS
                    135:             }
1.28      raeburn   136:             $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
                    137:             &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
                    138:             if ($env{'form.currcat_0'} ne '') {
1.33      raeburn   139:                 $r->print('<form name="'.$formname.
                    140:                           '" method="post" action="/adm/coursecatalog">'.
1.36      raeburn   141:                           &additional_filters($codedom,$has_subcats)."\n");
1.33      raeburn   142:                 my ($currdepth,$deeper) = &get_depth_values();
                    143:                 $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
                    144:                           $deeper.'" />'."\n");
                    145:                 for (my $i=0; $i<$deeper; $i++) {
                    146:                     $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
                    147:                 }
                    148:                 $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
                    149:                           '<input type="hidden" name="sortby" value="" />'."\n".
                    150:                           '<input type="hidden" name="state" value="listing" />'."\n".
                    151:                           '<input type="hidden" name="showdom" value="'.
                    152:                           $env{'form.showdom'}.'" />'.
                    153:                           '<input type="submit" name="catalogfilter" value="'.
                    154:                           &mt('Display courses').'" /></form><br /><br />');
                    155:             }
                    156:             if ($env{'form.state'} eq 'listing') {
1.36      raeburn   157:                 $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
1.28      raeburn   158:             }
1.18      raeburn   159:         }
1.7       raeburn   160:     }
1.32      raeburn   161:     $r->print('<br />'.&Apache::loncommon::end_page());
1.7       raeburn   162:     return OK;
                    163: }
                    164: 
                    165: sub course_details {
1.35      raeburn   166:     my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
1.7       raeburn   167:     my $output;
                    168:     my %add_entries = (topmargin    => "0",
                    169:                        marginheight => "0",);
1.40      raeburn   170:     my $js = '<script type="text/javascript">'."\n".
1.41      raeburn   171:              &courselink_javascript().'</script>'."\n";
1.7       raeburn   172:     my $start_page =
1.40      raeburn   173:         &Apache::loncommon::start_page('Course Catalog',$js,
1.7       raeburn   174:                                            {
                    175:                                              'add_entries' => \%add_entries,
                    176:                                              'no_inline_link'   => 1,});
                    177:     $r->print($start_page);
1.19      raeburn   178:     if ($env{'form.numtitles'} > 0) {
                    179:         &Apache::lonhtmlcommon::add_breadcrumb
                    180:                 ({href=>"/adm/coursecatalog",
                    181:                   text=>"Select courses"});
                    182:     }
1.7       raeburn   183:     &Apache::lonhtmlcommon::add_breadcrumb
1.19      raeburn   184:              ({href=>"javascript:document.$formname.submit()",
1.7       raeburn   185:               text=>"Course listing"},
                    186:              {text=>"Course details"});
                    187:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
                    188:     $r->print('<br />'.&mt('Detailed course information:').'<br /><br />'.
1.35      raeburn   189:               &print_course_listing($codedom,undef,$trails,$allitems).
                    190:               '<br /><br />');
1.40      raeburn   191:     $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
                    192:               '<a href = "javascript:document.coursecatalog.submit()">'.
1.7       raeburn   193:               &mt('Back to course listing').'</a>'.
1.41      raeburn   194:               &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
                    195:                                                        'showdetails','courseid']).'</form>');
1.40      raeburn   196:     return;
                    197: }
                    198: 
1.41      raeburn   199: sub courselink_javascript {
1.40      raeburn   200:     return <<"END";
                    201: 
                    202: function ToSyllabus(cdom,cnum) {
                    203:     if (cdom == '' || cdom == null) {
                    204:         return;
                    205:     }
                    206:     if (cnum == '' || cnum == null) {
                    207:         return;
                    208:     }
1.41      raeburn   209:     document.linklaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus";
                    210:     document.linklaunch.submit();
                    211: }
                    212: 
                    213: function ToSelfenroll(courseid) {
                    214:     if (courseid == '') {
                    215:         return;
                    216:     }
                    217:     document.linklaunch.action = "/adm/selfenroll";
                    218:     document.linklaunch.courseid.value = courseid;
                    219:     document.linklaunch.submit();
1.40      raeburn   220: }
                    221: 
                    222: END
1.7       raeburn   223: }
                    224: 
1.40      raeburn   225: 
1.28      raeburn   226: sub instcode_course_selector {
                    227:     my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
1.1       raeburn   228:     my %coursecodes = ();
                    229:     my %codes = ();
                    230:     my @codetitles = ();
                    231:     my %cat_titles = ();
                    232:     my %cat_order = ();
                    233:     my %idlist = ();
                    234:     my %idnums = ();
                    235:     my %idlist_titles = ();
1.6       raeburn   236:     my %by_year;
                    237:     my %by_sem;
                    238:     my %by_dept;
                    239:     my %cat_items;
1.1       raeburn   240:     my $caller = 'global';
                    241:     my $format_reply;
                    242:     my $totcodes = 0;
                    243:     my $jscript = '';
1.6       raeburn   244:     my ($numtitles,$lasttitle);
1.30      raeburn   245:     my %add_entries = (topmargin    => "0",
                    246:                        marginheight => "0",);
                    247:     my $js;
1.22      raeburn   248:     $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
1.1       raeburn   249:     if ($totcodes > 0) {
1.6       raeburn   250:         $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
                    251:         if ($format_reply eq 'ok') {
                    252:             my $numtypes = @codetitles;
                    253:             &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
                    254:             my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
                    255:             my $longtitles_str = join('","',@{$longtitles});
                    256:             my $allidlist = $idlist{$codetitles[0]};
                    257:             $numtitles = @codetitles;
                    258:             $lasttitle = $numtitles;
                    259:             if ($numtitles > 4) {
                    260:                 $lasttitle = 4;
1.1       raeburn   261:             }
1.18      raeburn   262:             if ($numtitles == 0) {
                    263:                 if (!defined($env{'form.state'})) {
                    264:                     $env{'form.state'} = 'listing';
                    265:                 }
                    266:             } else {
                    267:                 my @data = ('top');
                    268:                 for (my $k=0; $k<$lasttitle; $k++) {
                    269:                     my $cat = $codetitles[$k];
                    270:                     my $level = 1;
                    271:                     $level = &recurse_options($codetitles[$k],$idlist{$codetitles[$k]},$level,$cat,\%cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
                    272:                 }
                    273:                 $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,\%cat_order,\@codetitles);
                    274:                 $jscript .= &javascript_select_filler($formname,$scripttext,\@codetitles,$longtitles_str,$allidlist);
                    275:                 if ($env{'form.state'} eq 'listing') {
                    276:                     $jscript .= '
1.1       raeburn   277: function setElements() {
                    278: ';
1.18      raeburn   279:                     for (my $i=0; $i<@codetitles-1; $i++) {
                    280:                         if ($env{'form.'.$codetitles[$i]} != -1) {
                    281:                             $jscript .= '
1.1       raeburn   282:     for (var j=0; j<document.'.$formname.'.'.$codetitles[$i].'.length; j++) {
                    283:         if (document.'.$formname.'.'.$codetitles[$i].'[j].value == "'.$env{'form.'.$codetitles[$i]}.'") {
                    284:             document.'.$formname.'.'.$codetitles[$i].'.selectedIndex = j;
                    285:         }
                    286:     }
                    287: ';
1.18      raeburn   288:                         }
                    289:                     }
                    290:                     $jscript .= '   courseSet()'."\n";
                    291:                     if ($env{'form.'.$codetitles[-1]} != -1) {
                    292:                         $jscript .= '
1.6       raeburn   293:     for (var j=0; j<document.'.$formname.'.'.$codetitles[-1].'.length; j++) {
                    294:         if (document.'.$formname.'.'.$codetitles[-1].'[j].value == "'.$env{'form.'.$codetitles[-1]}.'") {
                    295:             document.'.$formname.'.'.$codetitles[-1].'.selectedIndex = j;
                    296:         }
                    297:     }
                    298: ';
1.18      raeburn   299:                     }
                    300:                     $jscript .= '}';
                    301:                 }
1.6       raeburn   302:             }
1.32      raeburn   303:         }
1.30      raeburn   304:         $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
                    305:               '</script>';
1.18      raeburn   306:         if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
1.7       raeburn   307:             $add_entries{'onLoad'} = 'setElements()';
                    308:         }
1.28      raeburn   309:         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
                    310:         my $cat_maxdepth = $env{'form.catalog_maxdepth'};
                    311:         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
1.32      raeburn   312:                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
                    313:                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
                    314:                   '<input type="hidden" name="currcat_0" value="instcode::0" />'.
1.33      raeburn   315:                   &additional_filters($codedom));
1.1       raeburn   316:         if ($numtitles > 0) {
1.32      raeburn   317:             $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />');
1.6       raeburn   318:             $r->print('<table><tr>');
                    319:             for (my $k=0; $k<$lasttitle-1; $k++) {
1.26      raeburn   320:                 my (@items,@unsorted);
                    321:                 if (ref($cat_items{$codetitles[$k]}) eq 'ARRAY') {
                    322:                     @unsorted = @{$cat_items{$codetitles[$k]}};
                    323:                 }
1.6       raeburn   324:                 &Apache::courseclassifier::sort_cats($k,\%cat_order,\@codetitles,\@unsorted,\@items);
                    325:                 my @longitems;
                    326:                 if (defined($cat_titles{$codetitles[$k]})) {
                    327:                     foreach my $item (@items) {
                    328:                         push(@longitems,$cat_titles{$codetitles[$k]}{$item});
                    329:                     }
1.1       raeburn   330:                 } else {
1.6       raeburn   331:                     @longitems = @items;
1.1       raeburn   332:                 }
1.6       raeburn   333:                 $r->print('<td align="center">'.$codetitles[$k].'<br />'."\n".
                    334:                           '<select name="'.$codetitles[$k].'" onChange="courseSet()"');
                    335:                 $r->print('>'."\n".'<option value="0" />All'."\n");
                    336:                 for (my $i=0; $i<@items; $i++) {
1.1       raeburn   337:                     if ($longitems[$i] eq '') {
                    338:                         $longitems[$i] = $items[$i];
                    339:                     }
1.6       raeburn   340:                     $r->print(' <option value="'.$items[$i].'">'.$longitems[$i].'</option>');
1.1       raeburn   341:                 }
1.6       raeburn   342:                 $r->print('</select></td>');
1.1       raeburn   343:             }
1.6       raeburn   344:             $r->print('<td align="center">'.$codetitles[$lasttitle-1].'<br />'."\n".
                    345:                       '<select name="'.$codetitles[$lasttitle-1].'">'."\n".
                    346:                       '<option value="0">All'."\n".
                    347:                       '</option>'."\n".'</select>'."\n".
1.32      raeburn   348:                  '</td></tr></table>'."\n");
1.1       raeburn   349:             if ($numtitles > 4) {
1.6       raeburn   350:                 $r->print('<br /><br />'.$codetitles[$numtitles-1].'<br />'."\n".
                    351:                 '<input type="text" name="'.$codetitles[$numtitles-1].'" /><br />'."\n");
1.1       raeburn   352:             }
1.18      raeburn   353:             $r->print('<br />');
                    354:         }
1.33      raeburn   355:         $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
                    356:                   '<input type="hidden" name="sortby" value="" />'."\n".
                    357:                   '<input type="hidden" name="state" value="listing" />'."\n".
                    358:                   '<input type="hidden" name="form.currcat_0" value="instcode::0" />'."\n".
                    359:                   '<input type="submit" name="catalogfilter" value="'.
                    360:                   &mt('Display courses').'" />'.
                    361:                   '<input type="hidden" name="numtitles" value="'.$numtitles.
1.37      raeburn   362:                   '" /></form><br /><br />');
1.5       raeburn   363:     } else {
1.45      raeburn   364:         $js = '<script type"text/javascript">'."\n$catjs\n".'</script>';
1.30      raeburn   365:         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles);
                    366:         my $cat_maxdepth = $env{'form.catalog_maxdepth'};
                    367:         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
                    368:                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
                    369:                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
                    370:                   '<input type="hidden" name="currcat_0" value="instcode::0" />');
                    371:         $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
1.1       raeburn   372:     }
1.18      raeburn   373:     return $numtitles;
1.1       raeburn   374: }
                    375: 
1.28      raeburn   376: sub cat_header {
                    377:     my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles) = @_;
                    378:     my $start_page =
1.49    ! schafran  379:         &Apache::loncommon::start_page('Other',$js,
1.28      raeburn   380:                                        {
                    381:                                          'add_entries' => $add_entries,
                    382:                                          'no_inline_link'   => 1,});
                    383:     $r->print($start_page);
                    384:     if ($env{'form.state'} eq 'listing') {
                    385:         if ($numtitles > 0) {
                    386:             &Apache::lonhtmlcommon::add_breadcrumb
                    387:                 ({href=>"/adm/coursecatalog",
                    388:                   text=>"Select courses"},
                    389:                  {text=>"Course listing"});
                    390:         } else {
                    391:             &Apache::lonhtmlcommon::add_breadcrumb
                    392:             ({text=>"Course listing"});
                    393:         }
                    394:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
                    395:     } else {
                    396:         &Apache::lonhtmlcommon::add_breadcrumb
                    397:         ({href=>"/adm/coursecatalog",
                    398:           text=>"Select courses"});
                    399:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Select courses'));
                    400:     }
1.47      raeburn   401:     my $onchange;
                    402:     unless (($env{'browser.interface'} eq 'textual') || ($env{'form.interface'} eq 'textual')) {
                    403:         $onchange = 1;
                    404:     }
1.34      raeburn   405:     $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
                    406:               '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
1.47      raeburn   407:               &Apache::loncommon::select_dom_form($codedom,'showdom','',1,$onchange));
                    408:     if (!$onchange) {
                    409: 	   $r->print('&nbsp;<input type="submit" name="godom" value="'.&mt('Change').'" />');
                    410:     }
                    411:     $r->print('</td></tr></table></form>'.
1.46      raeburn   412: 	      '<form name="coursecats" method="post" action="/adm/coursecatalog"'.
1.48      raeburn   413:               ' onsubmit="return check_selected();">'.
1.34      raeburn   414:               '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
1.28      raeburn   415:     return;
                    416: }
                    417: 
                    418: sub category_breadcrumbs {
1.35      raeburn   419:     my ($dom,@cats) = @_;
1.44      raeburn   420:     my $crumbsymbol = ' &#x25b6; ';
1.33      raeburn   421:     my ($currdepth,$deeper) = &get_depth_values();
                    422:     my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
1.28      raeburn   423:     my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
1.36      raeburn   424:     my $has_subcats;
1.46      raeburn   425:     my $selitem;
1.28      raeburn   426:     for (my $i=0; $i<$deeper; $i++) {
                    427:         $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
                    428:         my ($cattitle,$shallower);
                    429:         if ($i == 0) {
1.46      raeburn   430:             if (ref($cats[0]) eq 'ARRAY') {
                    431:                 if (@{$cats[0]} > 1) {
                    432:                     $cattitle = &mt('Main Categories');
                    433:                 }
                    434:             }
1.28      raeburn   435:         } else {
                    436:             $shallower = $i-1;
                    437:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
                    438:             $cattitle = $cat;
                    439:         }
1.46      raeburn   440:         if ($cattitle ne '') {
                    441:             $catlinks .= '<td valign="top"><a href="javascript:setCatDepth('."'$shallower'".')">'.$cattitle.'</a>'.$crumbsymbol.'</td>';
                    442:         }
1.28      raeburn   443:     }
                    444:     if ($deeper == 0) {
1.46      raeburn   445:         $catlinks .= '<td>';
1.28      raeburn   446:         if (ref($cats[0]) eq 'ARRAY') {
1.46      raeburn   447:             if ((@{$cats[0]} == 1) && (@cats == 1)) {
                    448:                 if ($cats[0][0] eq 'instcode') {
                    449:                     $catlinks .= &mt('Official courses (with institutional codes)').
                    450:                                  '<input type="hidden" name="currcat_0" value="instcode::0" />';
                    451:                     $env{'form.currcat_0'} = 'instcode::0';
                    452:                 } else {
                    453:                     my $name = $cats[0][0];
                    454:                     my $item = &escape($name).'::0';
                    455:                     $catlinks .= $name.
                    456:                              '<input type="hidden" name="currcat_0" value="'.$item.'" />';
                    457:                     $env{'form.currcat_0'} = $item;
                    458:                 }
1.28      raeburn   459:             } else {
1.36      raeburn   460:                 $has_subcats = 1;
1.46      raeburn   461:                 my $buttontext = &mt('Show subcategories');
                    462:                 $selitem = 'currcat_0';
                    463:                 $catlinks .= '<select name="'.$selitem.'">'."\n";
1.28      raeburn   464:                 if (@{$cats[0]} > 1) {
1.46      raeburn   465:                     $catlinks .= '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
                    466:                     $buttontext = &mt('Pick main category');
1.28      raeburn   467:                 }
                    468:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                    469:                     my $name = $cats[0][$i];
                    470:                     my $item = &escape($name).'::0';
1.36      raeburn   471:                     $catlinks .= '<option value="'.$item.'">';
1.28      raeburn   472:                     if ($name eq 'instcode') {
                    473:                         $catlinks .= &mt('Official courses (with institutional codes)');
                    474:                     } else {
                    475:                         $catlinks .= $name;
                    476:                     }
                    477:                     $catlinks .= '</option>'."\n";
                    478:                 }
                    479:                 $catlinks .= '</select>'."\n".
1.46      raeburn   480:                              '&nbsp;<input type="submit" name="gocats" value="'.
                    481:                              $buttontext.'" />';
1.28      raeburn   482:             }
                    483:         } else {
                    484:             $catlinks .= &mt('Official courses (with institutional codes)').
1.34      raeburn   485:                          '<input type="hidden" name="currcat_0" value="instcode::0" />';
1.28      raeburn   486:             $env{'form.currcat_0'} = 'instcode::0';
                    487:         }
                    488:     } else {
1.29      raeburn   489:         my ($cat,$container,$depth);
                    490:         if ($env{'form.currcat_'.$currdepth} eq '') {
                    491:             my $shallower = $currdepth - 1;
                    492:             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
                    493:         } else {
                    494:             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
                    495:         }
1.28      raeburn   496:         my $deeper = $depth +1;
                    497:         my $currcat = $cat;
                    498:         if ($cat eq 'instcode') {
                    499:             $currcat = &mt('Official courses (with institutional codes)');
                    500:         }
1.46      raeburn   501:         $catlinks .= '<td><b>'.$currcat.'</b>';
1.28      raeburn   502:         if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
1.36      raeburn   503:             $has_subcats = 1;
1.46      raeburn   504:             my $buttontext = &mt('Show subcategories');
                    505:             $selitem = 'currcat_'.$deeper;
                    506:             $catlinks .= ':&nbsp;<select name="'.$selitem.'">';
                    507:             if (@{$cats[$deeper]{$cat}} > 1) {
                    508:                 $catlinks .= '<option value="" selected="selected">'.
                    509:                              &mt('Select').'</option>';
                    510:                 $buttontext = &mt('Pick subcategory');
                    511:             }
1.28      raeburn   512:             for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
                    513:                 my $name = $cats[$deeper]{$cat}[$k];
                    514:                 my $item = &escape($name).':'.&escape($cat).':'.$deeper;
                    515:                 $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
                    516:             }
                    517:             $catlinks .= '</select>'."\n".
1.46      raeburn   518:                          '&nbsp;<input type="submit" name="gocats" value="'.
                    519:                          $buttontext.'" />';
                    520:         } elsif ($cat ne 'instcode') {
                    521:             $catlinks .= '&nbsp;'.&mt('(No subcategories)');
1.28      raeburn   522:         }
                    523:     }
                    524:     $catlinks .= $currcat_str.'</td></tr></table></td>';
1.46      raeburn   525:     return ($catlinks,$has_subcats,$selitem);
1.28      raeburn   526: }
                    527: 
1.33      raeburn   528: sub get_depth_values {
                    529:     my $currdepth = 0;
                    530:     my $deeper = 0;
                    531:     if ($env{'form.catalog_maxdepth'} ne '') {
                    532:         $currdepth = $env{'form.catalog_maxdepth'};
                    533:         if ($env{'form.currcat_'.$currdepth} eq '') {
                    534:             $deeper = $currdepth;
                    535:         } else {
                    536:             $deeper = $currdepth + 1;
                    537:         }
                    538:     }
                    539:     return ($currdepth,$deeper);
                    540: }
                    541: 
                    542: sub additional_filters {
1.36      raeburn   543:     my ($codedom,$has_subcats) = @_;
1.33      raeburn   544:     my $output = '<table>';
1.36      raeburn   545:     if (($env{'form.currcat_0'} ne 'instcode::0') && 
                    546:         ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
                    547:         my $include_subcat_status;
                    548:         if ($env{'form.withsubcats'}) {
                    549:             $include_subcat_status = 'checked="checked" ';
                    550:         }
                    551:         my $counter = $env{'form.catalog_maxdepth'};
                    552:         if ($counter > 0) {
                    553:             if ($env{'form.state'} eq 'listing') {
                    554:                 $counter --;
                    555:             } elsif ($env{'form.currcat_'.$counter} eq '') {
                    556:                 $counter --;
                    557:             }
                    558:         }
                    559:         my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
                    560:         if ($catname ne '') {
                    561:             $output .= '<tr><td><label>'.
                    562:                        '<input type="checkbox" name="withsubcats" value="1" '.
                    563:                        $include_subcat_status.'/>'.
1.38      raeburn   564:                        &mt('Include subcategories within "[_1]"',
                    565:                            &unescape($catname)).'</label></td></tr>';
1.36      raeburn   566:         }
                    567:     }
1.33      raeburn   568:     my $show_selfenroll_status;
                    569:     if ($env{'form.showselfenroll'}) {
                    570:         $show_selfenroll_status = 'checked="checked" ';
                    571:     }
1.36      raeburn   572:     $output .= '<tr><td>'.
                    573:                '<label><input type="checkbox" name="showselfenroll" value="1" '.
                    574:                $show_selfenroll_status.'/>'.
                    575:                &mt('Only show courses which allow self-enrollment').
                    576:                '</label></td></tr>';
1.33      raeburn   577:     if (&user_is_dc($codedom)) {
                    578:         my $showdetails_status;
                    579:         if ($env{'form.showdetails'}) {
                    580:             $showdetails_status = 'checked="checked" ';
                    581:         }
                    582:         my $showhidden_status;
                    583:         if ($env{'form.showhidden'}) {
                    584:              $showhidden_status = 'checked="checked" ';
                    585:         }
                    586:         my $dc_title = &Apache::lonnet::plaintext('dc');
                    587:         $output .= '<tr><td>'."\n".
                    588:                    '<label><input type="checkbox" name="showdetails" value="1" '.
1.36      raeburn   589:                    $showdetails_status.'/>'.
1.33      raeburn   590:                    &mt('Show full details for each course ([_1] only)',$dc_title).
                    591:                    '</label>'."\n".'</td></tr><tr><td>'.
                    592:                    '<label><input type="checkbox" name="showhidden" value="1" '.
                    593:                    $showhidden_status.'/>'.
                    594:                    &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title).
                    595:                    '</label>'."\n".'</td></tr>';
                    596:     }
1.36      raeburn   597:     $output .= '</table><br />';
1.33      raeburn   598:     return $output;
                    599: }
                    600: 
1.16      raeburn   601: sub user_is_dc {
                    602:     my ($codedom) = @_;
                    603:     if (exists($env{'user.role.dc./'.$codedom.'/'})) {
                    604:         my $livedc = 1;
                    605:         my $now = time;
                    606:         my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
                    607:         if ($start && $start>$now) { $livedc = 0; }
                    608:         if ($end   && $end  <$now) { $livedc = 0; }
                    609:         return $livedc;
                    610:     }
                    611:     return;
                    612: }
1.7       raeburn   613: 
1.6       raeburn   614: sub recurse_options {
                    615:     my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_;
                    616:     if (ref($currlist) eq 'HASH') {
                    617:         $level ++;
                    618:         foreach my $key (sort(keys(%{$currlist}))) {
                    619:             $$data[$level-1]= $key;
                    620:             &recurse_options($key,$currlist->{$key},$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept);
                    621:         }
                    622:     } else {
                    623:         $level --;
                    624:         my @contents = split(/","/,$currlist);
                    625:         foreach my $item (@contents) {
                    626:             if (!grep(/^\Q$item\E$/,@{$cat_options->{$cat}})) {
                    627:                 push(@{$cat_options->{$cat}},$item);
                    628:             }
                    629:             if ($level == 3) {
                    630:                 if (!grep/^\Q$item\E$/,@{$by_year->{$data->[1]}->{$currkey}}) {
                    631:                     push(@{$by_year->{$data->[1]}->{$currkey}},$item);                 
                    632:                 }
                    633:                 if (!grep/^\Q$item\E$/,@{$by_sem->{$data->[2]}->{$currkey}}) {
                    634:                     push(@{$by_sem->{$data->[2]}->{$currkey}},$item);
                    635:                 }
                    636:                 if (!grep/^\Q$item\E$/,@{$by_dept->{$currkey}}) {
                    637:                     push(@{$by_dept->{$currkey}},$item);
                    638:                 }
                    639: 
                    640:             }
                    641:         }
                    642:     }
                    643:     return $level;
                    644: }
                    645: 
                    646: sub build_javascript {
                    647:     my ($by_year,$by_sem,$by_dept,$cat_order,$codetitles) = @_;
                    648:     my @unsorted = keys(%{$by_year});
                    649:     my @sorted_yrs; 
                    650:     &Apache::courseclassifier::sort_cats('0',$cat_order,$codetitles,\@unsorted,\@sorted_yrs);
                    651:     my $output = 'var idcse_by_yr_year = new Array("'.join('","',@sorted_yrs).'");'."\n".
                    652:                  'var idcse_by_yr_dept = new Array('.scalar(@sorted_yrs).');'."\n".
                    653:                  'var idcse_by_yr_num = new Array('.scalar(@sorted_yrs).');'."\n";
                    654:     for (my $i=0; $i<@sorted_yrs; $i++) {
                    655:         my $numkeys = keys(%{$by_year->{$sorted_yrs[$i]}});
                    656:         $output .= " idcse_by_yr_num[$i] = new Array($numkeys);\n";
                    657:         if (ref($by_year->{$sorted_yrs[$i]}) eq 'HASH') {
                    658:             @unsorted = keys(%{$by_year->{$sorted_yrs[$i]}});
                    659:             my @sorted_depts;
                    660:             &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
                    661:             $output .= qq| idcse_by_yr_dept[$i] = new Array ("|.join('","',@sorted_depts).'");'."\n";
                    662:             for (my $j=0; $j<@sorted_depts; $j++) {
                    663:                 $output .= qq| idcse_by_yr_num[$i][$j] = new Array ("|;
                    664:                 $output .= join('","',sort(@{$by_year->{$sorted_yrs[$i]}->{$sorted_depts[$j]}})).'");'."\n";
                    665:             }
                    666:         }
                    667:     }
                    668:     @unsorted = keys(%{$by_sem});
                    669:     my @sorted_sems;
                    670:     &Apache::courseclassifier::sort_cats('1',$cat_order,$codetitles,\@unsorted,\@sorted_sems);
                    671:     $output .=  'idcse_by_sem_sems = new Array("'.join('","',@sorted_sems).'");'."\n".
                    672:                 'idcse_by_sem_dept = new Array('.scalar(@sorted_sems).');'."\n".
                    673:                 'idcse_by_sem_num = new Array('.scalar(@sorted_sems).');'."\n";
                    674:     for (my $i=0; $i<@sorted_sems; $i++) {
                    675:         my $numkeys = keys(%{$by_sem->{$sorted_sems[$i]}});
                    676:         $output .= " idcse_by_sem_num[$i] = new Array($numkeys);\n";
                    677:         if (ref($by_sem->{$sorted_sems[$i]}) eq 'HASH') {
                    678:             @unsorted = keys(%{$by_sem->{$sorted_sems[$i]}});
                    679:             my @sorted_depts;
                    680:             &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_depts);
                    681:             $output .= qq| idcse_by_sem_dept[$i] = new Array("|.join('","',@sorted_depts).'");'."\n";
                    682:             for (my $j=0; $j<@sorted_depts; $j++) {
                    683:                 $output .= qq| idcse_by_sem_num[$i][$j] = new Array ("|.join('","',sort(@{$by_sem->{$sorted_sems[$i]}->{$sorted_depts[$j]}})).'");'."\n";
                    684:             }
                    685:         }
                    686:     }
                    687:     @unsorted = keys(%{$by_dept});
                    688:     my @sorted_deps;
                    689:     &Apache::courseclassifier::sort_cats('2',$cat_order,$codetitles,\@unsorted,\@sorted_deps);
                    690:     $output .= 'idcse_by_dep = new Array('.scalar(@sorted_deps).');'."\n"; 
                    691:     for (my $k=0; $k<@sorted_deps; $k++) {
                    692:         $output .= qq| idcse_by_dep[$k] = new Array ("|.join('","',sort(@{$by_dept->{$sorted_deps[$k]}})).'");'."\n";
                    693:     }
                    694:     return $output;
                    695: }
                    696: 
1.28      raeburn   697: sub search_official_courselist {
1.18      raeburn   698:     my ($domain,$numtitles) = @_;
                    699:     my $instcode;
                    700:     if (defined($numtitles) && $numtitles == 0) {
                    701:         $instcode = '.+';
                    702:     } else {
                    703:         my (%codedefaults,@code_order);
                    704:         my $defaults_result = 
                    705:             &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
                    706:                                                     \@code_order);
                    707:         if ($defaults_result eq 'ok') {
                    708:             $instcode ='^';
                    709:             foreach my $item (@code_order) {
                    710:                 if ($env{'form.'.$item} eq '0' ) {
                    711:                     $instcode .= $codedefaults{$item}; 
                    712:                 } else {
                    713:                     $instcode .= $env{'form.'.$item};
                    714:                 }
1.7       raeburn   715:             }
1.18      raeburn   716:             $instcode .= '$';
                    717:         } else {
                    718:             $instcode = '.';
1.7       raeburn   719:         }
                    720:     }
1.32      raeburn   721:     my $showhidden;
                    722:     if (&user_is_dc($domain)) {
                    723:         $showhidden = $env{'form.showhidden'};
                    724:     }
                    725:     my %courses = 
                    726:         &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
                    727:                                       'Course',1,$env{'form.showselfenroll'},undef,
                    728:                                       $showhidden,'coursecatalog');
1.7       raeburn   729:     return %courses;
                    730: }
                    731: 
1.28      raeburn   732: sub search_courselist {
1.36      raeburn   733:     my ($domain,$subcats) = @_;
1.28      raeburn   734:     my $cat_maxdepth = $env{'form.catalog_maxdepth'};
                    735:     my $filter = $env{'form.currcat_'.$cat_maxdepth};
1.29      raeburn   736:     if (($filter eq '') && ($cat_maxdepth > 0)) {
                    737:         my $shallower = $cat_maxdepth - 1;
                    738:         $filter = $env{'form.currcat_'.$shallower};
                    739:     }
1.28      raeburn   740:     my %courses;
1.36      raeburn   741:     my $filterstr;
1.28      raeburn   742:     if ($filter ne '') {
1.36      raeburn   743:         if ($env{'form.withsubcats'}) {
                    744:             if (ref($subcats) eq 'HASH') {
                    745:                 if (ref($subcats->{$filter}) eq 'ARRAY') {
                    746:                     $filterstr = join('&',@{$subcats->{$filter}});
                    747:                     if ($filterstr ne '') {
                    748:                         $filterstr = $filter.'&'.$filterstr;
                    749:                     }
                    750:                 } else {
                    751:                     $filterstr = $filter;
                    752:                 }
                    753:             } else {
                    754:                 $filterstr = $filter;
                    755:             }  
                    756:         } else {
                    757:             $filterstr = $filter; 
                    758:         }
1.32      raeburn   759:         my $showhidden;
                    760:         if (&user_is_dc($domain)) {
                    761:             $showhidden = $env{'form.showhidden'};
                    762:         }
                    763:         %courses = 
                    764:             &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
                    765:                                           '.',1,$env{'form.showselfenroll'},
1.36      raeburn   766:                                           $filterstr,$showhidden,'coursecatalog');
1.28      raeburn   767:     }
                    768:     return %courses;
                    769: }
1.6       raeburn   770: 
1.1       raeburn   771: sub print_course_listing {
1.36      raeburn   772:     my ($domain,$numtitles,$trails,$allitems,$subcats) = @_;
1.1       raeburn   773:     my $output;
1.7       raeburn   774:     my %courses;
1.15      raeburn   775:     my $knownuser = &user_is_known();
1.16      raeburn   776:     my $details = $env{'form.coursenum'};
                    777:     if (&user_is_dc($domain)) {
                    778:         if ($env{'form.showdetails'}) {
                    779:             $details = 1;
                    780:         }
                    781:     }
1.7       raeburn   782:     if ($env{'form.coursenum'} ne '') {
                    783:         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
                    784:                                                  $env{'form.coursenum'},
1.33      raeburn   785:                                                  undef,undef,'.',1);
1.7       raeburn   786:         if (keys(%courses) == 0) {
                    787:             $output .= &mt('The courseID provided does not match a course in this domain.');
                    788:             return $output;
                    789:         }
1.6       raeburn   790:     } else {
1.28      raeburn   791:         if ($env{'form.currcat_0'} eq 'instcode::0') {
                    792:             %courses = &search_official_courselist($domain,$numtitles);
                    793:         } else {
1.36      raeburn   794:             %courses = &search_courselist($domain,$subcats);
1.28      raeburn   795:         }
1.7       raeburn   796:         if (keys(%courses) == 0) {
                    797:             $output = &mt('No courses match the criteria you selected.');
                    798:             return $output;
                    799:         }
1.32      raeburn   800:         if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) {
1.31      bisitz    801:             $output = '<b>'.&mt('Note for students:').'</b> '
                    802:                      .&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.')
                    803:                      .'<br /><br />';
1.8       raeburn   804:         }
1.7       raeburn   805:     }
1.27      raeburn   806:     my $now = time;
                    807:     my %domconfig =
                    808:         &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
1.35      raeburn   809:     $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems);
1.41      raeburn   810:     $output .= "\n".'<form name="linklaunch" method="post" action="">'.
1.40      raeburn   811:                '<input type="hidden" name="backto" value="coursecatalog" />'.
1.41      raeburn   812:                '<input type="hidden" name="courseid" value="" />'.
                    813:                &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
1.15      raeburn   814:     return $output;
                    815: }
                    816: 
                    817: sub construct_data_table {
1.35      raeburn   818:     my ($knownuser,$courses,$details,$usersections,$now,$domconfig,$trails,
                    819:         $allitems) = @_;
1.7       raeburn   820:     my %sortname;
1.16      raeburn   821:     if (($details eq '') || ($env{'form.showdetails'})) {
1.7       raeburn   822:         $sortname{'Code'} = 'code';
1.35      raeburn   823:         $sortname{'Categories'} = 'cats';
1.7       raeburn   824:         $sortname{'Title'} = 'title';
1.22      raeburn   825:         $sortname{'Owner(s)'} = 'owner';
1.7       raeburn   826:     }
1.15      raeburn   827:     my $output = &Apache::loncommon::start_data_table().
                    828:                  &Apache::loncommon::start_data_table_header_row();
1.35      raeburn   829:     my @coltitles = ('Count');
                    830:     if ($env{'form.currcat_0'} eq 'instcode::0') {
                    831:         push(@coltitles,'Code');
                    832:     } else {
                    833:         push(@coltitles,'Categories');
                    834:     }
                    835:     push(@coltitles,('Sections','Crosslisted','Title','Owner(s)'));
1.15      raeburn   836:     if (ref($usersections) eq 'HASH') {
                    837:        $coltitles[1] = 'Your Section';
                    838:     }
1.7       raeburn   839:     foreach my $item (@coltitles) {
                    840:         $output .= '<th>';
                    841:         if (defined($sortname{$item})) {
                    842:             $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
1.24      raeburn   843:         } elsif ($item eq 'Count') {
                    844:             $output .= '&nbsp;&nbsp;';
1.7       raeburn   845:         } else {
                    846:             $output .= &mt($item);
                    847:         }
                    848:         $output .= '</th>';
1.1       raeburn   849:     }
1.15      raeburn   850:     if ($knownuser) {
                    851:         if ($details) {
1.8       raeburn   852:             $output .=
1.7       raeburn   853:               '<th>'.&mt('Default Access Dates for Students').'</th>'.
                    854:               '<th>'.&mt('Student Counts').'</th>'.
1.42      bisitz    855:               '<th>'.&mt('Auto-enrollment of[_1]registered students','<br />').'</th>';
1.15      raeburn   856:         } else {
1.27      raeburn   857:             $output .= '<th>'.&mt('Details').'</th>';
1.8       raeburn   858:         }
1.1       raeburn   859:     }
1.27      raeburn   860:     $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
1.7       raeburn   861:     &Apache::loncommon::end_data_table_header_row();
1.15      raeburn   862:     my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$details,
                    863:                                             $usersections);
1.7       raeburn   864:     my %Sortby;
1.15      raeburn   865:     foreach my $course (sort(keys(%{$courses}))) {
1.7       raeburn   866:         if ($env{'form.sortby'} eq 'code') {
                    867:             push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
1.35      raeburn   868:         } elsif ($env{'form.sortby'} eq 'cats') {
                    869:             push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
1.7       raeburn   870:         } elsif ($env{'form.sortby'} eq 'owner') {
1.22      raeburn   871:             push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
1.7       raeburn   872:         } else {
1.25      raeburn   873:             my $clean_title = $courseinfo{$course}{'title'};
                    874:             $clean_title =~ s/\W+//g;
                    875:             if ($clean_title eq '') {
                    876:                 $clean_title = $courseinfo{$course}{'title'};
                    877:             }
                    878:             push(@{$Sortby{$clean_title}},$course);
1.7       raeburn   879:         }
                    880:     }
                    881:     my @sorted_courses;
1.35      raeburn   882:     if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
                    883:         ($env{'form.sortby'} eq 'cats')) {
1.7       raeburn   884:         @sorted_courses = sort(keys(%Sortby));
1.6       raeburn   885:     } else {
1.7       raeburn   886:         @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
1.1       raeburn   887:     }
1.24      raeburn   888:     my $count = 1;
1.7       raeburn   889:     foreach my $item (@sorted_courses) {
                    890:         foreach my $course (@{$Sortby{$item}}) {
                    891:             $output.=&Apache::loncommon::start_data_table_row(); 
1.35      raeburn   892:             $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
                    893:                                      \$count,$now,$course,$trails,$allitems);
1.7       raeburn   894:             $output.=&Apache::loncommon::end_data_table_row();
                    895:         }
1.1       raeburn   896:     }
1.7       raeburn   897:     $output .= &Apache::loncommon::end_data_table();
                    898:     return $output;
                    899: }
                    900: 
                    901: sub build_courseinfo_hash {
1.15      raeburn   902:     my ($courses,$knownuser,$details,$usersections) = @_;
1.1       raeburn   903:     my %courseinfo;
1.7       raeburn   904:     my $now = time;
1.15      raeburn   905:     foreach my $course (keys(%{$courses})) {
1.1       raeburn   906:         my $descr;
1.22      raeburn   907:         if (ref($courses->{$course}) eq 'HASH') {
                    908:             $descr = $courses->{$course}{'description'}; 
1.1       raeburn   909:         }
                    910:         my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
                    911:         $cleandesc=~s/'/\\'/g;
1.10      raeburn   912:         $cleandesc =~ s/^\s+//;
1.1       raeburn   913:         my ($cdom,$cnum)=split(/\_/,$course);
1.39      raeburn   914:         my ($instcode,$singleowner,$ttype,$selfenroll_types,
1.35      raeburn   915:             $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
1.22      raeburn   916:         if (ref($courses->{$course}) eq 'HASH') {
                    917:             $descr = $courses->{$course}{'description'};
1.23      raeburn   918:             $instcode =  $courses->{$course}{'inst_code'};
1.22      raeburn   919:             $singleowner = $courses->{$course}{'owner'};
                    920:             $ttype =  $courses->{$course}{'type'};
1.27      raeburn   921:             $selfenroll_types = $courses->{$course}{'selfenroll_types'};
                    922:             $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
                    923:             $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
1.35      raeburn   924:             $categories = $courses->{$course}{'categories'};
1.22      raeburn   925:             push(@owners,$singleowner);
                    926:             if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
                    927:                 foreach my $item (@{$courses->{$course}{'co-owners'}}) {
                    928:                     push(@owners,$item);
                    929:                 }
                    930:             }
                    931:         }
                    932:         foreach my $owner (@owners) {
                    933:             my ($ownername,$ownerdom) = @_; 
                    934:             if ($owner =~ /:/) {
                    935:                 ($ownername,$ownerdom) = split(/:/,$owner);
                    936:             } else {
                    937:                 $ownername = $owner;
                    938:                 if ($owner ne '') {
                    939:                     $ownerdom = $cdom;
                    940:                 }
                    941:             }
                    942:             if ($ownername ne '' && $ownerdom ne '') {
                    943:                 my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
                    944:                 $ownernames{$ownername.':'.$ownerdom} = \%namehash; 
1.1       raeburn   945:             }
                    946:         }
                    947:         $courseinfo{$course}{'cdom'} = $cdom;
                    948:         $courseinfo{$course}{'cnum'} = $cnum;
                    949:         $courseinfo{$course}{'code'} = $instcode;
1.22      raeburn   950:         my @lastnames;
                    951:         foreach my $owner (keys(%ownernames)) {
                    952:             if (ref($ownernames{$owner}) eq 'HASH') {
                    953:                 push(@lastnames,$ownernames{$owner}{'lastname'});
                    954:             }
                    955:         }
                    956:         $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
1.1       raeburn   957:         $courseinfo{$course}{'title'} = $cleandesc;
1.22      raeburn   958:         $courseinfo{$course}{'owner'} = $singleowner;
1.27      raeburn   959:         $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
                    960:         $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
                    961:         $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
1.35      raeburn   962:         $courseinfo{$course}{'categories'} = $categories;
1.7       raeburn   963: 
                    964:         my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
                    965:         my @classids;
                    966:         my @crosslistings;
1.15      raeburn   967:         my ($seclist,$numsec) = 
                    968:             &identify_sections($coursehash{'internal.sectionnums'});
                    969:         if (ref($usersections) eq 'HASH') {
                    970:             if (ref($usersections->{$course}) eq 'ARRAY') {
                    971:                 $seclist = join(', ',@{$usersections->{$course}});
                    972:             }
                    973:         }
1.7       raeburn   974:         $courseinfo{$course}{'seclist'} = $seclist;
1.15      raeburn   975:         my ($xlist_items,$numxlist) = 
                    976:             &identify_sections($coursehash{'internal.crosslistings'});
1.7       raeburn   977:         my $showsyllabus = 1; # default is to include a syllabus link
                    978:         if (defined($coursehash{'showsyllabus'})) {
                    979:             $showsyllabus = $coursehash{'showsyllabus'};
                    980:         }
                    981:         $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
1.15      raeburn   982:         if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
1.22      raeburn   983:             ($knownuser && ($details == 1))) {
1.15      raeburn   984:             $courseinfo{$course}{'counts'} =  &count_students($cdom,$cnum,$numsec);
                    985:             $courseinfo{$course}{'autoenrollment'} =
                    986:                 &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
1.22      raeburn   987:                                  $instcode,\@owners,$cdom,$cnum);
1.15      raeburn   988: 
                    989:             my $startaccess = '';
                    990:             my $endaccess = '';
                    991:             my $accessdates;
                    992:             if ( defined($coursehash{'default_enrollment_start_date'}) ) {
                    993:                 $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
                    994:             }
                    995:             if ( defined($coursehash{'default_enrollment_end_date'}) ) {
                    996:                 $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
                    997:                 if ($coursehash{'default_enrollment_end_date'} == 0) {
1.34      raeburn   998:                     $endaccess = &mt('No ending date');
1.15      raeburn   999:                 }
                   1000:             }
                   1001:             if ($startaccess) {
1.42      bisitz   1002:                 $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
1.7       raeburn  1003:             }
1.15      raeburn  1004:             if ($endaccess) {
1.42      bisitz   1005:                 $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
1.15      raeburn  1006:             }
1.34      raeburn  1007:             if (($selfenroll_types ne '') && 
                   1008:                 ($selfenroll_end > 0 && $selfenroll_end > $now)) {
                   1009:                 my ($selfenroll_start_access,$selfenroll_end_access);
                   1010:                 if (($coursehash{'default_enrollment_start_date'} ne 
                   1011:                      $coursehash{'internal.selfenroll_start_access'}) ||
                   1012:                    ($coursehash{'default_enrollment_end_date'} ne 
                   1013:                     $coursehash{'internal.selfenroll_end_access'})) {
                   1014:                     if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
                   1015:                         $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
                   1016:                     }
                   1017:                     if ( defined($coursehash{'default_enrollment_end_date'}) ) {
                   1018:                         $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
                   1019:                         if ($coursehash{'internal.selfenroll_end_access'} == 0) {
                   1020:                             $selfenroll_end_access = &mt('No ending date');
                   1021:                         }
                   1022:                     }
                   1023:                     if ($selfenroll_start_access || $selfenroll_end_access) {
                   1024:                         $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
                   1025:                         if ($selfenroll_start_access) {
1.42      bisitz   1026:                             $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$selfenroll_start_access).'<br />';
1.34      raeburn  1027:                         }
                   1028:                         if ($selfenroll_end_access) {
1.42      bisitz   1029:                             $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$selfenroll_end_access).'<br />';
1.34      raeburn  1030:                         }
                   1031:                     }
                   1032:                 }
                   1033:             }
1.15      raeburn  1034:             $courseinfo{$course}{'access'} = $accessdates;
1.1       raeburn  1035:         }
1.7       raeburn  1036:         if ($xlist_items eq '') {
                   1037:             $xlist_items = &mt('No');
1.1       raeburn  1038:         }
1.7       raeburn  1039:         $courseinfo{$course}{'xlist'} = $xlist_items;
1.1       raeburn  1040:     }
1.7       raeburn  1041:     return %courseinfo;
1.1       raeburn  1042: }
                   1043: 
1.7       raeburn  1044: sub count_students {
1.15      raeburn  1045:     my ($cdom,$cnum,$numsec) = @_;
1.1       raeburn  1046:     my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.7       raeburn  1047:     my %student_count = (
                   1048:                            Active => 0,
                   1049:                            Future => 0,
                   1050:                            Expired => 0,
                   1051:                        );
1.1       raeburn  1052:     my %idx;
                   1053:     $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
1.4       albertel 1054:     my %status_title = &Apache::lonlocal::texthash(
1.1       raeburn  1055:                            Expired => 'Previous access',
                   1056:                            Active => 'Current access',
                   1057:                            Future => 'Future access',
                   1058:                        );
1.7       raeburn  1059: 
1.4       albertel 1060:     while (my ($student,$data) = each(%$classlist)) {
1.1       raeburn  1061:         $student_count{$data->[$idx{'status'}]} ++;
                   1062:     }
1.7       raeburn  1063: 
1.43      bisitz   1064:     my $countslist = &mt('[quant,_1,section:,sections:,No sections]',$numsec).'<br />';
1.7       raeburn  1065:     foreach my $status ('Active','Future') {
1.43      bisitz   1066:         $countslist .= '<span class="LC_nobreak">'.$status_title{$status}.': '.
                   1067:                        $student_count{$status}.'</span><br />';
1.1       raeburn  1068:     }
1.7       raeburn  1069:     return $countslist;
                   1070: }
                   1071: 
                   1072: sub courseinfo_row {
1.35      raeburn  1073:     my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems) = @_;
1.7       raeburn  1074:     my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
1.35      raeburn  1075:         $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories);
1.7       raeburn  1076:     if (ref($info) eq 'HASH') {
                   1077:         $cdom = $info->{'cdom'};
                   1078:         $cnum = $info->{'cnum'};
                   1079:         $title = $info->{'title'};
1.22      raeburn  1080:         $ownerlast = $info->{'ownerlastnames'};
1.7       raeburn  1081:         $code = $info->{'code'};
                   1082:         $owner = $info->{'owner'};
                   1083:         $seclist = $info->{'seclist'};
                   1084:         $xlist_items = $info->{'xlist'};
                   1085:         $accessdates = $info->{'access'};
                   1086:         $counts = $info->{'counts'};
                   1087:         $autoenrollment = $info->{'autoenrollment'};
                   1088:         $showsyllabus = $info->{'showsyllabus'};
1.35      raeburn  1089:         $categories = $info->{'categories'};
1.7       raeburn  1090:     } else {
                   1091:         $output = '<td colspan="8">'.&mt('No information available for [_1].',
                   1092:                                          $code).'</td>';
                   1093:         return $output;
1.2       raeburn  1094:     }
1.35      raeburn  1095:     $output .= '<td>'.$$countref.'</td>';
                   1096:     if ($env{'form.currcat_0'} eq 'instcode::0') {
                   1097:         $output .= '<td>'.$code.'</td>';
                   1098:     } else {
                   1099:         my ($categorylist,@cats);
                   1100:         if ($categories ne '') {
                   1101:             @cats = split('&',$categories);
                   1102:         }
                   1103:         if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
                   1104:             my @categories = map { $trails->[$allitems->{$_}]; } @cats;
                   1105:             $categorylist = join('<br />',@categories);
                   1106:         }
                   1107:         if ($categorylist eq '') {
                   1108:             $categorylist = '&nbsp;';
                   1109:         }
                   1110:         $output .= '<td>'.$categorylist.'</td>';
                   1111:     }
                   1112:     $output .= '<td>'.$seclist.'</td>'.
1.7       raeburn  1113:                '<td>'.$xlist_items.'</td>'.
                   1114:                '<td>'.$title.'&nbsp;<font size="-2">';
1.2       raeburn  1115:     if ($showsyllabus) {
1.40      raeburn  1116:         $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum'".')">'.&mt('Syllabus').'</a>';
1.7       raeburn  1117:     } else {
                   1118:         $output .= '&nbsp;';
1.2       raeburn  1119:     }
                   1120:     $output .= '</font></td>'.
1.7       raeburn  1121:                '<td>'.$ownerlast.'</td>';
1.15      raeburn  1122:     if ($knownuser) {
                   1123:         if ($details) {
1.8       raeburn  1124:             $output .=
1.7       raeburn  1125:                '<td>'.$accessdates.'</td>'. 
                   1126:                '<td>'.$counts.'</td>'.
                   1127:                '<td>'.$autoenrollment.'</td>';
1.15      raeburn  1128:         } else {
                   1129:             $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
1.8       raeburn  1130:         }
1.7       raeburn  1131:     }
1.27      raeburn  1132:     my $selfenroll;
                   1133:     if ($info->{'selfenroll_types'}) {
                   1134:         my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
                   1135:         my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
                   1136:         if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
                   1137:             if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
                   1138:                 $output .= '<td>'.&mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>').'</td>';
                   1139:             } else { 
1.41      raeburn  1140:                 $output .= '<td><a href="javascript:ToSelfenroll('."'$course'".')">'.&mt('Enroll in course').'</a></td>';
1.27      raeburn  1141:             }
                   1142:             $selfenroll = 1;
                   1143:         }
                   1144:     }
                   1145:     if (!$selfenroll) {
                   1146:         $output .= '<td>&nbsp;</td>';
                   1147:     }
1.24      raeburn  1148:     $$countref ++;
1.1       raeburn  1149:     return $output;
                   1150: }
                   1151: 
                   1152: sub identify_sections {
                   1153:     my ($seclist) = @_;
                   1154:     my @secnums;
                   1155:     if ($seclist =~ /,/) {
1.4       albertel 1156:         my @sections = split(/,/,$seclist);
1.1       raeburn  1157:         foreach my $sec (@sections) {
                   1158:             $sec =~ s/:[^:]*$//;
                   1159:             push(@secnums,$sec);
                   1160:         }
                   1161:     } else {
                   1162:         if ($seclist =~ m/^([^:]+):/) {
                   1163:             my $sec = $1;
1.4       albertel 1164:             if (!grep(/^\Q$sec\E$/,@secnums)) {
                   1165:                 push(@secnums,$sec);
1.1       raeburn  1166:             }
                   1167:         }
                   1168:     }
                   1169:     @secnums = sort {$a <=> $b} @secnums;
1.39      raeburn  1170:     $seclist = join(', ',@secnums);
1.15      raeburn  1171:     my $numsec = @secnums;
                   1172:     return ($seclist,$numsec);
1.1       raeburn  1173: }
                   1174: 
1.2       raeburn  1175: sub get_valid_classes {
1.22      raeburn  1176:     my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
1.2       raeburn  1177:     my $response;
                   1178:     my %validations;
                   1179:     @{$validations{'sections'}} = ();
                   1180:     @{$validations{'xlists'}} = ();
                   1181:     my $totalitems = 0;
                   1182:     if ($seclist) {
1.13      raeburn  1183:         foreach my $sec (split(/, /,$seclist)) {
1.2       raeburn  1184:             my $class = $crscode.$sec;
1.22      raeburn  1185:             if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1.3       albertel 1186: 							 $class) eq 'ok') {
1.2       raeburn  1187:                 if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
1.4       albertel 1188:                     push(@{$validations{'sections'}},$sec);
1.2       raeburn  1189:                     $totalitems ++;
                   1190:                 }
                   1191:             }
                   1192:         }
                   1193:     }
                   1194:     if ($xlist_items) {
1.13      raeburn  1195:         foreach my $item (split(/, /,$xlist_items)) {
1.22      raeburn  1196:             if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
1.3       albertel 1197: 							 $item) eq 'ok') {
1.2       raeburn  1198:                 if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
1.4       albertel 1199:                     push(@{$validations{'xlists'}},$item);
1.2       raeburn  1200:                     $totalitems ++;
                   1201:                 }
                   1202:             }
                   1203:         }
                   1204:     }
                   1205:     if ($totalitems > 0) {
                   1206:         if (@{$validations{'sections'}}) {
1.42      bisitz   1207:             $response = &mt('Sections:').' '.
1.14      raeburn  1208:                         join(', ',@{$validations{'sections'}}).'<br />';
1.2       raeburn  1209:         }
                   1210:         if (@{$validations{'xlists'}}) {
1.42      bisitz   1211:             $response .= &mt('Courses:').' '.
1.14      raeburn  1212:                         join(', ',@{$validations{'xlists'}});
1.2       raeburn  1213:         }
                   1214:     }
                   1215:     return $response;
                   1216: }
                   1217: 
1.6       raeburn  1218: sub javascript_select_filler {
                   1219:     my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
                   1220:     my $output = <<END;
                   1221: function courseSet() {
                   1222:     var longtitles = new Array ("$longtitles_str");
                   1223:     var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
                   1224:     var valsem  = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
                   1225:     var valdept = document.$formname.Department.options[document.$formname.Department.selectedIndex].value
                   1226:     var valclass = document.$formname.Number.options[document.$formname.Number.selectedIndex].value
                   1227:     var idyears = new Array("$allidlist");
                   1228:     var idyr = -1;
                   1229:     var idsem = -1;
                   1230:     var iddept = -1;
                   1231:     document.$formname.Number.length = 0;
                   1232: 
                   1233:     $scripttext
                   1234: 
                   1235:     selYear = document.$formname.Year.selectedIndex-1;
                   1236:     selSemester = document.$formname.Semester.selectedIndex-1;
                   1237:     selDepartment = document.$formname.Department.selectedIndex-1;
                   1238:     if (selYear == -1) {
                   1239:         if (selSemester == -1) {
                   1240:             if (selDepartment > -1) {
                   1241:                 document.$formname.Number.options[0] =  new Option('All','0',false,false);
                   1242:                 for (var k=0; k<idcse_by_dep[selDepartment].length; k++) {
                   1243:                     document.$formname.Number.options[k+1] = new Option(idcse_by_dep[selDepartment][k],idcse_by_dep[selDepartment][k],false,false);
                   1244: 
                   1245:                 }
                   1246:             } 
                   1247:             else {
                   1248:                 document.$formname.Number.options[0] = new Option("All","0",true,true);
                   1249:             }
                   1250:         }
                   1251:         else {
                   1252:             if (selDepartment > -1) {
                   1253:                 for (var i=0; i<idcse_by_sem_sems.length; i++) {
                   1254:                     if (idcse_by_sem_sems[i] == valsem) {
                   1255:                         idsem = i;
                   1256:                     }
                   1257:                 }
                   1258:                 if (idsem != -1) {
                   1259:                     for (var i=0; i<idcse_by_sem_dept[idsem].length; i++) {
                   1260:                         if (idcse_by_sem_dept[idsem][i] == valdept) {
                   1261:                             iddept = i;
                   1262:                         }
                   1263:                     }
                   1264:                 }
                   1265:                 if (iddept != -1) {
                   1266:                     document.$formname.Number.options[0] =  new Option('All','0',false,false);
                   1267:                     for (var k=0; k<idcse_by_sem_num[idsem][iddept].length; k++) {
                   1268:                         document.$formname.Number.options[k+1] = new Option(idcse_by_sem_num[idsem][iddept][k],idcse_by_sem_num[idsem][iddept][k],false,false);
                   1269:                     }
                   1270:                 }
                   1271:                 else {
                   1272:                     document.$formname.Number.options[0] =  new Option('No courses','0',true,true);
                   1273:                 }
                   1274:             }
                   1275:             else {
                   1276:                 document.$formname.Number.options[0] = new Option("All","0",true,true);
                   1277:             }
                   1278:         }
                   1279:     }
                   1280:     else {
                   1281:         if (selSemester == -1) {
                   1282:             if (selDepartment > -1) {
                   1283:                 for (var i=0; i<idcse_by_yr_year.length; i++) {
                   1284:                     if (idcse_by_yr_year[i] == valyr) {
                   1285:                         idyr = i;
                   1286:                     }
                   1287:                 }
                   1288:                 if (idyr != -1) {      
                   1289:                     for (var i=0; i<idcse_by_yr_dept[idyr].length; i++) {
                   1290:                         if (idcse_by_yr_dept[idyr][i] == valdept) {
                   1291:                             iddept = i;
                   1292:                         }
                   1293:                     }
                   1294:                 }
                   1295:                 if (iddept != -1) {
                   1296:                     document.$formname.Number.options[0] =  new Option('All','0',false,false);
                   1297:                     for (var k=0; k<idcse_by_yr_num[idyr][iddept].length; k++) {
                   1298:                         document.$formname.Number.options[k+1] = new Option(idcse_by_yr_num[idyr][iddept][k],idcse_by_yr_num[idyr][iddept][k],false,false);
                   1299:                     }
                   1300:                 } 
                   1301:                 else {
                   1302:                     document.$formname.Number.options[0] =  new Option('No courses','0',true,true);
                   1303:                 }
                   1304:             }
                   1305:             else {
                   1306:                 document.$formname.Number.options[0] = new Option("All","0",true,true);
                   1307:             }
                   1308:         }
                   1309:         else {
1.9       raeburn  1310:             if (selDepartment > -1) {
                   1311:                 for (var k=0; k<idyears.length; k++) {
                   1312:                     if (idyears[k] == valyr) {
                   1313:                         idyr = k;
                   1314:                     }
1.6       raeburn  1315:                 }
1.9       raeburn  1316:                 if (idyr != -1) {
                   1317:                     for (var k=0; k<idsems[idyr].length; k++) {
                   1318:                         if (idsems[idyr][k] == valsem) {
                   1319:                             idsem = k;
                   1320:                         }
1.6       raeburn  1321:                     }
                   1322:                 }
1.9       raeburn  1323:                 if (idsem != -1) {
                   1324:                     for (var k=0; k<idcodes[idyr][idsem].length; k++) {
                   1325:                         if (idcodes[idyr][idsem][k] == valdept) {
                   1326:                             iddept = k;
                   1327:                         }
1.6       raeburn  1328:                     }
                   1329:                 }
1.9       raeburn  1330:                 if (iddept != -1) {
                   1331:                     document.$formname.Number.options[0] =  new Option('All','0',false,false);
                   1332:                     for (var i=0; i<idcourses[idyr][idsem][iddept].length; i++) {
                   1333:                         var display = idcourses[idyr][idsem][iddept][i];
                   1334:                         if (longtitles[3] == 1) {
                   1335:                             if (idcourseslongs[idyr][idsem][iddept][i] != "") {
                   1336:                                 display = idcourseslongs[idyr][idsem][iddept][i]
                   1337:                             }
1.6       raeburn  1338:                         }
1.9       raeburn  1339:                         document.$formname.Number.options[i+1] = new Option(display,idcourses[idyr][idsem][iddept][i],false,false)
1.6       raeburn  1340:                     }
1.9       raeburn  1341:                 } 
                   1342:                 else {
                   1343:                     document.$formname.Number.options[0] =  new Option('No courses','0',true,true);
1.6       raeburn  1344:                 }
1.9       raeburn  1345:             } 
1.6       raeburn  1346:             else {
1.9       raeburn  1347:                 document.$formname.Number.options[0] =  new Option('All','0',true,true);
1.6       raeburn  1348:             }
                   1349:         }
                   1350:         document.$formname.Number.selectedIndex = 0
                   1351:     }
                   1352: }
                   1353: END
                   1354:     return $output;
                   1355: }
1.1       raeburn  1356: 
1.7       raeburn  1357: sub autoenroll_info {
1.22      raeburn  1358:     my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
1.7       raeburn  1359:     my $autoenrolldates = &mt('Not enabled');
                   1360:     if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
                   1361:         my ($autostart,$autoend);
                   1362:         if ( defined($coursehash->{'internal.autostart'}) ) {
                   1363:             $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
                   1364:         }
                   1365:         if ( defined($coursehash->{'internal.autoend'}) ) {
                   1366:             $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
                   1367:         }
                   1368:         if ($coursehash->{'internal.autostart'} > $now) {
                   1369:             if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
                   1370:                 $autoenrolldates = &mt('Not enabled');
                   1371:             } else {
                   1372:                 my $valid_classes = 
                   1373:                    &get_valid_classes($seclist,$xlist_items,$code,
1.22      raeburn  1374:                                       $owners,$cdom,$cnum);
1.7       raeburn  1375:                 if ($valid_classes ne '') {
1.42      bisitz   1376:                     $autoenrolldates = &mt('Not enabled').'<br />'
                   1377:                                       .&mt('Starts: [_1]',$autostart)
                   1378:                                       .'<br />'.$valid_classes;
                   1379:                 }
1.7       raeburn  1380:             }
                   1381:         } else {
                   1382:             if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
1.42      bisitz   1383:                 $autoenrolldates = &mt('Not enabled').'<br />'
                   1384:                                   .&mt('Ended: [_1]',$autoend);
1.7       raeburn  1385:             } else {
                   1386:                 my $valid_classes = &get_valid_classes($seclist,$xlist_items,
1.22      raeburn  1387:                                                        $code,$owners,$cdom,$cnum);
1.7       raeburn  1388:                 if ($valid_classes ne '') {
1.42      bisitz   1389:                     $autoenrolldates = &mt('Currently enabled').'<br />'.
1.7       raeburn  1390:                                        $valid_classes;
                   1391:                 }
                   1392:             }
                   1393:         }
                   1394:     }
                   1395:     return $autoenrolldates;
                   1396: }
                   1397: 
1.8       raeburn  1398: sub user_is_known {
                   1399:     my $known = 0;
                   1400:     if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public' 
                   1401:         && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
                   1402:         $known = 1;
                   1403:     }
                   1404:     return $known;
                   1405: }
                   1406: 
1.1       raeburn  1407: 1;

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