--- loncom/homework/inputtags.pm 2010/12/31 19:10:16 1.271.2.4
+++ loncom/homework/inputtags.pm 2011/10/08 19:19:58 1.295
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.271.2.4 2010/12/31 19:10:16 raeburn Exp $
+# $Id: inputtags.pm,v 1.295 2011/10/08 19:19:58 raeburn 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
@@ -354,7 +354,6 @@ sub start_textline {
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];
}
@@ -479,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()
@@ -529,7 +571,7 @@ sub file_selector {
if ($which eq 'uploadonly' || $which eq 'both') {
$result.=&mt('Submit a file: (only one file per submission)').
'
';
+ $jspart.'_'.$id.'" id="HWFILE'.$jspart.'_'.$id.'" />
';
}
if ( $which eq 'both') {
$result.='
'.''.&mt('OR:').'
';
@@ -685,7 +727,8 @@ sub valid_award {
'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
'UNIT_FAIL', 'NO_UNIT',
'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
- 'BAD_FORMULA', 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT',
+ 'BAD_FORMULA', 'NOT_FUNCTION', 'WRONG_FORMAT',
+ 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT',
'MISORDERED_RANK', 'INVALID_FILETYPE',
'EXCESS_FILESIZE', 'FILENAME_INUSE',
'DRAFT', 'SUBMITTED', 'SUBMITTED_CREDIT',
@@ -702,7 +745,8 @@ sub valid_award {
'TOO_LONG',
'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
- 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'INTERNAL_ERROR',
+ 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'NOT_FUNCTION',
+ 'WRONG_FORMAT', 'INTERNAL_ERROR',
'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE',
'DRAFT', 'SUBMITTED',
@@ -800,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;
@@ -818,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:");
@@ -835,8 +885,8 @@ sub decideoutput {
$message=&mt('Incorrect.');
$css_class=$possible_class{'charged_try'};
}
- if ($env{'request.filename'} =~
- m|/res/lib/templates/examupload.problem$|) {
+ if ($handgrade ||
+ ($env{'request.filename'}=~/\/res\/lib\/templates\/(examupload|DropBox).problem$/)) {
$message = &mt("A score has been assigned.");
$added_computer_text=1;
} else {
@@ -861,7 +911,7 @@ sub decideoutput {
}
}
}
- $button=0;
+ if ($awarded==1) { $button=0; } else { $button=1; }
$previousmsg='';
} elsif ($solved =~ /^excused/) {
if ($target eq 'tex') {
@@ -989,7 +1039,15 @@ sub decideoutput {
if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Formula_Answers')};
$css_class=$possible_class{'not_charged_try'};
$button=1;
- } elsif ($award eq 'INTERNAL_ERROR') {
+ } elsif ($award eq 'NOT_FUNCTION') {
+ $message = &mt("Not a function").'.';
+ $css_class=$possible_class{'not_charged_try'};
+ $button=1;
+ } elsif ($award eq 'WRONG_FORMAT') {
+ $message = &mt("Wrong format").'.';
+ $css_class=$possible_class{'not_charged_try'};
+ $button=1;
+ } elsif ($award eq 'INTERNAL_ERROR') {
$message = &mt("An internal error occurred while processing your answer. Please try again later.");
$css_class=$possible_class{'not_charged_try'};
$button=1;
@@ -1079,7 +1137,6 @@ sub decideoutput {
}
$message.=&mt('Submissions to practice problems are not permanently recorded.');
}
-
return ($button,$css_class,$message,$previousmsg);
}
@@ -1132,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,
@@ -1254,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
@@ -1265,14 +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::type eq 'randomizetry')) {
- $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
- }
- if ($Apache::lonhomework::type eq 'randomizetry') {
- $Apache::lonhomework::results{"resource.$id.rndseed"} = $env{'form.'.$id.'.rndseed'};
- }
+ $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 {
@@ -1352,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;
@@ -1367,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 {
@@ -1385,28 +1436,30 @@ sub get_grade_messages {
if ( $tries eq '' ) { $tries = '0'; }
if ( $maxtries eq '' ) { $maxtries = '2'; }
if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
- my $tries_text= &get_tries_text();;
+ my $tries_text= &get_tries_text();
if ($showbutton) {
if ($target eq 'tex') {
if ($env{'request.state'} ne "construct"
&& $Apache::lonhomework::type ne 'exam'
&& $env{'form.suppress_tries'} ne 'yes') {
- $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.
- $tries.'/'.$maxtries.'} \vskip 2 mm ';
+ $trystr ='{\vskip 1 mm \small '
+ .&mt('[_1]'.$tries_text.'[_2] [_3]'
+ ,'\textit{','}',$tries.'/'.$maxtries )
+ .'} \vskip 2 mm';
} else {
$trystr = '\vskip 0 mm ';
}
} else {
- $trystr = '