File:  [LON-CAPA] / loncom / interface / coursecatalog.pm
Revision 1.88.2.8: download - view: text, annotated - select for diffs
Sun Jun 20 17:49:08 2021 UTC (2 years, 11 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.105

    1: # The LearningOnline Network with CAPA
    2: # Handler for displaying the course catalog interface
    3: #
    4: # $Id: coursecatalog.pm,v 1.88.2.8 2021/06/20 17:49:08 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::coursecatalog;
   30: 
   31: use strict;
   32: use lib qw(/home/httpd/lib/perl);
   33: use Apache::Constants qw(:common);
   34: use Apache::loncommon;
   35: use Apache::lonhtmlcommon;
   36: use Apache::lonnet;
   37: use Apache::lonlocal;
   38: use Apache::courseclassifier;
   39: use Apache::lonacc;
   40: use LONCAPA;
   41: use LONCAPA::lonauthcgi;
   42: 
   43: sub handler {
   44:     my ($r) = @_;
   45:     &Apache::loncommon::content_type($r,'text/html');
   46:     $r->send_http_header;
   47:     if ($r->header_only) {
   48:         return OK;
   49:     }
   50:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   51:     my $lonidsdir=$r->dir_config('lonIDsDir');
   52:     if ($handle ne '') {
   53:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   54:     }
   55:     &Apache::lonacc::get_posted_cgi($r);
   56:     &Apache::lonlocal::get_language_handle($r);
   57:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   58:                                             ['sortby','showdom']);
   59: 
   60:     my $codedom = &Apache::lonnet::default_login_domain();
   61: 
   62:     if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) { 
   63:         $codedom = $env{'user.domain'};
   64:         if ($env{'request.role.domain'} ne '') {
   65:             $codedom = $env{'request.role.domain'};
   66:         }
   67:     }
   68:     my $formname = 'coursecatalog';
   69:     if ($env{'form.showdom'} ne '') {
   70:         $env{'form.showdom'} = &LONCAPA::clean_domain($env{'form.showdom'});
   71:         if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
   72:             $codedom = $env{'form.showdom'};
   73:         } else {
   74:             $env{'form.showdom'} = '';
   75:         }
   76:     }
   77:     my $domdesc = &Apache::lonnet::domain($codedom,'description');
   78:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   79: 
   80:     my $crscats = &Apache::lonnet::get_dom_cats($codedom);
   81:     my %domdefaults = &Apache::lonnet::get_domain_defaults($codedom);
   82:     my $knownuser = &user_is_known();
   83:     my $canviewall = &canview_all($knownuser,$codedom);
   84:     
   85:     my ($cathash,$cattype);
   86:     if (ref($crscats) eq 'HASH') {
   87:         %{$cathash} = %{$crscats};
   88:     } else {
   89:         $cathash = {};
   90:     }
   91:     if ($knownuser || $canviewall) {
   92:         $cattype = $domdefaults{'catauth'};
   93:     } else {
   94:         $cattype = $domdefaults{'catunauth'};
   95:     }
   96:     if ($cattype eq '') {
   97:         $cattype = 'std';
   98:     }
   99:     if ($cattype eq 'none') {
  100:         $r->print(&Apache::loncommon::start_page('Course/Community Catalog'));
  101:         &Apache::lonhtmlcommon::add_breadcrumb
  102:         ({href=>"/adm/coursecatalog",
  103:           text=>"Course/Community Catalog"});
  104:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
  105:         if ($knownuser || $canviewall) {
  106:             $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
  107:         } else {
  108:             if ($domdefaults{'catauth'} eq 'none') {
  109:                 $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
  110:             } else {
  111:                 $r->print('<div>'.&mt('The catalog of LON-CAPA courses/communities provided for: "[_1]" is only available to users who are logged in.',$domdesc).'</div>');
  112:             }
  113:         }      
  114:         $r->print(&Apache::loncommon::end_page());
  115:         return OK;
  116:     }
  117: 
  118:     my $cnum;
  119:     if ($cattype eq 'codesrch') {
  120:         my ($uniquecode,$codemsg,$brtext);
  121:         if ($env{'form.uniquecode'}) {
  122:             $uniquecode = $env{'form.uniquecode'};
  123:             $uniquecode =~ s/^\s+|\s+$//g;
  124:         }
  125:         my $js = '<script type="text/javascript">'."\n".
  126:                  '// <![CDATA['."\n".
  127:                  &courselink_javascript($r)."\n".
  128:                  '// ]]>'."\n".
  129:                  '</script>'."\n";
  130:         $r->print(&Apache::loncommon::start_page('Search for a Course/Community',$js));
  131:         if ($uniquecode =~ /^\w{6}$/) {
  132:             &Apache::lonhtmlcommon::add_breadcrumb
  133:             ({href=>"/adm/coursecatalog",
  134:               text=>"Course/Community Catalog"});
  135:             $brtext = 'Search Result';
  136:         } else {
  137:             $brtext = 'Course/Community Catalog';
  138:         }
  139:         &Apache::lonhtmlcommon::add_breadcrumb
  140:         ({href=>"/adm/coursecatalog",
  141:           text=>"$brtext"});
  142:         $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
  143:         $r->print(&coursesearch($codedom,$domdesc,$uniquecode));
  144:         if ($uniquecode =~ /^\w{6}$/) {
  145:             $r->print('<hr />');
  146:             my $confname = $codedom.'-domainconfig';
  147:             my %codes = &Apache::lonnet::get('uniquecodes',[$uniquecode],$codedom,$confname);
  148:             if ($codes{$uniquecode}) {
  149:                 $cnum = $codes{$uniquecode};
  150:                 my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.',
  151:                                                             $cnum,undef,undef,'.',1);
  152:                 if (keys(%courses)) {
  153:                     $env{'form.coursenum'} = $cnum;
  154:                     my %courseinfo = &build_courseinfo_hash(\%courses,$knownuser,$codedom,$canviewall);
  155:                     undef($env{'form.coursenum'});
  156:                     if (ref($courseinfo{$codedom.'_'.$cnum}) eq 'HASH') {
  157:                         $r->print(&Apache::lonhtmlcommon::start_pick_box());
  158:                         my @cols = ('title','ownerlastnames','seclist','access');
  159:                         my %lt = &Apache::lonlocal::texthash(
  160:                                      title          => 'Title',
  161:                                      ownerlastnames => 'Owner & Co-owner(s)',
  162:                                      seclist        => 'Sections',
  163:                                      access         => 'Default Access Dates for Students',
  164:                                  );
  165:                         my @shown;
  166:                         foreach my $item (@cols) {
  167:                             if ($courseinfo{$codedom.'_'.$cnum}{$item}) {
  168:                                 push(@shown,$item);
  169:                             }
  170:                         }
  171:                         my $num = 0;
  172:                         foreach my $item (@shown) {
  173:                             $num ++;
  174:                             $r->print(&Apache::lonhtmlcommon::row_title($lt{$item}).
  175:                                       $courseinfo{$codedom.'_'.$cnum}{$item});
  176:                             if ($item eq 'title') {
  177:                                 if ($courseinfo{$codedom.'_'.$cnum}{'showsyllabus'}) {
  178:                                     my $usehttp = 0;
  179:                                     if (($ENV{'SERVER_PORT'} == 443) && ($courseinfo{$codedom.'_'.$cnum}{'extsyllplain'})) {
  180:                                         unless (&Apache::lonnet::uses_sts()) {
  181:                                             $usehttp = 1;
  182:                                         }
  183:                                     }
  184:                                     $r->print('&nbsp;<font size="-2">'.
  185:                                               '<a href="javascript:ToSyllabus('."'$codedom','$cnum','$usehttp'".')">'.
  186:                                               &mt('Syllabus').'</a></font>');
  187:                                 }
  188:                             }
  189:                             my $arg = ( $num == scalar(@shown) ? 1 : '' );
  190:                             $r->print(&Apache::lonhtmlcommon::row_closure($arg));
  191:                         }
  192:                         $r->print(&Apache::lonhtmlcommon::end_pick_box());
  193:                         my $selfenroll = &selfenroll_status($courseinfo{$codedom.'_'.$cnum},$codedom.'_'.$cnum);
  194:                         if ($selfenroll) {
  195:                             $r->print('<br />'.$selfenroll);
  196:                         }
  197:                         $r->print('<form name="linklaunch" method="post" action="">'."\n".
  198:                                   '<input type="hidden" name="backto" value="coursecatalog" />'."\n".
  199:                                   '<input type="hidden" name="courseid" value="" />'."\n".
  200:                                   '</form>'."\n");
  201: 
  202:                     } else {
  203:                         $codemsg = &mt('Code matched, but course ID to which this mapped is invalid.');
  204:                     }
  205:                 } else {
  206:                     $codemsg = &mt('Code matched, but course ID to which this mapped is invalid.');              
  207:                 } 
  208:             } else {
  209:                 $codemsg = &mt('No match');
  210:             }
  211:         }
  212:         $r->print('<br />'.&Apache::loncommon::end_page());
  213:         return OK;
  214:     } else {
  215:         if ($env{'form.coursenum'} ne '') {
  216:             if ($env{'form.coursenum'} =~ /^$LONCAPA::match_courseid$/) {
  217:                 $cnum = $env{'form.coursenum'};
  218:             } else {
  219:                 delete($env{'form.coursenum'});
  220:             }
  221:         }
  222:     }
  223: 
  224:     my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$subcats,%maxd,
  225:         $toplevelstr,$maxdepthstr);
  226:     if ($env{'form.withsubcats'}) {
  227:         $subcats = \%subcathash;
  228:     }
  229:     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
  230:                                            \%idx,\@jsarray,$subcats,\%maxd);
  231:     if (ref($cats[0]) eq 'ARRAY') {
  232:         foreach my $item (@{$cats[0]}) {
  233:             $toplevelstr .= "'".&js_escape($item)."::0',";
  234:             $maxdepthstr .= "'$maxd{$item}',";
  235:         }
  236:         $toplevelstr =~ s/,$//;
  237:         $maxdepthstr =~ s/,$//;
  238:     }
  239:     &validate_input($codedom,\@cats,\%maxd,$cathash);
  240:     my ($numtitles,@codetitles);
  241:     if (($env{'form.coursenum'} ne '') && ($knownuser)) {
  242:         &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems,\@codetitles);
  243:     } else {
  244:         my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom,@cats);
  245:         my $wasacctext = &get_wasactive_text();
  246:         my $catjs = <<"ENDSCRIPT";
  247: 
  248: function setCatDepth(depth) {
  249:     var depth = parseInt(depth);
  250:     if (depth !== NaN) {
  251:         if (depth > 0) {
  252:             var possmaxd = 0;
  253:             var toplevel = new Array($toplevelstr);
  254:             var maxdepths = new Array($maxdepthstr);
  255:             if (toplevel.length) {
  256:                 for (var i=0; i<toplevel.length; i++) {
  257:                     var item = unescape(toplevel[i]);
  258:                     if (item == document.coursecats.currcat_0.value) {
  259:                         possmaxd = maxdepths[i];
  260:                         break;
  261:                     }
  262:                 }
  263:             }
  264:             if (depth > possmaxd) {
  265:                 depth = possmaxd;
  266:             }
  267:         }
  268:         document.coursecats.catalog_maxdepth.value = depth;
  269:     } else {
  270:         document.coursecats.currcat_0.value = '';
  271:         document.coursecats.catalog_maxdepth.value = '';
  272:     }
  273:     document.coursecats.submit();
  274:     return;
  275: }
  276: 
  277: function changeSort(caller) {
  278:     document.$formname.sortby.value = caller;
  279:     document.$formname.submit();
  280: }
  281: 
  282: function setCourseId(caller) {
  283:     document.$formname.coursenum.value = caller;
  284:     document.$formname.submit();
  285: }
  286: 
  287: ENDSCRIPT
  288:         $catjs .= &courselink_javascript($r);
  289:         if (&user_is_dc($codedom) || $canviewall) {
  290:             $catjs .= <<ENDTOGGJS
  291: 
  292: function toggleStatuses() {
  293:     if (document.$formname.showdetails.checked) {
  294:         document.getElementById('statuschoice').style.display='block';
  295:         document.getElementById('statuscell').style.borderLeft='1px solid'; 
  296:     } else {
  297:         document.getElementById('statuschoice').style.display='none';
  298:         document.getElementById('statuscell').style.borderLeft='0px';
  299:     }
  300:     return;
  301: }
  302: 
  303: function toggleWasActive() {
  304:     if (document.getElementById('counts_Previous')) {
  305:         if (document.getElementById('counts_Previous').checked) {
  306:             document.getElementById('choosewasactive').style.display='block';
  307:             document.getElementById('choosewasacctext').innerHTML = '$wasacctext';
  308:         } else {
  309:             document.getElementById('choosewasactive').style.display='none';
  310:             document.getElementById('choosewasacctext').innerHTML = '';
  311:         }
  312:     }
  313:     return;
  314: }
  315: 
  316: ENDTOGGJS
  317:         }
  318:         if ($env{'form.currcat_0'} eq 'instcode::0') {
  319:             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
  320:                                                    $catlinks,$catjs,\@codetitles,$cattype,$canviewall);
  321:             if ($env{'form.state'} eq 'listing') {
  322:                 $r->print(&print_course_listing($codedom,$numtitles,undef,undef,undef,
  323:                                                 \@codetitles,$canviewall));
  324:             }
  325:         } else {
  326:             my (%add_entries);
  327:             my ($currdepth,$deeper) = &get_depth_values();
  328:             if ($selitem) {
  329:                 my $alert = &mt('Choose a subcategory to display');
  330:                 if (!$deeper) {
  331:                     $alert = &mt('Choose a category to display');
  332:                 }
  333:                 &js_escape(\$alert);
  334:                 $catjs .= <<ENDJS;
  335: function check_selected() {
  336:     if (document.coursecats.$selitem.options[document.coursecats.$selitem.selectedIndex].value == "") {
  337:         alert('$alert');
  338:         return false;
  339:     }
  340: }
  341: ENDJS
  342:             }
  343:             $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
  344:             &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks,undef,$cattype);
  345:             if ($env{'form.currcat_0'} ne '') {
  346:                 $r->print('<form name="'.$formname.
  347:                           '" method="post" action="/adm/coursecatalog">'.
  348:                           &additional_filters($codedom,$has_subcats,$canviewall)."\n");
  349:                 $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
  350:                           $deeper.'" />'."\n");
  351:                 for (my $i=0; $i<$deeper; $i++) {
  352:                     $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
  353:                 }
  354:                 my $display_button;
  355:                 if ($env{'form.currcat_0'} eq 'communities::0') {
  356:                     $display_button = &mt('Display communities');
  357:                 } else {
  358:                     $display_button = &mt('Display courses');
  359:                 }
  360:                 $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
  361:                           '<input type="hidden" name="sortby" value="" />'."\n".
  362:                           '<input type="hidden" name="state" value="listing" />'."\n".
  363:                           '<input type="hidden" name="showdom" value="'.
  364:                           $env{'form.showdom'}.'" />'.
  365:                           '<input type="submit" name="catalogfilter" value="'.
  366:                           $display_button.'" /></form><br /><br />');
  367:             }
  368:             if ($env{'form.state'} eq 'listing') {
  369:                 $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles,
  370:                                                 $canviewall));
  371:             }
  372:         }
  373:     }
  374:     $r->print('<br />'.&Apache::loncommon::end_page());
  375:     return OK;
  376: }
  377: 
  378: sub validate_input {
  379:     my ($codedom,$cats,$maxd,$crscatsref) = @_;
  380:     my $currcat = '';
  381:     my $depth = 0;
  382:     if ($env{'form.catalog_maxdepth'} ne '') {
  383:         $env{'form.catalog_maxdepth'} =~ s{\D}{}g;
  384:     }
  385:     if ((ref($cats) eq 'ARRAY') && (ref($maxd) eq 'HASH')) {
  386:         if (ref($cats->[0]) eq 'ARRAY') {
  387:             if (@{$cats->[0]} == 1) {
  388:                 if ($cats->[0][0] eq 'instcode') {
  389:                     $currcat = 'instcode::0';
  390:                 } elsif ($cats->[0][0] eq 'communities') {
  391:                     $currcat = 'communities::0';
  392:                 } elsif ($cats->[0][0] eq 'placement') {
  393:                     $currcat = 'placement::0';
  394:                 } else {
  395:                     my $name = $cats->[0][0];
  396:                     $currcat = &escape($name).'::0';
  397:                 }
  398:                 if (exists($maxd->{$cats->[0][0]})) {
  399:                     if ($env{'form.catalog_maxdepth'} <= $maxd->{$cats->[0][0]}) {
  400:                         $depth = $env{'form.catalog_maxdepth'};
  401:                     } else {
  402:                         $depth = $maxd->{$cats->[0][0]};
  403:                     }
  404:                 }
  405:             } elsif ((@{$cats->[0]} > 1) && ($env{'form.currcat_0'} ne '')) {
  406:                 my ($escname) = ($env{'form.currcat_0'} =~ /^([^:]+)\:\:0$/);
  407:                 if ($escname =~ /^instcode|communities|placement$/) {
  408:                     $currcat = $env{'form.currcat_0'};
  409:                     if (exists($maxd->{$escname})) {
  410:                         if ($env{'form.catalog_maxdepth'} <= $maxd->{$escname}) {
  411:                             $depth = $env{'form.catalog_maxdepth'};
  412:                         } else {
  413:                             $depth = $maxd->{$escname};
  414:                         }
  415:                     } else {
  416:                         $depth = 1;
  417:                     }
  418:                 } elsif ($escname ne '') {
  419:                     my $name = &unescape($escname);
  420:                     if (grep(/^\Q$name\E$/,@{$cats->[0]})) {
  421:                         $currcat = $env{'form.currcat_0'};
  422:                         if (exists($maxd->{$name})) {
  423:                             if ($env{'form.catalog_maxdepth'} <= $maxd->{$name}) {
  424:                                 $depth = $env{'form.catalog_maxdepth'};
  425:                             } else {
  426:                                 $depth = $maxd->{$name};
  427:                             }
  428:                         }
  429:                     }
  430:                 }
  431:             }
  432:         }
  433:     }
  434:     $env{'form.currcat_0'} = $currcat;
  435:     $env{'form.catalog_maxdepth'} = $depth;
  436: 
  437:     my %possibles = (
  438:         backto => 1,
  439:         catalogfilter => 1,
  440:         catalog_maxdepth => 1,
  441:         courseid => 1,
  442:         coursenum => 1,
  443:         currcat_0 => 1,
  444:         numtitles => 1,
  445:         Year => 1,
  446:         Semester => 1,
  447:         Department => 1,
  448:         Number => 1,
  449:         showdom => 1,
  450:         sortby => 1,
  451:         showcounts => 1,
  452:         showdetails => 1,
  453:         showhidden => 1,
  454:         showselfenroll => 1,
  455:         state => 1,
  456:         uniquecode => 1,
  457:         wasactive => 1,
  458:         wasactiveon_day => 1,
  459:         wasactiveon_month => 1,
  460:         wasactiveon_year => 1,
  461:         withsubcats => 1,
  462:     );
  463:     my %currcats;
  464:     if ($env{'form.catalog_maxdepth'} > 0) {
  465:         for (my $i=1; $i<=$env{'form.catalog_maxdepth'}; $i++) {
  466:             $currcats{'currcat_'.$i} = 1;
  467:             $possibles{'currcat_'.$i} = 1;
  468:         }
  469:     }
  470: 
  471:     foreach my $key (sort(keys(%env))) {
  472:         if ($key =~ /^form\.(.+)$/) {
  473:             unless ($possibles{$1}) {
  474:                 delete($env{$key});
  475:             }
  476:         }
  477:     }
  478:     if (exists($env{'form.backto'})) {
  479:         unless ($env{'form.backto'} eq 'coursecatalog') {
  480:             delete($env{'form.backto'});
  481:         }
  482:     }
  483:     if (exists($env{'form.catalogfilter'})) {
  484:         unless (($env{'form.catalogfilter'} eq &mt('Display courses')) ||
  485:                 ($env{'form.catalogfilter'} eq &mt('Display communities')) ||
  486:                 ($env{'form.catalogfilter'} eq &mt('Display placement tests'))) {
  487:             delete($env{'form.catalogfilter'});
  488:         }
  489:     }
  490:     if (exists($env{'form.courseid'})) {
  491:         if ($env{'form.courseid'} ne '') {
  492:             unless ($env{'form.courseid'} =~ /^\Q$codedom\E_$LONCAPA::match_courseid$/) {
  493:                 $env{'form.courseid'} = '';
  494:             }
  495:         }
  496:     }
  497:     if (exists($env{'form.coursenum'})) {
  498:         unless ($env{'form.coursenum'} =~ /^$LONCAPA::match_courseid$/) {
  499:             $env{'form.coursenum'} = '';
  500:         }
  501:     }
  502:     if (exists($env{'form.currcat_0'})) {
  503:         unless ($env{'form.currcat_0'} =~ /^(instcode|communities|placement)\Q::0\E$/) {
  504:             if ($env{'form.currcat_0'} =~ /^.+\Q::0\E$/) {
  505:                 if (ref($crscatsref) eq 'HASH') {
  506:                     unless (exists($crscatsref->{$env{'form.currcat_0'}})) {
  507:                         delete($env{'form.currcat_0'});
  508:                     }
  509:                 } else {
  510:                     delete($env{'form.currcat_0'});
  511:                 }
  512:             } else {
  513:                 delete($env{'form.currcat_0'});
  514:             }
  515:         }
  516:     }
  517:     if (exists($env{'form.numtitles'})) {
  518:         unless ($env{'form.numtitles'} =~ /^\d+$/) {
  519:             delete($env{'form.numtitles'});
  520:         }
  521:     }
  522:     my ($gotcodes,%possvals);
  523:     foreach my $item ('Year','Semester','Department','Number') {
  524:         if (exists($env{'form.'.$item})) {
  525:             unless ($env{'form.'.$item} eq '0') {
  526:                 unless ($gotcodes) {
  527:                     $gotcodes = &get_instcode_allowable($codedom,\%possvals);
  528:                 }
  529:                 if (ref($possvals{$item}) eq 'HASH') {
  530:                     unless (exists($possvals{$item}{$env{'form.'.$item}})) {
  531:                         delete($env{'form.'.$item});
  532:                     }
  533:                 } else {
  534:                     delete($env{'form.'.$item});
  535:                 }
  536:             }
  537:         }
  538:     }
  539:     if (exists($env{'form.showdom'})) {
  540:         unless ($env{'form.showdom'} =~ /^$LONCAPA::match_domain$/) {
  541:             delete($env{'form.showdom'});
  542:         }
  543:     }
  544:     if (exists($env{'form.sortby'})) {
  545:         unless ($env{'form.sortby'} =~ /^(title|code|owner|cats)$/) {
  546:             delete($env{'form.sortby'});
  547:         }
  548:     }
  549:     if (exists($env{'form.showcounts'})) {
  550:         if (ref($env{'form.showcounts'}) eq 'ARRAY') {
  551:             foreach my $item (@{$env{'form.showcounts'}}) {
  552:                 unless ($item =~ /^(Active|Future|Previous)$/) {
  553:                     delete($env{'form.showcounts'});
  554:                     last;
  555:                 }
  556:             }
  557:         } else {
  558:             unless ($env{'form.showcounts'} =~ /^(Active|Future|Previous)$/) {
  559:                 delete($env{'form.showcounts'});
  560:             }
  561:         }
  562:     }
  563:     foreach my $item ('showhidden','showdetails','showselfenroll','withsubcats') {
  564:         if (exists($env{'form.'.$item})) {
  565:             unless ($env{'form.'.$item} eq '1') {
  566:                 delete($env{'form.'.$item});
  567:             }
  568:         }
  569:     }
  570:     if (exists($env{'form.state'})) {
  571:         unless ($env{'form.state'} eq 'listing') {
  572:             delete($env{'form.state'});
  573:         }
  574:     }
  575:     if (exists($env{'form.uniquecode'})) {
  576:         unless ($env{'form.uniquecode'} =~ /^\w{6}$/) {
  577:             delete($env{'form.uniquecode'});
  578:         }
  579:     }
  580:     if (exists($env{'form.wasactive'})) {
  581:         unless (($env{'form.wasactive'} eq 'accessend') || ($env{'form.wasactive'} eq 'enrollend')) {
  582:             delete($env{'form.wasactive'});
  583:         }
  584:     }
  585:     if (exists($env{'form.wasactiveon_day'})) {
  586:         my $tmpday = $env{'form.wasactiveon_day'};
  587:         unless (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
  588:             delete($env{'form.wasactiveon_day'});
  589:         }
  590:     }
  591:     if (exists($env{'form.wasactiveon_month'})) {
  592:         my $tmpmonth = $env{'form.wasactiveon_month'};
  593:         unless (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
  594:             delete($env{'form.wasactiveon_month'});
  595:         }
  596:     }
  597:     if (exists($env{'form.wasactiveon_year'})) {
  598:         my $tmpyear = $env{'form.wasactiveon_year'};
  599:         unless (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
  600:             delete($env{'form.wasactiveon_year'});
  601:         }
  602:     }
  603:     if (keys(%currcats)) {
  604:         foreach my $key (keys(%currcats)) {
  605:             if ($env{'form.'.$key} eq '') {
  606:                 delete($env{'form.'.$key});
  607:             } elsif (ref($crscatsref) eq 'HASH') {
  608:                 unless (exists($crscatsref->{$env{'form.'.$key}})) {
  609:                     delete($env{'form.'.$key});
  610:                 }
  611:             } else {
  612:                 delete($env{'form.'.$key});
  613:             }
  614:         }
  615:     }
  616:     return;
  617: }
  618: 
  619: sub get_instcode_allowable {
  620:     my ($codedom,$possvalref) = @_;
  621:     return 1 unless (ref($possvalref) eq 'HASH');
  622:     my $instcats = &Apache::lonnet::get_dom_instcats($codedom);
  623:     if (ref($instcats) eq 'HASH') {
  624:         if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH')) {
  625:             my %codes = %{$instcats->{'codes'}};
  626:             my @codetitles = @{$instcats->{'codetitles'}};
  627:             my @standardnames = &Apache::loncommon::get_standard_codeitems();
  628:             my %local_to_standard;
  629:             for (my $i=0; $i<@codetitles; $i++) {
  630:                 $local_to_standard{$codetitles[$i]} = $standardnames[$i];
  631:                 $possvalref->{$standardnames[$i]} = {};
  632:             }
  633:             foreach my $cid (sort(keys(%codes))) {
  634:                 if (ref($codes{$cid}) eq 'HASH') {
  635:                     foreach my $item (keys(%{$codes{$cid}})) {
  636:                         $possvalref->{$local_to_standard{$item}}{$codes{$cid}{$item}} = 1;
  637:                     }
  638:                 }
  639:             }
  640:         }
  641:     }
  642:     return 1;
  643: }
  644: 
  645: sub course_details {
  646:     my ($r,$codedom,$formname,$domdesc,$trails,$allitems,$codetitles) = @_;
  647:     my $output;
  648:     my %add_entries = (topmargin    => "0",
  649:                        marginheight => "0",);
  650:     my $js = '<script type="text/javascript">'."\n".
  651:              &courselink_javascript($r).'</script>'."\n";
  652:     my $start_page =
  653:         &Apache::loncommon::start_page('Course/Community Catalog',$js,
  654:                                        {'add_entries' => \%add_entries, });
  655:     $r->print($start_page);
  656:     if ($env{'form.numtitles'} > 0) {
  657:         &Apache::lonhtmlcommon::add_breadcrumb
  658:                 ({href=>"/adm/coursecatalog",
  659:                   text=>"Course/Community Catalog"});
  660:     }
  661:     my $brtextone = 'Course listing';
  662:     my $brtexttwo = 'Course details';
  663:     if ($env{'form.currcat_0'} eq 'communities::0') {
  664:         $brtextone = 'Community listing';
  665:         $brtexttwo = 'Community details';
  666:     }
  667:     &Apache::lonhtmlcommon::add_breadcrumb
  668:              ({href=>"javascript:document.$formname.submit()",
  669:               text=>$brtextone},
  670:              {text=>$brtexttwo});
  671:     $r->print(
  672:         &Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog').
  673:         '<h2>'.
  674:         (($env{'form.currcat_0'} eq 'communities::0') ?
  675:             &mt('Detailed community information:') :
  676:             &mt('Detailed course information:')).
  677:         '</h2>'.
  678:         &print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles).
  679:         '<br />'.
  680:         '<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
  681:         &Apache::lonhtmlcommon::actionbox([
  682:             '<a href = "javascript:document.coursecatalog.submit()">'.
  683:             (($env{'form.currcat_0'} eq 'communities::0') ?
  684:                 &mt('Back to community listing') : &mt('Back to course listing')).
  685:             '</a>'
  686:         ]).
  687:         &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
  688:                                                  'showdetails','courseid']).
  689:         '</form>');
  690:     return;
  691: }
  692: 
  693: sub coursesearch {
  694:     my ($codedom,$domdesc,$uniquecode) = @_;
  695:     my %lt = &Apache::lonlocal::texthash (
  696:                                            crlk => 'Course look-up',  
  697:                                            code => 'Code',
  698:                                            ifyo => 'Enter the course code (six letters and numbers)',
  699:                                            srch => 'Find course',
  700:                                          );
  701:     return <<"END";
  702: <h3>$lt{'crlk'} ($domdesc)</h3>
  703: $lt{'ifyo'}
  704: <form name="searchbycode" method="post" action="">
  705: <span class="LC_nobreak">
  706: <input type="text" value="$uniquecode" size="6" name="uniquecode" />&nbsp;
  707: <br />
  708: <input type="submit" value="$lt{'srch'}" name="srch" /></span>
  709: </form>
  710: END
  711: }
  712: 
  713: sub courselink_javascript {
  714:     my ($r) = @_;
  715:     my $hostname = $r->hostname();    
  716:     return <<"END";
  717: 
  718: function ToSyllabus(cdom,cnum,usehttp) {
  719:     if (cdom == '' || cdom == null) {
  720:         return;
  721:     }
  722:     if (cnum == '' || cnum == null) {
  723:         return;
  724:     }
  725:     document.linklaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus";
  726:     if (usehttp == 1) {
  727:         var hostname = '$hostname';
  728:         if (hostname != '') {
  729:             document.linklaunch.action = 'http://'+hostname+document.linklaunch.action;
  730:         }
  731:         document.linklaunch.action += '?usehttp=1';
  732:     }
  733:     document.linklaunch.submit();
  734: }
  735: 
  736: function ToSelfenroll(courseid) {
  737:     if (courseid == '') {
  738:         return;
  739:     }
  740:     document.linklaunch.action = "/adm/selfenroll";
  741:     document.linklaunch.courseid.value = courseid;
  742:     document.linklaunch.submit();
  743: }
  744: 
  745: END
  746: }
  747: 
  748: sub instcode_course_selector {
  749:     my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs,$codetitles,$cattype,$canviewall) = @_;
  750:     my %cat_titles = ();
  751:     my %cat_order = ();
  752:     my %cat_items = ();
  753:     my %add_entries = (topmargin    => "0",
  754:                        marginheight => "0",);
  755:     my ($jscript,$totcodes,$numtitles,$lasttitle) = 
  756:         &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
  757:                            \%cat_items,$codetitles,\%cat_titles,\%cat_order);
  758:     my $js = '<script type="text/javascript">'."\n".
  759:              '// <![CDATA['."\n".
  760:              "$jscript\n$catjs\n".
  761:              '// ]]>'."\n".
  762:              '</script>';
  763:     if ($totcodes) {
  764:         if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
  765:             $add_entries{'onload'} = 'setElements();';
  766:         }
  767:         if (&user_is_dc($codedom) || $canviewall) {
  768:             $add_entries{'onload'} .= ' toggleStatuses();toggleWasActive();'
  769:         }
  770:         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
  771:         my $cat_maxdepth = $env{'form.catalog_maxdepth'};
  772:         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
  773:                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
  774:                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
  775:                   '<input type="hidden" name="currcat_0" value="instcode::0" />'.
  776:                   &additional_filters($codedom,undef,$canviewall));
  777:         if ($numtitles > 0) {
  778:             $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />'.
  779:                       &Apache::courseclassifier::build_instcode_selectors($numtitles,
  780:                        $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order));
  781:         }
  782:         $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
  783:                   '<input type="hidden" name="sortby" value="" />'."\n".
  784:                   '<input type="hidden" name="state" value="listing" />'."\n".
  785:                   '<input type="submit" name="catalogfilter" value="'.
  786:                   &mt('Display courses').'" />'.
  787:                   '<input type="hidden" name="numtitles" value="'.$numtitles.
  788:                   '" /></form><br /><br />');
  789:     } else {
  790:         $js = '<script type="text/javascript">'."\n".
  791:               '// <![CDATA['."\n".
  792:               "$catjs\n".
  793:               '// ]]>'."\n".
  794:               '</script>';
  795:         &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles,$cattype);
  796:         my $cat_maxdepth = $env{'form.catalog_maxdepth'};
  797:         $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
  798:                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'.
  799:                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
  800:                   '<input type="hidden" name="currcat_0" value="instcode::0" />');
  801:         $r->print('<br />'.&mt('No official courses to display for [_1].',$domdesc).'</form>');
  802:     }
  803:     return $numtitles;
  804: }
  805: 
  806: sub cat_header {
  807:     my ($r,$codedom,$js,$add_entries,$catlinks,$numtitles,$cattype) = @_;
  808:     my $start_page =
  809:         &Apache::loncommon::start_page('Course/Community Catalog',$js,
  810:                                        { 'add_entries' => $add_entries, });
  811:     $r->print($start_page);
  812:     my $brtext = 'Course listing';
  813:     if ($env{'form.currcat_0'} eq 'communities::0') {
  814:         $brtext = 'Community listing';
  815:     }
  816:     if ($env{'form.state'} eq 'listing') {
  817:         if ($numtitles > 0) {
  818:             &Apache::lonhtmlcommon::add_breadcrumb
  819:                 ({href=>"/adm/coursecatalog",
  820:                   text=>"Course/Community Catalog"},
  821:                  {text=>$brtext});
  822:         } else {
  823:             &Apache::lonhtmlcommon::add_breadcrumb
  824:             ({text=>$brtext});
  825:         }
  826:     } else {
  827:         &Apache::lonhtmlcommon::add_breadcrumb
  828:         ({href=>"/adm/coursecatalog",
  829:           text=>"Course/Community Catalog"});
  830:     }
  831:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
  832:     if ($cattype eq 'std') {
  833:         my $onchange = 'this.form.submit()';
  834:         $r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
  835:                   '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
  836:                   &Apache::loncommon::select_dom_form($codedom,'showdom','',1,$onchange));
  837:         if (!$onchange) {
  838: 	   $r->print('&nbsp;<input type="submit" name="godom" value="'.&mt('Change').'" />');
  839:         }
  840:         $r->print('</td></tr></table></form>');
  841:     }
  842:     $r->print('<form name="coursecats" method="post" action="/adm/coursecatalog"'.
  843:               ' onsubmit="return check_selected();">'.
  844:               '<table border="0"><tr>'.$catlinks.'</tr></table></form>');
  845:     return;
  846: }
  847: 
  848: sub category_breadcrumbs {
  849:     my ($dom,@cats) = @_;
  850:     my $crumbsymbol = ' &#x25b6; ';
  851:     my ($currdepth,$deeper) = &get_depth_values();
  852:     my $currcat_str = 
  853:         '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" />'.
  854:         '<input type="hidden" name="showdom" value="'.$dom.'" />';
  855:     my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr><td>';
  856:     my $has_subcats;
  857:     my $selitem;
  858:     if (ref($cats[0]) eq 'ARRAY') {
  859:         if (@{$cats[0]} == 0) {
  860:             $catlinks .= &mt('No categories defined in this domain'); 
  861:         } elsif (@{$cats[0]} == 1) {
  862:             if ($cats[0][0] eq 'instcode') {
  863:                 $catlinks .= &mt('Official courses (with institutional codes)');
  864:                 $env{'form.currcat_0'} = 'instcode::0';
  865:             } elsif ($cats[0][0] eq 'communities') {
  866:                 $catlinks .= &mt('Communities');
  867:                 $env{'form.currcat_0'} = 'communities::0';
  868:             } else {
  869:                 my $name = $cats[0][0];
  870:                 my $item = &escape($name).'::0';
  871:                 $catlinks .= $name;
  872:                 $env{'form.currcat_0'} = $item;
  873:             }
  874:             $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
  875:         } else {
  876:             $catlinks .= &main_category_selector(@cats);
  877:             if (($env{'form.currcat_0'} ne '') && 
  878:                 ($env{'form.currcat_0'} ne 'instcode::0')) {
  879:                 $catlinks .= $crumbsymbol;
  880:             }
  881:         }
  882:     } else {
  883:         $catlinks .= &mt('Official courses (with institutional codes)');
  884:                      $env{'form.currcat_0'} = 'instcode::0';
  885:          $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
  886:     }
  887:     if ($deeper) {
  888:         for (my $i=1; $i<=$deeper; $i++) {
  889:             my $shallower = $i-1;
  890:             next if ($shallower == 0);
  891:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
  892:             if ($cat ne '') {
  893:                 $catlinks .= '<td valign="top">'.
  894:                              '<select name="currcat_'.$shallower.'" onchange="'.
  895:                              'setCatDepth('."'$shallower'".');this.form.submit();">';
  896:                 if (ref($cats[$shallower]{$container}) eq 'ARRAY') {
  897:                     $catlinks .= '<option value="">'.&mt('De-select').'</option>';
  898:                     for (my $j=0; $j<@{$cats[$shallower]{$container}}; $j++) {
  899:                         my $name = $cats[$shallower]{$container}[$j];
  900:                         my $item = &escape($name).':'.&escape($container).':'.$shallower;
  901:                         my $selected = '';
  902:                         if ($item eq $env{'form.currcat_'.$shallower}) {
  903:                             $selected = ' selected="selected"';
  904:                         }
  905:                         $catlinks .= 
  906:                            '<option value="'.$item.'"'.$selected.'>'.$name.'</option>';
  907:                     }
  908:                 }
  909:                 $catlinks .= '</select>';
  910:             }
  911:             unless ($i == $deeper) {
  912:                 $catlinks .= $crumbsymbol;
  913:             } 
  914:         }
  915:         my ($cat,$container,$depth);
  916:         if ($env{'form.currcat_'.$currdepth} eq '') {
  917:             my $shallower = $currdepth - 1;
  918:             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
  919:         } else {
  920:             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
  921:         }
  922:         my $deeperlevel = $depth +1;
  923:         if (ref($cats[$deeperlevel]{$cat}) eq 'ARRAY') {
  924:             $has_subcats = 1;
  925:             my $buttontext = &mt('Show subcategories');
  926:             my $selitem = 'currcat_'.$deeperlevel;
  927:             $catlinks .= '&nbsp;<select name="'.$selitem.'" onchange="this.form.submit()">';
  928:             if (@{$cats[$deeperlevel]{$cat}}) {
  929:                 $catlinks .= '<option value="" selected="selected">'.
  930:                              &mt('Subcategory ...').'</option>';
  931:             }
  932:             for (my $k=0; $k<@{$cats[$deeperlevel]{$cat}}; $k++) {
  933:                 my $name = $cats[$deeperlevel]{$cat}[$k];
  934:                 my $item = &escape($name).':'.&escape($cat).':'.$deeperlevel;
  935:                 $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
  936:             }
  937:             $catlinks .= '</select>'."\n";
  938:         } elsif ($cat ne 'instcode') {
  939:             $catlinks .= '&nbsp;'.&mt('(No subcategories)');
  940:         }
  941:     } else {
  942:         $selitem = 'currcat_0';
  943:     }
  944:     $catlinks .= $currcat_str.'</td></tr></table></td>';
  945:     return ($catlinks,$has_subcats,$selitem);
  946: }
  947: 
  948: sub main_category_selector {
  949:     my (@cats) = @_;
  950:     my $maincatlinks = '<select name="currcat_0" onchange="setCatDepth('."'0'".');this.form.submit();">'."\n";
  951:     if (ref($cats[0]) eq 'ARRAY') {
  952:         if (@{$cats[0]} > 1) {
  953:             my $selected = '';
  954:             if ($env{'form.currcat_0'} eq '') {
  955:                 $selected = ' selected="selected"';    
  956:             }
  957:             $maincatlinks .= 
  958:                 '<option value=""'.$selected.'>'.&mt('Select').'</option>'."\n";
  959:         }
  960:         for (my $i=0; $i<@{$cats[0]}; $i++) {
  961:             my $name = $cats[0][$i];
  962:             my $item = &escape($name).'::0';
  963:             my $selected;
  964:             if ($env{'form.currcat_0'} eq $item) {
  965:                 $selected = ' selected="selected"';
  966:             }
  967:             $maincatlinks .= '<option value="'.$item.'"'.$selected.'>';
  968:             if ($name eq 'instcode') {
  969:                 $maincatlinks .= &mt('Official courses (with institutional codes)');
  970:             } elsif ($name eq 'communities') {
  971:                 $maincatlinks .= &mt('Communities');
  972:             } else {
  973:                 $maincatlinks .= $name;
  974:             }
  975:             $maincatlinks .= '</option>'."\n";
  976:         }
  977:         $maincatlinks .= '</select>'."\n";
  978:     }
  979:     return $maincatlinks;
  980: }
  981: 
  982: sub get_depth_values {
  983:     my $currdepth = 0;
  984:     my $deeper = 0;
  985:     if ($env{'form.catalog_maxdepth'} ne '') {
  986:         $currdepth = $env{'form.catalog_maxdepth'};
  987:         if ($env{'form.currcat_'.$currdepth} eq '') {
  988:             $deeper = $currdepth;
  989:         } else {
  990:             $deeper = $currdepth + 1;
  991:         }
  992:     }
  993:     return ($currdepth,$deeper);
  994: }
  995: 
  996: sub additional_filters {
  997:     my ($codedom,$has_subcats,$canviewall) = @_;
  998:     my $is_dc = &user_is_dc($codedom);
  999:     my $output = '<div class="LC_left_float">';
 1000:     if ($is_dc || $canviewall) {
 1001:         $output .= '<fieldset><legend>'.&mt('Options').'</legend>';
 1002:     }
 1003:     $output .= '<table><tr><td valign="top">';
 1004:     if (($env{'form.currcat_0'} ne 'instcode::0') &&
 1005:         ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
 1006:         my $include_subcat_status;
 1007:         if ($env{'form.withsubcats'}) {
 1008:             $include_subcat_status = 'checked="checked" ';
 1009:         }
 1010:         my $counter = $env{'form.catalog_maxdepth'};
 1011:         if ($counter > 0) {
 1012:             if ($env{'form.state'} eq 'listing') {
 1013:                 $counter --;
 1014:             } elsif ($env{'form.currcat_'.$counter} eq '') {
 1015:                 $counter --;
 1016:             }
 1017:         }
 1018:         my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
 1019:         if ($catname ne '') {
 1020:             $output .= '<span class="LC_nobreak"><label>'.
 1021:                        '<input type="checkbox" name="withsubcats" value="1" '.
 1022:                        $include_subcat_status.'/>'.
 1023:                        &mt('Include subcategories within "[_1]"',
 1024:                            &unescape($catname)).'</label></span><br />';
 1025:         }
 1026:     }
 1027:     my $show_selfenroll_status;
 1028:     if ($env{'form.showselfenroll'}) {
 1029:         $show_selfenroll_status = 'checked="checked" ';
 1030:     }
 1031:     my $selfenroll_text;
 1032:     if ($env{'form.currcat_0'} eq 'communities::0') {
 1033:         $selfenroll_text = &mt('Only show communities which currently allow self-enrollment (or will allow it in the future)');
 1034:     } else {
 1035:         $selfenroll_text = &mt('Only show courses which currently allow self-enrollment (or will allow it in the future)');
 1036:     }
 1037:     $output .= '<span class="LC_nobreak">'.
 1038:                '<label><input type="checkbox" name="showselfenroll" value="1" '.
 1039:                $show_selfenroll_status.'/>'.$selfenroll_text.
 1040:                '</label></span><br />';
 1041:     if ($is_dc || $canviewall) {
 1042:         my ($titlesref,$orderref) = &get_statustitles('filters');
 1043:         my $showdetails_status;
 1044:         if ($env{'form.showdetails'}) {
 1045:             $showdetails_status = 'checked="checked" ';
 1046:         }
 1047:         my $showhidden_status;
 1048:         if ($env{'form.showhidden'}) {
 1049:             $showhidden_status = 'checked="checked" ';
 1050:         }
 1051:         my @currstatuses = &Apache::loncommon::get_env_multiple('form.showcounts');
 1052:         my ($details_text,$hidden_text,$statusdisplay,$cellborder);
 1053:         my $wasactivedisplay = 'none';
 1054:         if ($env{'form.showdetails'}) {
 1055:             $statusdisplay = 'block';
 1056:             $cellborder = 'border-left: 1px solid;';
 1057:             if (grep(/^Previous$/,@currstatuses)) {
 1058:                 $wasactivedisplay = 'block';
 1059:             }
 1060:         } else {
 1061:             $statusdisplay = 'none';
 1062:             $cellborder = 'border-left: 0px';
 1063:         }
 1064:         if ($env{'form.currcat_0'} eq 'communities::0') {
 1065:             $details_text = &mt('Show full details for each community (domain staff only)');
 1066:             $hidden_text = &mt('Include communities set to be hidden from catalog (domain staff only)');
 1067:         } else {
 1068:             $details_text = &mt('Show full details for each course (domain staff only)');
 1069:             $hidden_text = &mt('Include courses set to be hidden from catalog (domain staff only)');
 1070:         }
 1071:         if ($is_dc) {
 1072:             $output .= '<span class="LC_nobreak">'.
 1073:                        '<label><input type="checkbox" name="showhidden" value="1" '.
 1074:                        $showhidden_status.'/>'.$hidden_text.
 1075:                        '</label></span><br />'."\n";
 1076:         }
 1077:         $output .= '<span class="LC_nobreak">'.
 1078:                    '<label><input type="checkbox" name="showdetails" value="1" '.
 1079:                    $showdetails_status.'onclick="toggleStatuses();" />'.
 1080:                    $details_text.'</label></span></td>'."\n".
 1081:                    '<td id="statuscell" valign="top" style="'.$cellborder.'">'.
 1082:                    '<div id="statuschoice" style="display:'.$statusdisplay.'">';
 1083:         if (ref($orderref) eq 'ARRAY') {
 1084:             if (@{$orderref} > 0) {
 1085:                 foreach my $type (@{$orderref}) {
 1086:                     my $checked;
 1087:                     if (grep(/^\Q$type\E$/,@currstatuses)) {
 1088:                         $checked = ' checked="checked"';
 1089:                     }
 1090:                     my $title;
 1091:                     if (ref($titlesref) eq 'HASH') {
 1092:                         $title = $titlesref->{$type};
 1093:                     }
 1094:                     unless ($title) {
 1095:                         $title = &mt($type);
 1096:                     }
 1097:                     my $onclick;
 1098:                     if ($type eq 'Previous') {
 1099:                         $onclick = ' onclick="toggleWasActive();"'; 
 1100:                     }
 1101:                     $output .= '<span class="LC_nobreak">'.
 1102:                                '<label><input type="checkbox" id="counts_'.$type.'"'.
 1103:                                ' name="showcounts" value="'.$type.'"'.$checked.$onclick.
 1104:                                ' />'.$title.'</label></span>';
 1105:                     if ($type eq 'Previous') {
 1106:                         my %milestonetext = &Apache::lonlocal::texthash (
 1107:                             accessend => 'immediately prior to default end access date',
 1108:                             enrollend => 'immediately prior to end date for auto-enrollment',
 1109:                             date      => 'immediately prior to specific date:',
 1110:                         );
 1111:                         my @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
 1112:                         $output .= '<span id="choosewasacctext" class="LC_nobreak">';
 1113:                         if ($checked) {
 1114:                             $output .= &get_wasactive_text();
 1115:                         }
 1116:                         $output .= '</span>'.
 1117:                                    '<div id="choosewasactive" style="display:'.$wasactivedisplay.'">'.
 1118:                                    '<table>';
 1119:                         my @milestones = ('accessend');
 1120:                         if (&Apache::lonnet::auto_run(undef,$codedom)) {
 1121:                             push(@milestones,'enrollend');
 1122:                         }
 1123:                         push(@milestones,'date');
 1124:                         foreach my $item (@milestones) {
 1125:                             my $checked;
 1126:                             if ($env{'form.state'} eq 'listing') {
 1127:                                 if ($env{'form.wasactive'} eq $item) {
 1128:                                     $checked = ' checked="checked"';
 1129:                                 }
 1130:                             } elsif ($item eq 'accessend') {
 1131:                                 $checked = ' checked="checked"';
 1132:                             }
 1133:                             $output .=
 1134:                                 '<tr><td width="10">&nbsp;</td><td>'.
 1135:                                 '<span class="LC_nobreak"><label>'.
 1136:                                 '<input type="radio" value="'.$item.'" name="wasactive"'.$checked.' />'.
 1137:                                 $milestonetext{$item}.'</label></span>';
 1138:                             if ($item eq 'date') {
 1139:                                 my $wasactiveon;
 1140:                                 if (grep(/^Previous$/,@currstatuses)) {
 1141:                                     $wasactiveon =
 1142:                                         &Apache::lonhtmlcommon::get_date_from_form('wasactiveon');
 1143:                                 } else {
 1144:                                     $wasactiveon = 'now';
 1145:                                 }
 1146:                                 $output .= ' '.
 1147:                                     &Apache::lonhtmlcommon::date_setter('coursecatalog',
 1148:                                                                         'wasactiveon',
 1149:                                                                         $wasactiveon,
 1150:                                                                         '','','',1,'',
 1151:                                                                         '','',1);
 1152:                             }
 1153:                             $output .= '</td></tr>';
 1154:                         }
 1155:                         $output .= '</table></div>';
 1156:                     }
 1157:                     $output .= '<br />';
 1158:                 }
 1159:             }
 1160:         }
 1161:         $output .= '</div></td>';
 1162:     } else {
 1163:         $output .= '</td>';  
 1164:     }
 1165:     $output .= '</tr></table></fieldset></div>'.
 1166:                '<div style="clear:both;margin:0;"></div>';  
 1167:     return $output;
 1168: }
 1169: 
 1170: sub user_is_dc {
 1171:     my ($codedom) = @_;
 1172:     if (exists($env{'user.role.dc./'.$codedom.'/'})) {
 1173:         my $livedc = 1;
 1174:         my $now = time;
 1175:         my ($start,$end)=split(/\./,$env{'user.role.dc./'.$codedom.'/'});
 1176:         if ($start && $start>$now) { $livedc = 0; }
 1177:         if ($end   && $end  <$now) { $livedc = 0; }
 1178:         return $livedc;
 1179:     }
 1180:     return;
 1181: }
 1182: 
 1183: sub canview_all {
 1184:     my ($knownuser,$codedom) = @_;
 1185:     my $canviewall = 0;
 1186:     my $page = 'coursecatalog';
 1187:     if (&LONCAPA::lonauthcgi::can_view($page)) {
 1188:         $canviewall = 1;
 1189:     } elsif (&LONCAPA::lonauthcgi::check_ipbased_access($page)) {
 1190:         $canviewall= 1;
 1191:     } elsif (($knownuser) && ($codedom ne '')) {
 1192:         if (&Apache::lonnet::allowed('dcd',$codedom)) {
 1193:             $canviewall = 1;
 1194:         }
 1195:     }
 1196:     return $canviewall;
 1197: }
 1198: 
 1199: sub get_statustitles {
 1200:     my ($caller) = @_;
 1201:     my @status_order = ('Active','Future','Previous');
 1202:     my %status_title;
 1203:     if ($caller eq 'filters') {
 1204:         %status_title = &Apache::lonlocal::texthash(
 1205:                            Previous => 'Show count for past access',
 1206:                            Active => 'Show count for current student access',
 1207:                            Future => 'Show count for future student access',
 1208:                         );
 1209:         if ($env{'form.currcat_0'} eq 'communities::0') {
 1210:             $status_title{'Active'} = 'Show count for current member access';
 1211:             $status_title{'Future'} = 'Show count for future member access'; 
 1212:         }
 1213:     } else {    
 1214:         %status_title = &Apache::lonlocal::texthash(
 1215:                            Previous => 'Previous access',
 1216:                            Active => 'Current access',
 1217:                            Future => 'Future access',
 1218:                         );
 1219:     }
 1220:     return (\%status_title,\@status_order);
 1221: }
 1222: 
 1223: sub get_wasactive_text {
 1224:     my $wasacctext = ' -- ';
 1225:     if ($env{'form.currcat_0'} eq 'communities::0') {
 1226:         $wasacctext .= &mt('where member access status was current ...');
 1227:     } else {
 1228:         $wasacctext .= &mt('where student access status was current ...');
 1229:     }
 1230:     return $wasacctext;
 1231: }
 1232: 
 1233: sub search_official_courselist {
 1234:     my ($domain,$numtitles,$codetitles) = @_;
 1235:     my $instcode = &Apache::courseclassifier::instcode_search_str($domain,$numtitles,$codetitles);
 1236:     my $showhidden;
 1237:     if (&user_is_dc($domain)) {
 1238:         $showhidden = $env{'form.showhidden'};
 1239:     }
 1240:     my %courses = 
 1241:         &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',undef,undef,
 1242:                                       'Course',1,$env{'form.showselfenroll'},undef,
 1243:                                       $showhidden,'coursecatalog');
 1244:     return %courses;
 1245: }
 1246: 
 1247: sub search_courselist {
 1248:     my ($domain,$subcats) = @_;
 1249:     my $cat_maxdepth = $env{'form.catalog_maxdepth'};
 1250:     my $filter = $env{'form.currcat_'.$cat_maxdepth};
 1251:     if (($filter eq '') && ($cat_maxdepth > 0)) {
 1252:         my $shallower = $cat_maxdepth - 1;
 1253:         $filter = $env{'form.currcat_'.$shallower};
 1254:     }
 1255:     my %courses;
 1256:     my $filterstr;
 1257:     if ($filter ne '') {
 1258:         if ($env{'form.withsubcats'}) {
 1259:             if (ref($subcats) eq 'HASH') {
 1260:                 if (ref($subcats->{$filter}) eq 'ARRAY') {
 1261:                     $filterstr = join('&',@{$subcats->{$filter}});
 1262:                     if ($filterstr ne '') {
 1263:                         $filterstr = $filter.'&'.$filterstr;
 1264:                     }
 1265:                 } else {
 1266:                     $filterstr = $filter;
 1267:                 }
 1268:             } else {
 1269:                 $filterstr = $filter;
 1270:             }  
 1271:         } else {
 1272:             $filterstr = $filter; 
 1273:         }
 1274:         my ($showhidden,$typefilter);
 1275:         if (&user_is_dc($domain)) {
 1276:             $showhidden = $env{'form.showhidden'};
 1277:         }
 1278:         if ($env{'form.currcat_0'} eq 'communities::0') {
 1279:             $typefilter = 'Community';
 1280:         } else {
 1281:             $typefilter = '.';
 1282:         }
 1283:         %courses = 
 1284:             &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
 1285:                                           $typefilter,1,$env{'form.showselfenroll'},
 1286:                                           $filterstr,$showhidden,'coursecatalog');
 1287:     }
 1288:     return %courses;
 1289: }
 1290: 
 1291: sub print_course_listing {
 1292:     my ($domain,$numtitles,$trails,$allitems,$subcats,$codetitles,$canviewall) = @_;
 1293:     my $output;
 1294:     my %courses;
 1295:     my $knownuser = &user_is_known();
 1296:     my $canviewall = &canview_all();
 1297:     my $details = $env{'form.coursenum'};
 1298:     if (&user_is_dc($domain) || $canviewall) {
 1299:         if ($env{'form.showdetails'}) {
 1300:             $details = 1;
 1301:         }
 1302:     }
 1303:     if ($env{'form.coursenum'} ne '') {
 1304:         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
 1305:                                                  $env{'form.coursenum'},
 1306:                                                  undef,undef,'.',1);
 1307:         if (keys(%courses) == 0) {
 1308:             $output = '<p class="LC_error">';
 1309:             if ($env{'form.currcat_0'} eq 'communities::0') {
 1310:                 $output .= &mt('The courseID provided does not match a community in this domain.');
 1311:             } else { 
 1312:                 $output .= &mt('The courseID provided does not match a course in this domain.');
 1313:             }
 1314:             $output .= '</p>';
 1315:             return $output;
 1316:         }
 1317:     } else {
 1318:         if ($env{'form.currcat_0'} eq 'instcode::0') {
 1319:             %courses = &search_official_courselist($domain,$numtitles,$codetitles);
 1320:         } else {
 1321:             %courses = &search_courselist($domain,$subcats);
 1322:         }
 1323:         if (keys(%courses) == 0) {
 1324:             $output = '<p class="LC_info">';
 1325:             if ($env{'form.currcat_0'} eq 'communities::0') {
 1326:                 $output .= &mt('No communities match the criteria you selected.');
 1327:             } else {
 1328:                 $output .= &mt('No courses match the criteria you selected.');
 1329:             }
 1330:             $output .= '</p>';
 1331:             return $output;
 1332:         }
 1333:         if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain)) && (!$canviewall)) {
 1334:             $output = '<b>'.&mt('Note for students:').'</b> '
 1335:                      .&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.')
 1336:                      .'<br /><br />';
 1337:         }
 1338:     }
 1339:     my $now = time;
 1340:     $output .= &construct_data_table($knownuser,$domain,\%courses,$details,undef,
 1341:                                      $now,$trails,$allitems,$canviewall);
 1342:     $output .= "\n".'<form name="linklaunch" method="post" action="">'.
 1343:                '<input type="hidden" name="backto" value="coursecatalog" />'.
 1344:                '<input type="hidden" name="courseid" value="" />'.
 1345:                &Apache::lonhtmlcommon::echo_form_input(['catalogfilter','courseid']).'</form>';
 1346:     return $output;
 1347: }
 1348: 
 1349: sub construct_data_table {
 1350:     my ($knownuser,$domain,$courses,$details,$usersections,$now,$trails,$allitems,$canviewall) = @_;
 1351:     my %sortname;
 1352:     if (($details eq '') || ($env{'form.showdetails'})) {
 1353:         $sortname{'Code'} = 'code';
 1354:         $sortname{'Categories'} = 'cats';
 1355:         $sortname{'Title'} = 'title';
 1356:         $sortname{'Owner & Co-owner(s)'} = 'owner';
 1357:     }
 1358:     my $output = &Apache::loncommon::start_data_table().
 1359:                  &Apache::loncommon::start_data_table_header_row();
 1360:     my @coltitles = ('Count');
 1361:     if ($env{'form.currcat_0'} eq 'instcode::0') {
 1362:         push(@coltitles,'Code');
 1363:     } else {
 1364:         push(@coltitles,'Categories');
 1365:     }
 1366:     push(@coltitles,('Sections','Crosslisted','Title','Owner & Co-owner(s)'));
 1367:     if (ref($usersections) eq 'HASH') {
 1368:        $coltitles[1] = 'Your Section';
 1369:     }
 1370:     foreach my $item (@coltitles) {
 1371:         $output .= '<th>';
 1372:         if (defined($sortname{$item})) {
 1373:             $output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
 1374:         } elsif ($item eq 'Count') {
 1375:             $output .= '&nbsp;&nbsp;';
 1376:         } else {
 1377:             $output .= &mt($item);
 1378:         }
 1379:         $output .= '</th>';
 1380:     }
 1381:     my (@fields,%fieldtitles,$wasactiveon);
 1382:     if ($knownuser || ($canviewall && $details)) {
 1383:         if ($details) {
 1384:             if ($env{'form.currcat_0'} eq 'communities::0') {
 1385:                 $output .= '<th>'.&mt('Default Access Dates for Members').'</th>'.
 1386:                            '<th>'.&mt('Member Counts').'</th>';
 1387:             } else {
 1388:                 $output .=
 1389:                     '<th>'.&mt('Default Access Dates for Students').'</th>'.
 1390:                     '<th>'.&mt('Student Counts').'</th>'.
 1391:                     '<th>'.&mt('Auto-enrollment of[_1]registered students','<br />').'</th>';
 1392:             }
 1393:             my ($titlesref,$orderref) = &get_statustitles();
 1394:             my @statuses;
 1395:             if (&user_is_dc($domain) || $canviewall) {
 1396:                 @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
 1397:                 if (grep(/^Previous$/,@statuses)) {
 1398:                     if ($env{'form.wasactive'} eq 'date') { 
 1399:                         $wasactiveon = 
 1400:                             &Apache::lonhtmlcommon::get_date_from_form('wasactiveon');
 1401:                     } else {
 1402:                         $wasactiveon = $env{'form.wasactive'};
 1403:                     }
 1404:                 }
 1405:                 if (ref($orderref) eq 'ARRAY') {
 1406:                     foreach my $status (@{$orderref}) {
 1407:                         if (grep(/^\Q$status\E$/,@statuses)) {
 1408:                             push(@fields,$status); 
 1409:                         }
 1410:                     }
 1411:                 }
 1412:             } else {
 1413:                 @fields = ('Active','Future');
 1414:             }
 1415:             foreach my $status (@fields) {
 1416:                 my $title;
 1417:                 if (ref($titlesref) eq 'HASH') {
 1418:                     $title = $titlesref->{$status};
 1419:                 }
 1420:                 unless ($title) {
 1421:                     $title = &mt($status);
 1422:                 }
 1423:                 $fieldtitles{$status} = $title;
 1424:             }
 1425:         } else {
 1426:             $output .= '<th>'.&mt('Details').'</th>';
 1427:         }
 1428:     }
 1429:     $output .= '<th>'.&mt('Self-enroll (if permitted)').'</th>';
 1430:     &Apache::loncommon::end_data_table_header_row();
 1431:     my (%numbers,%creditsum);
 1432:     my ($showcredits,$defofficial,$defunofficial,$deftextbook);
 1433:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
 1434:     unless ($env{'form.currcat_0'} eq 'communities::0') {
 1435:         if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
 1436:             $showcredits = 1;
 1437:             $defofficial = $domdefaults{'officialcredits'};
 1438:             $defunofficial = $domdefaults{'unofficialcredits'};
 1439:             $deftextbook = $domdefaults{'textbookcredits'};
 1440:         }
 1441:     }
 1442:     my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$canviewall,$details,
 1443:                                             $usersections,\@fields,\%fieldtitles,
 1444:                                             $wasactiveon,\%numbers,\%creditsum,
 1445:                                             $showcredits,$defofficial,$defunofficial,$deftextbook);
 1446:     my %Sortby;
 1447:     foreach my $course (sort(keys(%{$courses}))) {
 1448:         if ($env{'form.sortby'} eq 'code') {
 1449:             push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
 1450:         } elsif ($env{'form.sortby'} eq 'cats') {
 1451:             push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course);
 1452:         } elsif ($env{'form.sortby'} eq 'owner') {
 1453:             push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
 1454:         } else {
 1455:             my $clean_title = $courseinfo{$course}{'title'};
 1456:             $clean_title =~ s/\W+//g;
 1457:             if ($clean_title eq '') {
 1458:                 $clean_title = $courseinfo{$course}{'title'};
 1459:             }
 1460:             push(@{$Sortby{$clean_title}},$course);
 1461:         }
 1462:     }
 1463:     my @sorted_courses;
 1464:     if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') ||
 1465:         ($env{'form.sortby'} eq 'cats')) {
 1466:         @sorted_courses = sort(keys(%Sortby));
 1467:     } else {
 1468:         @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
 1469:     }
 1470:     my $count = 1;
 1471:     my $totalsec = 0;
 1472:     my %clutteredxlists;
 1473:     foreach my $course (keys(%courseinfo)) {
 1474:         if (ref($courseinfo{$course}) eq 'HASH') {
 1475:             if ($courseinfo{$course}{'xlist'} ne '') {
 1476:                 my $crskey = $courseinfo{$course}{'cnum'}.':'.$courseinfo{$course}{'code'};
 1477:                 my @xlists = split(/,\s/,$courseinfo{$course}{'xlist'});
 1478:                 $clutteredxlists{$crskey} = \@xlists;
 1479:             }
 1480:         }
 1481:     }
 1482:     if (keys(%clutteredxlists)) {
 1483:         my %reformattedxlists = &Apache::lonnet::auto_instsec_reformat($domain,'declutter',\%clutteredxlists);
 1484:         foreach my $crskey (keys(%reformattedxlists)) {
 1485:             if (ref($reformattedxlists{$crskey}) eq 'ARRAY') {
 1486:                 my $course = $domain.'_'.(split(/:/,$crskey))[0];
 1487:                 $courseinfo{$course}{'xlist'} = join(', ',@{$reformattedxlists{$crskey}});
 1488:             }
 1489:         }
 1490:     }
 1491:     foreach my $item (@sorted_courses) {
 1492:         foreach my $course (@{$Sortby{$item}}) {
 1493:             $output.=&Apache::loncommon::start_data_table_row(); 
 1494:             $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,
 1495:                                      \$count,$now,$course,$trails,$allitems,\%numbers,$canviewall);
 1496:             $output.=&Apache::loncommon::end_data_table_row();
 1497:         }
 1498:     }
 1499:     if (($knownuser || $canviewall) && ($count > 1) && $env{'form.showdetails'}) {
 1500:         if (&user_is_dc($domain) || $canviewall) {
 1501:             my %lt = &Apache::lonlocal::texthash (
 1502:                                                      'Active'   => 'Total current students',
 1503:                                                      'Future'   => 'Total future students',
 1504:                                                      'Previous' => 'Total previous students',
 1505:                                                      'courses'  => 'Total unique codes and courses without codes',
 1506:                                                      'sections' => 'Total sections',
 1507:                                                      'xlists'   => 'Total cross-listings',
 1508:                                                  );
 1509:             if ($showcredits) {
 1510:                 $lt{'cr_Active'} = &mt('Total current student credit hours');
 1511:                 $lt{'cr_Future'} = &mt('Total future student credit hours');
 1512:                 $lt{'cr_Previous'} = &mt('Total previous student credit hours');
 1513:             }
 1514:             if ($env{'form.currcat_0'} eq 'communities::0') {
 1515:                 $lt{'courses'} = &mt('Total communities');
 1516:                 $lt{'Active'} = &mt('Total current members'); 
 1517:                 $lt{'Future'} = &mt('Total future members');
 1518:                 $lt{'Previous'} = &mt('Total previous members');
 1519:             }
 1520:             my $colspan = 8;
 1521:             if ($showcredits) {
 1522:                 $colspan = 4;
 1523:             }
 1524:             $output .= '<tr class="LC_footer_row">'.
 1525:                        '<td colspan="2">&nbsp;</td>'.
 1526:                        '<td colspan="'.$colspan.'">'.
 1527:                        '<table border="0">';
 1528:             foreach my $item ('courses','sections','xlists') {
 1529:                 $output .= '<tr>'.
 1530:                            '<td>'.$lt{$item}.'</td><td>&nbsp;</td>'.
 1531:                            '<td align="right">'.$numbers{$item}.'</td>'.
 1532:                            '</tr>'."\n";
 1533:             }
 1534:             if (@fields > 0) { 
 1535:                 foreach my $status (@fields) {
 1536:                     $output .= '<tr>'.
 1537:                                '<td>'.$lt{$status}.'</td><td>&nbsp;</td>'.
 1538:                                '<td align="right">'.$numbers{$status}.'</td>'.
 1539:                                '</tr>'."\n";
 1540:                 }
 1541:             }
 1542:             $output .= '</table></td>';
 1543:             if ($showcredits) {
 1544:                 $output .= '<td colspan="'.$colspan.'" valign="bottom"><table>';
 1545:                 foreach my $status (@fields) {
 1546:                     $output .= '<tr>'.
 1547:                                '<td>'.$lt{'cr_'.$status}.'</td><td>&nbsp;</td>'.
 1548:                                '<td align="right">'.$creditsum{$status}.'</td></tr>';
 1549:                 }
 1550:                 $output .= '</table></td></tr>';
 1551:             }
 1552:         }
 1553:     }
 1554:     $output .= &Apache::loncommon::end_data_table();
 1555:     return $output;
 1556: }
 1557: 
 1558: sub build_courseinfo_hash {
 1559:     my ($courses,$knownuser,$domain,$canviewall,$details,$usersections,$fields,$fieldtitles,
 1560:         $wasactiveon,$numbers,$creditsum,$showcredits,$defofficial,$defunofficial) = @_;
 1561:     my %courseinfo;
 1562:     my $now = time;
 1563:     my $gettotals;
 1564:     if ((keys(%{$courses}) > 0) && (&user_is_dc($domain) || $canviewall) && ($details)) {
 1565:         $gettotals = 1;
 1566:     }
 1567:     my (%uniquecodes,$nocodes,$defcreds);
 1568:     foreach my $course (keys(%{$courses})) {
 1569:         my $descr;
 1570:         if (ref($courses->{$course}) eq 'HASH') {
 1571:             $descr = $courses->{$course}{'description'}; 
 1572:         }
 1573:         my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
 1574:         $cleandesc=~s/'/\\'/g;
 1575:         $cleandesc =~ s/^\s+//;
 1576:         my ($cdom,$cnum)=split(/\_/,$course);
 1577:         my ($instcode,$singleowner,$ttype,$selfenroll_types,$extsyllplain,
 1578:             $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories);
 1579:         if (ref($courses->{$course}) eq 'HASH') {
 1580:             $descr = $courses->{$course}{'description'};
 1581:             $instcode =  $courses->{$course}{'inst_code'};
 1582:             $singleowner = $courses->{$course}{'owner'};
 1583:             $ttype =  $courses->{$course}{'type'};
 1584:             $selfenroll_types = $courses->{$course}{'selfenroll_types'};
 1585:             $selfenroll_start = $courses->{$course}{'selfenroll_start_date'};
 1586:             $selfenroll_end = $courses->{$course}{'selfenroll_end_date'};
 1587:             $categories = $courses->{$course}{'categories'};
 1588:             $extsyllplain = $courses->{$course}{'extsyllplain'};
 1589:             push(@owners,$singleowner);
 1590:             if ($courses->{$course}{'co-owners'} ne '') {
 1591:                 foreach my $item (split(/,/,$courses->{$course}{'co-owners'})) {
 1592:                     push(@owners,$item);
 1593:                 }
 1594:             }
 1595:         }
 1596:         if ($instcode ne '') {
 1597:             $uniquecodes{$instcode} = 1;
 1598:         } else {
 1599:             $nocodes ++;
 1600:         } 
 1601:         foreach my $owner (@owners) {
 1602:             my ($ownername,$ownerdom); 
 1603:             if ($owner =~ /:/) {
 1604:                 ($ownername,$ownerdom) = split(/:/,$owner);
 1605:             } else {
 1606:                 $ownername = $owner;
 1607:                 if ($owner ne '') {
 1608:                     $ownerdom = $cdom;
 1609:                 }
 1610:             }
 1611:             if ($ownername ne '' && $ownerdom ne '') {
 1612:                 my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
 1613:                 $ownernames{$ownername.':'.$ownerdom} = \%namehash; 
 1614:             }
 1615:         }
 1616:         $courseinfo{$course}{'cdom'} = $cdom;
 1617:         $courseinfo{$course}{'cnum'} = $cnum;
 1618:         $courseinfo{$course}{'code'} = $instcode;
 1619:         my @lastnames;
 1620:         foreach my $owner (keys(%ownernames)) {
 1621:             if (ref($ownernames{$owner}) eq 'HASH') {
 1622:                 push(@lastnames,$ownernames{$owner}{'lastname'});
 1623:             }
 1624:         }
 1625:         $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
 1626:         $courseinfo{$course}{'title'} = $cleandesc;
 1627:         $courseinfo{$course}{'owner'} = $singleowner;
 1628:         $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types;
 1629:         $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start;
 1630:         $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end;
 1631:         $courseinfo{$course}{'categories'} = $categories;
 1632:         $courseinfo{$course}{'extsyllplain'} = $extsyllplain;
 1633: 
 1634:         my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
 1635:         my @classids;
 1636:         my @crosslistings;
 1637:         my ($seclist,$numsec) = 
 1638:             &identify_sections($coursehash{'internal.sectionnums'});
 1639:         $courseinfo{$course}{'seclist'} = $seclist;
 1640:         my ($xlist_items,$numxlist) = 
 1641:             &identify_sections($coursehash{'internal.crosslistings'});
 1642:         if (ref($numbers) eq 'HASH') {
 1643:             $numbers->{'sections'} += $numsec; 
 1644:             $numbers->{'xlists'} += $numxlist;  
 1645:         }
 1646:         my $showsyllabus = 1; # default is to include a syllabus link
 1647:         if (defined($coursehash{'showsyllabus'})) {
 1648:             $showsyllabus = $coursehash{'showsyllabus'};
 1649:         }
 1650:         $courseinfo{$course}{'showsyllabus'} = $showsyllabus;
 1651:         if ($showcredits) {
 1652:             if ($coursehash{'internal.defaultcredits'}) {
 1653:                 $courseinfo{$course}{'defaultcredits'} = $coursehash{'internal.defaultcredits'};
 1654:             } elsif ($instcode ne '') {
 1655:                 $courseinfo{$course}{'defaultcredits'} = $defofficial;
 1656:             } else {
 1657:                 $courseinfo{$course}{'defaultcredits'} = $defunofficial;
 1658:             }
 1659:             $defcreds = $courseinfo{$course}{'defaultcredits'};
 1660:         }
 1661:         if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
 1662:             (($knownuser || $canviewall) && ($details == 1))) {
 1663:             my $milestone;
 1664:             if ($wasactiveon eq 'accessend') {
 1665:                 if ($coursehash{'default_enrollment_end_date'}) {
 1666:                     $milestone = $coursehash{'default_enrollment_end_date'};
 1667:                 } else {
 1668:                     $milestone = time;
 1669:                 }
 1670:             } elsif ($wasactiveon eq 'enrollend') {
 1671:                 if ($coursehash{'internal.autoend'}) {
 1672:                     $milestone = $coursehash{'internal.autoend'};
 1673:                 } else {
 1674:                     $milestone = time;
 1675:                 }
 1676:             } else {
 1677:                 $milestone = $wasactiveon;
 1678:             }
 1679:             $courseinfo{$course}{'counts'} =  
 1680:                 &count_students($cdom,$cnum,$numsec,$fields,$fieldtitles,$gettotals,
 1681:                                 $numbers,$creditsum,$showcredits,$defcreds,$milestone);
 1682:             if ($instcode ne '') {
 1683:                 $courseinfo{$course}{'autoenrollment'} =
 1684:                     &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
 1685:                                      $instcode,\@owners,$cdom,$cnum);
 1686:             }
 1687:             my $startaccess = '';
 1688:             my $endaccess = '';
 1689:             my $accessdates;
 1690:             if ( defined($coursehash{'default_enrollment_start_date'}) ) {
 1691:                 $startaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_start_date'});
 1692:             }
 1693:             if ( defined($coursehash{'default_enrollment_end_date'}) ) {
 1694:                 $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'});
 1695:                 if ($coursehash{'default_enrollment_end_date'} == 0) {
 1696:                     $endaccess = &mt('No ending date');
 1697:                 }
 1698:             }
 1699:             if ($startaccess) {
 1700:                 $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$startaccess).'<br />';
 1701:             }
 1702:             if ($endaccess) {
 1703:                 $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$endaccess).'<br />';
 1704:             }
 1705:             if (($selfenroll_types ne '') && 
 1706:                 ($selfenroll_end > 0 && $selfenroll_end > $now)) {
 1707:                 my ($selfenroll_start_access,$selfenroll_end_access);
 1708:                 if (($coursehash{'default_enrollment_start_date'} ne 
 1709:                      $coursehash{'internal.selfenroll_start_access'}) ||
 1710:                    ($coursehash{'default_enrollment_end_date'} ne 
 1711:                     $coursehash{'internal.selfenroll_end_access'})) {
 1712:                     if ( defined($coursehash{'internal.selfenroll_start_access'}) ) {
 1713:                         $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'});
 1714:                     }
 1715:                     if ( defined($coursehash{'default_enrollment_end_date'}) ) {
 1716:                         $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'});
 1717:                         if ($coursehash{'internal.selfenroll_end_access'} == 0) {
 1718:                             $selfenroll_end_access = &mt('No ending date');
 1719:                         }
 1720:                     }
 1721:                     if ($selfenroll_start_access || $selfenroll_end_access) {
 1722:                         $accessdates .= '<br/><br /><i>'.&mt('Self-enrollers:').'</i><br />';
 1723:                         if ($selfenroll_start_access) {
 1724:                             $accessdates .= '<i>'.&mt('From:[_1]','</i> '.$selfenroll_start_access).'<br />';
 1725:                         }
 1726:                         if ($selfenroll_end_access) {
 1727:                             $accessdates .= '<i>'.&mt('To:[_1]','</i> '.$selfenroll_end_access).'<br />';
 1728:                         }
 1729:                     }
 1730:                 }
 1731:             }
 1732:             $courseinfo{$course}{'access'} = $accessdates;
 1733:         }
 1734:         if ($xlist_items eq '') {
 1735:             $xlist_items = &mt('No');
 1736:         }
 1737:         $courseinfo{$course}{'xlist'} = $xlist_items;
 1738:     }
 1739:     if (ref($numbers) eq 'HASH') {
 1740:         $numbers->{'courses'} = $nocodes + scalar(keys(%uniquecodes));
 1741:     }
 1742:     return %courseinfo;
 1743: }
 1744: 
 1745: sub count_students {
 1746:     my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$creditsum,
 1747:         $showcredits,$defcreds,$wasactiveon) = @_;
 1748:     my $countslist = '<span class="LC_nobreak">'.
 1749:                      &mt('[quant,_1,section,sections,No sections]',$numsec).'</span>';
 1750:     my (@fields,%titles,$showexpired);
 1751:     if ((ref($fieldsref) eq 'ARRAY') && (ref($titlesref) eq 'HASH') &&
 1752:         (ref($numbers) eq 'HASH')) {
 1753:         @fields = @{$fieldsref};
 1754:         %titles = %{$titlesref};
 1755:         if (grep(/^Previous$/,@fields)) {
 1756:             $showexpired = 1;
 1757:         }
 1758:     } else {
 1759:         return;
 1760:     }
 1761:     my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum);
 1762:     my (%student_count,%credit_count);
 1763:     %student_count = (
 1764:                            Active   => 0,
 1765:                            Future   => 0,
 1766:                            Previous => 0,
 1767:                      );
 1768:     if ($showcredits) {
 1769:         %credit_count = (
 1770:                           Active   => 0,
 1771:                           Future   => 0,
 1772:                           Previous => 0,
 1773:                         );
 1774:     }
 1775:     my %idx;
 1776:     $idx{'status'} = &Apache::loncoursedata::CL_STATUS();
 1777:     $idx{'end'}    = &Apache::loncoursedata::CL_END();
 1778:     $idx{'credits'} = &Apache::loncoursedata::CL_CREDITS();
 1779:     while (my ($student,$data) = each(%$classlist)) {
 1780:         my $status = $data->[$idx{'status'}];
 1781:         my $credits = $data->[$idx{'credits'}];
 1782:         if ($credits eq '') {
 1783:             $credits = $defcreds;  
 1784:         }
 1785:         if ($status eq 'Expired') {
 1786:             if (($showexpired) &&
 1787:                 ($data->[$idx{'end'}] >= $wasactiveon)) {
 1788:                 $student_count{'Previous'} ++;
 1789:                 if ($showcredits) {
 1790:                     $credit_count{'Previous'} += $credits; 
 1791:                 }
 1792:             }
 1793:         } else {
 1794:             $student_count{$status} ++;
 1795:             if ($showcredits) {
 1796:                 $credit_count{$status} += $credits;
 1797:             }
 1798:         }
 1799:     }
 1800:     if (@fields) {
 1801:         $countslist .= ':<br />';
 1802:         foreach my $status (@fields) {
 1803:             $countslist .= '<span class="LC_nobreak">'.$titles{$status}.': '.
 1804:                            $student_count{$status}.'</span><br />';
 1805:             $numbers->{$status} += $student_count{$status};
 1806:             if ($showcredits) {
 1807:                 $creditsum->{$status} += $credit_count{$status};
 1808:             }
 1809:         }
 1810:     }
 1811:     return $countslist;
 1812: }
 1813: 
 1814: sub courseinfo_row {
 1815:     my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems,$numbers,$canviewall) = @_;
 1816:     my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
 1817:         $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories,
 1818:         $extsyllplain);
 1819:     if (ref($info) eq 'HASH') {
 1820:         $cdom = $info->{'cdom'};
 1821:         $cnum = $info->{'cnum'};
 1822:         $title = $info->{'title'};
 1823:         $ownerlast = $info->{'ownerlastnames'};
 1824:         $code = $info->{'code'};
 1825:         $owner = $info->{'owner'};
 1826:         $seclist = $info->{'seclist'};
 1827:         $xlist_items = $info->{'xlist'};
 1828:         $accessdates = $info->{'access'};
 1829:         $counts = $info->{'counts'};
 1830:         $autoenrollment = $info->{'autoenrollment'};
 1831:         $showsyllabus = $info->{'showsyllabus'};
 1832:         $extsyllplain = $info->{'extsyllplain'};
 1833:         $categories = $info->{'categories'};
 1834:     } else {
 1835:         $output = '<td colspan="8">'.&mt('No information available for [_1].',
 1836:                                          $code).'</td>';
 1837:         return $output;
 1838:     }
 1839:     $output .= '<td>'.$$countref.'</td>';
 1840:     if ($env{'form.currcat_0'} eq 'instcode::0') {
 1841:         $output .= '<td>'.$code.'</td>';
 1842:     } else {
 1843:         my ($categorylist,@cats);
 1844:         if ($categories ne '') {
 1845:             @cats = split('&',$categories);
 1846:         }
 1847:         if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) {
 1848:             my @categories = map { $trails->[$allitems->{$_}]; } @cats;
 1849:             $categorylist = join('<br />',@categories);
 1850:         }
 1851:         if ($categorylist eq '') {
 1852:             $categorylist = '&nbsp;';
 1853:         }
 1854:         $output .= '<td>'.$categorylist.'</td>';
 1855:     }
 1856:     $output .= '<td>'.$seclist.'</td>'.
 1857:                '<td>'.$xlist_items.'</td>'.
 1858:                '<td>'.$title.'&nbsp;<font size="-2">';
 1859:     if ($showsyllabus) {
 1860:         my $usehttp = 0;
 1861:         if (($ENV{'SERVER_PORT'} == 443) && ($extsyllplain)) {
 1862:             unless (&Apache::lonnet::uses_sts()) {
 1863:                 $usehttp = 1;
 1864:             }
 1865:         }
 1866:         $output .= '<a href="javascript:ToSyllabus('."'$cdom','$cnum','$usehttp'".')">'.&mt('Syllabus').'</a>';
 1867:     } else {
 1868:         $output .= '&nbsp;';
 1869:     }
 1870:     $output .= '</font></td>'.
 1871:                '<td>'.$ownerlast.'</td>';
 1872:     if (($knownuser) || ($canviewall && $details)) {
 1873:         if ($details) {
 1874:             $output .=
 1875:                 '<td>'.$accessdates.'</td>'.
 1876:                 '<td>'.$counts.'</td>';
 1877:             unless ($env{'form.currcat_0'} eq 'communities::0') {
 1878:                 $output .= '<td>'.$autoenrollment.'</td>';
 1879:             }
 1880:         } else {
 1881:             $output .= "<td><a href=\"javascript:setCourseId('$cnum')\">".&mt('Show more details').'</a></td>';
 1882:         }
 1883:     }
 1884:     my $selfenroll = &selfenroll_status($info,$course);
 1885:     if ($selfenroll) {
 1886:         $output .= '<td>'.$selfenroll.'</td>';
 1887:     } else {
 1888:         $output .= '<td>&nbsp;</td>';
 1889:     }
 1890:     $$countref ++;
 1891:     return $output;
 1892: }
 1893: 
 1894: sub selfenroll_status {
 1895:     my ($info,$course) = @_;
 1896:     my $now = time;
 1897:     my $output;
 1898:     if (ref($info) eq 'HASH') {
 1899:         if ($info->{'selfenroll_types'}) {
 1900:             my $showstart = &Apache::lonlocal::locallocaltime($info->{'selfenroll_start'});
 1901:             my $showend = &Apache::lonlocal::locallocaltime($info->{'selfenroll_end'});
 1902:             if (($info->{'selfenroll_end'} > 0) && ($info->{'selfenroll_end'} > $now)) {
 1903:                 if (($info->{'selfenroll_start'} > 0) && ($info->{'selfenroll_start'} > $now)) {
 1904:                     $output = &mt('Starts: [_1]','<span class="LC_cusr_emph">'.$showstart.'</span>').'<br />'.&mt('Ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>');
 1905:                 } else {
 1906:                     $output = '<a href="javascript:ToSelfenroll('."'$course'".')">'.
 1907:                               &mt('Enroll in course').'</a><br />';
 1908:                     if ($info->{'selfenroll_end'} == 0) {
 1909:                         $output .= &mt('Available permanently');
 1910:                     } elsif ($info->{'selfenroll_end'} > $now) {
 1911:                         $output .= &mt('Self-enrollment ends: [_1]','<span class="LC_cusr_emph">'.$showend.'</span>');
 1912:                     }
 1913:                 }
 1914:             }
 1915:         }
 1916:     }
 1917:     return $output;
 1918: }
 1919: 
 1920: sub identify_sections {
 1921:     my ($seclist) = @_;
 1922:     my @secnums;
 1923:     if ($seclist =~ /,/) {
 1924:         my @sections = split(/,/,$seclist);
 1925:         foreach my $sec (@sections) {
 1926:             $sec =~ s/:[^:]*$//;
 1927:             push(@secnums,$sec);
 1928:         }
 1929:     } else {
 1930:         if ($seclist =~ m/^([^:]+):/) {
 1931:             my $sec = $1;
 1932:             if (!grep(/^\Q$sec\E$/,@secnums)) {
 1933:                 push(@secnums,$sec);
 1934:             }
 1935:         }
 1936:     }
 1937:     @secnums = sort {$a <=> $b} @secnums;
 1938:     $seclist = join(', ',@secnums);
 1939:     my $numsec = @secnums;
 1940:     return ($seclist,$numsec);
 1941: }
 1942: 
 1943: sub get_valid_classes {
 1944:     my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
 1945:     my $response;
 1946:     my (@sections,@format_sections,@xlists,%possclasses,%okclasses,%validations);
 1947:     @{$validations{'sections'}} = ();
 1948:     @{$validations{'xlists'}} = ();
 1949:     my $totalitems = 0;
 1950:     if ($seclist) {
 1951:         @sections = split(/,\s+/,$seclist);
 1952:         my $crskey = $cnum.':'.$crscode;
 1953:         my %formattedsec = &Apache::lonnet::auto_instsec_reformat($cdom,'clutter',
 1954:                                                                   {$crskey => \@sections});
 1955:         if (ref($formattedsec{$crskey}) eq 'ARRAY') {
 1956:             @format_sections = @{$formattedsec{$crskey}};
 1957:             map { $possclasses{$crscode.$_} = 1; } @format_sections;
 1958:         }
 1959:     }
 1960:     if ($xlist_items) {
 1961:         @xlists = split(/,\s+/,$xlist_items);
 1962:         map { $possclasses{$_} = 1; } @xlists;
 1963:     }
 1964:     my %okclasses = &Apache::lonnet::auto_validate_instclasses($cdom,$cnum,$owners,
 1965:                                                                \%possclasses);
 1966:     if (keys(%okclasses)) {
 1967:         for (my $i=0; $i<@sections; $i++) {
 1968:             if ($okclasses{$crscode.$format_sections[$i]}) {
 1969:                 my $sec = $sections[$i];
 1970:                 if (!grep(/^\Q$sec\E$/,@{$validations{'sections'}})) {
 1971:                     push(@{$validations{'sections'}},$sec);
 1972:                     $totalitems ++;
 1973:                 }
 1974:             }
 1975:         }
 1976:         foreach my $item (@xlists) {
 1977:             if ($okclasses{$item}) {
 1978:                 if (!grep(/^\Q$item\E$/,@{$validations{'xlists'}})) {
 1979:                     push(@{$validations{'xlists'}},$item);
 1980:                     $totalitems ++;
 1981:                 }
 1982:             }
 1983:         }
 1984:     }
 1985:     if ($totalitems > 0) {
 1986:         if (@{$validations{'sections'}}) {
 1987:             $response = &mt('Sections:').' '.
 1988:                         join(', ',@{$validations{'sections'}}).'<br />';
 1989:         }
 1990:         if (@{$validations{'xlists'}}) {
 1991:             my $crskey = $cnum.':'.$crscode;
 1992:             my %reformattedxlists =
 1993:                 &Apache::lonnet::auto_instsec_reformat($cdom,'declutter',
 1994:                                                        {$crskey => $validations{'xlists'}});
 1995:             if (ref($reformattedxlists{$crskey}) eq 'ARRAY') {
 1996:                 $validations{'xlists'} = $reformattedxlists{$crskey};
 1997:             }
 1998:             $response .= &mt('Courses:').' '.
 1999:                         join(', ',@{$validations{'xlists'}});
 2000:         }
 2001:     }
 2002:     return $response;
 2003: }
 2004: 
 2005: sub autoenroll_info {
 2006:     my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
 2007:     my $autoenrolldates = &mt('Not enabled');
 2008:     if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
 2009:         my ($autostart,$autoend);
 2010:         if ( defined($coursehash->{'internal.autostart'}) ) {
 2011:             $autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
 2012:         }
 2013:         if ( defined($coursehash->{'internal.autoend'}) ) {
 2014:             $autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
 2015:         }
 2016:         if ($coursehash->{'internal.autostart'} > $now) {
 2017:             if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
 2018:                 $autoenrolldates = &mt('Not enabled');
 2019:             } else {
 2020:                 my $valid_classes = 
 2021:                    &get_valid_classes($seclist,$xlist_items,$code,
 2022:                                       $owners,$cdom,$cnum);
 2023:                 if ($valid_classes ne '') {
 2024:                     $autoenrolldates = &mt('Not enabled').'<br />'
 2025:                                       .&mt('Starts: [_1]',$autostart)
 2026:                                       .'<br />'.$valid_classes;
 2027:                 }
 2028:             }
 2029:         } else {
 2030:             if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
 2031:                 $autoenrolldates = &mt('Not enabled').'<br />'
 2032:                                   .&mt('Ended: [_1]',$autoend);
 2033:             } else {
 2034:                 my $valid_classes = &get_valid_classes($seclist,$xlist_items,
 2035:                                                        $code,$owners,$cdom,$cnum);
 2036:                 if ($valid_classes ne '') {
 2037:                     $autoenrolldates = &mt('Currently enabled').'<br />'.
 2038:                                        $valid_classes;
 2039:                 }
 2040:             }
 2041:         }
 2042:     }
 2043:     return $autoenrolldates;
 2044: }
 2045: 
 2046: sub user_is_known {
 2047:     my $known = 0;
 2048:     if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public' 
 2049:         && $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
 2050:         $known = 1;
 2051:     }
 2052:     return $known;
 2053: }
 2054: 
 2055: 1;

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