File:  [LON-CAPA] / loncom / interface / coursecatalog.pm
Revision 1.69: download - view: text, annotated - select for diffs
Mon Nov 21 15:42:59 2011 UTC (12 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: language_hyphenation_merge, language_hyphenation, HEAD, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
- Bug 6470. Wording change.

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

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