--- loncom/interface/courseclassifier.pm 2013/07/15 14:32:45 1.15 +++ loncom/interface/courseclassifier.pm 2014/07/31 15:45:27 1.19 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utilities for classifying courses based on institutional code # -# $Id: courseclassifier.pm,v 1.15 2013/07/15 14:32:45 bisitz Exp $ +# $Id: courseclassifier.pm,v 1.19 2014/07/31 15:45:27 musolffc Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,7 +37,8 @@ use LONCAPA; sub retrieve_instcodes { my ($coursecodes,$codedom) = @_; my $totcodes; - my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.', undef,undef,'Course'); + my %courses = &Apache::lonnet::courseiddump($codedom,'.',1,'.','.','.', + undef,undef,'Course'); foreach my $course (keys(%courses)) { if (ref($courses{$course}) eq 'HASH') { if ($courses{$course}{'inst_code'} ne '') { @@ -488,12 +489,27 @@ sub instcode_selectors_data { if ($officialjs) { $jscript .= ' -function toggleOfficial() {'; +function toggleOfficial() { + var choice; + for (var i=0; i[$i].'.selectedIndex = 0;'; + document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;'; } - $jscript .= ' + $jscript .= ' + } else { + if (document.getElementById("instcodes")) { + document.getElementById("instcodes").style.display = "block"; + } + } } function setOfficial(caller) { @@ -563,7 +579,11 @@ sub build_instcode_selectors { my $output; my @standardnames = &Apache::loncommon::get_standard_codeitems(); if ($numtitles > 0) { - $output .= ''; + my $style; + if ($env{'form.official'} eq 'off') { + $style = ' style="display: none"'; + } + $output .= '
'; for (my $k=0; $k<$lasttitle-1; $k++) { my (@items,@unsorted); if (ref($cat_items->{$codetitles->[$k]}) eq 'ARRAY') { @@ -599,11 +619,38 @@ sub build_instcode_selectors { '
'."\n"; } - $output .= '
'; + $output .= ''; } return $output; } +sub instcode_selectors { + my ($codedom,$formname,$officialjs,$codetitles) = @_; + my ($output,%cat_titles,%cat_order,%cat_items); + my ($jscript,$totcodes,$numtitles,$lasttitle) = + &instcode_selectors_data($codedom,$formname,\%cat_items,$codetitles, + \%cat_titles,\%cat_order,$officialjs); + if ($numtitles > 0) { + my $official = ' checked="checked" '; + my $unofficial = ''; + if (($formname eq 'filterpicker') && ($env{'form.official'} eq 'off')) { + $unofficial = $official; + $official = ''; + } + $output .= ''.&mt('Official course:').' '. + (' 'x3).'
'. + &build_instcode_selectors($numtitles,$lasttitle,\%cat_items,$codetitles, + \%cat_titles,\%cat_order)."\n". + ''."\n". + ''."\n"; + } + return ($output,$jscript,$numtitles); +} + sub recurse_options { my ($currkey,$currlist,$level,$cat,$cat_options,$data,$by_year,$by_sem,$by_dept) = @_; if (ref($currlist) eq 'HASH') { @@ -692,12 +739,23 @@ sub javascript_select_filler { my $nocrs = &mt('No courses'); my $output = < 0) { + for (var i = 0; i< document.$formname.Year.options.length; i++) { + if (document.$formname.Year.options[i].value == "$env{'form.Year'}") { + document.$formname.Year.selectedIndex = i; + break; + } + } + } + if (document.$formname.Department.options.length > 0) { + for (var i = 0; i< document.$formname.Department.options.length; i++) { + if (document.$formname.Department.options[i].value == "$env{'form.Department'}") { + document.$formname.Department.selectedIndex = i; + break; + } + } + } + if (document.$formname.Semester.options.length > 0) { + for (var i = 0; i< document.$formname.Semester.options.length; i++) { + if (document.$formname.Semester.options[i].value == "$env{'form.Semester'}") { + document.$formname.Semester.selectedIndex = i; + break; + } + } + } + } + + var selYear = document.$formname.Year.selectedIndex-1; + var selSemester = document.$formname.Semester.selectedIndex-1; + var selDepartment = document.$formname.Department.selectedIndex-1; if (selYear == -1) { if (selSemester == -1) { if (selDepartment > -1) { @@ -802,7 +887,7 @@ function courseSet(caller) { } } if (iddept != -1) { - document.$formname.Number.options[0] = new Option('$all','0',false,false); + document.$formname.Number.options[0] = new Option('$all','0',false,false); for (var i=0; i 0) { + for (var i = 0; i< document.$formname.Number.options.length; i++) { + if (document.$formname.Number.options[i].value == "$env{'form.Number'}") { + document.$formname.Number.selectedIndex = i; + break; + } + } + } + } else { + $officialjs + } } END return $output;