');
for (my $k=0; $k<$lasttitle-1; $k++) {
my @unsorted = @{$cat_items{$codetitles[$k]}};
@@ -252,15 +271,24 @@ function setCourseId(caller) {
$r->print('
'.$codetitles[$numtitles-1].'
'."\n".
'
'."\n");
}
+ $r->print('
');
+ }
+ $r->print('');
+ if ($numtitles > 0) {
+ $r->print('');
+ }
+ $r->print('');
+ if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
+ $r->print('
');
}
- $r->print('
');
} else {
$r->print(&Apache::loncommon::start_page('Course Catalog','',
{
'no_inline_link' => 1,}));
$r->print('
'.&mt('No official courses to display for [_1].',$domdesc));
}
- return;
+ return $numtitles;
}
sub user_is_dc {
@@ -360,23 +388,28 @@ sub build_javascript {
}
sub search_courselist {
- my ($domain) = @_;
- my ($instcode,%codedefaults,@code_order);
- my $defaults_result =
- &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
- \@code_order);
- if ($defaults_result eq 'ok') {
- $instcode ='^';
- foreach my $item (@code_order) {
- if ($env{'form.'.$item} eq '0' ) {
- $instcode .= $codedefaults{$item};
- } else {
- $instcode .= $env{'form.'.$item};
+ my ($domain,$numtitles) = @_;
+ my $instcode;
+ if (defined($numtitles) && $numtitles == 0) {
+ $instcode = '.+';
+ } else {
+ my (%codedefaults,@code_order);
+ my $defaults_result =
+ &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
+ \@code_order);
+ if ($defaults_result eq 'ok') {
+ $instcode ='^';
+ foreach my $item (@code_order) {
+ if ($env{'form.'.$item} eq '0' ) {
+ $instcode .= $codedefaults{$item};
+ } else {
+ $instcode .= $env{'form.'.$item};
+ }
}
+ $instcode .= '$';
+ } else {
+ $instcode = '.';
}
- $instcode .= '$';
- } else {
- $instcode = '.';
}
my %courses = &Apache::lonnet::courseiddump($domain,'.',1,$instcode,'.','.',
undef,undef,'Course',1);
@@ -385,7 +418,7 @@ sub search_courselist {
sub print_course_listing {
- my ($domain) = @_;
+ my ($domain,$numtitles) = @_;
my $output;
my %courses;
my $knownuser = &user_is_known();
@@ -398,13 +431,13 @@ 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;
}
} else {
- %courses = &search_courselist($domain);
+ %courses = &search_courselist($domain,$numtitles);
if (keys(%courses) == 0) {
$output = &mt('No courses match the criteria you selected.');
return $output;
@@ -424,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';
}
@@ -436,6 +469,8 @@ sub construct_data_table {
$output .= '';
if (defined($sortname{$item})) {
$output .= ''.&mt($item).'';
+ } elsif ($item eq 'Count') {
+ $output .= ' ';
} else {
$output .= &mt($item);
}
@@ -459,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;
@@ -470,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();
}
}
@@ -487,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;
@@ -538,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 = '';
@@ -601,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'};
@@ -622,7 +679,8 @@ sub courseinfo_row {
$code).'';
return $output;
}
- $output .= ' | '.$code.' | '.
+ $output .= ''.$$countref.' | '.
+ ''.$code.' | '.
''.$seclist.' | '.
''.$xlist_items.' | '.
''.$title.' ';
@@ -643,6 +701,7 @@ sub courseinfo_row {
$output .= " | ".&mt('Show more details').' | ';
}
}
+ $$countref ++;
return $output;
}
@@ -670,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'}} = ();
@@ -679,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);
@@ -690,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);
@@ -852,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);
@@ -868,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; }
@@ -878,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;