--- loncom/homework/lonhomework.pm 2002/02/27 20:23:26 1.71
+++ loncom/homework/lonhomework.pm 2002/09/24 12:39:42 1.90
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
#
-# $Id: lonhomework.pm,v 1.71 2002/02/27 20:23:26 albertel Exp $
+# $Id: lonhomework.pm,v 1.90 2002/09/24 12:39:42 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -28,20 +28,29 @@
# Guy Albertelli
# 11/30 Gerd Kortemeyer
# 6/1,8/17,8/18 Gerd Kortemeyer
+# 7/18 Jeremy Bowers
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::caparesponse();
+use Apache::radiobuttonresponse();
+use Apache::optionresponse();
+use Apache::imageresponse();
+use Apache::essayresponse();
+use Apache::externalresponse();
use Apache::Constants qw(:common);
+use HTML::Entities();
+use Apache::loncommon();
#use Time::HiRes qw( gettimeofday tv_interval );
BEGIN {
@@ -50,16 +59,23 @@ BEGIN {
sub get_target {
if ( $ENV{'request.state'} eq "published") {
- if ( defined($ENV{'form.grade_target'})
+ if ( defined($ENV{'form.grade_target'} )
+ && ($ENV{'form.grade_target'} eq 'tex')) {
+ return ($ENV{'form.grade_target'});
+ } elsif ( defined($ENV{'form.grade_target'} )
&& ($Apache::lonhomework::viewgrades == 'F' )) {
return ($ENV{'form.grade_target'});
}
+
if ( defined($ENV{'form.submitted'})) {
return ('grade', 'web');
} else {
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');
@@ -67,7 +83,8 @@ sub get_target {
return ('web');
}
} else {
- if ( $ENV{'form.problemmode'} eq 'View' ) {
+ if ( $ENV{'form.problemmode'} eq 'View' ||
+ $ENV{'form.problemmode'} eq 'Discard Edits and View') {
if ( defined($ENV{'form.submitted'}) &&
(!defined($ENV{'form.resetdata'})) ) {
return ('grade', 'web','answer');
@@ -76,7 +93,11 @@ sub get_target {
}
} elsif ( $ENV{'form.problemmode'} eq 'Edit' ) {
if ( $ENV{'form.submitted'} eq 'edit' ) {
- return ('modified','edit');
+ if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) {
+ return ('modified','web','answer');
+ } else {
+ return ('modified','edit');
+ }
} else {
return ('edit');
}
@@ -104,7 +125,7 @@ sub createmenu {
my ($which,$request)=@_;
if ($which eq 'grade') {
$request->print('');
}
@@ -128,9 +149,19 @@ 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");
+ my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type");
+ if ($thistype eq 'date_interval') {
+ if ($temp eq 'opendate') {
+ $date=&Apache::lonnet::EXT("resource.$id.duedate")-$date;
+ }
+ if ($temp eq 'answerdate') {
+ $date=&Apache::lonnet::EXT("resource.$id.duedate")+$date;
+ }
+ }
&Apache::lonxml::debug("found :$date: for :$temp:");
if ($date eq '') {
$date = "an unknown date"; $passed = 0;
@@ -173,7 +204,7 @@ sub check_access {
&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");
+ &Apache::lonxml::debug("should be allowed to browse a resource when closed");
$status='CAN_ANSWER';
$datemsg='is closed but you are allowed to view it';
}
@@ -187,9 +218,30 @@ sub check_access {
sub showhash {
my (%hash) = @_;
+ &showhashsubset(\%hash,'');
+ return '';
+}
+
+sub showhashsubset {
+ my ($hash,$keyre) = @_;
my $resultkey;
- foreach $resultkey (sort keys %hash) {
- &Apache::lonxml::debug("$resultkey ---- $hash{$resultkey}");
+ foreach $resultkey (sort keys %$hash) {
+ if ($resultkey =~ /$keyre/) {
+ 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 '';
@@ -255,6 +307,16 @@ sub handle_save_or_undo {
return $error;
}
+sub analyze {
+ my ($request,$file) = @_;
+ &Apache::lonxml::debug("Analyze");
+ my $result=&Apache::lonnet::ssi($request->uri,('grade_target' => 'analyze'));
+ &Apache::lonxml::debug(":$result:");
+ (my $garbage,$result)=split(/_HASH_REF__/,$result,2);
+ &showhash(&Apache::lonnet::str2hash($result));
+ return $result;
+}
+
sub editxmlmode {
my ($request,$file) = @_;
my $result;
@@ -268,22 +330,34 @@ sub editxmlmode {
\$ENV{'form.editxmltext'});
if (!$error) { $problem=&Apache::lonnet::getfile($file); }
}
- my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem);
- if ($cols > 80) { $cols = 80; }
- $result.='