--- loncom/interface/coursecatalog.pm 2008/07/06 17:59:25 1.35 +++ loncom/interface/coursecatalog.pm 2008/07/07 15:20:18 1.36 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler for displaying the course catalog interface # -# $Id: coursecatalog.pm,v 1.35 2008/07/06 17:59:25 raeburn Exp $ +# $Id: coursecatalog.pm,v 1.36 2008/07/07 15:20:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -74,22 +74,29 @@ sub handler { my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom); - my (@cats,@trails,%allitems,%idx,@jsarray,$cathash); + my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash); if (ref($domconfig{'coursecategories'}) eq 'HASH') { $cathash = $domconfig{'coursecategories'}{'cats'}; } else { $cathash = {}; } + my $subcats; + if ($env{'form.withsubcats'}) { + $subcats = \%subcathash; + } &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems, - \%idx,\@jsarray); + \%idx,\@jsarray,$subcats); if ($env{'form.coursenum'} ne '' && &user_is_known()) { &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems); } else { - my $catlinks = &category_breadcrumbs($codedom,@cats); + my ($catlinks,$has_subcats) = &category_breadcrumbs($codedom,@cats); my $catjs = <<"ENDSCRIPT"; function setCatDepth(depth) { document.coursecats.catalog_maxdepth.value = depth; + if (depth == '') { + document.coursecats.currcat_0.value = ''; + } document.coursecats.submit(); return; } @@ -120,7 +127,7 @@ function setCourseId(caller) { if ($env{'form.currcat_0'} ne '') { $r->print('
'. - &additional_filters($codedom)."\n"); + &additional_filters($codedom,$has_subcats)."\n"); my ($currdepth,$deeper) = &get_depth_values(); $r->print(''."\n"); @@ -136,7 +143,7 @@ function setCourseId(caller) { &mt('Display courses').'" />


'); } if ($env{'form.state'} eq 'listing') { - $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems)); + $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats)); } } } @@ -367,6 +374,7 @@ sub category_breadcrumbs { my ($currdepth,$deeper) = &get_depth_values(); my $currcat_str = ''; my $catlinks = ''.&mt('Catalog:').''; + my $has_subcats; for (my $i=0; $i<$deeper; $i++) { $currcat_str .= ''; my ($cattitle,$shallower); @@ -387,22 +395,19 @@ sub category_breadcrumbs { ''; $env{'form.currcat_0'} = 'instcode::0'; } else { + $has_subcats = 1; $catlinks .= '
'.$currcat; if (ref($cats[$deeper]{$cat}) eq 'ARRAY') { + $has_subcats = 1; + my $selstr; $catlinks .= ': 
'; - return $catlinks; + return ($catlinks,$has_subcats); } sub get_depth_values { @@ -463,12 +471,40 @@ sub get_depth_values { } sub additional_filters { - my ($codedom) = @_; + my ($codedom,$has_subcats) = @_; my $output = ''; + if (($env{'form.currcat_0'} ne 'instcode::0') && + ($env{'form.currcat_0'} ne '') && ($has_subcats)) { + my $include_subcat_status; + if ($env{'form.withsubcats'}) { + $include_subcat_status = 'checked="checked" '; + } + my $counter = $env{'form.catalog_maxdepth'}; + if ($counter > 0) { + if ($env{'form.state'} eq 'listing') { + $counter --; + } elsif ($env{'form.currcat_'.$counter} eq '') { + $counter --; + } + } + my ($catname) = split(/:/,$env{'form.currcat_'.$counter}); + if ($catname ne '') { + $output .= ''; + } + } my $show_selfenroll_status; if ($env{'form.showselfenroll'}) { $show_selfenroll_status = 'checked="checked" '; } + $output .= ''; if (&user_is_dc($codedom)) { my $showdetails_status; if ($env{'form.showdetails'}) { @@ -481,7 +517,7 @@ sub additional_filters { my $dc_title = &Apache::lonnet::plaintext('dc'); $output .= ''; } - $output .= '
'. + '
'."\n". ''."\n".'
'. '
'. - '

'; + $output .= '
'; return $output; } @@ -629,7 +661,7 @@ sub search_official_courselist { } sub search_courselist { - my ($domain) = @_; + my ($domain,$subcats) = @_; my $cat_maxdepth = $env{'form.catalog_maxdepth'}; my $filter = $env{'form.currcat_'.$cat_maxdepth}; if (($filter eq '') && ($cat_maxdepth > 0)) { @@ -637,7 +669,24 @@ sub search_courselist { $filter = $env{'form.currcat_'.$shallower}; } my %courses; + my $filterstr; if ($filter ne '') { + if ($env{'form.withsubcats'}) { + if (ref($subcats) eq 'HASH') { + if (ref($subcats->{$filter}) eq 'ARRAY') { + $filterstr = join('&',@{$subcats->{$filter}}); + if ($filterstr ne '') { + $filterstr = $filter.'&'.$filterstr; + } + } else { + $filterstr = $filter; + } + } else { + $filterstr = $filter; + } + } else { + $filterstr = $filter; + } my $showhidden; if (&user_is_dc($domain)) { $showhidden = $env{'form.showhidden'}; @@ -645,13 +694,13 @@ sub search_courselist { %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef, '.',1,$env{'form.showselfenroll'}, - $filter,$showhidden,'coursecatalog'); + $filterstr,$showhidden,'coursecatalog'); } return %courses; } sub print_course_listing { - my ($domain,$numtitles,$trails,$allitems) = @_; + my ($domain,$numtitles,$trails,$allitems,$subcats) = @_; my $output; my %courses; my $knownuser = &user_is_known(); @@ -673,7 +722,7 @@ sub print_course_listing { if ($env{'form.currcat_0'} eq 'instcode::0') { %courses = &search_official_courselist($domain,$numtitles); } else { - %courses = &search_courselist($domain); + %courses = &search_courselist($domain,$subcats); } if (keys(%courses) == 0) { $output = &mt('No courses match the criteria you selected.'); @@ -689,7 +738,9 @@ sub print_course_listing { my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems); - $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']); + if ($env{'form.coursenum'} ne '') { + $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']); + } return $output; }