File:  [LON-CAPA] / loncom / interface / coursecatalog.pm
Revision 1.54: download - view: text, annotated - select for diffs
Thu Oct 1 17:24:23 2009 UTC (14 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- @_ not relevant here.

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

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