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

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 17 Oct 2005 21:14:55 -0000


albertel		Mon Oct 17 17:14:55 2005 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  - <defaultvalue> in <student> works now
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.125 loncom/interface/lonhelper.pm:1.126
--- loncom/interface/lonhelper.pm:1.125	Mon Oct 17 16:21:31 2005
+++ loncom/interface/lonhelper.pm	Mon Oct 17 17:14:55 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.125 2005/10/17 20:21:31 albertel Exp $
+# $Id: lonhelper.pm,v 1.126 2005/10/17 21:14:55 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2370,6 +2370,18 @@
         $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
     }
 
+    my %defaultUsers;
+    if (defined($self->{DEFAULT_VALUE})) {
+        my $valueFunc = eval($self->{DEFAULT_VALUE});
+        die 'Error in default value code for variable ' . 
+            $self->{'variable'} . ', Perl said: ' . $@ if $@;
+        my @defaultUsers = &$valueFunc($helper, $self);
+	if (!$self->{'multichoice'} && @defaultUsers) { # only allowed 1
+	    @defaultUsers = ($defaultUsers[0]);
+	}
+	%defaultUsers = map { if ($_) {($_,1) } } @defaultUsers;
+	delete($defaultUsers{''});
+    }
     my $choices = [];
 
     # Load up the non-students, if necessary
@@ -2435,7 +2447,13 @@
         $result .= "<tr><td><input type='$type' name='" .
             $self->{'variable'} . '.forminput' . "'";
             
-        if (!$self->{'multichoice'} && !$checked) {
+	if (%defaultUsers) {
+	    my $user=$choice->[0];
+	    if (exists($defaultUsers{$user})) {
+		$result .= " checked='checked' ";
+		$checked = 1;
+	    }
+	} elsif (!$self->{'multichoice'} && !$checked) {
             $result .= " checked='checked' ";
             $checked = 1;
         }