--- loncom/interface/coursecatalog.pm 2007/10/03 19:57:29 1.22 +++ loncom/interface/coursecatalog.pm 2014/04/28 22:12:55 1.84 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler for displaying the course catalog interface # -# $Id: coursecatalog.pm,v 1.22 2007/10/03 19:57:29 raeburn Exp $ +# $Id: coursecatalog.pm,v 1.84 2014/04/28 22:12:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,8 +53,10 @@ sub handler { } &Apache::lonacc::get_posted_cgi($r); &Apache::lonlocal::get_language_handle($r); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']); - my $codedom = &Apache::lonnet::default_login_domain(); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['sortby','showdom']); + + my $codedom = &Apache::lonnet::default_login_domain(); if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) { $codedom = $env{'user.domain'}; @@ -63,232 +65,791 @@ sub handler { } } my $formname = 'coursecatalog'; + if ($env{'form.showdom'} ne '') { + $env{'form.showdom'} = &LONCAPA::clean_domain($env{'form.showdom'}); + if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') { + $codedom = $env{'form.showdom'}; + } else { + $env{'form.showdom'} = ''; + } + } my $domdesc = &Apache::lonnet::domain($codedom,'description'); - &Apache::lonhtmlcommon::clear_breadcrumbs(); - if ($env{'form.coursenum'} ne '' && &user_is_known()) { - &course_details($r,$codedom,$formname,$domdesc); + + my %domconfig = + &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom); + my $knownuser = &user_is_known(); + + my ($cathash,$cattype); + if (ref($domconfig{'coursecategories'}) eq 'HASH') { + $cathash = $domconfig{'coursecategories'}{'cats'}; + if ($knownuser) { + $cattype = $domconfig{'coursecategories'}{'auth'}; + } else { + $cattype = $domconfig{'coursecategories'}{'unauth'}; + } + } else { + $cathash = {}; + $cattype = 'std'; + } + if ($cattype eq 'none') { + $r->print(&Apache::loncommon::start_page('Course/Community Catalog')); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/coursecatalog", + text=>"Course/Community Catalog"}); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog')); + if ($knownuser) { + $r->print('
'; + my $has_subcats; + my $selitem; + if (ref($cats[0]) eq 'ARRAY') { + if (@{$cats[0]} == 0) { + $catlinks .= &mt('No categories defined in this domain'); + } elsif (@{$cats[0]} == 1) { + if ($cats[0][0] eq 'instcode') { + $catlinks .= &mt('Official courses (with institutional codes)'); + $env{'form.currcat_0'} = 'instcode::0'; + } elsif ($cats[0][0] eq 'communities') { + $catlinks .= &mt('Communities'); + $env{'form.currcat_0'} = 'communities::0'; + } else { + my $name = $cats[0][0]; + my $item = &escape($name).'::0'; + $catlinks .= $name; + $env{'form.currcat_0'} = $item; + } + $currcat_str .= ''; + } else { + $catlinks .= &main_category_selector(@cats); + if (($env{'form.currcat_0'} ne '') && + ($env{'form.currcat_0'} ne 'instcode::0')) { + $catlinks .= $crumbsymbol; + } + } + } else { + $catlinks .= &mt('Official courses (with institutional codes)'); + $env{'form.currcat_0'} = 'instcode::0'; + $currcat_str .= ''; + } + if ($deeper) { + for (my $i=1; $i<=$deeper; $i++) { + my $shallower = $i-1; + next if ($shallower == 0); + my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower}); + if ($cat ne '') { + $catlinks .= ' | '. + ''; } - if ($env{'form.state'} eq 'listing') { - $jscript .= qq| -function changeSort(caller) { - document.$formname.sortby.value = caller; - document.$formname.submit(); + unless ($i == $deeper) { + $catlinks .= $crumbsymbol; + } + } + my ($cat,$container,$depth); + if ($env{'form.currcat_'.$currdepth} eq '') { + my $shallower = $currdepth - 1; + ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower}); + } else { + ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth}); + } + my $deeperlevel = $depth +1; + if (ref($cats[$deeperlevel]{$cat}) eq 'ARRAY') { + $has_subcats = 1; + my $buttontext = &mt('Show subcategories'); + my $selitem = 'currcat_'.$deeperlevel; + $catlinks .= ' '."\n"; + } elsif ($cat ne 'instcode') { + $catlinks .= ' '.&mt('(No subcategories)'); + } + } else { + $selitem = 'currcat_0'; + } + $catlinks .= $currcat_str.' |
'; + if ($env{'form.currcat_0'} eq 'communities::0') { + $output .= &mt('The courseID provided does not match a community in this domain.'); + } else { + $output .= &mt('The courseID provided does not match a course in this domain.'); + } + $output .= '
'; return $output; } } else { - %courses = &search_courselist($domain,$numtitles); + if ($env{'form.currcat_0'} eq 'instcode::0') { + %courses = &search_official_courselist($domain,$numtitles,$codetitles); + } else { + %courses = &search_courselist($domain,$subcats); + } if (keys(%courses) == 0) { - $output = &mt('No courses match the criteria you selected.'); + $output = ''; + if ($env{'form.currcat_0'} eq 'communities::0') { + $output .= &mt('No communities match the criteria you selected.'); + } else { + $output .= &mt('No courses match the criteria you selected.'); + } + $output .= '
'; return $output; } - if ($knownuser && !$env{'form.showdetails'}) { - $output = &mt('Note for students: 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.'.$lt{$item}.' | '. + ' | '.$numbers{$item}.' | '. + '
'.$lt{$status}.' | '. + ' | '.$numbers{$status}.' | '. + '
'.$lt{'cr_'.$status}.' | '. + ' | '.$creditsum{$status}.' |