--- loncom/interface/coursecatalog.pm 2008/07/06 17:59:25 1.35 +++ loncom/interface/coursecatalog.pm 2008/07/15 19:43:15 1.40 @@ -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.40 2008/07/15 19:43:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,7 +53,8 @@ sub handler { } &Apache::lonacc::get_posted_cgi($r); &Apache::lonlocal::get_language_handle($r); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['sortby']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['sortby','showdom']); my $codedom = &Apache::lonnet::default_login_domain(); @@ -74,38 +75,45 @@ 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; } -ENDSCRIPT - if ($env{'form.state'} eq 'listing') { - $catjs .= qq| function changeSort(caller) { document.$formname.sortby.value = caller; document.$formname.submit(); } + function setCourseId(caller) { document.$formname.coursenum.value = caller; document.$formname.submit(); -}\n|; - } +} + +ENDSCRIPT + $catjs .= &syllabus_javascript(); my $numtitles; if ($env{'form.currcat_0'} eq 'instcode::0') { $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc, @@ -120,7 +128,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 +144,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)); } } } @@ -149,8 +157,10 @@ sub course_details { my $output; my %add_entries = (topmargin => "0", marginheight => "0",); + my $js = ''."\n"; my $start_page = - &Apache::loncommon::start_page('Course Catalog','', + &Apache::loncommon::start_page('Course Catalog',$js, { 'add_entries' => \%add_entries, 'no_inline_link' => 1,}); @@ -166,16 +176,33 @@ sub course_details { {text=>"Course details"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Details')); $r->print('
'.&mt('Detailed course information:').'

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

'); - $r->print(''. + $r->print(''. + ''. &mt('Back to course listing').''. - ''. - '
'); + &Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter','showdetails']).''); + return; +} + +sub syllabus_javascript { + return <<"END"; + +function ToSyllabus(cdom,cnum) { + if (cdom == '' || cdom == null) { + return; + } + if (cnum == '' || cnum == null) { + return; + } + document.syllabuslaunch.action = "/public/"+cdom+"/"+cnum+"/syllabus"; + document.syllabuslaunch.submit(); +} + +END } + sub instcode_course_selector { my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_; my %coursecodes = (); @@ -312,10 +339,7 @@ function setElements() { ''. ''); - if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) { - $r->print('
'); - } + '" />

'); } else { &cat_header($r,$codedom,$js,\%add_entries,$catlinks,$numtitles); my $cat_maxdepth = $env{'form.catalog_maxdepth'}; @@ -367,6 +391,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 +412,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 +488,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 +534,7 @@ sub additional_filters { my $dc_title = &Apache::lonnet::plaintext('dc'); $output .= ''; } - $output .= '
'. + '
'."\n". ''."\n".'
'. '
'. - '

'; + $output .= '
'; return $output; } @@ -629,7 +678,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 +686,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 +711,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 +739,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 +755,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']); + $output .= "\n".'
'. + ''. + &Apache::lonhtmlcommon::echo_form_input(['catalogfilter']).'
'; return $output; } @@ -790,7 +858,7 @@ sub build_courseinfo_hash { $cleandesc=~s/'/\\'/g; $cleandesc =~ s/^\s+//; my ($cdom,$cnum)=split(/\_/,$course); - my ($descr,$instcode,$singleowner,$ttype,$selfenroll_types, + my ($instcode,$singleowner,$ttype,$selfenroll_types, $selfenroll_start,$selfenroll_end,@owners,%ownernames,$categories); if (ref($courses->{$course}) eq 'HASH') { $descr = $courses->{$course}{'description'}; @@ -992,7 +1060,7 @@ sub courseinfo_row { ''.$xlist_items.''. ''.$title.' '; if ($showsyllabus) { - $output .= &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$cnum,$cdom); + $output .= ''.&mt('Syllabus').''; } else { $output .= ' '; } @@ -1046,7 +1114,7 @@ sub identify_sections { } } @secnums = sort {$a <=> $b} @secnums; - my $seclist = join(', ',@secnums); + $seclist = join(', ',@secnums); my $numsec = @secnums; return ($seclist,$numsec); }