--- loncom/homework/optionresponse.pm	2001/05/04 21:19:37	1.6
+++ loncom/homework/optionresponse.pm	2001/06/01 15:56:49	1.10
@@ -11,21 +11,39 @@ sub BEGIN {
 
 sub start_optionresponse {
   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
+  my $result='';
   #when in a radiobutton response use these
   &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
+  push (@Apache::lonxml::namespace,'optionresponse');
   my $id = &Apache::response::start_response($parstack,$safeeval);
-  return '';
+  if ($target eq 'edit') {
+    $result.="<table width=\"100%\" border=\"2\"><tr><td>Multiple Option Response Question</td>
+<td>Delete:".
+  &Apache::edit::deletelist($target,$token)
+."</td></tr><tr><td colspan=\"3\">\n";
+  }
+
+  return $result;
 }
 
 sub end_optionresponse {
   &Apache::response::end_response;
+  pop @Apache::lonxml::namespace;
   return '';
 }
 
+sub insert_optionresponse {
+  return '
+<optionresponse max="10">
+    <foilgroup options=\"\">
+    </foilgroup>
+</optionresponse>';
+}
+
 %Apache::response::foilgroup={};
 sub start_foilgroup {
   %Apache::response::foilgroup={};
-  $Apache::optionresponse::conceptgroup=0;  
+  $Apache::optionresponse::conceptgroup=0;
   &Apache::response::setrandomnumber();
   return '';
 }
@@ -52,6 +70,7 @@ sub end_foilgroup {
 	my $allresponse;
 	my $right=0;
 	my $wrong=0;
+	my $ignored=0;
 	foreach $name (@whichopt) {
 	  my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1'].":$temp"};
 	  $allresponse.="$response:";
@@ -59,13 +78,15 @@ sub end_foilgroup {
 	    &Apache::lonxml::debug("submitted a $response<br />\n");
 	    my $value=$Apache::response::foilgroup{$name.'.value'};
 	    if ($value eq $response) {$right++;} else {$wrong++;}
+	  } else {
+	    $ignored++;
 	  }
 	  $temp++;
 	}
 	my $id = $Apache::inputtags::response['-1'];
 	$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$allresponse;
-	&Apache::lonxml::debug("Got $right right and $wrong wrong");
-	if ($wrong==0) {
+	&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
+	if ($wrong==0 && $ignored==0) {
 	  $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS';
 	} else {
 	  $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT';
@@ -78,10 +99,9 @@ sub end_foilgroup {
 
 sub getfoilcounts {
   my ($parstack,$safeeval)=@_;
-  my $rrargs ='';
-  if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; }
-  my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval);
-  my $count = $#{ $Apache::response::foilgroup{'names'} };
+  my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
+  # +1 since instructors will count from 1
+  my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
   return ($count,$max);
 }
 
@@ -89,8 +109,9 @@ sub whichfoils {
   my ($max)=@_;
   my @names = @{ $Apache::response::foilgroup{'names'} };
   my @whichopt =();
-  while ((($#whichopt) < $max) && ($#names > -1)) {
-    my $aopt=int rand $#names;
+  while ((($#whichopt+1) < $max) && ($#names > -1)) {
+    &Apache::lonxml::debug("Have $#whichopt max is $max");
+    my $aopt=int(rand($#names+1));
     &Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
     $aopt=splice(@names,$aopt,1);
     &Apache::lonxml::debug("Picked $aopt");
@@ -146,9 +167,7 @@ sub end_conceptgroup {
     push @{ $Apache::response::foilgroup{'names'} }, $name;
     $Apache::response::foilgroup{"$name.value"} =  $Apache::response::conceptgroup{"$name.value"};
     $Apache::response::foilgroup{"$name.text"} =  $Apache::response::conceptgroup{"$name.text"};
-    my $args;
-    if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
-    my $concept = &Apache::run::run("{$args;".'return $concept}',$safeeval);
+    my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
     $Apache::response::foilgroup{"$name.concept"} = $concept;
     &Apache::lonxml::debug("Selecting $name in $concept");
   }
@@ -166,11 +185,9 @@ sub end_foil {
   my $text ='';
   if ($target eq 'web') { $text=&Apache::lonxml::endredirection; }
   if ($target eq 'web' || $target eq 'grade') {
-    my $args ='';
-    if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
-    my $value = &Apache::run::run("{$args;".'return $value}',$safeeval);
+    my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
     if ($value ne 'unused') {
-      my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
+      my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
       if ( $Apache::optionresponse::conceptgroup ) {
 	push @{ $Apache::response::conceptgroup{'names'} }, $name;
 	$Apache::response::conceptgroup{"$name.value"} = $value;
@@ -183,9 +200,7 @@ sub end_foil {
     }
   }
   if ($target eq 'edit') {
-    my $args ='';
-    if ( $#$parstack > 1 ) { $args=$$parstack['-2']; }
-    my $options=&Apache::run::run("{$args;".'return $options}',$safeeval);
+    my $options= &Apache::lonxml::get_param('options',$parstack,$safeeval);
     if (!$options && $#$parstack > 2 ) { $args=$$parstack['-2']; }
     my @opt;
     #eval '@opt ='.
@@ -193,6 +208,11 @@ sub end_foil {
   return '';
 }
 
+sub insert_foil {
+  return '
+<foil name="" value="">
+</foil>';
+}
 1;
 __END__