--- loncom/homework/lonhomework.pm 2001/06/12 22:42:55 1.46
+++ loncom/homework/lonhomework.pm 2001/08/17 15:51:00 1.54
@@ -1,7 +1,7 @@
# The LON-CAPA Homework handler
# Guy Albertelli
# 11/30 Gerd Kortemeyer
-# 6/1 Gerd Kortemeyer
+# 6/1,8/17 Gerd Kortemeyer
package Apache::lonhomework;
use strict;
@@ -14,7 +14,7 @@ use Apache::response;
use Apache::hint;
use Apache::outputtags;
use Apache::Constants qw(:common);
-
+#use Time::HiRes qw( gettimeofday tv_interval );
sub BEGIN {
&Apache::lonxml::register_insert();
@@ -84,7 +84,8 @@ sub send_footer {
}
$Apache::lonxml::browse='';
-sub check_date {
+
+sub check_access {
my ($id) = @_;
my $date ='';
my $status = '';
@@ -130,6 +131,12 @@ sub check_date {
if ( $maxtries eq '' ) { $maxtries = '2'; }
if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
}
+
+ if (($status ne 'CLOSED') && (&Apache::lonhomework::type eq 'exam')) {
+ return ('UNCHECKEDOUT','needs to be checked out');
+ }
+
+
&Apache::lonxml::debug("sending back :$status:$datemsg:");
if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {
&Apache::lonxml::debug("should be allowed to browse a resource when closed");
@@ -172,11 +179,41 @@ sub setupheader {
return ''
}
+sub handle_save_or_undo {
+ my ($request,$problem,$result) = @_;
+ my $fileout = &Apache::lonnet::filelocation("",$request->uri);
+ my $filesave=$fileout.".bak";
+
+ if ($ENV{'form.Undo'} eq 'undo') {
+ if (copy($filesave,$fileout)) {
+ $request->print("Undid changes, Copied $filesave to $fileout
");
+ } else {
+ $request->print("Unable to undo, unable to copy $filesave to $fileout
");
+ }
+ } else {
+ my $fs=Apache::File->new(">$filesave");
+ if (defined($fs)) {
+ print $fs $$problem;
+ $request->print("Making Backup to $filesave
");
+ } else {
+ $request->print("Unable to make backup $filesave");
+ }
+ my $fh=Apache::File->new(">$fileout");
+ if (defined($fh)) {
+ print $fh $$result;
+ $request->print("Saving Modifications to $fileout
");
+ } else {
+ $request->print("Unable to write to $fileout");
+ }
+ }
+}
+
sub renderpage {
my ($request,$file) = @_;
my (@targets) = &get_target();
foreach my $target (@targets) {
+ #my $t0 = [&gettimeofday()];
my $problem=&Apache::lonnet::getfile($file);
if ($problem == -1) {
&Apache::lonxml::error(" Unable to find $file");
@@ -214,17 +251,13 @@ sub renderpage {
#$request->print("Result follows:");
if ($target eq 'modified') {
- my $fileout = &Apache::lonnet::filelocation("",$request->uri);
- my $filesave=$fileout.".bak";
-
- my $fs=Apache::File->new(">$filesave");
- print $fs $problem;
- $request->print("Making Backup to $filesave
");
-
- my $fh=Apache::File->new(">$fileout");
- print $fh $result;
- $request->print("Saving Modifications to $fileout
");
+ &handle_save_or_undo($request,\$problem,\$result);
} else {
+ #my $td=&tv_interval($t0);
+ #if ( $Apache::lonxml::debug) {
+ #$result =~ s: