--- loncom/interface/coursecatalog.pm 2007/03/08 01:58:44 1.20
+++ 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.20 2007/03/08 01:58:44 albertel Exp $
+# $Id: coursecatalog.pm,v 1.25 2008/01/12 22:32:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,14 +46,9 @@ 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);
@@ -133,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') {
@@ -436,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;
@@ -462,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';
}
@@ -474,6 +469,8 @@ sub construct_data_table {
$output .= '
';
if (defined($sortname{$item})) {
$output .= ''.&mt($item).'';
+ } elsif ($item eq 'Count') {
+ $output .= ' ';
} else {
$output .= &mt($item);
}
@@ -497,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;
@@ -508,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();
}
}
@@ -525,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;
@@ -576,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 = '';
@@ -639,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'};
@@ -660,7 +679,8 @@ sub courseinfo_row {
$code).'';
return $output;
}
- $output .= ' | '.$code.' | '.
+ $output .= ''.$$countref.' | '.
+ ''.$code.' | '.
''.$seclist.' | '.
''.$xlist_items.' | '.
''.$title.' ';
@@ -681,6 +701,7 @@ sub courseinfo_row {
$output .= " | ".&mt('Show more details').' | ';
}
}
+ $$countref ++;
return $output;
}
@@ -708,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'}} = ();
@@ -717,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);
@@ -728,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);
@@ -890,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);
@@ -906,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; }
@@ -916,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;