--- loncom/homework/inputtags.pm 2010/10/31 12:33:02 1.272 +++ loncom/homework/inputtags.pm 2011/06/06 23:28:42 1.290 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.272 2010/10/31 12:33:02 www Exp $ +# $Id: inputtags.pm,v 1.290 2011/06/06 23:28:42 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,7 +60,7 @@ use LONCAPA; BEGIN { - &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline')); + &Apache::lonxml::register('Apache::inputtags',('hiddensubmission','hiddenline','textfield','textline')); } =pod @@ -175,7 +175,18 @@ sub start_textfield { if ($target eq 'web') { $Apache::lonxml::evaluate--; my $partid=$Apache::inputtags::part; - my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"'); + my ($oldresponse,$newvariation); + if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') || + ($Apache::lonhomework::type eq 'randomizetry')) && + ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) { + if ($env{'form.'.$partid.'.rndseed'} ne + $Apache::lonhomework::history{"resource.$partid.rndseed"}) { + $newvariation = 1; + } + } + unless ($newvariation) { + $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"'); + } if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval); if ( $cols eq '') { $cols = 80; } @@ -331,16 +342,26 @@ sub start_textline { $maxlength = ' maxlength="'.$size.'"'; } } - my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"}; - &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse)); - - if (ref($oldresponse) eq 'ARRAY') { - $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist]; - } - $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"'); - $oldresponse =~ s/^\s+//; - $oldresponse =~ s/\s+$//; - $oldresponse =~ s/\s+/ /g; + my ($oldresponse,$newvariation); + if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') || + ($Apache::lonhomework::type eq 'randomizetry')) && + ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) { + if ($env{'form.'.$partid.'.rndseed'} ne + $Apache::lonhomework::history{"resource.$partid.rndseed"}) { + $newvariation = 1; + } + } + unless ($newvariation) { + $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"}; + &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse)); + if (ref($oldresponse) eq 'ARRAY') { + $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist]; + } + $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"'); + $oldresponse =~ s/^\s+//; + $oldresponse =~ s/\s+$//; + $oldresponse =~ s/\s+/ /g; + } if ($Apache::lonhomework::type ne 'exam') { my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval); $result=''; @@ -457,6 +478,49 @@ sub end_hiddenline { return ""; } + +sub start_hiddensubmission { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result = ""; + my $input_id = &start_input($parstack,$safeeval); + if ($target eq 'web') { + $Apache::lonxml::evaluate--; + if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { + my $partid=$Apache::inputtags::part; + my $id=$Apache::inputtags::response[-1]; + if ($Apache::lonhomework::type ne 'exam') { + my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval); + $value = &HTML::Entities::encode($value,'<>&"'); + $result= ''; + } + } + } elsif ($target eq 'edit') { + $result=&Apache::edit::tag_start($target,$token); + $result.=&Apache::edit::text_arg('Value:','value',$token,'15'); + $result.=&Apache::edit::end_row(); + $result.=&Apache::edit::end_table(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'value'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } + + if ( ($target eq 'web' || $target eq 'tex') + && $Apache::lonhomework::type eq 'exam' + && &needs_exam_box($tagstack)) { + $result.=&exam_box($target); + } + return $result; +} + +sub end_hiddensubmission { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + if ($target eq 'web') { $Apache::lonxml::evaluate++; } + elsif ($target eq 'edit') { return ('','no'); } + &end_input(); + return ""; +} + =pod =item file_selector() @@ -574,6 +638,7 @@ sub current_file_submissions { } } } + my $num = 0; foreach my $name (sort(keys(%okfiles))) { if (ref($okfiles{$name}) eq 'ARRAY') { foreach my $url (@{$okfiles{$name}}) { @@ -592,7 +657,8 @@ sub current_file_submissions { if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') { $result .= ''."\n"; + ' value="'.$portfile.'" id="HWFILE'.$jspart.'_'.$id.'_'.$num.'_delete" />'."\n"; + $num ++; } my $showname = $rows{$url}{path}.$name; if ($legacy{$url}) { @@ -600,7 +666,7 @@ sub current_file_submissions { } $result .= ''.$showname.''."\n". + '" border="0" alt="" />'.$showname.''."\n". ''.$rows{$url}{size}.''."\n". ''.$rows{$url}{lastmodified}.''."\n". &Apache::loncommon::end_data_table_row(); @@ -610,7 +676,9 @@ sub current_file_submissions { } } if ($header_shown) { - $result .= &Apache::loncommon::end_data_table(); + $result .= &Apache::loncommon::end_data_table(). + '
'. + &mt('Exclude existing file(s) from grading by checking the "Delete?" checkbox(es) and clicking "Submit Answer"').''; } if (@bad_file_list) { my $bad_files = ''. @@ -776,7 +844,7 @@ sub finalizeawards { } sub decideoutput { - my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_; + my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect)=@_; my $message=''; my $button=0; @@ -794,8 +862,14 @@ sub decideoutput { my $part = $Apache::inputtags::part; my $tohandgrade = &Apache::lonnet::EXT("resource.$part.handgrade"); my $handgrade = ('yes' eq lc($tohandgrade)); +# +# Should "Computer's Answer" be displayed? +# Should not be displayed if still answerable, +# if the problem is handgraded, +# or if the problem does not give a correct answer +# - my $computer = ($handgrade)? '' + my $computer = ($handgrade || $nocorrect)? '' : " ".&mt("Computer's answer now shown above."); &Apache::lonxml::debug("handgrade has :$handgrade:"); @@ -837,7 +911,7 @@ sub decideoutput { } } } - $button=0; + if ($awarded==1) { $button=0; } else { $button=1; } $previousmsg=''; } elsif ($solved =~ /^excused/) { if ($target eq 'tex') { @@ -1063,7 +1137,6 @@ sub decideoutput { } $message.=&mt('Submissions to practice problems are not permanently recorded.'); } - return ($button,$css_class,$message,$previousmsg); } @@ -1116,8 +1189,7 @@ sub setgradedata { $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') { $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award; return ''; - } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~ - /^correct/ + } elsif ( $Apache::lonhomework::history{"resource.$id.awarded"} < 1 || $Apache::lonhomework::scantronmode || &Apache::lonhomework::hide_problem_status() ) { # the student doesn't already have it correct, @@ -1238,8 +1310,7 @@ sub setgradedata { $Apache::lonhomework::results{"resource.$id.previous"} = '0'; } } - } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~ - /^correct/ ) { + } elsif ( $Apache::lonhomework::history{"resource.$id.awarded"} == 1 ) { #delete all data as they student already has it correct &removealldata($id); #and since they didn't do anything we were never here @@ -1249,10 +1320,10 @@ sub setgradedata { if ($award eq 'SUBMITTED') { &Apache::response::add_to_gradingqueue(); } - if (($Apache::lonhomework::type eq 'anonsurvey') || - ($Apache::lonhomework::type eq 'anonsurveycred')) { - $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type; - } + $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type; + $Apache::lonhomework::results{"resource.$id.duedate"} = &Apache::lonnet::EXT("resource.$id.duedate"); + $Apache::lonhomework::results{"resource.$id.hinttries"} = &Apache::lonnet::EXT("resource.$id.hinttries"); + $Apache::lonhomework::results{"resourse.$id.version"} = &Apache::lonnet::usedversion(); } sub find_which_previous { @@ -1332,8 +1403,8 @@ sub grade { } sub get_grade_messages { - my ($id,$prefix,$target,$status) = @_; - + my ($id,$prefix,$target,$status,$nocorrect) = @_; +# nocorrect suppresses "Computer's answer now shown above" my ($message,$latemessage,$trystr,$previousmsg); my $showbutton = 1; @@ -1347,7 +1418,7 @@ sub get_grade_messages { &Apache::lonxml::debug('Getting message'); ($showbutton,my $css_class,$message,$previousmsg) = &decideoutput($award,$awarded,$awardmsg,$solved,$previous, - $target); + $target,(($status eq 'CAN_ANSWER') || $nocorrect)); if ($target eq 'tex') { $message='\vskip 2 mm '.$message.' '; } else { @@ -1380,7 +1451,7 @@ sub get_grade_messages { $trystr = ''.&mt($tries_text)." $tries"; if ($Apache::lonhomework::parsing_a_task) { } elsif($env{'request.state'} ne 'construct') { - $trystr.="/$maxtries"; + $trystr.="/".&Apache::lonhtmlcommon::direct_parm_link($maxtries,$env{'request.symb'},'maxtries',$id,$target); } else { if (defined($Apache::inputtags::params{'maxtries'})) { $trystr.="/".$Apache::inputtags::params{'maxtries'}; @@ -1461,6 +1532,7 @@ sub previous_tries { my $count; my %count_lookup; + my $lastrndseed; foreach my $i (1..$Apache::lonhomework::history{'version'}) { my $prefix = $i.":resource.$id"; @@ -1474,7 +1546,7 @@ sub previous_tries { next if (!exists($Apache::lonhomework::history{"$prefix.award"})); $count++; $count_lookup{$i} = $count; - + my $curr_rndseed = $Apache::lonhomework::history{"$prefix.rndseed"}; my ($previousmsg,$latemessage,$message,$trystr); ($previousmsg,$latemessage,$message,$trystr) = @@ -1492,10 +1564,25 @@ sub previous_tries { ) { my $txt_correct = &mt('Correct'); + my $awarded = $Apache::lonhomework::history{"$prefix.awarded"}; + if ($awarded < 1 && $awarded > 0) { + $txt_correct=&mt('Partially Correct'); + } elsif ($awarded < 1) { + if ($awarded eq '') { + $txt_correct=''; + } else { + $txt_correct=&mt('Incorrect'); + } + } $message =~ s{()(.*?)()} {$1 $txt_correct. $3}s; } my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")"; + if ($curr_rndseed || $lastrndseed) { + if ($curr_rndseed ne $lastrndseed) { + $trystr .= '
'.&mt('New problem variation this try.').''; + } + } $message =~ s{()}{ $trystr $1}; } my ($class) = ($message =~ m{