--- loncom/interface/coursecatalog.pm 2008/06/30 04:07:06 1.33 +++ loncom/interface/coursecatalog.pm 2008/07/06 17:59:25 1.35 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler for displaying the course catalog interface # -# $Id: coursecatalog.pm,v 1.33 2008/06/30 04:07:06 raeburn Exp $ +# $Id: coursecatalog.pm,v 1.35 2008/07/06 17:59:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -71,10 +71,21 @@ sub handler { } 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,$cathash); + if (ref($domconfig{'coursecategories'}) eq 'HASH') { + $cathash = $domconfig{'coursecategories'}{'cats'}; + } else { + $cathash = {}; + } + &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems, + \%idx,\@jsarray); if ($env{'form.coursenum'} ne '' && &user_is_known()) { - &course_details($r,$codedom,$formname,$domdesc); + &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems); } else { - my $catlinks = &category_breadcrumbs($codedom); + my $catlinks = &category_breadcrumbs($codedom,@cats); my $catjs = <<"ENDSCRIPT"; function setCatDepth(depth) { @@ -125,7 +136,7 @@ function setCourseId(caller) { &mt('Display courses').'" />

'); } if ($env{'form.state'} eq 'listing') { - $r->print(&print_course_listing($codedom)); + $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems)); } } } @@ -134,7 +145,7 @@ function setCourseId(caller) { } sub course_details { - my ($r,$codedom,$formname,$domdesc) = @_; + my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_; my $output; my %add_entries = (topmargin => "0", marginheight => "0",); @@ -156,7 +167,8 @@ sub course_details { $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details')); $r->print('
'.&mt('Detailed course information:').'

'. '
'. - &print_course_listing($codedom).'

'); + &print_course_listing($codedom,undef,$trails,$allitems). + '

'); $r->print(''. &mt('Back to course listing').''. 'print(&Apache::lonhtmlcommon::breadcrumbs('Select courses')); } - $r->print(''. - ''. - '
'.&mt('Domain:').''. + $r->print(''. + ''. - ''. - $catlinks.'
'.&mt('Domain:').''. &Apache::loncommon::select_dom_form($codedom,'showdom','',1). - ' 
'); + ' 
'. + '
'. + ''.$catlinks.'
'); return; } sub category_breadcrumbs { - my ($dom) = @_; - my %domconfig = - &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom); - my (@cats,@trails,%allitems,%idx,@jsarray,$cathash); - if (ref($domconfig{'coursecategories'}) eq 'HASH') { - $cathash = $domconfig{'coursecategories'}{'cats'}; - } else { - $cathash = {}; - } - &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx, - \@jsarray); + my ($dom,@cats) = @_; my ($currdepth,$deeper) = &get_depth_values(); my $currcat_str = ''; my $catlinks = ''.&mt('Catalog:').''; @@ -383,7 +384,7 @@ sub category_breadcrumbs { if (ref($cats[0]) eq 'ARRAY') { if ((@{$cats[0]} == 1) && ($cats[0][0] eq 'instcode')) { $catlinks .= &mt('Official courses (with institutional codes)'). - ''; + ''; $env{'form.currcat_0'} = 'instcode::0'; } else { $catlinks .= ''; + ''; $env{'form.currcat_0'} = 'instcode::0'; } } else { @@ -650,7 +651,7 @@ sub search_courselist { } sub print_course_listing { - my ($domain,$numtitles) = @_; + my ($domain,$numtitles,$trails,$allitems) = @_; my $output; my %courses; my $knownuser = &user_is_known(); @@ -687,22 +688,30 @@ sub print_course_listing { my $now = time; my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); - $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig); + $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems); $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']); return $output; } sub construct_data_table { - my ($knownuser,$courses,$details,$usersections,$now,$domconfig) = @_; + my ($knownuser,$courses,$details,$usersections,$now,$domconfig,$trails, + $allitems) = @_; my %sortname; if (($details eq '') || ($env{'form.showdetails'})) { $sortname{'Code'} = 'code'; + $sortname{'Categories'} = 'cats'; $sortname{'Title'} = 'title'; $sortname{'Owner(s)'} = 'owner'; } my $output = &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(); - my @coltitles = ('Count','Code','Sections','Crosslisted','Title','Owner(s)'); + my @coltitles = ('Count'); + if ($env{'form.currcat_0'} eq 'instcode::0') { + push(@coltitles,'Code'); + } else { + push(@coltitles,'Categories'); + } + push(@coltitles,('Sections','Crosslisted','Title','Owner(s)')); if (ref($usersections) eq 'HASH') { $coltitles[1] = 'Your Section'; } @@ -735,6 +744,8 @@ sub construct_data_table { foreach my $course (sort(keys(%{$courses}))) { if ($env{'form.sortby'} eq 'code') { push(@{$Sortby{$courseinfo{$course}{'code'}}},$course); + } elsif ($env{'form.sortby'} eq 'cats') { + push(@{$Sortby{$courseinfo{$course}{'categories'}}},$course); } elsif ($env{'form.sortby'} eq 'owner') { push(@{$Sortby{$courseinfo{$course}{'ownerlastnames'}}},$course); } else { @@ -747,7 +758,8 @@ sub construct_data_table { } } my @sorted_courses; - if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner')) { + if (($env{'form.sortby'} eq 'code') || ($env{'form.sortby'} eq 'owner') || + ($env{'form.sortby'} eq 'cats')) { @sorted_courses = sort(keys(%Sortby)); } else { @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby)); @@ -756,8 +768,8 @@ sub construct_data_table { foreach my $item (@sorted_courses) { foreach my $course (@{$Sortby{$item}}) { $output.=&Apache::loncommon::start_data_table_row(); - $output.=&courseinfo_row($courseinfo{$course},$knownuser, - $details,\$count,$now,$course); + $output.=&courseinfo_row($courseinfo{$course},$knownuser,$details, + \$count,$now,$course,$trails,$allitems); $output.=&Apache::loncommon::end_data_table_row(); } } @@ -779,7 +791,7 @@ sub build_courseinfo_hash { $cleandesc =~ s/^\s+//; my ($cdom,$cnum)=split(/\_/,$course); my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types, - $selfenroll_start,$selfenroll_end,@owners,%ownernames); + $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories); if (ref($courses->{$course}) eq 'HASH') { $descr = $courses->{$course}{'description'}; $instcode = $courses->{$course}{'inst_code'}; @@ -788,6 +800,7 @@ sub build_courseinfo_hash { $selfenroll_types = $courses->{$course}{'selfenroll_types'}; $selfenroll_start = $courses->{$course}{'selfenroll_start_date'}; $selfenroll_end = $courses->{$course}{'selfenroll_end_date'}; + $categories = $courses->{$course}{'categories'}; push(@owners,$singleowner); if (ref($courses->{$course}{'co-owners'}) eq 'ARRAY') { foreach my $item (@{$courses->{$course}{'co-owners'}}) { @@ -825,6 +838,7 @@ sub build_courseinfo_hash { $courseinfo{$course}{'selfenroll_types'} = $selfenroll_types; $courseinfo{$course}{'selfenroll_start'} = $selfenroll_start; $courseinfo{$course}{'selfenroll_end'} = $selfenroll_end; + $courseinfo{$course}{'categories'} = $categories; my %coursehash = &Apache::lonnet::dump('environment',$cdom,$cnum); my @classids; @@ -860,7 +874,7 @@ sub build_courseinfo_hash { if ( defined($coursehash{'default_enrollment_end_date'}) ) { $endaccess = &Apache::lonlocal::locallocaltime($coursehash{'default_enrollment_end_date'}); if ($coursehash{'default_enrollment_end_date'} == 0) { - $endaccess = "No ending date"; + $endaccess = &mt('No ending date'); } } if ($startaccess) { @@ -869,6 +883,33 @@ sub build_courseinfo_hash { if ($endaccess) { $accessdates .= &mt('To: ').$endaccess.'
'; } + if (($selfenroll_types ne '') && + ($selfenroll_end > 0 && $selfenroll_end > $now)) { + my ($selfenroll_start_access,$selfenroll_end_access); + if (($coursehash{'default_enrollment_start_date'} ne + $coursehash{'internal.selfenroll_start_access'}) || + ($coursehash{'default_enrollment_end_date'} ne + $coursehash{'internal.selfenroll_end_access'})) { + if ( defined($coursehash{'internal.selfenroll_start_access'}) ) { + $selfenroll_start_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_start_access'}); + } + if ( defined($coursehash{'default_enrollment_end_date'}) ) { + $selfenroll_end_access = &Apache::lonlocal::locallocaltime($coursehash{'internal.selfenroll_end_access'}); + if ($coursehash{'internal.selfenroll_end_access'} == 0) { + $selfenroll_end_access = &mt('No ending date'); + } + } + if ($selfenroll_start_access || $selfenroll_end_access) { + $accessdates .= '

'.&mt('Self-enrollers:').'
'; + if ($selfenroll_start_access) { + $accessdates .= &mt('From: ').$selfenroll_start_access.'
'; + } + if ($selfenroll_end_access) { + $accessdates .= &mt('To: ').$selfenroll_end_access.'
'; + } + } + } + } $courseinfo{$course}{'access'} = $accessdates; } if ($xlist_items eq '') { @@ -908,9 +949,9 @@ sub count_students { } sub courseinfo_row { - my ($info,$knownuser,$details,$countref,$now,$course) = @_; + my ($info,$knownuser,$details,$countref,$now,$course,$trails,$allitems) = @_; my ($cdom,$cnum,$title,$ownerlast,$code,$owner,$seclist,$xlist_items, - $accessdates,$showsyllabus,$counts,$autoenrollment,$output); + $accessdates,$showsyllabus,$counts,$autoenrollment,$output,$categories); if (ref($info) eq 'HASH') { $cdom = $info->{'cdom'}; $cnum = $info->{'cnum'}; @@ -924,14 +965,30 @@ sub courseinfo_row { $counts = $info->{'counts'}; $autoenrollment = $info->{'autoenrollment'}; $showsyllabus = $info->{'showsyllabus'}; + $categories = $info->{'categories'}; } else { $output = ''; return $output; } - $output .= ''. - ''. - ''. + $output .= ''; + if ($env{'form.currcat_0'} eq 'instcode::0') { + $output .= ''; + } else { + my ($categorylist,@cats); + if ($categories ne '') { + @cats = split('&',$categories); + } + if ((ref($trails) eq 'ARRAY') && (ref($allitems) eq 'HASH')) { + my @categories = map { $trails->[$allitems->{$_}]; } @cats; + $categorylist = join('
',@categories); + } + if ($categorylist eq '') { + $categorylist = ' '; + } + $output .= ''; + } + $output .= ''. ''. '
'.&mt('No information available for [_1].', $code).''.$$countref.''.$code.''.$seclist.''.$$countref.''.$code.''.$categorylist.''.$seclist.''.$xlist_items.''.$title.' '; if ($showsyllabus) {