--- loncom/interface/coursecatalog.pm 2007/01/12 23:37:22 1.18
+++ loncom/interface/coursecatalog.pm 2008/02/15 02:30:14 1.26
@@ -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.26 2008/02/15 02:30:14 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",
@@ -221,8 +231,10 @@ function setCourseId(caller) {
$r->print(&mt('Choose which course(s) to list.
'));
$r->print('
'; if (defined($sortname{$item})) { $output .= ''.&mt($item).''; + } elsif ($item eq 'Count') { + $output .= ' '; } else { $output .= &mt($item); } @@ -481,9 +496,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 +512,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 +530,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 +597,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 +660,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 +681,8 @@ sub courseinfo_row { $code).''; return $output; } - $output .= ' | '.$code.' | '. + $output .= ''.$$countref.' | '. + ''.$code.' | '. ''.$seclist.' | '. ''.$xlist_items.' | '. ''.$title.' '; @@ -665,6 +703,7 @@ sub courseinfo_row { $output .= " | ".&mt('Show more details').' | '; } } + $$countref ++; return $output; } @@ -692,7 +731,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 +740,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 +751,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 +913,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 +929,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
---|