# The LearningOnline Network with CAPA # Handler for displaying the course catalog interface # # $Id: coursecatalog.pm,v 1.89 2016/04/04 01:09:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # package Apache::coursecatalog; use strict; use lib qw(/home/httpd/lib/perl); use Apache::Constants qw(:common); use Apache::loncommon; use Apache::lonhtmlcommon; use Apache::lonnet; use Apache::lonlocal; use Apache::courseclassifier; use Apache::lonacc; use LONCAPA; use LONCAPA::lonauthcgi; sub handler { my ($r) = @_; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; if ($r->header_only) { return OK; } my $handle = &Apache::lonnet::check_for_valid_session($r); my $lonidsdir=$r->dir_config('lonIDsDir'); if ($handle ne '') { &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); } &Apache::lonacc::get_posted_cgi($r); &Apache::lonlocal::get_language_handle($r); &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'}; if ($env{'request.role.domain'} ne '') { $codedom = $env{'request.role.domain'}; } } 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(); my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom); my $knownuser = &user_is_known(); my $canviewall = &canview_all(); my ($cathash,$cattype); if (ref($domconfig{'coursecategories'}) eq 'HASH') { $cathash = $domconfig{'coursecategories'}{'cats'}; if ($knownuser || $canviewall) { $cattype = $domconfig{'coursecategories'}{'auth'}; } else { $cattype = $domconfig{'coursecategories'}{'unauth'}; } if ($cattype eq '') { $cattype = 'std'; } } 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 || $canviewall) { $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'; } elsif ($cats[0][0] eq 'placement') { $catlinks .= &mt('Placement Tests'); $env{'form.currcat_0'} = 'placement::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 .= ' | '. ''; } 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.'); } elsif ($env{'form.currcat_0'} eq 'placement::0') { $output .= &mt('The courseID provided does not match a placement test in this domain.'); } else { $output .= &mt('The courseID provided does not match a course in this domain.'); } $output .= '
'; return $output; } } else { 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 = ''; if ($env{'form.currcat_0'} eq 'communities::0') { $output .= &mt('No communities match the criteria you selected.'); } elsif ($env{'form.currcat_0'} eq 'placement::0') { $output .= &mt('No placement tests match the criteria you selected.'); } else { $output .= &mt('No courses match the criteria you selected.'); } $output .= '
'; return $output; } if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain)) && (!$canviewall)) { $output = ''.&mt('Note for students:').' ' .&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.') .''.$lt{$item}.' | '. ' | '.$numbers{$item}.' | '. '
'.$lt{$status}.' | '. ' | '.$numbers{$status}.' | '. '
'.$lt{'cr_'.$status}.' | '. ' | '.$creditsum{$status}.' |