--- loncom/homework/lonhomework.pm 2002/01/17 12:23:31 1.69
+++ loncom/homework/lonhomework.pm 2002/03/29 18:32:46 1.74
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
#
-# $Id: lonhomework.pm,v 1.69 2002/01/17 12:23:31 harris41 Exp $
+# $Id: lonhomework.pm,v 1.74 2002/03/29 18:32:46 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,17 +31,18 @@
package Apache::lonhomework;
use strict;
-use Apache::style;
-use Apache::lonxml;
-use Apache::lonnet;
-use Apache::lonplot;
-use Apache::inputtags;
-use Apache::structuretags;
-use Apache::randomlabel;
-use Apache::response;
-use Apache::hint;
-use Apache::outputtags;
+use Apache::style();
+use Apache::lonxml();
+use Apache::lonnet();
+use Apache::lonplot();
+use Apache::inputtags();
+use Apache::structuretags();
+use Apache::randomlabel();
+use Apache::response();
+use Apache::hint();
+use Apache::outputtags();
use Apache::Constants qw(:common);
+use HTML::Entities();
#use Time::HiRes qw( gettimeofday tv_interval );
BEGIN {
@@ -60,6 +61,9 @@ sub get_target {
return ('web');
}
} elsif ($ENV{'request.state'} eq "construct") {
+ if ( defined($ENV{'form.grade_target'}) ) {
+ return ($ENV{'form.grade_target'});
+ }
if ( defined($ENV{'form.preview'})) {
if ( defined($ENV{'form.submitted'})) {
return ('grade', 'web');
@@ -128,6 +132,7 @@ sub check_access {
my $type;
my $passed;
&Apache::lonxml::debug("checking for part :$id:");
+ &Apache::lonxml::debug("time:".time);
foreach $temp ("opendate","duedate","answerdate") {
$lastdate = $date;
$date = &Apache::lonnet::EXT("resource.$id.$temp");
@@ -189,7 +194,20 @@ sub showhash {
my (%hash) = @_;
my $resultkey;
foreach $resultkey (sort keys %hash) {
- &Apache::lonxml::debug("$resultkey ---- $hash{$resultkey}");
+ if (ref($hash{$resultkey})) {
+ if ($hash{$resultkey} =~ /ARRAY/ ) {
+ my $string="$resultkey ---- (";
+ foreach my $elm (@{ $hash{$resultkey} }) {
+ $string.="$elm,";
+ }
+ chop($string);
+ &Apache::lonxml::debug("$string)");
+ } else {
+ &Apache::lonxml::debug("$resultkey ---- $hash{$resultkey}");
+ }
+ } else {
+ &Apache::lonxml::debug("$resultkey ---- $hash{$resultkey}");
+ }
}
&Apache::lonxml::debug("\n
restored values^\n");
return '';
@@ -218,38 +236,53 @@ sub setupheader {
sub handle_save_or_undo {
my ($request,$problem,$result) = @_;
- my $fileout = &Apache::lonnet::filelocation("",$request->uri);
- my $filesave=$fileout.".bak";
+ my $file = &Apache::lonnet::filelocation("",$request->uri);
+ my $filebak =$file.".bak";
+ my $filetmp =$file.".tmp";
my $error=0;
if ($ENV{'form.Undo'} eq 'undo') {
- if (copy($filesave,$fileout)) {
- $request->print("Undid changes, Copied $filesave to $fileout
");
+ my $error=0;
+ if (!copy($file,$filetmp)) { $error=1; }
+ if ((!$error) && (!copy($filebak,$file))) { $error=1; }
+ if ((!$error) && (!move($filetmp,$filebak))) { $error=1; }
+ if (!$error) {
+ $request->print("
Undid changes, Switched $filebak and $file
"); } else { - $request->print("Unable to undo, unable to copy $filesave to $fileoutUnable to undo, unable to switch $filebak and $file
"); $error=1; } } else { - my $fs=Apache::File->new(">$filesave"); + my $fs=Apache::File->new(">$filebak"); if (defined($fs)) { print $fs $$problem; - $request->print("Making Backup to $filesave