[LON-CAPA-cvs] cvs: loncom /interface courseclassifier.pm

raeburn raeburn@source.lon-capa.org
Fri, 25 Feb 2011 02:07:46 -0000


raeburn		Fri Feb 25 02:07:46 2011 EDT

  Modified files:              
    /loncom/interface	courseclassifier.pm 
  Log:
  - Bug 6333.
  
  
Index: loncom/interface/courseclassifier.pm
diff -u loncom/interface/courseclassifier.pm:1.11 loncom/interface/courseclassifier.pm:1.12
--- loncom/interface/courseclassifier.pm:1.11	Fri Dec  3 04:28:36 2010
+++ loncom/interface/courseclassifier.pm	Fri Feb 25 02:07:46 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utilities for classifying courses based on institutional code
 #
-# $Id: courseclassifier.pm,v 1.11 2010/12/03 04:28:36 raeburn Exp $
+# $Id: courseclassifier.pm,v 1.12 2011/02/25 02:07:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -55,7 +55,7 @@
     if (defined($$cat_order{$$codetitles[$num]})) {
         foreach my $item (@{$$cat_order{$$codetitles[$num]}}) {
             if (grep/^\Q$item\E$/,@unsorted) {
-                push @{$sorted}, $item;
+                push(@{$sorted},$item);
             }
         }
     } else {
@@ -517,26 +517,35 @@
                 }
                 $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs);
                 if ($env{'form.state'} eq 'listing') {
+                    my @standardnames = &Apache::loncommon::get_standard_codeitems();
+                    my %local_to_standard;
+                    if (ref($codetitles) eq 'ARRAY') {
+                        for (my $i=0; $i<@{$codetitles}; $i++) {
+                            $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
+                        }
+                    }
                     $jscript .= '
 function setElements() {
 ';
                     for (my $i=0; $i<@{$codetitles}-1; $i++) {
-                        if ($env{'form.'.$codetitles->[$i]} != -1) {
+                        my $item = $local_to_standard{$codetitles->[$i]};
+                        if ($env{'form.'.$item} != -1) {
                             $jscript .= '
-    for (var j=0; j<document.'.$formname.'.'.$codetitles->[$i].'.length; j++) {
-        if (document.'.$formname.'.'.$codetitles->[$i].'[j].value == "'.$env{'form.'.$codetitles->[$i]}.'") {
-            document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = j;
+    for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
+        if (document.'.$formname.'.'.$item.'[j].value == "'.$env{'form.'.$item}.'") {
+            document.'.$formname.'.'.$item.'.selectedIndex = j;
         }
     }
 ';
                         }
                     }
                     $jscript .= '   courseSet()'."\n";
-                    if ($env{'form.'.$codetitles->[-1]} != -1) {
+                    my $lastcodetitle =  $local_to_standard{$codetitles->[-1]};
+                    if ($env{'form.'.$lastcodetitle} != -1) {
                         $jscript .= '
-    for (var j=0; j<document.'.$formname.'.'.$codetitles->[-1].'.length; j++) {
-        if (document.'.$formname.'.'.$codetitles->[-1].'[j].value == "'.$env{'form.'.$codetitles->[-1]}.'") {
-            document.'.$formname.'.'.$codetitles->[-1].'.selectedIndex = j;
+    for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
+        if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$env{'form.'.$lastcodetitle}.'") {
+            document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
         }
     }
 ';
@@ -841,7 +850,7 @@
                 my $item = $local_to_standard{$loctitle};
                 if ($item ne '') {
                     if ($env{'form.'.$item} eq '0' ) {
-                        $instcode .= $codedefaults{$item};
+                        $instcode .= $codedefaults{$loctitle};
                     } else {
                         $instcode .= $env{'form.'.$item};
                     }