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

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

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