[LON-CAPA-cvs] cvs: loncom /homework imageresponse.pm matchresponse.pm optionresponse.pm radiobuttonresponse.pm rankresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 08 Mar 2004 23:23:05 -0000


This is a MIME encoded message

--albertel1078788185
Content-Type: text/plain

albertel		Mon Mar  8 18:23:05 2004 EDT

  Modified files:              
    /loncom/homework	imageresponse.pm matchresponse.pm 
                    	optionresponse.pm radiobuttonresponse.pm 
                    	rankresponse.pm 
  Log:
  - BUG#2551, foil names need to be unique otherwise things go wonky, throw errors if we see repeated names.
  
  
  
--albertel1078788185
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040308182305.txt"

Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.50 loncom/homework/imageresponse.pm:1.51
--- loncom/homework/imageresponse.pm:1.50	Tue Feb 24 13:57:43 2004
+++ loncom/homework/imageresponse.pm	Mon Mar  8 18:23:04 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # image click response style
 #
-# $Id: imageresponse.pm,v 1.50 2004/02/24 18:57:43 albertel Exp $
+# $Id: imageresponse.pm,v 1.51 2004/03/08 23:23:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,10 +31,11 @@
 
 package Apache::imageresponse;
 use strict;
-use Image::Magick;
-use Apache::randomlylabel;
-use Apache::londefdef;
+use Image::Magick();
+use Apache::randomlylabel();
+use Apache::londefdef();
 use Apache::Constants qw(:common :http);
+use Apache::lonlocal;
 
 BEGIN {
     &Apache::lonxml::register('Apache::imageresponse',('imageresponse'));
@@ -49,6 +50,7 @@
 			       'polygon','conceptgroup'));
     push (@Apache::lonxml::namespace,'imageresponse');
     my $id = &Apache::response::start_response($parstack,$safeeval);
+    undef(%Apache::response::foilnames);
     if ($target eq 'meta') {
 	$result=&Apache::response::meta_package_write('imageresponse');
     } elsif ($target eq 'analyze') {
@@ -65,6 +67,7 @@
     &Apache::lonxml::deregister('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));
     my $result;
     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
+    undef(%Apache::response::foilnames);
     return $result;
 }
 
@@ -335,6 +338,9 @@
 	$target eq 'analyze') {
 	my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
 	if ($name eq '') { $name=$Apache::lonxml::curdepth; }
+	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));
+	}
 	if ( $Apache::imageresponse::conceptgroup
 	     && !&Apache::response::showallfoils()) {
 	    push(@{ $Apache::response::conceptgroup{'names'} }, $name);
Index: loncom/homework/matchresponse.pm
diff -u loncom/homework/matchresponse.pm:1.36 loncom/homework/matchresponse.pm:1.37
--- loncom/homework/matchresponse.pm:1.36	Tue Feb 10 12:01:20 2004
+++ loncom/homework/matchresponse.pm	Mon Mar  8 18:23:04 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Full matching style response
 #
-# $Id: matchresponse.pm,v 1.36 2004/02/10 17:01:20 albertel Exp $
+# $Id: matchresponse.pm,v 1.37 2004/03/08 23:23:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,7 +30,8 @@
 use strict;
 use HTML::Entities();
 use Math::Random();
-use Apache::optionresponse;
+use Apache::optionresponse();
+use Apache::lonlocal;
 
 BEGIN {
     &Apache::lonxml::register('Apache::matchresponse',('matchresponse'));
@@ -46,6 +47,7 @@
     push (@Apache::lonxml::namespace,'matchresponse');
     my $id = &Apache::response::start_response($parstack,$safeeval);
     %Apache::hint::match=();
+    undef(%Apache::response::foilnames);
     if ($target eq 'meta') {
 	$result=&Apache::response::meta_package_write('matchresponse');
     } elsif ($target eq 'edit' ) {
@@ -80,6 +82,7 @@
     pop @Apache::lonxml::namespace;
     &Apache::lonxml::deregister('Apache::matchresponse',
 				('foilgroup','foil','conceptgroup'));
+    undef(%Apache::response::foilnames);
     return $result;
 }
 
@@ -592,10 +595,14 @@
 	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::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::matchresponse::conceptgroup
 		 && !&Apache::response::showallfoils() ) {
 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.102 loncom/homework/optionresponse.pm:1.103
--- loncom/homework/optionresponse.pm:1.102	Thu Feb 19 16:55:54 2004
+++ loncom/homework/optionresponse.pm	Mon Mar  8 18:23:04 2004
@@ -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 @@
   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 @@
   &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 @@
     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;
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.84 loncom/homework/radiobuttonresponse.pm:1.85
--- loncom/homework/radiobuttonresponse.pm:1.84	Fri Mar  5 18:04:31 2004
+++ loncom/homework/radiobuttonresponse.pm	Mon Mar  8 18:23:04 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.84 2004/03/05 23:04:31 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.85 2004/03/08 23:23:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -29,6 +29,7 @@
 package Apache::radiobuttonresponse;
 use strict;
 use HTML::Entities();
+use Apache::lonlocal;
 
 BEGIN {
     &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
@@ -42,6 +43,7 @@
     push (@Apache::lonxml::namespace,'radiobuttonresponse');
     my $id = &Apache::response::start_response($parstack,$safeeval);
     %Apache::hint::radiobutton=();
+    undef(%Apache::response::foilnames);
     if ($target eq 'meta') {
 	$result=&Apache::response::meta_package_write('radiobuttonresponse');
     } elsif ($target eq 'edit' ) {
@@ -92,6 +94,7 @@
     &Apache::response::end_response;
     pop @Apache::lonxml::namespace;
     &Apache::lonxml::deregister('Apache::radiobuttonresponse',('foilgroup','foil','conceptgroup'));
+    undef(%Apache::response::foilnames);
     return $result;
 }
 
@@ -535,12 +538,17 @@
     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
 	$text=&Apache::lonxml::endredirection;
     }
-    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'  || $target eq 'tex' || $target eq 'analyze') {
+    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
+	|| $target eq 'tex' || $target eq 'analyze') {
 	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);
 	    if (!$name) { $name=$Apache::lonxml::curdepth; }
+	    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::radiobuttonresponse::conceptgroup
 		 && !&Apache::response::showallfoils() ) {
 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
Index: loncom/homework/rankresponse.pm
diff -u loncom/homework/rankresponse.pm:1.29 loncom/homework/rankresponse.pm:1.30
--- loncom/homework/rankresponse.pm:1.29	Tue Feb 10 12:01:20 2004
+++ loncom/homework/rankresponse.pm	Mon Mar  8 18:23:04 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # rank style response
 #
-# $Id: rankresponse.pm,v 1.29 2004/02/10 17:01:20 albertel Exp $
+# $Id: rankresponse.pm,v 1.30 2004/03/08 23:23:04 albertel Exp $
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -28,7 +28,8 @@
 package Apache::rankresponse;
 use strict;
 use HTML::Entities();
-use Apache::optionresponse;
+use Apache::optionresponse();
+use Apache::lonlocal;
 
 BEGIN {
     &Apache::lonxml::register('Apache::rankresponse',('rankresponse'));
@@ -43,6 +44,7 @@
     push (@Apache::lonxml::namespace,'rankresponse');
     my $id = &Apache::response::start_response($parstack,$safeeval);
     %Apache::hint::rank=();
+    undef(%Apache::response::foilnames);
     if ($target eq 'meta') {
 	$result=&Apache::response::meta_package_write('rankresponse');
     } elsif ($target eq 'edit' ) {
@@ -77,6 +79,7 @@
     pop @Apache::lonxml::namespace;
     &Apache::lonxml::deregister('Apache::rankresponse',
 				('foilgroup','foil','conceptgroup'));
+    undef(%Apache::response::foilnames);
     return $result;
 }
 
@@ -406,10 +409,14 @@
 	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::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::rankresponse::conceptgroup
 		 && !&Apache::response::showallfoils() ) {
 		push @{ $Apache::response::conceptgroup{'names'} }, $name;

--albertel1078788185--