--- loncom/homework/inputtags.pm 2005/11/15 22:28:30 1.180 +++ loncom/homework/inputtags.pm 2006/07/14 18:12:16 1.200 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.180 2005/11/15 22:28:30 albertel Exp $ +# $Id: inputtags.pm,v 1.200 2006/07/14 18:12:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,9 @@ use strict; use Apache::loncommon; use Apache::lonlocal; use Apache::lonnet; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + BEGIN { &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline')); @@ -131,7 +134,7 @@ sub addchars { } sub start_textfield { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result = ""; my $id = &start_input($parstack,$safeeval); my $resid=$Apache::inputtags::response[-1]; @@ -149,23 +152,24 @@ sub start_textfield { if ($addchars) { $result.=&addchars('HWVAL_'.$resid,$addchars); } - push @Apache::lonxml::htmlareafields,'HWVAL_'.$resid; + &Apache::lonhtmlcommon::add_htmlareafields('HWVAL_'.$resid); $result.= '

'; + } + return $result; +} + +sub needs_exam_box { + my ($tagstack) = @_; + my @tags = ('formularesponse', + 'stringresponse', + 'reactionresponse', + 'organicresponse', + ); + + foreach my $tag (@tags) { + if (grep(/\Q$tag\E/,@$tagstack)) { + return 1; + } + } + return 0; +} + sub start_textline { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result = ""; @@ -227,7 +283,10 @@ sub start_textline { $Apache::lonxml::evaluate--; my $partid=$Apache::inputtags::part; my $id=$Apache::inputtags::response[-1]; - if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER' + || lc($Apache::lonhomework::problemstatus) eq 'no' + || ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER' + && $Apache::lonhomework::history{"resource.$partid.solved"} !~ /^correct/ )) { my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval); my $maxlength; if ($size eq '') { $size=20; } else { @@ -242,14 +301,23 @@ sub start_textline { } my $readonly=&Apache::lonxml::get_param('readonly',$parstack, $safeeval); - if (lc($readonly) eq 'yes') { + if (lc($readonly) eq 'yes' + || $Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') { $readonly=' readonly="readonly" '; } else { $readonly=''; } - $result.= ''; } + if ($Apache::lonhomework::type eq 'exam' + && &needs_exam_box($tagstack)) { + $result.=&exam_box($target); + } } else { #right or wrong don't show what was last typed in. $result=''.$Apache::inputtags::answertxt{$id}.''; @@ -269,10 +337,16 @@ sub start_textline { $safeeval,'size', 'addchars','readonly'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } - } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') { + } elsif ($target eq 'tex' + && $Apache::lonhomework::type ne 'exam') { my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval); if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';} $result='\framebox['.$size.'][s]{\tiny\strut}'; + + } elsif ($target eq 'tex' + && $Apache::lonhomework::type eq 'exam' + && &needs_exam_box($tagstack)) { + $result.=&exam_box($target); } return $result; } @@ -302,6 +376,12 @@ sub start_hiddenline { $result=&Apache::edit::tag_start($target,$token); $result.=&Apache::edit::end_table; } + + if ( ($target eq 'web' || $target eq 'tex') + && $Apache::lonhomework::type eq 'exam' + && &needs_exam_box($tagstack)) { + $result.=&exam_box($target); + } return $result; } @@ -361,15 +441,29 @@ sub file_selector { ''. '
'; if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){ - my @filelist; - foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) { + my (@file_list,@bad_file_list); + foreach my $file (split(/\s*,\s*/,&unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) { my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser(); my $url="/uploaded/$domain/$user/portfolio$file"; my $icon=&Apache::loncommon::icon($url); - push(@filelist,''.$file.''); + if (! &Apache::lonnet::stat_file($url)) { + &Apache::lonnet::logthis("bad file is $url"); + push(@bad_file_list,''.$file.''); + } + } + my $files = ''. + join(', ',@file_list). + ''; + $result.=&mt("Portfolio files previously selected: [_1]",$files); + if (@bad_file_list) { + my $bad_files = ''. + join(', ',@bad_file_list). + ''; + $result.='
'.&mt('These file(s) don\'t exist: [_1]',$bad_files); } - $result.=&mt("Portfolio files previously selected: [_1]",join(', ',@filelist)); } } $result.=''; @@ -388,7 +482,8 @@ sub checkstatus { sub valid_award { my ($award) =@_; - foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE', + foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR', + 'NO_RESPONSE', 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT', @@ -403,7 +498,7 @@ sub valid_award { } sub finalizeawards { - my ($awardref,$msgref)=@_; + my ($awardref,$msgref,$nameref,$reverse)=@_; my $result=undef; my $award; my $msg; @@ -419,15 +514,19 @@ sub finalizeawards { if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; } } if (defined($result)) { return ($result,$msg); } - foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE', - 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR', - 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE', - 'UNIT_FAIL', 'NO_UNIT', - 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', - 'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', - 'MISORDERED_RANK', 'INVALID_FILETYPE', - 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE', - 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') { + + # these awards are ordered from most important error through best correct + + my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE', + 'TOO_LONG', + 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT', + 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT', + 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', + 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK', + 'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE', + 'APPROX_ANS', 'EXACT_ANS'); + if ($reverse) { @awards=reverse(@awards); } + foreach my $possibleaward (@awards) { ($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref); if (defined($result)) { return ($result,$msg); } } @@ -458,8 +557,8 @@ sub decideoutput { if ($previous) { $previousmsg=&mt('You have entered that answer before'); } - if ($solved =~ /^correct/) { - $bgcolor=$possiblecolors{'correct'}; + if ($solved =~ /^correct/) { + $bgcolor=$possiblecolors{'correct'}; $message=&mt('You are correct.'); if ($awarded < 1 && $awarded > 0) { $message=&mt('You are partially correct.'); @@ -527,6 +626,10 @@ sub decideoutput { $message = ''; $bgcolor=$possiblecolors{'no_feedback'}; $button=1; + } elsif ($award eq 'EXTRA_ANSWER') { + $message = &mt('Some extra items were submitted.'); + $bgcolor=$possiblecolors{'not_charged_try'}; + $button = 1; } elsif ($award eq 'MISSING_ANSWER') { $message = &mt('Some items were not submitted.'); $bgcolor=$possiblecolors{'not_charged_try'}; @@ -611,12 +714,31 @@ sub decideoutput { $bgcolor=$possiblecolors{'correct'}; $button=0; } elsif ($award eq '') { - $bgcolor=$possiblecolors{'not_charged_try'}; + if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') { + $message = &mt("Nothing submitted."); + $bgcolor=$possiblecolors{'charged_try'}; + } else { + $bgcolor=$possiblecolors{'not_charged_try'}; + } $button=1; } else { $message = &mt("Unknown message").": $award"; $button=1; } + my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser(); + foreach my $resid(@Apache::inputtags::response){ + if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) { + $message.='
'; + my @files = split(/\s*,\s*/, + $Apache::lonhomework::history{"resource.$part.$resid.handback"}); + my $file_msg; + foreach my $file (@files) { + $file_msg.= '
'.$file.''; + } + $message .= &mt('Returned file(s): [_1]',$file_msg); + } + } + if (lc($Apache::lonhomework::problemstatus) eq 'no' && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER') { $message = &mt("Answer Submitted: Your final submission will be graded after the due date."); @@ -781,6 +903,9 @@ sub setgradedata { return ''; } $Apache::lonhomework::results{"resource.$id.award"} = $award; + if ($award eq 'SUBMITTED') { + &Apache::response::add_to_gradingqueue(); + } } sub grade { @@ -837,8 +962,11 @@ sub gradestatus { my $status = $Apache::inputtags::status['-1']; &Apache::lonxml::debug("gradestatus has :$status:"); - if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE' && - $status ne 'INVALID_ACCESS') { + if ( $status ne 'CLOSED' + && $status ne 'UNAVAILABLE' + && $status ne 'INVALID_ACCESS' + && $status ne 'NEEDS_CHECKIN' + && $status ne 'NOT_IN_A_SLOT') { my $award = $Apache::lonhomework::history{"resource.$id.award"}; my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"}; my $solved = $Apache::lonhomework::history{"resource.$id.solved"};