--- loncom/homework/inputtags.pm 2002/10/01 21:05:45 1.63 +++ loncom/homework/inputtags.pm 2003/04/07 20:52:58 1.87 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.63 2002/10/01 21:05:45 sakharuk Exp $ +# $Id: inputtags.pm,v 1.87 2003/04/07 20:52:58 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,9 +30,10 @@ package Apache::inputtags; use HTML::Entities(); use strict; +use Apache::loncommon; BEGIN { - &Apache::lonxml::register('Apache::inputtags',('textfield','textline','datasubmission')); + &Apache::lonxml::register('Apache::inputtags',('textfield','textline')); } @@ -47,6 +48,8 @@ sub initialize_inputtags { @Apache::inputtags::responselist=(); # list of whether or not a specific response was previously used @Apache::inputtags::previous=(); + # submission it was used in + @Apache::inputtags::previous_version=(); # id of current part, 0 means that no part is current (inside only $Apache::inputtags::part=''; # list of problem date statuses, the first element is for @@ -90,17 +93,17 @@ sub start_textfield { "rows=\"$rows\" cols=\"$cols\">".$oldresponse; if ($oldresponse ne '') { #get rid of any startup text if the user has already responded - &Apache::lonxml::get_all_text("/textfield",$$parser[-1]); + &Apache::lonxml::get_all_text("/textfield",$parser); } } else { #right or wrong don't show it #$result='
'.$oldresponse.'
'; $result=''; #get rid of any startup text - &Apache::lonxml::get_all_text("/textfield",$$parser[-1]); + &Apache::lonxml::get_all_text("/textfield",$parser); } } elsif ($target eq 'grade') { - my $seedtext=&Apache::lonxml::get_all_text("/textfield",$$parser[-1]); + my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser); if ($seedtext eq $ENV{'form.HWVAL'.$resid}) { # if the seed text is still there it wasn't a real submission $ENV{'form.HWVAL'.$resid}=''; @@ -109,7 +112,7 @@ sub start_textfield { $result.=&Apache::edit::tag_start($target,$token); $result.=&Apache::edit::text_arg('Rows:','rows',$token,4); $result.=&Apache::edit::text_arg('Columns:','cols',$token,4); - my $bodytext=&Apache::lonxml::get_all_text("/textfield",$$parser[-1]); + my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser); $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, @@ -120,6 +123,13 @@ sub start_textfield { $result=$token->[4]; } $result.=&Apache::edit::modifiedfield(); + } elsif ($target eq 'tex') { + if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') { + my $number_of_lines= &Apache::lonxml::get_param('rows',$parstack,$safeeval); + $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{'; + for (my $i=0;$i'; + if ($Apache::lonhomework::type ne 'exam') { + $result= ''; + } } else { #right or wrong don't show what was last typed in. #$result=''.$oldresponse.''; @@ -164,6 +179,10 @@ sub start_textline { } elsif ($target eq 'modified') { my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } elsif ($target eq 'tex' and $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}'; } return $result; } @@ -175,40 +194,6 @@ sub end_textline { return ""; } -sub start_datasubmission { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my $id = &Apache::response::start_response($parstack,$safeeval); - my $result; - if ($target eq 'meta') { - $result = &Apache::response::meta_stores_write($token->[2]->{'name'}, - $token->[2]->{'type'}, - $token->[2]->{'display'}); - $result .= &Apache::response::meta_package_write('datasubmission'); - } - return $result; -} - -sub end_datasubmission { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my $result; - if ( $target eq 'web' ) { - } elsif ($target eq 'grade' ) { - if ( defined $ENV{'form.submitted'}) { - &Apache::response::setup_params('datasubmission'); - my $partid = $Apache::inputtags::part; - my $id = $Apache::inputtags::response['-1']; - my $response = $ENV{'form.HWVAL'.$id}; - my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); - if ( $response =~ /[^\s]/) { - $Apache::lonhomework::results{"resource.$partid.$id.$name"}= - $response; - } - } - } - &Apache::response::end_response; - return $result; -} - sub finalizeawards { my $result=''; my $award; @@ -255,6 +240,12 @@ sub finalizeawards { foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} } } if ($result eq '' ) { + foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} } + } + if ($result eq '' ) { + foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} } + } + if ($result eq '' ) { foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} } } if ($result eq '' ) { @@ -268,7 +259,7 @@ sub finalizeawards { } sub decideoutput { - my ($award,$solved,$previous)=@_; + my ($award,$solved,$previous,$target)=@_; my $message=''; my $button=0; my $previousmsg; @@ -276,8 +267,13 @@ sub decideoutput { if ($previous) { $previousmsg='You have entered that answer before'; } if ($solved =~ /^correct/) { - $message = "You are correct. Your receipt is ". + if ($target eq 'tex') { + $message = '\textbf{You are correct}. Your receipt is '. + &Apache::lonnet::receipt; + } else { + $message = "You are correct. Your receipt is ". &Apache::lonnet::receipt; + } $button=0; $previousmsg=''; } elsif ($solved =~ /^excused/) { @@ -303,17 +299,26 @@ sub decideoutput { } elsif ($award eq 'WANTED_NUMERIC') { $message = "This question expects a numeric answer"; $button=1; + } elsif ($award eq 'MISORDERED_RANK') { + $message = 'You have provided an invalid ranking, please refer to '. + &Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems').'.'; + $button=1; + } elsif ($award eq 'INVALID_FILETYPE') { + $message = 'The filetype extension of the file you uploaded is not allowed.'; + $button=1; } elsif ($award eq 'SIG_FAIL') { $message = "Please adjust significant figures.";# you provided %s significant figures"; $button=1; } elsif ($award eq 'UNIT_FAIL') { - $message = "Units incorrect."; #Computer reads units as %s"; + $message = "Units incorrect. ". + &Apache::loncommon::help_open_topic('Physical_Units'); #Computer reads units as %s"; $button=1; } elsif ($award eq 'UNIT_NOTNEEDED') { $message = "Only a number required.";# Computer reads units of %s"; $button=1; } elsif ($award eq 'NO_UNIT') { - $message = "Units required"; + $message = "Units required". + &Apache::loncommon::help_open_topic('Physical_Units'); $button=1; } elsif ($award eq 'BAD_FORMULA') { $message = "Unable to understand formula"; @@ -331,13 +336,25 @@ sub decideoutput { $message = "Unknown message: $award"; $button=1; } + if ($Apache::lonhomework::type eq 'exam') {$message='';$previousmsg='';} return ($button,$message,$previousmsg); } +sub remove_alldata { + my ($id)=@_; + foreach my $key (keys(%Apache::lonhomework::results)) { + if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) { + &Apache::lonxml::debug("Removing $key"); + delete($Apache::lonhomework::results{$key}); + } + } +} + sub setgradedata { my ($award,$id,$previously_used) = @_; # if the student already has it correct, don't modify the status - if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER') { + if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' && + $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') { $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award; return ''; } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~ @@ -365,7 +382,9 @@ sub setgradedata { } elsif ( $award eq 'DRAFT' ) { $Apache::lonhomework::results{"resource.$id.solved"} = ''; } elsif ( $award eq 'NO_RESPONSE' ) { - return ''; + #no real response so delete any data that got stored + &removealldata($id); + return ''; } else { $Apache::lonhomework::results{"resource.$id.solved"} = 'incorrect_attempted'; @@ -379,17 +398,18 @@ sub setgradedata { } elsif ( $previously_used eq 'PREVIOUSLY_LAST') { #delete all data as they student didn't do anything, but save #the list of collaborators. - foreach my $key (keys(%Apache::lonhomework::results)) { - if (($key =~ /^resource\.$id\./) && ($key !~ /\.collaborators$/)) { - &Apache::lonxml::debug("Removing $key"); - delete($Apache::lonhomework::results{$key}); - } - } + &removealldata($id); #and since they didn't do anything we were never here return ''; } else { $Apache::lonhomework::results{"resource.$id.previous"} = '0'; } + } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~ + /^correct/ ) { + #delete all data as they student already has it correct + &removealldata($id); + #and since they didn't do anything we were never here + return ''; } $Apache::lonhomework::results{"resource.$id.award"} = $award; } @@ -409,13 +429,23 @@ sub grade { my $finalaward = &finalizeawards(@awards); my $previously_used; if ( $#Apache::inputtags::previous eq $#awards ) { - $previously_used = 'PREVIOUSLY_LAST'; - foreach my $value (@Apache::inputtags::previous) { - if ($value eq 'PREVIOUSLY_USED' ) { - $previously_used = $value; - last; + my $match=0; + my @matches; + foreach my $versionar (@Apache::inputtags::previous_version) { + foreach my $version (@$versionar) { + $matches[$version]++; + } + } + foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}} + if ($match) { + $previously_used = 'PREVIOUSLY_LAST'; + foreach my $value (@Apache::inputtags::previous) { + if ($value eq 'PREVIOUSLY_USED' ) { + $previously_used = $value; + last; + } + } } - } } &Apache::lonxml::debug("final award $finalaward, $previously_used"); &setgradedata($finalaward,$id,$previously_used); @@ -434,7 +464,7 @@ sub gradestatus { my $status = $Apache::inputtags::status['-1']; &Apache::lonxml::debug("gradestatus has :$status:"); - if ( $status ne 'CLOSED' ) { + if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE') { my $award = $Apache::lonhomework::history{"resource.$id.award"}; my $solved = $Apache::lonhomework::history{"resource.$id.solved"}; my $previous = $Apache::lonhomework::history{"resource.$id.previous"}; @@ -442,7 +472,7 @@ sub gradestatus { if ( $award ne '' ) { &Apache::lonxml::debug('Getting message'); ($showbutton,$message,$previousmsg) = - &decideoutput($award,$solved,$previous); + &decideoutput($award,$solved,$previous,$target); if ($target eq 'tex') { $message=' '.$message.' '; } else { @@ -460,7 +490,11 @@ sub gradestatus { if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } if ( $showbutton ) { if ($target eq 'tex') { - $trystr = ' '.$tries.'/'.$maxtries.' '; + if ($ENV{'request.state'} ne "construct") { + $trystr = ' {\small \textit{Tries} '.$tries.'/'.$maxtries.'} \vskip 0 mm '; + } else { + $trystr = '\vskip 0 mm '; + } } else { $trystr = "Tries $tries/$maxtries"; }