--- loncom/homework/response.pm	2005/02/24 00:36:10	1.114
+++ 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.114 2005/02/24 00:36:10 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();
@@ -512,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;
 	}
     }
@@ -726,6 +728,37 @@ sub submitted {
     # 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__