[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /homework grades.pm
raeburn
raeburn@source.lon-capa.org
Wed, 27 Jan 2010 05:12:15 -0000
This is a MIME encoded message
--raeburn1264569135
Content-Type: text/plain
raeburn Wed Jan 27 05:12:15 2010 EDT
Modified files: (Branch: version_2_9_X)
/loncom/homework grades.pm
Log:
- Backport 1.582, 1.583.
--raeburn1264569135
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100127051215.txt"
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.574.2.6 loncom/homework/grades.pm:1.574.2.7
--- loncom/homework/grades.pm:1.574.2.6 Sun Dec 27 02:05:40 2009
+++ loncom/homework/grades.pm Wed Jan 27 05:12:15 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.574.2.6 2009/12/27 02:05:40 raeburn Exp $
+# $Id: grades.pm,v 1.574.2.7 2010/01/27 05:12:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -97,9 +97,15 @@
#
# --- Retrieve the parts from the metadata file.---
sub getpartlist {
- my ($symb) = @_;
+ my ($symb,$errorref) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($errorref)) {
+ $$errorref = 'navmap';
+ return;
+ }
+ }
my $res = $navmap->getBySymb($symb);
my $partlist = $res->parts();
my $url = $res->src();
@@ -144,9 +150,15 @@
#--- Get the partlist and the response type for a given problem. ---
#--- Indicate if a response type is coded handgraded or not. ---
sub response_type {
- my ($symb) = shift;
+ my ($symb,$response_error) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($response_error)) {
+ $$response_error = 1;
+ }
+ return;
+ }
my $res = $navmap->getBySymb($symb);
my $partlist = $res->parts();
my %vPart =
@@ -193,12 +205,17 @@
#--- Show resource title
#--- and parts and response type
sub showResourceInfo {
- my ($symb,$probTitle,$checkboxes) = @_;
+ my ($symb,$probTitle,$checkboxes,$res_error) = @_;
my $col=3;
if ($checkboxes) { $col=4; }
my $result = '<h3>'.&mt('Current Resource').': '.$probTitle.'</h3>'."\n";
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
+ if (ref($res_error)) {
+ if ($$res_error) {
+ return;
+ }
+ }
$result .='<table border="0">';
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
my %resptype = ();
my $hdgrade='no';
my %partsseen;
@@ -766,7 +783,13 @@
if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
$env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
my $parts=['0'];
- if ($receiptparts) { ($parts)=&response_type($symb); }
+ if ($receiptparts) {
+ my $res_error;
+ ($parts)=&response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
+ }
my $header =
&Apache::loncommon::start_data_table().
@@ -1744,15 +1767,19 @@
$$record{'resource.'.$partid.'.tries'}.'" />'."\n".
'<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
$aggtries.'" />'."\n";
- $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
+ my $res_error;
+ $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
return $result;
}
sub handback_box {
- my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my ($symb,$uname,$udom,$counter,$partid,$record,$res_error) = @_;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
my (@respids);
- my @part_response_id = &flatten_responseType($responseType);
+ my @part_response_id = &flatten_responseType($responseType);
foreach my $part_response_id (@part_response_id) {
my ($part,$resp) = @{ $part_response_id };
if ($part eq $partid) {
@@ -2045,7 +2072,12 @@
}
my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
# Display student info
$request->print(($counter == 0 ? '' : '<br />'));
@@ -2592,7 +2624,12 @@
}
$ctr = 0;
@parsedlist = reverse @parsedlist if ($button eq 'Previous');
- my ($partlist) = &response_type($symb);
+ my $res_error;
+ my ($partlist) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
foreach my $student (@parsedlist) {
my $submitonly=$env{'form.submitonly'};
my ($uname,$udom) = split(/:/,$student);
@@ -2790,8 +2827,12 @@
sub handback_files {
my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
my $portfolio_root = '/userfiles/portfolio';
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
-
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print('<br />'.&navmap_errormsg().'<br />');
+ return;
+ }
my @part_response_id = &flatten_responseType($responseType);
foreach my $part_response_id (@part_response_id) {
my ($part_id,$resp_id) = @{ $part_response_id };
@@ -3249,7 +3290,11 @@
$result.= '<h3>'.$common_header.'</h3>'.&Apache::loncommon::start_data_table();
#radio buttons/text box for assigning points for a section or class.
#handles different parts of a problem
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
my %weight = ();
my $ctsparts = 0;
my %seen = ();
@@ -3309,7 +3354,11 @@
&Apache::loncommon::start_data_table_header_row().
'<th>'.&mt('No.').'</th>'.
'<th>'.&nameUserString('header')."</th>\n";
- my (@parts) = sort(&getpartlist($symb));
+ my $partserror;
+ my (@parts) = sort(&getpartlist($symb,\$partserror));
+ if ($partserror) {
+ return &navmap_errormsg();
+ }
my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
my @partids = ();
foreach my $part (@parts) {
@@ -3468,7 +3517,11 @@
my %columns = ();
my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
- my (@parts) = sort(&getpartlist($symb));
+ my $partserror;
+ my (@parts) = sort(&getpartlist($symb,\$partserror));
+ if ($partserror) {
+ return &navmap_errormsg();
+ }
my $header;
while ($ctr < $env{'form.totalparts'}) {
my $partid = $env{'form.partid_'.$ctr};
@@ -3801,7 +3854,14 @@
sub csvupload_fields {
my ($symb) = @_;
- my (@parts) = &getpartlist($symb);
+ my ($symb,$errorref) = @_;
+ my (@parts) = &getpartlist($symb,$errorref);
+ if (ref($errorref)) {
+ if ($$errorref) {
+ return;
+ }
+ }
+
my @fields=(['ID','Student/Employee ID'],
['username','Student Username'],
['domain','Student Domain']);
@@ -3901,8 +3961,12 @@
&csvuploadmap_header($request,$symb,$datatoken,$#records+1);
my ($i,$keyfields);
if (@records) {
- my @fields=&csvupload_fields($symb);
-
+ my $fieldserror;
+ my @fields=&csvupload_fields($symb,\$fieldserror);
+ if ($fieldserror) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($request,\@records);
$i=&Apache::loncommon::csv_print_select_table($request,\@records,
@@ -4138,7 +4202,12 @@
&mt('Manual Grading by Page or Sequence').'</span></h3>';
$result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
- my ($titles,$symbx) = &getSymbMap();
+ my $map_error;
+ my ($titles,$symbx) = &getSymbMap($map_error);
+ if ($map_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
my ($curpage) =&Apache::lonnet::decode_symb($symb);
# my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
# my $type=($curpage =~ /\.(page|sequence)/);
@@ -4233,8 +4302,14 @@
}
sub getSymbMap {
+ my ($map_error) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
-
+ unless (ref($navmap)) {
+ if (ref($map_error)) {
+ $$map_error = 'navmap';
+ }
+ return;
+ }
my %symbx = ();
my @titles = ();
my $minder = 0;
@@ -4293,6 +4368,11 @@
$request->print($result);
my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ $request->print(&navmap_errormsg());
+ $request->print(&show_grading_menu_form($symb));
+ return;
+ }
my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
if (!$map) {
@@ -4544,6 +4624,10 @@
$request->print($result);
my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
if (!$map) {
@@ -4747,7 +4831,9 @@
Returns html hidden inputs used to hold context/default values.
Arguments:
- $symb - $symb of the current resource
+ $symb - $symb of the current resource
+ $map_error - ref to scalar which will container error if
+ $navmap object is unavailable in &getSymbMap().
=cut
@@ -4771,9 +4857,12 @@
=cut
sub getSequenceDropDown {
- my ($symb)=@_;
+ my ($symb,$map_error)=@_;
my $result='<select name="selectpage">'."\n";
- my ($titles,$symbx) = &getSymbMap();
+ my ($titles,$symbx) = &getSymbMap($map_error);
+ if (ref($map_error)) {
+ return if ($$map_error);
+ }
my ($curpage)=&Apache::lonnet::decode_symb($symb);
my $ctr=0;
foreach (@$titles) {
@@ -5039,7 +5128,12 @@
my ($r,$file2grade) = @_;
my ($symb)=&get_symb($r);
if (!$symb) {return '';}
- my $sequence_selector=&getSequenceDropDown($symb);
+ my $map_error;
+ my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
+ if ($map_error) {
+ $r->print('<br />'.&navmap_errormsg().'<br />');
+ return;
+ }
my $default_form_data=&defaultFormData($symb);
my $grading_menu_button=&show_grading_menu_form($symb);
my $file_selector=&scantron_uploads($file2grade);
@@ -6213,7 +6307,12 @@
$r->print('<p>'.&mt('Gathering necessary information.').'</p>');$r->rflush();
#get the student pick code ready
$r->print(&Apache::loncommon::studentbrowser_javascript());
- my $max_bubble=&scantron_get_maxbubble();
+ my $nav_error;
+ my $max_bubble=&scantron_get_maxbubble(\$nav_error);
+ if ($nav_error) {
+ $r->print(&navmap_errormsg());
+ return '';
+ }
my $result=&scantron_form_start($max_bubble).$default_form_data;
$r->print($result);
@@ -6625,6 +6724,10 @@
my ($r,$currentphase) = @_;
my $navmap=Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ $r->print(&navmap_errormsg());
+ return (1,$currentphase);
+ }
my (undef,undef,$sequence)=
&Apache::lonnet::decode_symb($env{'form.selectpage'});
@@ -6657,7 +6760,12 @@
my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
my ($scanlines,$scan_data)=&scantron_getfile();
- &scantron_get_maxbubble(); # parse needs the bubble_lines.. array.
+ my $nav_error;
+ &scantron_get_maxbubble(\$nav_error); # parse needs the bubble_lines.. array.
+ if ($nav_error) {
+ $r->print(&navmap_errormsg());
+ return(1,$currentphase);
+ }
my %found=('ids'=>{},'usernames'=>{});
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
@@ -7210,7 +7318,12 @@
my %allcodes=&get_codes();
- &scantron_get_maxbubble(); # parse needs the lines per response array.
+ my $nav_error;
+ &scantron_get_maxbubble(\$nav_error); # parse needs the lines per response array.
+ if ($nav_error) {
+ $r->print(&navmap_errormsg());
+ return(1,$currentphase);
+ }
my ($scanlines,$scan_data)=&scantron_getfile();
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
@@ -7264,7 +7377,12 @@
#get scantron line setup
my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
my ($scanlines,$scan_data)=&scantron_getfile();
- &scantron_get_maxbubble(); # parse needs the bubble line array.
+ my $nav_error;
+ &scantron_get_maxbubble(\$nav_error); # parse needs the bubble line array.
+ if ($nav_error) {
+ $r->print(&navmap_errormsg());
+ return(1,$currentphase);
+ }
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
my $line=&scantron_get_line($scanlines,$scan_data,$i);
@@ -7282,6 +7400,8 @@
sub scantron_get_maxbubble {
+ my ($nav_error) = @_;
+
if (defined($env{'form.scantron_maxbubble'}) &&
$env{'form.scantron_maxbubble'}) {
&restore_bubble_lines();
@@ -7292,6 +7412,11 @@
&Apache::lonnet::decode_symb($env{'form.selectpage'});
my $navmap=Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($nav_error)) {
+ $$nav_error = 1;
+ }
+ }
my $map=$navmap->getResourceByUrl($sequence);
my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
@@ -7381,7 +7506,11 @@
#get scantron line setup
my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
my ($scanlines,$scan_data)=&scantron_getfile();
- my $max_bubble=&scantron_get_maxbubble();
+ my $nav_error;
+ my $max_bubble=&scantron_get_maxbubble(\$nav_error);
+ if ($nav_error) {
+ return(1,$currentphase);
+ }
if (!$max_bubble) { $max_bubble=2**31; }
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
my $line=&scantron_get_line($scanlines,$scan_data,$i);
@@ -7441,6 +7570,10 @@
my $classlist=&Apache::loncoursedata::get_classlist();
my %idmap=&username_to_idmap($classlist);
my $navmap=Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ $r->print(&navmap_errormsg());
+ return '';
+ }
my $map=$navmap->getResourceByUrl($sequence);
my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
my (%grader_partids_by_symb,%grader_randomlists_by_symb);
@@ -7483,7 +7616,12 @@
my $i=-1;
my $started;
- &scantron_get_maxbubble(); # Need the bubble lines array to parse.
+ my $nav_error;
+ &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
+ if ($nav_error) {
+ $r->print(&navmap_errormsg());
+ return '';
+ }
# If an ssi failed in scantron_get_maxbubble, put an error message out to
# the user and return.
@@ -7967,6 +8105,10 @@
my $classlist=&Apache::loncoursedata::get_classlist();
my %idmap=&Apache::grades::username_to_idmap($classlist);
my $navmap=Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ $r->print(&navmap_errormsg());
+ return '';
+ }
my $map=$navmap->getResourceByUrl($sequence);
my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
my (%grader_partids_by_symb,%grader_randomlists_by_symb);
@@ -7985,8 +8127,12 @@
'Progress of Bubblesheet Data/Submission Records Comparison',$count,
'inline',undef,'checkscantron');
my ($username,$domain,$started);
-
- &scantron_get_maxbubble(); # Need the bubble lines array to parse.
+ my $nav_error;
+ &scantron_get_maxbubble(\$nav_error); # Need the bubble lines array to parse.
+ if ($nav_error) {
+ $r->print(&navmap_errormsg());
+ return '';
+ }
&Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
'Processing first student');
@@ -8986,7 +9132,11 @@
my ($symb)=&get_symb($r);
if (!$symb) {return '';}
# See which part we are saving to
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
# FIXME: This should probably look for the first handgradeable part
my $part=$$partlist[0];
# Start screen output
@@ -9090,6 +9240,13 @@
return $result.&show_grading_menu_form($symb);
}
+sub navmap_errormsg {
+ return '<div class="LC_error">'.
+ &mt('An error occurred retrieving information about resources in the course.').'<br />'.
+ &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this grading page..','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'">','</a>').
+ '</div>';
+}
+
sub handler {
my $request=$_[0];
&reset_caches();
@@ -9315,6 +9472,13 @@
=item scantron_get_maxbubble() :
+ Arguments:
+ $nav_error - Reference to scalar which is a flag to indicate a
+ failure to retrieve a navmap object.
+ if $nav_error is set to 1 by scantron_get_maxbubble(), the
+ calling routine should trap the error condition and display the warning
+ found in &navmap_errormsg().
+
Returns the maximum number of bubble lines that are expected to
occur. Does this by walking the selected sequence rendering the
resource and then checking &Apache::lonxml::get_problem_counter()
@@ -9380,6 +9544,11 @@
Validates all scanlines in the selected file to not have any
invalid or underspecified student/employee IDs
+=item navmap_errormsg() :
+
+ Returns HTML mark-up inside a <div></div> with a link to re-initialize the course.
+ Should be called whenever the request to instantiate a navmap object fails.
+
=back
=cut
--raeburn1264569135--