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

foxr foxr@source.lon-capa.org
Tue, 17 Mar 2009 11:13:59 -0000


foxr		Tue Mar 17 11:13:59 2009 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  BZ 4360  Added code to post processing stage of <resource> tag.
  If the form.VARNAME_forminput variable for an OPTION_VAR is not defined,
  act as if it's set to ''...that is no options selected.  Otherwise,
  if someone unselects all options, the prior, saved setting is used.
  
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.170 loncom/interface/lonhelper.pm:1.171
--- loncom/interface/lonhelper.pm:1.170	Fri Feb 13 20:20:30 2009
+++ loncom/interface/lonhelper.pm	Tue Mar 17 11:13:59 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.170 2009/02/13 20:20:30 schafran Exp $
+# $Id: lonhelper.pm,v 1.171 2009/03/17 11:13:59 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -188,6 +188,8 @@
 use Apache::lonnet;
 use Apache::longroup;
 use Apache::lonselstudent;
+
+
 use LONCAPA;
 
 # Register all the tags with the helper, so the helper can 
@@ -1508,12 +1510,15 @@
     my $self = shift;
     my $chosenValue = $env{'form.' . $self->{'variable'} . '_forminput'};
 
+
     if (!defined($chosenValue) && !$self->{'allowempty'}) {
         $self->{ERROR_MSG} = 
 	    &mt("You must choose one or more choices to continue.");
         return 0;
     }
 
+
+
     if (ref($chosenValue)) {
         $helper->{VARS}->{$self->{'variable'}} = join('|||', @$chosenValue);
     }
@@ -2446,6 +2451,21 @@
         $self->{ERROR_MSG} = 'You must choose at least one resource to continue.';
         return 0;
     }
+    # For each of the attached options.  If it's env var is undefined, set it to
+    # an empty string instead.. an undef'd env var means no choices selected.
+    #
+
+    my $option_vars = $self->{OPTION_VARS};
+    if ($option_vars) {
+	foreach my $var (@$option_vars) {
+	    my $env_name = "form.".$var."_forminput";
+	    if (!defined($env{$env_name})) {
+		$env{$env_name} = '';
+		$helper->{VARS}->{$var} = '';
+	    }
+	}
+    }
+
 
     if (defined($self->{NEXTSTATE})) {
         $helper->changeState($self->{NEXTSTATE});