--- loncom/homework/response.pm	2005/03/28 11:57:48	1.115
+++ loncom/homework/response.pm	2005/04/01 18:08:14	1.117
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.115 2005/03/28 11:57:48 foxr Exp $
+# $Id: response.pm,v 1.117 2005/04/01 18:08:14 albertel 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();
@@ -513,8 +514,7 @@ sub showallfoils {
     if (defined($ENV{'form.showallfoils'})) {
 	my ($symb)=&Apache::lonxml::whichuser();
 	if ($ENV{'request.state'} eq 'construct' || 
-	    ($ENV{'user.adv'} && $symb eq '')    ||
-            ($ENV{'print.showallfoils'})  ) {
+	    $ENV{'user.adv'} ) {
 	    return 1;
 	}
     }
@@ -727,6 +727,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__