# The LearningOnline Network with CAPA
# Handler for displaying the course catalog interface
#
# $Id: coursecatalog.pm,v 1.44 2008/09/23 20:31:09 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;
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 '') {
if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
$codedom = $env{'form.showdom'};
}
}
my $domdesc = &Apache::lonnet::domain($codedom,'description');
&Apache::lonhtmlcommon::clear_breadcrumbs();
my %domconfig =
&Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash);
if (ref($domconfig{'coursecategories'}) eq 'HASH') {
$cathash = $domconfig{'coursecategories'}{'cats'};
} else {
$cathash = {};
}
my $subcats;
if ($env{'form.withsubcats'}) {
$subcats = \%subcathash;
}
&Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
\%idx,\@jsarray,$subcats);
if ($env{'form.coursenum'} ne '' && &user_is_known()) {
&course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
} else {
my ($catlinks,$has_subcats) = &category_breadcrumbs($codedom,@cats);
my $catjs = <<"ENDSCRIPT";
function setCatDepth(depth) {
document.coursecats.catalog_maxdepth.value = depth;
if (depth == '') {
document.coursecats.currcat_0.value = '';
}
document.coursecats.submit();
return;
}
function changeSort(caller) {
document.$formname.sortby.value = caller;
document.$formname.submit();
}
function setCourseId(caller) {
document.$formname.coursenum.value = caller;
document.$formname.submit();
}
ENDSCRIPT
$catjs .= &courselink_javascript();
my $numtitles;
if ($env{'form.currcat_0'} eq 'instcode::0') {
$numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
$catlinks,$catjs);
if ($env{'form.state'} eq 'listing') {
$r->print(&print_course_listing($codedom,$numtitles));
}
} else {
my (%add_entries);
$catjs = '';
&cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
if ($env{'form.currcat_0'} ne '') {
$r->print('
');
}
if ($env{'form.state'} eq 'listing') {
$r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
}
}
}
$r->print(' '.&Apache::loncommon::end_page());
return OK;
}
sub course_details {
my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
my $output;
my %add_entries = (topmargin => "0",
marginheight => "0",);
my $js = ''."\n";
my $start_page =
&Apache::loncommon::start_page('Course Catalog',$js,
{
'add_entries' => \%add_entries,
'no_inline_link' => 1,});
$r->print($start_page);
if ($env{'form.numtitles'} > 0) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/coursecatalog",
text=>"Select courses"});
}
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:document.$formname.submit()",
text=>"Course listing"},
{text=>"Course details"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
$r->print(' '.&mt('Detailed course information:').'
';
}
$$countref ++;
return $output;
}
sub identify_sections {
my ($seclist) = @_;
my @secnums;
if ($seclist =~ /,/) {
my @sections = split(/,/,$seclist);
foreach my $sec (@sections) {
$sec =~ s/:[^:]*$//;
push(@secnums,$sec);
}
} else {
if ($seclist =~ m/^([^:]+):/) {
my $sec = $1;
if (!grep(/^\Q$sec\E$/,@secnums)) {
push(@secnums,$sec);
}
}
}
@secnums = sort {$a <=> $b} @secnums;
$seclist = join(', ',@secnums);
my $numsec = @secnums;
return ($seclist,$numsec);
}
sub get_valid_classes {
my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
my $response;
my %validations;
@{$validations{'sections'}} = ();
@{$validations{'xlists'}} = ();
my $totalitems = 0;
if ($seclist) {
foreach my $sec (split(/, /,$seclist)) {
my $class = $crscode.$sec;
if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
$class) eq 'ok') {
if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
push(@{$validations{'sections'}},$sec);
$totalitems ++;
}
}
}
}
if ($xlist_items) {
foreach my $item (split(/, /,$xlist_items)) {
if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
$item) eq 'ok') {
if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
push(@{$validations{'xlists'}},$item);
$totalitems ++;
}
}
}
}
if ($totalitems > 0) {
if (@{$validations{'sections'}}) {
$response = &mt('Sections:').' '.
join(', ',@{$validations{'sections'}}).' ';
}
if (@{$validations{'xlists'}}) {
$response .= &mt('Courses:').' '.
join(', ',@{$validations{'xlists'}});
}
}
return $response;
}
sub javascript_select_filler {
my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
my $output = < -1) {
document.$formname.Number.options[0] = new Option('All','0',false,false);
for (var k=0; k -1) {
for (var i=0; i -1) {
for (var i=0; i -1) {
for (var k=0; k{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
my ($autostart,$autoend);
if ( defined($coursehash->{'internal.autostart'}) ) {
$autostart = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autostart'});
}
if ( defined($coursehash->{'internal.autoend'}) ) {
$autoend = &Apache::lonlocal::locallocaltime($coursehash->{'internal.autoend'});
}
if ($coursehash->{'internal.autostart'} > $now) {
if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
$autoenrolldates = &mt('Not enabled');
} else {
my $valid_classes =
&get_valid_classes($seclist,$xlist_items,$code,
$owners,$cdom,$cnum);
if ($valid_classes ne '') {
$autoenrolldates = &mt('Not enabled').' '
.&mt('Starts: [_1]',$autostart)
.' '.$valid_classes;
}
}
} else {
if ($coursehash->{'internal.autoend'} && $coursehash->{'internal.autoend'} < $now) {
$autoenrolldates = &mt('Not enabled').' '
.&mt('Ended: [_1]',$autoend);
} else {
my $valid_classes = &get_valid_classes($seclist,$xlist_items,
$code,$owners,$cdom,$cnum);
if ($valid_classes ne '') {
$autoenrolldates = &mt('Currently enabled').' '.
$valid_classes;
}
}
}
}
return $autoenrolldates;
}
sub user_is_known {
my $known = 0;
if ($env{'user.name'} ne '' && $env{'user.name'} ne 'public'
&& $env{'user.domain'} ne '' && $env{'user.domain'} ne 'public') {
$known = 1;
}
return $known;
}
1;
500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator at
root@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.
More information about this error may be available
in the server error log.