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

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 08 Nov 2005 03:12:35 -0000


albertel		Mon Nov  7 22:12:35 2005 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - allow an optional order arg
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.283 loncom/interface/loncommon.pm:1.284
--- loncom/interface/loncommon.pm:1.283	Mon Nov  7 22:08:15 2005
+++ loncom/interface/loncommon.pm	Mon Nov  7 22:12:35 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.283 2005/11/08 03:08:15 albertel Exp $
+# $Id: loncommon.pm,v 1.284 2005/11/08 03:12:35 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1170,12 +1170,13 @@
   $size - number of rows long the select element is
   $hash - the elements should be 'option' => 'shown text'
           (shown text should already have been &mt())
+  $order - (optional) array ref of the order to show the elments in
 
 =cut
 
 #-------------------------------------------
 sub multiple_select_form {
-    my ($name,$value,$size,$hash)=@_;
+    my ($name,$value,$size,$hash,$order)=@_;
     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
     my $output='';
     if (! defined($size)) {
@@ -1185,10 +1186,12 @@
         }
     }
     $output.="\n<select name='$name' size='$size' multiple='1'>";
-    foreach (sort(keys(%$hash))) {
-        $output.='<option value="'.$_.'" ';
-        $output.='selected="selected" ' if ($selected{$_});
-        $output.='>'.$hash->{$_}."</option>\n";
+    my @order = ref($order) ? @{$order}
+                            : sort(keys(%$hash));
+    foreach my $key (@order) {
+        $output.='<option value="'.$key.'" ';
+        $output.='selected="selected" ' if ($selected{$key});
+        $output.='>'.$hash->{$key}."</option>\n";
     }
     $output.="</select>\n";
     return $output;