--- loncom/homework/inputtags.pm 2007/04/16 22:50:41 1.221 +++ loncom/homework/inputtags.pm 2007/10/03 02:10:45 1.232 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.221 2007/04/16 22:50:41 albertel Exp $ +# $Id: inputtags.pm,v 1.232 2007/10/03 02:10:45 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,7 +31,6 @@ use strict; use Apache::loncommon; use Apache::lonlocal; use Apache::lonnet; -use lib '/home/httpd/lib/perl/'; use LONCAPA; @@ -116,8 +115,7 @@ sub check_for_duplicate_ids { sub start_input { my ($parstack,$safeeval)=@_; - my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval); - if ($id eq '') { $id = $Apache::lonxml::curdepth; } + my $id = &Apache::lonxml::get_id($parstack,$safeeval); push (@Apache::inputtags::input,$id); push (@Apache::inputtags::inputlist,$id); return $id; @@ -449,7 +447,7 @@ sub file_selector { $result.='
'.''.&mt('OR:').'
'; } if ($which eq 'portfolioonly' || $which eq 'both') { - $result.=$extratext.''. + $result.=$extratext.''. &mt('Select Portfolio Files').'
'. ''. '
'; @@ -541,8 +539,17 @@ sub valid_award { $i=0; my %rev_awards = map { ($_,$i++) } @awards; +sub awarddetail_to_awarded { + my ($awarddetail) = @_; + if ($awarddetail eq 'EXACT_ANS' + || $awarddetail eq 'APPROX_ANS') { + return 1; + } + return 0; +} + sub finalizeawards { - my ($awardref,$msgref,$nameref,$reverse)=@_; + my ($awardref,$msgref,$nameref,$reverse,$final_scantron)=@_; my $result; if ($#$awardref == -1) { $result = "NO_RESPONSE"; } if ($result eq '' ) { @@ -553,10 +560,29 @@ sub finalizeawards { $blankcount++; } } - if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; } + if ($blankcount == ($#$awardref + 1)) { + return ('NO_RESPONSE'); + } } - if (defined($result)) { return ($result); } + if (!$final_scantron && defined($result)) { return ($result); } + # if in scantron mode, if the award for any response is + # assigned score, then the part gets an assigned score + if ($final_scantron + && grep {$_ eq 'ASSIGNED_SCORE'} (@$awardref)) { + return ('ASSIGNED_SCORE'); + } + + # if in scantron mode, if the award for any response is + # correct and there are non-correct responses, + # then the part gets an assigned score + if ($final_scantron + && (grep { $_ eq 'EXACT_ANS' || + $_ eq 'APPROX_ANS' } (@$awardref)) + && (grep { $_ ne 'EXACT_ANS' && + $_ ne 'APPROX_ANS' } (@$awardref))) { + return ('ASSIGNED_SCORE'); + } # these awards are ordered from most important error through best correct my $awards = (!$reverse) ? \%fwd_awards : \%rev_awards ; @@ -570,6 +596,7 @@ sub finalizeawards { } $j++; } + if (defined($which)) { if (ref($nameref)) { return ($$awardref[$which],$$msgref[$which],$$nameref[$which]); @@ -629,10 +656,10 @@ sub decideoutput { } $added_computer_text=1; my ($symb) = &Apache::lonnet::whichuser(); - if ((!$env{'course.'. - $env{'request.course.id'}. - '.disable_receipt_display'} eq 'yes')&& - $symb) { + if (($symb ne '') + && + ($env{'course.'.$env{'request.course.id'}. + '.disable_receipt_display'} ne 'yes')) { $message.=(($target eq 'web')?'
':' '). &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part). (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):''); @@ -875,8 +902,13 @@ sub setgradedata { my $numawards=scalar(@Apache::inputtags::response); $Apache::lonhomework::results{"resource.$id.awarded"} = 0; foreach my $res (@Apache::inputtags::response) { - $Apache::lonhomework::results{"resource.$id.awarded"}+= - $Apache::lonhomework::results{"resource.$id.$res.awarded"}; + if (defined($Apache::lonhomework::results{"resource.$id.$res.awarded"})) { + $Apache::lonhomework::results{"resource.$id.awarded"}+= + $Apache::lonhomework::results{"resource.$id.$res.awarded"}; + } else { + $Apache::lonhomework::results{"resource.$id.awarded"}+= + &awarddetail_to_awarded($Apache::lonhomework::results{"resource.$id.$res.awarddetail"}); + } } if ($numawards > 0) { $Apache::lonhomework::results{"resource.$id.awarded"}/= @@ -1008,7 +1040,9 @@ sub grade { &Apache::lonxml::debug("got message $value from $response for $id"); push (@msgs,$value); } - my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs); + my ($finalaward,$msg) = + &finalizeawards(\@awards,\@msgs,undef,undef, + $Apache::lonhomework::scantronmode); my $previously_used; if ( $#Apache::inputtags::previous eq $#awards ) { my ($match) = @@ -1106,7 +1140,7 @@ sub get_grade_messages { } sub gradestatus { - my ($id,$target) = @_; + my ($id,$target,$no_previous) = @_; my $showbutton = 1; my $message = ''; my $latemessage = ''; @@ -1133,7 +1167,12 @@ sub gradestatus { } if ( $showbutton ) { if ($target ne 'tex') { - $button = ''; + $button = + ''; } } @@ -1145,7 +1184,13 @@ sub gradestatus { if ($target eq 'tex') { return $button.' \vskip 0 mm '.$output.' '; } else { - return ''.$output.'
'.$button.''.&previous_tries($id,$target).'
'; + $output = + ''.$output; + if (!$no_previous) { + $output.=''; + } + $output.= '
'.$button.''.&previous_tries($id,$target).'
'; + return $output; } } } @@ -1174,12 +1219,15 @@ sub previous_tries { my ($match,$which) = &find_which_previous($i); $message=$previousmsg; my $previous = $count_lookup{$which}; - $message =~ s{()}{ as submission # $previous $1}; + $message =~ s{()}{ as submission \# $previous $1}; } elsif ($Apache::lonhomework::history{"$prefix.tries"}) { - if ( $Apache::lonhomework::history{"$prefix.solved"} =~ - /^correct/) { + if (!(lc($Apache::lonhomework::problemstatus) eq 'no' + && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER') + && $Apache::lonhomework::history{"$prefix.solved"} =~/^correct/ + ) { + $message =~ s{()(.*?)()} - {$1 Correct. $3}; + {$1 Correct. $3}s; } my $trystr = "(Try ". $Apache::lonhomework::history{"$prefix.tries"}.')'; @@ -1190,7 +1238,7 @@ sub previous_tries { $output.=''; - $output.=''.$count.''; + $output.=''.$count.''; $output.=$message; foreach my $resid (@Apache::inputtags::response) { @@ -1211,28 +1259,32 @@ sub previous_tries { } return if ($output eq ''); my $headers = - ''.''.&mt('Submission #').''.&mt(' '). + ''.''.&mt('Submission #').''.&mt('Try'). ''. &mt('Submitted Answer').''; $output =''.$headers.$output.'
'; #return $output; - $output=~s/\\/\\\\/g; - $output=~s/\'/\\\'/g; - $output=~s/\s+/ /g; + $output = &Apache::loncommon::js_ready($output); + $output.='
'; + my $windowopen=&Apache::lonhtmlcommon::javascript_docopen(); my $start_page = &Apache::loncommon::start_page('Previous Tries', undef, - {'only_body' => 1, - 'bgcolor' => '#FFFFFF', - 'js_ready' => 1,}); + {'only_body' => 1, + 'bgcolor' => '#FFFFFF', + 'js_ready' => 1, + 'inherit_jsmath' => 1, }); my $end_page = &Apache::loncommon::end_page({'js_ready' => 1,}); - + my $prefix = $env{'form.request.prefix'}; + $prefix =~ tr{.}{_}; + my $function_name = "LONCAPA_previous_tries_".$prefix. + $Apache::lonxml::curdepth; my $result ="".&mt("Previous Tries")."
"; +".&mt("Previous Tries")."
"; #use Data::Dumper; #&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display)); return $result;