--- loncom/homework/lonhomework.pm 2002/01/30 17:39:13 1.70
+++ loncom/homework/lonhomework.pm 2003/05/09 22:24:05 1.123
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
#
-# $Id: lonhomework.pm,v 1.70 2002/01/30 17:39:13 albertel Exp $
+# $Id: lonhomework.pm,v 1.123 2003/05/09 22:24:05 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -28,20 +28,32 @@
# 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::rankresponse();
+use Apache::matchresponse();
+#use Apache::chemresponse();
use Apache::Constants qw(:common);
+use HTML::Entities();
+use Apache::loncommon();
#use Time::HiRes qw( gettimeofday tv_interval );
BEGIN {
@@ -50,16 +62,24 @@ BEGIN {
sub get_target {
if ( $ENV{'request.state'} eq "published") {
- if ( defined($ENV{'form.grade_target'})
- && ($Apache::lonhomework::viewgrades == 'F' )) {
+ 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 eq 'F' )) {
return ($ENV{'form.grade_target'});
}
- if ( defined($ENV{'form.submitted'})) {
+
+ if ( defined($ENV{'form.submitted'}) &&
+ ( !defined($ENV{'form.resetdata'}))) {
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 +87,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 +97,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');
}
@@ -118,19 +143,45 @@ sub send_footer {
$Apache::lonxml::browse='';
+# JB, 9/24/2002: Any changes in this function may require a change
+# in lonnavmaps::resource::getDateStatus.
sub check_access {
my ($id) = @_;
my $date ='';
- my $status = '';
+ my $status;
my $datemsg = '';
my $lastdate = '';
my $temp;
my $type;
my $passed;
+
+ if ($ENV{'request.state'} eq "construct") {
+ &Apache::lonxml::debug("in construction ignoring dates");
+ $status='CAN_ANSWER';
+ $datemsg='is in under construction';
+ return ($status,$datemsg);
+ }
+
&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 =~ /^(con_lost|no_such_host)/ ||
+ $date =~ /^(con_lost|no_such_host)/) {
+ $status='UNAVAILABLE';
+ $date="may open later.";
+ return($status,$date);
+ }
+ 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;
@@ -157,12 +208,16 @@ sub check_access {
$datemsg = "was due on $lastdate, and answers will be available on $date";
}
if ($status eq 'CAN_ANSWER') {
- #check #tries
+ #check #tries, and if correct.
my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
if ( $tries eq '' ) { $tries = '0'; }
if ( $maxtries eq '' ) { $maxtries = '2'; }
if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; }
+ if($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/
+ && lc($Apache::lonhomework::problemstatus) ne 'no') {
+ $status = 'CANNOT_ANSWER';
+ }
}
if (($status ne 'CLOSED') && ($Apache::lonhomework::type eq 'exam') &&
@@ -177,19 +232,52 @@ sub check_access {
$status='CAN_ANSWER';
$datemsg='is closed but you are allowed to view it';
}
- if ($ENV{'request.state'} eq "construct") {
- &Apache::lonxml::debug("in construction ignoring dates");
- $status='CAN_ANSWER';
- $datemsg='is in under construction';
- }
+
return ($status,$datemsg);
}
sub showhash {
my (%hash) = @_;
+ &showhashsubset(\%hash,'.');
+ return '';
+}
+
+sub showarray {
+ my ($array)=@_;
+ my $string="(";
+ foreach my $elm (@{ $array }) {
+ if (ref($elm)) {
+ if ($elm =~ /ARRAY/ ) {
+ $string.=&showarray($elm);
+ }
+ } else {
+ $string.="$elm,"
+ }
+ }
+ chop($string);
+ $string.=")";
+ return $string;
+}
+
+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/ ) {
+ &Apache::lonxml::debug("$resultkey ---- ".
+ &showarray($$hash{$resultkey}));
+ } elsif ($$hash{$resultkey} =~ /HASH/ ) {
+ &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
+ &showhashsubset($$hash{$resultkey},'.');
+ } else {
+ &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
+ }
+ } else {
+ &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}");
+ }
+ }
}
&Apache::lonxml::debug("\n
restored values^\n");
return '';
@@ -202,18 +290,19 @@ sub setuppermissions {
}
sub setupheader {
- my $request=$_[0];
- if ($ENV{'browser.mathml'}) {
- $request->content_type('text/xml');
- } else {
- $request->content_type('text/html');
- }
- if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
- &Apache::loncommon::no_cache($request);
- }
- $request->send_http_header;
- return OK if $request->header_only;
- return ''
+ my $request=$_[0];
+ if ($ENV{'browser.mathml'}) {
+ $request->content_type('text/xml');
+ } else {
+ $request->content_type('text/html');
+ }
+ $request->content_encoding('UTF-8');
+ if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) {
+ &Apache::loncommon::no_cache($request);
+ }
+ $request->send_http_header;
+ return OK if $request->header_only;
+ return ''
}
sub handle_save_or_undo {
@@ -255,11 +344,92 @@ sub handle_save_or_undo {
return $error;
}
+sub analyze_header {
+ my ($request) = @_;
+ my $result.='
+
Part '.$part.' | |
'.join(' | ',@{ $answer }). + ' |
Part '.$part. + ' is not analyzabale at this time
'); + } + } + &Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); + &analyze_footer($request); + &Apache::lonhomework::showhash(%overall); + return $result; +} + sub editxmlmode { my ($request,$file) = @_; my $result; my $problem=&Apache::lonnet::getfile($file); - if ($problem == -1) { + if ($problem eq -1) { &Apache::lonxml::error(" Unable to find $file"); $problem=''; } @@ -268,22 +438,42 @@ 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.=' + &Apache::lonhomework::showhashsubset(\%ENV,'^form'); + if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) { + &Apache::lonhomework::showhashsubset(\%ENV,'^form'); + $ENV{'form.problemmode'}='View'; + &renderpage($request,$file); + } else { + my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem); + my $xml_help = ''. + &Apache::loncommon::help_open_topic("Problem_Editor_XML_Index",'Problem Editing Help') + .' | '. + &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols', + undef,undef,600) + .' | '. + &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols', + undef,undef,600) + .' |