File:  [LON-CAPA] / loncom / interface / coursecatalog.pm
Revision 1.56: download - view: text, annotated - select for diffs
Fri Oct 23 16:14:43 2009 UTC (14 years, 8 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Consistent wording "Course Catalog" -> "Course/Community Catalog"

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

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