--- loncom/interface/lonhelper.pm	2005/10/17 20:21:31	1.125
+++ loncom/interface/lonhelper.pm	2005/10/17 21:17:59	1.127
@@ -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.127 2005/10/17 21:17:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2370,6 +2370,18 @@ BUTTONS
         $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 @@ BUTTONS
         $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;
         }
@@ -3343,8 +3361,11 @@ sub render {
     }
     my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"');
     my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"');
+    my $target = " target='loncapaclient'";
+    if (($env{'browser.interface'} eq 'textual') ||
+        ($env{'environment.remote'} eq 'off')) {  $target='';  }
     $result .= "<center>\n" .
-	"<form action='".$actionURL."' method='post' target='loncapaclient'>\n" .
+	"<form action='".$actionURL."' method='post' $target>\n" .
 	"<input type='button' onclick='history.go(-1)' value='$previous' />" .
 	"<input type='hidden' name='orgurl' value='$targetURL' />" .
 	"<input type='hidden' name='selectrole' value='1' />\n" .