--- loncom/homework/grades.pm 2007/11/13 01:14:32 1.488
+++ loncom/homework/grades.pm 2011/10/09 16:23:34 1.656
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.488 2007/11/13 01:14:32 albertel Exp $
+# $Id: grades.pm,v 1.656 2011/10/09 16:23:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,6 +26,8 @@
# http://www.lon-capa.org/
#
+
+
package Apache::grades;
use strict;
use Apache::style;
@@ -38,105 +40,77 @@ use Apache::lonhomework;
use Apache::lonpickcode;
use Apache::loncoursedata;
use Apache::lonmsg();
-use Apache::Constants qw(:common);
+use Apache::Constants qw(:common :http);
use Apache::lonlocal;
use Apache::lonenc;
+use Apache::lonstathelpers;
+use Apache::lonquickgrades;
use String::Similarity;
use LONCAPA;
use POSIX qw(floor);
+
my %perm=();
-my %bubble_lines_per_response = (); # no. bubble lines for each response.
- # index is "symb.part_id"
-my %first_bubble_line = (); # First bubble line no. for each bubble.
+# These variables are used to recover from ssi errors
-# Save and restore the bubble lines array to the form env.
+my $ssi_retries = 5;
+my $ssi_error;
+my $ssi_error_resource;
+my $ssi_error_message;
-sub save_bubble_lines {
- foreach my $line (keys(%bubble_lines_per_response)) {
- $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
- $env{"form.scantron.first_bubble_line.$line"} =
- $first_bubble_line{$line};
+sub ssi_with_retries {
+ my ($resource, $retries, %form) = @_;
+ my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
+ if ($response->is_error) {
+ $ssi_error = 1;
+ $ssi_error_resource = $resource;
+ $ssi_error_message = $response->code . " " . $response->message;
}
-}
-
-sub restore_bubble_lines {
- my $line = 0;
- %bubble_lines_per_response = ();
- while ($env{"form.scantron.bubblelines.$line"}) {
- my $value = $env{"form.scantron.bubblelines.$line"};
- $bubble_lines_per_response{$line} = $value;
- $first_bubble_line{$line} =
- $env{"form.scantron.first_bubble_line.$line"};
- $line++;
- }
+ return $content;
}
+#
+# Prodcuces an ssi retry failure error message to the user:
+#
-# Given the parsed scanline, get the response for
-# 'answer' number n:
-
-sub get_response_bubbles {
- my ($parsed_line, $response) = @_;
-
-
- my $bubble_line = $first_bubble_line{$response-1} +1;
- my $bubble_lines= $bubble_lines_per_response{$response-1};
-
- my $selected = "";
-
- for (my $bline = 0; $bline < $bubble_lines; $bline++) {
- $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":";
- $bubble_line++;
- }
- return $selected;
-}
-
-
-# ----- These first few routines are general use routines.----
-
-# Return the number of occurences of a pattern in a string.
-
-sub occurence_count {
- my ($string, $pattern) = @_;
-
- my @matches = ($string =~ /$pattern/g);
-
- return scalar(@matches);
-}
-
-
-# Take a string known to have digits and convert all the
-# digits into letters in the range J,A..I.
-
-sub digits_to_letters {
- my ($input) = @_;
-
- my @alphabet = ('J', 'A'..'I');
-
- my @input = split(//, $input);
- my $output ='';
- for (my $i = 0; $i < scalar(@input); $i++) {
- if ($input[$i] =~ /\d/) {
- $output .= $alphabet[$input[$i]];
- } else {
- $output .= $input[$i];
- }
- }
- return $output;
+sub ssi_print_error {
+ my ($r) = @_;
+ my $helpurl = &Apache::loncommon::top_nav_help('Helpdesk');
+ $r->print('
+
+
+'.&mt('Unable to retrieve a resource from a server:').'
+'.&mt('Resource:').' '.$ssi_error_resource.'
+'.&mt('Error:').' '.$ssi_error_message.'
+
'.
+&mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').'
'.
+&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
+'
"; - } else { - $result.=" | "; - } - $partsseen{$partID}=1; - } - my $display_part=&get_display_part($partID,$symb); - $result.=' | '.&mt('Part: [_1]',$display_part).' '. - $resID.' | '. - ''.&mt('Type: [_1]',$responsetype).' | '.&mt('Handgrade: [_1]',$handgrade).' | '; - } - } - $result.='
'; + $bottomrow.''.''; } elsif ($response eq 'essay') { if (! exists ($env{'form.'.$symb})) { my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade', @@ -439,8 +445,7 @@ sub cleanRecord { #-- A couple of common js functions sub commonJSfunctions { my $request = shift; - $request->print(<'. '
'. ' '.&mt('Answer').' '.$toprow.''.' '.$grayFont.&mt('Option ID').' '. - $grayFont.$bottomrow.'
' + .&mt('No match found for the above receipt number.') + .'
'; } else { $string = &jscriptNform($symb).$title. ''. - &mt('The above receipt matches the following [numerate,_1,student].',$matches). + &mt('The above receipt number matches the following [quant,_1,student].',$matches). '
'. $header. $contents. &Apache::loncommon::end_data_table()."\n"; } - return $string.&show_grading_menu_form($symb); + return $string; } #--- This is called by a number of programs. @@ -807,32 +827,25 @@ sub verifyreceipt { #--- Also called directly when one clicks on the subm button # on the problem page. sub listStudents { - my ($request) = shift; + my ($request,$symb,$submitonly) = @_; - my ($symb) = &get_symb($request); my $cdom = $env{"course.$env{'request.course.id'}.domain"}; my $cnum = $env{"course.$env{'request.course.id'}.num"}; my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'}; my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'}; - my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'}; - my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View'; - $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ? - &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'}; - - my $result='");
- pDoc.write("
|