--- loncom/homework/optionresponse.pm	2004/02/19 21:55:54	1.102
+++ loncom/homework/optionresponse.pm	2004/03/08 23:23:04	1.103
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.102 2004/02/19 21:55:54 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.103 2004/03/08 23:23:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -27,7 +27,8 @@
 #
 package Apache::optionresponse;
 use strict;
-use Apache::response;
+use Apache::response();
+use Apache::lonlocal;
 
 BEGIN {
   &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
@@ -41,6 +42,7 @@ sub start_optionresponse {
   push (@Apache::lonxml::namespace,'optionresponse');
   my $id = &Apache::response::start_response($parstack,$safeeval);
   %Apache::hint::option=();
+  undef(%Apache::response::foilnames);
   if ($target eq 'edit') {
     $result.=&Apache::edit::start_table($token).
 	"<tr><td>Multiple Option Response Question ".
@@ -75,6 +77,7 @@ sub end_optionresponse {
   &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
   my $result;
   if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
+  undef(%Apache::response::foilnames);
   return $result;
 }
 
@@ -565,10 +568,14 @@ sub end_foil {
     my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
     if ($value ne 'unused') {
       my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
-      my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
+      $Apache::response::foilnames{$name}++;
       &Apache::lonxml::debug("Got a name of :$name:");
       if (!$name) { $name=$Apache::lonxml::curdepth; }
       &Apache::lonxml::debug("Using a name of :$name:");
+      if (defined($Apache::response::foilnames{$name})) {
+	  &Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name));
+      }
+      my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
       if ( $Apache::optionresponse::conceptgroup
 	   && !&Apache::response::showallfoils() ) {
 	push @{ $Apache::response::conceptgroup{'names'} }, $name;