--- loncom/homework/inputtags.pm 2005/11/10 22:19:27 1.179
+++ loncom/homework/inputtags.pm 2006/03/09 01:11:12 1.190
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.179 2005/11/10 22:19:27 albertel Exp $
+# $Id: inputtags.pm,v 1.190 2006/03/09 01:11:12 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -131,7 +131,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];
@@ -155,17 +155,18 @@ sub start_textfield {
if ($oldresponse ne '') {
#get rid of any startup text if the user has already responded
- &Apache::lonxml::get_all_text("/textfield",$parser);
+ &Apache::lonxml::get_all_text("/textfield",$parser,$style);
}
} else {
#right or wrong don't show it
#$result='
'.$oldresponse.'
';
$result='';
#get rid of any startup text
- &Apache::lonxml::get_all_text("/textfield",$parser);
+ &Apache::lonxml::get_all_text("/textfield",$parser,$style);
}
} elsif ($target eq 'grade') {
- my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);
+ my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser,
+ $style);
if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
# if the seed text is still there it wasn't a real submission
$env{'form.HWVAL_'.$resid}='';
@@ -176,7 +177,8 @@ sub start_textfield {
$result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
$result.=&Apache::edit::text_arg
('Click-On Texts (comma sep):','addchars',$token,10);
- my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
+ my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser,
+ $style);
$result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
@@ -220,6 +222,57 @@ sub end_textfield {
return $result;
}
+sub exam_score_line {
+ my ($target) = @_;
+
+ my $result;
+ if ($target eq 'tex') {
+ my $repetition = &Apache::response::repetition();
+ $result.='\begin{enumerate}';
+ if ($env{'request.state'} eq "construct" ) {$result.='\item[\strut]';}
+ foreach my $i (0..$repetition-1) {
+ $result.='\item[\textbf{'.
+ ($Apache::lonxml::counter+$i).
+ '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
+ }
+ $result.= '\end{enumerate}';
+ }
+
+ return $result;
+}
+
+sub exam_box {
+ my ($target) = @_;
+ my $result;
+
+ if ($target eq 'tex') {
+ $result .= '\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
+ $result .= &exam_score_line($target);
+ } elsif ($target eq 'web') {
+ my $id=$Apache::inputtags::response[-1];
+ $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 = "";
@@ -250,6 +303,10 @@ sub start_textline {
$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 +326,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 +365,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 +430,22 @@ sub file_selector {
''.
' ';
if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
- my @filelist;
+ my (@filelist,@bad_file_list);
foreach my $file (split(',',&Apache::lonnet::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)) {
+ push(@bad_file_list,''.$file.'');
+ }
}
$result.=&mt("Portfolio files previously selected: [_1]",join(', ',@filelist));
+ if (@bad_file_list) {
+ $result.=' '.&mt('These file(s) don\'t exist: [_1]',join(', ',@bad_file_list));
+ }
}
}
$result.='';
@@ -388,7 +464,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 +480,7 @@ sub valid_award {
}
sub finalizeawards {
- my ($awardref,$msgref)=@_;
+ my ($awardref,$msgref,$nameref,$reverse)=@_;
my $result=undef;
my $award;
my $msg;
@@ -419,15 +496,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); }
}
@@ -448,6 +529,14 @@ sub decideoutput {
'no_message' => '#fffff',
);
+ my $part = $Apache::inputtags::part;
+ my $handgrade =
+ ('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
+
+ my $computer = ($handgrade)? ''
+ : " ".&mt("Computer's answer now shown above.");
+ &Apache::lonxml::debug("handgrade has :$handgrade:");
+
if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
if ($solved =~ /^correct/) {
@@ -469,7 +558,7 @@ sub decideoutput {
$message = '\textbf{'.$message.'}';
} else {
$message = "".$message."";
- $message.=" ".&mt("Computer's answer now shown above.");
+ $message.= $computer;
}
$added_computer_text=1;
unless ($env{'course.'.
@@ -501,7 +590,7 @@ sub decideoutput {
$message = '\textbf{'.&mt('You are correct.').'}';
} else {
$message = "".&mt('You are correct.')."";
- $message.=" ".&mt("Computer's answer now shown above.");
+ $message.= $computer;
}
$added_computer_text=1;
unless ($env{'course.'.
@@ -519,6 +608,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'};
@@ -603,7 +696,12 @@ 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";
@@ -617,7 +715,7 @@ sub decideoutput {
}
if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
!$added_computer_text && $target ne 'tex') {
- $message.=" ".&mt("Computer's answer now shown above.");
+ $message.= $computer;
$added_computer_text=1;
}
return ($button,$bgcolor,$message,$previousmsg);
@@ -773,6 +871,9 @@ sub setgradedata {
return '';
}
$Apache::lonhomework::results{"resource.$id.award"} = $award;
+ if ($award eq 'SUBMITTED') {
+ &Apache::response::add_to_gradingqueue();
+ }
}
sub grade {
@@ -829,8 +930,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"};