--- loncom/homework/lonhomework.pm 2001/02/13 18:42:06 1.37
+++ loncom/homework/lonhomework.pm 2002/11/12 05:05:26 1.101
@@ -1,38 +1,109 @@
+# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
+#
+# $Id: lonhomework.pm,v 1.101 2002/11/12 05:05:26 albertel Exp $
+#
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
# Guy Albertelli
# 11/30 Gerd Kortemeyer
-# 6/1 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::inputtags;
-use Apache::structuretags;
-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 {
+ &Apache::lonxml::register_insert();
+}
sub get_target {
if ( $ENV{'request.state'} eq "published") {
- if ( defined $ENV{'form.submitted'}) {
+ 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.preview'}) {
- if ( defined $ENV{'form.submitted'}) {
+ if ( defined($ENV{'form.grade_target'}) ) {
+ return ($ENV{'form.grade_target'});
+ }
+ if ( defined($ENV{'form.preview'})) {
+ if ( defined($ENV{'form.submitted'})) {
return ('grade', 'web');
} else {
return ('web');
}
} else {
- #return ('edit');
- #edit is currently broken
- return ('web');
+ 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');
+ } else {
+ return ('web','answer');
+ }
+ } elsif ( $ENV{'form.problemmode'} eq 'Edit' ) {
+ if ( $ENV{'form.submitted'} eq 'edit' ) {
+ if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) {
+ return ('modified','web','answer');
+ } else {
+ return ('modified','edit');
+ }
+ } else {
+ return ('edit');
+ }
+ } else {
+ return ('web');
+ }
}
}
return ();
@@ -47,7 +118,6 @@ sub setup_vars {
sub send_header {
my ($request)= @_;
$request->print(&Apache::lontexconvert::header());
- $ENV{'request.uri'}=$request->uri;
# $request->print('
';
+ $request->print($result);
+ $request->rflush();
+}
+
+sub analyze {
+ my ($request,$file) = @_;
+ &Apache::lonxml::debug("Analyze");
+ my $result;
+ my %overall;
+ my %allparts;
+ my $rndseed=$ENV{'form.rndseed'};
+ srand($rndseed);
+ &analyze_header($request);
+ for(my $i;$i<$ENV{'form.numtoanalyze'};$i++) {
+ my $subresult=&Apache::lonnet::ssi($request->uri,
+ ('grade_target' => 'analyze'),
+ ('rndseed' => rand));
+ #&Apache::lonxml::debug(":$subresult:");
+ (my $garbage,$subresult)=split(/_HASH_REF__/,$subresult,2);
+ my %analyze=&Apache::lonnet::str2hash($subresult);
+ &Apache::lonhomework::showhash(%analyze);
+ my @parts = @{ $analyze{'parts'} };
+ foreach my $part (@parts) {
+ if (!exists($allparts{$part})) {$allparts{$part}=1;};
+ if ($analyze{$part.'.type'} eq 'numericalresponse') {
+ push( @{ $overall{$part.'.answer'} },
+ [@{ $analyze{$part.'.answer'} }]);
+ }
+ }
}
+ foreach my $part (keys(%allparts)) {
+ $request->print('