--- loncom/interface/coursecatalog.pm 2013/01/23 15:23:19 1.72 +++ loncom/interface/coursecatalog.pm 2014/01/15 18:49:19 1.78 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler for displaying the course catalog interface # -# $Id: coursecatalog.pm,v 1.72 2013/01/23 15:23:19 raeburn Exp $ +# $Id: coursecatalog.pm,v 1.78 2014/01/15 18:49:19 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -66,13 +66,20 @@ sub handler { } my $formname = 'coursecatalog'; if ($env{'form.showdom'} ne '') { + $env{'form.showdom'} = &LONCAPA::clean_domain($env{'form.showdom'}); if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') { $codedom = $env{'form.showdom'}; + } else { + $env{'form.showdom'} = ''; } } my $domdesc = &Apache::lonnet::domain($codedom,'description'); &Apache::lonhtmlcommon::clear_breadcrumbs(); + if ($env{'form.catalog_maxdepth'} ne '') { + $env{'form.catalog_maxdepth'} =~ s{\D}{}g; + } + my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom); my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash); @@ -229,26 +236,25 @@ sub course_details { ({href=>"javascript:document.$formname.submit()", text=>$brtextone}, {text=>$brtexttwo}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog')); - $r->print('
'); - if ($env{'form.currcat_0'} eq 'communities::0') { - $r->print(&mt('Detailed community information:')); - } else { - $r->print(&mt('Detailed course information:')); - } - $r->print('

'. - &print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles). - '

'); - $r->print('
'. - ''); - if ($env{'form.currcat_0'} eq 'communities::0') { - $r->print(&mt('Back to community listing')); - } else { - $r->print(&mt('Back to course listing')); - } - $r->print(''. - &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter', - 'showdetails','courseid']).'
'); + $r->print( + &Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'). + '

'. + (($env{'form.currcat_0'} eq 'communities::0') ? + &mt('Detailed community information:') : + &mt('Detailed course information:')). + '

'. + &print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles). + '
'. + '
'. + &Apache::lonhtmlcommon::actionbox([ + ''. + (($env{'form.currcat_0'} eq 'communities::0') ? + &mt('Back to community listing') : &mt('Back to course listing')). + '' + ]). + &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter', + 'showdetails','courseid']). + '
'); return; } @@ -405,8 +411,6 @@ sub category_breadcrumbs { if (($env{'form.currcat_0'} ne '') && ($env{'form.currcat_0'} ne 'instcode::0')) { $catlinks .= $crumbsymbol; - } else { - $catlinks .= ''; } } } else { @@ -633,12 +637,12 @@ sub additional_filters { ' />'.$title.''; if ($type eq 'Previous') { my %milestonetext = &Apache::lonlocal::texthash ( - accessend => 'prior to default end access date', - enrollend => 'prior to end date for auto-enrollment', - date => 'prior to specific date:', + accessend => 'immediately prior to default end access date', + enrollend => 'immediately prior to end date for auto-enrollment', + date => 'immediately prior to specific date:', ); my @statuses = &Apache::loncommon::get_env_multiple('form.showcounts'); - $output .= ''; + $output .= ''; if ($checked) { $output .= &get_wasactive_text(); } @@ -736,11 +740,10 @@ sub get_statustitles { sub get_wasactive_text { my $wasacctext = ' -- '; if ($env{'form.currcat_0'} eq 'communities::0') { - $wasacctext .= &mt('where members had access ...'); + $wasacctext .= &mt('where member access status was current ...'); } else { - $wasacctext .= &mt('where students had access ...'); + $wasacctext .= &mt('where student access status was current ...'); } - $wasacctext .= '
'; return $wasacctext; } @@ -818,11 +821,13 @@ sub print_course_listing { $env{'form.coursenum'}, undef,undef,'.',1); if (keys(%courses) == 0) { + $output = '

'; if ($env{'form.currcat_0'} eq 'communities::0') { $output .= &mt('The courseID provided does not match a community in this domain.'); } else { $output .= &mt('The courseID provided does not match a course in this domain.'); } + $output .= '

'; return $output; } } else { @@ -832,17 +837,13 @@ sub print_course_listing { %courses = &search_courselist($domain,$subcats); } if (keys(%courses) == 0) { + $output = '

'; if ($env{'form.currcat_0'} eq 'communities::0') { - $output = - '

' - .&mt('No communities match the criteria you selected.') - .'

'; + $output .= &mt('No communities match the criteria you selected.'); } else { - $output = - '

' - .&mt('No courses match the criteria you selected.') - .'

'; + $output .= &mt('No courses match the criteria you selected.'); } + $output .= '

'; return $output; } if (($knownuser) && (!$env{'form.showdetails'}) && (!&user_is_dc($domain))) { @@ -946,10 +947,21 @@ sub construct_data_table { } $output .= ''.&mt('Self-enroll (if permitted)').''; &Apache::loncommon::end_data_table_header_row(); - my %numbers; + my (%numbers,%creditsum); + my ($showcredits,$defofficial,$defunofficial,$deftextbook); + my %domdefaults = &Apache::lonnet::get_domain_defaults($domain); + unless ($env{'form.currcat_0'} eq 'communities::0') { + if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) { + $showcredits = 1; + $defofficial = $domdefaults{'officialcredits'}; + $defunofficial = $domdefaults{'unofficialcredits'}; + $deftextbook = $domdefaults{'textbookcredits'}; + } + } my %courseinfo = &build_courseinfo_hash($courses,$knownuser,$domain,$details, $usersections,\@fields,\%fieldtitles, - $wasactiveon,\%numbers); + $wasactiveon,\%numbers,\%creditsum, + $showcredits,$defofficial,$defunofficial,$deftextbook); my %Sortby; foreach my $course (sort(keys(%{$courses}))) { if ($env{'form.sortby'} eq 'code') { @@ -992,33 +1004,51 @@ sub construct_data_table { 'Previous' => 'Total previous students', 'courses' => 'Total unique codes and courses without codes', 'sections' => 'Total sections', - 'xlists' => 'Total cross-listings', + 'xlists' => 'Total cross-listings', ); + if ($showcredits) { + $lt{'cr_Active'} = &mt('Total current student credit hours'); + $lt{'cr_Future'} = &mt('Total future student credit hours'); + $lt{'cr_Previous'} = &mt('Total previous student credit hours'); + } if ($env{'form.currcat_0'} eq 'communities::0') { $lt{'courses'} = &mt('Total communities'); $lt{'Active'} = &mt('Total current members'); $lt{'Future'} = &mt('Total future members'); $lt{'Previous'} = &mt('Total previous members'); - } + } + my $colspan = 8; + if ($showcredits) { + $colspan = 4; + } $output .= ''. ' '. - ''. + ''. ''; foreach my $item ('courses','sections','xlists') { $output .= ''. - ''. + ''. ''. ''."\n"; } if (@fields > 0) { foreach my $status (@fields) { $output .= ''. - ''. + ''. ''. ''."\n"; } } - $output .= '
'.$lt{$item}.''.$lt{$item}.' '.$numbers{$item}.'
'.$lt{$status}.''.$lt{$status}.' '.$numbers{$status}.'
'; + $output .= ''; + if ($showcredits) { + $output .= ''; + foreach my $status (@fields) { + $output .= ''. + ''. + ''; + } + $output .= '
'.$lt{'cr_'.$status}.' '.$creditsum{$status}.'
'; + } } } $output .= &Apache::loncommon::end_data_table(); @@ -1027,14 +1057,14 @@ sub construct_data_table { sub build_courseinfo_hash { my ($courses,$knownuser,$domain,$details,$usersections,$fields,$fieldtitles, - $wasactiveon,$numbers) = @_; + $wasactiveon,$numbers,$creditsum,$showcredits,$defofficial,$defunofficial) = @_; my %courseinfo; my $now = time; my $gettotals; if ((keys(%{$courses}) > 0) && (&user_is_dc($domain)) && ($details)) { $gettotals = 1; } - my (%uniquecodes,$nocodes),; + my (%uniquecodes,$nocodes,$defcreds); foreach my $course (keys(%{$courses})) { my $descr; if (ref($courses->{$course}) eq 'HASH') { @@ -1116,6 +1146,16 @@ sub build_courseinfo_hash { $showsyllabus = $coursehash{'showsyllabus'}; } $courseinfo{$course}{'showsyllabus'} = $showsyllabus; + if ($showcredits) { + if ($coursehash{'internal.defaultcredits'}) { + $courseinfo{$course}{'defaultcredits'} = $coursehash{'internal.defaultcredits'}; + } elsif ($instcode ne '') { + $courseinfo{$course}{'defaultcredits'} = $defofficial; + } else { + $courseinfo{$course}{'defaultcredits'} = $defunofficial; + } + $defcreds = $courseinfo{$course}{'defaultcredits'}; + } if (((defined($env{'form.coursenum'}) && ($cnum eq $env{'form.coursenum'}))) || ($knownuser && ($details == 1))) { my $milestone; @@ -1136,7 +1176,7 @@ sub build_courseinfo_hash { } $courseinfo{$course}{'counts'} = &count_students($cdom,$cnum,$numsec,$fields,$fieldtitles,$gettotals, - $numbers,$milestone); + $numbers,$creditsum,$showcredits,$defcreds,$milestone); if ($instcode ne '') { $courseinfo{$course}{'autoenrollment'} = &autoenroll_info(\%coursehash,$now,$seclist,$xlist_items, @@ -1201,7 +1241,8 @@ sub build_courseinfo_hash { } sub count_students { - my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$wasactiveon) = @_; + my ($cdom,$cnum,$numsec,$fieldsref,$titlesref,$getcounts,$numbers,$creditsum, + $showcredits,$defcreds,$wasactiveon) = @_; my $countslist = ''. &mt('[quant,_1,section,sections,No sections]',$numsec).''; my (@fields,%titles,$showexpired); @@ -1216,23 +1257,42 @@ sub count_students { return; } my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum); - my %student_count = ( + my (%student_count,%credit_count); + %student_count = ( Active => 0, Future => 0, Previous => 0, - ); + ); + if ($showcredits) { + %credit_count = ( + Active => 0, + Future => 0, + Previous => 0, + ); + } my %idx; $idx{'status'} = &Apache::loncoursedata::CL_STATUS(); $idx{'end'} = &Apache::loncoursedata::CL_END(); + $idx{'credits'} = &Apache::loncoursedata::CL_CREDITS(); while (my ($student,$data) = each(%$classlist)) { my $status = $data->[$idx{'status'}]; + my $credits = $data->[$idx{'credits'}]; + if ($credits eq '') { + $credits = $defcreds; + } if ($status eq 'Expired') { if (($showexpired) && ($data->[$idx{'end'}] >= $wasactiveon)) { $student_count{'Previous'} ++; + if ($showcredits) { + $credit_count{'Previous'} += $credits; + } } } else { $student_count{$status} ++; + if ($showcredits) { + $credit_count{$status} += $credits; + } } } if (@fields) { @@ -1241,6 +1301,9 @@ sub count_students { $countslist .= ''.$titles{$status}.': '. $student_count{$status}.'
'; $numbers->{$status} += $student_count{$status}; + if ($showcredits) { + $creditsum->{$status} += $credit_count{$status}; + } } } return $countslist;