File:  [LON-CAPA] / loncom / interface / coursecatalog.pm
Revision 1.100: download - view: text, annotated - select for diffs
Sun Jul 21 14:26:02 2019 UTC (4 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Typo

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

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