--- loncom/homework/lonhomework.pm 2001/06/12 22:42:55 1.46
+++ loncom/homework/lonhomework.pm 2001/09/14 20:14:12 1.60
@@ -1,7 +1,7 @@
# The LON-CAPA Homework handler
# Guy Albertelli
# 11/30 Gerd Kortemeyer
-# 6/1 Gerd Kortemeyer
+# 6/1,8/17,8/18 Gerd Kortemeyer
package Apache::lonhomework;
use strict;
@@ -10,11 +10,12 @@ use Apache::lonxml;
use Apache::lonnet;
use Apache::inputtags;
use Apache::structuretags;
+use Apache::randomlabel;
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();
@@ -37,9 +38,9 @@ sub get_target {
} else {
if ( $ENV{'form.problemmode'} eq 'View' ) {
if ( defined $ENV{'form.submitted'}) {
- return ('grade', 'web');
+ return ('grade', 'web','answer');
} else {
- return ('web');
+ return ('web','answer');
}
} elsif ( $ENV{'form.problemmode'} eq 'Edit' ) {
if ( $ENV{'form.submitted'} eq 'edit' ) {
@@ -84,7 +85,8 @@ sub send_footer {
}
$Apache::lonxml::browse='';
-sub check_date {
+
+sub check_access {
my ($id) = @_;
my $date ='';
my $status = '';
@@ -130,6 +132,13 @@ sub check_date {
if ( $maxtries eq '' ) { $maxtries = '2'; }
if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
}
+
+ if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
+ (!$Apache::lonhomework::history{"resource.0.outtoken"})) {
+ 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 +181,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");
@@ -187,15 +226,9 @@ sub renderpage {
my $result = '';
&Apache::inputtags::initialize_inputtags;
&Apache::edit::initialize_edit;
- %Apache::lonhomework::results=();
- %Apache::lonhomework::history=&Apache::lonnet::restore();
- #ignore error conditions
- my ($temp)=keys %Apache::lonhomework::history ;
- if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
if ($target eq 'web') {
if (&Apache::lonnet::symbread() eq '') {
if ($ENV{'request.state'} eq "construct") {
- $request->print("In construction space, submissions ignored
");
} else {
$request->print("Browsing or ambiguous reference, submissions ignored
");
}
@@ -214,37 +247,27 @@ 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: