--- loncom/interface/coursecatalog.pm 2007/01/12 23:37:22 1.18
+++ loncom/interface/coursecatalog.pm 2008/01/12 22:32:04 1.25
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler for displaying the course catalog interface
#
-# $Id: coursecatalog.pm,v 1.18 2007/01/12 23:37:22 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.25 2008/01/12 22:32:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,22 +46,24 @@ sub handler {
if ($r->header_only) {
return OK;
}
- my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
- my $lonid=$cookies{'lonID'};
+ my $handle = &Apache::lonnet::check_for_valid_session($r);
my $lonidsdir=$r->dir_config('lonIDsDir');
- my $handle;
- if ($lonid) {
- $handle=&LONCAPA::clean_handle($lonid->value);
- }
- if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
+ 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']);
- my $codedom = $Apache::lonnet::perlvar{'lonDefDomain'};
+ 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';
- my $domdesc = $Apache::lonnet::domaindescription{$codedom};
+ my $domdesc = &Apache::lonnet::domain($codedom,'description');
&Apache::lonhtmlcommon::clear_breadcrumbs();
if ($env{'form.coursenum'} ne '' && &user_is_known()) {
@@ -87,10 +89,13 @@ sub course_details {
'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=>"/adm/coursecatalog",
- text=>"Select courses"},
- {href=>"javascript:document.$formname.submit()",
+ ({href=>"javascript:document.$formname.submit()",
text=>"Course listing"},
{text=>"Course details"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details'));
@@ -123,7 +128,7 @@ sub course_selector {
my $totcodes = 0;
my $jscript = '';
my ($numtitles,$lasttitle);
- $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
+ $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
if ($totcodes > 0) {
$format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
if ($format_reply eq 'ok') {
@@ -204,11 +209,16 @@ function setCourseId(caller) {
'no_inline_link' => 1,});
$r->print($start_page);
if ($env{'form.state'} eq 'listing') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/coursecatalog",
- text=>"Select courses"},
- {text=>"Course listing"});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
+ if ($numtitles > 0) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/coursecatalog",
+ text=>"Select courses"},
+ {text=>"Course listing"});
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({text=>"Course listing"});
+ }
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Listing'));
} else {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/coursecatalog",
@@ -267,7 +277,8 @@ function setCourseId(caller) {
if ($numtitles > 0) {
$r->print('');
}
- $r->print('');
+ $r->print('');
if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
$r->print('
');
}
@@ -420,7 +431,7 @@ sub print_course_listing {
if ($env{'form.coursenum'} ne '') {
%courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
$env{'form.coursenum'},
- undef,undef,'Course');
+ undef,undef,'Course',1);
if (keys(%courses) == 0) {
$output .= &mt('The courseID provided does not match a course in this domain.');
return $output;
@@ -446,11 +457,11 @@ sub construct_data_table {
if (($details eq '') || ($env{'form.showdetails'})) {
$sortname{'Code'} = 'code';
$sortname{'Title'} = 'title';
- $sortname{'Owner'} = 'owner';
+ $sortname{'Owner(s)'} = 'owner';
}
my $output = &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
- my @coltitles = ('Code','Sections','Crosslisted','Title','Owner');
+ my @coltitles = ('Count','Code','Sections','Crosslisted','Title','Owner(s)');
if (ref($usersections) eq 'HASH') {
$coltitles[1] = 'Your Section';
}
@@ -458,6 +469,8 @@ sub construct_data_table {
$output .= '
';
if (defined($sortname{$item})) {
$output .= ''.&mt($item).'';
+ } elsif ($item eq 'Count') {
+ $output .= ' ';
} else {
$output .= &mt($item);
}
@@ -481,9 +494,14 @@ sub construct_data_table {
if ($env{'form.sortby'} eq 'code') {
push(@{$Sortby{$courseinfo{$course}{'code'}}},$course);
} elsif ($env{'form.sortby'} eq 'owner') {
- push(@{$Sortby{$courseinfo{$course}{'ownerlastname'}}},$course);
+ push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course);
} else {
- push(@{$Sortby{$courseinfo{$course}{'title'}}},$course);
+ my $clean_title = $courseinfo{$course}{'title'};
+ $clean_title =~ s/\W+//g;
+ if ($clean_title eq '') {
+ $clean_title = $courseinfo{$course}{'title'};
+ }
+ push(@{$Sortby{$clean_title}},$course);
}
}
my @sorted_courses;
@@ -492,10 +510,11 @@ sub construct_data_table {
} else {
@sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
}
+ my $count = 1;
foreach my $item (@sorted_courses) {
foreach my $course (@{$Sortby{$item}}) {
$output.=&Apache::loncommon::start_data_table_row();
- $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details);
+ $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details,\$count);
$output.=&Apache::loncommon::end_data_table_row();
}
}
@@ -509,37 +528,53 @@ sub build_courseinfo_hash {
my $now = time;
foreach my $course (keys(%{$courses})) {
my $descr;
- if ($courses->{$course} =~ m/^([^:]*):/i) {
- $descr = &unescape($1);
- } else {
- $descr = &unescape($courses->{$course});
+ if (ref($courses->{$course}) eq 'HASH') {
+ $descr = $courses->{$course}{'description'};
}
my $cleandesc=&HTML::Entities::encode($descr,'<>&"');
$cleandesc=~s/'/\\'/g;
$cleandesc =~ s/^\s+//;
my ($cdom,$cnum)=split(/\_/,$course);
-
- my ($desc,$instcode,$owner,$ttype) = split(/:/,$courses->{$course});
- $owner = &unescape($owner);
- my ($ownername,$ownerdom);
- if ($owner =~ /:/) {
- ($ownername,$ownerdom) = split(/:/,$owner);
- } else {
- $ownername = $owner;
- if ($owner ne '') {
- $ownerdom = $cdom;
+ my ($descr,$instcode,$singleowner,$ttype,@owners,%ownernames);
+ if (ref($courses->{$course}) eq 'HASH') {
+ $descr = $courses->{$course}{'description'};
+ $instcode = $courses->{$course}{'inst_code'};
+ $singleowner = $courses->{$course}{'owner'};
+ $ttype = $courses->{$course}{'type'};
+ push(@owners,$singleowner);
+ if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') {
+ foreach my $item (@{$courses->{$course}{'co-owners'}}) {
+ push(@owners,$item);
+ }
}
}
- my %ownernames;
- if ($ownername ne '' && $ownerdom ne '') {
- %ownernames = &Apache::loncommon::getnames($ownername,$ownerdom);
+ foreach my $owner (@owners) {
+ my ($ownername,$ownerdom) = @_;
+ if ($owner =~ /:/) {
+ ($ownername,$ownerdom) = split(/:/,$owner);
+ } else {
+ $ownername = $owner;
+ if ($owner ne '') {
+ $ownerdom = $cdom;
+ }
+ }
+ if ($ownername ne '' && $ownerdom ne '') {
+ my %namehash=&Apache::loncommon::getnames($ownername,$ownerdom);
+ $ownernames{$ownername.':'.$ownerdom} = \%namehash;
+ }
}
$courseinfo{$course}{'cdom'} = $cdom;
$courseinfo{$course}{'cnum'} = $cnum;
$courseinfo{$course}{'code'} = $instcode;
- $courseinfo{$course}{'ownerlastname'} = $ownernames{'lastname'};
+ my @lastnames;
+ foreach my $owner (keys(%ownernames)) {
+ if (ref($ownernames{$owner}) eq 'HASH') {
+ push(@lastnames,$ownernames{$owner}{'lastname'});
+ }
+ }
+ $courseinfo{$course}{'ownerlastnames'} = join(', ',sort(@lastnames));
$courseinfo{$course}{'title'} = $cleandesc;
- $courseinfo{$course}{'owner'} = $owner;
+ $courseinfo{$course}{'owner'} = $singleowner;
my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum);
my @classids;
@@ -560,11 +595,11 @@ sub build_courseinfo_hash {
}
$courseinfo{$course}{'showsyllabus'} = $showsyllabus;
if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) ||
- ($knownuser && ($details == 1))) {
+ ($knownuser && ($details == 1))) {
$courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,$numsec);
$courseinfo{$course}{'autoenrollment'} =
&autoenroll_info(\%coursehash,$now,$seclist,$xlist_items,
- $instcode,$owner,$cdom,$cnum);
+ $instcode,\@owners,$cdom,$cnum);
my $startaccess = '';
my $endaccess = '';
@@ -623,14 +658,14 @@ sub count_students {
}
sub courseinfo_row {
- my ($info,$knownuser,$details) = @_;
+ my ($info,$knownuser,$details,$countref) = @_;
my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items,
$accessdates,$showsyllabus,$counts,$autoenrollment,$output);
if (ref($info) eq 'HASH') {
$cdom = $info->{'cdom'};
$cnum = $info->{'cnum'};
$title = $info->{'title'};
- $ownerlast = $info->{'ownerlastname'};
+ $ownerlast = $info->{'ownerlastnames'};
$code = $info->{'code'};
$owner = $info->{'owner'};
$seclist = $info->{'seclist'};
@@ -644,7 +679,8 @@ sub courseinfo_row {
$code).'';
return $output;
}
- $output .= ' | '.$code.' | '.
+ $output .= ''.$$countref.' | '.
+ ''.$code.' | '.
''.$seclist.' | '.
''.$xlist_items.' | '.
''.$title.' ';
@@ -665,6 +701,7 @@ sub courseinfo_row {
$output .= " | ".&mt('Show more details').' | ';
}
}
+ $$countref ++;
return $output;
}
@@ -692,7 +729,7 @@ sub identify_sections {
}
sub get_valid_classes {
- my ($seclist,$xlist_items,$crscode,$owner,$cdom,$cnum) = @_;
+ my ($seclist,$xlist_items,$crscode,$owners,$cdom,$cnum) = @_;
my $response;
my %validations;
@{$validations{'sections'}} = ();
@@ -701,7 +738,7 @@ sub get_valid_classes {
if ($seclist) {
foreach my $sec (split(/, /,$seclist)) {
my $class = $crscode.$sec;
- if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
+ if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
$class) eq 'ok') {
if (!grep(/^\Q$sec$\E/,@{$validations{'sections'}})) {
push(@{$validations{'sections'}},$sec);
@@ -712,7 +749,7 @@ sub get_valid_classes {
}
if ($xlist_items) {
foreach my $item (split(/, /,$xlist_items)) {
- if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owner,
+ if (&Apache::lonnet::auto_validate_class_sec($cdom,$cnum,$owners,
$item) eq 'ok') {
if (!grep(/^\Q$item$\E/,@{$validations{'xlists'}})) {
push(@{$validations{'xlists'}},$item);
@@ -874,7 +911,7 @@ END
}
sub autoenroll_info {
- my ($coursehash,$now,$seclist,$xlist_items,$code,$owner,$cdom,$cnum) = @_;
+ my ($coursehash,$now,$seclist,$xlist_items,$code,$owners,$cdom,$cnum) = @_;
my $autoenrolldates = &mt('Not enabled');
if (defined($coursehash->{'internal.autoadds'}) && $coursehash->{'internal.autoadds'} == 1) {
my ($autostart,$autoend);
@@ -890,7 +927,7 @@ sub autoenroll_info {
} else {
my $valid_classes =
&get_valid_classes($seclist,$xlist_items,$code,
- $owner,$cdom,$cnum);
+ $owners,$cdom,$cnum);
if ($valid_classes ne '') {
$autoenrolldates = &mt('Not enabled
Starts: ').
$autostart.'
'.$valid_classes; }
@@ -900,7 +937,7 @@ sub autoenroll_info {
$autoenrolldates = &mt('Not enabled
Ended: ').$autoend;
} else {
my $valid_classes = &get_valid_classes($seclist,$xlist_items,
- $code,$owner,$cdom,$cnum);
+ $code,$owners,$cdom,$cnum);
if ($valid_classes ne '') {
$autoenrolldates = &mt('Currently enabled
').
$valid_classes;