--- loncom/homework/response.pm	2004/11/08 19:20:13	1.109
+++ loncom/homework/response.pm	2005/04/04 10:04:09	1.118
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.109 2004/11/08 19:20:13 albertel Exp $
+# $Id: response.pm,v 1.118 2005/04/04 10:04:09 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -110,6 +110,7 @@ sub poprandomnumber {
 	&Apache::lonxml::error("Unable to restore random algorithm.");
     }
 }
+
 sub setrandomnumber {
     my $rndseed;
     $rndseed=&Apache::structuretags::setup_rndseed();
@@ -124,11 +125,17 @@ sub setrandomnumber {
 	if (defined($Apache::inputtags::response[-1])) {
 	    $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
 	}
-    } else {
+    } elsif ($rand_alg eq '64bit3') {
 	$rndmod=(&Apache::lonnet::numval2($Apache::inputtags::part) << 10);
 	if (defined($Apache::inputtags::response[-1])) {
 	    $rndmod+=&Apache::lonnet::numval2($Apache::inputtags::response[-1]);
 	}
+    } else {
+	my $shift=(4*scalar(@Apache::inputtags::responselist))%30;
+	$rndmod=(&Apache::lonnet::numval3($Apache::inputtags::part) << (($shift+15)%30));
+	if (defined($Apache::inputtags::response[-1])) {
+	    $rndmod+=(&Apache::lonnet::numval3($Apache::inputtags::response[-1]) << $shift );
+	}
     }
     if ($rndseed =~/([,:])/) {
 	my $char=$1;
@@ -145,7 +152,7 @@ sub setrandomnumber {
 	    $rndseed=(($rndseed<<32)>>32);
 	}
     }
-    &Apache::lonxml::debug("randseed $rndseed");
+    &Apache::lonxml::debug("randseed $rndmod $rndseed");
     &Apache::lonnet::setup_random_from_rndseed($rndseed);
     return '';
 }
@@ -425,13 +432,11 @@ sub end_responseparam {
 }
 
 sub start_parameter {
-    my $result = &start_responseparam(@_);
-    return $result;
+    return &start_responseparam(@_);
 }
 
 sub end_parameter {
-    my $result = &end_responseparam(@_);
-    return $result;
+    return &end_responseparam(@_);
 }
 
 sub reset_params {
@@ -508,8 +513,9 @@ sub answer_footer {
 sub showallfoils {
     if (defined($ENV{'form.showallfoils'})) {
 	my ($symb)=&Apache::lonxml::whichuser();
-	if ($ENV{'request.state'} eq 'construct' || 
-	    ($ENV{'user.adv'} && $symb eq '')) {
+	if (($ENV{'request.state'} eq 'construct') || 
+	    ($ENV{'user.adv'} && $symb eq '')      ||
+            ($Apache::lonhomework::viewgrades) ) {
 	    return 1;
 	}
     }
@@ -709,6 +715,50 @@ sub get_response_param {
     return $parameter;
 }
 
+sub submitted {
+    my ($who)=@_;
+    
+    # when scatron grading any submission is a submission
+    if ($ENV{'form.submitted'} eq 'scantron') { return 1; }
+    # if the caller only cared if this was a scantron submission
+    if ($who eq 'scantron') { return 0; }
+    # if the Submit Answer button for this particular part was pressed
+    my $partid=$Apache::inputtags::part;
+    if (defined($ENV{'form.submit_'.$partid})) { return 1; }
+    # otherwise no submission occured
+    return 0;
+}
+
+# basically undef and 0 (both false) mean that they still have work to do
+# and all true values mean that they can't do any more work
+#
+# a return of undef means it is unattempted
+# a return of 0 means it is attmpted and wrong but still has tries
+# a return of 1 means it is marked correct
+# a return of 2 means they have exceed maximum number of tries
+# a return of 3 means it after the answer date
+sub check_status {
+    my ($id)=@_;
+    if (!$id) {	$id=$Apache::linputtags::part; }
+    my $curtime=&Apache::lonnet::EXT('system.time');
+    my $opendate=&Apache::lonnet::EXT("resource.$id.opendate");
+    my $duedate=&Apache::lonnet::EXT("resource.$id.duedate");
+    my $answerdate=&Apache::lonnet::EXT("resource.$id.answerdate");
+    if ( $opendate && $curtime > $opendate &&
+         $duedate && $curtime > $duedate &&
+         $answerdate && $curtime > $answerdate) {
+        return 3;
+    }
+    my $status=&Apache::lonnet::EXT("user.resource.resource.$id.solved");
+    if ($status =~ /^correct/) { return 1; }
+    if (!$status) { return undef; }
+    my $maxtries=&Apache::lonnet::EXT("resource.$id.maxtries");
+    if ($maxtries eq '') { $maxtries=2; }
+    my $curtries=&Apache::lonnet::EXT("user.resource.resource.$id.tries");
+    if ($curtries < $maxtries) { return 0; }
+    return 2;
+}
+
 1;
 __END__