--- loncom/homework/lonhomework.pm 2001/06/12 22:42:55 1.46
+++ loncom/homework/lonhomework.pm 2001/07/18 18:45:37 1.49
@@ -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();
@@ -172,11 +172,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 +244,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: