--- loncom/homework/matchresponse.pm 2004/02/09 19:38:00 1.33 +++ loncom/homework/matchresponse.pm 2004/03/15 22:09:52 1.38 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Full matching style response # -# $Id: matchresponse.pm,v 1.33 2004/02/09 19:38:00 albertel Exp $ +# $Id: matchresponse.pm,v 1.38 2004/03/15 22:09:52 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,7 +30,8 @@ package Apache::matchresponse; use strict; use HTML::Entities(); use Math::Random(); -use Apache::optionresponse; +use Apache::optionresponse(); +use Apache::lonlocal; BEGIN { &Apache::lonxml::register('Apache::matchresponse',('matchresponse')); @@ -46,6 +47,7 @@ sub start_matchresponse { push (@Apache::lonxml::namespace,'matchresponse'); my $id = &Apache::response::start_response($parstack,$safeeval); %Apache::hint::match=(); + undef(%Apache::response::foilnames); if ($target eq 'meta') { $result=&Apache::response::meta_package_write('matchresponse'); } elsif ($target eq 'edit' ) { @@ -80,6 +82,7 @@ sub end_matchresponse { pop @Apache::lonxml::namespace; &Apache::lonxml::deregister('Apache::matchresponse', ('foilgroup','foil','conceptgroup')); + undef(%Apache::response::foilnames); return $result; } @@ -314,7 +317,7 @@ sub grade_response { } my @items; foreach my $name (@whichfoils) { - my $response = &Apache::response::getresponse($temp); + my $response = &Apache::response::getresponse($temp,'letter'); push(@items,$response); my $responsename = $letter_name_map{$response}; my $value=$Apache::response::foilgroup{$name.'.value'}; @@ -338,26 +341,41 @@ sub grade_response { my $gradestr =&Apache::lonnet::hash2str(%grade); my %previous=&Apache::response::check_for_previous($responsestr,$part,$id); &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored "); - my $ad; - if ($wrong==0 && $ignored==0) { - $ad='EXACT_ANS'; - } elsif ($wrong==0 && $right==0) { - #nothing submitted - } else { - if ($ignored==0) { - $ad='INCORRECT'; - } else { - $ad='MISSING_ANSWER'; - } - } $Apache::lonhomework::results{"resource.$part.$id.submission"}= $responsestr; $Apache::lonhomework::results{"resource.$part.$id.submissionitems"}= $itemstr; $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}= $gradestr; - $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad; - &Apache::response::handle_previous(\%previous,$ad); + if (!$Apache::lonhomework::scantronmode) { + my $ad; + if ($wrong==0 && $ignored==0) { + $ad='EXACT_ANS'; + } elsif ($wrong==0 && $right==0) { + #nothing submitted + } else { + if ($ignored==0) { + $ad='INCORRECT'; + } else { + $ad='MISSING_ANSWER'; + } + } + $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad; + &Apache::response::handle_previous(\%previous,$ad); + } else { + my $ad; + if ($wrong==0 && $right==0) { + #nothing submitted + } else { + $ad='ASSIGNED_SCORE'; + $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}= + $ad; + $Apache::lonhomework::results{"resource.$part.$id.awarded"}= + $right/(scalar(@whichfoils)); + $Apache::lonhomework::results{"resource.$part.$id.numfoils"}= + scalar(@whichfoils); + } + } } sub itemdisplay { @@ -404,7 +422,7 @@ sub displayfoils { } } else { my $i = 0; - my $temp=0; + my $temp=1; my $id=$Apache::inputtags::response[-1]; my $part=$Apache::inputtags::part; my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"}; @@ -577,10 +595,15 @@ sub end_foil { my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval); if ($value ne 'unused') { my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); - my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval); &Apache::lonxml::debug("Got a name of :$name:"); if (!$name) { $name=$Apache::lonxml::curdepth; } &Apache::lonxml::debug("Using a name of :$name:"); + if (defined($Apache::response::foilnames{$name})) { + &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",$name)); + } + $Apache::response::foilnames{$name}++; + my $location =&Apache::lonxml::get_param('location',$parstack, + $safeeval); if ( $Apache::matchresponse::conceptgroup && !&Apache::response::showallfoils() ) { push @{ $Apache::response::conceptgroup{'names'} }, $name;