[LON-CAPA-cvs] cvs: loncom /homework optionresponse.pm radiobuttonresponse.pm /homework/caparesponse caparesponse.pm /xml lonxml.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 17 Oct 2002 17:13:44 -0000


albertel		Thu Oct 17 13:13:44 2002 EDT

  Modified files:              
    /loncom/homework	radiobuttonresponse.pm optionresponse.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
    /loncom/xml	lonxml.pm 
  Log:
  - Rewrite counter code
  
  
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.56 loncom/homework/radiobuttonresponse.pm:1.57
--- loncom/homework/radiobuttonresponse.pm:1.56	Thu Oct 17 10:40:23 2002
+++ loncom/homework/radiobuttonresponse.pm	Thu Oct 17 13:13:44 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.56 2002/10/17 14:40:23 sakharuk Exp $
+# $Id: radiobuttonresponse.pm,v 1.57 2002/10/17 17:13:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -86,10 +86,7 @@
   &Apache::response::setrandomnumber();
   if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
       $result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
-      $Apache::lonxml::counter++;
-      my %moreenv;
-      $moreenv{'form.counter'}=$Apache::lonxml::counter;
-      &Apache::lonnet::appenv(%moreenv);
+      &Apache::lonxml::increment_counter();
   }
   return $result;
 }
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.52 loncom/homework/optionresponse.pm:1.53
--- loncom/homework/optionresponse.pm:1.52	Thu Oct 17 10:40:05 2002
+++ loncom/homework/optionresponse.pm	Thu Oct 17 13:13:44 2002
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.52 2002/10/17 14:40:05 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.53 2002/10/17 17:13:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -438,10 +438,7 @@
 	}
 
     }
-    $Apache::lonxml::counter++;
-    my %moreenv;
-    $moreenv{'form.counter'}=$Apache::lonxml::counter;
-    &Apache::lonnet::appenv(%moreenv);
+    &Apache::lonxml::increment_counter();
     return $result;
 }
 
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.66 loncom/homework/caparesponse/caparesponse.pm:1.67
--- loncom/homework/caparesponse/caparesponse.pm:1.66	Thu Oct 17 10:40:58 2002
+++ loncom/homework/caparesponse/caparesponse.pm	Thu Oct 17 13:13:44 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.66 2002/10/17 14:40:58 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.67 2002/10/17 17:13:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -278,7 +278,7 @@
 			    my $power = $2;
 			    $power=~s/^\+//;
 			    $power=~s/^(-?)0+(\d+)//;
-			    $ans=$number.'$\times 10^{'.$1.$2.'}$';
+			    $ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs
 			} 
 		    } else {
 			my $badans = $bubbles_values[$ind];
@@ -297,7 +297,7 @@
 			    my $power = $2;
 			    $power=~s/^\+//;
 			    $power=~s/^(-?)0+(\d+)//;
-			    $ans=$number.'$\times 10^{'.$1.$2.'}$';
+			    $ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs
 			} 
 		    }
 		    $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';
@@ -308,10 +308,7 @@
 		$result.='\\\\\end{tabular}\vskip 0 mm ';    
 	    }
 	    $result.='\end{enumerate}';
-	    $Apache::lonxml::counter++;		    
-	    my %moreenv;
-	    $moreenv{'form.counter'}=$Apache::lonxml::counter;
-	    &Apache::lonnet::appenv(%moreenv);   
+	    &Apache::lonxml::increment_counter();
 	}
     }
   } elsif ($target eq 'edit') {
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.203 loncom/xml/lonxml.pm:1.204
--- loncom/xml/lonxml.pm:1.203	Thu Oct 17 10:42:07 2002
+++ loncom/xml/lonxml.pm	Thu Oct 17 13:13:44 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.203 2002/10/17 14:42:07 sakharuk Exp $
+# $Id: lonxml.pm,v 1.204 2002/10/17 17:13:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,6 +140,10 @@
 # a pointer the the Apache request object
 $Apache::lonxml::request='';
 
+# a problem number counter, and check on hether it is used
+$Apache::lonxml::counter=0;
+$Apache::lonxml::counter_changed=0;
+
 sub xmlbegin {
   my $output='';
   if ($ENV{'browser.mathml'}) {
@@ -555,6 +559,7 @@
  if ($ENV{'request.uri'}) {
     &writeallows($ENV{'request.uri'});
  }
+ if ($Apache::lonxml::counter_changed) { &store_counter() }
  return $finaloutput;
 }
 
@@ -847,14 +852,7 @@
   my ($request,$target)=@_;
   $Apache::lonxml::request=$request;
   $Apache::lonxml::registered = 0;
-  if ($ENV{'form.counter'}) {
-      $Apache::lonxml::counter=$ENV{'form.counter'}
-  } elsif (not defined $Apache::lonxml::counter) {
-      $Apache::lonxml::counter=1;
-      my %moreenv;
-      $moreenv{'form.counter'}=$Apache::lonxml::counter;
-      &Apache::lonnet::appenv(%moreenv);
-  } 
+  &init_counter();
   @Apache::lonxml::pwd=();
   @Apache::lonxml::extlinks=();
   if ($target eq 'meta') {
@@ -1036,6 +1034,26 @@
    }
  }
  return $result
+}
+
+sub increment_counter {
+    $Apache::lonxml::counter++;
+    $Apache::lonxml::counter_changed=1;
+}
+
+sub init_counter {
+    if (defined($ENV{'form.counter'})) {
+	$Apache::lonxml::counter=$ENV{'form.counter'};
+    } elsif (not defined($Apache::lonxml::counter)) {
+	$Apache::lonxml::counter=1;
+	&store_counter();
+    }
+    $Apache::lonxml::counter_changed=0;
+}
+
+sub store_counter {
+    &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter));
+    return '';
 }
 
 sub get_all_text {