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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 06 Mar 2008 21:57:35 -0000


raeburn		Thu Mar  6 16:57:35 2008 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - &course_sections() can take a third (optional argument) which is the single section currently stored.  The existing sections pulldown includes this section as the selected item.
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.50 loncom/interface/lonuserutils.pm:1.51
--- loncom/interface/lonuserutils.pm:1.50	Sun Jan 20 17:25:05 2008
+++ loncom/interface/lonuserutils.pm	Thu Mar  6 16:57:33 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.50 2008/01/20 22:25:05 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.51 2008/03/06 21:57:33 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4207,17 +4207,29 @@
 }
 
 sub course_sections {
-    my ($sections_count,$role) = @_;
+    my ($sections_count,$role,$current_sec) = @_;
     my $output = '';
     my @sections = (sort {$a <=> $b} keys %{$sections_count});
     my $numsec = scalar(@sections);
+    my $is_selected = ' selected="selected" ';
     if ($numsec <= 1) {
         $output = '<select name="currsec_'.$role.'" >'."\n".
-                  '  <option value="">'.&mt('Select').'</option>'."\n".
+                  '  <option value="">'.&mt('Select').'</option>'."\n";
+        if ($current_sec eq 'none') {
+            $output .=       
+                  '  <option value=""'.$is_selected.'>'.&mt('No section').'</option>'."\n";
+        } else {
+            $output .=
                   '  <option value="">'.&mt('No section').'</option>'."\n";
+        }
         if ($numsec == 1) {
-            $output .=  
+            if ($current_sec eq $sections[0]) {
+                $output .=
+                  '  <option value="'.$sections[0].'"'.$is_selected.'>'.$sections[0].'</option>'."\n";
+            } else {
+                $output .=  
                   '  <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
+            }
         }
     } else {
         $output = '<select name="currsec_'.$role.'" ';
@@ -4225,13 +4237,23 @@
         if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
         if ($role eq 'st') {
             $output .= '>'."\n".
-                       '  <option value="">'.&mt('Select').'</option>'."\n".
+                       '  <option value="">'.&mt('Select').'</option>'."\n";
+            if ($current_sec eq 'none') {
+                $output .= 
+                       '  <option value=""'.$is_selected.'>'.&mt('No section')."</option>\n";
+            } else {
+                $output .=
                        '  <option value="">'.&mt('No section')."</option>\n";
+            }
         } else {
             $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
         }
         foreach my $sec (@sections) {
-            $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
+            if ($current_sec eq $sec) {
+                $output .= '<option value="'.$sec.'"'.$is_selected.'>'.$sec."</option>\n";
+            } else {
+                $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
+            }
         }
     }
     $output .= '</select>';